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 be89fcaba473a69acc87e0085f85a2c779d8aaa9..db11b578c492a561bd3202df0ed53cde09fe8cbc 100644 |
--- a/chrome/browser/resources/print_preview/data/destination_store.js |
+++ b/chrome/browser/resources/print_preview/data/destination_store.js |
@@ -39,7 +39,7 @@ cr.define('print_preview', function() { |
this.destinations_ = []; |
/** |
- * Cache used for constant lookup of destinations by ID. |
+ * Cache used for constant lookup of destinations by origin and id. |
* @type {object.<string, !print_preview.Destination>} |
* @private |
*/ |
@@ -62,11 +62,11 @@ cr.define('print_preview', function() { |
this.initialDestinationId_ = null; |
/** |
- * Whether the initial destination is a local one or not. |
- * @type {boolean} |
+ * Initial origin used to auto-select destination. |
+ * @type {print_preview.Destination.Origin} |
* @private |
*/ |
- this.isInitialDestinationLocal_ = true; |
+ this.initialDestinationOrigin_ = print_preview.Destination.Origin.LOCAL; |
/** |
* Whether the destination store will auto select the destination that |
@@ -154,7 +154,7 @@ cr.define('print_preview', function() { |
var dest = new print_preview.Destination( |
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
print_preview.Destination.Type.LOCAL, |
- print_preview.Destination.AuthType.LOCAL, |
+ print_preview.Destination.Origin.LOCAL, |
localStrings.getString('printToPDF'), |
false /*isRecent*/, |
print_preview.Destination.ConnectionStatus.ONLINE); |
@@ -218,25 +218,31 @@ cr.define('print_preview', function() { |
* @private |
*/ |
init: function(systemDefaultDestinationId) { |
- if (this.appState_.selectedDestinationId) { |
+ if (this.appState_.selectedDestinationId && |
+ this.appState_.selectedDestinationOrigin) { |
this.initialDestinationId_ = this.appState_.selectedDestinationId; |
- this.isInitialDestinationLocal_ = |
- this.appState_.isSelectedDestinationLocal; |
+ this.initialDestinationOrigin_ = |
+ this.appState_.selectedDestinationOrigin_; |
} else { |
this.initialDestinationId_ = systemDefaultDestinationId; |
- this.isInitialDestinationLocal_ = true; |
+ this.initialDestinationOrigin_ = |
+ print_preview.Destination.Origin.LOCAL; |
} |
- |
this.isInAutoSelectMode_ = true; |
- if (this.initialDestinationId_ == null) { |
+ if (this.initialDestinationId_ == null || |
+ this.initialDestinationOrigin_ == null) { |
assert(this.destinations_.length > 0, |
'No destinations available to select'); |
this.selectDestination(this.destinations_[0]); |
} else { |
- var candidate = this.destinationMap_[this.initialDestinationId_]; |
+ var key = this.getDestinationKey_(this.initialDestinationOrigin_, |
+ this.initialDestinationId_); |
+ var candidate = this.destinationMap_[key]; |
if (candidate != null) { |
this.selectDestination(candidate); |
- } else if (!cr.isChromeOS && this.isInitialDestinationLocal_) { |
+ } else if (!cr.isChromeOS && |
+ this.initialDestinationOrigin_ == |
+ print_preview.Destination.Origin.LOCAL) { |
this.nativeLayer_.startGetLocalDestinationCapabilities( |
this.initialDestinationId_); |
} |
@@ -267,8 +273,10 @@ cr.define('print_preview', function() { |
cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED, |
this.onCloudPrintPrinterFailed_.bind(this)); |
// Fetch initial destination if its a cloud destination. |
- if (this.isInAutoSelectMode_ && !this.isInitialDestinationLocal_) { |
- this.cloudPrintInterface_.printer(this.initialDestinationId_); |
+ var origin = this.initialDestinationOrigin_; |
+ if (this.isInAutoSelectMode_ && |
+ origin != print_preview.Destination.Origin.LOCAL) { |
+ this.cloudPrintInterface_.printer(this.initialDestinationId_, origin); |
} |
}, |
@@ -313,7 +321,8 @@ cr.define('print_preview', function() { |
assert(this.cloudPrintInterface_ != null, |
'Selected destination is a cloud destination, but Google ' + |
'Cloud Print is not enabled'); |
- this.cloudPrintInterface_.printer(destination.id); |
+ this.cloudPrintInterface_.printer(destination.id, |
+ destination.origin); |
} |
} else { |
cr.dispatchSimpleEvent( |
@@ -379,12 +388,14 @@ cr.define('print_preview', function() { |
* updated. |
*/ |
updateDestination: function(destination) { |
- var existingDestination = this.destinationMap_[destination.id]; |
+ var key = this.getDestinationKey_(destination.origin, destination.id); |
+ var existingDestination = this.destinationMap_[key]; |
if (existingDestination != null) { |
existingDestination.capabilities = destination.capabilities; |
return existingDestination; |
} else { |
this.insertDestination(destination); |
+ return destination; |
Toscano
2013/04/18 22:45:40
No it should be "return null;" since the destinati
|
} |
}, |
@@ -418,10 +429,11 @@ cr.define('print_preview', function() { |
* @private |
*/ |
insertDestination_: function(destination) { |
- var existingDestination = this.destinationMap_[destination.id]; |
+ var key = this.getDestinationKey_(destination.origin, destination.id); |
+ var existingDestination = this.destinationMap_[key]; |
if (existingDestination == null) { |
this.destinations_.push(destination); |
- this.destinationMap_[destination.id] = destination; |
+ this.destinationMap_[key] = destination; |
return true; |
} else if (existingDestination.connectionStatus == |
print_preview.Destination.ConnectionStatus.UNKNOWN && |
@@ -499,7 +511,10 @@ cr.define('print_preview', function() { |
*/ |
onLocalDestinationCapabilitiesSet_: function(event) { |
var destinationId = event.settingsInfo['printerId']; |
- var destination = this.destinationMap_[destinationId]; |
+ var key = |
+ this.getDestinationKey_(print_preview.Destination.Origin.LOCAL, |
+ destinationId); |
+ var destination = this.destinationMap_[key]; |
var capabilities = print_preview.LocalCapabilitiesParser.parse( |
event.settingsInfo); |
if (destination) { |
@@ -625,6 +640,16 @@ cr.define('print_preview', function() { |
assert(this.destinations_.length > 0, |
'No destinations were loaded before auto-select timeout expired'); |
this.selectDestination(this.destinations_[0]); |
+ }, |
+ |
+ /** |
+ * Returns key to be used with {@code destinationMap_}. |
+ * @param {!print_preview.Destination.Origin} origin Destination origin. |
+ * @return {!string} id Destination id. |
+ * @private |
+ */ |
+ getDestinationKey_: function(origin, id) { |
+ return origin + '/' + id; |
} |
}; |