2012-03-06 23:50:58 +04: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-29 00:13:26 +04: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 23:50:58 +04:00
|
|
|
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
2012-09-23 04:48:26 +04:00
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-09-27 02:03:25 +04:00
|
|
|
Cu.import("resource://gre/modules/BrowserElementPromptService.jsm");
|
2014-05-24 23:28:13 +04:00
|
|
|
Cu.import("resource://gre/modules/AppsServiceChild.jsm");
|
2014-11-02 22:04:08 +03:00
|
|
|
Cu.import("resource://gre/modules/Preferences.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
|
|
|
|
"@mozilla.org/AppsService;1",
|
|
|
|
"nsIAppsService");
|
2012-03-06 23:50:58 +04:00
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsIMessageSender");
|
2012-03-06 23:50:58 +04:00
|
|
|
|
2014-08-19 20:30:54 +04:00
|
|
|
function debug(aMsg) {
|
|
|
|
dump("-*- Webapps.js " + aMsg + "\n");
|
|
|
|
}
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
function convertAppsArray(aApps, aWindow) {
|
2014-03-24 18:30:20 +04:00
|
|
|
let apps = new aWindow.Array();
|
2014-08-19 20:30:54 +04:00
|
|
|
aApps.forEach((aApp) => {
|
|
|
|
let obj = createContentApplicationObject(aWindow, aApp);
|
|
|
|
apps.push(obj);
|
|
|
|
});
|
2012-03-06 23:50:58 +04:00
|
|
|
return apps;
|
|
|
|
}
|
2011-11-29 00:13:26 +04:00
|
|
|
|
|
|
|
function WebappsRegistry() {
|
|
|
|
}
|
|
|
|
|
|
|
|
WebappsRegistry.prototype = {
|
2012-03-06 23:50:58 +04:00
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
2011-11-29 00:13:26 +04:00
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let msg = aMessage.json;
|
2015-01-11 02:00:27 +03:00
|
|
|
let req;
|
|
|
|
if (aMessage.name != "Webapps:AdditionalLanguageChange") {
|
|
|
|
if (msg.oid != this._id) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMessage.name == "Webapps:GetAdditionalLanguages:Return" ||
|
|
|
|
aMessage.name == "Webapps:GetLocalizationResource:Return") {
|
|
|
|
req = this.takePromiseResolver(msg.requestID);
|
|
|
|
} else {
|
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
}
|
|
|
|
if (!req) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 00:13:26 +04:00
|
|
|
let app = msg.app;
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Webapps:Install:Return:OK":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners("Webapps:Install:Return:KO");
|
2014-08-19 20:30:54 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, createContentApplicationObject(this._window, app));
|
2013-02-13 23:55:45 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Install:Return:Ack",
|
|
|
|
{ manifestURL : app.manifestURL });
|
2011-11-29 00:13:26 +04:00
|
|
|
break;
|
|
|
|
case "Webapps:Install:Return:KO":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2012-08-09 01:07:39 +04:00
|
|
|
Services.DOMRequest.fireError(req, msg.error || "DENIED");
|
2011-11-29 00:13:26 +04:00
|
|
|
break;
|
2012-03-06 23:50:58 +04:00
|
|
|
case "Webapps:GetSelf:Return:OK":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2012-03-06 23:50:58 +04:00
|
|
|
if (msg.apps.length) {
|
|
|
|
app = msg.apps[0];
|
2014-08-19 20:30:54 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, createContentApplicationObject(this._window, app));
|
2012-03-06 23:50:58 +04:00
|
|
|
} else {
|
2012-04-11 09:55:54 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
2011-11-29 00:13:26 +04:00
|
|
|
}
|
|
|
|
break;
|
2012-10-03 00:38:51 +04:00
|
|
|
case "Webapps:CheckInstalled:Return:OK":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2015-08-08 22:26:00 +03:00
|
|
|
Services.DOMRequest.fireSuccess(req, createContentApplicationObject(this._window, msg.app));
|
2012-09-25 19:04:24 +04:00
|
|
|
break;
|
2012-03-06 23:50:58 +04:00
|
|
|
case "Webapps:GetInstalled:Return:OK":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2012-04-11 09:55:54 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
|
2012-03-06 23:50:58 +04:00
|
|
|
break;
|
2015-01-11 02:00:27 +03:00
|
|
|
case "Webapps:AdditionalLanguageChange":
|
|
|
|
// Check if the current page is from the app receiving the event.
|
|
|
|
let manifestURL = AppsUtils.getAppManifestURLFromWindow(this._window);
|
|
|
|
if (manifestURL && manifestURL == msg.manifestURL) {
|
|
|
|
// Let's dispatch an "additionallanguageschange" event on the document.
|
|
|
|
let doc = this._window.document;
|
|
|
|
let event = doc.createEvent("CustomEvent");
|
|
|
|
event.initCustomEvent("additionallanguageschange", true, true,
|
|
|
|
Cu.cloneInto(msg.languages, this._window));
|
|
|
|
doc.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "Webapps:GetLocalizationResource:Return":
|
|
|
|
this.removeMessageListeners(["Webapps:GetLocalizationResource:Return"]);
|
|
|
|
if (msg.error) {
|
|
|
|
req.reject(new this._window.DOMError(msg.error));
|
|
|
|
} else {
|
|
|
|
req.resolve(Cu.cloneInto(msg.data, this._window));
|
|
|
|
}
|
|
|
|
break;
|
2011-11-29 00:13:26 +04:00
|
|
|
}
|
2012-03-06 23:50:58 +04:00
|
|
|
this.removeRequest(msg.requestID);
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_getOrigin: function(aURL) {
|
|
|
|
let uri = Services.io.newURI(aURL, null, null);
|
2012-08-28 06:43:57 +04:00
|
|
|
return uri.prePath;
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2013-11-07 15:30:31 +04: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 23:41:24 +04:00
|
|
|
let uri;
|
|
|
|
let res;
|
2013-11-07 15:30:31 +04:00
|
|
|
|
2013-01-14 23:41:24 +04:00
|
|
|
try {
|
|
|
|
uri = Services.io.newURI(aURL, null, null);
|
|
|
|
if (uri.schemeIs("http") || uri.schemeIs("https")) {
|
|
|
|
res = uri.spec;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
2013-11-07 15:30:31 +04:00
|
|
|
Services.DOMRequest.fireErrorAsync(aRequest, "INVALID_URL");
|
|
|
|
return false;
|
2013-01-14 23:41:24 +04:00
|
|
|
}
|
|
|
|
|
2013-11-07 15:30:31 +04:00
|
|
|
// The scheme is incorrect, fire DOMRequest error.
|
2013-01-14 23:41:24 +04:00
|
|
|
if (!res) {
|
2013-11-07 15:30:31 +04:00
|
|
|
Services.DOMRequest.fireErrorAsync(aRequest, "INVALID_URL");
|
|
|
|
return false;
|
2012-09-25 06:41:21 +04:00
|
|
|
}
|
2013-11-07 15:30:31 +04:00
|
|
|
|
2013-01-14 23:41:24 +04:00
|
|
|
return uri.spec;
|
2012-09-25 06:41:21 +04:00
|
|
|
},
|
|
|
|
|
2013-01-08 21:02:17 +04: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 15:30:31 +04:00
|
|
|
Services.DOMRequest.fireErrorAsync(aRequest, "BACKGROUND_APP");
|
2013-01-08 21:02:17 +04:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2013-08-02 04:00:39 +04:00
|
|
|
_prepareInstall: function(aURL, aRequest, aParams, isPackage) {
|
2013-08-02 05:51:12 +04:00
|
|
|
let installURL = this._window.location.href;
|
2013-08-02 04:00:39 +04:00
|
|
|
let requestID = this.getRequestId(aRequest);
|
2013-08-02 05:51:12 +04: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 04:00:39 +04:00
|
|
|
|
|
|
|
return { app: {
|
|
|
|
installOrigin: this._getOrigin(installURL),
|
|
|
|
origin: this._getOrigin(aURL),
|
|
|
|
manifestURL: aURL,
|
|
|
|
receipts: receipts,
|
|
|
|
categories: categories
|
|
|
|
},
|
|
|
|
|
|
|
|
from: installURL,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2013-08-02 04:00:39 +04:00
|
|
|
requestID: requestID,
|
|
|
|
appId: principal.appId,
|
|
|
|
isBrowser: principal.isInBrowserElement,
|
|
|
|
isPackage: isPackage
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
// mozIDOMApplicationRegistry implementation
|
|
|
|
|
|
|
|
install: function(aURL, aParams) {
|
|
|
|
let request = this.createRequest();
|
|
|
|
|
2013-11-07 15:30:31 +04:00
|
|
|
let uri = this._validateURL(aURL, request);
|
|
|
|
|
|
|
|
if (uri && this._ensureForeground(request)) {
|
2013-10-05 01:59:48 +04:00
|
|
|
this.addMessageListeners("Webapps:Install:Return:KO");
|
2013-08-02 04:00:39 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Install",
|
|
|
|
this._prepareInstall(uri, request, aParams, false));
|
|
|
|
}
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
return request;
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
getSelf: function() {
|
|
|
|
let request = this.createRequest();
|
2013-10-05 01:59:48 +04:00
|
|
|
this.addMessageListeners("Webapps:GetSelf:Return:OK");
|
2012-03-06 23:50:58 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetSelf", { origin: this._getOrigin(this._window.location.href),
|
2012-09-25 19:04:24 +04:00
|
|
|
appId: this._window.document.nodePrincipal.appId,
|
2015-02-11 20:03:12 +03:00
|
|
|
oid: this._id, topId: this._topId,
|
2012-03-06 23:50:58 +04:00
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
return request;
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2012-10-03 00:38:51 +04:00
|
|
|
checkInstalled: function(aManifestURL) {
|
2012-09-25 19:04:24 +04:00
|
|
|
let manifestURL = Services.io.newURI(aManifestURL, null, this._window.document.baseURIObject);
|
|
|
|
|
|
|
|
let request = this.createRequest();
|
2013-10-05 01:59:48 +04:00
|
|
|
|
2014-06-25 03:51:28 +04: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-05 01:59:48 +04:00
|
|
|
this.addMessageListeners("Webapps:CheckInstalled:Return:OK");
|
2012-10-03 00:38:51 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:CheckInstalled", { origin: this._getOrigin(this._window.location.href),
|
|
|
|
manifestURL: manifestURL.spec,
|
2015-02-11 20:03:12 +03:00
|
|
|
oid: this._id, topId: this._topId,
|
2012-10-03 00:38:51 +04:00
|
|
|
requestID: this.getRequestId(request) });
|
2012-09-25 19:04:24 +04:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
getInstalled: function() {
|
|
|
|
let request = this.createRequest();
|
2013-10-05 01:59:48 +04:00
|
|
|
this.addMessageListeners("Webapps:GetInstalled:Return:OK");
|
2012-03-06 23:50:58 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetInstalled", { origin: this._getOrigin(this._window.location.href),
|
2015-02-11 20:03:12 +03:00
|
|
|
oid: this._id, topId: this._topId,
|
2012-03-06 23:50:58 +04:00
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
return request;
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2012-09-12 00:53:42 +04:00
|
|
|
get mgmt() {
|
2013-01-19 20:56:29 +04:00
|
|
|
if (!this.hasMgmtPrivilege) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-08-19 20:30:54 +04:00
|
|
|
if (!this._mgmt) {
|
|
|
|
let mgmt = Cc["@mozilla.org/webapps/manager;1"]
|
|
|
|
.createInstance(Ci.nsISupports);
|
2014-11-02 22:04:08 +03:00
|
|
|
mgmt.wrappedJSObject.init(this._window, this.hasFullMgmtPrivilege);
|
2014-06-12 01:23:18 +04:00
|
|
|
mgmt.wrappedJSObject._windowId = this._id;
|
2015-02-11 20:03:12 +03:00
|
|
|
mgmt.wrappedJSObject._topId = this._topId;
|
2014-08-19 20:30:54 +04:00
|
|
|
this._mgmt = mgmt.__DOM_IMPL__
|
|
|
|
? mgmt.__DOM_IMPL__
|
|
|
|
: this._window.DOMApplicationsManager._create(this._window, mgmt.wrappedJSObject);
|
|
|
|
}
|
2012-09-12 00:53:42 +04:00
|
|
|
return this._mgmt;
|
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function() {
|
|
|
|
this._mgmt = null;
|
2012-10-19 22:17:05 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
|
2015-01-11 02:00:27 +03:00
|
|
|
["Webapps:Install:Return:OK",
|
|
|
|
"Webapps:AdditionalLanguageChange"]);
|
Bug 1077168 - Cancel in-flight Webapp install jobs from windows that change location. r=myk.
Installing a Webapp is an asynchronous job, and there is a pocket of time
between when web content requests to install an app and before the browser
displays an installation prompt that the outer window of the content can
browse away. This pocket of time is typically used by XHR to request the
web app resources and verify their contents.
This pocket of time is, essentially, bug 771294, and is a bit of a security
problem.
This problem was originally patched over on Desktop by checking in the parent
process that the outer window was still at the same URI as it had been when it
made the request. I'm not entirely sure if Android / B2G made similar checks.
With separated content processes, however, the browser front-end can no longer
performantly check to ensure that the outer window is at the same URI.
We solve this problem by sending up a message in the content process when
the location of an outer window making use of navigator.mozApps changes.
We hold a Map of "actions" mapping to in-flight installs mapped by the
outer window ID of the requesting content. When we notice a location
change, we mark those actions as cancelled. When the XHR returns, we have
it check the state of its actions, and if they're cancelled, it aborts
further action.
Normally, this wouldn't be necessary, since any XHR initiated by the
content window would be cancelled once the location changed, but in
this case, the XHR is occurring in Webapps.jsm, and is not influenced
by the outer window of the content.
--HG--
extra : rebase_source : 5f95002a21c96c5cbf3dca8ca265400448251b43
2015-02-10 21:18:47 +03:00
|
|
|
this._window.removeEventListener("pagehide", this);
|
2012-09-12 00:53:42 +04:00
|
|
|
},
|
|
|
|
|
2012-09-27 23:34:41 +04:00
|
|
|
installPackage: function(aURL, aParams) {
|
2013-01-08 21:02:17 +04:00
|
|
|
let request = this.createRequest();
|
|
|
|
|
2013-11-07 15:30:31 +04:00
|
|
|
let uri = this._validateURL(aURL, request);
|
|
|
|
|
|
|
|
if (uri && this._ensureForeground(request)) {
|
2013-10-05 01:59:48 +04:00
|
|
|
this.addMessageListeners("Webapps:Install:Return:KO");
|
2013-08-02 04:00:39 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:InstallPackage",
|
|
|
|
this._prepareInstall(uri, request, aParams, true));
|
2013-01-08 21:02:17 +04:00
|
|
|
}
|
|
|
|
|
2012-07-11 19:38:33 +04:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2015-01-11 02:00:27 +03:00
|
|
|
_getCurrentAppManifestURL: function() {
|
|
|
|
let appId = this._window.document.nodePrincipal.appId;
|
|
|
|
if (appId === Ci.nsIScriptSecurityManager.NO_APP_ID) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return appsService.getManifestURLByLocalId(appId);
|
|
|
|
},
|
|
|
|
|
|
|
|
getAdditionalLanguages: function() {
|
|
|
|
let manifestURL = AppsUtils.getAppManifestURLFromWindow(this._window);
|
|
|
|
|
|
|
|
return new this._window.Promise((aResolve, aReject) => {
|
|
|
|
if (!manifestURL) {
|
|
|
|
aReject("NotInApp");
|
|
|
|
} else {
|
|
|
|
let langs = DOMApplicationRegistry.getAdditionalLanguages(manifestURL);
|
|
|
|
aResolve(Cu.cloneInto(langs, this._window));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getLocalizationResource: function(aLanguage, aVersion, aPath, aType) {
|
|
|
|
let manifestURL = AppsUtils.getAppManifestURLFromWindow(this._window);
|
|
|
|
|
|
|
|
if (!manifestURL) {
|
|
|
|
return new Promise((aResolve, aReject) => {
|
|
|
|
aReject("NotInApp");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addMessageListeners(["Webapps:GetLocalizationResource:Return"]);
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2015-01-11 02:00:27 +03:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetLocalizationResource", {
|
|
|
|
manifestURL: manifestURL,
|
|
|
|
lang: aLanguage,
|
|
|
|
version: aVersion,
|
|
|
|
path: aPath,
|
|
|
|
dataType: aType,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
2015-01-11 02:00:27 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-11-29 00:13:26 +04:00
|
|
|
// nsIDOMGlobalPropertyInitializer implementation
|
|
|
|
init: function(aWindow) {
|
2014-11-02 22:04:08 +03:00
|
|
|
const prefs = new Preferences();
|
|
|
|
|
|
|
|
this._window = aWindow;
|
Bug 1077168 - Cancel in-flight Webapp install jobs from windows that change location. r=myk.
Installing a Webapp is an asynchronous job, and there is a pocket of time
between when web content requests to install an app and before the browser
displays an installation prompt that the outer window of the content can
browse away. This pocket of time is typically used by XHR to request the
web app resources and verify their contents.
This pocket of time is, essentially, bug 771294, and is a bit of a security
problem.
This problem was originally patched over on Desktop by checking in the parent
process that the outer window was still at the same URI as it had been when it
made the request. I'm not entirely sure if Android / B2G made similar checks.
With separated content processes, however, the browser front-end can no longer
performantly check to ensure that the outer window is at the same URI.
We solve this problem by sending up a message in the content process when
the location of an outer window making use of navigator.mozApps changes.
We hold a Map of "actions" mapping to in-flight installs mapped by the
outer window ID of the requesting content. When we notice a location
change, we mark those actions as cancelled. When the XHR returns, we have
it check the state of its actions, and if they're cancelled, it aborts
further action.
Normally, this wouldn't be necessary, since any XHR initiated by the
content window would be cancelled once the location changed, but in
this case, the XHR is occurring in Webapps.jsm, and is not influenced
by the outer window of the content.
--HG--
extra : rebase_source : 5f95002a21c96c5cbf3dca8ca265400448251b43
2015-02-10 21:18:47 +03:00
|
|
|
this._window.addEventListener("pagehide", this);
|
2014-11-02 22:04:08 +03:00
|
|
|
|
2015-01-11 02:00:27 +03:00
|
|
|
this.initDOMRequestHelper(aWindow, ["Webapps:Install:Return:OK",
|
|
|
|
"Webapps:AdditionalLanguageChange"]);
|
2011-12-08 06:15:42 +04:00
|
|
|
|
2013-01-19 20:56:29 +04:00
|
|
|
let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
2012-03-06 23:50:58 +04:00
|
|
|
this._id = util.outerWindowID;
|
2015-02-11 20:03:12 +03:00
|
|
|
|
|
|
|
let topUtil = this._window.top
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
this._topId = topUtil.outerWindowID;
|
|
|
|
|
2012-09-18 21:34:55 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:RegisterForMessages",
|
2015-01-11 02:00:27 +03:00
|
|
|
{ messages: ["Webapps:Install:Return:OK",
|
|
|
|
"Webapps:AdditionalLanguageChange"]});
|
2013-01-19 20:56:29 +04:00
|
|
|
|
|
|
|
let principal = aWindow.document.nodePrincipal;
|
2014-11-02 22:04:08 +03:00
|
|
|
let appId = principal.appId;
|
|
|
|
let app = appId && appsService.getAppByLocalId(appId);
|
2013-01-19 20:56:29 +04:00
|
|
|
|
2014-11-02 22:04:08 +03: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-29 00:13:26 +04:00
|
|
|
},
|
2012-08-28 06:43:57 +04:00
|
|
|
|
Bug 1077168 - Cancel in-flight Webapp install jobs from windows that change location. r=myk.
Installing a Webapp is an asynchronous job, and there is a pocket of time
between when web content requests to install an app and before the browser
displays an installation prompt that the outer window of the content can
browse away. This pocket of time is typically used by XHR to request the
web app resources and verify their contents.
This pocket of time is, essentially, bug 771294, and is a bit of a security
problem.
This problem was originally patched over on Desktop by checking in the parent
process that the outer window was still at the same URI as it had been when it
made the request. I'm not entirely sure if Android / B2G made similar checks.
With separated content processes, however, the browser front-end can no longer
performantly check to ensure that the outer window is at the same URI.
We solve this problem by sending up a message in the content process when
the location of an outer window making use of navigator.mozApps changes.
We hold a Map of "actions" mapping to in-flight installs mapped by the
outer window ID of the requesting content. When we notice a location
change, we mark those actions as cancelled. When the XHR returns, we have
it check the state of its actions, and if they're cancelled, it aborts
further action.
Normally, this wouldn't be necessary, since any XHR initiated by the
content window would be cancelled once the location changed, but in
this case, the XHR is occurring in Webapps.jsm, and is not influenced
by the outer window of the content.
--HG--
extra : rebase_source : 5f95002a21c96c5cbf3dca8ca265400448251b43
2015-02-10 21:18:47 +03:00
|
|
|
handleEvent(event) {
|
|
|
|
if (event.type == "pagehide" &&
|
|
|
|
event.target.defaultView == this._window) {
|
|
|
|
cpmm.sendAsyncMessage("Webapps:LocationChange", {
|
|
|
|
oid: this._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-11-29 00:13:26 +04:00
|
|
|
classID: Components.ID("{fff440b3-fae2-45c1-bf03-3b5a2e432270}"),
|
|
|
|
|
2013-07-09 01:55:42 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
|
2014-08-19 20:30:54 +04:00
|
|
|
Ci.nsISupports,
|
2013-11-20 09:33:10 +04:00
|
|
|
Ci.nsIObserver,
|
2014-08-19 20:30:54 +04:00
|
|
|
Ci.nsIDOMGlobalPropertyInitializer])
|
2011-11-29 00:13:26 +04:00
|
|
|
}
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
/**
|
2014-08-19 20:30:54 +04:00
|
|
|
* DOMApplication object
|
2012-03-06 23:50:58 +04:00
|
|
|
*/
|
2012-06-11 22:41:46 +04:00
|
|
|
|
2012-08-30 01:20:03 +04:00
|
|
|
function createApplicationObject(aWindow, aApp) {
|
2014-05-24 23:28:13 +04:00
|
|
|
let app = Cc["@mozilla.org/webapps/application;1"]
|
2014-08-19 20:30:54 +04:00
|
|
|
.createInstance(Ci.nsISupports);
|
2012-08-30 01:20:03 +04:00
|
|
|
app.wrappedJSObject.init(aWindow, aApp);
|
2012-06-11 22:41:46 +04:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2014-08-19 20:30:54 +04:00
|
|
|
function createContentApplicationObject(aWindow, aApp) {
|
|
|
|
return createApplicationObject(aWindow, aApp).wrappedJSObject
|
|
|
|
._prepareForContent();
|
|
|
|
}
|
|
|
|
|
2012-06-11 22:41:46 +04:00
|
|
|
function WebappsApplication() {
|
|
|
|
this.wrappedJSObject = this;
|
2011-11-29 00:13:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WebappsApplication.prototype = {
|
2012-03-06 23:50:58 +04:00
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
2011-11-29 00:13:26 +04:00
|
|
|
|
2012-08-30 01:20:03 +04:00
|
|
|
init: function(aWindow, aApp) {
|
2014-11-02 22:04:08 +03:00
|
|
|
this._window = aWindow;
|
|
|
|
|
2014-05-24 23:28:13 +04: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-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2012-10-19 02:30:58 +04:00
|
|
|
get manifest() {
|
2014-05-24 23:28:13 +04:00
|
|
|
return WrappedManifestCache.get(this.manifestURL,
|
|
|
|
this._proxy.manifest,
|
|
|
|
this._window,
|
|
|
|
this.innerWindowID);
|
2012-10-19 02:30:58 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get updateManifest() {
|
2014-05-24 23:28:13 +04:00
|
|
|
return this._proxy.updateManifest ?
|
|
|
|
Cu.cloneInto(this._proxy.updateManifest, this._window) : null;
|
2012-10-19 02:30:58 +04:00
|
|
|
},
|
|
|
|
|
2012-06-11 22:41:46 +04:00
|
|
|
set onprogress(aCallback) {
|
2014-08-19 20:30:54 +04:00
|
|
|
this.__DOM_IMPL__.setEventHandler("onprogress", aCallback);
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2012-06-11 22:41:46 +04:00
|
|
|
get onprogress() {
|
2014-08-19 20:30:54 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("onprogress");
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2012-09-27 05:01:20 +04:00
|
|
|
set ondownloadsuccess(aCallback) {
|
2014-08-19 20:30:54 +04:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloadsuccess", aCallback);
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloadsuccess() {
|
2014-08-19 20:30:54 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloadsuccess");
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
set ondownloaderror(aCallback) {
|
2014-08-19 20:30:54 +04:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloaderror", aCallback);
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloaderror() {
|
2014-08-19 20:30:54 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloaderror");
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
set ondownloadavailable(aCallback) {
|
2014-08-19 20:30:54 +04:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloadavailable", aCallback);
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloadavailable() {
|
2014-08-19 20:30:54 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloadavailable");
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
set ondownloadapplied(aCallback) {
|
2014-08-19 20:30:54 +04:00
|
|
|
this.__DOM_IMPL__.setEventHandler("ondownloadapplied", aCallback);
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get ondownloadapplied() {
|
2014-08-19 20:30:54 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("ondownloadapplied");
|
|
|
|
},
|
|
|
|
|
|
|
|
get receipts() {
|
2014-09-06 03:55:30 +04:00
|
|
|
return this._proxy.receipts || [];
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get downloadError() {
|
2014-06-26 00:47:00 +04:00
|
|
|
// Only return DOMError when we have an error.
|
2014-05-24 23:28:13 +04:00
|
|
|
if (!this._proxy.downloadError) {
|
2014-06-26 00:47:00 +04:00
|
|
|
return null;
|
|
|
|
}
|
2014-05-24 23:28:13 +04:00
|
|
|
return new this._window.DOMError(this._proxy.downloadError);
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
2014-10-24 03:40:08 +04:00
|
|
|
get enabled() {
|
2015-05-21 09:06:03 +03:00
|
|
|
let value = this._proxy.enabled;
|
|
|
|
return (value === undefined ? true : value);
|
2014-10-24 03:40:08 +04:00
|
|
|
},
|
|
|
|
|
2012-09-27 05:01:20 +04:00
|
|
|
download: function() {
|
2012-09-29 21:57:18 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Download",
|
|
|
|
{ manifestURL: this.manifestURL });
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelDownload: function() {
|
|
|
|
cpmm.sendAsyncMessage("Webapps:CancelDownload",
|
|
|
|
{ manifestURL: this.manifestURL });
|
|
|
|
},
|
|
|
|
|
|
|
|
checkForUpdate: function() {
|
|
|
|
let request = this.createRequest();
|
2012-12-03 23:38:09 +04:00
|
|
|
|
2012-12-17 23:11:05 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:CheckForUpdate",
|
|
|
|
{ manifestURL: this.manifestURL,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2012-12-17 23:11:05 +04:00
|
|
|
requestID: this.getRequestId(request) });
|
2012-09-27 05:01:20 +04:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
launch: function(aStartPoint) {
|
|
|
|
let request = this.createRequest();
|
2015-11-25 14:37:24 +03:00
|
|
|
this.addMessageListeners(["Webapps:Launch:Return:OK",
|
|
|
|
"Webapps:Launch:Return:KO"]);
|
2012-06-11 22:41:46 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Launch", { origin: this.origin,
|
2012-09-07 19:41:26 +04:00
|
|
|
manifestURL: this.manifestURL,
|
2012-05-04 22:02:05 +04:00
|
|
|
startPoint: aStartPoint || "",
|
2012-03-06 23:50:58 +04:00
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2013-02-05 22:05:56 +04:00
|
|
|
timestamp: Date.now(),
|
2012-03-06 23:50:58 +04:00
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-09-27 02:03:25 +04:00
|
|
|
clearBrowserData: function() {
|
2013-05-20 21:20:19 +04:00
|
|
|
let request = this.createRequest();
|
2012-09-27 02:03:25 +04:00
|
|
|
let browserChild =
|
|
|
|
BrowserElementPromptService.getBrowserElementChildForWindow(this._window);
|
|
|
|
if (browserChild) {
|
2013-10-05 01:59:48 +04:00
|
|
|
this.addMessageListeners("Webapps:ClearBrowserData:Return");
|
2014-05-24 23:28:13 +04:00
|
|
|
browserChild.messageManager.sendAsyncMessage("Webapps:ClearBrowserData", {
|
|
|
|
manifestURL: this.manifestURL,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2014-05-24 23:28:13 +04:00
|
|
|
requestID: this.getRequestId(request)
|
|
|
|
});
|
2013-05-20 21:20:19 +04:00
|
|
|
} else {
|
2013-11-07 15:30:31 +04:00
|
|
|
Services.DOMRequest.fireErrorAsync(request, "NO_CLEARABLE_BROWSER");
|
2012-09-27 02:03:25 +04:00
|
|
|
}
|
2013-05-20 21:20:19 +04:00
|
|
|
return request;
|
2012-09-27 02:03:25 +04:00
|
|
|
},
|
|
|
|
|
2013-07-30 18:03:06 +04:00
|
|
|
connect: function(aKeyword, aRules) {
|
2014-05-24 23:28:13 +04:00
|
|
|
this.addMessageListeners(["Webapps:Connect:Return:OK",
|
|
|
|
"Webapps:Connect:Return:KO"]);
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2015-07-05 15:45:00 +03:00
|
|
|
let from = this._window.location.origin + this._window.location.pathname;
|
2014-05-24 23:28:13 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Connect", {
|
|
|
|
keyword: aKeyword,
|
|
|
|
rules: aRules,
|
|
|
|
manifestURL: this.manifestURL,
|
2015-07-05 15:45:00 +03:00
|
|
|
pubPageURL: from,
|
2014-05-24 23:28:13 +04:00
|
|
|
outerWindowID: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topWindowID: this._topId,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
2014-05-24 23:28:13 +04:00
|
|
|
});
|
2015-08-20 00:53:22 +03:00
|
|
|
});
|
2013-07-30 18:03:06 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getConnections: function() {
|
2014-05-24 23:28:13 +04:00
|
|
|
this.addMessageListeners("Webapps:GetConnections:Return:OK");
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2014-05-24 23:28:13 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetConnections", {
|
|
|
|
manifestURL: this.manifestURL,
|
|
|
|
outerWindowID: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topWindowID: this._topId,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
2014-05-24 23:28:13 +04:00
|
|
|
});
|
2015-08-20 00:53:22 +03:00
|
|
|
});
|
2013-07-30 18:03:06 +04:00
|
|
|
},
|
|
|
|
|
2014-01-17 04:26:26 +04: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,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2014-01-17 04:26:26 +04:00
|
|
|
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,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2014-01-17 04:26:26 +04:00
|
|
|
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,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2014-01-17 04:26:26 +04:00
|
|
|
requestID: this.getRequestId(request) });
|
|
|
|
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-15 09:55:14 +04:00
|
|
|
export: function() {
|
|
|
|
this.addMessageListeners(["Webapps:Export:Return"]);
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2014-10-15 09:55:14 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Export",
|
|
|
|
{ manifestURL: this.manifestURL,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
2014-10-15 09:55:14 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-06 09:43:57 +03:00
|
|
|
getLocalizedValue: function(aProperty, aLang, aEntryPoint) {
|
|
|
|
this.addMessageListeners(["Webapps:GetLocalizedValue:Return"]);
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2015-03-06 09:43:57 +03:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetLocalizedValue",
|
|
|
|
{ manifestURL: this.manifestURL,
|
|
|
|
oid: this._id,
|
|
|
|
topId: this._topId,
|
|
|
|
property: aProperty,
|
|
|
|
lang: aLang,
|
|
|
|
entryPoint: aEntryPoint,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
2015-03-06 09:43:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-08-19 20:30:54 +04:00
|
|
|
_prepareForContent: function() {
|
|
|
|
if (this.__DOM_IMPL__) {
|
|
|
|
return this.__DOM_IMPL__;
|
|
|
|
}
|
|
|
|
return this._window.DOMApplication._create(this._window, this.wrappedJSObject);
|
|
|
|
},
|
|
|
|
|
2012-06-11 22:41:46 +04:00
|
|
|
uninit: function() {
|
2014-05-24 23:28:13 +04:00
|
|
|
WrappedManifestCache.evict(this.manifestURL, this.innerWindowID);
|
2012-06-11 22:41:46 +04:00
|
|
|
},
|
|
|
|
|
2013-10-17 16:47:58 +04:00
|
|
|
_fireEvent: function(aName) {
|
2014-08-19 20:30:54 +04:00
|
|
|
let obj = this._prepareForContent();
|
|
|
|
let event = new this._window.MozApplicationEvent(aName, {
|
|
|
|
application: obj
|
|
|
|
});
|
|
|
|
obj.dispatchEvent(event);
|
2013-10-17 16:47:58 +04:00
|
|
|
},
|
|
|
|
|
2014-05-24 23:28:13 +04:00
|
|
|
_fireRequestResult: function(aMessage, aIsError) {
|
|
|
|
let req;
|
|
|
|
let msg = aMessage.data;
|
|
|
|
req = this.takeRequest(msg.requestID);
|
|
|
|
if (!req) {
|
|
|
|
return;
|
2014-07-28 22:31:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-24 23:28:13 +04:00
|
|
|
aIsError ? Services.DOMRequest.fireError(req, msg.error)
|
|
|
|
: Services.DOMRequest.fireSuccess(req, msg.result);
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
receiveMessage: function(aMessage) {
|
2012-09-27 23:34:41 +04:00
|
|
|
let msg = aMessage.json;
|
2013-08-16 13:49:15 +04:00
|
|
|
let req;
|
|
|
|
if (aMessage.name == "Webapps:Connect:Return:OK" ||
|
2013-08-17 18:40:01 +04:00
|
|
|
aMessage.name == "Webapps:Connect:Return:KO" ||
|
2014-10-15 09:55:14 +04:00
|
|
|
aMessage.name == "Webapps:GetConnections:Return:OK" ||
|
2015-03-06 09:43:57 +03:00
|
|
|
aMessage.name == "Webapps:Export:Return" ||
|
|
|
|
aMessage.name == "Webapps:GetLocalizedValue:Return") {
|
2013-08-16 13:49:15 +04:00
|
|
|
req = this.takePromiseResolver(msg.requestID);
|
|
|
|
} else {
|
|
|
|
req = this.takeRequest(msg.requestID);
|
|
|
|
}
|
2012-12-28 21:57:35 +04:00
|
|
|
|
2014-05-24 23:28:13 +04:00
|
|
|
if (msg.oid !== this._id || !req) {
|
2012-03-06 23:50:58 +04:00
|
|
|
return;
|
2013-10-17 16:47:58 +04:00
|
|
|
}
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
switch (aMessage.name) {
|
2012-09-27 05:01:20 +04:00
|
|
|
case "Webapps:Launch:Return:KO":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners(["Webapps:Launch:Return:OK",
|
|
|
|
"Webapps:Launch:Return:KO"]);
|
2014-10-24 03:40:08 +04:00
|
|
|
Services.DOMRequest.fireError(req, msg.error);
|
2012-09-27 05:01:20 +04:00
|
|
|
break;
|
2013-07-02 05:29:51 +04:00
|
|
|
case "Webapps:Launch:Return:OK":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners(["Webapps:Launch:Return:OK",
|
|
|
|
"Webapps:Launch:Return:KO"]);
|
2013-07-03 21:48:55 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
2013-07-02 05:29:51 +04:00
|
|
|
break;
|
2013-05-20 21:20:19 +04:00
|
|
|
case "Webapps:ClearBrowserData:Return":
|
2013-10-05 01:59:48 +04:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2013-05-20 21:20:19 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, null);
|
|
|
|
break;
|
2013-08-16 13:49:15 +04:00
|
|
|
case "Webapps:Connect:Return:OK":
|
2014-05-24 23:28:13 +04:00
|
|
|
this.removeMessageListeners(["Webapps:Connect:Return:OK",
|
|
|
|
"Webapps:Connect:Return:KO"]);
|
2014-10-03 12:05:51 +04:00
|
|
|
let messagePorts = new this._window.Array();
|
2013-10-17 16:47:58 +04:00
|
|
|
msg.messagePortIDs.forEach((aPortID) => {
|
2013-09-12 18:14:48 +04:00
|
|
|
let port = new this._window.MozInterAppMessagePort(aPortID);
|
2013-08-16 13:49:15 +04:00
|
|
|
messagePorts.push(port);
|
2013-10-17 16:47:58 +04:00
|
|
|
});
|
2013-08-16 13:49:15 +04:00
|
|
|
req.resolve(messagePorts);
|
|
|
|
break;
|
|
|
|
case "Webapps:Connect:Return:KO":
|
2014-05-24 23:28:13 +04:00
|
|
|
this.removeMessageListeners(["Webapps:Connect:Return:OK",
|
|
|
|
"Webapps:Connect:Return:KO"]);
|
2013-08-16 13:49:15 +04:00
|
|
|
req.reject("No connections registered");
|
|
|
|
break;
|
2013-08-17 18:40:01 +04:00
|
|
|
case "Webapps:GetConnections:Return:OK":
|
2014-05-24 23:28:13 +04:00
|
|
|
this.removeMessageListeners(aMessage.name);
|
2014-10-03 12:05:51 +04:00
|
|
|
let connections = new this._window.Array();
|
2013-10-17 16:47:58 +04:00
|
|
|
msg.connections.forEach((aConnection) => {
|
2013-08-17 18:40:01 +04:00
|
|
|
let connection =
|
|
|
|
new this._window.MozInterAppConnection(aConnection.keyword,
|
|
|
|
aConnection.pubAppManifestURL,
|
|
|
|
aConnection.subAppManifestURL);
|
|
|
|
connections.push(connection);
|
2013-10-17 16:47:58 +04:00
|
|
|
});
|
2013-08-17 18:40:01 +04:00
|
|
|
req.resolve(connections);
|
|
|
|
break;
|
2014-01-17 04:26:26 +04:00
|
|
|
case "Webapps:AddReceipt:Return:OK":
|
|
|
|
this.removeMessageListeners(["Webapps:AddReceipt:Return:OK",
|
|
|
|
"Webapps:AddReceipt:Return:KO"]);
|
2014-09-06 03:55:30 +04:00
|
|
|
this.__DOM_IMPL__._clearCachedReceiptsValue();
|
2014-08-19 20:30:54 +04:00
|
|
|
this._proxy.receipts = msg.receipts;
|
2014-01-17 04:26:26 +04: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-06 03:55:30 +04:00
|
|
|
this.__DOM_IMPL__._clearCachedReceiptsValue();
|
2014-08-19 20:30:54 +04:00
|
|
|
this._proxy.receipts = msg.receipts;
|
2014-01-17 04:26:26 +04: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-06 03:55:30 +04:00
|
|
|
this.__DOM_IMPL__._clearCachedReceiptsValue();
|
2014-08-19 20:30:54 +04:00
|
|
|
this._proxy.receipts = msg.receipts;
|
2014-01-17 04:26:26 +04: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 09:55:14 +04: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;
|
2015-03-06 09:43:57 +03:00
|
|
|
case "Webapps:GetLocalizedValue:Return":
|
|
|
|
this.removeMessageListeners(["Webapps:GetLocalizedValue:Return"]);
|
|
|
|
if (msg.success) {
|
|
|
|
req.resolve(msg.value);
|
|
|
|
} else {
|
|
|
|
req.reject(new this._window.DOMError(msg.error || ""));
|
|
|
|
}
|
|
|
|
break;
|
2012-03-06 23:50:58 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-11-29 00:13:26 +04:00
|
|
|
classID: Components.ID("{723ed303-7757-4fb0-b261-4f78b1f6bd22}"),
|
|
|
|
|
2014-08-19 20:30:54 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference])
|
2011-11-29 00:13:26 +04:00
|
|
|
}
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
/**
|
2014-08-19 20:30:54 +04:00
|
|
|
* DOMApplicationsManager object
|
2012-03-06 23:50:58 +04:00
|
|
|
*/
|
2014-08-19 20:30:54 +04:00
|
|
|
function WebappsApplicationMgmt() {
|
|
|
|
this.wrappedJSObject = this;
|
2011-11-29 00:13:26 +04:00
|
|
|
}
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
WebappsApplicationMgmt.prototype = {
|
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
2014-08-19 20:30:54 +04:00
|
|
|
|
2014-11-02 22:04:08 +03:00
|
|
|
init: function(aWindow, aHasFullMgmtPrivilege) {
|
|
|
|
this._window = aWindow;
|
|
|
|
|
2014-08-19 20:30:54 +04:00
|
|
|
this.initDOMRequestHelper(aWindow, ["Webapps:Uninstall:Return:OK",
|
|
|
|
"Webapps:Uninstall:Broadcast:Return:OK",
|
|
|
|
"Webapps:Uninstall:Return:KO",
|
|
|
|
"Webapps:Install:Return:OK",
|
2014-10-15 09:55:14 +04:00
|
|
|
"Webapps:GetNotInstalled:Return:OK",
|
2014-12-19 01:40:41 +03:00
|
|
|
"Webapps:GetIcon:Return",
|
2014-10-15 09:55:14 +04:00
|
|
|
"Webapps:Import:Return",
|
2014-10-24 03:40:08 +04:00
|
|
|
"Webapps:ExtractManifest:Return",
|
|
|
|
"Webapps:SetEnabled:Return"]);
|
2014-08-19 20:30:54 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:RegisterForMessages",
|
|
|
|
{
|
|
|
|
messages: ["Webapps:Install:Return:OK",
|
|
|
|
"Webapps:Uninstall:Return:OK",
|
2014-10-24 03:40:08 +04:00
|
|
|
"Webapps:Uninstall:Broadcast:Return:OK",
|
|
|
|
"Webapps:SetEnabled:Return"]
|
2014-08-19 20:30:54 +04:00
|
|
|
}
|
|
|
|
);
|
2014-11-02 22:04:08 +03:00
|
|
|
|
|
|
|
if (!aHasFullMgmtPrivilege) {
|
|
|
|
this.getNotInstalled = null;
|
|
|
|
this.applyDownload = null;
|
|
|
|
}
|
2014-08-19 20:30:54 +04:00
|
|
|
},
|
2012-03-06 23:50:58 +04:00
|
|
|
|
|
|
|
uninit: function() {
|
2012-10-19 22:17:05 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
|
2013-01-11 16:50:46 +04:00
|
|
|
["Webapps:Install:Return:OK",
|
|
|
|
"Webapps:Uninstall:Return:OK",
|
2014-10-24 03:40:08 +04:00
|
|
|
"Webapps:Uninstall:Broadcast:Return:OK",
|
|
|
|
"Webapps:SetEnabled:Return"]);
|
2011-11-29 00:13:26 +04:00
|
|
|
},
|
|
|
|
|
2012-09-27 05:01:20 +04:00
|
|
|
applyDownload: function(aApp) {
|
2012-09-29 21:57:18 +04:00
|
|
|
if (!aApp.readyToApplyDownload) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-02 22:04:08 +03:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
|
|
|
|
2012-10-30 04:17:47 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:ApplyDownload",
|
2014-11-02 22:04:08 +03:00
|
|
|
{ manifestURL: aApp.manifestURL },
|
|
|
|
null, principal);
|
2012-09-27 05:01:20 +04:00
|
|
|
},
|
|
|
|
|
2013-01-11 16:50:46 +04:00
|
|
|
uninstall: function(aApp) {
|
|
|
|
let request = this.createRequest();
|
2014-11-02 22:04:08 +03:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
2014-06-12 01:23:18 +04:00
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("Webapps:Uninstall", {
|
|
|
|
origin: aApp.origin,
|
|
|
|
manifestURL: aApp.manifestURL,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2014-06-12 01:23:18 +04:00
|
|
|
from: this._window.location.href,
|
|
|
|
windowId: this._windowId,
|
|
|
|
requestID: this.getRequestId(request)
|
2014-11-02 22:04:08 +03:00
|
|
|
}, null, principal);
|
|
|
|
|
2013-01-11 16:50:46 +04:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
getAll: function() {
|
|
|
|
let request = this.createRequest();
|
2014-07-07 22:01:30 +04:00
|
|
|
let window = this._window;
|
|
|
|
DOMApplicationRegistry.getAll((aApps) => {
|
|
|
|
Services.DOMRequest.fireSuccessAsync(request,
|
|
|
|
convertAppsArray(aApps, window));
|
|
|
|
});
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-12-19 01:40:41 +03:00
|
|
|
getIcon: function(aApp, aIconID, aEntryPoint) {
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2014-12-19 01:40:41 +03:00
|
|
|
cpmm.sendAsyncMessage("Webapps:GetIcon", {
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2014-12-19 01:40:41 +03:00
|
|
|
manifestURL: aApp.manifestURL,
|
|
|
|
iconID: aIconID,
|
|
|
|
entryPoint: aEntryPoint,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
2014-12-19 01:40:41 +03:00
|
|
|
});
|
2015-08-20 00:53:22 +03:00
|
|
|
});
|
2014-12-19 01:40:41 +03:00
|
|
|
},
|
|
|
|
|
2012-08-20 21:19:56 +04:00
|
|
|
getNotInstalled: function() {
|
|
|
|
let request = this.createRequest();
|
2014-11-02 22:04:08 +03:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
|
|
|
|
|
|
|
cpmm.sendAsyncMessage("Webapps:GetNotInstalled", {
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2014-11-02 22:04:08 +03:00
|
|
|
requestID: this.getRequestId(request)
|
|
|
|
}, null, principal);
|
|
|
|
|
2012-08-20 21:19:56 +04:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-10-15 09:55:14 +04:00
|
|
|
import: function(aBlob) {
|
2014-11-02 22:04:08 +03:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2014-10-15 09:55:14 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:Import",
|
|
|
|
{ blob: aBlob,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
|
|
|
}, null, principal);
|
2014-10-15 09:55:14 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
extractManifest: function(aBlob) {
|
2014-11-02 22:04:08 +03:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
2015-08-20 00:53:22 +03:00
|
|
|
return this.createPromiseWithId((aResolverId) => {
|
2014-10-15 09:55:14 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:ExtractManifest",
|
|
|
|
{ blob: aBlob,
|
|
|
|
oid: this._id,
|
2015-02-11 20:03:12 +03:00
|
|
|
topId: this._topId,
|
2015-08-20 00:53:22 +03:00
|
|
|
requestID: aResolverId
|
|
|
|
}, null, principal);
|
2014-10-15 09:55:14 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-10-24 03:40:08 +04:00
|
|
|
setEnabled: function(aApp, aValue) {
|
2014-11-02 22:04:08 +03:00
|
|
|
let principal = this._window.document.nodePrincipal;
|
|
|
|
|
2014-10-24 03:40:08 +04:00
|
|
|
cpmm.sendAsyncMessage("Webapps:SetEnabled",
|
|
|
|
{ manifestURL: aApp.manifestURL,
|
2014-11-02 22:04:08 +03:00
|
|
|
enabled: aValue }, null, principal);
|
2014-10-24 03:40:08 +04:00
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
get oninstall() {
|
2014-08-19 20:30:54 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("oninstall");
|
2012-03-06 23:50:58 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get onuninstall() {
|
2014-08-19 20:30:54 +04:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("onuninstall");
|
2012-03-06 23:50:58 +04:00
|
|
|
},
|
|
|
|
|
2014-10-24 03:40:08 +04:00
|
|
|
get onenabledstatechange() {
|
|
|
|
return this.__DOM_IMPL__.getEventHandler("onenabledstatechange");
|
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
set oninstall(aCallback) {
|
2014-08-19 20:30:54 +04:00
|
|
|
this.__DOM_IMPL__.setEventHandler("oninstall", aCallback);
|
2012-03-06 23:50:58 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
set onuninstall(aCallback) {
|
2014-08-19 20:30:54 +04:00
|
|
|
this.__DOM_IMPL__.setEventHandler("onuninstall", aCallback);
|
2012-03-06 23:50:58 +04:00
|
|
|
},
|
|
|
|
|
2014-10-24 03:40:08 +04:00
|
|
|
set onenabledstatechange(aCallback) {
|
|
|
|
this.__DOM_IMPL__.setEventHandler("onenabledstatechange", aCallback);
|
|
|
|
},
|
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
receiveMessage: function(aMessage) {
|
2014-10-15 09:55:14 +04:00
|
|
|
let msg = aMessage.data;
|
|
|
|
let req;
|
2014-10-24 03:40:08 +04:00
|
|
|
|
2014-12-19 01:40:41 +03:00
|
|
|
if (["Webapps:GetIcon:Return",
|
|
|
|
"Webapps:Import:Return",
|
2014-10-15 09:55:14 +04:00
|
|
|
"Webapps:ExtractManifest:Return"]
|
|
|
|
.indexOf(aMessage.name) != -1) {
|
|
|
|
req = this.takePromiseResolver(msg.requestID);
|
|
|
|
} else {
|
|
|
|
req = this.getRequest(msg.requestID);
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:40:08 +04:00
|
|
|
// We want Webapps:Install:Return:OK, Webapps:Uninstall:Broadcast:Return:OK
|
|
|
|
// and Webapps:SetEnabled:Return
|
2013-11-07 15:30:31 +04:00
|
|
|
// to be broadcasted to all instances of mozApps.mgmt.
|
2013-01-11 16:50:46 +04:00
|
|
|
if (!((msg.oid == this._id && req) ||
|
|
|
|
aMessage.name == "Webapps:Install:Return:OK" ||
|
2014-10-24 03:40:08 +04:00
|
|
|
aMessage.name == "Webapps:Uninstall:Broadcast:Return:OK" ||
|
|
|
|
aMessage.name == "Webapps:SetEnabled:Return")) {
|
2012-03-06 23:50:58 +04:00
|
|
|
return;
|
2013-01-11 16:50:46 +04:00
|
|
|
}
|
2014-10-15 09:55:14 +04:00
|
|
|
|
2012-03-06 23:50:58 +04:00
|
|
|
switch (aMessage.name) {
|
2012-08-20 21:19:56 +04:00
|
|
|
case "Webapps:GetNotInstalled:Return:OK":
|
|
|
|
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
|
|
|
|
break;
|
2012-03-06 23:50:58 +04:00
|
|
|
case "Webapps:Install:Return:OK":
|
2014-08-19 20:30:54 +04: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 23:50:58 +04:00
|
|
|
}
|
|
|
|
break;
|
2013-01-11 16:50:46 +04:00
|
|
|
case "Webapps:Uninstall:Broadcast:Return:OK":
|
2014-08-19 20:30:54 +04:00
|
|
|
{
|
2014-08-20 23:27:32 +04:00
|
|
|
let app = createContentApplicationObject(this._window, msg);
|
2014-08-19 20:30:54 +04:00
|
|
|
let event =
|
|
|
|
new this._window.MozApplicationEvent("uninstall", { application : app });
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
2012-03-06 23:50:58 +04:00
|
|
|
}
|
|
|
|
break;
|
2013-01-11 16:50:46 +04:00
|
|
|
case "Webapps:Uninstall:Return:OK":
|
2014-07-23 00:08:21 +04:00
|
|
|
Services.DOMRequest.fireSuccess(req, msg.manifestURL);
|
2013-01-11 16:50:46 +04:00
|
|
|
break;
|
|
|
|
case "Webapps:Uninstall:Return:KO":
|
|
|
|
Services.DOMRequest.fireError(req, "NOT_INSTALLED");
|
|
|
|
break;
|
2014-10-15 09:55:14 +04: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-24 03:40:08 +04: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;
|
2014-12-19 01:40:41 +03:00
|
|
|
case "Webapps:GetIcon:Return":
|
|
|
|
if (msg.blob) {
|
|
|
|
req.resolve(Cu.cloneInto(msg.blob, this._window));
|
|
|
|
} else if (msg.error && msg.error == "NETWORK_ERROR"
|
|
|
|
&& !this._window.navigator.onLine) {
|
|
|
|
req.reject(new this._window.DOMError("NETWORK_OFFLINE"));
|
|
|
|
} else {
|
|
|
|
req.reject(new this._window.DOMError(msg.error || ""));
|
|
|
|
}
|
|
|
|
break;
|
2013-01-11 16:50:46 +04:00
|
|
|
}
|
2014-12-19 01:40:41 +03:00
|
|
|
|
2013-01-11 16:50:46 +04:00
|
|
|
if (aMessage.name !== "Webapps:Uninstall:Broadcast:Return:OK") {
|
|
|
|
this.removeRequest(msg.requestID);
|
2012-03-06 23:50:58 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{8c1bca96-266f-493a-8d57-ec7a95098c15}"),
|
|
|
|
|
2014-08-19 20:30:54 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference])
|
2012-03-06 23:50:58 +04:00
|
|
|
}
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsRegistry,
|
2014-08-19 20:30:54 +04:00
|
|
|
WebappsApplicationMgmt,
|
2013-05-18 21:52:06 +04:00
|
|
|
WebappsApplication]);
|