dom/datastore/DataStoreServiceInternal.jsm
author Trevor Saunders <trev.saunders@gmail.com>
Fri, 22 Nov 2013 14:45:50 -0500
changeset 157184 93370e83103200b4943cc450166a379a403a7ff2
parent 154272 db2f368bf99991579f65e7494280d363d526ad90
child 157551 ccb70d9cf9256b0d916c271972f7dba0c03fc81a
permissions -rw-r--r--
bug 938025 - part 1 - get rid of some static constructors r=bz r=bjacob

/* 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"

const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;

this.EXPORTED_SYMBOLS = ["DataStoreServiceInternal"];

function debug(s) {
  // dump('DEBUG DataStoreServiceInternal: ' + s + '\n');
}

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                   "@mozilla.org/parentprocessmessagemanager;1",
                                   "nsIMessageBroadcaster");

XPCOMUtils.defineLazyServiceGetter(this, "dataStoreService",
                                   "@mozilla.org/datastore-service;1",
                                   "nsIDataStoreService");

this.DataStoreServiceInternal = {
  init: function() {
    debug("init");

    let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
                      .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
    if (inParent) {
      ppmm.addMessageListener("DataStore:Get", this);
    }
  },

  receiveMessage: function(aMessage) {
    debug("receiveMessage");

    if (aMessage.name != 'DataStore:Get') {
      return;
    }

    let msg = aMessage.data;

    // This is a security issue and it will be fixed by Bug 916091
    msg.stores = dataStoreService.getDataStoresInfo(msg.name, msg.appId);
    aMessage.target.sendAsyncMessage("DataStore:Get:Return", msg);
  }
}

DataStoreServiceInternal.init();