| 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 6f52f234d593b34e24ddd3a133d9404ac0ee2635..60d8d0ecc9fce62b0186e4b27f86d8c78989cf96 100644
|
| --- a/chrome/browser/resources/print_preview/data/destination_store.js
|
| +++ b/chrome/browser/resources/print_preview/data/destination_store.js
|
| @@ -199,6 +199,8 @@ cr.define('print_preview', function() {
|
| DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT',
|
| DESTINATIONS_INSERTED:
|
| 'print_preview.DestinationStore.DESTINATIONS_INSERTED',
|
| + PROVISIONAL_DESTINATION_RESOLVED:
|
| + 'print_preview.DestinationStore.PROVISIONAL_DESTINATION_RESOLVED',
|
| CACHED_SELECTED_DESTINATION_INFO_READY:
|
| 'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY',
|
| SELECTED_DESTINATION_CAPABILITIES_READY:
|
| @@ -461,6 +463,9 @@ cr.define('print_preview', function() {
|
| this, DestinationStore.EventType.DESTINATION_SELECT);
|
| return;
|
| }
|
| +
|
| + assert(!destination.isProvisional, 'Selecting provisonal destination');
|
| +
|
| // Update and persist selected destination.
|
| this.selectedDestination_ = destination;
|
| this.selectedDestination_.isRecent = true;
|
| @@ -511,6 +516,17 @@ cr.define('print_preview', function() {
|
| }
|
| },
|
|
|
| + resolveProvisionalDestination: function(destination) {
|
| + assert(
|
| + destination.provisionalType ==
|
| + print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION,
|
| + 'Provisional type cannot be resolved.');
|
| + assert(destination.usbId != null,
|
| + 'Resolving provisional destination without USB ID.');
|
| + this.nativeLayer_.grantUsbExtensionPermission(
|
| + destination.id, destination.extensionId, destination.usbId);
|
| + },
|
| +
|
| /**
|
| * Selects 'Save to PDF' destination (since it always exists).
|
| * @private
|
| @@ -613,6 +629,36 @@ cr.define('print_preview', function() {
|
| this.waitForRegisterDestination_ = id;
|
| },
|
|
|
| + resolveProvisionalDestination_: function(evt) {
|
| + var provisionalDestinationIndex = -1;
|
| + var provisionalDestination = null;
|
| + for (var i = 0; i < this.destinations_.length; ++i) {
|
| + if (evt.provisionalId == this.destinations_[i].id) {
|
| + provisionalDestinationIndex = i;
|
| + provisionalDestination = this.destinations_[i];
|
| + break;
|
| + }
|
| + }
|
| +
|
| + if (!provisionalDestination)
|
| + return;
|
| +
|
| + this.destinations_.splice(provisionalDestinationIndex, 1);
|
| + this.destinationMap_[this.getKey_(provisionalDestination)] = undefined;
|
| +
|
| + var destination = evt.destination ?
|
| + print_preview.ExtensionDestinationParser.parse(evt.destination) :
|
| + null;
|
| + if (destination)
|
| + this.insertIntoStore_(destination);
|
| +
|
| + var event = new Event(
|
| + DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED);
|
| + event.provisionalId = evt.provisionalId;
|
| + event.destination = destination;
|
| + this.dispatchEvent(event);
|
| + },
|
| +
|
| /**
|
| * Inserts {@code destination} to the data store and dispatches a
|
| * DESTINATIONS_INSERTED event.
|
| @@ -782,6 +828,10 @@ cr.define('print_preview', function() {
|
| this.nativeLayer_,
|
| print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET,
|
| this.onExtensionCapabilitiesSet_.bind(this));
|
| + this.tracker_.add(
|
| + this.nativeLayer_,
|
| + print_preview.NativeLayer.EventType.EXTENSION_USB_PRINTER_RESOLVED,
|
| + this.resolveProvisionalDestination_.bind(this));
|
| },
|
|
|
| /**
|
| @@ -1008,14 +1058,29 @@ cr.define('print_preview', function() {
|
| * @private
|
| */
|
| onExtensionPrintersAdded_: function(event) {
|
| - // Filter out printers enumerated from providers' "usbPrinters" manifest
|
| - // key for now.
|
| - var filteredPrinters = event.printers.filter(function(printer) {
|
| - return 'extensionId' in printer;
|
| - });
|
| - this.insertDestinations_(filteredPrinters.map(function(printer) {
|
| - return print_preview.ExtensionDestinationParser.parse(printer);
|
| - }));
|
| + event.printers.forEach(function(printer) {
|
| + if (!printer.needsUsbPermission) {
|
| + this.insertDestinations_([
|
| + print_preview.ExtensionDestinationParser.parse(printer)
|
| + ]);
|
| + return;
|
| + }
|
| +
|
| + // Add provisional extension destinations that support a USB printer.
|
| + printer.extensions.forEach(function(extension) {
|
| + var provisionalDest = print_preview.ExtensionDestinationParser.parse({
|
| + id: extension.printerId,
|
| + extensionId: extension.extensionId,
|
| + extensionName: extension.extensionName,
|
| + name: printer.name,
|
| + usbDevice: printer.usbDevice
|
| + });
|
| +
|
| + provisionalDest.provisionalType =
|
| + print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION;
|
| + this.insertDestinations_([provisionalDest]);
|
| + }.bind(this));
|
| + }.bind(this));
|
|
|
| if (event.done && this.isExtensionDestinationSearchInProgress_) {
|
| clearTimeout(this.extensionSearchTimeout_);
|
|
|