| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 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/dom_ui/print_preview_ui.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/singleton.h" |
| 13 #include "base/string_piece.h" |
| 14 #include "base/values.h" |
| 15 #include "chrome/browser/chrome_thread.h" |
| 16 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents.h" |
| 18 #include "chrome/common/jstemplate_builder.h" |
| 19 #include "chrome/common/url_constants.h" |
| 20 |
| 21 #include "grit/browser_resources.h" |
| 22 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" |
| 24 |
| 25 namespace { |
| 26 |
| 27 void SetLocalizedStrings(DictionaryValue* localized_strings) { |
| 28 localized_strings->SetString(std::string("title"), |
| 29 l10n_util::GetStringUTF8(IDS_PRINTPREVIEW_TITLE)); |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
| 34 //////////////////////////////////////////////////////////////////////////////// |
| 35 // |
| 36 // PrintPreviewUIHTMLSource |
| 37 // |
| 38 //////////////////////////////////////////////////////////////////////////////// |
| 39 |
| 40 PrintPreviewUIHTMLSource::PrintPreviewUIHTMLSource() |
| 41 : DataSource(chrome::kChromeUIPrintHost, MessageLoop::current()) { |
| 42 } |
| 43 |
| 44 PrintPreviewUIHTMLSource::~PrintPreviewUIHTMLSource() {} |
| 45 |
| 46 void PrintPreviewUIHTMLSource::StartDataRequest(const std::string& path, |
| 47 bool is_off_the_record, |
| 48 int request_id) { |
| 49 DictionaryValue localized_strings; |
| 50 SetLocalizedStrings(&localized_strings); |
| 51 SetFontAndTextDirection(&localized_strings); |
| 52 |
| 53 static const base::StringPiece print_html( |
| 54 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 55 IDR_PRINTPREVIEW_HTML)); |
| 56 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
| 57 print_html, &localized_strings); |
| 58 |
| 59 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 60 html_bytes->data.resize(full_html.size()); |
| 61 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| 62 |
| 63 SendResponse(request_id, html_bytes); |
| 64 } |
| 65 |
| 66 std::string PrintPreviewUIHTMLSource::GetMimeType(const std::string&) const { |
| 67 return "text/html"; |
| 68 } |
| 69 |
| 70 //////////////////////////////////////////////////////////////////////////////// |
| 71 // |
| 72 // PrintPreviewUI |
| 73 // |
| 74 //////////////////////////////////////////////////////////////////////////////// |
| 75 |
| 76 PrintPreviewUI::PrintPreviewUI(TabContents* contents) : DOMUI(contents) { |
| 77 // Set up the chrome://print/ source. |
| 78 ChromeThread::PostTask( |
| 79 ChromeThread::IO, FROM_HERE, |
| 80 NewRunnableMethod( |
| 81 Singleton<ChromeURLDataManager>::get(), |
| 82 &ChromeURLDataManager::AddDataSource, |
| 83 make_scoped_refptr(new PrintPreviewUIHTMLSource()))); |
| 84 } |
| 85 |
| 86 PrintPreviewUI::~PrintPreviewUI() { |
| 87 } |
| OLD | NEW |