summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/sync_internals_html_source.cc
blob: c5c28090c2545d22bf0728d04b658f68f306fdd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/sync_internals_html_source.h"

#include <algorithm>

#include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h"
#include "base/message_loop.h"
#include "base/string_piece.h"
#include "base/values.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/url_constants.h"
#include "grit/sync_internals_resources.h"
#include "ui/base/resource/resource_bundle.h"

SyncInternalsHTMLSource::SyncInternalsHTMLSource()
    : DataSource(chrome::kChromeUISyncInternalsHost,
                 MessageLoop::current()) {}

SyncInternalsHTMLSource::~SyncInternalsHTMLSource() {}

void SyncInternalsHTMLSource::StartDataRequest(const std::string& path,
                                               bool is_incognito,
                                               int request_id) {
  base::StringPiece html_template(
      ResourceBundle::GetSharedInstance().GetRawDataResource(
          IDR_SYNC_INTERNALS_INDEX_HTML));
  DictionaryValue localized_strings;
  SetFontAndTextDirection(&localized_strings);

  std::string html(html_template.data(), html_template.size());
  jstemplate_builder::AppendI18nTemplateSourceHtml(&html);
  jstemplate_builder::AppendJsTemplateSourceHtml(&html);
  jstemplate_builder::AppendJsonHtml(&localized_strings, &html);
  jstemplate_builder::AppendI18nTemplateProcessHtml(&html);

  scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes());
  bytes->data.resize(html.size());
  std::copy(html.begin(), html.end(), bytes->data.begin());
  SendResponse(request_id, bytes);
}

std::string SyncInternalsHTMLSource::GetMimeType(
    const std::string& path) const {
  return "text/html";
}