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

Side by Side Diff: chrome/browser/resources/print_preview/native_layer.js

Issue 1144983002: Introduce concept of provisional destinations to print preview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 6 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
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.exportPath('print_preview'); 5 cr.exportPath('print_preview');
6 6
7 /** 7 /**
8 * @typedef {{selectSaveAsPdfDestination: boolean, 8 * @typedef {{selectSaveAsPdfDestination: boolean,
9 * layoutSettings.portrait: boolean, 9 * layoutSettings.portrait: boolean,
10 * pageRange: string, 10 * pageRange: string,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 this.onPrivetCapabilitiesSet_.bind(this); 60 this.onPrivetCapabilitiesSet_.bind(this);
61 global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this); 61 global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this);
62 global.onExtensionPrintersAdded = 62 global.onExtensionPrintersAdded =
63 this.onExtensionPrintersAdded_.bind(this); 63 this.onExtensionPrintersAdded_.bind(this);
64 global.onExtensionCapabilitiesSet = 64 global.onExtensionCapabilitiesSet =
65 this.onExtensionCapabilitiesSet_.bind(this); 65 this.onExtensionCapabilitiesSet_.bind(this);
66 global.onEnableManipulateSettingsForTest = 66 global.onEnableManipulateSettingsForTest =
67 this.onEnableManipulateSettingsForTest_.bind(this); 67 this.onEnableManipulateSettingsForTest_.bind(this);
68 global.printPresetOptionsFromDocument = 68 global.printPresetOptionsFromDocument =
69 this.onPrintPresetOptionsFromDocument_.bind(this); 69 this.onPrintPresetOptionsFromDocument_.bind(this);
70 global.onProvisionalPrinterResolved =
71 this.onProvisionalDestinationResolved_.bind(this);
72 global.failedToResolveProvisionalPrinter =
73 this.failedToResolveProvisionalDestination_.bind(this);
70 }; 74 };
71 75
72 /** 76 /**
73 * Event types dispatched from the Chromium native layer. 77 * Event types dispatched from the Chromium native layer.
74 * @enum {string} 78 * @enum {string}
75 * @const 79 * @const
76 */ 80 */
77 NativeLayer.EventType = { 81 NativeLayer.EventType = {
78 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', 82 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY',
79 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', 83 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET',
(...skipping 19 matching lines...) Expand all
99 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', 103 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID',
100 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', 104 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED',
101 PRIVET_CAPABILITIES_SET: 105 PRIVET_CAPABILITIES_SET:
102 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', 106 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET',
103 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', 107 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED',
104 EXTENSION_PRINTERS_ADDED: 108 EXTENSION_PRINTERS_ADDED:
105 'print_preview.NativeLayer.EXTENSION_PRINTERS_ADDED', 109 'print_preview.NativeLayer.EXTENSION_PRINTERS_ADDED',
106 EXTENSION_CAPABILITIES_SET: 110 EXTENSION_CAPABILITIES_SET:
107 'print_preview.NativeLayer.EXTENSION_CAPABILITIES_SET', 111 'print_preview.NativeLayer.EXTENSION_CAPABILITIES_SET',
108 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', 112 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS',
113 PROVISIONAL_DESTINATION_RESOLVED:
114 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED'
109 }; 115 };
110 116
111 /** 117 /**
112 * Constant values matching printing::DuplexMode enum. 118 * Constant values matching printing::DuplexMode enum.
113 * @enum {number} 119 * @enum {number}
114 */ 120 */
115 NativeLayer.DuplexMode = { 121 NativeLayer.DuplexMode = {
116 SIMPLEX: 0, 122 SIMPLEX: 0,
117 LONG_EDGE: 1, 123 LONG_EDGE: 1,
118 UNKNOWN_DUPLEX_MODE: -1 124 UNKNOWN_DUPLEX_MODE: -1
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 /** 213 /**
208 * Requests the destination's printing capabilities. A CAPABILITIES_SET 214 * Requests the destination's printing capabilities. A CAPABILITIES_SET
209 * event will be dispatched in response. 215 * event will be dispatched in response.
210 * @param {string} destinationId ID of the destination. 216 * @param {string} destinationId ID of the destination.
211 */ 217 */
212 startGetLocalDestinationCapabilities: function(destinationId) { 218 startGetLocalDestinationCapabilities: function(destinationId) {
213 chrome.send('getPrinterCapabilities', [destinationId]); 219 chrome.send('getPrinterCapabilities', [destinationId]);
214 }, 220 },
215 221
216 /** 222 /**
223 * Requests Chrome to resolve provisional extension destination by granting
224 * the provider extension access to the printer. Chrome will respond with
225 * the resolved destination properties by calling
226 * {@code onProvisionalPrinterResolved}, or in case of an error
227 * {@code failedToResolveProvisionalPrinter}
228 * @param {string} provisionalDestinationId
229 */
230 grantExtensionPrinterAccess: function(provisionalDestinationId) {
231 chrome.send('grantExtensionPrinterAccess', [provisionalDestinationId]);
232 },
233
234 /**
217 * @param {!print_preview.Destination} destination Destination to print to. 235 * @param {!print_preview.Destination} destination Destination to print to.
218 * @param {!print_preview.ticket_items.Color} color Color ticket item. 236 * @param {!print_preview.ticket_items.Color} color Color ticket item.
219 * @return {number} Native layer color model. 237 * @return {number} Native layer color model.
220 * @private 238 * @private
221 */ 239 */
222 getNativeColorModel_: function(destination, color) { 240 getNativeColorModel_: function(destination, color) {
223 // For non-local printers native color model is ignored anyway. 241 // For non-local printers native color model is ignored anyway.
224 var option = destination.isLocal ? color.getSelectedOption() : null; 242 var option = destination.isLocal ? color.getSelectedOption() : null;
225 var nativeColorModel = parseInt(option ? option.vendor_id : null, 10); 243 var nativeColorModel = parseInt(option ? option.vendor_id : null, 10);
226 if (isNaN(nativeColorModel)) { 244 if (isNaN(nativeColorModel)) {
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); 781 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED);
764 privetPrintFailedEvent.httpError = http_error; 782 privetPrintFailedEvent.httpError = http_error;
765 this.dispatchEvent(privetPrintFailedEvent); 783 this.dispatchEvent(privetPrintFailedEvent);
766 }, 784 },
767 785
768 /** 786 /**
769 * @param {Array<!{extensionId: string, 787 * @param {Array<!{extensionId: string,
770 * extensionName: string, 788 * extensionName: string,
771 * id: string, 789 * id: string,
772 * name: string, 790 * name: string,
773 * description: (string|undefined)}>} printers The list 791 * description: (string|undefined),
792 * provisional: (boolean|undefined)}>} printers The list
774 * containing information about printers added by an extension. 793 * containing information about printers added by an extension.
775 * @param {boolean} done Whether this is the final list of extension 794 * @param {boolean} done Whether this is the final list of extension
776 * managed printers. 795 * managed printers.
777 */ 796 */
778 onExtensionPrintersAdded_: function(printers, done) { 797 onExtensionPrintersAdded_: function(printers, done) {
779 var event = new Event(NativeLayer.EventType.EXTENSION_PRINTERS_ADDED); 798 var event = new Event(NativeLayer.EventType.EXTENSION_PRINTERS_ADDED);
780 event.printers = printers; 799 event.printers = printers;
781 event.done = done; 800 event.done = done;
782 this.dispatchEvent(event); 801 this.dispatchEvent(event);
783 }, 802 },
784 803
785 /** 804 /**
786 * Called when an extension responds to a request for an extension printer 805 * Called when an extension responds to a request for an extension printer
787 * capabilities. 806 * capabilities.
788 * @param {string} printerId The printer's ID. 807 * @param {string} printerId The printer's ID.
789 * @param {!Object} capabilities The reported printer capabilities. 808 * @param {!Object} capabilities The reported printer capabilities.
790 */ 809 */
791 onExtensionCapabilitiesSet_: function(printerId, 810 onExtensionCapabilitiesSet_: function(printerId,
792 capabilities) { 811 capabilities) {
793 var event = new Event(NativeLayer.EventType.EXTENSION_CAPABILITIES_SET); 812 var event = new Event(NativeLayer.EventType.EXTENSION_CAPABILITIES_SET);
794 event.printerId = printerId; 813 event.printerId = printerId;
795 event.capabilities = capabilities; 814 event.capabilities = capabilities;
796 this.dispatchEvent(event); 815 this.dispatchEvent(event);
797 }, 816 },
798 817
818 /**
819 * Called when Chrome reports that attempt to resolve a provisional
820 * destination failed.
821 * @param {string} destinationId The provisional destination ID.
822 * @private
823 */
824 failedToResolveProvisionalDestination_: function(destinationId) {
825 var evt = new Event(
826 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED);
827 evt.provisionalId = destinationId;
828 evt.destination = null;
829 this.dispatchEvent(evt);
830 },
831
832 /**
833 * Called when Chrome reports that a provisional destination has been
834 * successfully resolved.
835 * Currently used only for extension provided destinations.
836 * @param {string} provisionalDestinationId The provisional destination id.
837 * @param {!{extensionId: string,
838 * extensionName: string,
839 * id: string,
840 * name: string,
841 * description: (string|undefined)}} destinationInfo The resolved
842 * destination info.
843 * @private
844 */
845 onProvisionalDestinationResolved_: function(provisionalDestinationId,
846 destinationInfo) {
847 var evt = new Event(
848 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED);
849 evt.provisionalId = provisionalDestinationId;
850 evt.destination = destinationInfo;
851 this.dispatchEvent(evt);
852 },
853
799 /** 854 /**
800 * Allows for onManipulateSettings to be called 855 * Allows for onManipulateSettings to be called
801 * from the native layer. 856 * from the native layer.
802 * @private 857 * @private
803 */ 858 */
804 onEnableManipulateSettingsForTest_: function() { 859 onEnableManipulateSettingsForTest_: function() {
805 global.onManipulateSettingsForTest = 860 global.onManipulateSettingsForTest =
806 this.onManipulateSettingsForTest_.bind(this); 861 this.onManipulateSettingsForTest_.bind(this);
807 }, 862 },
808 863
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 return this.serializedAppStateStr_; 1088 return this.serializedAppStateStr_;
1034 } 1089 }
1035 }; 1090 };
1036 1091
1037 // Export 1092 // Export
1038 return { 1093 return {
1039 NativeInitialSettings: NativeInitialSettings, 1094 NativeInitialSettings: NativeInitialSettings,
1040 NativeLayer: NativeLayer 1095 NativeLayer: NativeLayer
1041 }; 1096 };
1042 }); 1097 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698