Example #1
0
  registerActor: method(function (sourceText, fileName, options) {
    const principal = CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")();
    const sandbox = Cu.Sandbox(principal);
    const exports = sandbox.exports = {};
    sandbox.require = require;

    Cu.evalInSandbox(sourceText, sandbox, "1.8", fileName, 1);

    let { prefix, constructor, type } = options;

    if (type.global) {
      DebuggerServer.addGlobalActor({
        constructorName: constructor,
        constructorFun: sandbox[constructor]
      }, prefix);
    }

    if (type.tab) {
      DebuggerServer.addTabActor({
        constructorName: constructor,
        constructorFun: sandbox[constructor]
      }, prefix);
    }

    return ActorActor(this.conn, {
      name: constructor,
      tab: type.tab,
      global: type.global
    });
  }, {
function ContentProcessTargetActor(connection) {
  this.conn = connection;
  this._contextPool = new ActorPool(this.conn);
  this.conn.addActorPool(this._contextPool);
  this.threadActor = null;

  // Use a see-everything debugger
  this.makeDebugger = makeDebugger.bind(null, {
    findDebuggees: dbg => dbg.findAllGlobals(),
    shouldAddNewGlobalAsDebuggee: global => true
  });

  const sandboxPrototype = {
    get tabs() {
      return Array.from(Services.ww.getWindowEnumerator(),
                        win => win.docShell.messageManager);
    },
  };

  // Scope into which the webconsole executes:
  // A sandbox with chrome privileges with a `tabs` getter.
  const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
    .createInstance(Ci.nsIPrincipal);
  const sandbox = Cu.Sandbox(systemPrincipal, {
    sandboxPrototype,
    wantGlobalProperties: ["ChromeUtils"],
  });
  this._consoleScope = sandbox;

  this._workerList = null;
  this._workerTargetActorPool = null;
  this._onWorkerListChanged = this._onWorkerListChanged.bind(this);
}
Example #3
0
			function (aSubject, aData) {
			    let self = this;
			    var aWindow = aSubject.window;
			
			    this.window = XPCNativeWrapper.unwrap(aWindow);
			
			    this.sandbox = Cu.Sandbox(this.window, 
			                              { sandboxPrototype: this.window, wantXrays: false });
			
                this.window.smartcard = scApi.api;
//                this.window.smartcard = cardTerminals;
                
			    // we need a xul window reference for the DOMCryptMethods
//			    this.xulWindow = aWindow.QueryInterface(Ci.nsIDOMWindow)
//			      .QueryInterface(Ci.nsIInterfaceRequestor)
//			      .getInterface(Ci.nsIWebNavigation)
//			      .QueryInterface(Ci.nsIDocShellTreeItem)
//			      .rootTreeItem
//			      .QueryInterface(Ci.nsIInterfaceRequestor)
//			      .getInterface(Ci.nsIDOMWindow)
//			      .QueryInterface(Ci.nsIDOMChromeWindow);
			
//			    crypto.setXULWindow(this.xulWindow);
			
			    
//			    Cu.evalInSandbox("", sandbox);
//			    log("aWindow.smartcard: "+this.sandbox.smartcard);
			    
			},
Example #4
0
exports.get = function(gaiaDir) {
  var rjs = utils.getFile(gaiaDir);
  rjs.append('build');
  rjs.append('r.js');
  var options = {};
  var ruri = Services.io.newFileURI(rjs).spec;

  try {
    options = JSON.parse(utils.getEnv('BUILD_CONFIG'));
  } catch (e) {
    // parsing BUILD_CONFIG error or this env variable is not available.
    // we simply skip this exception here
  }

  var global = Cu.Sandbox(Services.scriptSecurityManager.getSystemPrincipal());
  global.print = function() {
    if(options.VERBOSE === '1') {
      dump(Array.prototype.join.call(arguments, ' ') + '\n');
    }
  };
  global.arguments = [];
  global.requirejsAsLib = true;
  // XXX: Dark matter. Reflect.jsm introduces slowness by instanciating Reflect
  // API in Reflect.jsm scope (call JS_InitReflect on jsm global). For some
  // reasons, most likely wrappers, Reflect API usages from another
  // compartments/global ends up being slower...
  Cu.evalInSandbox('new ' + function sandboxScope() {
    var init = Components.classes['@mozilla.org/jsreflect;1'].createInstance();
    init();
  }, global);

  Services.scriptloader.loadSubScript(ruri, global);
  return global.requirejs;
};
Example #5
0
const FakeCu = function() {
  const sandbox = Cu.Sandbox(systemPrincipal, {wantXrays: false});
  sandbox.toString = function() {
    return "[object BackstagePass]";
  }
  this.sandbox = sandbox;
}
Example #6
0
exports.registerActor = function(sourceText, fileName, options) {
  const principal = CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")();
  const sandbox = Cu.Sandbox(principal);
  const exports = sandbox.exports = {};
  sandbox.require = require;

  Cu.evalInSandbox(sourceText, sandbox, "1.8", fileName, 1);

  let { prefix, constructor, type } = options;

  if (type.global && !DebuggerServer.globalActorFactories.hasOwnProperty(prefix)) {
    DebuggerServer.addGlobalActor({
      constructorName: constructor,
      constructorFun: sandbox[constructor]
    }, prefix);
  }

  if (type.tab && !DebuggerServer.tabActorFactories.hasOwnProperty(prefix)) {
    DebuggerServer.addTabActor({
      constructorName: constructor,
      constructorFun: sandbox[constructor]
    }, prefix);
  }

  // Also register in all child processes in case the current scope
  // is chrome parent process.
  if (!DebuggerServer.isInChildProcess) {
    DebuggerServer.setupInChild({
      module: "devtools/server/actors/utils/actor-registry-utils",
      setupChild: "registerActor",
      args: [sourceText, fileName, options]
    });
  }
}
  _inject: function _inject() {
    var self = this;
    var unsafeWindow = self._window.wrappedJSObject;
    var sandbox = Cu.Sandbox(unsafeWindow);

    function whenMessaged(cb) {
      self._sendToContent = XPCSafeJSObjectWrapper(cb);
    };
    sandbox.importFunction(whenMessaged);

    function sendToChrome(data) {
      if (self._receivedFromContent) {
        data = XPCSafeJSObjectWrapper(data);
        var result = self._receivedFromContent.call(undefined,
                                                    JSON.parse(data));
        if (typeof(result) == "object")
          return JSON.stringify(result);
        return result;
      }
      return undefined;
    };
    sandbox.importFunction(sendToChrome);

    sandbox.name = self._manager.name;
    sandbox.window = unsafeWindow;
    self._sandbox = sandbox;
    Cu.evalInSandbox("(" + buildChannelInContent + ")(this);", sandbox);
  },
Example #8
0
 function createSandBox() {
     let win = navigator.browser.contentWindow;
     let sandbox = Cu.Sandbox(win,
         {
             'sandboxName': navigator.browser.currentURI.spec,
             'sandboxPrototype': win,
             'wantXrays': false
         });
     return sandbox;
 }
Example #9
0
defineLazyGetter(exports.modules, "Debugger", () => {
  // addDebuggerToGlobal only allows adding the Debugger object to a global. The
  // this object is not guaranteed to be a global (in particular on B2G, due to
  // compartment sharing), so add the Debugger object to a sandbox instead.
  const sandbox = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")());
  Cu.evalInSandbox(
    "Components.utils.import('resource://gre/modules/jsdebugger.jsm');" +
    "addDebuggerToGlobal(this);",
    sandbox
  );
  return sandbox.Debugger;
});
Example #10
0
defineLazyGetter(exports.modules, "indexedDB", () => {
  // On xpcshell, we can't instantiate indexedDB without crashing
  try {
    let sandbox
      = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
                   {wantGlobalProperties: ["indexedDB"]});
    return sandbox.indexedDB;

  } catch (e) {
    return {};
  }
});
Example #11
0
  eval: function(js) {
    // We have to use a sandbox, as CSP prevent us from using eval on apps...
    const sb = Cu.Sandbox(this.content, { sandboxPrototype: this.content });
    const result = Cu.evalInSandbox(js, sb);

    // Ensure passing only serializable data to RDP
    if (typeof result == "function") {
      return null;
    } else if (typeof result == "object") {
      return JSON.parse(JSON.stringify(result));
    }
    return result;
  },
Example #12
0
/**
 * Make a new sandbox that inherits given `source`'s principals. Source can be
 * URI string, DOMWindow or `null` for system principals.
 */
function sandbox(target, options) {
  options = options || {};
  options.metadata = options.metadata ? options.metadata : {};
  options.metadata.addonID = options.metadata.addonID ?
    options.metadata.addonID : self.id;

  let sandbox = Cu.Sandbox(target || systemPrincipal, options);
  Cu.setSandboxMetadata(sandbox, options.metadata);
  let innerWindowID = options.metadata['inner-window-id']
  if (innerWindowID) {
    addContentGlobal({
      global: sandbox,
      'inner-window-id': innerWindowID
    });
  }
  return sandbox;
}
Example #13
0
function ChildProcessActor(aConnection) {
  this.conn = aConnection;
  this._contextPool = new ActorPool(this.conn);
  this.conn.addActorPool(this._contextPool);
  this.threadActor = null;

  // Use a see-everything debugger
  this.makeDebugger = makeDebugger.bind(null, {
    findDebuggees: dbg => dbg.findAllGlobals(),
    shouldAddNewGlobalAsDebuggee: global => true
  });

  // Scope into which the webconsole executes:
  // An empty sandbox with chrome privileges
  let systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
    .createInstance(Ci.nsIPrincipal);
  let sandbox = Cu.Sandbox(systemPrincipal);
  this._consoleScope = sandbox;
}
Example #14
0
exports.testExceptionsWithEmptyStacksAreLogged = function(assert) {
  // Ensures that our fix to bug 550368 works.
  var sandbox = Cu.Sandbox("http://www.foo.com");
  var excRaised = false;
  try {
    Cu.evalInSandbox("returns 1 + 2;", sandbox, "1.8",
                     "blah.js", 25);
  } catch (e) {
    excRaised = true;
    var stack = traceback.fromException(e);
    assert.equal(stack.length, 1, "stack should have one frame");

    assert.ok(stack[0].fileName, "blah.js", "frame should have filename");
    assert.ok(stack[0].lineNumber, 25, "frame should have line no");
    assert.equal(stack[0].name, null, "frame should have null function name");
  }
  if (!excRaised)
    assert.fail("Exception should have been raised.");
};
Example #15
0
function ContentProcessTargetActor(connection) {
  this.conn = connection;
  this._contextPool = new ActorPool(this.conn);
  this.conn.addActorPool(this._contextPool);
  this.threadActor = null;

  // Use a see-everything debugger
  this.makeDebugger = makeDebugger.bind(null, {
    findDebuggees: dbg => dbg.findAllGlobals(),
    shouldAddNewGlobalAsDebuggee: global => true
  });

  const sandboxPrototype = {
    get tabs() {
      const tabs = [];
      const windowEnumerator = Services.ww.getWindowEnumerator();
      while (windowEnumerator.hasMoreElements()) {
        const window = windowEnumerator.getNext().QueryInterface(Ci.nsIDOMWindow);
        const tabChildGlobal = window.QueryInterface(Ci.nsIInterfaceRequestor)
                                     .getInterface(Ci.nsIDocShell)
                                     .sameTypeRootTreeItem
                                     .QueryInterface(Ci.nsIInterfaceRequestor)
                                     .getInterface(Ci.nsIContentFrameMessageManager);
        tabs.push(tabChildGlobal);
      }
      return tabs;
    },
  };

  // Scope into which the webconsole executes:
  // A sandbox with chrome privileges with a `tabs` getter.
  const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
    .createInstance(Ci.nsIPrincipal);
  const sandbox = Cu.Sandbox(systemPrincipal, {
    sandboxPrototype,
  });
  this._consoleScope = sandbox;

  this._workerList = null;
  this._workerTargetActorPool = null;
  this._onWorkerListChanged = this._onWorkerListChanged.bind(this);
}
exports.registerActorInCurrentProcess = function (sourceText, fileName, options) {
  const principal = CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")();
  const sandbox = Cu.Sandbox(principal);
  sandbox.exports = {};
  sandbox.require = require;

  Cu.evalInSandbox(sourceText, sandbox, "1.8", fileName, 1);

  let { prefix, constructor, type } = options;

  if (type.global && !DebuggerServer.globalActorFactories.hasOwnProperty(prefix)) {
    DebuggerServer.addGlobalActor({
      constructorName: constructor,
      constructorFun: sandbox[constructor]
    }, prefix);
  }

  if (type.tab && !DebuggerServer.tabActorFactories.hasOwnProperty(prefix)) {
    DebuggerServer.addTabActor({
      constructorName: constructor,
      constructorFun: sandbox[constructor]
    }, prefix);
  }
};
Example #17
0
exports.get = function(gaiaDir) {
  var rjs = utils.getFile(gaiaDir);
  rjs.append('build');
  rjs.append('r.js');
  var ruri = Services.io.newFileURI(rjs).spec;

  var global = Cu.Sandbox(Services.scriptSecurityManager.getSystemPrincipal());
  global.print = function() {
    dump(Array.prototype.join.call(arguments, ' ') + '\n');
  };
  global.arguments = [];
  global.requirejsAsLib = true;
  // XXX: Dark matter. Reflect.jsm introduces slowness by instanciating Reflect
  // API in Reflect.jsm scope (call JS_InitReflect on jsm global). For some
  // reasons, most likely wrappers, Reflect API usages from another
  // compartments/global ends up being slower...
  Cu.evalInSandbox('new ' + function sandboxScope() {
    var init = Components.classes['@mozilla.org/jsreflect;1'].createInstance();
    init();
  }, global);

  Services.scriptloader.loadSubScript(ruri, global);
  return global.requirejs;
};
Example #18
0
/**
 * Make a new sandbox that inherits given `source`'s principals. Source can be
 * URI string, DOMWindow or `null` for system principals.
 */
function sandbox(target, options) {
  return Cu.Sandbox(target || systemPrincipal, options || {});
}
Example #19
0
 eval: protocol.method(function (js) {
   // We have to use a sandbox, as CSP prevent us from using eval on apps...
   let sb = Cu.Sandbox(this.content, { sandboxPrototype: this.content });
   return Cu.evalInSandbox(js, sb);
 }, {
Example #20
0
  Node,
  TextDecoder,
  TextEncoder,
  URL,
  XMLHttpRequest,
} = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(), {
  wantGlobalProperties: [
    "atob",
    "btoa",
    "ChromeUtils",
    "CSS",
    "CSSRule",
    "DOMParser",
    "Element",
    "Event",
    "FileReader",
    "FormData",
    "indexedDB",
    "InspectorUtils",
    "Node",
    "TextDecoder",
    "TextEncoder",
    "URL",
    "XMLHttpRequest",
  ]
});

/**
 * Defines a getter on a specified object that will be created upon first use.
 *
 * @param object
defineLazyGetter(globals, "CSS", () => {
  let sandbox
    = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
                 {wantGlobalProperties: ["CSS"]});
  return sandbox.CSS;
});
defineLazyGetter(exports.modules, "URL", () => {
  let sandbox
    = Cu.Sandbox(CC('@mozilla.org/systemprincipal;1', 'nsIPrincipal')(),
                 {wantGlobalProperties: ["URL"]});
  return sandbox.URL;
});
 * pseudo modules that aren't separate files but just dynamically set values.
 *
 * As it does so, the module itself doesn't have access to these globals,
 * nor the pseudo modules. Be careful to avoid loading any other js module as
 * they would also miss them.
 */

const { Cu, CC, Cc, Ci } = require("chrome");
const { Loader } = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
const jsmScope = Cu.import("resource://gre/modules/Services.jsm", {});
const { Services } = jsmScope;
// Steal various globals only available in JSM scope (and not Sandbox one)
const { PromiseDebugging, ChromeUtils, ThreadSafeChromeUtils, HeapSnapshot,
        atob, btoa, Iterator } = jsmScope;
const { URL } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
                           {wantGlobalProperties: ["URL"]});

/**
 * Defines a getter on a specified object that will be created upon first use.
 *
 * @param aObject
 *        The object to define the lazy getter on.
 * @param aName
 *        The name of the getter to define on aObject.
 * @param aLambda
 *        A function that returns what the getter should return.  This will
 *        only ever be called once.
 */
function defineLazyGetter(aObject, aName, aLambda)
{
  Object.defineProperty(aObject, aName, {
defineLazyGetter(exports.modules, "FileReader", () => {
  let sandbox
    = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
                 {wantGlobalProperties: ["FileReader"]});
  return sandbox.FileReader;
});