Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/local_discovery/privet_http_impl.h" | 5 #include "chrome/browser/local_discovery/privet_http_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/local_discovery/privet_constants.h" | 16 #include "chrome/browser/local_discovery/privet_constants.h" |
| 17 #include "components/cloud_devices/printer_description.h" | 17 #include "components/cloud_devices/printer_description.h" |
| 18 #include "net/base/url_util.h" | 18 #include "net/base/url_util.h" |
| 19 #include "printing/bitmap_transform_settings.h" | |
| 19 #include "printing/units.h" | 20 #include "printing/units.h" |
| 20 #include "ui/gfx/text_elider.h" | 21 #include "ui/gfx/text_elider.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace local_discovery { | 24 namespace local_discovery { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 const char kUrlPlaceHolder[] = "http://host/"; | 27 const char kUrlPlaceHolder[] = "http://host/"; |
| 27 const char kPrivetRegisterActionArgName[] = "action"; | 28 const char kPrivetRegisterActionArgName[] = "action"; |
| 28 const char kPrivetRegisterUserArgName[] = "user"; | 29 const char kPrivetRegisterUserArgName[] = "user"; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 } | 529 } |
| 529 StartConvertToPWG(); | 530 StartConvertToPWG(); |
| 530 } | 531 } |
| 531 } | 532 } |
| 532 | 533 |
| 533 void PrivetLocalPrintOperationImpl::DoCreatejob() { | 534 void PrivetLocalPrintOperationImpl::DoCreatejob() { |
| 534 current_response_ = base::Bind( | 535 current_response_ = base::Bind( |
| 535 &PrivetLocalPrintOperationImpl::OnCreatejobResponse, | 536 &PrivetLocalPrintOperationImpl::OnCreatejobResponse, |
| 536 base::Unretained(this)); | 537 base::Unretained(this)); |
| 537 | 538 |
| 539 // Add PWG raster settings to ticket if they are supplied by the printer. | |
| 540 cloud_devices::printer::PwgRasterConfigCapability raster_capability; | |
| 541 cloud_devices::printer::PwgRasterConfigTicketItem raster_ticket_item; | |
| 542 if (raster_capability.LoadFrom(capabilities_)) { | |
| 543 raster_ticket_item.set_value(raster_capability.value()); | |
| 544 raster_ticket_item.SaveTo(&ticket_); | |
| 545 } | |
| 546 | |
| 538 url_fetcher_= privet_client_->CreateURLFetcher( | 547 url_fetcher_= privet_client_->CreateURLFetcher( |
| 539 CreatePrivetURL(kPrivetCreatejobPath), net::URLFetcher::POST, this); | 548 CreatePrivetURL(kPrivetCreatejobPath), net::URLFetcher::POST, this); |
| 540 url_fetcher_->SetUploadData(kPrivetContentTypeCJT, ticket_.ToString()); | 549 url_fetcher_->SetUploadData(kPrivetContentTypeCJT, ticket_.ToString()); |
| 541 | 550 |
| 542 url_fetcher_->Start(); | 551 url_fetcher_->Start(); |
| 543 } | 552 } |
| 544 | 553 |
| 545 void PrivetLocalPrintOperationImpl::DoSubmitdoc() { | 554 void PrivetLocalPrintOperationImpl::DoSubmitdoc() { |
| 546 current_response_ = base::Bind( | 555 current_response_ = base::Bind( |
| 547 &PrivetLocalPrintOperationImpl::OnSubmitdocResponse, | 556 &PrivetLocalPrintOperationImpl::OnSubmitdocResponse, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 } | 607 } |
| 599 | 608 |
| 600 void PrivetLocalPrintOperationImpl::StartPrinting() { | 609 void PrivetLocalPrintOperationImpl::StartPrinting() { |
| 601 if (has_extended_workflow_ && jobid_.empty()) { | 610 if (has_extended_workflow_ && jobid_.empty()) { |
| 602 DoCreatejob(); | 611 DoCreatejob(); |
| 603 } else { | 612 } else { |
| 604 DoSubmitdoc(); | 613 DoSubmitdoc(); |
| 605 } | 614 } |
| 606 } | 615 } |
| 607 | 616 |
| 617 void PrivetLocalPrintOperationImpl::FillBitmapTransformSettings( | |
| 618 printing::BitmapTransformSettings* transform_settings) { | |
| 619 cloud_devices::printer::PwgRasterConfigCapability raster_capability; | |
|
Vitaly Buka (NO REVIEWS)
2014/03/26 00:31:12
using namespace cloud_devices::printer;
Noam Samuel
2014/03/26 18:54:29
Done.
| |
| 620 // If the raster capability fails to load, raster_capability will contain | |
| 621 // the default value. | |
| 622 raster_capability.LoadFrom(capabilities_); | |
| 623 | |
| 624 cloud_devices::printer::DuplexTicketItem duplex_item; | |
| 625 cloud_devices::printer::DuplexType duplex_value = | |
| 626 cloud_devices::printer::NO_DUPLEX; | |
| 627 | |
| 628 cloud_devices::printer::DocumentSheetBack document_sheet_back = | |
| 629 raster_capability.value().document_sheet_back; | |
| 630 | |
| 631 if (duplex_item.LoadFrom(ticket_)) { | |
| 632 duplex_value = duplex_item.value(); | |
| 633 } | |
| 634 | |
| 635 transform_settings->odd_page_transform = printing::TRANSFORM_NORMAL; | |
| 636 switch (duplex_value) { | |
| 637 case cloud_devices::printer::NO_DUPLEX: | |
| 638 transform_settings->odd_page_transform = printing::TRANSFORM_NORMAL; | |
| 639 break; | |
| 640 case cloud_devices::printer::LONG_EDGE: | |
| 641 if (document_sheet_back == cloud_devices::printer::ROTATED) { | |
| 642 transform_settings->odd_page_transform = printing::TRANSFORM_ROTATE_180; | |
| 643 } else if (document_sheet_back == cloud_devices::printer::FLIPPED) { | |
| 644 transform_settings->odd_page_transform = | |
| 645 printing::TRANSFORM_FLIP_VERTICAL; | |
| 646 } | |
| 647 break; | |
| 648 case cloud_devices::printer::SHORT_EDGE: | |
| 649 if (document_sheet_back == cloud_devices::printer::MANUAL_TUMBLE) { | |
| 650 transform_settings->odd_page_transform = printing::TRANSFORM_ROTATE_180; | |
| 651 } else if (document_sheet_back == cloud_devices::printer::FLIPPED) { | |
| 652 transform_settings->odd_page_transform = | |
| 653 printing::TRANSFORM_FLIP_HORIZONTAL; | |
| 654 } | |
| 655 } | |
| 656 | |
| 657 transform_settings->rotate_all_pages = | |
| 658 raster_capability.value().rotate_all_pages; | |
| 659 | |
| 660 transform_settings->reverse_page_order = | |
| 661 raster_capability.value().reverse_order_streaming; | |
| 662 } | |
| 663 | |
| 608 void PrivetLocalPrintOperationImpl::StartConvertToPWG() { | 664 void PrivetLocalPrintOperationImpl::StartConvertToPWG() { |
| 665 printing::BitmapTransformSettings transform_settings; | |
| 666 | |
| 667 FillBitmapTransformSettings(&transform_settings); | |
| 668 | |
| 609 if (!pwg_raster_converter_) | 669 if (!pwg_raster_converter_) |
| 610 pwg_raster_converter_ = PWGRasterConverter::CreateDefault(); | 670 pwg_raster_converter_ = PWGRasterConverter::CreateDefault(); |
| 671 | |
| 611 double scale = dpi_; | 672 double scale = dpi_; |
| 612 scale /= printing::kPointsPerInch; | 673 scale /= printing::kPointsPerInch; |
| 613 // Make vertical rectangle to optimize streaming to printer. Fix orientation | 674 // Make vertical rectangle to optimize streaming to printer. Fix orientation |
| 614 // by autorotate. | 675 // by autorotate. |
| 615 gfx::Rect area(std::min(page_size_.width(), page_size_.height()) * scale, | 676 gfx::Rect area(std::min(page_size_.width(), page_size_.height()) * scale, |
| 616 std::max(page_size_.width(), page_size_.height()) * scale); | 677 std::max(page_size_.width(), page_size_.height()) * scale); |
| 617 pwg_raster_converter_->Start( | 678 pwg_raster_converter_->Start( |
| 618 data_, printing::PdfRenderSettings(area, dpi_, true), | 679 data_, |
| 680 printing::PdfRenderSettings(area, dpi_, true), | |
| 681 transform_settings, | |
| 619 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, | 682 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, |
| 620 base::Unretained(this))); | 683 base::Unretained(this))); |
| 621 } | 684 } |
| 622 | 685 |
| 623 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse( | 686 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse( |
| 624 bool has_error, | 687 bool has_error, |
| 625 const base::DictionaryValue* value) { | 688 const base::DictionaryValue* value) { |
| 626 std::string error; | 689 std::string error; |
| 627 // This error is only relevant in the case of extended workflow: | 690 // This error is only relevant in the case of extended workflow: |
| 628 // If the print job ID is invalid, retry createjob and submitdoc, | 691 // If the print job ID is invalid, retry createjob and submitdoc, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 TokenCallbackVector token_callbacks; | 923 TokenCallbackVector token_callbacks; |
| 861 token_callbacks_.swap(token_callbacks); | 924 token_callbacks_.swap(token_callbacks); |
| 862 | 925 |
| 863 for (TokenCallbackVector::iterator i = token_callbacks.begin(); | 926 for (TokenCallbackVector::iterator i = token_callbacks.begin(); |
| 864 i != token_callbacks.end(); i++) { | 927 i != token_callbacks.end(); i++) { |
| 865 i->Run(token); | 928 i->Run(token); |
| 866 } | 929 } |
| 867 } | 930 } |
| 868 | 931 |
| 869 } // namespace local_discovery | 932 } // namespace local_discovery |
| OLD | NEW |