dom/apps/src/AppsServiceChild.jsm

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.

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 const Cu = Components.utils;
michael@0 8 const Cc = Components.classes;
michael@0 9 const Ci = Components.interfaces;
michael@0 10
michael@0 11 // This module exposes a subset of the functionnalities of the parent DOM
michael@0 12 // Registry to content processes, to be be used from the AppsService component.
michael@0 13
michael@0 14 this.EXPORTED_SYMBOLS = ["DOMApplicationRegistry"];
michael@0 15
michael@0 16 Cu.import("resource://gre/modules/AppsUtils.jsm");
michael@0 17 Cu.import("resource://gre/modules/Services.jsm");
michael@0 18
michael@0 19 function debug(s) {
michael@0 20 //dump("-*- AppsServiceChild.jsm: " + s + "\n");
michael@0 21 }
michael@0 22
michael@0 23 this.DOMApplicationRegistry = {
michael@0 24 init: function init() {
michael@0 25 debug("init");
michael@0 26 this.cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
michael@0 27 .getService(Ci.nsISyncMessageSender);
michael@0 28
michael@0 29 ["Webapps:AddApp", "Webapps:RemoveApp"].forEach((function(aMsgName) {
michael@0 30 this.cpmm.addMessageListener(aMsgName, this);
michael@0 31 }).bind(this));
michael@0 32
michael@0 33 // We need to prime the cache with the list of apps.
michael@0 34 // XXX shoud we do this async and block callers if it's not yet there?
michael@0 35 this.webapps = this.cpmm.sendSyncMessage("Webapps:GetList", { })[0];
michael@0 36
michael@0 37 // We need a fast mapping from localId -> app, so we add an index.
michael@0 38 this.localIdIndex = { };
michael@0 39 for (let id in this.webapps) {
michael@0 40 let app = this.webapps[id];
michael@0 41 this.localIdIndex[app.localId] = app;
michael@0 42 }
michael@0 43
michael@0 44 Services.obs.addObserver(this, "xpcom-shutdown", false);
michael@0 45 },
michael@0 46
michael@0 47 observe: function(aSubject, aTopic, aData) {
michael@0 48 // cpmm.addMessageListener causes the DOMApplicationRegistry object to live
michael@0 49 // forever if we don't clean up properly.
michael@0 50 this.webapps = null;
michael@0 51 ["Webapps:AddApp", "Webapps:RemoveApp"].forEach((function(aMsgName) {
michael@0 52 this.cpmm.removeMessageListener(aMsgName, this);
michael@0 53 }).bind(this));
michael@0 54 },
michael@0 55
michael@0 56 receiveMessage: function receiveMessage(aMessage) {
michael@0 57 debug("Received " + aMessage.name + " message.");
michael@0 58 let msg = aMessage.json;
michael@0 59 switch (aMessage.name) {
michael@0 60 case "Webapps:AddApp":
michael@0 61 this.webapps[msg.id] = msg.app;
michael@0 62 this.localIdIndex[msg.app.localId] = msg.app;
michael@0 63 break;
michael@0 64 case "Webapps:RemoveApp":
michael@0 65 delete this.localIdIndex[this.webapps[msg.id].localId];
michael@0 66 delete this.webapps[msg.id];
michael@0 67 break;
michael@0 68 }
michael@0 69 },
michael@0 70
michael@0 71 getAppByManifestURL: function getAppByManifestURL(aManifestURL) {
michael@0 72 debug("getAppByManifestURL " + aManifestURL);
michael@0 73 return AppsUtils.getAppByManifestURL(this.webapps, aManifestURL);
michael@0 74 },
michael@0 75
michael@0 76 getAppLocalIdByManifestURL: function getAppLocalIdByManifestURL(aManifestURL) {
michael@0 77 debug("getAppLocalIdByManifestURL " + aManifestURL);
michael@0 78 return AppsUtils.getAppLocalIdByManifestURL(this.webapps, aManifestURL);
michael@0 79 },
michael@0 80
michael@0 81 getCSPByLocalId: function(aLocalId) {
michael@0 82 debug("getCSPByLocalId:" + aLocalId);
michael@0 83 return AppsUtils.getCSPByLocalId(this.webapps, aLocalId);
michael@0 84 },
michael@0 85
michael@0 86 getAppLocalIdByStoreId: function(aStoreId) {
michael@0 87 debug("getAppLocalIdByStoreId:" + aStoreId);
michael@0 88 return AppsUtils.getAppLocalIdByStoreId(this.webapps, aStoreId);
michael@0 89 },
michael@0 90
michael@0 91 getAppByLocalId: function getAppByLocalId(aLocalId) {
michael@0 92 debug("getAppByLocalId " + aLocalId);
michael@0 93 let app = this.localIdIndex[aLocalId];
michael@0 94 if (!app) {
michael@0 95 debug("Ouch, No app!");
michael@0 96 return null;
michael@0 97 }
michael@0 98
michael@0 99 return new mozIApplication(app);
michael@0 100 },
michael@0 101
michael@0 102 getManifestURLByLocalId: function getManifestURLByLocalId(aLocalId) {
michael@0 103 debug("getManifestURLByLocalId " + aLocalId);
michael@0 104 return AppsUtils.getManifestURLByLocalId(this.webapps, aLocalId);
michael@0 105 },
michael@0 106
michael@0 107 getCoreAppsBasePath: function getCoreAppsBasePath() {
michael@0 108 debug("getCoreAppsBasePath() not yet supported on child!");
michael@0 109 return null;
michael@0 110 },
michael@0 111
michael@0 112 getWebAppsBasePath: function getWebAppsBasePath() {
michael@0 113 debug("getWebAppsBasePath() not yet supported on child!");
michael@0 114 return null;
michael@0 115 },
michael@0 116
michael@0 117 getAppInfo: function getAppInfo(aAppId) {
michael@0 118 return AppsUtils.getAppInfo(this.webapps, aAppId);
michael@0 119 }
michael@0 120 }
michael@0 121
michael@0 122 DOMApplicationRegistry.init();

mercurial