| 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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 | 910 |
| 911 int width = 0; | 911 int width = 0; |
| 912 int height = 0; | 912 int height = 0; |
| 913 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || | 913 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || |
| 914 !settings->GetString(printing::kSettingTicket, &print_ticket) || | 914 !settings->GetString(printing::kSettingTicket, &print_ticket) || |
| 915 !settings->GetString(printing::kSettingCapabilities, &capabilities) || | 915 !settings->GetString(printing::kSettingCapabilities, &capabilities) || |
| 916 !settings->GetInteger(printing::kSettingPageWidth, &width) || | 916 !settings->GetInteger(printing::kSettingPageWidth, &width) || |
| 917 !settings->GetInteger(printing::kSettingPageHeight, &height) || | 917 !settings->GetInteger(printing::kSettingPageHeight, &height) || |
| 918 width <= 0 || height <= 0) { | 918 width <= 0 || height <= 0) { |
| 919 NOTREACHED(); | 919 NOTREACHED(); |
| 920 base::Value http_code_value(-1); | 920 FireWebUIListener("print-failed", base::Value(-1)); |
| 921 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 922 http_code_value); | |
| 923 return; | 921 return; |
| 924 } | 922 } |
| 925 | 923 |
| 926 PrintToPrivetPrinter( | 924 PrintToPrivetPrinter( |
| 927 printer_name, print_ticket, capabilities, gfx::Size(width, height)); | 925 printer_name, print_ticket, capabilities, gfx::Size(width, height)); |
| 928 return; | 926 return; |
| 929 } | 927 } |
| 930 #endif | 928 #endif |
| 931 | 929 |
| 932 if (print_with_extension) { | 930 if (print_with_extension) { |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 weak_factory_.GetWeakPtr(), callback_id)); | 1599 weak_factory_.GetWeakPtr(), callback_id)); |
| 1602 privet_capabilities_operation_->Start(); | 1600 privet_capabilities_operation_->Start(); |
| 1603 } | 1601 } |
| 1604 | 1602 |
| 1605 bool PrintPreviewHandler::PrivetUpdateClient( | 1603 bool PrintPreviewHandler::PrivetUpdateClient( |
| 1606 const std::string& callback_id, | 1604 const std::string& callback_id, |
| 1607 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { | 1605 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client) { |
| 1608 if (!http_client) { | 1606 if (!http_client) { |
| 1609 if (callback_id.empty()) { | 1607 if (callback_id.empty()) { |
| 1610 // This was an attempt to print to a privet printer and has failed. | 1608 // This was an attempt to print to a privet printer and has failed. |
| 1611 base::Value http_code_value(-1); | 1609 FireWebUIListener("print-failed", base::Value(-1)); |
| 1612 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 1613 http_code_value); | |
| 1614 } else { // Capabilities update failed | 1610 } else { // Capabilities update failed |
| 1615 RejectJavascriptCallback(base::Value(callback_id), base::Value()); | 1611 RejectJavascriptCallback(base::Value(callback_id), base::Value()); |
| 1616 } | 1612 } |
| 1617 privet_http_resolution_.reset(); | 1613 privet_http_resolution_.reset(); |
| 1618 return false; | 1614 return false; |
| 1619 } | 1615 } |
| 1620 | 1616 |
| 1621 privet_local_print_operation_.reset(); | 1617 privet_local_print_operation_.reset(); |
| 1622 privet_capabilities_operation_.reset(); | 1618 privet_capabilities_operation_.reset(); |
| 1623 privet_http_client_ = cloud_print::PrivetV1HTTPClient::CreateDefault( | 1619 privet_http_client_ = cloud_print::PrivetV1HTTPClient::CreateDefault( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1645 privet_local_print_operation_ = | 1641 privet_local_print_operation_ = |
| 1646 privet_http_client_->CreateLocalPrintOperation(this); | 1642 privet_http_client_->CreateLocalPrintOperation(this); |
| 1647 | 1643 |
| 1648 privet_local_print_operation_->SetTicket(print_ticket); | 1644 privet_local_print_operation_->SetTicket(print_ticket); |
| 1649 privet_local_print_operation_->SetCapabilities(capabilities); | 1645 privet_local_print_operation_->SetCapabilities(capabilities); |
| 1650 | 1646 |
| 1651 scoped_refptr<base::RefCountedBytes> data; | 1647 scoped_refptr<base::RefCountedBytes> data; |
| 1652 base::string16 title; | 1648 base::string16 title; |
| 1653 | 1649 |
| 1654 if (!GetPreviewDataAndTitle(&data, &title)) { | 1650 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 1655 base::Value http_code_value(-1); | 1651 FireWebUIListener("print-failed", base::Value(-1)); |
| 1656 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 1657 http_code_value); | |
| 1658 return; | 1652 return; |
| 1659 } | 1653 } |
| 1660 | 1654 |
| 1661 privet_local_print_operation_->SetJobname(base::UTF16ToUTF8(title)); | 1655 privet_local_print_operation_->SetJobname(base::UTF16ToUTF8(title)); |
| 1662 privet_local_print_operation_->SetPageSize(page_size); | 1656 privet_local_print_operation_->SetPageSize(page_size); |
| 1663 privet_local_print_operation_->SetData(data.get()); | 1657 privet_local_print_operation_->SetData(data.get()); |
| 1664 | 1658 |
| 1665 Profile* profile = Profile::FromWebUI(web_ui()); | 1659 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1666 SigninManagerBase* signin_manager = | 1660 SigninManagerBase* signin_manager = |
| 1667 SigninManagerFactory::GetForProfileIfExists(profile); | 1661 SigninManagerFactory::GetForProfileIfExists(profile); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 | 1703 |
| 1710 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, | 1704 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, |
| 1711 const std::string& ticket, | 1705 const std::string& ticket, |
| 1712 const std::string& capabilities, | 1706 const std::string& capabilities, |
| 1713 const gfx::Size& page_size) { | 1707 const gfx::Size& page_size) { |
| 1714 if (!CreatePrivetHTTP( | 1708 if (!CreatePrivetHTTP( |
| 1715 device_name, | 1709 device_name, |
| 1716 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, | 1710 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, |
| 1717 weak_factory_.GetWeakPtr(), ticket, capabilities, | 1711 weak_factory_.GetWeakPtr(), ticket, capabilities, |
| 1718 page_size))) { | 1712 page_size))) { |
| 1719 base::Value http_code_value(-1); | 1713 FireWebUIListener("print-failed", base::Value(-1)); |
| 1720 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 1721 http_code_value); | |
| 1722 } | 1714 } |
| 1723 } | 1715 } |
| 1724 | 1716 |
| 1725 bool PrintPreviewHandler::CreatePrivetHTTP( | 1717 bool PrintPreviewHandler::CreatePrivetHTTP( |
| 1726 const std::string& name, | 1718 const std::string& name, |
| 1727 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& | 1719 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& |
| 1728 callback) { | 1720 callback) { |
| 1729 const cloud_print::DeviceDescription* device_description = | 1721 const cloud_print::DeviceDescription* device_description = |
| 1730 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; | 1722 printer_lister_ ? printer_lister_->GetDeviceDescription(name) : NULL; |
| 1731 | 1723 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1742 } | 1734 } |
| 1743 | 1735 |
| 1744 void PrintPreviewHandler::OnPrivetPrintingDone( | 1736 void PrintPreviewHandler::OnPrivetPrintingDone( |
| 1745 const cloud_print::PrivetLocalPrintOperation* print_operation) { | 1737 const cloud_print::PrivetLocalPrintOperation* print_operation) { |
| 1746 ClosePreviewDialog(); | 1738 ClosePreviewDialog(); |
| 1747 } | 1739 } |
| 1748 | 1740 |
| 1749 void PrintPreviewHandler::OnPrivetPrintingError( | 1741 void PrintPreviewHandler::OnPrivetPrintingError( |
| 1750 const cloud_print::PrivetLocalPrintOperation* print_operation, | 1742 const cloud_print::PrivetLocalPrintOperation* print_operation, |
| 1751 int http_code) { | 1743 int http_code) { |
| 1752 base::Value http_code_value(http_code); | 1744 FireWebUIListener("print-failed", base::Value(http_code)); |
| 1753 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 1754 http_code_value); | |
| 1755 } | 1745 } |
| 1756 | 1746 |
| 1757 void PrintPreviewHandler::FillPrinterDescription( | 1747 void PrintPreviewHandler::FillPrinterDescription( |
| 1758 const std::string& name, | 1748 const std::string& name, |
| 1759 const cloud_print::DeviceDescription& description, | 1749 const cloud_print::DeviceDescription& description, |
| 1760 bool has_local_printing, | 1750 bool has_local_printing, |
| 1761 base::DictionaryValue* printer_value) { | 1751 base::DictionaryValue* printer_value) { |
| 1762 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 1752 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1763 | 1753 |
| 1764 printer_value->SetString("serviceName", name); | 1754 printer_value->SetString("serviceName", name); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 } | 1804 } |
| 1815 ResolveJavascriptCallback(base::Value(callback_id), capabilities); | 1805 ResolveJavascriptCallback(base::Value(callback_id), capabilities); |
| 1816 } | 1806 } |
| 1817 | 1807 |
| 1818 void PrintPreviewHandler::OnExtensionPrintResult(bool success, | 1808 void PrintPreviewHandler::OnExtensionPrintResult(bool success, |
| 1819 const std::string& status) { | 1809 const std::string& status) { |
| 1820 if (success) { | 1810 if (success) { |
| 1821 ClosePreviewDialog(); | 1811 ClosePreviewDialog(); |
| 1822 return; | 1812 return; |
| 1823 } | 1813 } |
| 1824 | 1814 FireWebUIListener("print-failed", base::Value(status)); |
| 1825 // TODO(tbarzic): This function works for extension printers case too, but it | |
| 1826 // should be renamed to something more generic. | |
| 1827 web_ui()->CallJavascriptFunctionUnsafe("onPrivetPrintFailed", | |
| 1828 base::Value(status)); | |
| 1829 } | 1815 } |
| 1830 | 1816 |
| 1831 void PrintPreviewHandler::RegisterForGaiaCookieChanges() { | 1817 void PrintPreviewHandler::RegisterForGaiaCookieChanges() { |
| 1832 DCHECK(!gaia_cookie_manager_service_); | 1818 DCHECK(!gaia_cookie_manager_service_); |
| 1833 Profile* profile = Profile::FromWebUI(web_ui()); | 1819 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1834 if (switches::IsAccountConsistencyMirrorEnabled() && | 1820 if (switches::IsAccountConsistencyMirrorEnabled() && |
| 1835 !profile->IsOffTheRecord()) { | 1821 !profile->IsOffTheRecord()) { |
| 1836 gaia_cookie_manager_service_ = | 1822 gaia_cookie_manager_service_ = |
| 1837 GaiaCookieManagerServiceFactory::GetForProfile(profile); | 1823 GaiaCookieManagerServiceFactory::GetForProfile(profile); |
| 1838 if (gaia_cookie_manager_service_) | 1824 if (gaia_cookie_manager_service_) |
| 1839 gaia_cookie_manager_service_->AddObserver(this); | 1825 gaia_cookie_manager_service_->AddObserver(this); |
| 1840 } | 1826 } |
| 1841 } | 1827 } |
| 1842 | 1828 |
| 1843 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1829 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1844 if (gaia_cookie_manager_service_) | 1830 if (gaia_cookie_manager_service_) |
| 1845 gaia_cookie_manager_service_->RemoveObserver(this); | 1831 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1846 } | 1832 } |
| 1847 | 1833 |
| 1848 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1834 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1849 const base::Closure& closure) { | 1835 const base::Closure& closure) { |
| 1850 pdf_file_saved_closure_ = closure; | 1836 pdf_file_saved_closure_ = closure; |
| 1851 } | 1837 } |
| OLD | NEW |