1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/webui/sync_internals_html_source.h" 6 7#include <algorithm> 8 9#include "base/memory/ref_counted.h" 10#include "base/memory/ref_counted_memory.h" 11#include "base/message_loop.h" 12#include "base/string_piece.h" 13#include "base/values.h" 14#include "chrome/common/jstemplate_builder.h" 15#include "chrome/common/url_constants.h" 16#include "grit/sync_internals_resources.h" 17#include "ui/base/resource/resource_bundle.h" 18 19SyncInternalsHTMLSource::SyncInternalsHTMLSource() 20 : DataSource(chrome::kChromeUISyncInternalsHost, 21 MessageLoop::current()) {} 22 23SyncInternalsHTMLSource::~SyncInternalsHTMLSource() {} 24 25void SyncInternalsHTMLSource::StartDataRequest(const std::string& path, 26 bool is_incognito, 27 int request_id) { 28 base::StringPiece html_template( 29 ResourceBundle::GetSharedInstance().GetRawDataResource( 30 IDR_SYNC_INTERNALS_INDEX_HTML)); 31 DictionaryValue localized_strings; 32 SetFontAndTextDirection(&localized_strings); 33 34 std::string html(html_template.data(), html_template.size()); 35 jstemplate_builder::AppendI18nTemplateSourceHtml(&html); 36 jstemplate_builder::AppendJsTemplateSourceHtml(&html); 37 jstemplate_builder::AppendJsonHtml(&localized_strings, &html); 38 jstemplate_builder::AppendI18nTemplateProcessHtml(&html); 39 40 scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes()); 41 bytes->data.resize(html.size()); 42 std::copy(html.begin(), html.end(), bytes->data.begin()); 43 SendResponse(request_id, bytes); 44} 45 46std::string SyncInternalsHTMLSource::GetMimeType( 47 const std::string& path) const { 48 return "text/html"; 49} 50