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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 #endif | 704 #endif |
| 705 } | 705 } |
| 706 | 706 |
| 707 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( | 707 void PrintPreviewHandler::HandleGetPrivetPrinterCapabilities( |
| 708 const base::ListValue* args) { | 708 const base::ListValue* args) { |
| 709 AllowJavascript(); | |
| 710 | |
| 711 std::string callback_id; | |
| 712 std::string printer_name; | |
| 713 if (!args->GetString(0, &callback_id) || !args->GetString(1, &printer_name) || | |
| 714 callback_id.empty() || printer_name.empty()) { | |
| 715 RejectJavascriptCallback(base::Value(callback_id), | |
| 716 base::Value(printer_name)); | |
| 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(printer_name)); | |
| 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), | |
| 767 base::Value(printer_name)); | |
| 768 return; | |
| 769 } | |
| 753 | 770 |
| 754 EnsureExtensionPrinterHandlerSet(); | 771 EnsureExtensionPrinterHandlerSet(); |
| 755 extension_printer_handler_->StartGetCapability( | 772 extension_printer_handler_->StartGetCapability( |
| 756 printer_id, | 773 printer_name, |
| 757 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, | 774 base::Bind(&PrintPreviewHandler::OnGotExtensionPrinterCapabilities, |
| 758 weak_factory_.GetWeakPtr())); | 775 weak_factory_.GetWeakPtr(), callback_id)); |
| 759 } | 776 } |
| 760 | 777 |
| 761 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { | 778 void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { |
| 762 DCHECK_EQ(2U, args->GetSize()); | 779 DCHECK_EQ(2U, args->GetSize()); |
| 763 std::unique_ptr<base::DictionaryValue> settings = GetSettingsDictionary(args); | 780 std::unique_ptr<base::DictionaryValue> settings = GetSettingsDictionary(args); |
| 764 if (!settings) | 781 if (!settings) |
| 765 return; | 782 return; |
| 766 int request_id = -1; | 783 int request_id = -1; |
| 767 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 784 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) |
| 768 return; | 785 return; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 std::string data_to_save; | 1081 std::string data_to_save; |
| 1065 printing::StickySettings* sticky_settings = GetStickySettings(); | 1082 printing::StickySettings* sticky_settings = GetStickySettings(); |
| 1066 if (args->GetString(0, &data_to_save) && !data_to_save.empty()) | 1083 if (args->GetString(0, &data_to_save) && !data_to_save.empty()) |
| 1067 sticky_settings->StoreAppState(data_to_save); | 1084 sticky_settings->StoreAppState(data_to_save); |
| 1068 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( | 1085 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( |
| 1069 preview_web_contents()->GetBrowserContext())->GetPrefs()); | 1086 preview_web_contents()->GetBrowserContext())->GetPrefs()); |
| 1070 } | 1087 } |
| 1071 | 1088 |
| 1072 void PrintPreviewHandler::HandleGetPrinterCapabilities( | 1089 void PrintPreviewHandler::HandleGetPrinterCapabilities( |
| 1073 const base::ListValue* args) { | 1090 const base::ListValue* args) { |
| 1091 AllowJavascript(); | |
| 1092 | |
| 1093 std::string callback_id; | |
| 1074 std::string printer_name; | 1094 std::string printer_name; |
| 1075 bool ret = args->GetString(0, &printer_name); | 1095 if (!args->GetString(0, &callback_id) || !args->GetString(1, &printer_name) || |
| 1076 if (!ret || printer_name.empty()) | 1096 callback_id.empty() || printer_name.empty()) { |
| 1097 RejectJavascriptCallback(base::Value(callback_id), | |
| 1098 base::Value(printer_name)); | |
| 1077 return; | 1099 return; |
| 1100 } | |
| 1078 | 1101 |
| 1079 if (printer_name == kLocalPdfPrinterId) { | 1102 if (printer_name == kLocalPdfPrinterId) { |
| 1080 auto printer_info = base::MakeUnique<base::DictionaryValue>(); | 1103 auto printer_info = base::MakeUnique<base::DictionaryValue>(); |
| 1081 printer_info->SetString(printing::kPrinterId, printer_name); | 1104 printer_info->SetString(printing::kPrinterId, printer_name); |
| 1082 printer_info->Set( | 1105 printer_info->Set( |
| 1083 printing::kPrinterCapabilities, | 1106 printing::kPrinterCapabilities, |
| 1084 GetPdfCapabilities(g_browser_process->GetApplicationLocale())); | 1107 GetPdfCapabilities(g_browser_process->GetApplicationLocale())); |
| 1085 SendPrinterCapabilities(printer_name, std::move(printer_info)); | 1108 SendPrinterCapabilities(callback_id, printer_name, std::move(printer_info)); |
| 1086 return; | 1109 return; |
| 1087 } | 1110 } |
| 1088 | 1111 |
| 1089 printing::PrinterSetupCallback cb = | 1112 printing::PrinterSetupCallback cb = |
| 1090 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities, | 1113 base::Bind(&PrintPreviewHandler::SendPrinterCapabilities, |
| 1091 weak_factory_.GetWeakPtr(), printer_name); | 1114 weak_factory_.GetWeakPtr(), callback_id, printer_name); |
| 1092 | 1115 |
| 1093 printer_backend_proxy()->ConfigurePrinterAndFetchCapabilities(printer_name, | 1116 printer_backend_proxy()->ConfigurePrinterAndFetchCapabilities(printer_name, |
| 1094 cb); | 1117 cb); |
| 1095 } | 1118 } |
| 1096 | 1119 |
| 1097 // |args| is expected to contain a string with representing the callback id | 1120 // |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. | 1121 // followed by a list of arguments the first of which should be the printer id. |
| 1099 void PrintPreviewHandler::HandlePrinterSetup(const base::ListValue* args) { | 1122 void PrintPreviewHandler::HandlePrinterSetup(const base::ListValue* args) { |
| 1100 AllowJavascript(); | 1123 AllowJavascript(); |
| 1101 | 1124 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1300 } | 1323 } |
| 1301 | 1324 |
| 1302 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1325 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
| 1303 const std::string& access_token) { | 1326 const std::string& access_token) { |
| 1304 VLOG(1) << "Get getAccessToken finished"; | 1327 VLOG(1) << "Get getAccessToken finished"; |
| 1305 web_ui()->CallJavascriptFunctionUnsafe( | 1328 web_ui()->CallJavascriptFunctionUnsafe( |
| 1306 "onDidGetAccessToken", base::Value(type), base::Value(access_token)); | 1329 "onDidGetAccessToken", base::Value(type), base::Value(access_token)); |
| 1307 } | 1330 } |
| 1308 | 1331 |
| 1309 void PrintPreviewHandler::SendPrinterCapabilities( | 1332 void PrintPreviewHandler::SendPrinterCapabilities( |
| 1333 const std::string& callback_id, | |
| 1310 const std::string& printer_name, | 1334 const std::string& printer_name, |
| 1311 std::unique_ptr<base::DictionaryValue> settings_info) { | 1335 std::unique_ptr<base::DictionaryValue> settings_info) { |
| 1312 // Check that |settings_info| is valid. | 1336 // Check that |settings_info| is valid. |
| 1313 if (settings_info && settings_info->Get("capabilities", nullptr)) { | 1337 if (settings_info && settings_info->Get("capabilities", nullptr)) { |
| 1314 VLOG(1) << "Get printer capabilities finished"; | 1338 VLOG(1) << "Get printer capabilities finished"; |
| 1315 web_ui()->CallJavascriptFunctionUnsafe("updateWithPrinterCapabilities", | 1339 ResolveJavascriptCallback(base::Value(callback_id), *settings_info); |
| 1316 *settings_info); | |
| 1317 return; | 1340 return; |
| 1318 } | 1341 } |
| 1319 | 1342 |
| 1320 VLOG(1) << "Get printer capabilities failed"; | 1343 VLOG(1) << "Get printer capabilities failed"; |
| 1321 web_ui()->CallJavascriptFunctionUnsafe("failedToGetPrinterCapabilities", | 1344 RejectJavascriptCallback(base::Value(callback_id), base::Value(printer_name)); |
| 1322 base::Value(printer_name)); | |
| 1323 } | 1345 } |
| 1324 | 1346 |
| 1325 void PrintPreviewHandler::SendPrinterSetup( | 1347 void PrintPreviewHandler::SendPrinterSetup( |
| 1326 const std::string& callback_id, | 1348 const std::string& callback_id, |
| 1327 const std::string& printer_name, | 1349 const std::string& printer_name, |
| 1328 std::unique_ptr<base::DictionaryValue> destination_info) { | 1350 std::unique_ptr<base::DictionaryValue> destination_info) { |
| 1329 auto response = base::MakeUnique<base::DictionaryValue>(); | 1351 auto response = base::MakeUnique<base::DictionaryValue>(); |
| 1330 bool success = true; | 1352 bool success = true; |
| 1331 auto caps_value = base::MakeUnique<base::Value>(); | 1353 auto caps_value = base::MakeUnique<base::Value>(); |
| 1332 auto caps = base::MakeUnique<base::DictionaryValue>(); | 1354 auto caps = base::MakeUnique<base::DictionaryValue>(); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1563 } | 1585 } |
| 1564 } | 1586 } |
| 1565 | 1587 |
| 1566 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { | 1588 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { |
| 1567 } | 1589 } |
| 1568 | 1590 |
| 1569 void PrintPreviewHandler::LocalPrinterCacheFlushed() { | 1591 void PrintPreviewHandler::LocalPrinterCacheFlushed() { |
| 1570 } | 1592 } |
| 1571 | 1593 |
| 1572 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( | 1594 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( |
| 1595 const std::string& callback_id, | |
| 1573 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { | 1596 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
| 1574 if (!PrivetUpdateClient(std::move(http_client))) | 1597 if (!PrivetUpdateClient(callback_id, std::move(http_client))) |
| 1575 return; | 1598 return; |
| 1576 | 1599 |
| 1577 privet_capabilities_operation_ = | 1600 privet_capabilities_operation_ = |
| 1578 privet_http_client_->CreateCapabilitiesOperation( | 1601 privet_http_client_->CreateCapabilitiesOperation( |
| 1579 base::Bind(&PrintPreviewHandler::OnPrivetCapabilities, | 1602 base::Bind(&PrintPreviewHandler::OnPrivetCapabilities, |
| 1580 weak_factory_.GetWeakPtr())); | 1603 weak_factory_.GetWeakPtr(), callback_id)); |
| 1581 privet_capabilities_operation_->Start(); | 1604 privet_capabilities_operation_->Start(); |
| 1582 } | 1605 } |
| 1583 | 1606 |
| 1584 bool PrintPreviewHandler::PrivetUpdateClient( | 1607 bool PrintPreviewHandler::PrivetUpdateClient( |
| 1608 const std::string& callback_id, | |
| 1585 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { | 1609 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
| 1586 if (!http_client) { | 1610 if (!http_client) { |
| 1587 SendPrivetCapabilitiesError(privet_http_resolution_->GetName()); | 1611 if (callback_id.empty()) { |
|
rbpotter
2017/06/09 10:24:23
Here and in one other location the capabilities er
dpapad
2017/06/09 17:59:11
Hm, I don't fully understand the implications here
rbpotter
2017/06/14 03:55:08
Was originally thinking it might be temporary and
dpapad
2017/06/14 17:19:36
Ok. Can we then eliminate (in a follow up CL) the
rbpotter
2017/06/14 18:28:25
Ok, will do.
rbpotter
2017/06/14 19:19:55
See followup here: https://codereview.chromium.org
| |
| 1612 // This was an attempt to print to a privet printer and has failed. | |
| 1613 base::Value http_code_value(-1); | |
| 1614 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 1615 http_code_value); | |
| 1616 } else { // Capabilities update failed | |
| 1617 RejectJavascriptCallback(base::Value(callback_id), | |
| 1618 base::Value(privet_http_resolution_->GetName())); | |
| 1619 } | |
| 1588 privet_http_resolution_.reset(); | 1620 privet_http_resolution_.reset(); |
| 1589 return false; | 1621 return false; |
| 1590 } | 1622 } |
| 1591 | 1623 |
| 1592 privet_local_print_operation_.reset(); | 1624 privet_local_print_operation_.reset(); |
| 1593 privet_capabilities_operation_.reset(); | 1625 privet_capabilities_operation_.reset(); |
| 1594 privet_http_client_ = cloud_print::PrivetV1HTTPClient::CreateDefault( | 1626 privet_http_client_ = cloud_print::PrivetV1HTTPClient::CreateDefault( |
| 1595 std::move(http_client)); | 1627 std::move(http_client)); |
| 1596 | 1628 |
| 1597 privet_http_resolution_.reset(); | 1629 privet_http_resolution_.reset(); |
| 1598 | 1630 |
| 1599 return true; | 1631 return true; |
| 1600 } | 1632 } |
| 1601 | 1633 |
| 1602 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( | 1634 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( |
| 1603 std::string print_ticket, | 1635 std::string print_ticket, |
| 1604 std::string capabilities, | 1636 std::string capabilities, |
| 1605 gfx::Size page_size, | 1637 gfx::Size page_size, |
| 1606 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { | 1638 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
| 1607 if (!PrivetUpdateClient(std::move(http_client))) | 1639 if (!PrivetUpdateClient("", std::move(http_client))) |
| 1608 return; | 1640 return; |
| 1609 | 1641 |
| 1610 StartPrivetLocalPrint(print_ticket, capabilities, page_size); | 1642 StartPrivetLocalPrint(print_ticket, capabilities, page_size); |
| 1611 } | 1643 } |
| 1612 | 1644 |
| 1613 void PrintPreviewHandler::StartPrivetLocalPrint(const std::string& print_ticket, | 1645 void PrintPreviewHandler::StartPrivetLocalPrint(const std::string& print_ticket, |
| 1614 const std::string& capabilities, | 1646 const std::string& capabilities, |
| 1615 const gfx::Size& page_size) { | 1647 const gfx::Size& page_size) { |
| 1616 privet_local_print_operation_ = | 1648 privet_local_print_operation_ = |
| 1617 privet_http_client_->CreateLocalPrintOperation(this); | 1649 privet_http_client_->CreateLocalPrintOperation(this); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1638 SigninManagerFactory::GetForProfileIfExists(profile); | 1670 SigninManagerFactory::GetForProfileIfExists(profile); |
| 1639 | 1671 |
| 1640 if (signin_manager) { | 1672 if (signin_manager) { |
| 1641 privet_local_print_operation_->SetUsername( | 1673 privet_local_print_operation_->SetUsername( |
| 1642 signin_manager->GetAuthenticatedAccountInfo().email); | 1674 signin_manager->GetAuthenticatedAccountInfo().email); |
| 1643 } | 1675 } |
| 1644 | 1676 |
| 1645 privet_local_print_operation_->Start(); | 1677 privet_local_print_operation_->Start(); |
| 1646 } | 1678 } |
| 1647 | 1679 |
| 1648 | |
| 1649 void PrintPreviewHandler::OnPrivetCapabilities( | 1680 void PrintPreviewHandler::OnPrivetCapabilities( |
| 1681 const std::string& callback_id, | |
| 1650 const base::DictionaryValue* capabilities) { | 1682 const base::DictionaryValue* capabilities) { |
| 1651 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName(); | 1683 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName(); |
| 1652 | 1684 |
| 1653 if (!capabilities || capabilities->HasKey(cloud_print::kPrivetKeyError) || | 1685 if (!capabilities || capabilities->HasKey(cloud_print::kPrivetKeyError) || |
| 1654 !printer_lister_) { | 1686 !printer_lister_) { |
| 1655 SendPrivetCapabilitiesError(name); | 1687 RejectJavascriptCallback(base::Value(callback_id), base::Value(name)); |
| 1656 return; | 1688 return; |
| 1657 } | 1689 } |
| 1658 | 1690 |
| 1659 base::DictionaryValue printer_info; | 1691 base::DictionaryValue printer_info; |
| 1660 const cloud_print::DeviceDescription* description = | 1692 const cloud_print::DeviceDescription* description = |
| 1661 printer_lister_->GetDeviceDescription(name); | 1693 printer_lister_->GetDeviceDescription(name); |
| 1662 | 1694 |
| 1663 if (!description) { | 1695 if (!description) { |
| 1664 SendPrivetCapabilitiesError(name); | 1696 RejectJavascriptCallback(base::Value(callback_id), base::Value(name)); |
| 1665 return; | 1697 return; |
| 1666 } | 1698 } |
| 1667 | 1699 |
| 1668 FillPrinterDescription(name, *description, true, &printer_info); | 1700 FillPrinterDescription(name, *description, true, &printer_info); |
| 1669 | 1701 |
| 1670 web_ui()->CallJavascriptFunctionUnsafe("onPrivetCapabilitiesSet", | 1702 base::DictionaryValue printer_info_and_caps; |
| 1671 printer_info, *capabilities); | 1703 printer_info_and_caps.SetDictionary("printer", |
| 1704 base::WrapUnique(&printer_info)); | |
| 1705 base::DictionaryValue capabilities_copy = *capabilities; | |
| 1706 printer_info_and_caps.SetDictionary("capabilities", | |
| 1707 base::WrapUnique(&capabilities_copy)); | |
| 1708 ResolveJavascriptCallback(base::Value(callback_id), printer_info_and_caps); | |
| 1672 | 1709 |
| 1673 privet_capabilities_operation_.reset(); | 1710 privet_capabilities_operation_.reset(); |
| 1674 } | 1711 } |
| 1675 | 1712 |
| 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, | 1713 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, |
| 1684 const std::string& ticket, | 1714 const std::string& ticket, |
| 1685 const std::string& capabilities, | 1715 const std::string& capabilities, |
| 1686 const gfx::Size& page_size) { | 1716 const gfx::Size& page_size) { |
| 1687 CreatePrivetHTTP( | 1717 if (!CreatePrivetHTTP( |
| 1688 device_name, | 1718 device_name, |
| 1689 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, | 1719 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, |
| 1690 weak_factory_.GetWeakPtr(), ticket, capabilities, page_size)); | 1720 weak_factory_.GetWeakPtr(), ticket, capabilities, |
| 1721 page_size))) { | |
| 1722 base::Value http_code_value(-1); | |
| 1723 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 1724 http_code_value); | |
| 1725 } | |
| 1691 } | 1726 } |
| 1692 | 1727 |
| 1693 bool PrintPreviewHandler::CreatePrivetHTTP( | 1728 bool PrintPreviewHandler::CreatePrivetHTTP( |
| 1694 const std::string& name, | 1729 const std::string& name, |
| 1695 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& | 1730 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& |
| 1696 callback) { | 1731 callback) { |
| 1697 const cloud_print::DeviceDescription* device_description = | 1732 const cloud_print::DeviceDescription* device_description = |
| 1698 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; | 1733 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; |
| 1699 | 1734 |
| 1700 if (!device_description) { | 1735 if (!device_description) |
| 1701 SendPrivetCapabilitiesError(name); | |
| 1702 return false; | 1736 return false; |
| 1703 } | |
| 1704 | 1737 |
| 1705 privet_http_factory_ = | 1738 privet_http_factory_ = |
| 1706 cloud_print::PrivetHTTPAsynchronousFactory::CreateInstance( | 1739 cloud_print::PrivetHTTPAsynchronousFactory::CreateInstance( |
| 1707 Profile::FromWebUI(web_ui())->GetRequestContext()); | 1740 Profile::FromWebUI(web_ui())->GetRequestContext()); |
| 1708 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP(name); | 1741 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP(name); |
| 1709 privet_http_resolution_->Start(device_description->address, callback); | 1742 privet_http_resolution_->Start(device_description->address, callback); |
| 1710 | 1743 |
| 1711 return true; | 1744 return true; |
| 1712 } | 1745 } |
| 1713 | 1746 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1769 web_ui()->CallJavascriptFunctionUnsafe("failedToResolveProvisionalPrinter", | 1802 web_ui()->CallJavascriptFunctionUnsafe("failedToResolveProvisionalPrinter", |
| 1770 base::Value(printer_id)); | 1803 base::Value(printer_id)); |
| 1771 return; | 1804 return; |
| 1772 } | 1805 } |
| 1773 | 1806 |
| 1774 web_ui()->CallJavascriptFunctionUnsafe("onProvisionalPrinterResolved", | 1807 web_ui()->CallJavascriptFunctionUnsafe("onProvisionalPrinterResolved", |
| 1775 base::Value(printer_id), printer_info); | 1808 base::Value(printer_id), printer_info); |
| 1776 } | 1809 } |
| 1777 | 1810 |
| 1778 void PrintPreviewHandler::OnGotExtensionPrinterCapabilities( | 1811 void PrintPreviewHandler::OnGotExtensionPrinterCapabilities( |
| 1812 const std::string& callback_id, | |
| 1779 const std::string& printer_id, | 1813 const std::string& printer_id, |
| 1780 const base::DictionaryValue& capabilities) { | 1814 const base::DictionaryValue& capabilities) { |
| 1781 if (capabilities.empty()) { | 1815 if (capabilities.empty()) { |
| 1782 web_ui()->CallJavascriptFunctionUnsafe( | 1816 RejectJavascriptCallback(base::Value(callback_id), base::Value(printer_id)); |
|
dpapad
2017/06/09 17:59:11
Does it still make sense to pass the printer_id in
rbpotter
2017/06/14 03:55:08
Done.
| |
| 1783 "failedToGetExtensionPrinterCapabilities", base::Value(printer_id)); | |
| 1784 return; | 1817 return; |
| 1785 } | 1818 } |
| 1786 | 1819 base::DictionaryValue printer_id_and_capabilities; |
| 1787 web_ui()->CallJavascriptFunctionUnsafe("onExtensionCapabilitiesSet", | 1820 printer_id_and_capabilities.SetString("printerId", printer_id); |
| 1788 base::Value(printer_id), capabilities); | 1821 base::DictionaryValue capabilities_copy = capabilities; |
| 1822 printer_id_and_capabilities.SetDictionary( | |
| 1823 "capabilities", base::WrapUnique(&capabilities_copy)); | |
| 1824 ResolveJavascriptCallback(base::Value(callback_id), | |
| 1825 printer_id_and_capabilities); | |
| 1789 } | 1826 } |
| 1790 | 1827 |
| 1791 void PrintPreviewHandler::OnExtensionPrintResult(bool success, | 1828 void PrintPreviewHandler::OnExtensionPrintResult(bool success, |
| 1792 const std::string& status) { | 1829 const std::string& status) { |
| 1793 if (success) { | 1830 if (success) { |
| 1794 ClosePreviewDialog(); | 1831 ClosePreviewDialog(); |
| 1795 return; | 1832 return; |
| 1796 } | 1833 } |
| 1797 | 1834 |
| 1798 // TODO(tbarzic): This function works for extension printers case too, but it | 1835 // TODO(tbarzic): This function works for extension printers case too, but it |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1815 | 1852 |
| 1816 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1853 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1817 if (gaia_cookie_manager_service_) | 1854 if (gaia_cookie_manager_service_) |
| 1818 gaia_cookie_manager_service_->RemoveObserver(this); | 1855 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1819 } | 1856 } |
| 1820 | 1857 |
| 1821 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1858 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1822 const base::Closure& closure) { | 1859 const base::Closure& closure) { |
| 1823 pdf_file_saved_closure_ = closure; | 1860 pdf_file_saved_closure_ = closure; |
| 1824 } | 1861 } |
| OLD | NEW |