2012-05-16 10:40:47 +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/. */
|
|
|
|
|
|
|
|
"use strict"
|
|
|
|
|
|
|
|
function debug(s) {
|
2012-08-28 02:43:57 +00:00
|
|
|
//dump("-*- AppsService.js: " + s + "\n");
|
2012-05-16 10:40:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 16:30:38 +00:00
|
|
|
const Cc = Components.classes;
|
2012-05-16 10:40:47 +00:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
2015-08-27 01:40:05 +00:00
|
|
|
const Cr = Components.results;
|
2012-05-16 10:40:47 +00:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-05-14 19:00:09 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2014-05-01 09:23:00 +00:00
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2015-08-27 01:40:05 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UserCustomizations",
|
|
|
|
"resource://gre/modules/UserCustomizations.jsm");
|
2012-05-16 10:40:47 +00:00
|
|
|
|
2012-07-26 16:30:38 +00:00
|
|
|
const APPS_SERVICE_CID = Components.ID("{05072afa-92fe-45bf-ae22-39b69c117058}");
|
2012-05-16 10:40:47 +00:00
|
|
|
|
|
|
|
function AppsService()
|
|
|
|
{
|
|
|
|
debug("AppsService Constructor");
|
2014-05-01 09:23:00 +00:00
|
|
|
this.inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
|
|
|
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
|
|
debug("inParent: " + this.inParent);
|
|
|
|
Cu.import(this.inParent ? "resource://gre/modules/Webapps.jsm" :
|
|
|
|
"resource://gre/modules/AppsServiceChild.jsm");
|
2012-05-16 10:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AppsService.prototype = {
|
2012-10-19 10:43:17 +00:00
|
|
|
|
2015-04-08 19:59:35 +00:00
|
|
|
isInvalidId: function(localId) {
|
|
|
|
return (localId == Ci.nsIScriptSecurityManager.NO_APP_ID ||
|
|
|
|
localId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
|
|
|
|
},
|
|
|
|
|
2014-09-16 20:14:02 +00:00
|
|
|
getManifestCSPByLocalId: function getCSPByLocalId(localId) {
|
|
|
|
debug("GetManifestCSPByLocalId( " + localId + " )");
|
2015-04-08 19:59:35 +00:00
|
|
|
if (this.isInvalidId(localId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-16 20:14:02 +00:00
|
|
|
return DOMApplicationRegistry.getManifestCSPByLocalId(localId);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultCSPByLocalId: function getCSPByLocalId(localId) {
|
|
|
|
debug("GetDefaultCSPByLocalId( " + localId + " )");
|
2015-04-08 19:59:35 +00:00
|
|
|
if (this.isInvalidId(localId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-16 20:14:02 +00:00
|
|
|
return DOMApplicationRegistry.getDefaultCSPByLocalId(localId);
|
2012-10-19 10:43:17 +00:00
|
|
|
},
|
|
|
|
|
2012-05-16 10:40:47 +00:00
|
|
|
getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
|
|
|
|
debug("GetAppByManifestURL( " + aManifestURL + " )");
|
2012-08-28 02:43:57 +00:00
|
|
|
return DOMApplicationRegistry.getAppByManifestURL(aManifestURL);
|
2012-05-16 10:40:47 +00:00
|
|
|
},
|
|
|
|
|
2014-05-01 09:23:00 +00:00
|
|
|
getManifestFor: function getManifestFor(aManifestURL) {
|
|
|
|
debug("getManifestFor(" + aManifestURL + ")");
|
|
|
|
if (this.inParent) {
|
|
|
|
return DOMApplicationRegistry.getManifestFor(aManifestURL);
|
|
|
|
} else {
|
|
|
|
return Promise.reject(
|
|
|
|
new Error("Calling getManifestFor() from child is not supported"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-07-09 10:25:41 +00:00
|
|
|
getAppLocalIdByManifestURL: function getAppLocalIdByManifestURL(aManifestURL) {
|
|
|
|
debug("getAppLocalIdByManifestURL( " + aManifestURL + " )");
|
2012-08-28 02:43:57 +00:00
|
|
|
return DOMApplicationRegistry.getAppLocalIdByManifestURL(aManifestURL);
|
2012-07-09 10:25:41 +00:00
|
|
|
},
|
|
|
|
|
2013-01-25 09:57:14 +00:00
|
|
|
getAppLocalIdByStoreId: function getAppLocalIdByStoreId(aStoreId) {
|
|
|
|
debug("getAppLocalIdByStoreId( " + aStoreId + " )");
|
|
|
|
return DOMApplicationRegistry.getAppLocalIdByStoreId(aStoreId);
|
|
|
|
},
|
|
|
|
|
2012-08-08 16:41:47 +00:00
|
|
|
getAppByLocalId: function getAppByLocalId(aLocalId) {
|
|
|
|
debug("getAppByLocalId( " + aLocalId + " )");
|
2015-04-08 19:59:35 +00:00
|
|
|
if (this.isInvalidId(aLocalId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-08-28 02:43:57 +00:00
|
|
|
return DOMApplicationRegistry.getAppByLocalId(aLocalId);
|
2012-08-08 16:41:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getManifestURLByLocalId: function getManifestURLByLocalId(aLocalId) {
|
|
|
|
debug("getManifestURLByLocalId( " + aLocalId + " )");
|
2015-04-08 19:59:35 +00:00
|
|
|
if (this.isInvalidId(aLocalId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-08-28 02:43:57 +00:00
|
|
|
return DOMApplicationRegistry.getManifestURLByLocalId(aLocalId);
|
2012-08-08 16:41:47 +00:00
|
|
|
},
|
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
getCoreAppsBasePath: function getCoreAppsBasePath() {
|
|
|
|
debug("getCoreAppsBasePath()");
|
|
|
|
return DOMApplicationRegistry.getCoreAppsBasePath();
|
|
|
|
},
|
|
|
|
|
|
|
|
getWebAppsBasePath: function getWebAppsBasePath() {
|
|
|
|
debug("getWebAppsBasePath()");
|
|
|
|
return DOMApplicationRegistry.getWebAppsBasePath();
|
|
|
|
},
|
|
|
|
|
2016-02-18 04:57:41 +00:00
|
|
|
areAnyAppsInstalled: function() {
|
|
|
|
return DOMApplicationRegistry.areAnyAppsInstalled();
|
|
|
|
},
|
|
|
|
|
2013-01-31 21:35:13 +00:00
|
|
|
getAppInfo: function getAppInfo(aAppId) {
|
|
|
|
debug("getAppInfo()");
|
|
|
|
return DOMApplicationRegistry.getAppInfo(aAppId);
|
|
|
|
},
|
|
|
|
|
2013-05-14 19:00:09 +00:00
|
|
|
getRedirect: function getRedirect(aLocalId, aURI) {
|
|
|
|
debug("getRedirect for " + aLocalId + " " + aURI.spec);
|
2015-04-08 19:59:35 +00:00
|
|
|
if (this.isInvalidId(aLocalId)) {
|
2013-05-14 19:00:09 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let app = DOMApplicationRegistry.getAppByLocalId(aLocalId);
|
|
|
|
if (app && app.redirects) {
|
|
|
|
let spec = aURI.spec;
|
|
|
|
for (let i = 0; i < app.redirects.length; i++) {
|
|
|
|
let redirect = app.redirects[i];
|
|
|
|
if (spec.startsWith(redirect.from)) {
|
|
|
|
// Prepend the app origin to the redirection. We need that since
|
|
|
|
// the origin of packaged apps is a uuid created at install time.
|
|
|
|
let to = app.origin + redirect.to;
|
|
|
|
// If we have a ? or a # in the current URL, add this part to the
|
|
|
|
// redirection.
|
|
|
|
let index = -1;
|
|
|
|
index = spec.indexOf('?');
|
|
|
|
if (index == -1) {
|
|
|
|
index = spec.indexOf('#');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
to += spec.substring(index);
|
|
|
|
}
|
|
|
|
debug('App specific redirection from ' + spec + ' to ' + to);
|
|
|
|
return Services.io.newURI(to, null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 17:15:37 +00:00
|
|
|
// No matching redirect.
|
|
|
|
return null;
|
2013-05-14 19:00:09 +00:00
|
|
|
},
|
|
|
|
|
2015-04-17 01:15:18 +00:00
|
|
|
getScopeByLocalId: function(aLocalId) {
|
|
|
|
debug("getScopeByLocalId( " + aLocalId + " )");
|
|
|
|
if (this.isInvalidId(aLocalId)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// TODO : implement properly!
|
|
|
|
// We just return null for now to not break PushService.jsm
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2015-08-27 01:40:05 +00:00
|
|
|
isExtensionResource: function(aURI) {
|
|
|
|
// This is only expected to be used by NeckoParent, and will not work
|
|
|
|
// properly in child processes.
|
|
|
|
if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
|
|
|
|
throw Cr.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UserCustomizations.isFromExtension(aURI);
|
|
|
|
},
|
|
|
|
|
2015-09-18 05:49:24 +00:00
|
|
|
updateDataStoreEntriesFromLocalId: function(aLocalId) {
|
|
|
|
return DOMApplicationRegistry.updateDataStoreEntriesFromLocalId(aLocalId);
|
|
|
|
},
|
|
|
|
|
2012-05-16 10:40:47 +00:00
|
|
|
classID : APPS_SERVICE_CID,
|
2012-07-26 16:30:38 +00:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService])
|
2012-05-16 10:40:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AppsService])
|