Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1284)

Side by Side Diff: chrome/browser/resources/print_preview/data/destination_store.js

Issue 294923005: Add media size capability to PDF printer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * A data store that stores destinations and dispatches events when the data 9 * A data store that stores destinations and dispatches events when the data
10 * store changes. 10 * store changes.
(...skipping 30 matching lines...) Expand all
41 this.appState_ = appState; 41 this.appState_ = appState;
42 42
43 /** 43 /**
44 * Used to track metrics. 44 * Used to track metrics.
45 * @type {!print_preview.AppState} 45 * @type {!print_preview.AppState}
46 * @private 46 * @private
47 */ 47 */
48 this.metrics_ = metrics; 48 this.metrics_ = metrics;
49 49
50 /** 50 /**
51 * Cached local PDF printer capabilities.
52 * @type {Object}
53 * @private
54 */
55 this.pdfCapabilities_ = DestinationStore.createPdfCapabilities_();
56
57 /**
51 * Internal backing store for the data store. 58 * Internal backing store for the data store.
52 * @type {!Array.<!print_preview.Destination>} 59 * @type {!Array.<!print_preview.Destination>}
53 * @private 60 * @private
54 */ 61 */
55 this.destinations_ = []; 62 this.destinations_ = [];
56 63
57 /** 64 /**
58 * Cache used for constant lookup of destinations by origin and id. 65 * Cache used for constant lookup of destinations by origin and id.
59 * @type {object.<string, !print_preview.Destination>} 66 * @type {object.<string, !print_preview.Destination>}
60 * @private 67 * @private
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 194
188 /** 195 /**
189 * Amount of time spent searching for privet destination, in milliseconds. 196 * Amount of time spent searching for privet destination, in milliseconds.
190 * @type {number} 197 * @type {number}
191 * @const 198 * @const
192 * @private 199 * @private
193 */ 200 */
194 DestinationStore.PRIVET_SEARCH_DURATION_ = 2000; 201 DestinationStore.PRIVET_SEARCH_DURATION_ = 2000;
195 202
196 /** 203 /**
197 * Creates a local PDF print destination. 204 * Creates capabilities for local PDF printer destination.
198 * @return {!print_preview.Destination} Created print destination. 205 * @param {Object=} opt_capabilitiesTemplate Some of the capabilities to fill
206 * in the printer ones.
207 * @return {!Object} PDF printer capabilities.
199 * @private 208 * @private
200 */ 209 */
201 DestinationStore.createLocalPdfPrintDestination_ = function() { 210 DestinationStore.createPdfCapabilities_ = function(opt_capabilitiesTemplate) {
202 var dest = new print_preview.Destination( 211 var capabilities = {
203 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
204 print_preview.Destination.Type.LOCAL,
205 print_preview.Destination.Origin.LOCAL,
206 localStrings.getString('printToPDF'),
207 false /*isRecent*/,
208 print_preview.Destination.ConnectionStatus.ONLINE);
209 dest.capabilities = {
210 version: '1.0', 212 version: '1.0',
211 printer: { 213 printer: {
212 page_orientation: { 214 page_orientation: {
213 option: [ 215 option: [
214 {type: 'AUTO', is_default: true}, 216 {type: 'AUTO', is_default: true},
215 {type: 'PORTRAIT'}, 217 {type: 'PORTRAIT'},
216 {type: 'LANDSCAPE'} 218 {type: 'LANDSCAPE'}
217 ] 219 ]
218 }, 220 },
219 color: { option: [{type: 'STANDARD_COLOR', is_default: true}] } 221 color: { option: [{type: 'STANDARD_COLOR', is_default: true}] }
220 } 222 }
221 }; 223 };
222 return dest; 224 if (opt_capabilitiesTemplate) {
225 var mediaSize = opt_capabilitiesTemplate.printer.media_size;
226 var mediaDisplayNames = {
227 'ISO_A4': 'A4',
228 'ISO_A3': 'A3',
229 'NA_LETTER': 'Letter',
230 'NA_LEGAL': 'Legal',
231 'NA_LEDGER': 'Tabloid'
232 };
233 for (var i = 0, media; media = mediaSize.option[i]; i++) {
234 media.custom_display_name = mediaDisplayNames[media.name] || media.name;
235 }
236 capabilities.printer.media_size = mediaSize;
237 }
238 return capabilities;
223 }; 239 };
224 240
225 DestinationStore.prototype = { 241 DestinationStore.prototype = {
226 __proto__: cr.EventTarget.prototype, 242 __proto__: cr.EventTarget.prototype,
227 243
228 /** 244 /**
229 * @param {string=} opt_account Account to filter destinations by. When 245 * @param {string=} opt_account Account to filter destinations by. When
230 * omitted, all destinations are returned. 246 * omitted, all destinations are returned.
231 * @return {!Array.<!print_preview.Destination>} List of destinations 247 * @return {!Array.<!print_preview.Destination>} List of destinations
232 * accessible by the {@code account}. 248 * accessible by the {@code account}.
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 } 640 }
625 }, 641 },
626 642
627 /** 643 /**
628 * Binds handlers to events. 644 * Binds handlers to events.
629 * @private 645 * @private
630 */ 646 */
631 addEventListeners_: function() { 647 addEventListeners_: function() {
632 this.tracker_.add( 648 this.tracker_.add(
633 this.nativeLayer_, 649 this.nativeLayer_,
650 print_preview.NativeLayer.EventType.PDF_CAPABILITIES_READY,
651 this.onPdfCapabilitiesReady_.bind(this));
652 this.tracker_.add(
653 this.nativeLayer_,
634 print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET, 654 print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET,
635 this.onLocalDestinationsSet_.bind(this)); 655 this.onLocalDestinationsSet_.bind(this));
636 this.tracker_.add( 656 this.tracker_.add(
637 this.nativeLayer_, 657 this.nativeLayer_,
638 print_preview.NativeLayer.EventType.CAPABILITIES_SET, 658 print_preview.NativeLayer.EventType.CAPABILITIES_SET,
639 this.onLocalDestinationCapabilitiesSet_.bind(this)); 659 this.onLocalDestinationCapabilitiesSet_.bind(this));
640 this.tracker_.add( 660 this.tracker_.add(
641 this.nativeLayer_, 661 this.nativeLayer_,
642 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL, 662 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL,
643 this.onGetCapabilitiesFail_.bind(this)); 663 this.onGetCapabilitiesFail_.bind(this));
644 this.tracker_.add( 664 this.tracker_.add(
645 this.nativeLayer_, 665 this.nativeLayer_,
646 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD, 666 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD,
647 this.onDestinationsReload_.bind(this)); 667 this.onDestinationsReload_.bind(this));
648 this.tracker_.add( 668 this.tracker_.add(
649 this.nativeLayer_, 669 this.nativeLayer_,
650 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, 670 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED,
651 this.onPrivetPrinterAdded_.bind(this)); 671 this.onPrivetPrinterAdded_.bind(this));
652 this.tracker_.add( 672 this.tracker_.add(
653 this.nativeLayer_, 673 this.nativeLayer_,
654 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, 674 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET,
655 this.onPrivetCapabilitiesSet_.bind(this)); 675 this.onPrivetCapabilitiesSet_.bind(this));
656 }, 676 },
657 677
658 /** 678 /**
679 * Creates a local PDF print destination.
680 * @return {!print_preview.Destination} Created print destination.
681 * @private
682 */
683 createLocalPdfPrintDestination_: function() {
684 var destination = new print_preview.Destination(
685 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
686 print_preview.Destination.Type.LOCAL,
687 print_preview.Destination.Origin.LOCAL,
688 localStrings.getString('printToPDF'),
689 false /*isRecent*/,
690 print_preview.Destination.ConnectionStatus.ONLINE);
691 destination.capabilities = this.pdfCapabilities_;
692 return destination;
693 },
694
695 /**
659 * Resets the state of the destination store to its initial state. 696 * Resets the state of the destination store to its initial state.
660 * @private 697 * @private
661 */ 698 */
662 reset_: function() { 699 reset_: function() {
663 this.destinations_ = []; 700 this.destinations_ = [];
664 this.destinationMap_ = {}; 701 this.destinationMap_ = {};
665 this.selectDestination(null); 702 this.selectDestination(null);
666 this.loadedCloudOrigins_ = {}; 703 this.loadedCloudOrigins_ = {};
667 this.hasLoadedAllLocalDestinations_ = false; 704 this.hasLoadedAllLocalDestinations_ = false;
668 this.insertDestination_( 705 this.insertDestination_(this.createLocalPdfPrintDestination_());
669 DestinationStore.createLocalPdfPrintDestination_());
670 this.resetAutoSelectTimeout_(); 706 this.resetAutoSelectTimeout_();
671 }, 707 },
672 708
673 /** 709 /**
674 * Resets destination auto selection timeout. 710 * Resets destination auto selection timeout.
675 * @private 711 * @private
676 */ 712 */
677 resetAutoSelectTimeout_: function() { 713 resetAutoSelectTimeout_: function() {
678 this.cancelAutoSelectTimeout_(); 714 this.cancelAutoSelectTimeout_();
679 this.autoSelectTimeout_ = 715 this.autoSelectTimeout_ =
680 setTimeout(this.onAutoSelectFailed_.bind(this), 716 setTimeout(this.onAutoSelectFailed_.bind(this),
681 DestinationStore.AUTO_SELECT_TIMEOUT_); 717 DestinationStore.AUTO_SELECT_TIMEOUT_);
682 }, 718 },
683 719
684 /** 720 /**
685 * Cancels destination auto selection timeout. 721 * Cancels destination auto selection timeout.
686 * @private 722 * @private
687 */ 723 */
688 cancelAutoSelectTimeout_: function() { 724 cancelAutoSelectTimeout_: function() {
689 if (this.autoSelectTimeout_ != null) { 725 if (this.autoSelectTimeout_ != null) {
690 clearTimeout(this.autoSelectTimeout_); 726 clearTimeout(this.autoSelectTimeout_);
691 this.autoSelectTimeout_ = null; 727 this.autoSelectTimeout_ = null;
692 } 728 }
693 }, 729 },
694 730
731 onPdfCapabilitiesReady_: function(event) {
732 this.pdfCapabilities_ =
733 DestinationStore.createPdfCapabilities_(event.capabilities);
734 if (this.destinations_[0] &&
Vitaly Buka (NO REVIEWS) 2014/05/20 22:52:19 Why do you need this if?
735 this.destinations_[0].id ==
736 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) {
737 var pdfDestination = this.destinations_[0];
738 pdfDestination.capabilities = this.pdfCapabilities_;
739 if (this.selectedDestination_ &&
740 this.selectedDestination_.id == pdfDestination.id) {
741 cr.dispatchSimpleEvent(this,
742 DestinationStore.EventType.
743 SELECTED_DESTINATION_CAPABILITIES_READY);
744 }
745 }
746 },
747
695 /** 748 /**
696 * Called when the local destinations have been got from the native layer. 749 * Called when the local destinations have been got from the native layer.
697 * @param {Event} Contains the local destinations. 750 * @param {Event} Contains the local destinations.
698 * @private 751 * @private
699 */ 752 */
700 onLocalDestinationsSet_: function(event) { 753 onLocalDestinationsSet_: function(event) {
701 var localDestinations = event.destinationInfos.map(function(destInfo) { 754 var localDestinations = event.destinationInfos.map(function(destInfo) {
702 return print_preview.LocalDestinationParser.parse(destInfo); 755 return print_preview.LocalDestinationParser.parse(destInfo);
703 }); 756 });
704 this.insertDestinations_(localDestinations); 757 this.insertDestinations_(localDestinations);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 return id == this.appState_.selectedDestinationId && 967 return id == this.appState_.selectedDestinationId &&
915 origin == this.appState_.selectedDestinationOrigin; 968 origin == this.appState_.selectedDestinationOrigin;
916 } 969 }
917 }; 970 };
918 971
919 // Export 972 // Export
920 return { 973 return {
921 DestinationStore: DestinationStore 974 DestinationStore: DestinationStore
922 }; 975 };
923 }); 976 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698