| 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   std::string callback_id; | 
|  | 1213   CHECK(args->GetString(0, &callback_id)); | 
|  | 1214   CHECK(!callback_id.empty()); | 
|  | 1215 | 
|  | 1216   AllowJavascript(); | 
|  | 1217 | 
| 1212   // Send before SendInitialSettings() to allow cloud printer auto select. | 1218   // Send before SendInitialSettings() to allow cloud printer auto select. | 
| 1213   SendCloudPrintEnabled(); | 1219   SendCloudPrintEnabled(); | 
| 1214   printer_backend_proxy()->GetDefaultPrinter(base::Bind( | 1220   printer_backend_proxy()->GetDefaultPrinter( | 
| 1215       &PrintPreviewHandler::SendInitialSettings, weak_factory_.GetWeakPtr())); | 1221       base::Bind(&PrintPreviewHandler::SendInitialSettings, | 
|  | 1222                  weak_factory_.GetWeakPtr(), callback_id)); | 
| 1216 } | 1223 } | 
| 1217 | 1224 | 
| 1218 void PrintPreviewHandler::HandleForceOpenNewTab(const base::ListValue* args) { | 1225 void PrintPreviewHandler::HandleForceOpenNewTab(const base::ListValue* args) { | 
| 1219   std::string url; | 1226   std::string url; | 
| 1220   if (!args->GetString(0, &url)) | 1227   if (!args->GetString(0, &url)) | 
| 1221     return; | 1228     return; | 
| 1222   Browser* browser = chrome::FindBrowserWithWebContents(GetInitiator()); | 1229   Browser* browser = chrome::FindBrowserWithWebContents(GetInitiator()); | 
| 1223   if (!browser) | 1230   if (!browser) | 
| 1224     return; | 1231     return; | 
| 1225   chrome::AddSelectedTabWithURL(browser, | 1232   chrome::AddSelectedTabWithURL(browser, | 
| 1226                                 GURL(url), | 1233                                 GURL(url), | 
| 1227                                 ui::PAGE_TRANSITION_LINK); | 1234                                 ui::PAGE_TRANSITION_LINK); | 
| 1228 } | 1235 } | 
| 1229 | 1236 | 
| 1230 void PrintPreviewHandler::SendInitialSettings( | 1237 void PrintPreviewHandler::SendInitialSettings( | 
|  | 1238     const std::string& callback_id, | 
| 1231     const std::string& default_printer) { | 1239     const std::string& default_printer) { | 
| 1232   base::DictionaryValue initial_settings; | 1240   base::DictionaryValue initial_settings; | 
| 1233   initial_settings.SetString(kInitiatorTitle, | 1241   initial_settings.SetString(kInitiatorTitle, | 
| 1234                              print_preview_ui()->initiator_title()); | 1242                              print_preview_ui()->initiator_title()); | 
| 1235   initial_settings.SetBoolean(printing::kSettingPreviewModifiable, | 1243   initial_settings.SetBoolean(printing::kSettingPreviewModifiable, | 
| 1236                               print_preview_ui()->source_is_modifiable()); | 1244                               print_preview_ui()->source_is_modifiable()); | 
| 1237   initial_settings.SetString(printing::kSettingPrinterName, default_printer); | 1245   initial_settings.SetString(printing::kSettingPrinterName, default_printer); | 
| 1238   initial_settings.SetBoolean(kDocumentHasSelection, | 1246   initial_settings.SetBoolean(kDocumentHasSelection, | 
| 1239                               print_preview_ui()->source_has_selection()); | 1247                               print_preview_ui()->source_has_selection()); | 
| 1240   initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, | 1248   initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 1255                               chrome::IsRunningInForcedAppMode()); | 1263                               chrome::IsRunningInForcedAppMode()); | 
| 1256   if (prefs) { | 1264   if (prefs) { | 
| 1257     const std::string rules_str = | 1265     const std::string rules_str = | 
| 1258         prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); | 1266         prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); | 
| 1259     if (!rules_str.empty()) | 1267     if (!rules_str.empty()) | 
| 1260       initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); | 1268       initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); | 
| 1261   } | 1269   } | 
| 1262 | 1270 | 
| 1263   if (print_preview_ui()->source_is_modifiable()) | 1271   if (print_preview_ui()->source_is_modifiable()) | 
| 1264     GetNumberFormatAndMeasurementSystem(&initial_settings); | 1272     GetNumberFormatAndMeasurementSystem(&initial_settings); | 
| 1265   web_ui()->CallJavascriptFunctionUnsafe("setInitialSettings", | 1273   ResolveJavascriptCallback(base::Value(callback_id), initial_settings); | 
| 1266                                          initial_settings); |  | 
| 1267 } | 1274 } | 
| 1268 | 1275 | 
| 1269 void PrintPreviewHandler::ClosePreviewDialog() { | 1276 void PrintPreviewHandler::ClosePreviewDialog() { | 
| 1270   print_preview_ui()->OnClosePrintPreviewDialog(); | 1277   print_preview_ui()->OnClosePrintPreviewDialog(); | 
| 1271 } | 1278 } | 
| 1272 | 1279 | 
| 1273 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1280 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 
| 1274                                           const std::string& access_token) { | 1281                                           const std::string& access_token) { | 
| 1275   VLOG(1) << "Get getAccessToken finished"; | 1282   VLOG(1) << "Get getAccessToken finished"; | 
| 1276   web_ui()->CallJavascriptFunctionUnsafe( | 1283   web_ui()->CallJavascriptFunctionUnsafe( | 
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1778 | 1785 | 
| 1779 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1786 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 
| 1780   if (gaia_cookie_manager_service_) | 1787   if (gaia_cookie_manager_service_) | 
| 1781     gaia_cookie_manager_service_->RemoveObserver(this); | 1788     gaia_cookie_manager_service_->RemoveObserver(this); | 
| 1782 } | 1789 } | 
| 1783 | 1790 | 
| 1784 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1791 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 
| 1785     const base::Closure& closure) { | 1792     const base::Closure& closure) { | 
| 1786   pdf_file_saved_closure_ = closure; | 1793   pdf_file_saved_closure_ = closure; | 
| 1787 } | 1794 } | 
| OLD | NEW | 
|---|