Chromium Code Reviews| 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 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1201 if (errorCode > U_ZERO_ERROR || system != UMS_US) | 1201 if (errorCode > U_ZERO_ERROR || system != UMS_US) |
| 1202 system = UMS_SI; | 1202 system = UMS_SI; |
| 1203 | 1203 |
| 1204 // Getting the number formatting based on the locale and writing to | 1204 // Getting the number formatting based on the locale and writing to |
| 1205 // dictionary. | 1205 // dictionary. |
| 1206 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2)); | 1206 settings->SetString(kNumberFormat, base::FormatDouble(123456.78, 2)); |
| 1207 settings->SetInteger(kMeasurementSystem, system); | 1207 settings->SetInteger(kMeasurementSystem, system); |
| 1208 } | 1208 } |
| 1209 | 1209 |
| 1210 void PrintPreviewHandler::HandleGetInitialSettings( | 1210 void PrintPreviewHandler::HandleGetInitialSettings( |
| 1211 const base::ListValue* /*args*/) { | 1211 const base::ListValue* args) { |
| 1212 AllowJavascript(); | |
| 1213 | |
| 1214 std::string callback_id; | |
| 1215 if (!args->GetString(0, &callback_id) || callback_id.empty()) { | |
|
dpapad
2017/05/17 23:59:12
If we get in here, that would be a programmer's er
rbpotter
2017/05/18 17:56:30
Done.
| |
| 1216 RejectJavascriptCallback(base::Value(callback_id), base::Value()); | |
| 1217 } | |
| 1218 | |
| 1212 // Send before SendInitialSettings() to allow cloud printer auto select. | 1219 // Send before SendInitialSettings() to allow cloud printer auto select. |
| 1213 SendCloudPrintEnabled(); | 1220 SendCloudPrintEnabled(); |
| 1214 printer_backend_proxy()->GetDefaultPrinter(base::Bind( | 1221 printer_backend_proxy()->GetDefaultPrinter( |
| 1215 &PrintPreviewHandler::SendInitialSettings, weak_factory_.GetWeakPtr())); | 1222 base::Bind(&PrintPreviewHandler::SendInitialSettings, |
| 1223 weak_factory_.GetWeakPtr(), callback_id)); | |
| 1216 } | 1224 } |
| 1217 | 1225 |
| 1218 void PrintPreviewHandler::HandleForceOpenNewTab(const base::ListValue* args) { | 1226 void PrintPreviewHandler::HandleForceOpenNewTab(const base::ListValue* args) { |
| 1219 std::string url; | 1227 std::string url; |
| 1220 if (!args->GetString(0, &url)) | 1228 if (!args->GetString(0, &url)) |
| 1221 return; | 1229 return; |
| 1222 Browser* browser = chrome::FindBrowserWithWebContents(GetInitiator()); | 1230 Browser* browser = chrome::FindBrowserWithWebContents(GetInitiator()); |
| 1223 if (!browser) | 1231 if (!browser) |
| 1224 return; | 1232 return; |
| 1225 chrome::AddSelectedTabWithURL(browser, | 1233 chrome::AddSelectedTabWithURL(browser, |
| 1226 GURL(url), | 1234 GURL(url), |
| 1227 ui::PAGE_TRANSITION_LINK); | 1235 ui::PAGE_TRANSITION_LINK); |
| 1228 } | 1236 } |
| 1229 | 1237 |
| 1230 void PrintPreviewHandler::SendInitialSettings( | 1238 void PrintPreviewHandler::SendInitialSettings( |
| 1239 const std::string& callback_id, | |
| 1231 const std::string& default_printer) { | 1240 const std::string& default_printer) { |
| 1232 base::DictionaryValue initial_settings; | 1241 base::DictionaryValue initial_settings; |
| 1233 initial_settings.SetString(kInitiatorTitle, | 1242 initial_settings.SetString(kInitiatorTitle, |
| 1234 print_preview_ui()->initiator_title()); | 1243 print_preview_ui()->initiator_title()); |
| 1235 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, | 1244 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, |
| 1236 print_preview_ui()->source_is_modifiable()); | 1245 print_preview_ui()->source_is_modifiable()); |
| 1237 initial_settings.SetString(printing::kSettingPrinterName, default_printer); | 1246 initial_settings.SetString(printing::kSettingPrinterName, default_printer); |
| 1238 initial_settings.SetBoolean(kDocumentHasSelection, | 1247 initial_settings.SetBoolean(kDocumentHasSelection, |
| 1239 print_preview_ui()->source_has_selection()); | 1248 print_preview_ui()->source_has_selection()); |
| 1240 initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, | 1249 initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1255 chrome::IsRunningInForcedAppMode()); | 1264 chrome::IsRunningInForcedAppMode()); |
| 1256 if (prefs) { | 1265 if (prefs) { |
| 1257 const std::string rules_str = | 1266 const std::string rules_str = |
| 1258 prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); | 1267 prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); |
| 1259 if (!rules_str.empty()) | 1268 if (!rules_str.empty()) |
| 1260 initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); | 1269 initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); |
| 1261 } | 1270 } |
| 1262 | 1271 |
| 1263 if (print_preview_ui()->source_is_modifiable()) | 1272 if (print_preview_ui()->source_is_modifiable()) |
| 1264 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1273 GetNumberFormatAndMeasurementSystem(&initial_settings); |
| 1265 web_ui()->CallJavascriptFunctionUnsafe("setInitialSettings", | 1274 ResolveJavascriptCallback(base::Value(callback_id), initial_settings); |
| 1266 initial_settings); | |
| 1267 } | 1275 } |
| 1268 | 1276 |
| 1269 void PrintPreviewHandler::ClosePreviewDialog() { | 1277 void PrintPreviewHandler::ClosePreviewDialog() { |
| 1270 print_preview_ui()->OnClosePrintPreviewDialog(); | 1278 print_preview_ui()->OnClosePrintPreviewDialog(); |
| 1271 } | 1279 } |
| 1272 | 1280 |
| 1273 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1281 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
| 1274 const std::string& access_token) { | 1282 const std::string& access_token) { |
| 1275 VLOG(1) << "Get getAccessToken finished"; | 1283 VLOG(1) << "Get getAccessToken finished"; |
| 1276 web_ui()->CallJavascriptFunctionUnsafe( | 1284 web_ui()->CallJavascriptFunctionUnsafe( |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1778 | 1786 |
| 1779 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1787 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1780 if (gaia_cookie_manager_service_) | 1788 if (gaia_cookie_manager_service_) |
| 1781 gaia_cookie_manager_service_->RemoveObserver(this); | 1789 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1782 } | 1790 } |
| 1783 | 1791 |
| 1784 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1792 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1785 const base::Closure& closure) { | 1793 const base::Closure& closure) { |
| 1786 pdf_file_saved_closure_ = closure; | 1794 pdf_file_saved_closure_ = closure; |
| 1787 } | 1795 } |
| OLD | NEW |