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;
|
|
|
|
|
|
|
|
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");
|
2014-12-17 02:32:28 +03:00
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("dom.apps.customization.enabled")) {
|
|
|
|
Cu.import("resource://gre/modules/UserCustomizations.jsm");
|
|
|
|
}
|
|
|
|
} catch(e) {}
|
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
|
|
|
|
2014-09-17 00:14:02 +04:00
|
|
|
getManifestCSPByLocalId: function getCSPByLocalId(localId) {
|
|
|
|
debug("GetManifestCSPByLocalId( " + localId + " )");
|
|
|
|
return DOMApplicationRegistry.getManifestCSPByLocalId(localId);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultCSPByLocalId: function getCSPByLocalId(localId) {
|
|
|
|
debug("GetDefaultCSPByLocalId( " + localId + " )");
|
|
|
|
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 + " )");
|
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 + " )");
|
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();
|
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
if (aLocalId == Ci.nsIScriptSecurityManager.NO_APP_ID ||
|
|
|
|
aLocalId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) {
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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])
|