2012-03-06 19:50:58 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-03-06 19:50:58 +00:00
|
|
|
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
2012-09-23 00:48:26 +00:00
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-09-26 22:03:25 +00:00
|
|
|
Cu.import("resource://gre/modules/BrowserElementPromptService.jsm");
|
2014-05-24 19:28:13 +00:00
|
|
|
Cu.import("resource://gre/modules/AppsServiceChild.jsm");
|
2014-11-02 19:04:08 +00:00
|
|
|
Cu.import("resource://gre/modules/Preferences.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
|
|
|
|
"@mozilla.org/AppsService;1",
|
|
|
|
"nsIAppsService");
|
2012-03-06 19:50:58 +00:00
|
|
|
|
2012-08-27 14:13:02 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsIMessageSender");
|
2012-03-06 19:50:58 +00:00
|
|
|
|
2014-08-19 16:30:54 +00:00
|
|
|
function debug(aMsg) {
|
|
|
|
dump("-*- Webapps.js " + aMsg + "\n");
|
|
|
|
}
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
function convertAppsArray(aApps, aWindow) {
|
2014-03-24 14:30:20 +00:00
|
|
|
let apps = new aWindow.Array();
|
2014-08-19 16:30:54 +00:00
|
|
|
aApps.forEach((aApp) => {
|
|
|
|
let obj = createContentApplicationObject(aWindow, aApp);
|
|
|
|
apps.push(obj);
|
|
|
|
});
|
2012-03-06 19:50:58 +00:00
|
|
|
return apps;
|
|
|
|
}
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
function WebappsRegistry() {
|
|
|
|
}
|
|
|
|
|
|
|
|
WebappsRegistry.prototype = {
|
2012-03-06 19:50:58 +00:00
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let msg = aMessage.json;
|
2012-03-06 19:50:58 +00:00
|
|
|
if (msg.oid != this._id)
|
2011-11-28 20:13:26 +00:00
|
|
|
return
|
2012-03-06 19:50:58 +00:00
|
|
|
let req = this.getRequest(msg.requestID);
|
|
|
|
if (!req)
|
|
|
|
return;
|
2011-11-28 20:13:26 +00:00
|
|
|
let app = msg.app;
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Webapps:Install:Return:OK":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners("Webapps:Install:Return:KO");
|
2014-08-19 16:30:54 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, createContentApplicationObject(this._window, app));
|
2013-02-13 19:55:45 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Install:Return:Ack",
|
|
|
|
{ manifestURL : app.manifestURL });
|
2011-11-28 20:13:26 +00:00
|
|
|
break;
|
|
|
|
case "Webapps:Install:Return:KO":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2012-08-08 21:07:39 +00:00
|
|
|
Services.DOMRequest.fireError(req, msg.error || "DENIED");
|
2011-11-28 20:13:26 +00:00
|
|
|
break;
|
2012-03-06 19:50:58 +00:00
|
|
|
case "Webapps:GetSelf:Return:OK":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2012-03-06 19:50:58 +00:00
|
|
|
if (msg.apps.length) {
|
|
|
|
app = msg.apps[0];
|
2014-08-19 16:30:54 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, createContentApplicationObject(this._window, app));
|
2012-03-06 19:50:58 +00:00
|
|
|
} else {
|
2012-04-11 05:55:54 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-10-02 20:38:51 +00:00
|
|
|
case "Webapps:CheckInstalled:Return:OK":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2012-10-02 20:38:51 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, msg.app);
|
2012-09-25 15:04:24 +00:00
|
|
|
break;
|
2012-03-06 19:50:58 +00:00
|
|
|
case "Webapps:GetInstalled:Return:OK":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2012-04-11 05:55:54 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
|
2012-03-06 19:50:58 +00:00
|
|
|
break;
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
2012-03-06 19:50:58 +00:00
|
|
|
this.removeRequest(msg.requestID);
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_getOrigin: function(aURL) {
|
|
|
|
let uri = Services.io.newURI(aURL, null, null);
|
2012-08-28 02:43:57 +00:00
|
|
|
return uri.prePath;
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2013-11-07 11:30:31 +00:00
|
|
|
// Checks that the URL scheme is appropriate (http or https) and
|
|
|
|
// asynchronously fire an error on the DOM Request if it isn't.
|
|
|
|
_validateURL: function(aURL, aRequest) {
|
2013-01-14 19:41:24 +00:00
|
|
|
let uri;
|
|
|
|
let res;
|
2013-11-07 11:30:31 +00:00
|
|
|
|
2013-01-14 19:41:24 +00:00
|
|
|
try {
|
|
|
|
uri = Services.io.newURI(aURL, null, null);
|
|
|
|
if (uri.schemeIs("http") || uri.schemeIs("https")) {
|
|
|
|
res = uri.spec;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
2013-11-07 11:30:31 +00:00
|
|
|
Services.DOMRequest.fireErrorAsync(aRequest, "INVALID_URL");
|
|
|
|
return false;
|
2013-01-14 19:41:24 +00:00
|
|
|
}
|
|
|
|
|
2013-11-07 11:30:31 +00:00
|
|
|
// The scheme is incorrect, fire DOMRequest error.
|
2013-01-14 19:41:24 +00:00
|
|
|
if (!res) {
|
2013-11-07 11:30:31 +00:00
|
|
|
Services.DOMRequest.fireErrorAsync(aRequest, "INVALID_URL");
|
|
|
|
return false;
|
2012-09-25 02:41:21 +00:00
|
|
|
}
|
2013-11-07 11:30:31 +00:00
|
|
|
|
2013-01-14 19:41:24 +00:00
|
|
|
return uri.spec;
|
2012-09-25 02:41:21 +00:00
|
|
|
},
|
|
|
|
|
2013-01-08 17:02:17 +00:00
|
|
|
// Checks that we run as a foreground page, and fire an error on the
|
|
|
|
// DOM Request if we aren't.
|
|
|
|
_ensureForeground: function(aRequest) {
|
|
|
|
let docShell = this._window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell);
|
|
|
|
if (docShell.isActive) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-07 11:30:31 +00:00
|
|
|
Services.DOMRequest.fireErrorAsync(aRequest, "BACKGROUND_APP");
|
2013-01-08 17:02:17 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2013-08-02 00:00:39 +00:00
|
|
|
_prepareInstall: function(aURL, aRequest, aParams, isPackage) {
|
2013-08-02 01:51:12 +00:00
|
|
|
let installURL = this._window.location.href;
|
2013-08-02 00:00:39 +00:00
|
|
|
let requestID = this.getRequestId(aRequest);
|
2013-08-02 01:51:12 +00:00
|
|
|
let receipts = (aParams && aParams.receipts &&
|
|
|
|
Array.isArray(aParams.receipts)) ? aParams.receipts
|
|
|
|
: [];
|
|
|
|
let categories = (aParams && aParams.categories &&
|
|
|
|
Array.isArray(aParams.categories)) ? aParams.categories
|
|
|
|
: [];
|
|
|
|
|
|
|
|
let principal = this._window.document.nodePrincipal;
|
2013-08-02 00:00:39 +00:00
|
|
|
|
|
|
|
return { app: {
|
|
|
|
installOrigin: this._getOrigin(installURL),
|
|
|
|
origin: this._getOrigin(aURL),
|
|
|
|
manifestURL: aURL,
|
|
|
|
receipts: receipts,
|
|
|
|
categories: categories
|
|
|
|
},
|
|
|
|
|
|
|
|
from: installURL,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: requestID,
|
|
|
|
appId: principal.appId,
|
|
|
|
isBrowser: principal.isInBrowserElement,
|
|
|
|
isPackage: isPackage
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
// mozIDOMApplicationRegistry implementation
|
|
|
|
|
|
|
|
install: function(aURL, aParams) {
|
|
|
|
let request = this.createRequest();
|
|
|
|
|
2013-11-07 11:30:31 +00:00
|
|
|
let uri = this._validateURL(aURL, request);
|
|
|
|
|
|
|
|
if (uri && this._ensureForeground(request)) {
|
2013-10-04 21:59:48 +00:00
|
|
|
this.addMessageListeners("Webapps:Install:Return:KO");
|
2013-08-02 00:00:39 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Install",
|
|
|
|
this._prepareInstall(uri, request, aParams, false));
|
|
|
|
}
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
return request;
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
getSelf: function() {
|
|
|
|
let request = this.createRequest();
|
2013-10-04 21:59:48 +00:00
|
|
|
this.addMessageListeners("Webapps:GetSelf:Return:OK");
|
2012-03-06 19:50:58 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetSelf", { origin: this._getOrigin(this._window.location.href),
|
2012-09-25 15:04:24 +00:00
|
|
|
appId: this._window.document.nodePrincipal.appId,
|
2012-03-06 19:50:58 +00:00
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
return request;
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-10-02 20:38:51 +00:00
|
|
|
checkInstalled: function(aManifestURL) {
|
2012-09-25 15:04:24 +00:00
|
|
|
let manifestURL = Services.io.newURI(aManifestURL, null, this._window.document.baseURIObject);
|
|
|
|
|
|
|
|
let request = this.createRequest();
|
2013-10-04 21:59:48 +00:00
|
|
|
|
2014-06-24 23:51:28 +00:00
|
|
|
try {
|
|
|
|
this._window.document.nodePrincipal.checkMayLoad(manifestURL, true,
|
|
|
|
false);
|
|
|
|
} catch (ex) {
|
|
|
|
Services.DOMRequest.fireErrorAsync(request, "CROSS_ORIGIN_CHECK_NOT_ALLOWED");
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
2013-10-04 21:59:48 +00:00
|
|
|
this.addMessageListeners("Webapps:CheckInstalled:Return:OK");
|
2012-10-02 20:38:51 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:CheckInstalled", { origin: this._getOrigin(this._window.location.href),
|
|
|
|
manifestURL: manifestURL.spec,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request) });
|
2012-09-25 15:04:24 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
getInstalled: function() {
|
|
|
|
let request = this.createRequest();
|
2013-10-04 21:59:48 +00:00
|
|
|
this.addMessageListeners("Webapps:GetInstalled:Return:OK");
|
2012-03-06 19:50:58 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetInstalled", { origin: this._getOrigin(this._window.location.href),
|
2011-11-28 20:13:26 +00:00
|
|
|
oid: this._id,
|
2012-03-06 19:50:58 +00:00
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
return request;
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-09-11 20:53:42 +00:00
|
|
|
get mgmt() {
|
2013-01-19 16:56:29 +00:00
|
|
|
if (!this.hasMgmtPrivilege) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-08-19 16:30:54 +00:00
|
|
|
if (!this._mgmt) {
|
|
|
|
let mgmt = Cc["@mozilla.org/webapps/manager;1"]
|
|
|
|
.createInstance(Ci.nsISupports);
|
2014-11-02 19:04:08 +00:00
|
|
|
mgmt.wrappedJSObject.init(this._window, this.hasFullMgmtPrivilege);
|
2014-06-11 21:23:18 +00:00
|
|
|
mgmt.wrappedJSObject._windowId = this._id;
|
2014-08-19 16:30:54 +00:00
|
|
|
this._mgmt = mgmt.__DOM_IMPL__
|
|
|
|
? mgmt.__DOM_IMPL__
|
|
|
|
: this._window.DOMApplicationsManager._create(this._window, mgmt.wrappedJSObject);
|
|
|
|
}
|
2012-09-11 20:53:42 +00:00
|
|
|
return this._mgmt;
|
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function() {
|
|
|
|
this._mgmt = null;
|
2012-10-19 18:17:05 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
|
|
|
|
["Webapps:Install:Return:OK"]);
|
2012-09-11 20:53:42 +00:00
|
|
|
},
|
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
installPackage: function(aURL, aParams) {
|
2013-01-08 17:02:17 +00:00
|
|
|
let request = this.createRequest();
|
|
|
|
|
2013-11-07 11:30:31 +00:00
|
|
|
let uri = this._validateURL(aURL, request);
|
|
|
|
|
|
|
|
if (uri && this._ensureForeground(request)) {
|
2013-10-04 21:59:48 +00:00
|
|
|
this.addMessageListeners("Webapps:Install:Return:KO");
|
2013-08-02 00:00:39 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:InstallPackage",
|
|
|
|
this._prepareInstall(uri, request, aParams, true));
|
2013-01-08 17:02:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 15:38:33 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
// nsIDOMGlobalPropertyInitializer implementation
|
|
|
|
init: function(aWindow) {
|
2014-11-02 19:04:08 +00:00
|
|
|
const prefs = new Preferences();
|
|
|
|
|
|
|
|
this._window = aWindow;
|
|
|
|
|
2013-10-04 21:59:48 +00:00
|
|
|
this.initDOMRequestHelper(aWindow, "Webapps:Install:Return:OK");
|
2011-12-08 02:15:42 +00:00
|
|
|
|
2013-01-19 16:56:29 +00:00
|
|
|
let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
2012-03-06 19:50:58 +00:00
|
|
|
this._id = util.outerWindowID;
|
2012-09-18 17:34:55 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:RegisterForMessages",
|
2013-09-13 09:33:52 +00:00
|
|
|
{ messages: ["Webapps:Install:Return:OK"]});
|
2013-01-19 16:56:29 +00:00
|
|
|
|
|
|
|
let principal = aWindow.document.nodePrincipal;
|
2014-11-02 19:04:08 +00:00
|
|
|
let appId = principal.appId;
|
|
|
|
let app = appId && appsService.getAppByLocalId(appId);
|
2013-01-19 16:56:29 +00:00
|
|
|
|
2014-11-02 19:04:08 +00:00
|
|
|
let isCurrentHomescreen = app &&
|
|
|
|
app.manifestURL == prefs.get("dom.mozApps.homescreenURL") &&
|
|
|
|
app.appStatus != Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED;
|
|
|
|
|
|
|
|
let hasWebappsPermission = Ci.nsIPermissionManager.ALLOW_ACTION ==
|
|
|
|
Services.perms.testExactPermissionFromPrincipal(
|
|
|
|
principal, "webapps-manage");
|
|
|
|
|
|
|
|
let hasHomescreenPermission = Ci.nsIPermissionManager.ALLOW_ACTION ==
|
|
|
|
Services.perms.testExactPermissionFromPrincipal(
|
|
|
|
principal, "homescreen-webapps-manage");
|
|
|
|
|
|
|
|
this.hasMgmtPrivilege = hasWebappsPermission ||
|
|
|
|
(isCurrentHomescreen && hasHomescreenPermission);
|
|
|
|
this.hasFullMgmtPrivilege = hasWebappsPermission;
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
2012-08-28 02:43:57 +00:00
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
classID: Components.ID("{fff440b3-fae2-45c1-bf03-3b5a2e432270}"),
|
|
|
|
|
2013-07-08 21:55:42 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
|
2014-08-19 16:30:54 +00:00
|
|
|
Ci.nsISupports,
|
2013-11-20 05:33:10 +00:00
|
|
|
Ci.nsIObserver,
|
2014-08-19 16:30:54 +00:00
|
|
|
Ci.nsIDOMGlobalPropertyInitializer])
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
/**
|
2014-08-19 16:30:54 +00:00
|
|
|
* DOMApplication object
|
2012-03-06 19:50:58 +00:00
|
|
|
*/
|
2012-06-11 18:41:46 +00:00
|
|
|
|
2012-08-29 21:20:03 +00:00
|
|
|
function createApplicationObject(aWindow, aApp) {
|
2014-05-24 19:28:13 +00:00
|
|
|
let app = Cc["@mozilla.org/webapps/application;1"]
|
2014-08-19 16:30:54 +00:00
|
|
|
.createInstance(Ci.nsISupports);
|
2012-08-29 21:20:03 +00:00
|
|
|
app.wrappedJSObject.init(aWindow, aApp);
|
2012-06-11 18:41:46 +00:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2014-08-19 16:30:54 +00:00
|
|
|
function createContentApplicationObject(aWindow, aApp) {
|
|
|
|
return createApplicationObject(aWindow, aApp).wrappedJSObject
|
|
|
|
._prepareForContent();
|
|
|
|
}
|
|
|
|
|
2012-06-11 18:41:46 +00:00
|
|
|
function WebappsApplication() {
|
|
|
|
this.wrappedJSObject = this;
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebappsApplication.prototype = {
|
2012-03-06 19:50:58 +00:00
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-08-29 21:20:03 +00:00
|
|
|
init: function(aWindow, aApp) {
|
2014-11-02 19:04:08 +00:00
|
|
|
this._window = aWindow;
|
|
|
|
|
2014-05-24 19:28:13 +00:00
|
|
|
let proxyHandler = DOMApplicationRegistry.addDOMApp(this,
|
|
|
|
aApp.manifestURL,
|
|
|
|
aApp.id);
|
|
|
|
this._proxy = new Proxy(this, proxyHandler);
|
|
|
|
|
|
|
|
this.initDOMRequestHelper(aWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
get _appStatus() {
|
|
|
|
return this._proxy.appStatus;
|
|
|
|
},
|
|
|
|
|
|
|
|
get downloadAvailable() {
|
|
|
|
return this._proxy.downloadAvailable;
|
|
|
|
},
|
|
|
|
|
|
|
|
get downloading() {
|
|
|
|
return this._proxy.downloading;
|
|
|
|
},
|
|
|
|
|
|
|
|
get downloadSize() {
|
|
|
|
return this._proxy.downloadSize;
|
|
|
|
},
|
|
|
|
|
|
|
|
get installOrigin() {
|
|
|
|
return this._proxy.installOrigin;
|
|
|
|
},
|
|
|
|
|
|
|
|
get installState() {
|
|
|
|
return this._proxy.installState;
|
|
|
|
},
|
|
|
|
|
|
|
|
get installTime() {
|
|
|
|
return this._proxy.installTime;
|
|
|
|
},
|
|
|
|
|
|
|
|
get lastUpdateCheck() {
|
|
|
|
return this._proxy.lastUpdateCheck;
|
|
|
|
},
|
|
|
|
|
|
|
|
get manifestURL() {
|
|
|
|
return this._proxy.manifestURL;
|
|
|
|
},
|
|
|
|
|
|
|
|
get origin() {
|
|
|
|
return this._proxy.origin;
|
|
|
|
},
|
|
|
|
|
|
|
|
get progress() {
|
|
|
|
return this._proxy.progress;
|
|
|
|
},
|
|
|
|
|
|
|
|
get readyToApplyDownload() {
|
|
|
|
return this._proxy.readyToApplyDownload;
|
|
|
|
},
|
|
|
|
|
|
|
|
get removable() {
|
|
|
|
return this._proxy.removable;
|
|
|
|
},
|
|
|
|
|
|
|
|
get updateTime() {
|
|
|
|
return this._proxy.updateTime;
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-10-18 22:30:58 +00:00
|
|
|
get manifest() {
|
2014-05-24 19:28:13 +00:00
|
|
|
return WrappedManifestCache.get(this.manifestURL,
|
|
|
|
this._proxy.manifest,
|
|
|
|
this._window,
|
|
|
|
this.innerWindowID);
|
2012-10-18 22:30:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get updateManifest() {
|
2014-05-24 19:28:13 +00:00
|
|
|
return this._proxy.updateManifest ?
|
|
|
|
Cu.cloneInto(this._proxy.updateManifest, this._window) : null;
|
2012-10-18 22:30:58 +00:00
|
|
|
},
|
|
|
|
|
2012-06-11 18:41:46 +00:00
|
|
|
set onprogress(aCallback) {
|
2014-08-19 16:30:54 +00:00
|
|
|
this.__DOM_IMPL__.setEventHandler("onprogress", aCallback);
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-06-11 18:41:46 +00:00
|
|
|
get onprogress() {
|
2014-08-19 16:30:54 +00:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("onprogress");
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-09-27 01:01:20 +00:00
|
|
|
set ondownloadsuccess(aCallback) {
|
2014-08-19 16:30:54 +00:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloadsuccess", aCallback);
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloadsuccess() {
|
2014-08-19 16:30:54 +00:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloadsuccess");
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set ondownloaderror(aCallback) {
|
2014-08-19 16:30:54 +00:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloaderror", aCallback);
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloaderror() {
|
2014-08-19 16:30:54 +00:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloaderror");
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set ondownloadavailable(aCallback) {
|
2014-08-19 16:30:54 +00:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloadavailable", aCallback);
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloadavailable() {
|
2014-08-19 16:30:54 +00:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloadavailable");
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set ondownloadapplied(aCallback) {
|
2014-08-19 16:30:54 +00:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloadapplied", aCallback);
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloadapplied() {
|
2014-08-19 16:30:54 +00:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloadapplied");
|
|
|
|
},
|
|
|
|
|
|
|
|
get receipts() {
|
2014-09-05 23:55:30 +00:00
|
|
|
return this._proxy.receipts || [];
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get downloadError() {
|
2014-06-25 20:47:00 +00:00
|
|
|
// Only return DOMError when we have an error.
|
2014-05-24 19:28:13 +00:00
|
|
|
if (!this._proxy.downloadError) {
|
2014-06-25 20:47:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
2014-05-24 19:28:13 +00:00
|
|
|
return new this._window.DOMError(this._proxy.downloadError);
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
2014-10-23 23:40:08 +00:00
|
|
|
get enabled() {
|
|
|
|
return this._proxy.enabled;
|
|
|
|
},
|
|
|
|
|
2012-09-27 01:01:20 +00:00
|
|
|
download: function() {
|
2012-09-29 17:57:18 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Download",
|
|
|
|
{ manifestURL: this.manifestURL });
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelDownload: function() {
|
|
|
|
cpmm.sendAsyncMessage("Webapps:CancelDownload",
|
|
|
|
{ manifestURL: this.manifestURL });
|
|
|
|
},
|
|
|
|
|
|
|
|
checkForUpdate: function() {
|
|
|
|
let request = this.createRequest();
|
2012-12-03 19:38:09 +00:00
|
|
|
|
2012-12-17 19:11:05 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:CheckForUpdate",
|
|
|
|
{ manifestURL: this.manifestURL,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request) });
|
2012-09-27 01:01:20 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
launch: function(aStartPoint) {
|
|
|
|
let request = this.createRequest();
|
2013-10-04 21:59:48 +00:00
|
|
|
this.addMessageListeners(["Webapps:Launch:Return:OK",
|
|
|
|
"Webapps:Launch:Return:KO"]);
|
2012-06-11 18:41:46 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Launch", { origin: this.origin,
|
2012-09-07 15:41:26 +00:00
|
|
|
manifestURL: this.manifestURL,
|
2012-05-04 18:02:05 +00:00
|
|
|
startPoint: aStartPoint || "",
|
2012-03-06 19:50:58 +00:00
|
|
|
oid: this._id,
|
2013-02-05 18:05:56 +00:00
|
|
|
timestamp: Date.now(),
|
2012-03-06 19:50:58 +00:00
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-09-26 22:03:25 +00:00
|
|
|
clearBrowserData: function() {
|
2013-05-20 17:20:19 +00:00
|
|
|
let request = this.createRequest();
|
2012-09-26 22:03:25 +00:00
|
|
|
let browserChild =
|
|
|
|
BrowserElementPromptService.getBrowserElementChildForWindow(this._window);
|
|
|
|
if (browserChild) {
|
2013-10-04 21:59:48 +00:00
|
|
|
this.addMessageListeners("Webapps:ClearBrowserData:Return");
|
2014-05-24 19:28:13 +00:00
|
|
|
browserChild.messageManager.sendAsyncMessage("Webapps:ClearBrowserData", {
|
|
|
|
manifestURL: this.manifestURL,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request)
|
|
|
|
});
|
2013-05-20 17:20:19 +00:00
|
|
|
} else {
|
2013-11-07 11:30:31 +00:00
|
|
|
Services.DOMRequest.fireErrorAsync(request, "NO_CLEARABLE_BROWSER");
|
2012-09-26 22:03:25 +00:00
|
|
|
}
|
2013-05-20 17:20:19 +00:00
|
|
|
return request;
|
2012-09-26 22:03:25 +00:00
|
|
|
},
|
|
|
|
|
2013-07-30 14:03:06 +00:00
|
|
|
connect: function(aKeyword, aRules) {
|
2014-05-24 19:28:13 +00:00
|
|
|
this.addMessageListeners(["Webapps:Connect:Return:OK",
|
|
|
|
"Webapps:Connect:Return:KO"]);
|
2013-09-12 15:21:10 +00:00
|
|
|
return this.createPromise(function (aResolve, aReject) {
|
2014-05-24 19:28:13 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Connect", {
|
|
|
|
keyword: aKeyword,
|
|
|
|
rules: aRules,
|
|
|
|
manifestURL: this.manifestURL,
|
|
|
|
outerWindowID: this._id,
|
|
|
|
requestID: this.getPromiseResolverId({
|
|
|
|
resolve: aResolve,
|
|
|
|
reject: aReject
|
|
|
|
})
|
|
|
|
});
|
2013-08-16 09:49:15 +00:00
|
|
|
}.bind(this));
|
2013-07-30 14:03:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getConnections: function() {
|
2014-05-24 19:28:13 +00:00
|
|
|
this.addMessageListeners("Webapps:GetConnections:Return:OK");
|
2013-09-12 15:21:10 +00:00
|
|
|
return this.createPromise(function (aResolve, aReject) {
|
2014-05-24 19:28:13 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetConnections", {
|
|
|
|
manifestURL: this.manifestURL,
|
|
|
|
outerWindowID: this._id,
|
|
|
|
requestID: this.getPromiseResolverId({
|
|
|
|
resolve: aResolve,
|
|
|
|
reject: aReject
|
|
|
|
})
|
|
|
|
});
|
2013-08-17 14:40:01 +00:00
|
|
|
}.bind(this));
|
2013-07-30 14:03:06 +00:00
|
|
|
},
|
|
|
|
|
2014-01-17 00:26:26 +00:00
|
|
|
addReceipt: function(receipt) {
|
|
|
|
let request = this.createRequest();
|
|
|
|
|
|
|
|
this.addMessageListeners(["Webapps:AddReceipt:Return:OK",
|
|
|
|
"Webapps:AddReceipt:Return:KO"]);
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("Webapps:AddReceipt", { manifestURL: this.manifestURL,
|
|
|
|
receipt: receipt,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeReceipt: function(receipt) {
|
|
|
|
let request = this.createRequest();
|
|
|
|
|
|
|
|
this.addMessageListeners(["Webapps:RemoveReceipt:Return:OK",
|
|
|
|
"Webapps:RemoveReceipt:Return:KO"]);
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("Webapps:RemoveReceipt", { manifestURL: this.manifestURL,
|
|
|
|
receipt: receipt,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
|
|
|
replaceReceipt: function(oldReceipt, newReceipt) {
|
|
|
|
let request = this.createRequest();
|
|
|
|
|
|
|
|
this.addMessageListeners(["Webapps:ReplaceReceipt:Return:OK",
|
|
|
|
"Webapps:ReplaceReceipt:Return:KO"]);
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("Webapps:ReplaceReceipt", { manifestURL: this.manifestURL,
|
|
|
|
newReceipt: newReceipt,
|
|
|
|
oldReceipt: oldReceipt,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-15 05:55:14 +00:00
|
|
|
export: function() {
|
|
|
|
this.addMessageListeners(["Webapps:Export:Return"]);
|
|
|
|
return this.createPromise((aResolve, aReject) => {
|
|
|
|
cpmm.sendAsyncMessage("Webapps:Export",
|
|
|
|
{ manifestURL: this.manifestURL,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getPromiseResolverId({
|
|
|
|
resolve: aResolve,
|
|
|
|
reject: aReject
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-08-19 16:30:54 +00:00
|
|
|
_prepareForContent: function() {
|
|
|
|
if (this.__DOM_IMPL__) {
|
|
|
|
return this.__DOM_IMPL__;
|
|
|
|
}
|
|
|
|
return this._window.DOMApplication._create(this._window, this.wrappedJSObject);
|
|
|
|
},
|
|
|
|
|
2012-06-11 18:41:46 +00:00
|
|
|
uninit: function() {
|
2014-05-24 19:28:13 +00:00
|
|
|
WrappedManifestCache.evict(this.manifestURL, this.innerWindowID);
|
2012-06-11 18:41:46 +00:00
|
|
|
},
|
|
|
|
|
2013-10-17 12:47:58 +00:00
|
|
|
_fireEvent: function(aName) {
|
2014-08-19 16:30:54 +00:00
|
|
|
let obj = this._prepareForContent();
|
|
|
|
let event = new this._window.MozApplicationEvent(aName, {
|
|
|
|
application: obj
|
|
|
|
});
|
|
|
|
obj.dispatchEvent(event);
|
2013-10-17 12:47:58 +00:00
|
|
|
},
|
|
|
|
|
2014-05-24 19:28:13 +00:00
|
|
|
_fireRequestResult: function(aMessage, aIsError) {
|
|
|
|
let req;
|
|
|
|
let msg = aMessage.data;
|
|
|
|
req = this.takeRequest(msg.requestID);
|
|
|
|
if (!req) {
|
|
|
|
return;
|
2014-07-28 18:31:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-24 19:28:13 +00:00
|
|
|
aIsError ? Services.DOMRequest.fireError(req, msg.error)
|
|
|
|
: Services.DOMRequest.fireSuccess(req, msg.result);
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
receiveMessage: function(aMessage) {
|
2012-09-27 19:34:41 +00:00
|
|
|
let msg = aMessage.json;
|
2013-08-16 09:49:15 +00:00
|
|
|
let req;
|
|
|
|
if (aMessage.name == "Webapps:Connect:Return:OK" ||
|
2013-08-17 14:40:01 +00:00
|
|
|
aMessage.name == "Webapps:Connect:Return:KO" ||
|
2014-10-15 05:55:14 +00:00
|
|
|
aMessage.name == "Webapps:GetConnections:Return:OK" ||
|
|
|
|
aMessage.name == "Webapps:Export:Return") {
|
2013-08-16 09:49:15 +00:00
|
|
|
req = this.takePromiseResolver(msg.requestID);
|
|
|
|
} else {
|
|
|
|
req = this.takeRequest(msg.requestID);
|
|
|
|
}
|
2012-12-28 17:57:35 +00:00
|
|
|
|
2014-05-24 19:28:13 +00:00
|
|
|
if (msg.oid !== this._id || !req) {
|
2012-03-06 19:50:58 +00:00
|
|
|
return;
|
2013-10-17 12:47:58 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
switch (aMessage.name) {
|
2012-09-27 01:01:20 +00:00
|
|
|
case "Webapps:Launch:Return:KO":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners(["Webapps:Launch:Return:OK",
|
|
|
|
"Webapps:Launch:Return:KO"]);
|
2014-10-23 23:40:08 +00:00
|
|
|
Services.DOMRequest.fireError(req, msg.error);
|
2012-09-27 01:01:20 +00:00
|
|
|
break;
|
2013-07-02 01:29:51 +00:00
|
|
|
case "Webapps:Launch:Return:OK":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners(["Webapps:Launch:Return:OK",
|
|
|
|
"Webapps:Launch:Return:KO"]);
|
2013-07-03 17:48:55 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
2013-07-02 01:29:51 +00:00
|
|
|
break;
|
2013-05-20 17:20:19 +00:00
|
|
|
case "Webapps:ClearBrowserData:Return":
|
2013-10-04 21:59:48 +00:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2013-05-20 17:20:19 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
|
|
|
break;
|
2013-08-16 09:49:15 +00:00
|
|
|
case "Webapps:Connect:Return:OK":
|
2014-05-24 19:28:13 +00:00
|
|
|
this.removeMessageListeners(["Webapps:Connect:Return:OK",
|
|
|
|
"Webapps:Connect:Return:KO"]);
|
2014-10-03 08:05:51 +00:00
|
|
|
let messagePorts = new this._window.Array();
|
2013-10-17 12:47:58 +00:00
|
|
|
msg.messagePortIDs.forEach((aPortID) => {
|
2013-09-12 14:14:48 +00:00
|
|
|
let port = new this._window.MozInterAppMessagePort(aPortID);
|
2013-08-16 09:49:15 +00:00
|
|
|
messagePorts.push(port);
|
2013-10-17 12:47:58 +00:00
|
|
|
});
|
2013-08-16 09:49:15 +00:00
|
|
|
req.resolve(messagePorts);
|
|
|
|
break;
|
|
|
|
case "Webapps:Connect:Return:KO":
|
2014-05-24 19:28:13 +00:00
|
|
|
this.removeMessageListeners(["Webapps:Connect:Return:OK",
|
|
|
|
"Webapps:Connect:Return:KO"]);
|
2013-08-16 09:49:15 +00:00
|
|
|
req.reject("No connections registered");
|
|
|
|
break;
|
2013-08-17 14:40:01 +00:00
|
|
|
case "Webapps:GetConnections:Return:OK":
|
2014-05-24 19:28:13 +00:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2014-10-03 08:05:51 +00:00
|
|
|
let connections = new this._window.Array();
|
2013-10-17 12:47:58 +00:00
|
|
|
msg.connections.forEach((aConnection) => {
|
2013-08-17 14:40:01 +00:00
|
|
|
let connection =
|
|
|
|
new this._window.MozInterAppConnection(aConnection.keyword,
|
|
|
|
aConnection.pubAppManifestURL,
|
|
|
|
aConnection.subAppManifestURL);
|
|
|
|
connections.push(connection);
|
2013-10-17 12:47:58 +00:00
|
|
|
});
|
2013-08-17 14:40:01 +00:00
|
|
|
req.resolve(connections);
|
|
|
|
break;
|
2014-01-17 00:26:26 +00:00
|
|
|
case "Webapps:AddReceipt:Return:OK":
|
|
|
|
this.removeMessageListeners(["Webapps:AddReceipt:Return:OK",
|
|
|
|
"Webapps:AddReceipt:Return:KO"]);
|
2014-09-05 23:55:30 +00:00
|
|
|
this.__DOM_IMPL__._clearCachedReceiptsValue();
|
2014-08-19 16:30:54 +00:00
|
|
|
this._proxy.receipts = msg.receipts;
|
2014-01-17 00:26:26 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
|
|
|
break;
|
|
|
|
case "Webapps:AddReceipt:Return:KO":
|
|
|
|
this.removeMessageListeners(["Webapps:AddReceipt:Return:OK",
|
|
|
|
"Webapps:AddReceipt:Return:KO"]);
|
|
|
|
Services.DOMRequest.fireError(req, msg.error);
|
|
|
|
break;
|
|
|
|
case "Webapps:RemoveReceipt:Return:OK":
|
|
|
|
this.removeMessageListeners(["Webapps:RemoveReceipt:Return:OK",
|
|
|
|
"Webapps:RemoveReceipt:Return:KO"]);
|
2014-09-05 23:55:30 +00:00
|
|
|
this.__DOM_IMPL__._clearCachedReceiptsValue();
|
2014-08-19 16:30:54 +00:00
|
|
|
this._proxy.receipts = msg.receipts;
|
2014-01-17 00:26:26 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
|
|
|
break;
|
|
|
|
case "Webapps:RemoveReceipt:Return:KO":
|
|
|
|
this.removeMessageListeners(["Webapps:RemoveReceipt:Return:OK",
|
|
|
|
"Webapps:RemoveReceipt:Return:KO"]);
|
|
|
|
Services.DOMRequest.fireError(req, msg.error);
|
|
|
|
break;
|
|
|
|
case "Webapps:ReplaceReceipt:Return:OK":
|
|
|
|
this.removeMessageListeners(["Webapps:ReplaceReceipt:Return:OK",
|
|
|
|
"Webapps:ReplaceReceipt:Return:KO"]);
|
2014-09-05 23:55:30 +00:00
|
|
|
this.__DOM_IMPL__._clearCachedReceiptsValue();
|
2014-08-19 16:30:54 +00:00
|
|
|
this._proxy.receipts = msg.receipts;
|
2014-01-17 00:26:26 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
|
|
|
break;
|
|
|
|
case "Webapps:ReplaceReceipt:Return:KO":
|
|
|
|
this.removeMessageListeners(["Webapps:ReplaceReceipt:Return:OK",
|
|
|
|
"Webapps:ReplaceReceipt:Return:KO"]);
|
|
|
|
Services.DOMRequest.fireError(req, msg.error);
|
|
|
|
break;
|
2014-10-15 05:55:14 +00:00
|
|
|
case "Webapps:Export:Return":
|
|
|
|
this.removeMessageListeners(["Webapps:Export:Return"]);
|
|
|
|
if (msg.success) {
|
|
|
|
req.resolve(Cu.cloneInto(msg.blob, this._window));
|
|
|
|
} else {
|
|
|
|
req.reject(new this._window.DOMError(msg.error || ""));
|
|
|
|
}
|
|
|
|
break;
|
2012-03-06 19:50:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
classID: Components.ID("{723ed303-7757-4fb0-b261-4f78b1f6bd22}"),
|
|
|
|
|
2014-08-19 16:30:54 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference])
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
/**
|
2014-08-19 16:30:54 +00:00
|
|
|
* DOMApplicationsManager object
|
2012-03-06 19:50:58 +00:00
|
|
|
*/
|
2014-08-19 16:30:54 +00:00
|
|
|
function WebappsApplicationMgmt() {
|
|
|
|
this.wrappedJSObject = this;
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
WebappsApplicationMgmt.prototype = {
|
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
2014-08-19 16:30:54 +00:00
|
|
|
|
2014-11-02 19:04:08 +00:00
|
|
|
init: function(aWindow, aHasFullMgmtPrivilege) {
|
|
|
|
this._window = aWindow;
|
|
|
|
|
2014-08-19 16:30:54 +00:00
|
|
|
this.initDOMRequestHelper(aWindow, ["Webapps:Uninstall:Return:OK",
|
|
|
|
"Webapps:Uninstall:Broadcast:Return:OK",
|
|
|
|
"Webapps:Uninstall:Return:KO",
|
|
|
|
"Webapps:Install:Return:OK",
|
2014-10-15 05:55:14 +00:00
|
|
|
"Webapps:GetNotInstalled:Return:OK",
|
|
|
|
"Webapps:Import:Return",
|
2014-10-23 23:40:08 +00:00
|
|
|
"Webapps:ExtractManifest:Return",
|
|
|
|
"Webapps:SetEnabled:Return"]);
|
2014-08-19 16:30:54 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:RegisterForMessages",
|
|
|
|
{
|
|
|
|
messages: ["Webapps:Install:Return:OK",
|
|
|
|
"Webapps:Uninstall:Return:OK",
|
2014-10-23 23:40:08 +00:00
|
|
|
"Webapps:Uninstall:Broadcast:Return:OK",
|
|
|
|
"Webapps:SetEnabled:Return"]
|
2014-08-19 16:30:54 +00:00
|
|
|
}
|
|
|
|
);
|
2014-11-02 19:04:08 +00:00
|
|
|
|
|
|
|
if (!aHasFullMgmtPrivilege) {
|
|
|
|
this.getNotInstalled = null;
|
|
|
|
this.applyDownload = null;
|
|
|
|
}
|
2014-08-19 16:30:54 +00:00
|
|
|
},
|
2012-03-06 19:50:58 +00:00
|
|
|
|
|
|
|
uninit: function() {
|
2012-10-19 18:17:05 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
|
2013-01-11 12:50:46 +00:00
|
|
|
["Webapps:Install:Return:OK",
|
|
|
|
"Webapps:Uninstall:Return:OK",
|
2014-10-23 23:40:08 +00:00
|
|
|
"Webapps:Uninstall:Broadcast:Return:OK",
|
|
|
|
"Webapps:SetEnabled:Return"]);
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-09-27 01:01:20 +00:00
|
|
|
applyDownload: function(aApp) {
|
2012-09-29 17:57:18 +00:00
|
|
|
if (!aApp.readyToApplyDownload) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-02 19:04:08 +00:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
|
|
|
|
2012-10-30 00:17:47 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:ApplyDownload",
|
2014-11-02 19:04:08 +00:00
|
|
|
{ manifestURL: aApp.manifestURL },
|
|
|
|
null, principal);
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
2013-01-11 12:50:46 +00:00
|
|
|
uninstall: function(aApp) {
|
|
|
|
let request = this.createRequest();
|
2014-11-02 19:04:08 +00:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
2014-06-11 21:23:18 +00:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("Webapps:Uninstall", {
|
|
|
|
origin: aApp.origin,
|
|
|
|
manifestURL: aApp.manifestURL,
|
|
|
|
oid: this._id,
|
|
|
|
from: this._window.location.href,
|
|
|
|
windowId: this._windowId,
|
|
|
|
requestID: this.getRequestId(request)
|
2014-11-02 19:04:08 +00:00
|
|
|
}, null, principal);
|
|
|
|
|
2013-01-11 12:50:46 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
getAll: function() {
|
|
|
|
let request = this.createRequest();
|
2014-07-07 18:01:30 +00:00
|
|
|
let window = this._window;
|
|
|
|
DOMApplicationRegistry.getAll((aApps) => {
|
|
|
|
Services.DOMRequest.fireSuccessAsync(request,
|
|
|
|
convertAppsArray(aApps, window));
|
|
|
|
});
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-08-20 17:19:56 +00:00
|
|
|
getNotInstalled: function() {
|
|
|
|
let request = this.createRequest();
|
2014-11-02 19:04:08 +00:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("Webapps:GetNotInstalled", {
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getRequestId(request)
|
|
|
|
}, null, principal);
|
|
|
|
|
2012-08-20 17:19:56 +00:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-15 05:55:14 +00:00
|
|
|
import: function(aBlob) {
|
2014-11-02 19:04:08 +00:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
2014-10-15 05:55:14 +00:00
|
|
|
return this.createPromise((aResolve, aReject) => {
|
|
|
|
cpmm.sendAsyncMessage("Webapps:Import",
|
|
|
|
{ blob: aBlob,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getPromiseResolverId({
|
|
|
|
resolve: aResolve,
|
|
|
|
reject: aReject
|
2014-11-02 19:04:08 +00:00
|
|
|
})}, null, principal);
|
2014-10-15 05:55:14 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
extractManifest: function(aBlob) {
|
2014-11-02 19:04:08 +00:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
2014-10-15 05:55:14 +00:00
|
|
|
return this.createPromise((aResolve, aReject) => {
|
|
|
|
cpmm.sendAsyncMessage("Webapps:ExtractManifest",
|
|
|
|
{ blob: aBlob,
|
|
|
|
oid: this._id,
|
|
|
|
requestID: this.getPromiseResolverId({
|
|
|
|
resolve: aResolve,
|
|
|
|
reject: aReject
|
2014-11-02 19:04:08 +00:00
|
|
|
})}, null, principal);
|
2014-10-15 05:55:14 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-10-23 23:40:08 +00:00
|
|
|
setEnabled: function(aApp, aValue) {
|
2014-11-02 19:04:08 +00:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
|
|
|
|
2014-10-23 23:40:08 +00:00
|
|
|
cpmm.sendAsyncMessage("Webapps:SetEnabled",
|
|
|
|
{ manifestURL: aApp.manifestURL,
|
2014-11-02 19:04:08 +00:00
|
|
|
enabled: aValue }, null, principal);
|
2014-10-23 23:40:08 +00:00
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
get oninstall() {
|
2014-08-19 16:30:54 +00:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("oninstall");
|
2012-03-06 19:50:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get onuninstall() {
|
2014-08-19 16:30:54 +00:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("onuninstall");
|
2012-03-06 19:50:58 +00:00
|
|
|
},
|
|
|
|
|
2014-10-23 23:40:08 +00:00
|
|
|
get onenabledstatechange() {
|
|
|
|
return this.__DOM_IMPL__.getEventHandler("onenabledstatechange");
|
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
set oninstall(aCallback) {
|
2014-08-19 16:30:54 +00:00
|
|
|
this.__DOM_IMPL__.setEventHandler("oninstall", aCallback);
|
2012-03-06 19:50:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set onuninstall(aCallback) {
|
2014-08-19 16:30:54 +00:00
|
|
|
this.__DOM_IMPL__.setEventHandler("onuninstall", aCallback);
|
2012-03-06 19:50:58 +00:00
|
|
|
},
|
|
|
|
|
2014-10-23 23:40:08 +00:00
|
|
|
set onenabledstatechange(aCallback) {
|
|
|
|
this.__DOM_IMPL__.setEventHandler("onenabledstatechange", aCallback);
|
|
|
|
},
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
receiveMessage: function(aMessage) {
|
2014-10-15 05:55:14 +00:00
|
|
|
let msg = aMessage.data;
|
|
|
|
let req;
|
2014-10-23 23:40:08 +00:00
|
|
|
|
2014-10-15 05:55:14 +00:00
|
|
|
if (["Webapps:Import:Return",
|
|
|
|
"Webapps:ExtractManifest:Return"]
|
|
|
|
.indexOf(aMessage.name) != -1) {
|
|
|
|
req = this.takePromiseResolver(msg.requestID);
|
|
|
|
} else {
|
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:40:08 +00:00
|
|
|
// We want Webapps:Install:Return:OK, Webapps:Uninstall:Broadcast:Return:OK
|
|
|
|
// and Webapps:SetEnabled:Return
|
2013-11-07 11:30:31 +00:00
|
|
|
// to be broadcasted to all instances of mozApps.mgmt.
|
2013-01-11 12:50:46 +00:00
|
|
|
if (!((msg.oid == this._id && req) ||
|
|
|
|
aMessage.name == "Webapps:Install:Return:OK" ||
|
2014-10-23 23:40:08 +00:00
|
|
|
aMessage.name == "Webapps:Uninstall:Broadcast:Return:OK" ||
|
|
|
|
aMessage.name == "Webapps:SetEnabled:Return")) {
|
2012-03-06 19:50:58 +00:00
|
|
|
return;
|
2013-01-11 12:50:46 +00:00
|
|
|
}
|
2014-10-15 05:55:14 +00:00
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
switch (aMessage.name) {
|
2012-08-20 17:19:56 +00:00
|
|
|
case "Webapps:GetNotInstalled:Return:OK":
|
|
|
|
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
|
|
|
|
break;
|
2012-03-06 19:50:58 +00:00
|
|
|
case "Webapps:Install:Return:OK":
|
2014-08-19 16:30:54 +00:00
|
|
|
{
|
|
|
|
let app = createContentApplicationObject(this._window, msg.app);
|
|
|
|
let event =
|
|
|
|
new this._window.MozApplicationEvent("install", { application: app });
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
2012-03-06 19:50:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-01-11 12:50:46 +00:00
|
|
|
case "Webapps:Uninstall:Broadcast:Return:OK":
|
2014-08-19 16:30:54 +00:00
|
|
|
{
|
2014-08-20 19:27:32 +00:00
|
|
|
let app = createContentApplicationObject(this._window, msg);
|
2014-08-19 16:30:54 +00:00
|
|
|
let event =
|
|
|
|
new this._window.MozApplicationEvent("uninstall", { application : app });
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
2012-03-06 19:50:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-01-11 12:50:46 +00:00
|
|
|
case "Webapps:Uninstall:Return:OK":
|
2014-07-22 20:08:21 +00:00
|
|
|
Services.DOMRequest.fireSuccess(req, msg.manifestURL);
|
2013-01-11 12:50:46 +00:00
|
|
|
break;
|
|
|
|
case "Webapps:Uninstall:Return:KO":
|
|
|
|
Services.DOMRequest.fireError(req, "NOT_INSTALLED");
|
|
|
|
break;
|
2014-10-15 05:55:14 +00:00
|
|
|
case "Webapps:Import:Return":
|
|
|
|
if (msg.success) {
|
|
|
|
req.resolve(createContentApplicationObject(this._window, msg.app));
|
|
|
|
} else {
|
|
|
|
req.reject(new this._window.DOMError(msg.error || ""));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "Webapps:ExtractManifest:Return":
|
|
|
|
if (msg.success) {
|
|
|
|
req.resolve(Cu.cloneInto(msg.manifest, this._window));
|
|
|
|
} else {
|
|
|
|
req.reject(new this._window.DOMError(msg.error || ""));
|
|
|
|
}
|
|
|
|
break;
|
2014-10-23 23:40:08 +00:00
|
|
|
case "Webapps:SetEnabled:Return":
|
|
|
|
{
|
|
|
|
let app = createContentApplicationObject(this._window, msg);
|
|
|
|
let event =
|
|
|
|
new this._window.MozApplicationEvent("enabledstatechange", { application : app });
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
break;
|
2013-01-11 12:50:46 +00:00
|
|
|
}
|
|
|
|
if (aMessage.name !== "Webapps:Uninstall:Broadcast:Return:OK") {
|
|
|
|
this.removeRequest(msg.requestID);
|
2012-03-06 19:50:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{8c1bca96-266f-493a-8d57-ec7a95098c15}"),
|
|
|
|
|
2014-08-19 16:30:54 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference])
|
2012-03-06 19:50:58 +00:00
|
|
|
}
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsRegistry,
|
2014-08-19 16:30:54 +00:00
|
|
|
WebappsApplicationMgmt,
|
2013-05-18 17:52:06 +00:00
|
|
|
WebappsApplication]);
|