"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 = {
# For tests, it's fine to include utility process code.
'test_service_discovery_client\.cc': [
......
......@@ -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(
......
......@@ -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(
......
......@@ -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_;
......
......@@ -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());
......
......@@ -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',
......
......@@ -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 {
......
......@@ -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;
......
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