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

Unified Diff: ui/file_manager/file_manager/foreground/js/cws_widget_container.js

Issue 1061133005: Wait for 'after_install' from widget before closing SuggestAppsDialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@break_up_suggest_apps_dialog
Patch Set: rebase Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/cws_container_client.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/cws_widget_container.js
diff --git a/ui/file_manager/file_manager/foreground/js/cws_widget_container.js b/ui/file_manager/file_manager/foreground/js/cws_widget_container.js
index af5307173286fd82539cd53b9db74f81e151b856..7c5aa8ad14c03a89065b3ce84654d915285599f3 100644
--- a/ui/file_manager/file_manager/foreground/js/cws_widget_container.js
+++ b/ui/file_manager/file_manager/foreground/js/cws_widget_container.js
@@ -205,6 +205,7 @@ CWSWidgetContainer.State = {
'CWSWidgetContainer.State.INITIALIZE_FAILED_CLOSING',
INITIALIZED: 'CWSWidgetContainer.State.INITIALIZED',
INSTALLING: 'CWSWidgetContainer.State.INSTALLING',
+ WAITING_FOR_CONFIRMATION: 'CWSWidgetContainer.State.WAITING_FOR_CONFIRMATION',
INSTALLED_CLOSING: 'CWSWidgetContainer.State.INSTALLED_CLOSING',
OPENING_WEBSTORE_CLOSING: 'CWSWidgetContainer.State.OPENING_WEBSTORE_CLOSING',
CANCELED_CLOSING: 'CWSWidgetContainer.State.CANCELED_CLOSING'
@@ -382,6 +383,9 @@ CWSWidgetContainer.prototype.start = function(options, webStoreUrl) {
this.webviewClient_.addEventListener(
CWSContainerClient.Events.REQUEST_INSTALL,
this.onInstallRequest_.bind(this));
+ this.webviewClient_.addEventListener(
+ CWSContainerClient.Events.INSTALL_DONE,
+ this.onInstallDone_.bind(this));
this.webviewClient_.load();
}.bind(this));
};
@@ -462,24 +466,40 @@ CWSWidgetContainer.prototype.onInstallRequest_ = function(e) {
this.installingItemId_ = itemId;
this.appInstaller_ = new AppInstaller(itemId);
- this.appInstaller_.install(this.onInstallCompleted_.bind(this));
+ this.appInstaller_.install(this.onItemInstalled_.bind(this));
this.webviewContainer_.classList.add('show-spinner');
this.state_ = CWSWidgetContainer.State.INSTALLING;
};
/**
+ * Called when the webview client receives install confirmation from the
+ * Web Store widget.
+ * @param {Event} e Event
+ * @private
+ */
+CWSWidgetContainer.prototype.onInstallDone_ = function(e) {
+ this.webviewContainer_.classList.remove('show-spinner');
+ this.state_ = CWSWidgetContainer.State.INSTALLED_CLOSING;
+ this.reportDone_();
+};
+
+/**
* Called when the installation is completed from the app installer.
* @param {AppInstaller.Result} result Result of the installation.
* @param {string} error Detail of the error.
* @private
*/
-CWSWidgetContainer.prototype.onInstallCompleted_ = function(result, error) {
+CWSWidgetContainer.prototype.onItemInstalled_ = function(result, error) {
var success = (result === AppInstaller.Result.SUCCESS);
- this.webviewContainer_.classList.remove('show-spinner');
+ // If install succeeded, the spinner will be removed once
+ // |this.webviewClient_| dispatched INSTALL_DONE event.
+ if (!success)
+ this.webviewContainer_.classList.remove('show-spinner');
+
this.state_ = success ?
- CWSWidgetContainer.State.INSTALLED_CLOSING :
+ CWSWidgetContainer.State.WAITING_FOR_CONFIRMATION :
CWSWidgetContainer.State.INITIALIZED; // Back to normal state.
this.webviewClient_.onInstallCompleted(success, this.installingItemId_);
this.installedItemId_ = this.installingItemId_;
@@ -489,7 +509,7 @@ CWSWidgetContainer.prototype.onInstallCompleted_ = function(result, error) {
case AppInstaller.Result.SUCCESS:
CWSWidgetContainer.Metrics.recordInstall(
CWSWidgetContainer.Metrics.INSTALL.SUCCEEDED);
- this.reportDone_();
+ // Wait for the widget webview container to dispatch INSTALL_DONE.
break;
case AppInstaller.Result.CANCELLED:
CWSWidgetContainer.Metrics.recordInstall(
@@ -546,6 +566,13 @@ CWSWidgetContainer.prototype.finalizeAndGetResult = function() {
CWSWidgetContainer.Metrics.LOAD.CANCELLED);
this.state_ = CWSWidgetContainer.State.CANCELED_CLOSING;
break;
+ case CWSWidgetContainer.State.WAITING_FOR_CONFIRMATION:
+ // This can happen if the dialog is closed by the user before Web Store
+ // widget replies with 'after_install'.
+ // Consider this success, as the app has actually been installed.
+ // TODO(tbarzic): Should the app be uninstalled in this case?
+ this.state_ = CWSWidgetContainer.State.INSTALLED_CLOSING;
+ break;
case CWSWidgetContainer.State.INSTALLED_CLOSING:
case CWSWidgetContainer.State.INITIALIZE_FAILED_CLOSING:
case CWSWidgetContainer.State.OPENING_WEBSTORE_CLOSING:
@@ -612,6 +639,10 @@ CWSWidgetContainer.prototype.reset_ = function () {
if (this.webview_)
this.webviewContainer_.removeChild(this.webview_);
+
+ if (this.appInstaller_)
+ this.appInstaller_.cancel();
+
this.options_ = null;
};
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/cws_container_client.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698