Chromium Code Reviews| Index: chrome/renderer/resources/extensions/webstore_custom_bindings.js |
| diff --git a/chrome/renderer/resources/extensions/webstore_custom_bindings.js b/chrome/renderer/resources/extensions/webstore_custom_bindings.js |
| index 963adaa1da3a04822a7a8bb382c33b64cb4900a3..d4e70f55de08233b2f14bcc777b6623161fce938 100644 |
| --- a/chrome/renderer/resources/extensions/webstore_custom_bindings.js |
| +++ b/chrome/renderer/resources/extensions/webstore_custom_bindings.js |
| @@ -8,12 +8,19 @@ var webstoreNatives = requireNative('webstore'); |
| function Installer() { |
| this._pendingInstall = null; |
| + this._installStageListener = null; |
| + this._downloadProgressListener = null; |
| } |
| Installer.prototype.install = function(url, onSuccess, onFailure) { |
| if (this._pendingInstall) |
| throw 'A Chrome Web Store installation is already pending.'; |
| - var installId = webstoreNatives.Install(url, onSuccess, onFailure); |
| + var installId = webstoreNatives.Install( |
| + this._installStageListener != null, |
| + this._downloadProgressListener != null, |
|
not at google - send to devlin
2014/02/27 21:49:56
you can also do !!this._installStageListener etc.
Devlin
2014/02/28 18:04:51
(replaced with event.hasListeners())
|
| + url, |
| + onSuccess, |
| + onFailure); |
| if (installId !== undefined) { |
| this._pendingInstall = { |
| installId: installId, |
| @@ -43,20 +50,64 @@ Installer.prototype.onInstallResponse = function(installId, success, error) { |
| } |
| }; |
| +Installer.prototype.setInstallStageListener = function(callback) { |
| + if (webstoreNatives.ValidateInstallStageListener(callback)) |
| + this._installStageListener = callback; |
| +}; |
| + |
| +Installer.prototype.onInstallStageChanged = function(installStage) { |
| + if (!this._installStageListener) |
| + return; // This could happen if we removed the listener mid-flight. |
| + |
| + try { |
| + this._installStageListener(installStage); |
| + } catch (e) { |
| + console.error('Exception in listener set by ' + |
| + 'chrome.webstore.setInstallStageListener: ' + |
| + e.message + ', ' + e.stack); |
| + } |
| +}; |
| + |
| +Installer.prototype.setDownloadProgressListener = function(callback) { |
| + if (webstoreNatives.ValidateDownloadProgressListener(callback)) |
| + this._downloadProgressListener = callback; |
| +}; |
| + |
| +Installer.prototype.onDownloadProgress = function(progress) { |
| + if (!this._downloadProgressListener) |
| + return; // This could happen if we removed the listener mid-flight. |
| + |
| + try { |
| + this._downloadProgressListener(progress); |
| + } catch (e) { |
| + console.error('Exception in listener set by ' + |
| + 'chrome.webstore.setDownloadProgressListener: ' + |
| + e.message + ', ' + e.stack); |
| + } |
| +}; |
| + |
| var installer = new Installer(); |
| var chromeWebstore = { |
| - install: function install(url, onSuccess, onFailure) { |
| + install: function (url, onSuccess, onFailure) { |
| installer.install(url, onSuccess, onFailure); |
| + }, |
| + setInstallStageListener: function (callback) { |
| + installer.setInstallStageListener(callback); |
| + }, |
| + setDownloadProgressListener: function (callback) { |
| + installer.setDownloadProgressListener(callback); |
| } |
|
not at google - send to devlin
2014/02/27 21:49:56
see comment in the JSON which applies here too. yo
Devlin
2014/02/28 18:04:51
Done.
|
| }; |
| -// Called by webstore_binding.cc. |
| -function onInstallResponse(installId, success, error) { |
| - installer.onInstallResponse(installId, success, error); |
| -} |
| - |
| -// These must match the names in InstallWebstorebinding in |
| +// This must match the name in InstallWebstoreBindings in |
| // chrome/renderer/extensions/dispatcher.cc. |
| exports.chromeWebstore = chromeWebstore; |
| -exports.onInstallResponse = onInstallResponse; |
| + |
| +// Called by webstore_binding.cc. |
| +exports.onInstallResponse = |
| + Installer.prototype.onInstallResponse.bind(installer); |
| +exports.onInstallStageChanged = |
| + Installer.prototype.onInstallStageChanged.bind(installer); |
| +exports.onDownloadProgress = |
| + Installer.prototype.onDownloadProgress.bind(installer); |