"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
parent 58956c2e
include_rules = [
"+components/cloud_devices",
]
specific_include_rules = { specific_include_rules = {
# For tests, it's fine to include utility process code. # For tests, it's fine to include utility process code.
'test_service_discovery_client\.cc': [ 'test_service_discovery_client\.cc': [
......
...@@ -148,8 +148,7 @@ class PrivetLocalPrintOperation { ...@@ -148,8 +148,7 @@ class PrivetLocalPrintOperation {
// to Google Cloud Print. // to Google Cloud Print.
virtual void SetOffline(bool offline) = 0; virtual void SetOffline(bool offline) = 0;
// Document page size. // Document page size.
virtual void SetConversionSettings( virtual void SetPageSize(const gfx::Size& page_size) = 0;
const printing::PdfRenderSettings& conversion_settings) = 0;
// For testing, inject an alternative PWG raster converter. // For testing, inject an alternative PWG raster converter.
virtual void SetPWGRasterConverterForTesting( virtual void SetPWGRasterConverterForTesting(
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/local_discovery/privet_constants.h" #include "chrome/browser/local_discovery/privet_constants.h"
#include "components/cloud_devices/printer_description.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "printing/units.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace local_discovery { namespace local_discovery {
...@@ -39,11 +41,6 @@ const char kPrivetStorageListPath[] = "/privet/storage/list"; ...@@ -39,11 +41,6 @@ const char kPrivetStorageListPath[] = "/privet/storage/list";
const char kPrivetStorageContentPath[] = "/privet/storage/content"; const char kPrivetStorageContentPath[] = "/privet/storage/content";
const char kPrivetStorageParamPathFormat[] = "path=%s"; const char kPrivetStorageParamPathFormat[] = "path=%s";
const char kPrivetCDDKeySupportedContentTypes[] =
"printer.supported_content_type";
const char kPrivetCDDKeyContentType[] = "content_type";
const char kPrivetKeyJobID[] = "job_id"; const char kPrivetKeyJobID[] = "job_id";
const int kPrivetCancelationTimeoutSeconds = 3; const int kPrivetCancelationTimeoutSeconds = 3;
...@@ -455,9 +452,15 @@ bool PrivetDataReadOperationImpl::OnRawData(PrivetURLFetcher* fetcher, ...@@ -455,9 +452,15 @@ bool PrivetDataReadOperationImpl::OnRawData(PrivetURLFetcher* fetcher,
PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl( PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl(
PrivetHTTPClientImpl* privet_client, PrivetHTTPClientImpl* privet_client,
PrivetLocalPrintOperation::Delegate* delegate) PrivetLocalPrintOperation::Delegate* delegate)
: privet_client_(privet_client), delegate_(delegate), : privet_client_(privet_client),
use_pdf_(false), has_capabilities_(false), has_extended_workflow_(false), delegate_(delegate),
started_(false), offline_(false), invalid_job_retries_(0), use_pdf_(false),
has_capabilities_(false),
has_extended_workflow_(false),
started_(false),
offline_(false),
dpi_(printing::kDefaultPdfDpi),
invalid_job_retries_(0),
weak_factory_(this) { weak_factory_(this) {
} }
...@@ -514,7 +517,7 @@ void PrivetLocalPrintOperationImpl::StartInitialRequest() { ...@@ -514,7 +517,7 @@ void PrivetLocalPrintOperationImpl::StartInitialRequest() {
if (has_capabilities_) { if (has_capabilities_) {
GetCapabilities(); GetCapabilities();
} else { } 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. // request is PWG Raster.
use_pdf_ = false; use_pdf_ = false;
StartConvertToPWG(); StartConvertToPWG();
...@@ -606,9 +609,14 @@ void PrivetLocalPrintOperationImpl::StartPrinting() { ...@@ -606,9 +609,14 @@ void PrivetLocalPrintOperationImpl::StartPrinting() {
void PrivetLocalPrintOperationImpl::StartConvertToPWG() { void PrivetLocalPrintOperationImpl::StartConvertToPWG() {
if (!pwg_raster_converter_) if (!pwg_raster_converter_)
pwg_raster_converter_ = PWGRasterConverter::CreateDefault(); 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( pwg_raster_converter_->Start(
data_, data_, printing::PdfRenderSettings(area, dpi_, true),
conversion_settings_,
base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted,
base::Unretained(this))); base::Unretained(this)));
} }
...@@ -621,28 +629,26 @@ void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse( ...@@ -621,28 +629,26 @@ void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse(
return; return;
} }
const base::ListValue* supported_content_types; cloud_devices::CloudDeviceDescription description;
use_pdf_ = false; if (!description.InitFromDictionary(make_scoped_ptr(value->DeepCopy()))) {
delegate_->OnPrivetPrintingError(this, 200);
return;
}
if (value->GetList(kPrivetCDDKeySupportedContentTypes, use_pdf_ = false;
&supported_content_types)) { cloud_devices::printer::ContentTypesCapability content_types;
for (size_t i = 0; i < supported_content_types->GetSize(); i++) { if (content_types.LoadFrom(description)) {
const base::DictionaryValue* content_type_value; use_pdf_ = content_types.Contains(kPrivetContentTypePDF) ||
std::string content_type; content_types.Contains(kPrivetContentTypeAny);
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;
}
}
} }
if (use_pdf_) { if (use_pdf_) {
StartPrinting(); StartPrinting();
} else { } else {
cloud_devices::printer::DpiCapability dpis;
if (dpis.LoadFrom(description)) {
dpi_ = std::max(dpis.GetDefault().horizontal, dpis.GetDefault().vertical);
}
StartConvertToPWG(); StartConvertToPWG();
} }
} }
...@@ -767,10 +773,9 @@ void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { ...@@ -767,10 +773,9 @@ void PrivetLocalPrintOperationImpl::SetOffline(bool offline) {
offline_ = offline; offline_ = offline;
} }
void PrivetLocalPrintOperationImpl::SetConversionSettings( void PrivetLocalPrintOperationImpl::SetPageSize(const gfx::Size& page_size) {
const printing::PdfRenderSettings& conversion_settings) {
DCHECK(!started_); DCHECK(!started_);
conversion_settings_ = conversion_settings; page_size_ = page_size;
} }
void PrivetLocalPrintOperationImpl::SetPWGRasterConverterForTesting( void PrivetLocalPrintOperationImpl::SetPWGRasterConverterForTesting(
......
...@@ -212,8 +212,7 @@ class PrivetLocalPrintOperationImpl ...@@ -212,8 +212,7 @@ class PrivetLocalPrintOperationImpl
virtual void SetOffline(bool offline) OVERRIDE; virtual void SetOffline(bool offline) OVERRIDE;
virtual void SetConversionSettings( virtual void SetPageSize(const gfx::Size& page_size) OVERRIDE;
const printing::PdfRenderSettings& conversion_settings) OVERRIDE;
virtual void SetPWGRasterConverterForTesting( virtual void SetPWGRasterConverterForTesting(
scoped_ptr<PWGRasterConverter> pwg_raster_converter) OVERRIDE; scoped_ptr<PWGRasterConverter> pwg_raster_converter) OVERRIDE;
...@@ -264,7 +263,8 @@ class PrivetLocalPrintOperationImpl ...@@ -264,7 +263,8 @@ class PrivetLocalPrintOperationImpl
bool has_extended_workflow_; bool has_extended_workflow_;
bool started_; bool started_;
bool offline_; bool offline_;
printing::PdfRenderSettings conversion_settings_; gfx::Size page_size_;
int dpi_;
std::string user_; std::string user_;
std::string jobname_; std::string jobname_;
......
...@@ -1450,19 +1450,8 @@ void PrintPreviewHandler::StartPrivetLocalPrint( ...@@ -1450,19 +1450,8 @@ void PrintPreviewHandler::StartPrivetLocalPrint(
return; return;
} }
privet_local_print_operation_->SetJobname( privet_local_print_operation_->SetJobname(base::UTF16ToUTF8(title));
base::UTF16ToUTF8(title)); privet_local_print_operation_->SetPageSize(page_size);
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_->SetData(data); privet_local_print_operation_->SetData(data);
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
'suggestions_proto', 'suggestions_proto',
'../components/component_strings.gyp:component_strings', '../components/component_strings.gyp:component_strings',
'../components/components.gyp:autofill_core_browser', '../components/components.gyp:autofill_core_browser',
'../components/components.gyp:cloud_devices',
'../components/components.gyp:encryptor', '../components/components.gyp:encryptor',
'../components/components.gyp:navigation_metrics', '../components/components.gyp:navigation_metrics',
'../components/components.gyp:password_manager_core_common', '../components/components.gyp:password_manager_core_common',
......
...@@ -24,19 +24,24 @@ void CloudDeviceDescription::Reset() { ...@@ -24,19 +24,24 @@ void CloudDeviceDescription::Reset() {
root_->SetString(json::kVersion, json::kVersion10); 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(); 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)); scoped_ptr<base::Value> parsed(base::JSONReader::Read(json));
base::DictionaryValue* description = NULL; base::DictionaryValue* description = NULL;
if (!parsed || !parsed->GetAsDictionary(&description)) if (!parsed || !parsed->GetAsDictionary(&description))
return false; return false;
root_.reset(description);
ignore_result(parsed.release()); ignore_result(parsed.release());
return InitFromDictionary(make_scoped_ptr(description));
std::string version;
description->GetString(json::kVersion, &version);
return version == json::kVersion10;
} }
std::string CloudDeviceDescription::ToString() const { std::string CloudDeviceDescription::ToString() const {
......
...@@ -26,6 +26,7 @@ class CloudDeviceDescription { ...@@ -26,6 +26,7 @@ class CloudDeviceDescription {
void Reset(); void Reset();
bool InitFromDictionary(scoped_ptr<base::DictionaryValue> root);
bool InitFromString(const std::string& json); bool InitFromString(const std::string& json);
std::string ToString() const; std::string ToString() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment