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
3 // found in the LICENSE file.
5 // Custom binding for the webstore API.
7 var webstoreNatives
= requireNative('webstore');
10 this._pendingInstall
= null;
13 Installer
.prototype.install = function(url
, onSuccess
, onFailure
) {
14 if (this._pendingInstall
)
15 throw 'A Chrome Web Store installation is already pending.';
16 var installId
= webstoreNatives
.Install(url
, onSuccess
, onFailure
);
17 if (installId
!== undefined) {
18 this._pendingInstall
= {
26 Installer
.prototype.onInstallResponse = function(installId
, success
, error
) {
27 var pendingInstall
= this._pendingInstall
;
28 if (!pendingInstall
|| pendingInstall
.installId
!= installId
) {
29 // TODO(kalman): should this be an error?
34 if (success
&& pendingInstall
.onSuccess
)
35 pendingInstall
.onSuccess();
36 else if (!success
&& pendingInstall
.onFailure
)
37 pendingInstall
.onFailure(error
);
39 console
.error('Exception in chrome.webstore.install response handler: ' +
42 this._pendingInstall
= null;
46 var installer
= new Installer();
48 var chromeWebstore
= {
49 install
: function install(url
, onSuccess
, onFailure
) {
50 installer
.install(url
, onSuccess
, onFailure
);
54 // Called by webstore_binding.cc.
55 function onInstallResponse(installId
, success
, error
) {
56 installer
.onInstallResponse(installId
, success
, error
);
59 // These must match the names in InstallWebstorebinding in
60 // chrome/renderer/extensions/dispatcher.cc.
61 exports
.chromeWebstore
= chromeWebstore
;
62 exports
.onInstallResponse
= onInstallResponse
;