| 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 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 StartPrivetLocalPrint(print_ticket); | 1415 StartPrivetLocalPrint(print_ticket); |
| 1416 } | 1416 } |
| 1417 | 1417 |
| 1418 void PrintPreviewHandler::StartPrivetLocalPrint( | 1418 void PrintPreviewHandler::StartPrivetLocalPrint( |
| 1419 const std::string& print_ticket) { | 1419 const std::string& print_ticket) { |
| 1420 privet_local_print_operation_ = | 1420 privet_local_print_operation_ = |
| 1421 privet_http_client_->CreateLocalPrintOperation(this); | 1421 privet_http_client_->CreateLocalPrintOperation(this); |
| 1422 | 1422 |
| 1423 privet_local_print_operation_->SetTicket(print_ticket); | 1423 privet_local_print_operation_->SetTicket(print_ticket); |
| 1424 | 1424 |
| 1425 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 1425 scoped_refptr<base::RefCountedBytes> data; |
| 1426 web_ui()->GetController()); | 1426 string16 title; |
| 1427 |
| 1428 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 1429 base::FundamentalValue http_code_value(-1); |
| 1430 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); |
| 1431 return; |
| 1432 } |
| 1433 |
| 1427 privet_local_print_operation_->SetJobname( | 1434 privet_local_print_operation_->SetJobname( |
| 1428 base::UTF16ToUTF8(print_preview_ui->initiator_title())); | 1435 base::UTF16ToUTF8(title)); |
| 1436 |
| 1437 privet_local_print_operation_->SetData(data); |
| 1429 | 1438 |
| 1430 Profile* profile = Profile::FromWebUI(web_ui()); | 1439 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1431 SigninManagerBase* signin_manager = | 1440 SigninManagerBase* signin_manager = |
| 1432 SigninManagerFactory::GetForProfileIfExists(profile); | 1441 SigninManagerFactory::GetForProfileIfExists(profile); |
| 1433 | 1442 |
| 1434 if (signin_manager) { | 1443 if (signin_manager) { |
| 1435 privet_local_print_operation_->SetUsername( | 1444 privet_local_print_operation_->SetUsername( |
| 1436 signin_manager->GetAuthenticatedUsername()); | 1445 signin_manager->GetAuthenticatedUsername()); |
| 1437 } | 1446 } |
| 1438 | 1447 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1506 Profile::FromWebUI(web_ui())->GetRequestContext()); | 1515 Profile::FromWebUI(web_ui())->GetRequestContext()); |
| 1507 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP( | 1516 privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP( |
| 1508 name, | 1517 name, |
| 1509 device_description->address, | 1518 device_description->address, |
| 1510 callback); | 1519 callback); |
| 1511 privet_http_resolution_->Start(); | 1520 privet_http_resolution_->Start(); |
| 1512 | 1521 |
| 1513 return true; | 1522 return true; |
| 1514 } | 1523 } |
| 1515 | 1524 |
| 1516 void PrintPreviewHandler::OnPrivetPrintingRequestPDF( | |
| 1517 const local_discovery::PrivetLocalPrintOperation* print_operation) { | |
| 1518 scoped_refptr<base::RefCountedBytes> data; | |
| 1519 string16 title; | |
| 1520 | |
| 1521 if (!GetPreviewDataAndTitle(&data, &title)) { | |
| 1522 base::FundamentalValue http_code_value(-1); | |
| 1523 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | |
| 1524 return; | |
| 1525 } | |
| 1526 | |
| 1527 // TODO(noamsml): Move data into request without copying it? | |
| 1528 std::string data_str((const char*)data->front(), data->size()); | |
| 1529 | |
| 1530 privet_local_print_operation_->SendData(data_str); | |
| 1531 } | |
| 1532 | |
| 1533 void PrintPreviewHandler::OnPrivetPrintingRequestPWGRaster( | |
| 1534 const local_discovery::PrivetLocalPrintOperation* print_operation) { | |
| 1535 NOTIMPLEMENTED(); | |
| 1536 } | |
| 1537 | |
| 1538 void PrintPreviewHandler::OnPrivetPrintingDone( | 1525 void PrintPreviewHandler::OnPrivetPrintingDone( |
| 1539 const local_discovery::PrivetLocalPrintOperation* print_operation) { | 1526 const local_discovery::PrivetLocalPrintOperation* print_operation) { |
| 1540 ClosePreviewDialog(); | 1527 ClosePreviewDialog(); |
| 1541 } | 1528 } |
| 1542 | 1529 |
| 1543 void PrintPreviewHandler::OnPrivetPrintingError( | 1530 void PrintPreviewHandler::OnPrivetPrintingError( |
| 1544 const local_discovery::PrivetLocalPrintOperation* print_operation, | 1531 const local_discovery::PrivetLocalPrintOperation* print_operation, |
| 1545 int http_code) { | 1532 int http_code) { |
| 1546 base::FundamentalValue http_code_value(http_code); | 1533 base::FundamentalValue http_code_value(http_code); |
| 1547 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 1534 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); |
| 1548 } | 1535 } |
| 1549 | 1536 |
| 1550 void PrintPreviewHandler::FillPrinterDescription( | 1537 void PrintPreviewHandler::FillPrinterDescription( |
| 1551 const std::string& name, | 1538 const std::string& name, |
| 1552 const local_discovery::DeviceDescription& description, | 1539 const local_discovery::DeviceDescription& description, |
| 1553 base::DictionaryValue* printer_value) { | 1540 base::DictionaryValue* printer_value) { |
| 1554 printer_value->SetString("serviceName", name); | 1541 printer_value->SetString("serviceName", name); |
| 1555 printer_value->SetString("name", description.name); | 1542 printer_value->SetString("name", description.name); |
| 1556 } | 1543 } |
| 1557 | 1544 |
| 1558 #endif | 1545 #endif |
| OLD | NEW |