| 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 | |
| 10 #include <map> | 9 #include <map> |
| 11 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/base64.h" | 13 #include "base/base64.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/i18n/file_util_icu.h" | 17 #include "base/i18n/file_util_icu.h" |
| 18 #include "base/i18n/number_formatting.h" | 18 #include "base/i18n/number_formatting.h" |
| 19 #include "base/json/json_reader.h" | 19 #include "base/json/json_reader.h" |
| 20 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return scoped_ptr<base::DictionaryValue>(); | 417 return scoped_ptr<base::DictionaryValue>(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 scoped_ptr<base::DictionaryValue> description( | 420 scoped_ptr<base::DictionaryValue> description( |
| 421 cloud_print::PrinterSemanticCapsAndDefaultsToCdd(info)); | 421 cloud_print::PrinterSemanticCapsAndDefaultsToCdd(info)); |
| 422 if (!description) { | 422 if (!description) { |
| 423 LOG(WARNING) << "Failed to convert capabilities for " << printer_name; | 423 LOG(WARNING) << "Failed to convert capabilities for " << printer_name; |
| 424 return scoped_ptr<base::DictionaryValue>(); | 424 return scoped_ptr<base::DictionaryValue>(); |
| 425 } | 425 } |
| 426 | 426 |
| 427 return description.Pass(); | 427 return description; |
| 428 } | 428 } |
| 429 | 429 |
| 430 void EnumeratePrintersOnFileThread(base::ListValue* printers) { | 430 void EnumeratePrintersOnFileThread(base::ListValue* printers) { |
| 431 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 431 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 432 | 432 |
| 433 scoped_refptr<printing::PrintBackend> print_backend( | 433 scoped_refptr<printing::PrintBackend> print_backend( |
| 434 printing::PrintBackend::CreateInstance(NULL)); | 434 printing::PrintBackend::CreateInstance(NULL)); |
| 435 | 435 |
| 436 VLOG(1) << "Enumerate printers start"; | 436 VLOG(1) << "Enumerate printers start"; |
| 437 printing::PrinterList printer_list; | 437 printing::PrinterList printer_list; |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 bool selection_only = false; | 866 bool selection_only = false; |
| 867 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, | 867 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 868 &selection_only)) { | 868 &selection_only)) { |
| 869 NOTREACHED(); | 869 NOTREACHED(); |
| 870 } | 870 } |
| 871 | 871 |
| 872 if (distill_page && !selection_only) { | 872 if (distill_page && !selection_only) { |
| 873 print_preview_distiller_.reset(new PrintPreviewDistiller( | 873 print_preview_distiller_.reset(new PrintPreviewDistiller( |
| 874 initiator, base::Bind(&PrintPreviewUI::OnPrintPreviewFailed, | 874 initiator, base::Bind(&PrintPreviewUI::OnPrintPreviewFailed, |
| 875 print_preview_ui()->GetWeakPtr()), | 875 print_preview_ui()->GetWeakPtr()), |
| 876 settings.Pass())); | 876 std::move(settings))); |
| 877 } else { | 877 } else { |
| 878 RenderViewHost* rvh = initiator->GetRenderViewHost(); | 878 RenderViewHost* rvh = initiator->GetRenderViewHost(); |
| 879 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); | 879 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
| 880 } | 880 } |
| 881 } | 881 } |
| 882 | 882 |
| 883 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 883 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
| 884 ReportStats(); | 884 ReportStats(); |
| 885 | 885 |
| 886 // Record the number of times the user requests to regenerate preview data | 886 // Record the number of times the user requests to regenerate preview data |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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<local_discovery::PrivetHTTPClient> http_client) { |
| 1579 if (!PrivetUpdateClient(http_client.Pass())) | 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<local_discovery::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_ = | 1599 privet_http_client_ = local_discovery::PrivetV1HTTPClient::CreateDefault( |
| 1600 local_discovery::PrivetV1HTTPClient::CreateDefault(http_client.Pass()); | 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<local_discovery::PrivetHTTPClient> http_client) { |
| 1612 if (!PrivetUpdateClient(http_client.Pass())) | 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_ = |
| 1622 privet_http_client_->CreateLocalPrintOperation(this); | 1622 privet_http_client_->CreateLocalPrintOperation(this); |
| (...skipping 197 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 |