dom/datastore/DataStoreServiceInternal.jsm
author Carsten "Tomcat" Book <cbook@mozilla.com>
Sat, 09 Nov 2013 10:06:10 +0100
changeset 154272 db2f368bf99991579f65e7494280d363d526ad90
parent 154250 6da206d64b498094eabf05cb71140023ff843a52
child 157551 ccb70d9cf9256b0d916c271972f7dba0c03fc81a
permissions -rw-r--r--
Backed out changeset 6da206d64b49 (bug 923625) for failing mochitest 3 on b2g ics

/* 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();