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

Side by Side Diff: chrome/renderer/resources/extensions/webstore_custom_bindings.js

Issue 175263003: Add chrome.webstore API methods to allow sites to see progress of installation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use Event structure Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom binding for the webstore API. 5 // Custom binding for the webstore API.
6 6
7 var webstoreNatives = requireNative('webstore'); 7 var webstoreNatives = requireNative('webstore');
8 var Event = require('event_bindings').Event;
8 9
9 function Installer() { 10 function Installer() {
10 this._pendingInstall = null; 11 this._pendingInstall = null;
12 this.onInstallStageChanged =
13 new Event(null, [{name: 'stage', type: 'string'}], {unmanaged: true});
14 this.onDownloadProgress =
15 new Event(null, [{name: 'progress', type: 'number'}], {unmanaged: true});
asargent_no_longer_on_chrome 2014/03/03 18:49:08 We'll want to update the documentation for this at
Devlin 2014/03/03 21:15:13 We discussed it, but we thought that would be too
asargent_no_longer_on_chrome 2014/03/03 22:25:33 Ok, sgtm.
11 } 16 }
12 17
13 Installer.prototype.install = function(url, onSuccess, onFailure) { 18 Installer.prototype.install = function(url, onSuccess, onFailure) {
14 if (this._pendingInstall) 19 if (this._pendingInstall)
15 throw 'A Chrome Web Store installation is already pending.'; 20 throw 'A Chrome Web Store installation is already pending.';
not at google - send to devlin 2014/03/01 01:42:07 throw new Error(...) same for all the rest.
Devlin 2014/03/03 17:44:59 Done.
asargent_no_longer_on_chrome 2014/03/03 18:49:08 If developers find themselves in a situation where
Devlin 2014/03/03 21:15:13 That's a good idea, but I think it's a separate is
asargent_no_longer_on_chrome 2014/03/03 22:25:33 Maybe just log a bug for follow-up and we can have
Devlin 2014/03/03 22:49:16 Done. crbug.com/348752
16 var installId = webstoreNatives.Install(url, onSuccess, onFailure); 21 if (url !== undefined && typeof(url) !== 'string')
22 throw 'The Chrome Web Store item link URL parameter must be a string.';
23 if (onSuccess !== undefined && typeof(onSuccess) !== 'function')
24 throw 'The success callback parameter must be a function.';
25 if (onFailure !== undefined && typeof(onFailure) !== 'function')
26 throw 'The failure callback parameter must be a function.';
27
28 var installId = webstoreNatives.Install(
29 this.onInstallStageChanged.hasListeners(),
30 this.onDownloadProgress.hasListeners(),
not at google - send to devlin 2014/03/01 01:42:07 make sure you document that listeners need to be a
Devlin 2014/03/03 17:44:59 Doc'd here in a comment and in the Event descripti
31 url,
32 onSuccess,
33 onFailure);
17 if (installId !== undefined) { 34 if (installId !== undefined) {
18 this._pendingInstall = { 35 this._pendingInstall = {
19 installId: installId, 36 installId: installId,
20 onSuccess: onSuccess, 37 onSuccess: onSuccess,
21 onFailure: onFailure 38 onFailure: onFailure
22 }; 39 };
23 } 40 }
24 }; 41 };
25 42
26 Installer.prototype.onInstallResponse = function(installId, success, error) { 43 Installer.prototype.onInstallResponse = function(installId, success, error) {
27 var pendingInstall = this._pendingInstall; 44 var pendingInstall = this._pendingInstall;
28 if (!pendingInstall || pendingInstall.installId != installId) { 45 if (!pendingInstall || pendingInstall.installId != installId) {
29 // TODO(kalman): should this be an error? 46 // TODO(kalman): should this be an error?
30 return; 47 return;
31 } 48 }
32 49
33 try { 50 try {
34 if (success && pendingInstall.onSuccess) 51 if (success && pendingInstall.onSuccess)
35 pendingInstall.onSuccess(); 52 pendingInstall.onSuccess();
36 else if (!success && pendingInstall.onFailure) 53 else if (!success && pendingInstall.onFailure)
37 pendingInstall.onFailure(error); 54 pendingInstall.onFailure(error);
38 } catch (e) { 55 } catch (e) {
39 console.error('Exception in chrome.webstore.install response handler: ' + 56 console.error('Exception in chrome.webstore.install response handler: ' +
40 e.stack); 57 e.stack);
41 } finally { 58 } finally {
42 this._pendingInstall = null; 59 this._pendingInstall = null;
43 } 60 }
44 }; 61 };
45 62
63 Installer.prototype.onInstallStageChanged = function(installStage) {
64 this.onInstallStageChanged.dispatch(installStage);
65 };
66
67 Installer.prototype.onDownloadProgress = function(progress) {
68 this.onDownloadProgress.dispatch(progress);
69 };
70
46 var installer = new Installer(); 71 var installer = new Installer();
47 72
48 var chromeWebstore = { 73 var chromeWebstore = {
49 install: function install(url, onSuccess, onFailure) { 74 install: function (url, onSuccess, onFailure) {
50 installer.install(url, onSuccess, onFailure); 75 installer.install(url, onSuccess, onFailure);
51 } 76 },
77 onInstallStageChanged: installer.onInstallStageChanged,
78 onDownloadProgress: installer.onDownloadProgress
52 }; 79 };
53 80
54 // Called by webstore_binding.cc. 81 // This must match the name in InstallWebstoreBindings in
55 function onInstallResponse(installId, success, error) {
56 installer.onInstallResponse(installId, success, error);
57 }
58
59 // These must match the names in InstallWebstorebinding in
60 // chrome/renderer/extensions/dispatcher.cc. 82 // chrome/renderer/extensions/dispatcher.cc.
61 exports.chromeWebstore = chromeWebstore; 83 exports.chromeWebstore = chromeWebstore;
62 exports.onInstallResponse = onInstallResponse; 84
85 // Called by webstore_binding.cc.
asargent_no_longer_on_chrome 2014/03/03 18:49:08 nit: I assume you meant webstore_bindings.cc ?
Devlin 2014/03/03 21:15:13 Whoops, done.
86 exports.onInstallResponse =
87 Installer.prototype.onInstallResponse.bind(installer);
88 exports.onInstallStageChanged =
89 Installer.prototype.onInstallStageChanged.bind(installer);
90 exports.onDownloadProgress =
91 Installer.prototype.onDownloadProgress.bind(installer);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698