dom/apps/src/AppsService.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial