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 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); | 715 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); |
716 ReportUserActionHistogram(PRINT_TO_PDF); | 716 ReportUserActionHistogram(PRINT_TO_PDF); |
717 PrintToPdf(); | 717 PrintToPdf(); |
718 return; | 718 return; |
719 } | 719 } |
720 | 720 |
721 #if defined(ENABLE_MDNS) | 721 #if defined(ENABLE_MDNS) |
722 if (print_with_privet && PrivetPrintingEnabled()) { | 722 if (print_with_privet && PrivetPrintingEnabled()) { |
723 std::string printer_name; | 723 std::string printer_name; |
724 std::string print_ticket; | 724 std::string print_ticket; |
| 725 std::string capabilities; |
725 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count); | 726 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count); |
726 ReportUserActionHistogram(PRINT_WITH_PRIVET); | 727 ReportUserActionHistogram(PRINT_WITH_PRIVET); |
727 | 728 |
728 int width = 0; | 729 int width = 0; |
729 int height = 0; | 730 int height = 0; |
730 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || | 731 if (!settings->GetString(printing::kSettingDeviceName, &printer_name) || |
731 !settings->GetString(printing::kSettingTicket, &print_ticket) || | 732 !settings->GetString(printing::kSettingTicket, &print_ticket) || |
| 733 !settings->GetString(printing::kSettingCapabilities, &capabilities) || |
732 !settings->GetInteger(printing::kSettingPageWidth, &width) || | 734 !settings->GetInteger(printing::kSettingPageWidth, &width) || |
733 !settings->GetInteger(printing::kSettingPageHeight, &height) || | 735 !settings->GetInteger(printing::kSettingPageHeight, &height) || |
734 width <= 0 || height <=0) { | 736 width <= 0 || height <= 0) { |
735 NOTREACHED(); | 737 NOTREACHED(); |
736 base::FundamentalValue http_code_value(-1); | 738 base::FundamentalValue http_code_value(-1); |
737 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 739 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); |
738 return; | 740 return; |
739 } | 741 } |
740 | 742 |
741 PrintToPrivetPrinter(printer_name, print_ticket, gfx::Size(width, height)); | 743 PrintToPrivetPrinter( |
| 744 printer_name, print_ticket, capabilities, gfx::Size(width, height)); |
742 return; | 745 return; |
743 } | 746 } |
744 #endif | 747 #endif |
745 | 748 |
746 scoped_refptr<base::RefCountedBytes> data; | 749 scoped_refptr<base::RefCountedBytes> data; |
747 base::string16 title; | 750 base::string16 title; |
748 if (!GetPreviewDataAndTitle(&data, &title)) { | 751 if (!GetPreviewDataAndTitle(&data, &title)) { |
749 // Nothing to print, no preview available. | 752 // Nothing to print, no preview available. |
750 return; | 753 return; |
751 } | 754 } |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 privet_capabilities_operation_.reset(); | 1399 privet_capabilities_operation_.reset(); |
1397 privet_http_client_ = http_client.Pass(); | 1400 privet_http_client_ = http_client.Pass(); |
1398 | 1401 |
1399 privet_http_resolution_.reset(); | 1402 privet_http_resolution_.reset(); |
1400 | 1403 |
1401 return true; | 1404 return true; |
1402 } | 1405 } |
1403 | 1406 |
1404 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( | 1407 void PrintPreviewHandler::PrivetLocalPrintUpdateClient( |
1405 std::string print_ticket, | 1408 std::string print_ticket, |
| 1409 std::string capabilities, |
1406 gfx::Size page_size, | 1410 gfx::Size page_size, |
1407 scoped_ptr<local_discovery::PrivetHTTPClient> http_client) { | 1411 scoped_ptr<local_discovery::PrivetHTTPClient> http_client) { |
1408 if (!PrivetUpdateClient(http_client.Pass())) | 1412 if (!PrivetUpdateClient(http_client.Pass())) |
1409 return; | 1413 return; |
1410 | 1414 |
1411 StartPrivetLocalPrint(print_ticket, page_size); | 1415 StartPrivetLocalPrint(print_ticket, capabilities, page_size); |
1412 } | 1416 } |
1413 | 1417 |
1414 void PrintPreviewHandler::StartPrivetLocalPrint( | 1418 void PrintPreviewHandler::StartPrivetLocalPrint(const std::string& print_ticket, |
1415 const std::string& print_ticket, | 1419 const std::string& capabilities, |
1416 const gfx::Size& page_size) { | 1420 const gfx::Size& page_size) { |
1417 privet_local_print_operation_ = | 1421 privet_local_print_operation_ = |
1418 privet_http_client_->CreateLocalPrintOperation(this); | 1422 privet_http_client_->CreateLocalPrintOperation(this); |
1419 | 1423 |
1420 privet_local_print_operation_->SetTicket(print_ticket); | 1424 privet_local_print_operation_->SetTicket(print_ticket); |
| 1425 privet_local_print_operation_->SetCapabilities(capabilities); |
1421 | 1426 |
1422 scoped_refptr<base::RefCountedBytes> data; | 1427 scoped_refptr<base::RefCountedBytes> data; |
1423 base::string16 title; | 1428 base::string16 title; |
1424 | 1429 |
1425 if (!GetPreviewDataAndTitle(&data, &title)) { | 1430 if (!GetPreviewDataAndTitle(&data, &title)) { |
1426 base::FundamentalValue http_code_value(-1); | 1431 base::FundamentalValue http_code_value(-1); |
1427 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 1432 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); |
1428 return; | 1433 return; |
1429 } | 1434 } |
1430 | 1435 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 } | 1479 } |
1475 | 1480 |
1476 void PrintPreviewHandler::SendPrivetCapabilitiesError( | 1481 void PrintPreviewHandler::SendPrivetCapabilitiesError( |
1477 const std::string& device_name) { | 1482 const std::string& device_name) { |
1478 base::StringValue name_value(device_name); | 1483 base::StringValue name_value(device_name); |
1479 web_ui()->CallJavascriptFunction( | 1484 web_ui()->CallJavascriptFunction( |
1480 "failedToGetPrivetPrinterCapabilities", | 1485 "failedToGetPrivetPrinterCapabilities", |
1481 name_value); | 1486 name_value); |
1482 } | 1487 } |
1483 | 1488 |
1484 void PrintPreviewHandler::PrintToPrivetPrinter( | 1489 void PrintPreviewHandler::PrintToPrivetPrinter(const std::string& device_name, |
1485 const std::string& device_name, | 1490 const std::string& ticket, |
1486 const std::string& ticket, | 1491 const std::string& capabilities, |
1487 const gfx::Size& page_size) { | 1492 const gfx::Size& page_size) { |
1488 CreatePrivetHTTP( | 1493 CreatePrivetHTTP( |
1489 device_name, | 1494 device_name, |
1490 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, | 1495 base::Bind(&PrintPreviewHandler::PrivetLocalPrintUpdateClient, |
1491 base::Unretained(this), ticket, page_size)); | 1496 base::Unretained(this), |
| 1497 ticket, |
| 1498 capabilities, |
| 1499 page_size)); |
1492 } | 1500 } |
1493 | 1501 |
1494 bool PrintPreviewHandler::CreatePrivetHTTP( | 1502 bool PrintPreviewHandler::CreatePrivetHTTP( |
1495 const std::string& name, | 1503 const std::string& name, |
1496 const local_discovery::PrivetHTTPAsynchronousFactory::ResultCallback& | 1504 const local_discovery::PrivetHTTPAsynchronousFactory::ResultCallback& |
1497 callback) { | 1505 callback) { |
1498 const local_discovery::DeviceDescription* device_description = | 1506 const local_discovery::DeviceDescription* device_description = |
1499 printer_lister_->GetDeviceDescription(name); | 1507 printer_lister_->GetDeviceDescription(name); |
1500 | 1508 |
1501 if (!device_description) { | 1509 if (!device_description) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 printer_value->SetString("name", description.name); | 1547 printer_value->SetString("name", description.name); |
1540 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); | 1548 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); |
1541 printer_value->SetBoolean( | 1549 printer_value->SetBoolean( |
1542 "isUnregistered", | 1550 "isUnregistered", |
1543 description.id.empty() && | 1551 description.id.empty() && |
1544 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); | 1552 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); |
1545 printer_value->SetString("cloudID", description.id); | 1553 printer_value->SetString("cloudID", description.id); |
1546 } | 1554 } |
1547 | 1555 |
1548 #endif | 1556 #endif |
OLD | NEW |