Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: chrome/browser/local_discovery/privet_http_impl.cc

Issue 211843004: Tunnel PWGRasterConfig capability to the ticket and to the utility process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/pwg_raster_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
24 using namespace cloud_devices::printer;
25
23 namespace local_discovery { 26 namespace local_discovery {
24 27
25 namespace { 28 namespace {
26 const char kUrlPlaceHolder[] = "http://host/"; 29 const char kUrlPlaceHolder[] = "http://host/";
27 const char kPrivetRegisterActionArgName[] = "action"; 30 const char kPrivetRegisterActionArgName[] = "action";
28 const char kPrivetRegisterUserArgName[] = "user"; 31 const char kPrivetRegisterUserArgName[] = "user";
29 32
30 const char kPrivetURLKeyUserName[] = "user_name"; 33 const char kPrivetURLKeyUserName[] = "user_name";
31 const char kPrivetURLKeyClientName[] = "client_name"; 34 const char kPrivetURLKeyClientName[] = "client_name";
32 const char kPrivetURLKeyJobname[] = "job_name"; 35 const char kPrivetURLKeyJobname[] = "job_name";
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 509 }
507 510
508 StartInitialRequest(); 511 StartInitialRequest();
509 } else { 512 } else {
510 delegate_->OnPrivetPrintingError(this, -1); 513 delegate_->OnPrivetPrintingError(this, -1);
511 } 514 }
512 } 515 }
513 516
514 void PrivetLocalPrintOperationImpl::StartInitialRequest() { 517 void PrivetLocalPrintOperationImpl::StartInitialRequest() {
515 use_pdf_ = false; 518 use_pdf_ = false;
516 cloud_devices::printer::ContentTypesCapability content_types; 519 ContentTypesCapability content_types;
517 if (content_types.LoadFrom(capabilities_)) { 520 if (content_types.LoadFrom(capabilities_)) {
518 use_pdf_ = content_types.Contains(kPrivetContentTypePDF) || 521 use_pdf_ = content_types.Contains(kPrivetContentTypePDF) ||
519 content_types.Contains(kPrivetContentTypeAny); 522 content_types.Contains(kPrivetContentTypeAny);
520 } 523 }
521 524
522 if (use_pdf_) { 525 if (use_pdf_) {
523 StartPrinting(); 526 StartPrinting();
524 } else { 527 } else {
525 cloud_devices::printer::DpiCapability dpis; 528 DpiCapability dpis;
526 if (dpis.LoadFrom(capabilities_)) { 529 if (dpis.LoadFrom(capabilities_)) {
527 dpi_ = std::max(dpis.GetDefault().horizontal, dpis.GetDefault().vertical); 530 dpi_ = std::max(dpis.GetDefault().horizontal, dpis.GetDefault().vertical);
528 } 531 }
529 StartConvertToPWG(); 532 StartConvertToPWG();
530 } 533 }
531 } 534 }
532 535
533 void PrivetLocalPrintOperationImpl::DoCreatejob() { 536 void PrivetLocalPrintOperationImpl::DoCreatejob() {
534 current_response_ = base::Bind( 537 current_response_ = base::Bind(
535 &PrivetLocalPrintOperationImpl::OnCreatejobResponse, 538 &PrivetLocalPrintOperationImpl::OnCreatejobResponse,
536 base::Unretained(this)); 539 base::Unretained(this));
537 540
541 // Add PWG raster settings to ticket if they are supplied by the printer.
542 PwgRasterConfigCapability raster_capability;
543 PwgRasterConfigTicketItem raster_ticket_item;
544 if (raster_capability.LoadFrom(capabilities_)) {
545 raster_ticket_item.set_value(raster_capability.value());
546 raster_ticket_item.SaveTo(&ticket_);
547 }
548
538 url_fetcher_= privet_client_->CreateURLFetcher( 549 url_fetcher_= privet_client_->CreateURLFetcher(
539 CreatePrivetURL(kPrivetCreatejobPath), net::URLFetcher::POST, this); 550 CreatePrivetURL(kPrivetCreatejobPath), net::URLFetcher::POST, this);
540 url_fetcher_->SetUploadData(kPrivetContentTypeCJT, ticket_.ToString()); 551 url_fetcher_->SetUploadData(kPrivetContentTypeCJT, ticket_.ToString());
541 552
542 url_fetcher_->Start(); 553 url_fetcher_->Start();
543 } 554 }
544 555
545 void PrivetLocalPrintOperationImpl::DoSubmitdoc() { 556 void PrivetLocalPrintOperationImpl::DoSubmitdoc() {
546 current_response_ = base::Bind( 557 current_response_ = base::Bind(
547 &PrivetLocalPrintOperationImpl::OnSubmitdocResponse, 558 &PrivetLocalPrintOperationImpl::OnSubmitdocResponse,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 609 }
599 610
600 void PrivetLocalPrintOperationImpl::StartPrinting() { 611 void PrivetLocalPrintOperationImpl::StartPrinting() {
601 if (has_extended_workflow_ && jobid_.empty()) { 612 if (has_extended_workflow_ && jobid_.empty()) {
602 DoCreatejob(); 613 DoCreatejob();
603 } else { 614 } else {
604 DoSubmitdoc(); 615 DoSubmitdoc();
605 } 616 }
606 } 617 }
607 618
619 void PrivetLocalPrintOperationImpl::FillPwgRasterSettings(
620 printing::PwgRasterSettings* transform_settings) {
621 PwgRasterConfigCapability raster_capability;
622 // If the raster capability fails to load, raster_capability will contain
623 // the default value.
624 raster_capability.LoadFrom(capabilities_);
625
626 DuplexTicketItem duplex_item;
627 DuplexType duplex_value = NO_DUPLEX;
628
629 DocumentSheetBack document_sheet_back =
630 raster_capability.value().document_sheet_back;
631
632 if (duplex_item.LoadFrom(ticket_)) {
633 duplex_value = duplex_item.value();
634 }
635
636 transform_settings->odd_page_transform = printing::TRANSFORM_NORMAL;
637 switch (duplex_value) {
638 case NO_DUPLEX:
639 transform_settings->odd_page_transform = printing::TRANSFORM_NORMAL;
640 break;
641 case LONG_EDGE:
642 if (document_sheet_back == ROTATED) {
643 transform_settings->odd_page_transform = printing::TRANSFORM_ROTATE_180;
644 } else if (document_sheet_back == FLIPPED) {
645 transform_settings->odd_page_transform =
646 printing::TRANSFORM_FLIP_VERTICAL;
647 }
648 break;
649 case SHORT_EDGE:
650 if (document_sheet_back == MANUAL_TUMBLE) {
651 transform_settings->odd_page_transform = printing::TRANSFORM_ROTATE_180;
652 } else if (document_sheet_back == FLIPPED) {
653 transform_settings->odd_page_transform =
654 printing::TRANSFORM_FLIP_HORIZONTAL;
655 }
656 }
657
658 transform_settings->rotate_all_pages =
659 raster_capability.value().rotate_all_pages;
660
661 transform_settings->reverse_page_order =
662 raster_capability.value().reverse_order_streaming;
663 }
664
608 void PrivetLocalPrintOperationImpl::StartConvertToPWG() { 665 void PrivetLocalPrintOperationImpl::StartConvertToPWG() {
666 printing::PwgRasterSettings transform_settings;
667
668 FillPwgRasterSettings(&transform_settings);
669
609 if (!pwg_raster_converter_) 670 if (!pwg_raster_converter_)
610 pwg_raster_converter_ = PWGRasterConverter::CreateDefault(); 671 pwg_raster_converter_ = PWGRasterConverter::CreateDefault();
672
611 double scale = dpi_; 673 double scale = dpi_;
612 scale /= printing::kPointsPerInch; 674 scale /= printing::kPointsPerInch;
613 // Make vertical rectangle to optimize streaming to printer. Fix orientation 675 // Make vertical rectangle to optimize streaming to printer. Fix orientation
614 // by autorotate. 676 // by autorotate.
615 gfx::Rect area(std::min(page_size_.width(), page_size_.height()) * scale, 677 gfx::Rect area(std::min(page_size_.width(), page_size_.height()) * scale,
616 std::max(page_size_.width(), page_size_.height()) * scale); 678 std::max(page_size_.width(), page_size_.height()) * scale);
617 pwg_raster_converter_->Start( 679 pwg_raster_converter_->Start(
618 data_, printing::PdfRenderSettings(area, dpi_, true), 680 data_,
681 printing::PdfRenderSettings(area, dpi_, true),
682 transform_settings,
619 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, 683 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted,
620 base::Unretained(this))); 684 base::Unretained(this)));
621 } 685 }
622 686
623 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse( 687 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse(
624 bool has_error, 688 bool has_error,
625 const base::DictionaryValue* value) { 689 const base::DictionaryValue* value) {
626 std::string error; 690 std::string error;
627 // This error is only relevant in the case of extended workflow: 691 // This error is only relevant in the case of extended workflow:
628 // If the print job ID is invalid, retry createjob and submitdoc, 692 // If the print job ID is invalid, retry createjob and submitdoc,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 TokenCallbackVector token_callbacks; 924 TokenCallbackVector token_callbacks;
861 token_callbacks_.swap(token_callbacks); 925 token_callbacks_.swap(token_callbacks);
862 926
863 for (TokenCallbackVector::iterator i = token_callbacks.begin(); 927 for (TokenCallbackVector::iterator i = token_callbacks.begin();
864 i != token_callbacks.end(); i++) { 928 i != token_callbacks.end(); i++) {
865 i->Run(token); 929 i->Run(token);
866 } 930 }
867 } 931 }
868 932
869 } // namespace local_discovery 933 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.h ('k') | chrome/browser/local_discovery/privet_http_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698