OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/i18n/file_util_icu.h" | 16 #include "base/i18n/file_util_icu.h" |
17 #include "base/i18n/number_formatting.h" | 17 #include "base/i18n/number_formatting.h" |
18 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
20 #include "base/memory/linked_ptr.h" | 20 #include "base/memory/linked_ptr.h" |
21 #include "base/memory/ref_counted_memory.h" | 21 #include "base/memory/ref_counted_memory.h" |
22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
24 #include "base/prefs/pref_service.h" | 24 #include "base/prefs/pref_service.h" |
25 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "base/threading/thread.h" | 27 #include "base/threading/thread.h" |
28 #include "base/threading/thread_restrictions.h" | 28 #include "base/threading/thread_restrictions.h" |
29 #include "base/values.h" | 29 #include "base/values.h" |
| 30 #include "chrome/browser/app_mode/app_mode_utils.h" |
30 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/platform_util.h" | 32 #include "chrome/browser/platform_util.h" |
32 #include "chrome/browser/printing/print_dialog_cloud.h" | 33 #include "chrome/browser/printing/print_dialog_cloud.h" |
33 #include "chrome/browser/printing/print_error_dialog.h" | 34 #include "chrome/browser/printing/print_error_dialog.h" |
34 #include "chrome/browser/printing/print_job_manager.h" | 35 #include "chrome/browser/printing/print_job_manager.h" |
35 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 36 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
36 #include "chrome/browser/printing/print_view_manager.h" | 37 #include "chrome/browser/printing/print_view_manager.h" |
37 #include "chrome/browser/printing/printer_manager_dialog.h" | 38 #include "chrome/browser/printing/printer_manager_dialog.h" |
38 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
39 #include "chrome/browser/signin/account_reconcilor_factory.h" | 40 #include "chrome/browser/signin/account_reconcilor_factory.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // Name of a dictionary field holding the initiator title. | 176 // Name of a dictionary field holding the initiator title. |
176 const char kInitiatorTitle[] = "initiatorTitle"; | 177 const char kInitiatorTitle[] = "initiatorTitle"; |
177 // Name of a dictionary field holding the measurement system according to the | 178 // Name of a dictionary field holding the measurement system according to the |
178 // locale. | 179 // locale. |
179 const char kMeasurementSystem[] = "measurementSystem"; | 180 const char kMeasurementSystem[] = "measurementSystem"; |
180 // Name of a dictionary field holding the number format according to the locale. | 181 // Name of a dictionary field holding the number format according to the locale. |
181 const char kNumberFormat[] = "numberFormat"; | 182 const char kNumberFormat[] = "numberFormat"; |
182 // Name of a dictionary field specifying whether to print automatically in | 183 // Name of a dictionary field specifying whether to print automatically in |
183 // kiosk mode. See http://crbug.com/31395. | 184 // kiosk mode. See http://crbug.com/31395. |
184 const char kPrintAutomaticallyInKioskMode[] = "printAutomaticallyInKioskMode"; | 185 const char kPrintAutomaticallyInKioskMode[] = "printAutomaticallyInKioskMode"; |
| 186 // Dictionary field to indicate whether Chrome is running in forced app (app |
| 187 // kiosk) mode. It's not the same as desktop Chrome kiosk (the one above). |
| 188 const char kAppKioskMode[] = "appKioskMode"; |
| 189 // Dictionary field to store Cloud Print base URL. |
| 190 const char kCloudPrintUrl[] = "cloudPrintUrl"; |
185 #if defined(OS_WIN) | 191 #if defined(OS_WIN) |
186 const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink"; | 192 const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink"; |
187 #endif | 193 #endif |
188 // Name of a dictionary field holding the state of selection for document. | 194 // Name of a dictionary field holding the state of selection for document. |
189 const char kDocumentHasSelection[] = "documentHasSelection"; | 195 const char kDocumentHasSelection[] = "documentHasSelection"; |
190 | 196 |
191 // Id of the predefined PDF printer. | 197 // Id of the predefined PDF printer. |
192 const char kLocalPdfPrinterId[] = "Save as PDF"; | 198 const char kLocalPdfPrinterId[] = "Save as PDF"; |
193 | 199 |
194 // Additional printer capability setting keys. | 200 // Additional printer capability setting keys. |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 sticky_settings->RestoreFromPrefs(Profile::FromBrowserContext( | 1194 sticky_settings->RestoreFromPrefs(Profile::FromBrowserContext( |
1189 preview_web_contents()->GetBrowserContext())->GetPrefs()); | 1195 preview_web_contents()->GetBrowserContext())->GetPrefs()); |
1190 if (sticky_settings->printer_app_state()) { | 1196 if (sticky_settings->printer_app_state()) { |
1191 initial_settings.SetString(kAppState, | 1197 initial_settings.SetString(kAppState, |
1192 *sticky_settings->printer_app_state()); | 1198 *sticky_settings->printer_app_state()); |
1193 } | 1199 } |
1194 | 1200 |
1195 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 1201 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
1196 initial_settings.SetBoolean(kPrintAutomaticallyInKioskMode, | 1202 initial_settings.SetBoolean(kPrintAutomaticallyInKioskMode, |
1197 cmdline->HasSwitch(switches::kKioskModePrinting)); | 1203 cmdline->HasSwitch(switches::kKioskModePrinting)); |
| 1204 initial_settings.SetBoolean(kAppKioskMode, |
| 1205 chrome::IsRunningInForcedAppMode()); |
1198 #if defined(OS_WIN) | 1206 #if defined(OS_WIN) |
1199 // In Win8 metro, the system print dialog can only open on the desktop. Doing | 1207 // In Win8 metro, the system print dialog can only open on the desktop. Doing |
1200 // so will cause the browser to appear hung, so we don't show the link in | 1208 // so will cause the browser to appear hung, so we don't show the link in |
1201 // metro. | 1209 // metro. |
1202 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); | 1210 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); |
1203 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); | 1211 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); |
1204 #endif | 1212 #endif |
1205 | 1213 |
1206 if (print_preview_ui->source_is_modifiable()) | 1214 if (print_preview_ui->source_is_modifiable()) |
1207 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1215 GetNumberFormatAndMeasurementSystem(&initial_settings); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 } | 1252 } |
1245 | 1253 |
1246 web_ui()->CallJavascriptFunction("setPrinters", *printers); | 1254 web_ui()->CallJavascriptFunction("setPrinters", *printers); |
1247 } | 1255 } |
1248 | 1256 |
1249 void PrintPreviewHandler::SendCloudPrintEnabled() { | 1257 void PrintPreviewHandler::SendCloudPrintEnabled() { |
1250 Profile* profile = Profile::FromBrowserContext( | 1258 Profile* profile = Profile::FromBrowserContext( |
1251 preview_web_contents()->GetBrowserContext()); | 1259 preview_web_contents()->GetBrowserContext()); |
1252 PrefService* prefs = profile->GetPrefs(); | 1260 PrefService* prefs = profile->GetPrefs(); |
1253 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { | 1261 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { |
1254 GURL gcp_url(cloud_devices::GetCloudPrintURL()); | 1262 base::DictionaryValue settings; |
1255 base::StringValue gcp_url_value(gcp_url.spec()); | 1263 settings.SetString(kCloudPrintUrl, |
1256 web_ui()->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); | 1264 GURL(cloud_devices::GetCloudPrintURL()).spec()); |
| 1265 settings.SetBoolean(kAppKioskMode, chrome::IsRunningInForcedAppMode()); |
| 1266 web_ui()->CallJavascriptFunction("setUseCloudPrint", settings); |
1257 } | 1267 } |
1258 } | 1268 } |
1259 | 1269 |
1260 void PrintPreviewHandler::SendCloudPrintJob(const base::RefCountedBytes* data) { | 1270 void PrintPreviewHandler::SendCloudPrintJob(const base::RefCountedBytes* data) { |
1261 // BASE64 encode the job data. | 1271 // BASE64 encode the job data. |
1262 std::string raw_data(reinterpret_cast<const char*>(data->front()), | 1272 std::string raw_data(reinterpret_cast<const char*>(data->front()), |
1263 data->size()); | 1273 data->size()); |
1264 std::string base64_data; | 1274 std::string base64_data; |
1265 base::Base64Encode(raw_data, &base64_data); | 1275 base::Base64Encode(raw_data, &base64_data); |
1266 base::StringValue data_value(base64_data); | 1276 base::StringValue data_value(base64_data); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1614 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile); | 1624 reconcilor_ = AccountReconcilorFactory::GetForProfile(profile); |
1615 if (reconcilor_) | 1625 if (reconcilor_) |
1616 reconcilor_->AddMergeSessionObserver(this); | 1626 reconcilor_->AddMergeSessionObserver(this); |
1617 } | 1627 } |
1618 } | 1628 } |
1619 | 1629 |
1620 void PrintPreviewHandler::UnregisterForMergeSession() { | 1630 void PrintPreviewHandler::UnregisterForMergeSession() { |
1621 if (reconcilor_) | 1631 if (reconcilor_) |
1622 reconcilor_->RemoveMergeSessionObserver(this); | 1632 reconcilor_->RemoveMergeSessionObserver(this); |
1623 } | 1633 } |
OLD | NEW |