Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/browser/ui/webui/print_preview_data_source.cc

Issue 8872051: Print preview: Display a dummy page when a user visits chrome://print directly. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 AddLocalizedString("defaultMargins", IDS_PRINT_PREVIEW_DEFAULT_MARGINS); 132 AddLocalizedString("defaultMargins", IDS_PRINT_PREVIEW_DEFAULT_MARGINS);
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 if (is_dummy) {
135 set_default_resource(IDR_PRINT_PREVIEW_HTML); 143 add_resource_path("print_preview_dummy.js", IDR_PRINT_PREVIEW_DUMMY_JS);
144 set_default_resource(IDR_PRINT_PREVIEW_DUMMY_HTML);
145 } else {
146 add_resource_path("print_preview.js", IDR_PRINT_PREVIEW_JS);
147 set_default_resource(IDR_PRINT_PREVIEW_HTML);
148 }
136 } 149 }
137 150
138 PrintPreviewDataSource::~PrintPreviewDataSource() { 151 PrintPreviewDataSource::~PrintPreviewDataSource() {
139 } 152 }
140 153
141 void PrintPreviewDataSource::StartDataRequest(const std::string& path, 154 void PrintPreviewDataSource::StartDataRequest(const std::string& path,
142 bool is_incognito, 155 bool is_incognito,
143 int request_id) { 156 int request_id) {
144 // Parent class handles most requests except for the print preview data. 157 // Parent class handles most requests except for the print preview data.
145 if (!EndsWith(path, "/print.pdf", true)) { 158 if (!EndsWith(path, "/print.pdf", true)) {
146 ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id); 159 ChromeWebUIDataSource::StartDataRequest(path, is_incognito, request_id);
147 return; 160 return;
148 } 161 }
149 162
150 // Print Preview data. 163 // Print Preview data.
151 scoped_refptr<RefCountedBytes> data; 164 scoped_refptr<RefCountedBytes> data;
152 std::vector<std::string> url_substr; 165 std::vector<std::string> url_substr;
153 base::SplitString(path, '/', &url_substr); 166 base::SplitString(path, '/', &url_substr);
154 int page_index = 0; 167 int page_index = 0;
155 if (url_substr.size() == 3 && base::StringToInt(url_substr[1], &page_index)) { 168 if (url_substr.size() == 3 && base::StringToInt(url_substr[1], &page_index)) {
156 PrintPreviewDataService::GetInstance()->GetDataEntry( 169 PrintPreviewDataService::GetInstance()->GetDataEntry(
157 url_substr[0], page_index, &data); 170 url_substr[0], page_index, &data);
158 } 171 }
159 if (data.get()) { 172 if (data.get()) {
160 SendResponse(request_id, data); 173 SendResponse(request_id, data);
161 return; 174 return;
162 } 175 }
163 // Invalid request. 176 // Invalid request.
164 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); 177 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
165 SendResponse(request_id, empty_bytes); 178 SendResponse(request_id, empty_bytes);
166 } 179 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_data_source.h ('k') | chrome/browser/ui/webui/print_preview_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698