| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/print_preview_data_source.h" | 5 #include "chrome/browser/ui/webui/print_preview_data_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8 | 29 // U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8 |
| 30 const char kAdvancedPrintShortcut[] = "\x28\xE2\x8c\xA5\xE2\x8C\x98\x50\x29"; | 30 const char kAdvancedPrintShortcut[] = "\x28\xE2\x8c\xA5\xE2\x8C\x98\x50\x29"; |
| 31 #elif defined(OS_WIN) | 31 #elif defined(OS_WIN) |
| 32 const char kAdvancedPrintShortcut[] = "(Ctrl+Shift+P)"; | 32 const char kAdvancedPrintShortcut[] = "(Ctrl+Shift+P)"; |
| 33 #else | 33 #else |
| 34 const char kAdvancedPrintShortcut[] = "(Shift+Ctrl+P)"; | 34 const char kAdvancedPrintShortcut[] = "(Shift+Ctrl+P)"; |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 }; // namespace | 37 }; // namespace |
| 38 | 38 |
| 39 PrintPreviewDataSource::PrintPreviewDataSource() | 39 PrintPreviewDataSource::PrintPreviewDataSource(bool is_dummy) |
| 40 : ChromeWebUIDataSource(chrome::kChromeUIPrintHost) { | 40 : ChromeWebUIDataSource(chrome::kChromeUIPrintHost) { |
| 41 Init(is_dummy); |
| 42 } |
| 43 |
| 44 void PrintPreviewDataSource::Init(bool is_dummy) { |
| 45 if (is_dummy) { |
| 46 AddLocalizedString("intentionallyBlankText", |
| 47 IDS_PRINT_PREVIEW_INTENTIONALLY_BLANK); |
| 48 } |
| 41 | 49 |
| 42 AddLocalizedString("title", IDS_PRINT_PREVIEW_TITLE); | 50 AddLocalizedString("title", IDS_PRINT_PREVIEW_TITLE); |
| 43 AddLocalizedString("loading", IDS_PRINT_PREVIEW_LOADING); | 51 AddLocalizedString("loading", IDS_PRINT_PREVIEW_LOADING); |
| 44 #if defined(GOOGLE_CHROME_BUILD) | 52 #if defined(GOOGLE_CHROME_BUILD) |
| 45 AddString("noPlugin", l10n_util::GetStringFUTF16( | 53 AddString("noPlugin", l10n_util::GetStringFUTF16( |
| 46 IDS_PRINT_PREVIEW_NO_PLUGIN, ASCIIToUTF16("chrome://plugins/"))); | 54 IDS_PRINT_PREVIEW_NO_PLUGIN, ASCIIToUTF16("chrome://plugins/"))); |
| 47 #else | 55 #else |
| 48 AddLocalizedString("noPlugin", IDS_PRINT_PREVIEW_NO_PLUGIN); | 56 AddLocalizedString("noPlugin", IDS_PRINT_PREVIEW_NO_PLUGIN); |
| 49 #endif | 57 #endif |
| 50 AddLocalizedString("launchNativeDialog", IDS_PRINT_PREVIEW_NATIVE_DIALOG); | 58 AddLocalizedString("launchNativeDialog", IDS_PRINT_PREVIEW_NATIVE_DIALOG); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 AddLocalizedString("noMargins", IDS_PRINT_PREVIEW_NO_MARGINS); | 133 AddLocalizedString("noMargins", IDS_PRINT_PREVIEW_NO_MARGINS); |
| 126 AddLocalizedString("customMargins", IDS_PRINT_PREVIEW_CUSTOM_MARGINS); | 134 AddLocalizedString("customMargins", IDS_PRINT_PREVIEW_CUSTOM_MARGINS); |
| 127 AddLocalizedString("minimumMargins", IDS_PRINT_PREVIEW_MINIMUM_MARGINS); | 135 AddLocalizedString("minimumMargins", IDS_PRINT_PREVIEW_MINIMUM_MARGINS); |
| 128 AddLocalizedString("top", IDS_PRINT_PREVIEW_TOP_MARGIN_LABEL); | 136 AddLocalizedString("top", IDS_PRINT_PREVIEW_TOP_MARGIN_LABEL); |
| 129 AddLocalizedString("bottom", IDS_PRINT_PREVIEW_BOTTOM_MARGIN_LABEL); | 137 AddLocalizedString("bottom", IDS_PRINT_PREVIEW_BOTTOM_MARGIN_LABEL); |
| 130 AddLocalizedString("left", IDS_PRINT_PREVIEW_LEFT_MARGIN_LABEL); | 138 AddLocalizedString("left", IDS_PRINT_PREVIEW_LEFT_MARGIN_LABEL); |
| 131 AddLocalizedString("right", IDS_PRINT_PREVIEW_RIGHT_MARGIN_LABEL); | 139 AddLocalizedString("right", IDS_PRINT_PREVIEW_RIGHT_MARGIN_LABEL); |
| 132 | 140 |
| 133 set_json_path("strings.js"); | 141 set_json_path("strings.js"); |
| 134 add_resource_path("print_preview.js", IDR_PRINT_PREVIEW_JS); | 142 add_resource_path("print_preview.js", IDR_PRINT_PREVIEW_JS); |
| 135 set_default_resource(IDR_PRINT_PREVIEW_HTML); | 143 set_default_resource( |
| 144 is_dummy ? IDR_PRINT_PREVIEW_HTML_DUMMY : IDR_PRINT_PREVIEW_HTML); |
| 136 } | 145 } |
| 137 | 146 |
| 138 PrintPreviewDataSource::~PrintPreviewDataSource() { | 147 PrintPreviewDataSource::~PrintPreviewDataSource() { |
| 139 } | 148 } |
| 140 | 149 |
| 141 void PrintPreviewDataSource::StartDataRequest(const std::string& path, | 150 void PrintPreviewDataSource::StartDataRequest(const std::string& path, |
| 142 bool is_incognito, | 151 bool is_incognito, |
| 143 int request_id) { | 152 int request_id) { |
| 144 // Parent class handles most requests except for the print preview data. | 153 // Parent class handles most requests except for the print preview data. |
| 145 if (!EndsWith(path, "/print.pdf", true)) { | 154 if (!EndsWith(path, "/print.pdf", true)) { |
| 146 ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id); | 155 ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id); |
| 147 return; | 156 return; |
| 148 } | 157 } |
| 149 | 158 |
| 150 // Print Preview data. | 159 // Print Preview data. |
| 151 scoped_refptr<RefCountedBytes> data; | 160 scoped_refptr<RefCountedBytes> data; |
| 152 std::vector<std::string> url_substr; | 161 std::vector<std::string> url_substr; |
| 153 base::SplitString(path, '/', &url_substr); | 162 base::SplitString(path, '/', &url_substr); |
| 154 int page_index = 0; | 163 int page_index = 0; |
| 155 if (url_substr.size() == 3 && base::StringToInt(url_substr[1], &page_index)) { | 164 if (url_substr.size() == 3 && base::StringToInt(url_substr[1], &page_index)) { |
| 156 PrintPreviewDataService::GetInstance()->GetDataEntry( | 165 PrintPreviewDataService::GetInstance()->GetDataEntry( |
| 157 url_substr[0], page_index, &data); | 166 url_substr[0], page_index, &data); |
| 158 } | 167 } |
| 159 if (data.get()) { | 168 if (data.get()) { |
| 160 SendResponse(request_id, data); | 169 SendResponse(request_id, data); |
| 161 return; | 170 return; |
| 162 } | 171 } |
| 163 // Invalid request. | 172 // Invalid request. |
| 164 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); | 173 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); |
| 165 SendResponse(request_id, empty_bytes); | 174 SendResponse(request_id, empty_bytes); |
| 166 } | 175 } |
| OLD | NEW |