dom/datastore/DataStoreServiceInternal.jsm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
     9 this.EXPORTED_SYMBOLS = ["DataStoreServiceInternal"];
    11 function debug(s) {
    12   //dump('DEBUG DataStoreServiceInternal: ' + s + '\n');
    13 }
    15 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    16 Cu.import("resource://gre/modules/Services.jsm");
    18 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
    19                                    "@mozilla.org/parentprocessmessagemanager;1",
    20                                    "nsIMessageBroadcaster");
    22 XPCOMUtils.defineLazyServiceGetter(this, "dataStoreService",
    23                                    "@mozilla.org/datastore-service;1",
    24                                    "nsIDataStoreService");
    26 this.DataStoreServiceInternal = {
    27   init: function() {
    28     debug("init");
    30     let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
    31                       .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
    32     if (inParent) {
    33       ppmm.addMessageListener("DataStore:Get", this);
    34     }
    35   },
    37   receiveMessage: function(aMessage) {
    38     debug("receiveMessage");
    40     if (aMessage.name != 'DataStore:Get') {
    41       return;
    42     }
    44     let prefName = 'dom.testing.datastore_enabled_for_hosted_apps';
    45     if ((Services.prefs.getPrefType(prefName) == Services.prefs.PREF_INVALID ||
    46          !Services.prefs.getBoolPref(prefName)) &&
    47         !aMessage.target.assertAppHasStatus(Ci.nsIPrincipal.APP_STATUS_CERTIFIED)) {
    48       return;
    49     }
    51     let msg = aMessage.data;
    53     if (!aMessage.principal ||
    54         aMessage.principal.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) {
    55       aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO");
    56       return;
    57     }
    59     msg.stores = dataStoreService.getDataStoresInfo(msg.name, aMessage.principal.appId);
    60     if (msg.stores === null) {
    61       aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO");
    62       return;
    63     }
    64     aMessage.target.sendAsyncMessage("DataStore:Get:Return:OK", msg);
    65   }
    66 }
    68 DataStoreServiceInternal.init();

mercurial