Files
palemoon27/dom/apps/AppsService.js
T
roytam1 c2bcdec5c9 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1261009 - Remove the Data Store API, r=fabrice (b22e580107)
- Bug 1268393 - Some compilation issues in ServiceWorker code, r=ehsan (d9c2f2554b)
- Bug 1209095 - Accept opaqueredirection fetch results if the request redirection type is manual. r=bkelly (6fe92d1368)
- Bug 1267733 P2 Pass ServiceWorkerRegistrationInfo down to CancelChannelRunnable. r=jdm (0ec51f09ef)
- Bug 1267733 P3 Trigger service worker update after failed interception. r=jdm (f89a7998d4)
- Bug 1267733 P4 Add a wpt test that verifies a service worker update can recover from a broken navigation interception. r=jdm (9dc0ce97bd)
- Bug 1267691: Assert on failed attempts to shutdown a thread from itself r=froyd (0cbd1e458c)
- Bug 1180533 - Disable BackgroundHangMonitor on gonk (a2d666e741)
- Bug 1121216 - disable BackgroundHangMonitor for TSan builds; r=jchen (ef15d1016f)
- Bug 1265621 - Use StaticRefPtr in Omnijar.cpp; r=froydnj (81bc32836e)
- Bug 1265621 - Expose outer zip readers in Omnijar::GetReader; r=froydnj (ce3f82929e)
- Bug 1267021 - Use fallible allocation and move semantics for Push events. r=wchen (3a1ae23d8d)
- Bug 1222899 - Handle geolocation-device-events callback. r=kchen (a33bcf4297)
- Bug 1237831 - Update GonkGPSGeolocationProvider.cpp to use B2G-style. r=jst (d389eedf47)
- Bug 1245033 - Build break in dom/system/gonk/GonkGPSGeolocationProvider.cpp:541:126: error: format '%d' expects argument of type 'int', but argument 5 has type 'nsresult'. r=fabrice (ecde789edf)
- Bug 1264287: Convert Wifi to use |UniquePtr|, r=nfroyd (9bad7792bf)
- Bug 1267577 - Move nsRunnable to mozilla::Runnable. r=gsvelto (f58e2161f2)
- Bug 1210370 - Close wpa_supplicant before we shutdown nsIWifiProxyService. r=mrbkap (5cd4dce58f)
- Bug 1218629 - Save audio volume for each device to setting db r=alwu (2f1847dd6f)
- Bug 1249437 - Remove workaround of volume control r=alwu (13cd144a89)
- Bug 1268432: Replace |Task| with |Runnable| in B2G code r=fabrice (bcc768e9cb)
- Bug 1226483 - Add ASSERT check to AudioManager::SelectDeviceFromDevices() r=alwu (446e8f634e)
- Bug 1229234 - Enable audio_is_output_device() on ICS r=alwu (84aae07f23)
- Bug 1267369 - Only generate typelib data for scriptable interfaces; r=khuey (e49b44c9ce)
- Bug 1155969 - Make runtests.py flake8 compliant. r=ted (1de456b206)
- Bug 1266569 - Avoid including the ChromeUtils binding in Base64.h. r=froydnj (7ba39a7687)
2024-08-29 00:00:08 +08:00

178 lines
5.7 KiB
JavaScript

/* 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) {
//dump("-*- AppsService.js: " + s + "\n");
}
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");
Cu.import("resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UserCustomizations",
"resource://gre/modules/UserCustomizations.jsm");
const APPS_SERVICE_CID = Components.ID("{05072afa-92fe-45bf-ae22-39b69c117058}");
function AppsService()
{
debug("AppsService Constructor");
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");
}
AppsService.prototype = {
isInvalidId: function(localId) {
return (localId == Ci.nsIScriptSecurityManager.NO_APP_ID ||
localId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
},
getManifestCSPByLocalId: function getCSPByLocalId(localId) {
debug("GetManifestCSPByLocalId( " + localId + " )");
if (this.isInvalidId(localId)) {
return null;
}
return DOMApplicationRegistry.getManifestCSPByLocalId(localId);
},
getDefaultCSPByLocalId: function getCSPByLocalId(localId) {
debug("GetDefaultCSPByLocalId( " + localId + " )");
if (this.isInvalidId(localId)) {
return null;
}
return DOMApplicationRegistry.getDefaultCSPByLocalId(localId);
},
getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
debug("GetAppByManifestURL( " + aManifestURL + " )");
return DOMApplicationRegistry.getAppByManifestURL(aManifestURL);
},
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"));
}
},
getAppLocalIdByManifestURL: function getAppLocalIdByManifestURL(aManifestURL) {
debug("getAppLocalIdByManifestURL( " + aManifestURL + " )");
return DOMApplicationRegistry.getAppLocalIdByManifestURL(aManifestURL);
},
getAppLocalIdByStoreId: function getAppLocalIdByStoreId(aStoreId) {
debug("getAppLocalIdByStoreId( " + aStoreId + " )");
return DOMApplicationRegistry.getAppLocalIdByStoreId(aStoreId);
},
getAppByLocalId: function getAppByLocalId(aLocalId) {
debug("getAppByLocalId( " + aLocalId + " )");
if (this.isInvalidId(aLocalId)) {
return null;
}
return DOMApplicationRegistry.getAppByLocalId(aLocalId);
},
getManifestURLByLocalId: function getManifestURLByLocalId(aLocalId) {
debug("getManifestURLByLocalId( " + aLocalId + " )");
if (this.isInvalidId(aLocalId)) {
return null;
}
return DOMApplicationRegistry.getManifestURLByLocalId(aLocalId);
},
getCoreAppsBasePath: function getCoreAppsBasePath() {
debug("getCoreAppsBasePath()");
return DOMApplicationRegistry.getCoreAppsBasePath();
},
getWebAppsBasePath: function getWebAppsBasePath() {
debug("getWebAppsBasePath()");
return DOMApplicationRegistry.getWebAppsBasePath();
},
areAnyAppsInstalled: function() {
return DOMApplicationRegistry.areAnyAppsInstalled();
},
getAppInfo: function getAppInfo(aAppId) {
debug("getAppInfo()");
return DOMApplicationRegistry.getAppInfo(aAppId);
},
getRedirect: function getRedirect(aLocalId, aURI) {
debug("getRedirect for " + aLocalId + " " + aURI.spec);
if (this.isInvalidId(aLocalId)) {
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);
}
}
}
// No matching redirect.
return null;
},
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;
},
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);
},
classID : APPS_SERVICE_CID,
QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService])
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AppsService])