| 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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 BrowserThread::FILE, FROM_HERE, | 701 BrowserThread::FILE, FROM_HERE, |
| 702 base::Bind(&EnumeratePrintersOnFileThread, | 702 base::Bind(&EnumeratePrintersOnFileThread, |
| 703 base::Unretained(results)), | 703 base::Unretained(results)), |
| 704 base::Bind(&PrintPreviewHandler::SetupPrinterList, | 704 base::Bind(&PrintPreviewHandler::SetupPrinterList, |
| 705 weak_factory_.GetWeakPtr(), | 705 weak_factory_.GetWeakPtr(), |
| 706 base::Owned(results))); | 706 base::Owned(results))); |
| 707 } | 707 } |
| 708 | 708 |
| 709 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { | 709 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { |
| 710 if (!PrivetPrintingEnabled()) | 710 if (!PrivetPrintingEnabled()) |
| 711 return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone"); | 711 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone"); |
| 712 #if defined(ENABLE_SERVICE_DISCOVERY) | 712 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 713 using local_discovery::ServiceDiscoverySharedClient; | 713 using local_discovery::ServiceDiscoverySharedClient; |
| 714 scoped_refptr<ServiceDiscoverySharedClient> service_discovery = | 714 scoped_refptr<ServiceDiscoverySharedClient> service_discovery = |
| 715 ServiceDiscoverySharedClient::GetInstance(); | 715 ServiceDiscoverySharedClient::GetInstance(); |
| 716 StartPrivetLister(service_discovery); | 716 StartPrivetLister(service_discovery); |
| 717 #endif // ENABLE_SERVICE_DISCOVERY | 717 #endif // ENABLE_SERVICE_DISCOVERY |
| 718 } | 718 } |
| 719 | 719 |
| 720 void PrintPreviewHandler::HandleStopGetPrivetPrinters( | 720 void PrintPreviewHandler::HandleStopGetPrivetPrinters( |
| 721 const base::ListValue* args) { | 721 const base::ListValue* args) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 int width = 0; | 921 int width = 0; |
| 922 int height = 0; | 922 int height = 0; |
| 923 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || | 923 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || |
| 924 !settings->GetString(printing::kSettingTicket, &print_ticket) || | 924 !settings->GetString(printing::kSettingTicket, &print_ticket) || |
| 925 !settings->GetString(printing::kSettingCapabilities, &capabilities) || | 925 !settings->GetString(printing::kSettingCapabilities, &capabilities) || |
| 926 !settings->GetInteger(printing::kSettingPageWidth, &width) || | 926 !settings->GetInteger(printing::kSettingPageWidth, &width) || |
| 927 !settings->GetInteger(printing::kSettingPageHeight, &height) || | 927 !settings->GetInteger(printing::kSettingPageHeight, &height) || |
| 928 width <= 0 || height <= 0) { | 928 width <= 0 || height <= 0) { |
| 929 NOTREACHED(); | 929 NOTREACHED(); |
| 930 base::FundamentalValue http_code_value(-1); | 930 base::FundamentalValue http_code_value(-1); |
| 931 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 931 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", |
| 932 http_code_value); |
| 932 return; | 933 return; |
| 933 } | 934 } |
| 934 | 935 |
| 935 PrintToPrivetPrinter( | 936 PrintToPrivetPrinter( |
| 936 printer_name, print_ticket, capabilities, gfx::Size(width, height)); | 937 printer_name, print_ticket, capabilities, gfx::Size(width, height)); |
| 937 return; | 938 return; |
| 938 } | 939 } |
| 939 #endif | 940 #endif |
| 940 | 941 |
| 941 if (print_with_extension) { | 942 if (print_with_extension) { |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 chrome::IsRunningInForcedAppMode()); | 1283 chrome::IsRunningInForcedAppMode()); |
| 1283 if (prefs) { | 1284 if (prefs) { |
| 1284 const std::string rules_str = | 1285 const std::string rules_str = |
| 1285 prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); | 1286 prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); |
| 1286 if (!rules_str.empty()) | 1287 if (!rules_str.empty()) |
| 1287 initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); | 1288 initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); |
| 1288 } | 1289 } |
| 1289 | 1290 |
| 1290 if (print_preview_ui()->source_is_modifiable()) | 1291 if (print_preview_ui()->source_is_modifiable()) |
| 1291 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1292 GetNumberFormatAndMeasurementSystem(&initial_settings); |
| 1292 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 1293 web_ui()->CallJavascriptFunctionUnsafe("setInitialSettings", |
| 1294 initial_settings); |
| 1293 | 1295 |
| 1294 if (PrintPreviewDistiller::IsEnabled()) { | 1296 if (PrintPreviewDistiller::IsEnabled()) { |
| 1295 using dom_distiller::url_utils::IsUrlDistillable; | 1297 using dom_distiller::url_utils::IsUrlDistillable; |
| 1296 WebContents* initiator = GetInitiator(); | 1298 WebContents* initiator = GetInitiator(); |
| 1297 if (initiator && IsUrlDistillable(initiator->GetLastCommittedURL())) | 1299 if (initiator && IsUrlDistillable(initiator->GetLastCommittedURL())) |
| 1298 web_ui()->CallJavascriptFunction("allowDistillPage"); | 1300 web_ui()->CallJavascriptFunctionUnsafe("allowDistillPage"); |
| 1299 } | 1301 } |
| 1300 } | 1302 } |
| 1301 | 1303 |
| 1302 void PrintPreviewHandler::ClosePreviewDialog() { | 1304 void PrintPreviewHandler::ClosePreviewDialog() { |
| 1303 print_preview_ui()->OnClosePrintPreviewDialog(); | 1305 print_preview_ui()->OnClosePrintPreviewDialog(); |
| 1304 } | 1306 } |
| 1305 | 1307 |
| 1306 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1308 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
| 1307 const std::string& access_token) { | 1309 const std::string& access_token) { |
| 1308 VLOG(1) << "Get getAccessToken finished"; | 1310 VLOG(1) << "Get getAccessToken finished"; |
| 1309 web_ui()->CallJavascriptFunction("onDidGetAccessToken", | 1311 web_ui()->CallJavascriptFunctionUnsafe("onDidGetAccessToken", |
| 1310 base::StringValue(type), | 1312 base::StringValue(type), |
| 1311 base::StringValue(access_token)); | 1313 base::StringValue(access_token)); |
| 1312 } | 1314 } |
| 1313 | 1315 |
| 1314 void PrintPreviewHandler::SendPrinterCapabilities( | 1316 void PrintPreviewHandler::SendPrinterCapabilities( |
| 1315 const std::string& printer_name, | 1317 const std::string& printer_name, |
| 1316 std::unique_ptr<base::DictionaryValue> settings_info) { | 1318 std::unique_ptr<base::DictionaryValue> settings_info) { |
| 1317 if (!settings_info) { | 1319 if (!settings_info) { |
| 1318 VLOG(1) << "Get printer capabilities failed"; | 1320 VLOG(1) << "Get printer capabilities failed"; |
| 1319 web_ui()->CallJavascriptFunction("failedToGetPrinterCapabilities", | 1321 web_ui()->CallJavascriptFunctionUnsafe("failedToGetPrinterCapabilities", |
| 1320 base::StringValue(printer_name)); | 1322 base::StringValue(printer_name)); |
| 1321 return; | 1323 return; |
| 1322 } | 1324 } |
| 1323 VLOG(1) << "Get printer capabilities finished"; | 1325 VLOG(1) << "Get printer capabilities finished"; |
| 1324 web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", | 1326 web_ui()->CallJavascriptFunctionUnsafe("updateWithPrinterCapabilities", |
| 1325 *settings_info); | 1327 *settings_info); |
| 1326 } | 1328 } |
| 1327 | 1329 |
| 1328 void PrintPreviewHandler::SetupPrinterList(const base::ListValue* printers) { | 1330 void PrintPreviewHandler::SetupPrinterList(const base::ListValue* printers) { |
| 1329 if (!has_logged_printers_count_) { | 1331 if (!has_logged_printers_count_) { |
| 1330 UMA_HISTOGRAM_COUNTS("PrintPreview.NumberOfPrinters", printers->GetSize()); | 1332 UMA_HISTOGRAM_COUNTS("PrintPreview.NumberOfPrinters", printers->GetSize()); |
| 1331 has_logged_printers_count_ = true; | 1333 has_logged_printers_count_ = true; |
| 1332 } | 1334 } |
| 1333 | 1335 |
| 1334 web_ui()->CallJavascriptFunction("setPrinters", *printers); | 1336 web_ui()->CallJavascriptFunctionUnsafe("setPrinters", *printers); |
| 1335 } | 1337 } |
| 1336 | 1338 |
| 1337 void PrintPreviewHandler::SendCloudPrintEnabled() { | 1339 void PrintPreviewHandler::SendCloudPrintEnabled() { |
| 1338 Profile* profile = Profile::FromBrowserContext( | 1340 Profile* profile = Profile::FromBrowserContext( |
| 1339 preview_web_contents()->GetBrowserContext()); | 1341 preview_web_contents()->GetBrowserContext()); |
| 1340 PrefService* prefs = profile->GetPrefs(); | 1342 PrefService* prefs = profile->GetPrefs(); |
| 1341 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { | 1343 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { |
| 1342 base::DictionaryValue settings; | 1344 base::DictionaryValue settings; |
| 1343 settings.SetString(kCloudPrintUrl, | 1345 settings.SetString(kCloudPrintUrl, |
| 1344 GURL(cloud_devices::GetCloudPrintURL()).spec()); | 1346 GURL(cloud_devices::GetCloudPrintURL()).spec()); |
| 1345 settings.SetBoolean(kAppKioskMode, chrome::IsRunningInForcedAppMode()); | 1347 settings.SetBoolean(kAppKioskMode, chrome::IsRunningInForcedAppMode()); |
| 1346 web_ui()->CallJavascriptFunction("setUseCloudPrint", settings); | 1348 web_ui()->CallJavascriptFunctionUnsafe("setUseCloudPrint", settings); |
| 1347 } | 1349 } |
| 1348 } | 1350 } |
| 1349 | 1351 |
| 1350 void PrintPreviewHandler::SendCloudPrintJob(const base::RefCountedBytes* data) { | 1352 void PrintPreviewHandler::SendCloudPrintJob(const base::RefCountedBytes* data) { |
| 1351 // BASE64 encode the job data. | 1353 // BASE64 encode the job data. |
| 1352 const base::StringPiece raw_data(reinterpret_cast<const char*>(data->front()), | 1354 const base::StringPiece raw_data(reinterpret_cast<const char*>(data->front()), |
| 1353 data->size()); | 1355 data->size()); |
| 1354 std::string base64_data; | 1356 std::string base64_data; |
| 1355 base::Base64Encode(raw_data, &base64_data); | 1357 base::Base64Encode(raw_data, &base64_data); |
| 1356 base::StringValue data_value(base64_data); | 1358 base::StringValue data_value(base64_data); |
| 1357 | 1359 |
| 1358 web_ui()->CallJavascriptFunction("printToCloud", data_value); | 1360 web_ui()->CallJavascriptFunctionUnsafe("printToCloud", data_value); |
| 1359 } | 1361 } |
| 1360 | 1362 |
| 1361 WebContents* PrintPreviewHandler::GetInitiator() const { | 1363 WebContents* PrintPreviewHandler::GetInitiator() const { |
| 1362 printing::PrintPreviewDialogController* dialog_controller = | 1364 printing::PrintPreviewDialogController* dialog_controller = |
| 1363 printing::PrintPreviewDialogController::GetInstance(); | 1365 printing::PrintPreviewDialogController::GetInstance(); |
| 1364 if (!dialog_controller) | 1366 if (!dialog_controller) |
| 1365 return NULL; | 1367 return NULL; |
| 1366 return dialog_controller->GetInitiator(preview_web_contents()); | 1368 return dialog_controller->GetInitiator(preview_web_contents()); |
| 1367 } | 1369 } |
| 1368 | 1370 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 #endif // ENABLE_BASIC_PRINTING | 1447 #endif // ENABLE_BASIC_PRINTING |
| 1446 | 1448 |
| 1447 void PrintPreviewHandler::FileSelected(const base::FilePath& path, | 1449 void PrintPreviewHandler::FileSelected(const base::FilePath& path, |
| 1448 int /* index */, | 1450 int /* index */, |
| 1449 void* /* params */) { | 1451 void* /* params */) { |
| 1450 // Updating |save_path_| to the newly selected folder. | 1452 // Updating |save_path_| to the newly selected folder. |
| 1451 printing::StickySettings* sticky_settings = GetStickySettings(); | 1453 printing::StickySettings* sticky_settings = GetStickySettings(); |
| 1452 sticky_settings->StoreSavePath(path.DirName()); | 1454 sticky_settings->StoreSavePath(path.DirName()); |
| 1453 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( | 1455 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( |
| 1454 preview_web_contents()->GetBrowserContext())->GetPrefs()); | 1456 preview_web_contents()->GetBrowserContext())->GetPrefs()); |
| 1455 web_ui()->CallJavascriptFunction("fileSelectionCompleted"); | 1457 web_ui()->CallJavascriptFunctionUnsafe("fileSelectionCompleted"); |
| 1456 print_to_pdf_path_ = path; | 1458 print_to_pdf_path_ = path; |
| 1457 PostPrintToPdfTask(); | 1459 PostPrintToPdfTask(); |
| 1458 } | 1460 } |
| 1459 | 1461 |
| 1460 void PrintPreviewHandler::PostPrintToPdfTask() { | 1462 void PrintPreviewHandler::PostPrintToPdfTask() { |
| 1461 scoped_refptr<base::RefCountedBytes> data; | 1463 scoped_refptr<base::RefCountedBytes> data; |
| 1462 base::string16 title; | 1464 base::string16 title; |
| 1463 if (!GetPreviewDataAndTitle(&data, &title)) { | 1465 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 1464 NOTREACHED() << "Preview data was checked before file dialog."; | 1466 NOTREACHED() << "Preview data was checked before file dialog."; |
| 1465 return; | 1467 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 *data = tmp_data; | 1510 *data = tmp_data; |
| 1509 *title = print_preview_ui()->initiator_title(); | 1511 *title = print_preview_ui()->initiator_title(); |
| 1510 return true; | 1512 return true; |
| 1511 } | 1513 } |
| 1512 | 1514 |
| 1513 #if defined(ENABLE_SERVICE_DISCOVERY) | 1515 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 1514 | 1516 |
| 1515 void PrintPreviewHandler::StartPrivetLister(const scoped_refptr< | 1517 void PrintPreviewHandler::StartPrivetLister(const scoped_refptr< |
| 1516 local_discovery::ServiceDiscoverySharedClient>& client) { | 1518 local_discovery::ServiceDiscoverySharedClient>& client) { |
| 1517 if (!PrivetPrintingEnabled()) | 1519 if (!PrivetPrintingEnabled()) |
| 1518 return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone"); | 1520 return web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterSearchDone"); |
| 1519 | 1521 |
| 1520 Profile* profile = Profile::FromWebUI(web_ui()); | 1522 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1521 DCHECK(!service_discovery_client_.get() || | 1523 DCHECK(!service_discovery_client_.get() || |
| 1522 service_discovery_client_.get() == client.get()); | 1524 service_discovery_client_.get() == client.get()); |
| 1523 service_discovery_client_ = client; | 1525 service_discovery_client_ = client; |
| 1524 printer_lister_.reset(new cloud_print::PrivetLocalPrinterLister( | 1526 printer_lister_.reset(new cloud_print::PrivetLocalPrinterLister( |
| 1525 service_discovery_client_.get(), profile->GetRequestContext(), this)); | 1527 service_discovery_client_.get(), profile->GetRequestContext(), this)); |
| 1526 printer_lister_->Start(); | 1528 printer_lister_->Start(); |
| 1527 } | 1529 } |
| 1528 | 1530 |
| 1529 void PrintPreviewHandler::LocalPrinterChanged( | 1531 void PrintPreviewHandler::LocalPrinterChanged( |
| 1530 bool added, | 1532 bool added, |
| 1531 const std::string& name, | 1533 const std::string& name, |
| 1532 bool has_local_printing, | 1534 bool has_local_printing, |
| 1533 const cloud_print::DeviceDescription& description) { | 1535 const cloud_print::DeviceDescription& description) { |
| 1534 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 1536 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1535 if (has_local_printing || | 1537 if (has_local_printing || |
| 1536 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { | 1538 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { |
| 1537 base::DictionaryValue info; | 1539 base::DictionaryValue info; |
| 1538 FillPrinterDescription(name, description, has_local_printing, &info); | 1540 FillPrinterDescription(name, description, has_local_printing, &info); |
| 1539 web_ui()->CallJavascriptFunction("onPrivetPrinterChanged", info); | 1541 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrinterChanged", info); |
| 1540 } | 1542 } |
| 1541 } | 1543 } |
| 1542 | 1544 |
| 1543 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { | 1545 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { |
| 1544 } | 1546 } |
| 1545 | 1547 |
| 1546 void PrintPreviewHandler::LocalPrinterCacheFlushed() { | 1548 void PrintPreviewHandler::LocalPrinterCacheFlushed() { |
| 1547 } | 1549 } |
| 1548 | 1550 |
| 1549 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( | 1551 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 privet_http_client_->CreateLocalPrintOperation(this); | 1596 privet_http_client_->CreateLocalPrintOperation(this); |
| 1595 | 1597 |
| 1596 privet_local_print_operation_->SetTicket(print_ticket); | 1598 privet_local_print_operation_->SetTicket(print_ticket); |
| 1597 privet_local_print_operation_->SetCapabilities(capabilities); | 1599 privet_local_print_operation_->SetCapabilities(capabilities); |
| 1598 | 1600 |
| 1599 scoped_refptr<base::RefCountedBytes> data; | 1601 scoped_refptr<base::RefCountedBytes> data; |
| 1600 base::string16 title; | 1602 base::string16 title; |
| 1601 | 1603 |
| 1602 if (!GetPreviewDataAndTitle(&data, &title)) { | 1604 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 1603 base::FundamentalValue http_code_value(-1); | 1605 base::FundamentalValue http_code_value(-1); |
| 1604 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 1606 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", |
| 1607 http_code_value); |
| 1605 return; | 1608 return; |
| 1606 } | 1609 } |
| 1607 | 1610 |
| 1608 privet_local_print_operation_->SetJobname(base::UTF16ToUTF8(title)); | 1611 privet_local_print_operation_->SetJobname(base::UTF16ToUTF8(title)); |
| 1609 privet_local_print_operation_->SetPageSize(page_size); | 1612 privet_local_print_operation_->SetPageSize(page_size); |
| 1610 privet_local_print_operation_->SetData(data.get()); | 1613 privet_local_print_operation_->SetData(data.get()); |
| 1611 | 1614 |
| 1612 Profile* profile = Profile::FromWebUI(web_ui()); | 1615 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1613 SigninManagerBase* signin_manager = | 1616 SigninManagerBase* signin_manager = |
| 1614 SigninManagerFactory::GetForProfileIfExists(profile); | 1617 SigninManagerFactory::GetForProfileIfExists(profile); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1636 const cloud_print::DeviceDescription* description = | 1639 const cloud_print::DeviceDescription* description = |
| 1637 printer_lister_->GetDeviceDescription(name); | 1640 printer_lister_->GetDeviceDescription(name); |
| 1638 | 1641 |
| 1639 if (!description) { | 1642 if (!description) { |
| 1640 SendPrivetCapabilitiesError(name); | 1643 SendPrivetCapabilitiesError(name); |
| 1641 return; | 1644 return; |
| 1642 } | 1645 } |
| 1643 | 1646 |
| 1644 FillPrinterDescription(name, *description, true, &printer_info); | 1647 FillPrinterDescription(name, *description, true, &printer_info); |
| 1645 | 1648 |
| 1646 web_ui()->CallJavascriptFunction( | 1649 web_ui()->CallJavascriptFunctionUnsafe("onPrivetCapabilitiesSet", |
| 1647 "onPrivetCapabilitiesSet", | 1650 printer_info, *capabilities); |
| 1648 printer_info, | |
| 1649 *capabilities); | |
| 1650 | 1651 |
| 1651 privet_capabilities_operation_.reset(); | 1652 privet_capabilities_operation_.reset(); |
| 1652 } | 1653 } |
| 1653 | 1654 |
| 1654 void PrintPreviewHandler::SendPrivetCapabilitiesError( | 1655 void PrintPreviewHandler::SendPrivetCapabilitiesError( |
| 1655 const std::string& device_name) { | 1656 const std::string& device_name) { |
| 1656 base::StringValue name_value(device_name); | 1657 base::StringValue name_value(device_name); |
| 1657 web_ui()->CallJavascriptFunction( | 1658 web_ui()->CallJavascriptFunctionUnsafe("failedToGetPrivetPrinterCapabilities", |
| 1658 "failedToGetPrivetPrinterCapabilities", | 1659 name_value); |
| 1659 name_value); | |
| 1660 } | 1660 } |
| 1661 | 1661 |
| 1662 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, | 1662 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, |
| 1663 const std::string& ticket, | 1663 const std::string& ticket, |
| 1664 const std::string& capabilities, | 1664 const std::string& capabilities, |
| 1665 const gfx::Size& page_size) { | 1665 const gfx::Size& page_size) { |
| 1666 CreatePrivetHTTP( | 1666 CreatePrivetHTTP( |
| 1667 device_name, | 1667 device_name, |
| 1668 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, | 1668 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, |
| 1669 base::Unretained(this), | 1669 base::Unretained(this), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1695 | 1695 |
| 1696 void PrintPreviewHandler::OnPrivetPrintingDone( | 1696 void PrintPreviewHandler::OnPrivetPrintingDone( |
| 1697 const cloud_print::PrivetLocalPrintOperation* print_operation) { | 1697 const cloud_print::PrivetLocalPrintOperation* print_operation) { |
| 1698 ClosePreviewDialog(); | 1698 ClosePreviewDialog(); |
| 1699 } | 1699 } |
| 1700 | 1700 |
| 1701 void PrintPreviewHandler::OnPrivetPrintingError( | 1701 void PrintPreviewHandler::OnPrivetPrintingError( |
| 1702 const cloud_print::PrivetLocalPrintOperation* print_operation, | 1702 const cloud_print::PrivetLocalPrintOperation* print_operation, |
| 1703 int http_code) { | 1703 int http_code) { |
| 1704 base::FundamentalValue http_code_value(http_code); | 1704 base::FundamentalValue http_code_value(http_code); |
| 1705 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 1705 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", |
| 1706 http_code_value); |
| 1706 } | 1707 } |
| 1707 | 1708 |
| 1708 void PrintPreviewHandler::FillPrinterDescription( | 1709 void PrintPreviewHandler::FillPrinterDescription( |
| 1709 const std::string& name, | 1710 const std::string& name, |
| 1710 const cloud_print::DeviceDescription& description, | 1711 const cloud_print::DeviceDescription& description, |
| 1711 bool has_local_printing, | 1712 bool has_local_printing, |
| 1712 base::DictionaryValue* printer_value) { | 1713 base::DictionaryValue* printer_value) { |
| 1713 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 1714 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1714 | 1715 |
| 1715 printer_value->SetString("serviceName", name); | 1716 printer_value->SetString("serviceName", name); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1728 if (extension_printer_handler_) | 1729 if (extension_printer_handler_) |
| 1729 return; | 1730 return; |
| 1730 | 1731 |
| 1731 extension_printer_handler_ = | 1732 extension_printer_handler_ = |
| 1732 PrinterHandler::CreateForExtensionPrinters(Profile::FromWebUI(web_ui())); | 1733 PrinterHandler::CreateForExtensionPrinters(Profile::FromWebUI(web_ui())); |
| 1733 } | 1734 } |
| 1734 | 1735 |
| 1735 void PrintPreviewHandler::OnGotPrintersForExtension( | 1736 void PrintPreviewHandler::OnGotPrintersForExtension( |
| 1736 const base::ListValue& printers, | 1737 const base::ListValue& printers, |
| 1737 bool done) { | 1738 bool done) { |
| 1738 web_ui()->CallJavascriptFunction("onExtensionPrintersAdded", printers, | 1739 web_ui()->CallJavascriptFunctionUnsafe("onExtensionPrintersAdded", printers, |
| 1739 base::FundamentalValue(done)); | 1740 base::FundamentalValue(done)); |
| 1740 } | 1741 } |
| 1741 | 1742 |
| 1742 void PrintPreviewHandler::OnGotExtensionPrinterInfo( | 1743 void PrintPreviewHandler::OnGotExtensionPrinterInfo( |
| 1743 const std::string& printer_id, | 1744 const std::string& printer_id, |
| 1744 const base::DictionaryValue& printer_info) { | 1745 const base::DictionaryValue& printer_info) { |
| 1745 if (printer_info.empty()) { | 1746 if (printer_info.empty()) { |
| 1746 web_ui()->CallJavascriptFunction("failedToResolveProvisionalPrinter", | 1747 web_ui()->CallJavascriptFunctionUnsafe("failedToResolveProvisionalPrinter", |
| 1747 base::StringValue(printer_id)); | 1748 base::StringValue(printer_id)); |
| 1748 return; | 1749 return; |
| 1749 } | 1750 } |
| 1750 | 1751 |
| 1751 web_ui()->CallJavascriptFunction("onProvisionalPrinterResolved", | 1752 web_ui()->CallJavascriptFunctionUnsafe("onProvisionalPrinterResolved", |
| 1752 base::StringValue(printer_id), | 1753 base::StringValue(printer_id), |
| 1753 printer_info); | 1754 printer_info); |
| 1754 } | 1755 } |
| 1755 | 1756 |
| 1756 void PrintPreviewHandler::OnGotExtensionPrinterCapabilities( | 1757 void PrintPreviewHandler::OnGotExtensionPrinterCapabilities( |
| 1757 const std::string& printer_id, | 1758 const std::string& printer_id, |
| 1758 const base::DictionaryValue& capabilities) { | 1759 const base::DictionaryValue& capabilities) { |
| 1759 if (capabilities.empty()) { | 1760 if (capabilities.empty()) { |
| 1760 web_ui()->CallJavascriptFunction("failedToGetExtensionPrinterCapabilities", | 1761 web_ui()->CallJavascriptFunctionUnsafe( |
| 1761 base::StringValue(printer_id)); | 1762 "failedToGetExtensionPrinterCapabilities", |
| 1763 base::StringValue(printer_id)); |
| 1762 return; | 1764 return; |
| 1763 } | 1765 } |
| 1764 | 1766 |
| 1765 web_ui()->CallJavascriptFunction("onExtensionCapabilitiesSet", | 1767 web_ui()->CallJavascriptFunctionUnsafe("onExtensionCapabilitiesSet", |
| 1766 base::StringValue(printer_id), capabilities); | 1768 base::StringValue(printer_id), |
| 1769 capabilities); |
| 1767 } | 1770 } |
| 1768 | 1771 |
| 1769 void PrintPreviewHandler::OnExtensionPrintResult(bool success, | 1772 void PrintPreviewHandler::OnExtensionPrintResult(bool success, |
| 1770 const std::string& status) { | 1773 const std::string& status) { |
| 1771 if (success) { | 1774 if (success) { |
| 1772 ClosePreviewDialog(); | 1775 ClosePreviewDialog(); |
| 1773 return; | 1776 return; |
| 1774 } | 1777 } |
| 1775 | 1778 |
| 1776 // TODO(tbarzic): This function works for extension printers case too, but it | 1779 // TODO(tbarzic): This function works for extension printers case too, but it |
| 1777 // should be renamed to something more generic. | 1780 // should be renamed to something more generic. |
| 1778 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", | 1781 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", |
| 1779 base::StringValue(status)); | 1782 base::StringValue(status)); |
| 1780 } | 1783 } |
| 1781 | 1784 |
| 1782 void PrintPreviewHandler::RegisterForGaiaCookieChanges() { | 1785 void PrintPreviewHandler::RegisterForGaiaCookieChanges() { |
| 1783 DCHECK(!gaia_cookie_manager_service_); | 1786 DCHECK(!gaia_cookie_manager_service_); |
| 1784 Profile* profile = Profile::FromWebUI(web_ui()); | 1787 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1785 if (switches::IsEnableAccountConsistency() && !profile->IsOffTheRecord()) { | 1788 if (switches::IsEnableAccountConsistency() && !profile->IsOffTheRecord()) { |
| 1786 gaia_cookie_manager_service_ = | 1789 gaia_cookie_manager_service_ = |
| 1787 GaiaCookieManagerServiceFactory::GetForProfile(profile); | 1790 GaiaCookieManagerServiceFactory::GetForProfile(profile); |
| 1788 if (gaia_cookie_manager_service_) | 1791 if (gaia_cookie_manager_service_) |
| 1789 gaia_cookie_manager_service_->AddObserver(this); | 1792 gaia_cookie_manager_service_->AddObserver(this); |
| 1790 } | 1793 } |
| 1791 } | 1794 } |
| 1792 | 1795 |
| 1793 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1796 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1794 if (gaia_cookie_manager_service_) | 1797 if (gaia_cookie_manager_service_) |
| 1795 gaia_cookie_manager_service_->RemoveObserver(this); | 1798 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1796 } | 1799 } |
| 1797 | 1800 |
| 1798 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1801 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1799 const base::Closure& closure) { | 1802 const base::Closure& closure) { |
| 1800 pdf_file_saved_closure_ = closure; | 1803 pdf_file_saved_closure_ = closure; |
| 1801 } | 1804 } |
| OLD | NEW |