dom/apps/src/AppsService.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict"
michael@0 6
michael@0 7 function debug(s) {
michael@0 8 //dump("-*- AppsService.js: " + s + "\n");
michael@0 9 }
michael@0 10
michael@0 11 const Cc = Components.classes;
michael@0 12 const Ci = Components.interfaces;
michael@0 13 const Cu = Components.utils;
michael@0 14
michael@0 15 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 16 Cu.import("resource://gre/modules/Services.jsm");
michael@0 17
michael@0 18 const APPS_SERVICE_CID = Components.ID("{05072afa-92fe-45bf-ae22-39b69c117058}");
michael@0 19
michael@0 20 function AppsService()
michael@0 21 {
michael@0 22 debug("AppsService Constructor");
michael@0 23 let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
michael@0 24 .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
michael@0 25 debug("inParent: " + inParent);
michael@0 26 Cu.import(inParent ? "resource://gre/modules/Webapps.jsm" :
michael@0 27 "resource://gre/modules/AppsServiceChild.jsm");
michael@0 28 }
michael@0 29
michael@0 30 AppsService.prototype = {
michael@0 31
michael@0 32 getCSPByLocalId: function getCSPByLocalId(localId) {
michael@0 33 debug("GetCSPByLocalId( " + localId + " )");
michael@0 34 return DOMApplicationRegistry.getCSPByLocalId(localId);
michael@0 35 },
michael@0 36
michael@0 37 getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
michael@0 38 debug("GetAppByManifestURL( " + aManifestURL + " )");
michael@0 39 return DOMApplicationRegistry.getAppByManifestURL(aManifestURL);
michael@0 40 },
michael@0 41
michael@0 42 getAppLocalIdByManifestURL: function getAppLocalIdByManifestURL(aManifestURL) {
michael@0 43 debug("getAppLocalIdByManifestURL( " + aManifestURL + " )");
michael@0 44 return DOMApplicationRegistry.getAppLocalIdByManifestURL(aManifestURL);
michael@0 45 },
michael@0 46
michael@0 47 getAppLocalIdByStoreId: function getAppLocalIdByStoreId(aStoreId) {
michael@0 48 debug("getAppLocalIdByStoreId( " + aStoreId + " )");
michael@0 49 return DOMApplicationRegistry.getAppLocalIdByStoreId(aStoreId);
michael@0 50 },
michael@0 51
michael@0 52 getAppByLocalId: function getAppByLocalId(aLocalId) {
michael@0 53 debug("getAppByLocalId( " + aLocalId + " )");
michael@0 54 return DOMApplicationRegistry.getAppByLocalId(aLocalId);
michael@0 55 },
michael@0 56
michael@0 57 getManifestURLByLocalId: function getManifestURLByLocalId(aLocalId) {
michael@0 58 debug("getManifestURLByLocalId( " + aLocalId + " )");
michael@0 59 return DOMApplicationRegistry.getManifestURLByLocalId(aLocalId);
michael@0 60 },
michael@0 61
michael@0 62 getCoreAppsBasePath: function getCoreAppsBasePath() {
michael@0 63 debug("getCoreAppsBasePath()");
michael@0 64 return DOMApplicationRegistry.getCoreAppsBasePath();
michael@0 65 },
michael@0 66
michael@0 67 getWebAppsBasePath: function getWebAppsBasePath() {
michael@0 68 debug("getWebAppsBasePath()");
michael@0 69 return DOMApplicationRegistry.getWebAppsBasePath();
michael@0 70 },
michael@0 71
michael@0 72 getAppInfo: function getAppInfo(aAppId) {
michael@0 73 debug("getAppInfo()");
michael@0 74 return DOMApplicationRegistry.getAppInfo(aAppId);
michael@0 75 },
michael@0 76
michael@0 77 getRedirect: function getRedirect(aLocalId, aURI) {
michael@0 78 debug("getRedirect for " + aLocalId + " " + aURI.spec);
michael@0 79 if (aLocalId == Ci.nsIScriptSecurityManager.NO_APP_ID ||
michael@0 80 aLocalId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) {
michael@0 81 return null;
michael@0 82 }
michael@0 83
michael@0 84 let app = DOMApplicationRegistry.getAppByLocalId(aLocalId);
michael@0 85 if (app && app.redirects) {
michael@0 86 let spec = aURI.spec;
michael@0 87 for (let i = 0; i < app.redirects.length; i++) {
michael@0 88 let redirect = app.redirects[i];
michael@0 89 if (spec.startsWith(redirect.from)) {
michael@0 90 // Prepend the app origin to the redirection. We need that since
michael@0 91 // the origin of packaged apps is a uuid created at install time.
michael@0 92 let to = app.origin + redirect.to;
michael@0 93 // If we have a ? or a # in the current URL, add this part to the
michael@0 94 // redirection.
michael@0 95 let index = -1;
michael@0 96 index = spec.indexOf('?');
michael@0 97 if (index == -1) {
michael@0 98 index = spec.indexOf('#');
michael@0 99 }
michael@0 100
michael@0 101 if (index != -1) {
michael@0 102 to += spec.substring(index);
michael@0 103 }
michael@0 104 debug('App specific redirection from ' + spec + ' to ' + to);
michael@0 105 return Services.io.newURI(to, null, null);
michael@0 106 }
michael@0 107 }
michael@0 108 }
michael@0 109 // No matching redirect.
michael@0 110 return null;
michael@0 111 },
michael@0 112
michael@0 113 classID : APPS_SERVICE_CID,
michael@0 114 QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService])
michael@0 115 }
michael@0 116
michael@0 117 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AppsService])

mercurial