diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-15 03:19:08 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-15 03:19:08 +0000 |
commit | 726127fdb3582f187eda5595fab13eb49de11fb2 (patch) | |
tree | 35099ebe437dfd3c8b13f7dd237966cc46fea5f5 | |
parent | 58956c2e50e5034734a9c79776dd37bc5af23620 (diff) | |
download | chromium_src-726127fdb3582f187eda5595fab13eb49de11fb2.zip chromium_src-726127fdb3582f187eda5595fab13eb49de11fb2.tar.gz chromium_src-726127fdb3582f187eda5595fab13eb49de11fb2.tar.bz2 |
"Privet" Printing reads DPI for PWG raster conversion from device capabilities.
BUG=343239
Review URL: https://codereview.chromium.org/166283002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251489 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/local_discovery/DEPS | 4 | ||||
-rw-r--r-- | chrome/browser/local_discovery/privet_http.h | 3 | ||||
-rw-r--r-- | chrome/browser/local_discovery/privet_http_impl.cc | 65 | ||||
-rw-r--r-- | chrome/browser/local_discovery/privet_http_impl.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview/print_preview_handler.cc | 15 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 1 | ||||
-rw-r--r-- | components/cloud_devices/cloud_device_description.cc | 17 | ||||
-rw-r--r-- | components/cloud_devices/cloud_device_description.h | 1 |
8 files changed, 58 insertions, 54 deletions
diff --git a/chrome/browser/local_discovery/DEPS b/chrome/browser/local_discovery/DEPS index cc56ec5b..28fe1f3 100644 --- a/chrome/browser/local_discovery/DEPS +++ b/chrome/browser/local_discovery/DEPS @@ -1,3 +1,7 @@ +include_rules = [ + "+components/cloud_devices", +] + specific_include_rules = { # For tests, it's fine to include utility process code. 'test_service_discovery_client\.cc': [ diff --git a/chrome/browser/local_discovery/privet_http.h b/chrome/browser/local_discovery/privet_http.h index 59a2cfad..92a6521 100644 --- a/chrome/browser/local_discovery/privet_http.h +++ b/chrome/browser/local_discovery/privet_http.h @@ -148,8 +148,7 @@ class PrivetLocalPrintOperation { // to Google Cloud Print. virtual void SetOffline(bool offline) = 0; // Document page size. - virtual void SetConversionSettings( - const printing::PdfRenderSettings& conversion_settings) = 0; + virtual void SetPageSize(const gfx::Size& page_size) = 0; // For testing, inject an alternative PWG raster converter. virtual void SetPWGRasterConverterForTesting( diff --git a/chrome/browser/local_discovery/privet_http_impl.cc b/chrome/browser/local_discovery/privet_http_impl.cc index 734308b..a6dcab7 100644 --- a/chrome/browser/local_discovery/privet_http_impl.cc +++ b/chrome/browser/local_discovery/privet_http_impl.cc @@ -13,7 +13,9 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "chrome/browser/local_discovery/privet_constants.h" +#include "components/cloud_devices/printer_description.h" #include "net/base/url_util.h" +#include "printing/units.h" #include "url/gurl.h" namespace local_discovery { @@ -39,11 +41,6 @@ const char kPrivetStorageListPath[] = "/privet/storage/list"; const char kPrivetStorageContentPath[] = "/privet/storage/content"; const char kPrivetStorageParamPathFormat[] = "path=%s"; -const char kPrivetCDDKeySupportedContentTypes[] = - "printer.supported_content_type"; - -const char kPrivetCDDKeyContentType[] = "content_type"; - const char kPrivetKeyJobID[] = "job_id"; const int kPrivetCancelationTimeoutSeconds = 3; @@ -455,9 +452,15 @@ bool PrivetDataReadOperationImpl::OnRawData(PrivetURLFetcher* fetcher, PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl( PrivetHTTPClientImpl* privet_client, PrivetLocalPrintOperation::Delegate* delegate) - : privet_client_(privet_client), delegate_(delegate), - use_pdf_(false), has_capabilities_(false), has_extended_workflow_(false), - started_(false), offline_(false), invalid_job_retries_(0), + : privet_client_(privet_client), + delegate_(delegate), + use_pdf_(false), + has_capabilities_(false), + has_extended_workflow_(false), + started_(false), + offline_(false), + dpi_(printing::kDefaultPdfDpi), + invalid_job_retries_(0), weak_factory_(this) { } @@ -514,7 +517,7 @@ void PrivetLocalPrintOperationImpl::StartInitialRequest() { if (has_capabilities_) { GetCapabilities(); } else { - // Since we have no capabiltties, the only reasonable format we can + // Since we have no capabilities, the only reasonable format we can // request is PWG Raster. use_pdf_ = false; StartConvertToPWG(); @@ -606,9 +609,14 @@ void PrivetLocalPrintOperationImpl::StartPrinting() { void PrivetLocalPrintOperationImpl::StartConvertToPWG() { if (!pwg_raster_converter_) pwg_raster_converter_ = PWGRasterConverter::CreateDefault(); + double scale = dpi_; + scale /= printing::kPointsPerInch; + // Make vertical rectangle to optimize streaming to printer. Fix orientation + // by autorotate. + gfx::Rect area(std::min(page_size_.width(), page_size_.height()) * scale, + std::max(page_size_.width(), page_size_.height()) * scale); pwg_raster_converter_->Start( - data_, - conversion_settings_, + data_, printing::PdfRenderSettings(area, dpi_, true), base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, base::Unretained(this))); } @@ -621,28 +629,26 @@ void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse( return; } - const base::ListValue* supported_content_types; - use_pdf_ = false; + cloud_devices::CloudDeviceDescription description; + if (!description.InitFromDictionary(make_scoped_ptr(value->DeepCopy()))) { + delegate_->OnPrivetPrintingError(this, 200); + return; + } - if (value->GetList(kPrivetCDDKeySupportedContentTypes, - &supported_content_types)) { - for (size_t i = 0; i < supported_content_types->GetSize(); i++) { - const base::DictionaryValue* content_type_value; - std::string content_type; - - if (supported_content_types->GetDictionary(i, &content_type_value) && - content_type_value->GetString(kPrivetCDDKeyContentType, - &content_type) && - (content_type == kPrivetContentTypePDF || - content_type == kPrivetContentTypeAny) ) { - use_pdf_ = true; - } - } + use_pdf_ = false; + cloud_devices::printer::ContentTypesCapability content_types; + if (content_types.LoadFrom(description)) { + use_pdf_ = content_types.Contains(kPrivetContentTypePDF) || + content_types.Contains(kPrivetContentTypeAny); } if (use_pdf_) { StartPrinting(); } else { + cloud_devices::printer::DpiCapability dpis; + if (dpis.LoadFrom(description)) { + dpi_ = std::max(dpis.GetDefault().horizontal, dpis.GetDefault().vertical); + } StartConvertToPWG(); } } @@ -767,10 +773,9 @@ void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { offline_ = offline; } -void PrivetLocalPrintOperationImpl::SetConversionSettings( - const printing::PdfRenderSettings& conversion_settings) { +void PrivetLocalPrintOperationImpl::SetPageSize(const gfx::Size& page_size) { DCHECK(!started_); - conversion_settings_ = conversion_settings; + page_size_ = page_size; } void PrivetLocalPrintOperationImpl::SetPWGRasterConverterForTesting( diff --git a/chrome/browser/local_discovery/privet_http_impl.h b/chrome/browser/local_discovery/privet_http_impl.h index d7699c0..558b971 100644 --- a/chrome/browser/local_discovery/privet_http_impl.h +++ b/chrome/browser/local_discovery/privet_http_impl.h @@ -212,8 +212,7 @@ class PrivetLocalPrintOperationImpl virtual void SetOffline(bool offline) OVERRIDE; - virtual void SetConversionSettings( - const printing::PdfRenderSettings& conversion_settings) OVERRIDE; + virtual void SetPageSize(const gfx::Size& page_size) OVERRIDE; virtual void SetPWGRasterConverterForTesting( scoped_ptr<PWGRasterConverter> pwg_raster_converter) OVERRIDE; @@ -264,7 +263,8 @@ class PrivetLocalPrintOperationImpl bool has_extended_workflow_; bool started_; bool offline_; - printing::PdfRenderSettings conversion_settings_; + gfx::Size page_size_; + int dpi_; std::string user_; std::string jobname_; diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc index d1f9025..9a586c4 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc @@ -1450,19 +1450,8 @@ void PrintPreviewHandler::StartPrivetLocalPrint( return; } - privet_local_print_operation_->SetJobname( - base::UTF16ToUTF8(title)); - - const int dpi = printing::kDefaultPdfDpi; - double scale = dpi; - scale /= printing::kPointsPerInch; - // Make vertical rectangle to optimize streaming to printer. Fix orientation - // by autorotate. - gfx::Rect area(std::min(page_size.width(), page_size.height()) * scale, - std::max(page_size.width(), page_size.height()) * scale); - privet_local_print_operation_->SetConversionSettings( - printing::PdfRenderSettings(area, dpi, true)); - + privet_local_print_operation_->SetJobname(base::UTF16ToUTF8(title)); + privet_local_print_operation_->SetPageSize(page_size); privet_local_print_operation_->SetData(data); Profile* profile = Profile::FromWebUI(web_ui()); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 76fc3ac..2e83106 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -29,6 +29,7 @@ 'suggestions_proto', '../components/component_strings.gyp:component_strings', '../components/components.gyp:autofill_core_browser', + '../components/components.gyp:cloud_devices', '../components/components.gyp:encryptor', '../components/components.gyp:navigation_metrics', '../components/components.gyp:password_manager_core_common', diff --git a/components/cloud_devices/cloud_device_description.cc b/components/cloud_devices/cloud_device_description.cc index 124bb49..baf544d 100644 --- a/components/cloud_devices/cloud_device_description.cc +++ b/components/cloud_devices/cloud_device_description.cc @@ -24,19 +24,24 @@ void CloudDeviceDescription::Reset() { root_->SetString(json::kVersion, json::kVersion10); } -bool CloudDeviceDescription::InitFromString(const std::string& json) { +bool CloudDeviceDescription::InitFromDictionary( + scoped_ptr<base::DictionaryValue> root) { + if (!root) + return false; Reset(); + root_ = root.Pass(); + std::string version; + root_->GetString(json::kVersion, &version); + return version == json::kVersion10; +} +bool CloudDeviceDescription::InitFromString(const std::string& json) { scoped_ptr<base::Value> parsed(base::JSONReader::Read(json)); base::DictionaryValue* description = NULL; if (!parsed || !parsed->GetAsDictionary(&description)) return false; - root_.reset(description); ignore_result(parsed.release()); - - std::string version; - description->GetString(json::kVersion, &version); - return version == json::kVersion10; + return InitFromDictionary(make_scoped_ptr(description)); } std::string CloudDeviceDescription::ToString() const { diff --git a/components/cloud_devices/cloud_device_description.h b/components/cloud_devices/cloud_device_description.h index ec59c87..d4ce081 100644 --- a/components/cloud_devices/cloud_device_description.h +++ b/components/cloud_devices/cloud_device_description.h @@ -26,6 +26,7 @@ class CloudDeviceDescription { void Reset(); + bool InitFromDictionary(scoped_ptr<base::DictionaryValue> root); bool InitFromString(const std::string& json); std::string ToString() const; |