dom/datastore/DataStoreServiceInternal.jsm
author Ryan VanderMeulen <ryanvm@gmail.com>
Thu, 05 Dec 2013 11:36:01 -0500
changeset 174623 e805a81f0a1c88dbc61082a155d91b90d277c9d5
parent 174597 9fb6d18116967ac51c8cc943a63fadf7a7d990de
child 174759 49da013f914eb6c6a13432079e68456495828ee6
permissions -rw-r--r--
Backed out changeset 9fb6d1811696 (bug 942639) for B2G mochitest-3 timeouts.

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

    if (!aMessage.principal ||
        aMessage.principal.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) {
      aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO");
      return;
    }

    msg.stores = dataStoreService.getDataStoresInfo(msg.name, aMessage.principal.appId);
    aMessage.target.sendAsyncMessage("DataStore:Get:Return:OK", msg);
  }
}

DataStoreServiceInternal.init();