2012-05-16 14:40:47 +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/. */
|
|
|
|
|
|
|
|
"use strict"
|
|
|
|
|
|
|
|
function debug(s) {
|
2012-08-28 06:43:57 +04:00
|
|
|
//dump("-*- AppsService.js: " + s + "\n");
|
2012-05-16 14:40:47 +04:00
|
|
|
}
|
|
|
|
|
2012-07-26 20:30:38 +04:00
|
|
|
const Cc = Components.classes;
|
2012-05-16 14:40:47 +04:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
2015-08-27 04:40:05 +03:00
|
|
|
const Cr = Components.results;
|
2012-05-16 14:40:47 +04:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-05-14 23:00:09 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2014-05-01 13:23:00 +04:00
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2015-08-27 04:40:05 +03:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UserCustomizations",
|
|
|
|
"resource://gre/modules/UserCustomizations.jsm");
|
2012-05-16 14:40:47 +04:00
|
|
|
|
2012-07-26 20:30:38 +04:00
|
|
|
const APPS_SERVICE_CID = Components.ID("{05072afa-92fe-45bf-ae22-39b69c117058}");
|
2012-05-16 14:40:47 +04:00
|
|
|
|
|
|
|
function AppsService()
|
|
|
|
{
|
|
|
|
debug("AppsService Constructor");
|
2014-05-01 13:23:00 +04: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 14:40:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
AppsService.prototype = {
|
2012-10-19 14:43:17 +04:00
|
|
|
|
2015-04-08 22:59:35 +03:00
|
|
|
isInvalidId: function(localId) {
|
|
|
|
return (localId == Ci.nsIScriptSecurityManager.NO_APP_ID ||
|
|
|
|
localId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
|
|
|
|
},
|
|
|
|
|
2014-09-17 00:14:02 +04:00
|
|
|
getManifestCSPByLocalId: function getCSPByLocalId(localId) {
|
|
|
|
debug("GetManifestCSPByLocalId( " + localId + " )");
|
2015-04-08 22:59:35 +03:00
|
|
|
if (this.isInvalidId(localId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-17 00:14:02 +04:00
|
|
|
return DOMApplicationRegistry.getManifestCSPByLocalId(localId);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultCSPByLocalId: function getCSPByLocalId(localId) {
|
|
|
|
debug("GetDefaultCSPByLocalId( " + localId + " )");
|
2015-04-08 22:59:35 +03:00
|
|
|
if (this.isInvalidId(localId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-17 00:14:02 +04:00
|
|
|
return DOMApplicationRegistry.getDefaultCSPByLocalId(localId);
|
2012-10-19 14:43:17 +04:00
|
|
|
},
|
|
|
|
|
2012-05-16 14:40:47 +04:00
|
|
|
getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
|
|
|
|
debug("GetAppByManifestURL( " + aManifestURL + " )");
|
2012-08-28 06:43:57 +04:00
|
|
|
return DOMApplicationRegistry.getAppByManifestURL(aManifestURL);
|
2012-05-16 14:40:47 +04:00
|
|
|
},
|
|
|
|
|
2014-05-01 13:23:00 +04: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 14:25:41 +04:00
|
|
|
getAppLocalIdByManifestURL: function getAppLocalIdByManifestURL(aManifestURL) {
|
|
|
|
debug("getAppLocalIdByManifestURL( " + aManifestURL + " )");
|
2012-08-28 06:43:57 +04:00
|
|
|
return DOMApplicationRegistry.getAppLocalIdByManifestURL(aManifestURL);
|
2012-07-09 14:25:41 +04:00
|
|
|
},
|
|
|
|
|
2013-01-25 13:57:14 +04:00
|
|
|
getAppLocalIdByStoreId: function getAppLocalIdByStoreId(aStoreId) {
|
|
|
|
debug("getAppLocalIdByStoreId( " + aStoreId + " )");
|
|
|
|
return DOMApplicationRegistry.getAppLocalIdByStoreId(aStoreId);
|
|
|
|
},
|
|
|
|
|
2012-08-08 20:41:47 +04:00
|
|
|
getAppByLocalId: function getAppByLocalId(aLocalId) {
|
|
|
|
debug("getAppByLocalId( " + aLocalId + " )");
|
2015-04-08 22:59:35 +03:00
|
|
|
if (this.isInvalidId(aLocalId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-08-28 06:43:57 +04:00
|
|
|
return DOMApplicationRegistry.getAppByLocalId(aLocalId);
|
2012-08-08 20:41:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getManifestURLByLocalId: function getManifestURLByLocalId(aLocalId) {
|
|
|
|
debug("getManifestURLByLocalId( " + aLocalId + " )");
|
2015-04-08 22:59:35 +03:00
|
|
|
if (this.isInvalidId(aLocalId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-08-28 06:43:57 +04:00
|
|
|
return DOMApplicationRegistry.getManifestURLByLocalId(aLocalId);
|
2012-08-08 20:41:47 +04:00
|
|
|
},
|
|
|
|
|
2012-12-22 17:56:21 +04:00
|
|
|
getCoreAppsBasePath: function getCoreAppsBasePath() {
|
|
|
|
debug("getCoreAppsBasePath()");
|
|
|
|
return DOMApplicationRegistry.getCoreAppsBasePath();
|
|
|
|
},
|
|
|
|
|
|
|
|
getWebAppsBasePath: function getWebAppsBasePath() {
|
|
|
|
debug("getWebAppsBasePath()");
|
|
|
|
return DOMApplicationRegistry.getWebAppsBasePath();
|
|
|
|
},
|
|
|
|
|
2016-02-18 07:57:41 +03:00
|
|
|
areAnyAppsInstalled: function() {
|
|
|
|
return DOMApplicationRegistry.areAnyAppsInstalled();
|
|
|
|
},
|
|
|
|
|
2013-02-01 01:35:13 +04:00
|
|
|
getAppInfo: function getAppInfo(aAppId) {
|
|
|
|
debug("getAppInfo()");
|
|
|
|
return DOMApplicationRegistry.getAppInfo(aAppId);
|
|
|
|
},
|
|
|
|
|
2013-05-14 23:00:09 +04:00
|
|
|
getRedirect: function getRedirect(aLocalId, aURI) {
|
|
|
|
debug("getRedirect for " + aLocalId + " " + aURI.spec);
|
2015-04-08 22:59:35 +03:00
|
|
|
if (this.isInvalidId(aLocalId)) {
|
2013-05-14 23:00:09 +04: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 21:15:37 +04:00
|
|
|
// No matching redirect.
|
|
|
|
return null;
|
2013-05-14 23:00:09 +04:00
|
|
|
},
|
|
|
|
|
2015-04-17 04:15:18 +03: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 04:40:05 +03: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 08:49:24 +03:00
|
|
|
updateDataStoreEntriesFromLocalId: function(aLocalId) {
|
|
|
|
return DOMApplicationRegistry.updateDataStoreEntriesFromLocalId(aLocalId);
|
|
|
|
},
|
|
|
|
|
2012-05-16 14:40:47 +04:00
|
|
|
classID : APPS_SERVICE_CID,
|
2012-07-26 20:30:38 +04:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService])
|
2012-05-16 14:40:47 +04:00
|
|
|
}
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AppsService])
|