summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/print_job_manager.cc17
-rw-r--r--chrome/browser/resources/print_preview/data/app_state.js1
-rw-r--r--chrome/browser/resources/print_preview/data/destination_store.js100
-rw-r--r--chrome/browser/resources/print_preview/native_layer.js2
-rw-r--r--chrome/browser/resources/print_preview/settings/media_size_settings.js4
-rw-r--r--chrome/browser/resources/print_preview/settings/other_options_settings.js20
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_handler.cc119
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_handler.h8
-rw-r--r--chrome/test/data/webui/print_preview.js44
-rw-r--r--components/cloud_devices/common/cloud_device_description.h2
-rw-r--r--components/cloud_devices/common/printer_description.cc28
-rw-r--r--components/cloud_devices/common/printer_description.h2
-rw-r--r--printing/printing_context.cc18
-rw-r--r--printing/printing_context.h3
14 files changed, 269 insertions, 99 deletions
diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc
index 9dc0c85..da0e91f 100644
--- a/chrome/browser/printing/print_job_manager.cc
+++ b/chrome/browser/printing/print_job_manager.cc
@@ -57,9 +57,20 @@ scoped_refptr<PrinterQuery> PrintQueriesQueue::CreatePrinterQuery() {
}
void PrintQueriesQueue::Shutdown() {
- base::AutoLock lock(lock_);
- queued_queries_.clear();
- destination_ = NULL;
+ PrinterQueries queries_to_stop;
+ {
+ base::AutoLock lock(lock_);
+ queued_queries_.swap(queries_to_stop);
+ destination_ = NULL;
+ }
+ // Stop all pending queries, requests to generate print preview do not have
+ // corresponding PrintJob, so any pending preview requests are not covered
+ // by PrintJobManager::StopJobs and should be stopped explicitly.
+ for (PrinterQueries::iterator itr = queries_to_stop.begin();
+ itr != queries_to_stop.end(); ++itr) {
+ (*itr)->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&PrinterQuery::StopWorker, *itr));
+ }
}
PrintJobManager::PrintJobManager() : is_shutdown_(false) {
diff --git a/chrome/browser/resources/print_preview/data/app_state.js b/chrome/browser/resources/print_preview/data/app_state.js
index c102843..2d9a9c1 100644
--- a/chrome/browser/resources/print_preview/data/app_state.js
+++ b/chrome/browser/resources/print_preview/data/app_state.js
@@ -147,6 +147,7 @@ cr.define('print_preview', function() {
systemDefaultDestinationId;
this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN] =
print_preview.Destination.Origin.LOCAL;
+ this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT] = '';
}
}
},
diff --git a/chrome/browser/resources/print_preview/data/destination_store.js b/chrome/browser/resources/print_preview/data/destination_store.js
index 27769cc..1f45947 100644
--- a/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chrome/browser/resources/print_preview/data/destination_store.js
@@ -194,32 +194,26 @@ cr.define('print_preview', function() {
DestinationStore.PRIVET_SEARCH_DURATION_ = 2000;
/**
- * Creates a local PDF print destination.
- * @return {!print_preview.Destination} Created print destination.
+ * Localizes printer capabilities.
+ * @param {!Object} capabilities Printer capabilities to localize.
+ * @return {!Object} Localized capabilities.
* @private
*/
- DestinationStore.createLocalPdfPrintDestination_ = function() {
- var dest = new print_preview.Destination(
- print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
- print_preview.Destination.Type.LOCAL,
- print_preview.Destination.Origin.LOCAL,
- localStrings.getString('printToPDF'),
- false /*isRecent*/,
- print_preview.Destination.ConnectionStatus.ONLINE);
- dest.capabilities = {
- version: '1.0',
- printer: {
- page_orientation: {
- option: [
- {type: 'AUTO', is_default: true},
- {type: 'PORTRAIT'},
- {type: 'LANDSCAPE'}
- ]
- },
- color: { option: [{type: 'STANDARD_COLOR', is_default: true}] }
+ DestinationStore.localizeCapabilities_ = function(capabilities) {
+ var mediaSize = capabilities.printer.media_size;
+ if (mediaSize) {
+ var mediaDisplayNames = {
+ 'ISO_A4': 'A4',
+ 'ISO_A3': 'A3',
+ 'NA_LETTER': 'Letter',
+ 'NA_LEGAL': 'Legal',
+ 'NA_LEDGER': 'Tabloid'
+ };
+ for (var i = 0, media; media = mediaSize.option[i]; i++) {
+ media.custom_display_name = mediaDisplayNames[media.name] || media.name;
}
- };
- return dest;
+ }
+ return capabilities;
};
DestinationStore.prototype = {
@@ -656,6 +650,21 @@ cr.define('print_preview', function() {
},
/**
+ * Creates a local PDF print destination.
+ * @return {!print_preview.Destination} Created print destination.
+ * @private
+ */
+ createLocalPdfPrintDestination_: function() {
+ return new print_preview.Destination(
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
+ print_preview.Destination.Type.LOCAL,
+ print_preview.Destination.Origin.LOCAL,
+ localStrings.getString('printToPDF'),
+ false /*isRecent*/,
+ print_preview.Destination.ConnectionStatus.ONLINE);
+ },
+
+ /**
* Resets the state of the destination store to its initial state.
* @private
*/
@@ -665,8 +674,9 @@ cr.define('print_preview', function() {
this.selectDestination(null);
this.loadedCloudOrigins_ = {};
this.hasLoadedAllLocalDestinations_ = false;
- this.insertDestination_(
- DestinationStore.createLocalPdfPrintDestination_());
+ // TODO(alekseys): Create PDF printer in the native code and send its
+ // capabilities back with other local printers.
+ this.insertDestination_(this.createLocalPdfPrintDestination_());
this.resetAutoSelectTimeout_();
},
@@ -723,23 +733,33 @@ cr.define('print_preview', function() {
destinationId,
'');
var destination = this.destinationMap_[key];
- var capabilities = print_preview.LocalCapabilitiesParser.parse(
- event.settingsInfo);
- if (destination) {
- // In case there were multiple capabilities request for this local
- // destination, just ignore the later ones.
- if (destination.capabilities != null) {
- return;
+ // Special case for PDF printer (until local printers capabilities are
+ // reported in CDD format too).
+ if (destinationId ==
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) {
+ if (destination) {
+ destination.capabilities = DestinationStore.localizeCapabilities_(
+ event.settingsInfo.capabilities);
}
- destination.capabilities = capabilities;
} else {
- // TODO(rltoscano): This makes the assumption that the "deviceName" is
- // the same as "printerName". We should include the "printerName" in the
- // response. See http://crbug.com/132831.
- destination = print_preview.LocalDestinationParser.parse(
- {deviceName: destinationId, printerName: destinationId});
- destination.capabilities = capabilities;
- this.insertDestination_(destination);
+ var capabilities = print_preview.LocalCapabilitiesParser.parse(
+ event.settingsInfo);
+ if (destination) {
+ // In case there were multiple capabilities request for this local
+ // destination, just ignore the later ones.
+ if (destination.capabilities != null) {
+ return;
+ }
+ destination.capabilities = capabilities;
+ } else {
+ // TODO(rltoscano): This makes the assumption that the "deviceName" is
+ // the same as "printerName". We should include the "printerName" in
+ // the response. See http://crbug.com/132831.
+ destination = print_preview.LocalDestinationParser.parse(
+ {deviceName: destinationId, printerName: destinationId});
+ destination.capabilities = capabilities;
+ this.insertDestination_(destination);
+ }
}
if (this.selectedDestination_ &&
this.selectedDestination_.id == destinationId) {
diff --git a/chrome/browser/resources/print_preview/native_layer.js b/chrome/browser/resources/print_preview/native_layer.js
index ea9effa..efdd55b 100644
--- a/chrome/browser/resources/print_preview/native_layer.js
+++ b/chrome/browser/resources/print_preview/native_layer.js
@@ -44,7 +44,7 @@ cr.define('print_preview', function() {
global['autoCancelForTesting'] = this.autoCancelForTesting_.bind(this);
global['onPrivetPrinterChanged'] = this.onPrivetPrinterChanged_.bind(this);
global['onPrivetCapabilitiesSet'] =
- this.onPrivetCapabilitiesSet_.bind(this);
+ this.onPrivetCapabilitiesSet_.bind(this);
global['onPrivetPrintFailed'] = this.onPrivetPrintFailed_.bind(this);
};
diff --git a/chrome/browser/resources/print_preview/settings/media_size_settings.js b/chrome/browser/resources/print_preview/settings/media_size_settings.js
index e551392..507fd93 100644
--- a/chrome/browser/resources/print_preview/settings/media_size_settings.js
+++ b/chrome/browser/resources/print_preview/settings/media_size_settings.js
@@ -55,7 +55,7 @@ cr.define('print_preview', function() {
updateSelect_: function() {
var select = this.select_;
if (!this.ticketItem_.isCapabilityAvailable()) {
- select.innerHtml = '';
+ select.innerHTML = '';
return;
}
// Should the select content be updated?
@@ -66,7 +66,7 @@ cr.define('print_preview', function() {
});
var indexToSelect = select.selectedIndex;
if (!sameContent) {
- select.innerHtml = '';
+ select.innerHTML = '';
// TODO: Better heuristics for the display name and options grouping.
this.ticketItem_.capability.option.forEach(function(option, index) {
var selectOption = document.createElement('option');
diff --git a/chrome/browser/resources/print_preview/settings/other_options_settings.js b/chrome/browser/resources/print_preview/settings/other_options_settings.js
index ac9f0d1..4b93539 100644
--- a/chrome/browser/resources/print_preview/settings/other_options_settings.js
+++ b/chrome/browser/resources/print_preview/settings/other_options_settings.js
@@ -235,6 +235,16 @@ cr.define('print_preview', function() {
this.duplexTicketItem_.isCapabilityAvailable() ||
this.cssBackgroundTicketItem_.isCapabilityAvailable() ||
this.selectionOnlyTicketItem_.isCapabilityAvailable()) {
+ setIsVisible(this.headerFooterContainer_,
+ this.headerFooterTicketItem_.isCapabilityAvailable());
+ setIsVisible(this.fitToPageContainer_,
+ this.fitToPageTicketItem_.isCapabilityAvailable());
+ setIsVisible(this.duplexContainer_,
+ this.duplexTicketItem_.isCapabilityAvailable());
+ setIsVisible(this.cssBackgroundContainer_,
+ this.cssBackgroundTicketItem_.isCapabilityAvailable());
+ setIsVisible(this.selectionOnlyContainer_,
+ this.selectionOnlyTicketItem_.isCapabilityAvailable());
fadeInOption(this.getElement());
} else {
fadeOutOption(this.getElement());
@@ -294,8 +304,6 @@ cr.define('print_preview', function() {
* @private
*/
onDuplexChange_: function() {
- setIsVisible(this.duplexContainer_,
- this.duplexTicketItem_.isCapabilityAvailable());
this.duplexCheckbox_.checked = this.duplexTicketItem_.getValue();
this.updateContainerState_();
},
@@ -306,8 +314,6 @@ cr.define('print_preview', function() {
* @private
*/
onFitToPageChange_: function() {
- setIsVisible(this.fitToPageContainer_,
- this.fitToPageTicketItem_.isCapabilityAvailable());
this.fitToPageCheckbox_.checked = this.fitToPageTicketItem_.getValue();
this.updateContainerState_();
},
@@ -318,8 +324,6 @@ cr.define('print_preview', function() {
* @private
*/
onCssBackgroundChange_: function() {
- setIsVisible(this.cssBackgroundContainer_,
- this.cssBackgroundTicketItem_.isCapabilityAvailable());
this.cssBackgroundCheckbox_.checked =
this.cssBackgroundTicketItem_.getValue();
this.updateContainerState_();
@@ -331,8 +335,6 @@ cr.define('print_preview', function() {
* @private
*/
onSelectionOnlyChange_: function() {
- setIsVisible(this.selectionOnlyContainer_,
- this.selectionOnlyTicketItem_.isCapabilityAvailable());
this.selectionOnlyCheckbox_.checked =
this.selectionOnlyTicketItem_.getValue();
this.updateContainerState_();
@@ -344,8 +346,6 @@ cr.define('print_preview', function() {
* @private
*/
onHeaderFooterChange_: function() {
- setIsVisible(this.headerFooterContainer_,
- this.headerFooterTicketItem_.isCapabilityAvailable());
this.headerFooterCheckbox_.checked =
this.headerFooterTicketItem_.getValue();
this.updateContainerState_();
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 7b4a5b3..b1c37ad 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -6,6 +6,7 @@
#include <ctype.h>
+#include <map>
#include <string>
#include "base/base64.h"
@@ -48,7 +49,9 @@
#include "chrome/common/crash_keys.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/print_messages.h"
+#include "components/cloud_devices/common/cloud_device_description.h"
#include "components/cloud_devices/common/cloud_devices_urls.h"
+#include "components/cloud_devices/common/printer_description.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/signin/core/browser/signin_manager_base.h"
@@ -66,6 +69,7 @@
#include "printing/metafile_impl.h"
#include "printing/pdf_render_settings.h"
#include "printing/print_settings.h"
+#include "printing/printing_context.h"
#include "printing/units.h"
#include "third_party/icu/source/i18n/unicode/ulocdata.h"
@@ -179,8 +183,12 @@ const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink";
// Name of a dictionary field holding the state of selection for document.
const char kDocumentHasSelection[] = "documentHasSelection";
+// Id of the predefined PDF printer.
+const char kLocalPdfPrinterId[] = "Save as PDF";
+
// Additional printer capability setting keys.
const char kPrinterId[] = "printerId";
+const char kPrinterCapabilities[] = "capabilities";
const char kDisableColorOption[] = "disableColorOption";
const char kSetDuplexAsDefault[] = "setDuplexAsDefault";
const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue";
@@ -267,20 +275,86 @@ void PrintToPdfCallback(printing::Metafile* metafile,
BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, metafile);
}
-std::string GetDefaultPrinterOnFileThread(
- scoped_refptr<printing::PrintBackend> print_backend) {
+std::string GetDefaultPrinterOnFileThread() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ scoped_refptr<printing::PrintBackend> print_backend(
+ printing::PrintBackend::CreateInstance(NULL));
+
std::string default_printer = print_backend->GetDefaultPrinterName();
VLOG(1) << "Default Printer: " << default_printer;
return default_printer;
}
-void EnumeratePrintersOnFileThread(
- scoped_refptr<printing::PrintBackend> print_backend,
- base::ListValue* printers) {
+gfx::Size GetDefaultPdfMediaSizeMicrons() {
+ scoped_ptr<printing::PrintingContext> printing_context(
+ printing::PrintingContext::Create(
+ g_browser_process->GetApplicationLocale()));
+ if (printing::PrintingContext::OK != printing_context->UsePdfSettings() ||
+ printing_context->settings().device_units_per_inch() <= 0) {
+ return gfx::Size();
+ }
+ gfx::Size pdf_media_size = printing_context->GetPdfPaperSizeDeviceUnits();
+ float deviceMicronsPerDeviceUnit =
+ (printing::kHundrethsMMPerInch * 10.0f) /
+ printing_context->settings().device_units_per_inch();
+ return gfx::Size(pdf_media_size.width() * deviceMicronsPerDeviceUnit,
+ pdf_media_size.height() * deviceMicronsPerDeviceUnit);
+}
+
+typedef base::Callback<void(const base::DictionaryValue*)>
+ GetPdfCapabilitiesCallback;
+
+scoped_ptr<base::DictionaryValue> GetPdfCapabilitiesOnFileThread(
+ const std::string& locale) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ cloud_devices::CloudDeviceDescription description;
+ using namespace cloud_devices::printer;
+
+ OrientationCapability orientation;
+ orientation.AddOption(cloud_devices::printer::PORTRAIT);
+ orientation.AddOption(cloud_devices::printer::LANDSCAPE);
+ orientation.AddDefaultOption(AUTO_ORIENTATION, true);
+ orientation.SaveTo(&description);
+
+ ColorCapability color;
+ color.AddDefaultOption(Color(STANDARD_COLOR), true);
+ color.SaveTo(&description);
+
+ static const cloud_devices::printer::MediaType kPdfMedia[] = {
+ ISO_A4,
+ ISO_A3,
+ NA_LETTER,
+ NA_LEGAL,
+ NA_LEDGER
+ };
+ const gfx::Size default_media_size = GetDefaultPdfMediaSizeMicrons();
+ Media default_media(
+ "", default_media_size.width(), default_media_size.height());
+ if (!default_media.MatchBySize() ||
+ std::find(kPdfMedia,
+ kPdfMedia + arraysize(kPdfMedia),
+ default_media.type) == kPdfMedia + arraysize(kPdfMedia)) {
+ default_media = Media(locale == "en-US" ? NA_LETTER : ISO_A4);
+ }
+ MediaCapability media;
+ for (size_t i = 0; i < arraysize(kPdfMedia); ++i) {
+ Media media_option(kPdfMedia[i]);
+ media.AddDefaultOption(media_option,
+ default_media.type == media_option.type);
+ }
+ media.SaveTo(&description);
+
+ return scoped_ptr<base::DictionaryValue>(description.root().DeepCopy());
+}
+
+void EnumeratePrintersOnFileThread(base::ListValue* printers) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+
+ scoped_refptr<printing::PrintBackend> print_backend(
+ printing::PrintBackend::CreateInstance(NULL));
+
VLOG(1) << "Enumerate printers start";
printing::PrinterList printer_list;
print_backend->EnumeratePrinters(&printer_list);
@@ -329,13 +403,28 @@ typedef base::Callback<void(const std::string&)>
GetPrinterCapabilitiesFailureCallback;
void GetPrinterCapabilitiesOnFileThread(
- scoped_refptr<printing::PrintBackend> print_backend,
const std::string& printer_name,
+ const std::string& locale,
const GetPrinterCapabilitiesSuccessCallback& success_cb,
const GetPrinterCapabilitiesFailureCallback& failure_cb) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
DCHECK(!printer_name.empty());
+ // Special case for PDF printer.
+ if (printer_name == kLocalPdfPrinterId) {
+ scoped_ptr<base::DictionaryValue> printer_info(new base::DictionaryValue);
+ printer_info->SetString(kPrinterId, printer_name);
+ printer_info->Set(kPrinterCapabilities,
+ GetPdfCapabilitiesOnFileThread(locale).release());
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(success_cb, base::Owned(printer_info.release())));
+ return;
+ }
+
+ scoped_refptr<printing::PrintBackend> print_backend(
+ printing::PrintBackend::CreateInstance(NULL));
+
VLOG(1) << "Get printer capabilities start for " << printer_name;
crash_keys::ScopedPrinterInfo crash_key(
print_backend->GetPrinterDriverInfo(printer_name));
@@ -367,7 +456,7 @@ void GetPrinterCapabilitiesOnFileThread(
#endif
// TODO(gene): Make new capabilities format for Print Preview
- // that will suit semantic capabiltities better.
+ // that will suit semantic capabilities better.
// Refactor pld API code below
bool default_duplex = info.duplex_capable ?
(info.duplex_default != printing::SIMPLEX) : false;
@@ -475,8 +564,7 @@ class PrintPreviewHandler::AccessTokenService
};
PrintPreviewHandler::PrintPreviewHandler()
- : print_backend_(printing::PrintBackend::CreateInstance(NULL)),
- regenerate_preview_request_count_(0),
+ : regenerate_preview_request_count_(0),
manage_printers_dialog_request_count_(0),
manage_cloud_printers_dialog_request_count_(0),
reported_failed_preview_(false),
@@ -570,7 +658,7 @@ void PrintPreviewHandler::HandleGetPrinters(const base::ListValue* /*args*/) {
base::ListValue* results = new base::ListValue;
BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&EnumeratePrintersOnFileThread, print_backend_,
+ base::Bind(&EnumeratePrintersOnFileThread,
base::Unretained(results)),
base::Bind(&PrintPreviewHandler::SetupPrinterList,
weak_factory_.GetWeakPtr(),
@@ -886,10 +974,11 @@ void PrintPreviewHandler::HandleGetPrinterCapabilities(
GetPrinterCapabilitiesFailureCallback failure_cb =
base::Bind(&PrintPreviewHandler::SendFailedToGetPrinterCapabilities,
weak_factory_.GetWeakPtr());
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&GetPrinterCapabilitiesOnFileThread,
- print_backend_, printer_name, success_cb, failure_cb));
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&GetPrinterCapabilitiesOnFileThread,
+ printer_name,
+ g_browser_process->GetApplicationLocale(),
+ success_cb, failure_cb));
}
void PrintPreviewHandler::OnSigninComplete() {
@@ -1041,7 +1130,7 @@ void PrintPreviewHandler::HandleGetInitialSettings(
SendCloudPrintEnabled();
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&GetDefaultPrinterOnFileThread, print_backend_),
+ base::Bind(&GetDefaultPrinterOnFileThread),
base::Bind(&PrintPreviewHandler::SendInitialSettings,
weak_factory_.GetWeakPtr()));
}
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.h b/chrome/browser/ui/webui/print_preview/print_preview_handler.h
index 5ff8fb4..70464a8 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.h
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.h
@@ -35,11 +35,6 @@ namespace gfx {
class Size;
}
-namespace printing {
-struct PageSizeMargins;
-class PrintBackend;
-}
-
// The handler for Javascript messages related to the print preview dialog.
class PrintPreviewHandler
: public content::WebUIMessageHandler,
@@ -277,9 +272,6 @@ class PrintPreviewHandler
base::DictionaryValue* printer_value);
#endif
- // Pointer to current print system.
- scoped_refptr<printing::PrintBackend> print_backend_;
-
// The underlying dialog object.
scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview.js
index 362aad7..3a51956 100644
--- a/chrome/test/data/webui/print_preview.js
+++ b/chrome/test/data/webui/print_preview.js
@@ -265,34 +265,46 @@ TEST_F('PrintPreviewWebUITest',
// Add PDF printer.
this.initialSettings_.isDocumentModifiable_ = false;
this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
- this.localDestinationInfos_.push(
- {printerName: 'Save as PDF', deviceName: 'Save as PDF'});
var initialSettingsSetEvent =
new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
initialSettingsSetEvent.initialSettings = this.initialSettings_;
this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
- var localDestsSetEvent =
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
- this.nativeLayer_.dispatchEvent(localDestsSetEvent);
-
var capsSetEvent =
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
capsSetEvent.settingsInfo = {
- 'printerId': 'FooDevice',
- 'disableColorOption': false,
- 'setColorAsDefault': true,
- 'disableCopiesOption': true,
- 'disableLandscapeOption': true,
- 'printerDefaultDuplexValue': 0
+ printerId: 'Save as PDF',
+ capabilities: {
+ version: '1.0',
+ printer: {
+ page_orientation: {
+ option: [
+ {type: 'AUTO', is_default: true},
+ {type: 'PORTRAIT'},
+ {type: 'LANDSCAPE'}
+ ]
+ },
+ color: {
+ option: [
+ {type: 'STANDARD_COLOR', is_default: true}
+ ]
+ },
+ media_size: {
+ option: [
+ { name: 'NA_LETTER',
+ width_microns: 0,
+ height_microns: 0,
+ is_default: true
+ }
+ ]
+ }
+ }
+ }
};
this.nativeLayer_.dispatchEvent(capsSetEvent);
- checkElementDisplayed(
- $('other-options-settings').querySelector('.fit-to-page-container'),
- false);
+ checkSectionVisible($('other-options-settings'), false);
});
// When the source is 'HTML', we always hide the fit to page option.
diff --git a/components/cloud_devices/common/cloud_device_description.h b/components/cloud_devices/common/cloud_device_description.h
index 8a00210..146c682 100644
--- a/components/cloud_devices/common/cloud_device_description.h
+++ b/components/cloud_devices/common/cloud_device_description.h
@@ -31,6 +31,8 @@ class CloudDeviceDescription {
std::string ToString() const;
+ const base::DictionaryValue& root() const { return *root_; }
+
// Returns dictionary with capability/option.
// Returns NULL if missing.
const base::DictionaryValue* GetItem(const std::string& path) const;
diff --git a/components/cloud_devices/common/printer_description.cc b/components/cloud_devices/common/printer_description.cc
index 8697795..2f70fa6 100644
--- a/components/cloud_devices/common/printer_description.cc
+++ b/components/cloud_devices/common/printer_description.cc
@@ -162,7 +162,7 @@ const int32 kSizeTrasholdUm = 1000;
static_cast<int>(height* unit_um + 0.5) \
}
-const struct MadiaDefinition {
+const struct MediaDefinition {
MediaType id;
const char* const json_name;
int width_um;
@@ -335,8 +335,17 @@ const struct MadiaDefinition {
MAP_CLOUD_PRINT_MEDIA_TYPE(OM_INVITE, 220, 220, kMmToUm)};
#undef MAP_CLOUD_PRINT_MEDIA_TYPE
-const MadiaDefinition* FindMediaBySize(int32 width_um, int32 height_um) {
- const MadiaDefinition* result = NULL;
+const MediaDefinition& FindMediaByType(MediaType type) {
+ for (size_t i = 0; i < arraysize(kMediaDefinitions); ++i) {
+ if (kMediaDefinitions[i].id == type)
+ return kMediaDefinitions[i];
+ }
+ NOTREACHED();
+ return kMediaDefinitions[0];
+}
+
+const MediaDefinition* FindMediaBySize(int32 width_um, int32 height_um) {
+ const MediaDefinition* result = NULL;
for (size_t i = 0; i < arraysize(kMediaDefinitions); ++i) {
int32 diff = std::max(std::abs(width_um - kMediaDefinitions[i].width_um),
std::abs(height_um - kMediaDefinitions[i].height_um));
@@ -432,6 +441,17 @@ Media::Media()
: type(CUSTOM_MEDIA), width_um(0), height_um(0), is_continuous_feed(false) {
}
+Media::Media(MediaType type)
+ : type(type),
+ width_um(0),
+ height_um(0),
+ is_continuous_feed(false) {
+ const MediaDefinition& media = FindMediaByType(type);
+ width_um = media.width_um;
+ height_um = media.height_um;
+ is_continuous_feed = width_um <= 0 || height_um <= 0;
+}
+
Media::Media(MediaType type, int32 width_um, int32 height_um)
: type(type),
width_um(width_um),
@@ -450,7 +470,7 @@ Media::Media(const std::string& custom_display_name,
}
bool Media::MatchBySize() {
- const MadiaDefinition* media = FindMediaBySize(width_um, height_um);
+ const MediaDefinition* media = FindMediaBySize(width_um, height_um);
if (!media)
return false;
type = media->id;
diff --git a/components/cloud_devices/common/printer_description.h b/components/cloud_devices/common/printer_description.h
index 74225ff..d434fa6 100644
--- a/components/cloud_devices/common/printer_description.h
+++ b/components/cloud_devices/common/printer_description.h
@@ -287,6 +287,8 @@ enum MediaType {
struct Media {
Media();
+ explicit Media(MediaType type);
+
Media(MediaType type, int32 width_um, int32 height_um);
Media(const std::string& custom_display_name,
diff --git a/printing/printing_context.cc b/printing/printing_context.cc
index 817d59c..8d438d0 100644
--- a/printing/printing_context.cc
+++ b/printing/printing_context.cc
@@ -48,6 +48,24 @@ PrintingContext::Result PrintingContext::OnError() {
return abort_printing_ ? CANCEL : FAILED;
}
+PrintingContext::Result PrintingContext::UsePdfSettings() {
+ scoped_ptr<base::DictionaryValue> pdf_settings(new base::DictionaryValue);
+ pdf_settings->SetBoolean(kSettingHeaderFooterEnabled, false);
+ pdf_settings->SetBoolean(kSettingShouldPrintBackgrounds, false);
+ pdf_settings->SetBoolean(kSettingShouldPrintSelectionOnly, false);
+ pdf_settings->SetInteger(kSettingMarginsType, printing::NO_MARGINS);
+ pdf_settings->SetBoolean(kSettingCollate, true);
+ pdf_settings->SetInteger(kSettingCopies, 1);
+ pdf_settings->SetInteger(kSettingColor, printing::COLOR);
+ pdf_settings->SetInteger(kSettingDuplexMode, printing::SIMPLEX);
+ pdf_settings->SetBoolean(kSettingLandscape, false);
+ pdf_settings->SetString(kSettingDeviceName, "");
+ pdf_settings->SetBoolean(kSettingPrintToPDF, true);
+ pdf_settings->SetBoolean(kSettingCloudPrintDialog, false);
+ pdf_settings->SetBoolean(kSettingPrintWithPrivet, false);
+ return UpdatePrintSettings(*pdf_settings, PageRanges());
+}
+
PrintingContext::Result PrintingContext::UpdatePrintSettings(
const base::DictionaryValue& job_settings,
const PageRanges& ranges) {
diff --git a/printing/printing_context.h b/printing/printing_context.h
index 7a0a8c8..fedf696 100644
--- a/printing/printing_context.h
+++ b/printing/printing_context.h
@@ -51,6 +51,9 @@ class PRINTING_EXPORT PrintingContext {
// default device settings.
virtual Result UseDefaultSettings() = 0;
+ // Updates the context with PDF printer settings.
+ Result UsePdfSettings();
+
// Returns paper size to be used for PDF or Cloud Print in device units.
virtual gfx::Size GetPdfPaperSizeDeviceUnits() = 0;