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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 } | 675 } |
676 | 676 |
677 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { | 677 void PrintPreviewHandler::HandleGetPrivetPrinters(const base::ListValue* args) { |
678 std::string callback_id; | 678 std::string callback_id; |
679 CHECK(args->GetString(0, &callback_id)); | 679 CHECK(args->GetString(0, &callback_id)); |
680 CHECK(!callback_id.empty()); | 680 CHECK(!callback_id.empty()); |
681 | 681 |
682 AllowJavascript(); | 682 AllowJavascript(); |
683 | 683 |
684 if (!PrivetPrintingEnabled()) { | 684 if (!PrivetPrintingEnabled()) { |
685 RejectJavascriptCallback(base::Value(callback_id), base::Value(false)); | 685 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
686 } | 686 } |
687 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) | 687 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
688 using local_discovery::ServiceDiscoverySharedClient; | 688 using local_discovery::ServiceDiscoverySharedClient; |
689 scoped_refptr<ServiceDiscoverySharedClient> service_discovery = | 689 scoped_refptr<ServiceDiscoverySharedClient> service_discovery = |
690 ServiceDiscoverySharedClient::GetInstance(); | 690 ServiceDiscoverySharedClient::GetInstance(); |
691 DCHECK(privet_callback_id_.empty()); | 691 DCHECK(privet_callback_id_.empty()); |
692 privet_callback_id_ = callback_id; | 692 privet_callback_id_ = callback_id; |
693 StartPrivetLister(service_discovery); | 693 StartPrivetLister(service_discovery); |
694 #endif | 694 #endif |
695 } | 695 } |
696 | 696 |
697 void PrintPreviewHandler::StopPrivetLister() { | 697 void PrintPreviewHandler::StopPrivetLister() { |
698 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) | 698 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
699 privet_lister_timer_.reset(); | 699 privet_lister_timer_.reset(); |
700 if (PrivetPrintingEnabled() && printer_lister_) { | 700 if (PrivetPrintingEnabled() && printer_lister_) { |
701 printer_lister_->Stop(); | 701 printer_lister_->Stop(); |
702 } | 702 } |
703 ResolveJavascriptCallback(base::Value(privet_callback_id_), base::Value()); | 703 ResolveJavascriptCallback(base::Value(privet_callback_id_), base::Value()); |
| 704 privet_callback_id_ = ""; |
704 #endif | 705 #endif |
705 } | 706 } |
706 | 707 |
707 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( | 708 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( |
708 const base::ListValue* args) { | 709 const base::ListValue* args) { |
| 710 AllowJavascript(); |
| 711 |
| 712 std::string callback_id; |
| 713 std::string printer_name; |
| 714 if (!args->GetString(0, &callback_id) || !args->GetString(1, &printer_name) || |
| 715 callback_id.empty() || printer_name.empty()) { |
| 716 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
| 717 return; |
| 718 } |
709 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) | 719 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
710 std::string name; | 720 if (CreatePrivetHTTP( |
711 bool success = args->GetString(0, &name); | 721 printer_name, |
712 DCHECK(success); | 722 base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient, |
713 | 723 weak_factory_.GetWeakPtr(), callback_id))) { |
714 CreatePrivetHTTP( | 724 return; |
715 name, base::Bind(&PrintPreviewHandler::PrivetCapabilitiesUpdateClient, | 725 } |
716 weak_factory_.GetWeakPtr())); | |
717 #endif | 726 #endif |
| 727 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
718 } | 728 } |
719 | 729 |
720 void PrintPreviewHandler::HandleGetExtensionPrinters( | 730 void PrintPreviewHandler::HandleGetExtensionPrinters( |
721 const base::ListValue* args) { | 731 const base::ListValue* args) { |
722 std::string callback_id; | 732 std::string callback_id; |
723 CHECK(args->GetString(0, &callback_id)); | 733 CHECK(args->GetString(0, &callback_id)); |
724 CHECK(!callback_id.empty()); | 734 CHECK(!callback_id.empty()); |
725 | 735 |
726 AllowJavascript(); | 736 AllowJavascript(); |
727 EnsureExtensionPrinterHandlerSet(); | 737 EnsureExtensionPrinterHandlerSet(); |
(...skipping 12 matching lines...) Expand all Loading... |
740 DCHECK(ok); | 750 DCHECK(ok); |
741 | 751 |
742 EnsureExtensionPrinterHandlerSet(); | 752 EnsureExtensionPrinterHandlerSet(); |
743 extension_printer_handler_->StartGrantPrinterAccess( | 753 extension_printer_handler_->StartGrantPrinterAccess( |
744 printer_id, base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterInfo, | 754 printer_id, base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterInfo, |
745 weak_factory_.GetWeakPtr(), printer_id)); | 755 weak_factory_.GetWeakPtr(), printer_id)); |
746 } | 756 } |
747 | 757 |
748 void PrintPreviewHandler::HandleGetExtensionPrinterCapabilities( | 758 void PrintPreviewHandler::HandleGetExtensionPrinterCapabilities( |
749 const base::ListValue* args) { | 759 const base::ListValue* args) { |
750 std::string printer_id; | 760 AllowJavascript(); |
751 bool ok = args->GetString(0, &printer_id); | 761 |
752 DCHECK(ok); | 762 std::string callback_id; |
| 763 std::string printer_name; |
| 764 if (!args->GetString(0, &callback_id) || !args->GetString(1, &printer_name) || |
| 765 callback_id.empty() || printer_name.empty()) { |
| 766 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
| 767 return; |
| 768 } |
753 | 769 |
754 EnsureExtensionPrinterHandlerSet(); | 770 EnsureExtensionPrinterHandlerSet(); |
755 extension_printer_handler_->StartGetCapability( | 771 extension_printer_handler_->StartGetCapability( |
756 printer_id, | 772 printer_name, |
757 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, | 773 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, |
758 weak_factory_.GetWeakPtr())); | 774 weak_factory_.GetWeakPtr(), callback_id)); |
759 } | 775 } |
760 | 776 |
761 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { | 777 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { |
762 DCHECK_EQ(2U, args->GetSize()); | 778 DCHECK_EQ(2U, args->GetSize()); |
763 std::unique_ptr<base::DictionaryValue> settings = GetSettingsDictionary(args); | 779 std::unique_ptr<base::DictionaryValue> settings = GetSettingsDictionary(args); |
764 if (!settings) | 780 if (!settings) |
765 return; | 781 return; |
766 int request_id = -1; | 782 int request_id = -1; |
767 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 783 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) |
768 return; | 784 return; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 std::string data_to_save; | 1080 std::string data_to_save; |
1065 printing::StickySettings* sticky_settings = GetStickySettings(); | 1081 printing::StickySettings* sticky_settings = GetStickySettings(); |
1066 if (args->GetString(0, &data_to_save) && !data_to_save.empty()) | 1082 if (args->GetString(0, &data_to_save) && !data_to_save.empty()) |
1067 sticky_settings->StoreAppState(data_to_save); | 1083 sticky_settings->StoreAppState(data_to_save); |
1068 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( | 1084 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( |
1069 preview_web_contents()->GetBrowserContext())->GetPrefs()); | 1085 preview_web_contents()->GetBrowserContext())->GetPrefs()); |
1070 } | 1086 } |
1071 | 1087 |
1072 void PrintPreviewHandler::HandleGetPrinterCapabilities( | 1088 void PrintPreviewHandler::HandleGetPrinterCapabilities( |
1073 const base::ListValue* args) { | 1089 const base::ListValue* args) { |
| 1090 AllowJavascript(); |
| 1091 |
| 1092 std::string callback_id; |
1074 std::string printer_name; | 1093 std::string printer_name; |
1075 bool ret = args->GetString(0, &printer_name); | 1094 if (!args->GetString(0, &callback_id) || !args->GetString(1, &printer_name) || |
1076 if (!ret || printer_name.empty()) | 1095 callback_id.empty() || printer_name.empty()) { |
| 1096 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
1077 return; | 1097 return; |
| 1098 } |
1078 | 1099 |
1079 if (printer_name == kLocalPdfPrinterId) { | 1100 if (printer_name == kLocalPdfPrinterId) { |
1080 auto printer_info = base::MakeUnique<base::DictionaryValue>(); | 1101 auto printer_info = base::MakeUnique<base::DictionaryValue>(); |
1081 printer_info->SetString(printing::kPrinterId, printer_name); | 1102 printer_info->SetString(printing::kPrinterId, printer_name); |
1082 printer_info->Set( | 1103 printer_info->Set( |
1083 printing::kPrinterCapabilities, | 1104 printing::kPrinterCapabilities, |
1084 GetPdfCapabilities(g_browser_process->GetApplicationLocale())); | 1105 GetPdfCapabilities(g_browser_process->GetApplicationLocale())); |
1085 SendPrinterCapabilities(printer_name, std::move(printer_info)); | 1106 SendPrinterCapabilities(callback_id, printer_name, std::move(printer_info)); |
1086 return; | 1107 return; |
1087 } | 1108 } |
1088 | 1109 |
1089 printing::PrinterSetupCallback cb = | 1110 printing::PrinterSetupCallback cb = |
1090 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities, | 1111 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities, |
1091 weak_factory_.GetWeakPtr(), printer_name); | 1112 weak_factory_.GetWeakPtr(), callback_id, printer_name); |
1092 | 1113 |
1093 printer_backend_proxy()->ConfigurePrinterAndFetchCapabilities(printer_name, | 1114 printer_backend_proxy()->ConfigurePrinterAndFetchCapabilities(printer_name, |
1094 cb); | 1115 cb); |
1095 } | 1116 } |
1096 | 1117 |
1097 // |args| is expected to contain a string with representing the callback id | 1118 // |args| is expected to contain a string with representing the callback id |
1098 // followed by a list of arguments the first of which should be the printer id. | 1119 // followed by a list of arguments the first of which should be the printer id. |
1099 void PrintPreviewHandler::HandlePrinterSetup(const base::ListValue* args) { | 1120 void PrintPreviewHandler::HandlePrinterSetup(const base::ListValue* args) { |
1100 AllowJavascript(); | 1121 AllowJavascript(); |
1101 | 1122 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 } | 1321 } |
1301 | 1322 |
1302 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1323 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
1303 const std::string& access_token) { | 1324 const std::string& access_token) { |
1304 VLOG(1) << "Get getAccessToken finished"; | 1325 VLOG(1) << "Get getAccessToken finished"; |
1305 web_ui()->CallJavascriptFunctionUnsafe( | 1326 web_ui()->CallJavascriptFunctionUnsafe( |
1306 "onDidGetAccessToken", base::Value(type), base::Value(access_token)); | 1327 "onDidGetAccessToken", base::Value(type), base::Value(access_token)); |
1307 } | 1328 } |
1308 | 1329 |
1309 void PrintPreviewHandler::SendPrinterCapabilities( | 1330 void PrintPreviewHandler::SendPrinterCapabilities( |
| 1331 const std::string& callback_id, |
1310 const std::string& printer_name, | 1332 const std::string& printer_name, |
1311 std::unique_ptr<base::DictionaryValue> settings_info) { | 1333 std::unique_ptr<base::DictionaryValue> settings_info) { |
1312 // Check that |settings_info| is valid. | 1334 // Check that |settings_info| is valid. |
1313 if (settings_info && settings_info->Get("capabilities", nullptr)) { | 1335 if (settings_info && settings_info->Get("capabilities", nullptr)) { |
1314 VLOG(1) << "Get printer capabilities finished"; | 1336 VLOG(1) << "Get printer capabilities finished"; |
1315 web_ui()->CallJavascriptFunctionUnsafe("updateWithPrinterCapabilities", | 1337 ResolveJavascriptCallback(base::Value(callback_id), *settings_info); |
1316 *settings_info); | |
1317 return; | 1338 return; |
1318 } | 1339 } |
1319 | 1340 |
1320 VLOG(1) << "Get printer capabilities failed"; | 1341 VLOG(1) << "Get printer capabilities failed"; |
1321 web_ui()->CallJavascriptFunctionUnsafe("failedToGetPrinterCapabilities", | 1342 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
1322 base::Value(printer_name)); | |
1323 } | 1343 } |
1324 | 1344 |
1325 void PrintPreviewHandler::SendPrinterSetup( | 1345 void PrintPreviewHandler::SendPrinterSetup( |
1326 const std::string& callback_id, | 1346 const std::string& callback_id, |
1327 const std::string& printer_name, | 1347 const std::string& printer_name, |
1328 std::unique_ptr<base::DictionaryValue> destination_info) { | 1348 std::unique_ptr<base::DictionaryValue> destination_info) { |
1329 auto response = base::MakeUnique<base::DictionaryValue>(); | 1349 auto response = base::MakeUnique<base::DictionaryValue>(); |
1330 bool success = true; | 1350 bool success = true; |
1331 auto caps_value = base::MakeUnique<base::Value>(); | 1351 auto caps_value = base::MakeUnique<base::Value>(); |
1332 auto caps = base::MakeUnique<base::DictionaryValue>(); | 1352 auto caps = base::MakeUnique<base::DictionaryValue>(); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 } | 1583 } |
1564 } | 1584 } |
1565 | 1585 |
1566 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { | 1586 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { |
1567 } | 1587 } |
1568 | 1588 |
1569 void PrintPreviewHandler::LocalPrinterCacheFlushed() { | 1589 void PrintPreviewHandler::LocalPrinterCacheFlushed() { |
1570 } | 1590 } |
1571 | 1591 |
1572 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( | 1592 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( |
| 1593 const std::string& callback_id, |
1573 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { | 1594 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
1574 if (!PrivetUpdateClient(std::move(http_client))) | 1595 if (!PrivetUpdateClient(callback_id, std::move(http_client))) |
1575 return; | 1596 return; |
1576 | 1597 |
1577 privet_capabilities_operation_ = | 1598 privet_capabilities_operation_ = |
1578 privet_http_client_->CreateCapabilitiesOperation( | 1599 privet_http_client_->CreateCapabilitiesOperation( |
1579 base::Bind(&PrintPreviewHandler::OnPrivetCapabilities, | 1600 base::Bind(&PrintPreviewHandler::OnPrivetCapabilities, |
1580 weak_factory_.GetWeakPtr())); | 1601 weak_factory_.GetWeakPtr(), callback_id)); |
1581 privet_capabilities_operation_->Start(); | 1602 privet_capabilities_operation_->Start(); |
1582 } | 1603 } |
1583 | 1604 |
1584 bool PrintPreviewHandler::PrivetUpdateClient( | 1605 bool PrintPreviewHandler::PrivetUpdateClient( |
| 1606 const std::string& callback_id, |
1585 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { | 1607 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
1586 if (!http_client) { | 1608 if (!http_client) { |
1587 SendPrivetCapabilitiesError(privet_http_resolution_->GetName()); | 1609 if (callback_id.empty()) { |
| 1610 // This was an attempt to print to a privet printer and has failed. |
| 1611 base::Value http_code_value(-1); |
| 1612 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", |
| 1613 http_code_value); |
| 1614 } else { // Capabilities update failed |
| 1615 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
| 1616 } |
1588 privet_http_resolution_.reset(); | 1617 privet_http_resolution_.reset(); |
1589 return false; | 1618 return false; |
1590 } | 1619 } |
1591 | 1620 |
1592 privet_local_print_operation_.reset(); | 1621 privet_local_print_operation_.reset(); |
1593 privet_capabilities_operation_.reset(); | 1622 privet_capabilities_operation_.reset(); |
1594 privet_http_client_ = cloud_print::PrivetV1HTTPClient::CreateDefault( | 1623 privet_http_client_ = cloud_print::PrivetV1HTTPClient::CreateDefault( |
1595 std::move(http_client)); | 1624 std::move(http_client)); |
1596 | 1625 |
1597 privet_http_resolution_.reset(); | 1626 privet_http_resolution_.reset(); |
1598 | 1627 |
1599 return true; | 1628 return true; |
1600 } | 1629 } |
1601 | 1630 |
1602 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( | 1631 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( |
1603 std::string print_ticket, | 1632 std::string print_ticket, |
1604 std::string capabilities, | 1633 std::string capabilities, |
1605 gfx::Size page_size, | 1634 gfx::Size page_size, |
1606 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { | 1635 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
1607 if (!PrivetUpdateClient(std::move(http_client))) | 1636 if (!PrivetUpdateClient("", std::move(http_client))) |
1608 return; | 1637 return; |
1609 | 1638 |
1610 StartPrivetLocalPrint(print_ticket, capabilities, page_size); | 1639 StartPrivetLocalPrint(print_ticket, capabilities, page_size); |
1611 } | 1640 } |
1612 | 1641 |
1613 void PrintPreviewHandler::StartPrivetLocalPrint(const std::string& print_ticket, | 1642 void PrintPreviewHandler::StartPrivetLocalPrint(const std::string& print_ticket, |
1614 const std::string& capabilities, | 1643 const std::string& capabilities, |
1615 const gfx::Size& page_size) { | 1644 const gfx::Size& page_size) { |
1616 privet_local_print_operation_ = | 1645 privet_local_print_operation_ = |
1617 privet_http_client_->CreateLocalPrintOperation(this); | 1646 privet_http_client_->CreateLocalPrintOperation(this); |
(...skipping 20 matching lines...) Expand all Loading... |
1638 SigninManagerFactory::GetForProfileIfExists(profile); | 1667 SigninManagerFactory::GetForProfileIfExists(profile); |
1639 | 1668 |
1640 if (signin_manager) { | 1669 if (signin_manager) { |
1641 privet_local_print_operation_->SetUsername( | 1670 privet_local_print_operation_->SetUsername( |
1642 signin_manager->GetAuthenticatedAccountInfo().email); | 1671 signin_manager->GetAuthenticatedAccountInfo().email); |
1643 } | 1672 } |
1644 | 1673 |
1645 privet_local_print_operation_->Start(); | 1674 privet_local_print_operation_->Start(); |
1646 } | 1675 } |
1647 | 1676 |
1648 | |
1649 void PrintPreviewHandler::OnPrivetCapabilities( | 1677 void PrintPreviewHandler::OnPrivetCapabilities( |
| 1678 const std::string& callback_id, |
1650 const base::DictionaryValue* capabilities) { | 1679 const base::DictionaryValue* capabilities) { |
1651 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName(); | 1680 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName(); |
1652 | 1681 |
1653 if (!capabilities || capabilities->HasKey(cloud_print::kPrivetKeyError) || | 1682 if (!capabilities || capabilities->HasKey(cloud_print::kPrivetKeyError) || |
1654 !printer_lister_) { | 1683 !printer_lister_) { |
1655 SendPrivetCapabilitiesError(name); | 1684 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
1656 return; | 1685 return; |
1657 } | 1686 } |
1658 | 1687 |
1659 base::DictionaryValue printer_info; | |
1660 const cloud_print::DeviceDescription* description = | 1688 const cloud_print::DeviceDescription* description = |
1661 printer_lister_->GetDeviceDescription(name); | 1689 printer_lister_->GetDeviceDescription(name); |
1662 | 1690 |
1663 if (!description) { | 1691 if (!description) { |
1664 SendPrivetCapabilitiesError(name); | 1692 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
1665 return; | 1693 return; |
1666 } | 1694 } |
1667 | 1695 |
1668 FillPrinterDescription(name, *description, true, &printer_info); | 1696 std::unique_ptr<base::DictionaryValue> printer_info = |
1669 | 1697 base::MakeUnique<base::DictionaryValue>(); |
1670 web_ui()->CallJavascriptFunctionUnsafe("onPrivetCapabilitiesSet", | 1698 FillPrinterDescription(name, *description, true, printer_info.get()); |
1671 printer_info, *capabilities); | 1699 base::DictionaryValue printer_info_and_caps; |
| 1700 printer_info_and_caps.SetDictionary("printer", std::move(printer_info)); |
| 1701 std::unique_ptr<base::DictionaryValue> capabilities_copy = |
| 1702 capabilities->CreateDeepCopy(); |
| 1703 printer_info_and_caps.SetDictionary("capabilities", |
| 1704 std::move(capabilities_copy)); |
| 1705 ResolveJavascriptCallback(base::Value(callback_id), printer_info_and_caps); |
1672 | 1706 |
1673 privet_capabilities_operation_.reset(); | 1707 privet_capabilities_operation_.reset(); |
1674 } | 1708 } |
1675 | 1709 |
1676 void PrintPreviewHandler::SendPrivetCapabilitiesError( | |
1677 const std::string& device_name) { | |
1678 base::Value name_value(device_name); | |
1679 web_ui()->CallJavascriptFunctionUnsafe("failedToGetPrivetPrinterCapabilities", | |
1680 name_value); | |
1681 } | |
1682 | |
1683 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, | 1710 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, |
1684 const std::string& ticket, | 1711 const std::string& ticket, |
1685 const std::string& capabilities, | 1712 const std::string& capabilities, |
1686 const gfx::Size& page_size) { | 1713 const gfx::Size& page_size) { |
1687 CreatePrivetHTTP( | 1714 if (!CreatePrivetHTTP( |
1688 device_name, | 1715 device_name, |
1689 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, | 1716 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, |
1690 weak_factory_.GetWeakPtr(), ticket, capabilities, page_size)); | 1717 weak_factory_.GetWeakPtr(), ticket, capabilities, |
| 1718 page_size))) { |
| 1719 base::Value http_code_value(-1); |
| 1720 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", |
| 1721 http_code_value); |
| 1722 } |
1691 } | 1723 } |
1692 | 1724 |
1693 bool PrintPreviewHandler::CreatePrivetHTTP( | 1725 bool PrintPreviewHandler::CreatePrivetHTTP( |
1694 const std::string& name, | 1726 const std::string& name, |
1695 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& | 1727 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& |
1696 callback) { | 1728 callback) { |
1697 const cloud_print::DeviceDescription* device_description = | 1729 const cloud_print::DeviceDescription* device_description = |
1698 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; | 1730 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; |
1699 | 1731 |
1700 if (!device_description) { | 1732 if (!device_description) |
1701 SendPrivetCapabilitiesError(name); | |
1702 return false; | 1733 return false; |
1703 } | |
1704 | 1734 |
1705 privet_http_factory_ = | 1735 privet_http_factory_ = |
1706 cloud_print::PrivetHTTPAsynchronousFactory::CreateInstance( | 1736 cloud_print::PrivetHTTPAsynchronousFactory::CreateInstance( |
1707 Profile::FromWebUI(web_ui())->GetRequestContext()); | 1737 Profile::FromWebUI(web_ui())->GetRequestContext()); |
1708 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP(name); | 1738 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP(name); |
1709 privet_http_resolution_->Start(device_description->address, callback); | 1739 privet_http_resolution_->Start(device_description->address, callback); |
1710 | 1740 |
1711 return true; | 1741 return true; |
1712 } | 1742 } |
1713 | 1743 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 web_ui()->CallJavascriptFunctionUnsafe("failedToResolveProvisionalPrinter", | 1799 web_ui()->CallJavascriptFunctionUnsafe("failedToResolveProvisionalPrinter", |
1770 base::Value(printer_id)); | 1800 base::Value(printer_id)); |
1771 return; | 1801 return; |
1772 } | 1802 } |
1773 | 1803 |
1774 web_ui()->CallJavascriptFunctionUnsafe("onProvisionalPrinterResolved", | 1804 web_ui()->CallJavascriptFunctionUnsafe("onProvisionalPrinterResolved", |
1775 base::Value(printer_id), printer_info); | 1805 base::Value(printer_id), printer_info); |
1776 } | 1806 } |
1777 | 1807 |
1778 void PrintPreviewHandler::OnGotExtensionPrinterCapabilities( | 1808 void PrintPreviewHandler::OnGotExtensionPrinterCapabilities( |
1779 const std::string& printer_id, | 1809 const std::string& callback_id, |
1780 const base::DictionaryValue& capabilities) { | 1810 const base::DictionaryValue& capabilities) { |
1781 if (capabilities.empty()) { | 1811 if (capabilities.empty()) { |
1782 web_ui()->CallJavascriptFunctionUnsafe( | 1812 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
1783 "failedToGetExtensionPrinterCapabilities", base::Value(printer_id)); | |
1784 return; | 1813 return; |
1785 } | 1814 } |
1786 | 1815 ResolveJavascriptCallback(base::Value(callback_id), capabilities); |
1787 web_ui()->CallJavascriptFunctionUnsafe("onExtensionCapabilitiesSet", | |
1788 base::Value(printer_id), capabilities); | |
1789 } | 1816 } |
1790 | 1817 |
1791 void PrintPreviewHandler::OnExtensionPrintResult(bool success, | 1818 void PrintPreviewHandler::OnExtensionPrintResult(bool success, |
1792 const std::string& status) { | 1819 const std::string& status) { |
1793 if (success) { | 1820 if (success) { |
1794 ClosePreviewDialog(); | 1821 ClosePreviewDialog(); |
1795 return; | 1822 return; |
1796 } | 1823 } |
1797 | 1824 |
1798 // TODO(tbarzic): This function works for extension printers case too, but it | 1825 // TODO(tbarzic): This function works for extension printers case too, but it |
(...skipping 16 matching lines...) Expand all Loading... |
1815 | 1842 |
1816 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1843 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
1817 if (gaia_cookie_manager_service_) | 1844 if (gaia_cookie_manager_service_) |
1818 gaia_cookie_manager_service_->RemoveObserver(this); | 1845 gaia_cookie_manager_service_->RemoveObserver(this); |
1819 } | 1846 } |
1820 | 1847 |
1821 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1848 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
1822 const base::Closure& closure) { | 1849 const base::Closure& closure) { |
1823 pdf_file_saved_closure_ = closure; | 1850 pdf_file_saved_closure_ = closure; |
1824 } | 1851 } |
OLD | NEW |