Chromium Code Reviews| Index: chrome/browser/resources/print_preview/data/destination_store.js |
| diff --git a/chrome/browser/resources/print_preview/data/destination_store.js b/chrome/browser/resources/print_preview/data/destination_store.js |
| index 27769ccc3d99d47cb72ed58e9edec34801dac7f1..ca3d238e625f3cdc609e441e15b2453aab81fffa 100644 |
| --- a/chrome/browser/resources/print_preview/data/destination_store.js |
| +++ b/chrome/browser/resources/print_preview/data/destination_store.js |
| @@ -48,6 +48,13 @@ cr.define('print_preview', function() { |
| this.metrics_ = metrics; |
| /** |
| + * Cached local PDF printer capabilities. |
| + * @type {Object} |
| + * @private |
| + */ |
| + this.pdfCapabilities_ = DestinationStore.createPdfCapabilities_(); |
| + |
| + /** |
| * Internal backing store for the data store. |
| * @type {!Array.<!print_preview.Destination>} |
| * @private |
| @@ -194,19 +201,14 @@ cr.define('print_preview', function() { |
| DestinationStore.PRIVET_SEARCH_DURATION_ = 2000; |
| /** |
| - * Creates a local PDF print destination. |
| - * @return {!print_preview.Destination} Created print destination. |
| + * Creates capabilities for local PDF printer destination. |
| + * @param {Object=} opt_capabilitiesTemplate Some of the capabilities to fill |
| + * in the printer ones. |
| + * @return {!Object} PDF printer 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 = { |
| + DestinationStore.createPdfCapabilities_ = function(opt_capabilitiesTemplate) { |
| + var capabilities = { |
| version: '1.0', |
| printer: { |
| page_orientation: { |
| @@ -219,7 +221,21 @@ cr.define('print_preview', function() { |
| color: { option: [{type: 'STANDARD_COLOR', is_default: true}] } |
| } |
| }; |
| - return dest; |
| + if (opt_capabilitiesTemplate) { |
| + var mediaSize = opt_capabilitiesTemplate.printer.media_size; |
| + 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; |
| + } |
| + capabilities.printer.media_size = mediaSize; |
| + } |
| + return capabilities; |
| }; |
| DestinationStore.prototype = { |
| @@ -631,6 +647,10 @@ cr.define('print_preview', function() { |
| addEventListeners_: function() { |
| this.tracker_.add( |
| this.nativeLayer_, |
| + print_preview.NativeLayer.EventType.PDF_CAPABILITIES_READY, |
| + this.onPdfCapabilitiesReady_.bind(this)); |
| + this.tracker_.add( |
| + this.nativeLayer_, |
| print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET, |
| this.onLocalDestinationsSet_.bind(this)); |
| this.tracker_.add( |
| @@ -656,6 +676,23 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| + * Creates a local PDF print destination. |
| + * @return {!print_preview.Destination} Created print destination. |
| + * @private |
| + */ |
| + createLocalPdfPrintDestination_: function() { |
| + var destination = 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); |
| + destination.capabilities = this.pdfCapabilities_; |
| + return destination; |
| + }, |
| + |
| + /** |
| * Resets the state of the destination store to its initial state. |
| * @private |
| */ |
| @@ -665,8 +702,7 @@ cr.define('print_preview', function() { |
| this.selectDestination(null); |
| this.loadedCloudOrigins_ = {}; |
| this.hasLoadedAllLocalDestinations_ = false; |
| - this.insertDestination_( |
| - DestinationStore.createLocalPdfPrintDestination_()); |
| + this.insertDestination_(this.createLocalPdfPrintDestination_()); |
| this.resetAutoSelectTimeout_(); |
| }, |
| @@ -692,6 +728,23 @@ cr.define('print_preview', function() { |
| } |
| }, |
| + onPdfCapabilitiesReady_: function(event) { |
| + this.pdfCapabilities_ = |
| + DestinationStore.createPdfCapabilities_(event.capabilities); |
| + if (this.destinations_[0] && |
|
Vitaly Buka (NO REVIEWS)
2014/05/20 22:52:19
Why do you need this if?
|
| + this.destinations_[0].id == |
| + print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| + var pdfDestination = this.destinations_[0]; |
| + pdfDestination.capabilities = this.pdfCapabilities_; |
| + if (this.selectedDestination_ && |
| + this.selectedDestination_.id == pdfDestination.id) { |
| + cr.dispatchSimpleEvent(this, |
| + DestinationStore.EventType. |
| + SELECTED_DESTINATION_CAPABILITIES_READY); |
| + } |
| + } |
| + }, |
| + |
| /** |
| * Called when the local destinations have been got from the native layer. |
| * @param {Event} Contains the local destinations. |