Commit f48a2afd authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Update DestinationStore events

- Remove events that have no listeners
- Restore a listener for an event that is still useful
- Remove usage of "new Event()" and cr.dispatchSimpleEvent which calls
it, in favor of CustomEvent
- For an event where the payload is/was unused, remove payload.

Bug: None
Change-Id: I647bb1b826df8f872482b444549829ae9d4e963c
Reviewed-on: https://chromium-review.googlesource.com/c/1394916Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619854}
parent 9d870bed
...@@ -518,11 +518,9 @@ cr.define('print_preview', function() { ...@@ -518,11 +518,9 @@ cr.define('print_preview', function() {
if (capabilities) { if (capabilities) {
this.selectedDestination_.capabilities = capabilities; this.selectedDestination_.capabilities = capabilities;
this.dispatchEvent(
cr.dispatchSimpleEvent( new CustomEvent(DestinationStore.EventType
this, .SELECTED_DESTINATION_CAPABILITIES_READY));
DestinationStore.EventType
.CACHED_SELECTED_DESTINATION_INFO_READY);
} }
return true; return true;
} }
...@@ -690,8 +688,8 @@ cr.define('print_preview', function() { ...@@ -690,8 +688,8 @@ cr.define('print_preview', function() {
} }
if (destination == null) { if (destination == null) {
this.selectedDestination_ = null; this.selectedDestination_ = null;
cr.dispatchSimpleEvent( this.dispatchEvent(
this, DestinationStore.EventType.DESTINATION_SELECT); new CustomEvent(DestinationStore.EventType.DESTINATION_SELECT));
return; return;
} }
...@@ -715,8 +713,8 @@ cr.define('print_preview', function() { ...@@ -715,8 +713,8 @@ cr.define('print_preview', function() {
.CLOUD_DUPLICATE_SELECTED); .CLOUD_DUPLICATE_SELECTED);
} }
// Notify about selected destination change. // Notify about selected destination change.
cr.dispatchSimpleEvent( this.dispatchEvent(
this, DestinationStore.EventType.DESTINATION_SELECT); new CustomEvent(DestinationStore.EventType.DESTINATION_SELECT));
// Request destination capabilities from backend, since they are not // Request destination capabilities from backend, since they are not
// known yet. // known yet.
if (destination.capabilities == null) { if (destination.capabilities == null) {
...@@ -768,26 +766,20 @@ cr.define('print_preview', function() { ...@@ -768,26 +766,20 @@ cr.define('print_preview', function() {
/** /**
* Removes the destination from the store and replaces it with a * Removes the destination from the store and replaces it with a
* destination created from the resolved destination properties, * destination created from the resolved destination properties,
* if any are reported. Then sends a * if any are reported. Then returns the new destination.
* PROVISIONAL_DESTINATION_RESOLVED event.
*/ */
this.removeProvisionalDestination_(destination.id); this.removeProvisionalDestination_(destination.id);
const parsedDestination = const parsedDestination =
print_preview.parseExtensionDestination(destinationInfo); print_preview.parseExtensionDestination(destinationInfo);
this.insertIntoStore_(parsedDestination); this.insertIntoStore_(parsedDestination);
this.dispatchProvisionalDestinationResolvedEvent_(
destination.id, parsedDestination);
return parsedDestination; return parsedDestination;
}, },
() => { () => {
/** /**
* The provisional destination is removed from the store and a * The provisional destination is removed from the store and
* PROVISIONAL_DESTINATION_RESOLVED event is dispatched with a * null is returned.
* null destination.
*/ */
this.removeProvisionalDestination_(destination.id); this.removeProvisionalDestination_(destination.id);
this.dispatchProvisionalDestinationResolvedEvent_(
destination.id, null);
return null; return null;
}); });
} }
...@@ -861,8 +853,6 @@ cr.define('print_preview', function() { ...@@ -861,8 +853,6 @@ cr.define('print_preview', function() {
this.destinationSearchStatus_.set( this.destinationSearchStatus_.set(
type, print_preview.DestinationStorePrinterSearchStatus.DONE); type, print_preview.DestinationStorePrinterSearchStatus.DONE);
}); });
cr.dispatchSimpleEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED);
} }
/** /**
...@@ -878,8 +868,6 @@ cr.define('print_preview', function() { ...@@ -878,8 +868,6 @@ cr.define('print_preview', function() {
(opt_origin && origins.indexOf(opt_origin) < 0)) { (opt_origin && origins.indexOf(opt_origin) < 0)) {
this.cloudPrintInterface_.search( this.cloudPrintInterface_.search(
this.userInfo_.activeUser, opt_origin); this.userInfo_.activeUser, opt_origin);
cr.dispatchSimpleEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED);
} }
} }
} }
...@@ -888,8 +876,8 @@ cr.define('print_preview', function() { ...@@ -888,8 +876,8 @@ cr.define('print_preview', function() {
reloadUserCookieBasedDestinations() { reloadUserCookieBasedDestinations() {
const origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || []; const origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || [];
if (origins.indexOf(print_preview.DestinationOrigin.COOKIES) >= 0) { if (origins.indexOf(print_preview.DestinationOrigin.COOKIES) >= 0) {
cr.dispatchSimpleEvent( this.dispatchEvent(new CustomEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); DestinationStore.EventType.DESTINATION_SEARCH_DONE));
} else { } else {
this.startLoadCloudDestinations( this.startLoadCloudDestinations(
print_preview.DestinationOrigin.COOKIES); print_preview.DestinationOrigin.COOKIES);
...@@ -946,22 +934,6 @@ cr.define('print_preview', function() { ...@@ -946,22 +934,6 @@ cr.define('print_preview', function() {
}, this); }, this);
} }
/**
* Dispatches the PROVISIONAL_DESTINATION_RESOLVED event for id
* |provisionalId| and destination |destination|.
* @param {string} provisionalId The ID of the destination that was
* resolved.
* @param {?print_preview.Destination} destination Information about the
* destination if it was resolved successfully.
*/
dispatchProvisionalDestinationResolvedEvent_(provisionalId, destination) {
const event = new Event(
DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED);
event.provisionalId = provisionalId;
event.destination = destination;
this.dispatchEvent(event);
}
/** /**
* Inserts {@code destination} to the data store and dispatches a * Inserts {@code destination} to the data store and dispatches a
* DESTINATIONS_INSERTED event. * DESTINATIONS_INSERTED event.
...@@ -1010,8 +982,8 @@ cr.define('print_preview', function() { ...@@ -1010,8 +982,8 @@ cr.define('print_preview', function() {
* {@code autoSelectMatchingDestination_}. * {@code autoSelectMatchingDestination_}.
*/ */
destinationsInserted_(opt_destination) { destinationsInserted_(opt_destination) {
cr.dispatchSimpleEvent( this.dispatchEvent(
this, DestinationStore.EventType.DESTINATIONS_INSERTED); new CustomEvent(DestinationStore.EventType.DESTINATIONS_INSERTED));
if (this.autoSelectMatchingDestination_) { if (this.autoSelectMatchingDestination_) {
const destinationsToSearch = const destinationsToSearch =
opt_destination && [opt_destination] || this.destinations_; opt_destination && [opt_destination] || this.destinations_;
...@@ -1030,12 +1002,11 @@ cr.define('print_preview', function() { ...@@ -1030,12 +1002,11 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
sendSelectedDestinationUpdateEvent_() { sendSelectedDestinationUpdateEvent_() {
cr.dispatchSimpleEvent( this.dispatchEvent(new CustomEvent(
this,
this.selectedDestination_.shouldShowInvalidCertificateError ? this.selectedDestination_.shouldShowInvalidCertificateError ?
DestinationStore.EventType.SELECTED_DESTINATION_UNSUPPORTED : DestinationStore.EventType.SELECTED_DESTINATION_UNSUPPORTED :
DestinationStore.EventType DestinationStore.EventType
.SELECTED_DESTINATION_CAPABILITIES_READY); .SELECTED_DESTINATION_CAPABILITIES_READY));
} }
/** /**
...@@ -1152,8 +1123,8 @@ cr.define('print_preview', function() { ...@@ -1152,8 +1123,8 @@ cr.define('print_preview', function() {
this.autoSelectTimeout_ = setTimeout( this.autoSelectTimeout_ = setTimeout(
this.selectDefaultDestination_.bind(this), this.selectDefaultDestination_.bind(this),
DestinationStore.AUTO_SELECT_TIMEOUT_); DestinationStore.AUTO_SELECT_TIMEOUT_);
cr.dispatchSimpleEvent( this.dispatchEvent(
this, DestinationStore.EventType.DESTINATIONS_RESET); new CustomEvent(DestinationStore.EventType.DESTINATIONS_RESET));
} }
...@@ -1165,8 +1136,8 @@ cr.define('print_preview', function() { ...@@ -1165,8 +1136,8 @@ cr.define('print_preview', function() {
onDestinationSearchDone_(type) { onDestinationSearchDone_(type) {
this.destinationSearchStatus_.set( this.destinationSearchStatus_.set(
type, print_preview.DestinationStorePrinterSearchStatus.DONE); type, print_preview.DestinationStorePrinterSearchStatus.DONE);
cr.dispatchSimpleEvent( this.dispatchEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); new CustomEvent(DestinationStore.EventType.DESTINATION_SEARCH_DONE));
if (type === print_preview.PrinterType.EXTENSION_PRINTER) { if (type === print_preview.PrinterType.EXTENSION_PRINTER) {
this.endExtensionPrinterSearch_(); this.endExtensionPrinterSearch_();
} }
...@@ -1236,10 +1207,8 @@ cr.define('print_preview', function() { ...@@ -1236,10 +1207,8 @@ cr.define('print_preview', function() {
'Failed to get print capabilities for printer ' + destinationId); 'Failed to get print capabilities for printer ' + destinationId);
if (this.selectedDestination_ && if (this.selectedDestination_ &&
this.selectedDestination_.id == destinationId) { this.selectedDestination_.id == destinationId) {
const event = this.dispatchEvent(new CustomEvent(
new Event(DestinationStore.EventType.SELECTED_DESTINATION_INVALID); DestinationStore.EventType.SELECTED_DESTINATION_INVALID));
event.destinationId = destinationId;
this.dispatchEvent(event);
} }
if (this.autoSelectMatchingDestination_ && if (this.autoSelectMatchingDestination_ &&
this.autoSelectMatchingDestination_.matchIdAndOrigin( this.autoSelectMatchingDestination_.matchIdAndOrigin(
...@@ -1269,8 +1238,8 @@ cr.define('print_preview', function() { ...@@ -1269,8 +1238,8 @@ cr.define('print_preview', function() {
this.loadedCloudOrigins_[event.user] = origins.concat([event.origin]); this.loadedCloudOrigins_[event.user] = origins.concat([event.origin]);
} }
} }
cr.dispatchSimpleEvent( this.dispatchEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); new CustomEvent(DestinationStore.EventType.DESTINATION_SEARCH_DONE));
this.sendNoPrinterEventIfNeeded_(); this.sendNoPrinterEventIfNeeded_();
} }
...@@ -1286,8 +1255,8 @@ cr.define('print_preview', function() { ...@@ -1286,8 +1255,8 @@ cr.define('print_preview', function() {
} }
this.selectFirstDestination_ = false; this.selectFirstDestination_ = false;
cr.dispatchSimpleEvent( this.dispatchEvent(
this, DestinationStore.EventType.NO_DESTINATIONS_FOUND); new CustomEvent(DestinationStore.EventType.NO_DESTINATIONS_FOUND));
} }
/** /**
...@@ -1399,22 +1368,16 @@ cr.define('print_preview', function() { ...@@ -1399,22 +1368,16 @@ cr.define('print_preview', function() {
} }
/** /**
* Event types dispatched by the data store. * Event types dispatched by the destination store.
* @enum {string} * @enum {string}
*/ */
DestinationStore.EventType = { DestinationStore.EventType = {
DESTINATION_SEARCH_DONE: DESTINATION_SEARCH_DONE:
'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE',
DESTINATION_SEARCH_STARTED:
'print_preview.DestinationStore.DESTINATION_SEARCH_STARTED',
DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT', DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT',
DESTINATIONS_RESET: 'print_preview.DestinationStore.DESTINATIONS_RESET',
DESTINATIONS_INSERTED: DESTINATIONS_INSERTED:
'print_preview.DestinationStore.DESTINATIONS_INSERTED', 'print_preview.DestinationStore.DESTINATIONS_INSERTED',
PROVISIONAL_DESTINATION_RESOLVED: DESTINATIONS_RESET: 'print_preview.DestinationStore.DESTINATIONS_RESET',
'print_preview.DestinationStore.PROVISIONAL_DESTINATION_RESOLVED',
CACHED_SELECTED_DESTINATION_INFO_READY:
'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY',
NO_DESTINATIONS_FOUND: NO_DESTINATIONS_FOUND:
'print_preview.DestinationStore.NO_DESTINATIONS_FOUND', 'print_preview.DestinationStore.NO_DESTINATIONS_FOUND',
SELECTED_DESTINATION_CAPABILITIES_READY: 'print_preview.DestinationStore' + SELECTED_DESTINATION_CAPABILITIES_READY: 'print_preview.DestinationStore' +
......
...@@ -210,6 +210,10 @@ Polymer({ ...@@ -210,6 +210,10 @@ Polymer({
print_preview.DestinationStore.EventType print_preview.DestinationStore.EventType
.SELECTED_DESTINATION_UNSUPPORTED, .SELECTED_DESTINATION_UNSUPPORTED,
this.onInvalidPrinter_.bind(this)); this.onInvalidPrinter_.bind(this));
this.tracker_.add(
this.destinationStore_,
print_preview.DestinationStore.EventType.SELECTED_DESTINATION_INVALID,
this.onInvalidPrinter_.bind(this));
this.nativeLayer_.getInitialSettings().then( this.nativeLayer_.getInitialSettings().then(
this.onInitialSettingsSet_.bind(this)); this.onInitialSettingsSet_.bind(this));
}, },
...@@ -568,6 +572,11 @@ Polymer({ ...@@ -568,6 +572,11 @@ Polymer({
print_preview_new.PreviewAreaState.UNSUPPORTED_CLOUD_PRINTER; print_preview_new.PreviewAreaState.UNSUPPORTED_CLOUD_PRINTER;
}, },
/** @private */
onInvalidPrinterCapabilities_: function() {
this.previewState_ = print_preview_new.PreviewAreaState.INVALID_SETTINGS;
},
/** @private */ /** @private */
onPreviewAreaStateChanged_: function() { onPreviewAreaStateChanged_: function() {
switch (this.previewState_) { switch (this.previewState_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment