| 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 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 #include "printing/printing_context.h" | 87 #include "printing/printing_context.h" |
| 88 #include "printing/units.h" | 88 #include "printing/units.h" |
| 89 #include "third_party/icu/source/i18n/unicode/ulocdata.h" | 89 #include "third_party/icu/source/i18n/unicode/ulocdata.h" |
| 90 | 90 |
| 91 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| 92 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 92 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
| 93 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 93 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
| 94 #endif | 94 #endif |
| 95 | 95 |
| 96 #if defined(ENABLE_SERVICE_DISCOVERY) | 96 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 97 #include "chrome/browser/local_discovery/privet_constants.h" | 97 #include "chrome/browser/printing/cloud_print/privet_constants.h" |
| 98 #endif | 98 #endif |
| 99 | 99 |
| 100 using content::BrowserThread; | 100 using content::BrowserThread; |
| 101 using content::RenderViewHost; | 101 using content::RenderViewHost; |
| 102 using content::WebContents; | 102 using content::WebContents; |
| 103 | 103 |
| 104 namespace { | 104 namespace { |
| 105 | 105 |
| 106 enum UserActionBuckets { | 106 enum UserActionBuckets { |
| 107 PRINT_TO_PRINTER, | 107 PRINT_TO_PRINTER, |
| (...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 | 1542 |
| 1543 void PrintPreviewHandler::StartPrivetLister(const scoped_refptr< | 1543 void PrintPreviewHandler::StartPrivetLister(const scoped_refptr< |
| 1544 local_discovery::ServiceDiscoverySharedClient>& client) { | 1544 local_discovery::ServiceDiscoverySharedClient>& client) { |
| 1545 if (!PrivetPrintingEnabled()) | 1545 if (!PrivetPrintingEnabled()) |
| 1546 return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone"); | 1546 return web_ui()->CallJavascriptFunction("onPrivetPrinterSearchDone"); |
| 1547 | 1547 |
| 1548 Profile* profile = Profile::FromWebUI(web_ui()); | 1548 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1549 DCHECK(!service_discovery_client_.get() || | 1549 DCHECK(!service_discovery_client_.get() || |
| 1550 service_discovery_client_.get() == client.get()); | 1550 service_discovery_client_.get() == client.get()); |
| 1551 service_discovery_client_ = client; | 1551 service_discovery_client_ = client; |
| 1552 printer_lister_.reset(new local_discovery::PrivetLocalPrinterLister( | 1552 printer_lister_.reset(new cloud_print::PrivetLocalPrinterLister( |
| 1553 service_discovery_client_.get(), profile->GetRequestContext(), this)); | 1553 service_discovery_client_.get(), profile->GetRequestContext(), this)); |
| 1554 printer_lister_->Start(); | 1554 printer_lister_->Start(); |
| 1555 } | 1555 } |
| 1556 | 1556 |
| 1557 void PrintPreviewHandler::LocalPrinterChanged( | 1557 void PrintPreviewHandler::LocalPrinterChanged( |
| 1558 bool added, | 1558 bool added, |
| 1559 const std::string& name, | 1559 const std::string& name, |
| 1560 bool has_local_printing, | 1560 bool has_local_printing, |
| 1561 const local_discovery::DeviceDescription& description) { | 1561 const cloud_print::DeviceDescription& description) { |
| 1562 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 1562 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1563 if (has_local_printing || | 1563 if (has_local_printing || |
| 1564 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { | 1564 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { |
| 1565 base::DictionaryValue info; | 1565 base::DictionaryValue info; |
| 1566 FillPrinterDescription(name, description, has_local_printing, &info); | 1566 FillPrinterDescription(name, description, has_local_printing, &info); |
| 1567 web_ui()->CallJavascriptFunction("onPrivetPrinterChanged", info); | 1567 web_ui()->CallJavascriptFunction("onPrivetPrinterChanged", info); |
| 1568 } | 1568 } |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { | 1571 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { |
| 1572 } | 1572 } |
| 1573 | 1573 |
| 1574 void PrintPreviewHandler::LocalPrinterCacheFlushed() { | 1574 void PrintPreviewHandler::LocalPrinterCacheFlushed() { |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( | 1577 void PrintPreviewHandler::PrivetCapabilitiesUpdateClient( |
| 1578 scoped_ptr<local_discovery::PrivetHTTPClient> http_client) { | 1578 scoped_ptr<cloud_print::PrivetHTTPClient> http_client) { |
| 1579 if (!PrivetUpdateClient(std::move(http_client))) | 1579 if (!PrivetUpdateClient(std::move(http_client))) |
| 1580 return; | 1580 return; |
| 1581 | 1581 |
| 1582 privet_capabilities_operation_ = | 1582 privet_capabilities_operation_ = |
| 1583 privet_http_client_->CreateCapabilitiesOperation( | 1583 privet_http_client_->CreateCapabilitiesOperation( |
| 1584 base::Bind(&PrintPreviewHandler::OnPrivetCapabilities, | 1584 base::Bind(&PrintPreviewHandler::OnPrivetCapabilities, |
| 1585 base::Unretained(this))); | 1585 base::Unretained(this))); |
| 1586 privet_capabilities_operation_->Start(); | 1586 privet_capabilities_operation_->Start(); |
| 1587 } | 1587 } |
| 1588 | 1588 |
| 1589 bool PrintPreviewHandler::PrivetUpdateClient( | 1589 bool PrintPreviewHandler::PrivetUpdateClient( |
| 1590 scoped_ptr<local_discovery::PrivetHTTPClient> http_client) { | 1590 scoped_ptr<cloud_print::PrivetHTTPClient> http_client) { |
| 1591 if (!http_client) { | 1591 if (!http_client) { |
| 1592 SendPrivetCapabilitiesError(privet_http_resolution_->GetName()); | 1592 SendPrivetCapabilitiesError(privet_http_resolution_->GetName()); |
| 1593 privet_http_resolution_.reset(); | 1593 privet_http_resolution_.reset(); |
| 1594 return false; | 1594 return false; |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 privet_local_print_operation_.reset(); | 1597 privet_local_print_operation_.reset(); |
| 1598 privet_capabilities_operation_.reset(); | 1598 privet_capabilities_operation_.reset(); |
| 1599 privet_http_client_ = local_discovery::PrivetV1HTTPClient::CreateDefault( | 1599 privet_http_client_ = cloud_print::PrivetV1HTTPClient::CreateDefault( |
| 1600 std::move(http_client)); | 1600 std::move(http_client)); |
| 1601 | 1601 |
| 1602 privet_http_resolution_.reset(); | 1602 privet_http_resolution_.reset(); |
| 1603 | 1603 |
| 1604 return true; | 1604 return true; |
| 1605 } | 1605 } |
| 1606 | 1606 |
| 1607 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( | 1607 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( |
| 1608 std::string print_ticket, | 1608 std::string print_ticket, |
| 1609 std::string capabilities, | 1609 std::string capabilities, |
| 1610 gfx::Size page_size, | 1610 gfx::Size page_size, |
| 1611 scoped_ptr<local_discovery::PrivetHTTPClient> http_client) { | 1611 scoped_ptr<cloud_print::PrivetHTTPClient> http_client) { |
| 1612 if (!PrivetUpdateClient(std::move(http_client))) | 1612 if (!PrivetUpdateClient(std::move(http_client))) |
| 1613 return; | 1613 return; |
| 1614 | 1614 |
| 1615 StartPrivetLocalPrint(print_ticket, capabilities, page_size); | 1615 StartPrivetLocalPrint(print_ticket, capabilities, page_size); |
| 1616 } | 1616 } |
| 1617 | 1617 |
| 1618 void PrintPreviewHandler::StartPrivetLocalPrint(const std::string& print_ticket, | 1618 void PrintPreviewHandler::StartPrivetLocalPrint(const std::string& print_ticket, |
| 1619 const std::string& capabilities, | 1619 const std::string& capabilities, |
| 1620 const gfx::Size& page_size) { | 1620 const gfx::Size& page_size) { |
| 1621 privet_local_print_operation_ = | 1621 privet_local_print_operation_ = |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 privet_local_print_operation_->Start(); | 1649 privet_local_print_operation_->Start(); |
| 1650 } | 1650 } |
| 1651 | 1651 |
| 1652 | 1652 |
| 1653 void PrintPreviewHandler::OnPrivetCapabilities( | 1653 void PrintPreviewHandler::OnPrivetCapabilities( |
| 1654 const base::DictionaryValue* capabilities) { | 1654 const base::DictionaryValue* capabilities) { |
| 1655 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName(); | 1655 std::string name = privet_capabilities_operation_->GetHTTPClient()->GetName(); |
| 1656 | 1656 |
| 1657 if (!capabilities || capabilities->HasKey(local_discovery::kPrivetKeyError) || | 1657 if (!capabilities || capabilities->HasKey(cloud_print::kPrivetKeyError) || |
| 1658 !printer_lister_) { | 1658 !printer_lister_) { |
| 1659 SendPrivetCapabilitiesError(name); | 1659 SendPrivetCapabilitiesError(name); |
| 1660 return; | 1660 return; |
| 1661 } | 1661 } |
| 1662 | 1662 |
| 1663 base::DictionaryValue printer_info; | 1663 base::DictionaryValue printer_info; |
| 1664 const local_discovery::DeviceDescription* description = | 1664 const cloud_print::DeviceDescription* description = |
| 1665 printer_lister_->GetDeviceDescription(name); | 1665 printer_lister_->GetDeviceDescription(name); |
| 1666 | 1666 |
| 1667 if (!description) { | 1667 if (!description) { |
| 1668 SendPrivetCapabilitiesError(name); | 1668 SendPrivetCapabilitiesError(name); |
| 1669 return; | 1669 return; |
| 1670 } | 1670 } |
| 1671 | 1671 |
| 1672 FillPrinterDescription(name, *description, true, &printer_info); | 1672 FillPrinterDescription(name, *description, true, &printer_info); |
| 1673 | 1673 |
| 1674 web_ui()->CallJavascriptFunction( | 1674 web_ui()->CallJavascriptFunction( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1695 device_name, | 1695 device_name, |
| 1696 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, | 1696 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, |
| 1697 base::Unretained(this), | 1697 base::Unretained(this), |
| 1698 ticket, | 1698 ticket, |
| 1699 capabilities, | 1699 capabilities, |
| 1700 page_size)); | 1700 page_size)); |
| 1701 } | 1701 } |
| 1702 | 1702 |
| 1703 bool PrintPreviewHandler::CreatePrivetHTTP( | 1703 bool PrintPreviewHandler::CreatePrivetHTTP( |
| 1704 const std::string& name, | 1704 const std::string& name, |
| 1705 const local_discovery::PrivetHTTPAsynchronousFactory::ResultCallback& | 1705 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& |
| 1706 callback) { | 1706 callback) { |
| 1707 const local_discovery::DeviceDescription* device_description = | 1707 const cloud_print::DeviceDescription* device_description = |
| 1708 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; | 1708 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; |
| 1709 | 1709 |
| 1710 if (!device_description) { | 1710 if (!device_description) { |
| 1711 SendPrivetCapabilitiesError(name); | 1711 SendPrivetCapabilitiesError(name); |
| 1712 return false; | 1712 return false; |
| 1713 } | 1713 } |
| 1714 | 1714 |
| 1715 privet_http_factory_ = | 1715 privet_http_factory_ = |
| 1716 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance( | 1716 cloud_print::PrivetHTTPAsynchronousFactory::CreateInstance( |
| 1717 Profile::FromWebUI(web_ui())->GetRequestContext()); | 1717 Profile::FromWebUI(web_ui())->GetRequestContext()); |
| 1718 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP(name); | 1718 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP(name); |
| 1719 privet_http_resolution_->Start(device_description->address, callback); | 1719 privet_http_resolution_->Start(device_description->address, callback); |
| 1720 | 1720 |
| 1721 return true; | 1721 return true; |
| 1722 } | 1722 } |
| 1723 | 1723 |
| 1724 void PrintPreviewHandler::OnPrivetPrintingDone( | 1724 void PrintPreviewHandler::OnPrivetPrintingDone( |
| 1725 const local_discovery::PrivetLocalPrintOperation* print_operation) { | 1725 const cloud_print::PrivetLocalPrintOperation* print_operation) { |
| 1726 ClosePreviewDialog(); | 1726 ClosePreviewDialog(); |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 void PrintPreviewHandler::OnPrivetPrintingError( | 1729 void PrintPreviewHandler::OnPrivetPrintingError( |
| 1730 const local_discovery::PrivetLocalPrintOperation* print_operation, | 1730 const cloud_print::PrivetLocalPrintOperation* print_operation, |
| 1731 int http_code) { | 1731 int http_code) { |
| 1732 base::FundamentalValue http_code_value(http_code); | 1732 base::FundamentalValue http_code_value(http_code); |
| 1733 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 1733 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 void PrintPreviewHandler::FillPrinterDescription( | 1736 void PrintPreviewHandler::FillPrinterDescription( |
| 1737 const std::string& name, | 1737 const std::string& name, |
| 1738 const local_discovery::DeviceDescription& description, | 1738 const cloud_print::DeviceDescription& description, |
| 1739 bool has_local_printing, | 1739 bool has_local_printing, |
| 1740 base::DictionaryValue* printer_value) { | 1740 base::DictionaryValue* printer_value) { |
| 1741 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 1741 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1742 | 1742 |
| 1743 printer_value->SetString("serviceName", name); | 1743 printer_value->SetString("serviceName", name); |
| 1744 printer_value->SetString("name", description.name); | 1744 printer_value->SetString("name", description.name); |
| 1745 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); | 1745 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); |
| 1746 printer_value->SetBoolean( | 1746 printer_value->SetBoolean( |
| 1747 "isUnregistered", | 1747 "isUnregistered", |
| 1748 description.id.empty() && | 1748 description.id.empty() && |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 | 1820 |
| 1821 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1821 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1822 if (gaia_cookie_manager_service_) | 1822 if (gaia_cookie_manager_service_) |
| 1823 gaia_cookie_manager_service_->RemoveObserver(this); | 1823 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1824 } | 1824 } |
| 1825 | 1825 |
| 1826 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1826 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1827 const base::Closure& closure) { | 1827 const base::Closure& closure) { |
| 1828 pdf_file_saved_closure_ = closure; | 1828 pdf_file_saved_closure_ = closure; |
| 1829 } | 1829 } |
| OLD | NEW |