Permalink
Browse files

Remove E10S abstraction layer.

  • Loading branch information...
Gozala committed Apr 12, 2012
1 parent 6a1a82e commit 55fccbc04ecb6746163e2481d647ced986519c52
@@ -1,46 +0,0 @@
-/* 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/. */
-
-const { jetpackID } = require('@packaging');
-const { when } = require('./unload');
-
-// TODO: Create a bug report and remove this workaround once it's fixed.
-// Only function needs defined in the context of the message manager window
-// can be registered via `addMessageListener`.
-function listener(callee) {
- return function listener() { return callee.apply(this, arguments); };
-}
-function messageListener(scope, callee) {
- return scope ? scope.eval('(' + listener + ')')(callee) : callee
-}
-
-exports.channel = function channel(scope, messageManager, address, raw) {
- address = jetpackID + ':' + address
- return {
- input: function input(next, stop) {
- let listener = messageListener(scope, function onMessage(message) {
- if (false === next(raw ? message : message.json) && listener) {
- messageManager.removeMessageListener(address, listener);
- listener = null;
- }
- });
- messageManager.addMessageListener(address, listener);
-
- // Bug 724433: do not leak `listener` on addon disabling
- when(function () {
- if (listener) {
- messageManager.removeMessageListener(address, listener);
- listener = null;
- }
- });
- },
- output: function output(data) {
- messageManager.sendAsyncMessage(address, data);
- },
- sync: !messageManager.sendSyncMessage ? null : function sync(data) {
- messageManager.sendSyncMessage(address, data);
- }
- };
-};
-
@@ -227,9 +227,7 @@ const Loader = {
return module.exports;
},
- // process.process() will eventually cause a call to main() to be evaluated
- // in the addon's context. This function loads and executes the addon's
- // entry point module.
+ // This function loads and executes the addon's entry point module.
main: function main(id, path) {
try {
let uri = this.uriPrefix + path;
@@ -252,47 +250,6 @@ const Loader = {
throw error;
}
},
-
- // This is the main entry-point: bootstrap.js calls this when the add-on is
- // installed. The order of calls is a bit confusing, but here's what
- // happens (in temporal order):
- // * process.spawn creates a new XUL 'browser' element which will house the
- // main addon code. When e10s is active, this uses a real separate OS
- // process. When e10s is disabled, this element lives in the one original
- // process. Either way, its API is the same.
- // * Grab the channel named "require!" and attach a handler which will load
- // modules (in the chrome process) when requested to by the addon
- // process. This handler uses Loader.require to import the module, then
- // calls the module's .initialize() function to connect a new channel.
- // The remote caller winds up with a channel reference, which they can
- // use to send messages to the newly loaded module. This is for e10s.
- // * After the channel handler is attached, process.process() (invoked by
- // process.spawn()) will use loadScript() to evaluate code in the
- // 'browser' element (which is where the main addon code starts running),
- // to do the following:
- // * create a Loader, initialized with the same manifest and
- // harness-options.json that we've got
- // * invoke it's main() method, with the name and path of the addon's
- // entry module (which comes from linker via harness-options.js, and is
- // usually main.js). That executes main(), above.
- // * main() loads the addon's main.js, which executes all top-level
- // forms. If the module defines an "exports.main=" function, we invoke
- // that too. This is where the addon finally gets to run.
- spawn: function spawn(id, path) {
- let loader = this;
- let process = this.require('api-utils/process');
- process.spawn(id, path)(function(addon) {
- // Listen to `require!` channel's input messages from the add-on process
- // and load modules being required.
- addon.channel('require!').input(function({ requirer: { path }, id }) {
- try {
- Loader.require.call(loader, path, id).initialize(addon.channel(id));
- } catch (error) {
- this.globals.console.exception(error);
- }
- });
- });
- },
unload: function unload(reason, callback) {
this.require('api-utils/unload').send(reason, callback);
}
@@ -1,20 +0,0 @@
-/* vim:set ts=2 sw=2 sts=2 expandtab */
-/* 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/. */
-
-const { messageManager } = require("chrome");
-const { channel } = require("./channel");
-
-module.exports = function load(module) {
- return {
- require: function require(id) {
- // Load required module on the chrome process.
- channel(messageManager, messageManager, 'require!').sync({
- requirer: module,
- id: id
- });
- return channel(messageManager, messageManager, id);
- }
- };
-};
@@ -1,203 +0,0 @@
-/* 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 BAD_LISTENER = "The event listener must be a function.";
-
-const { Cc, Ci, Cu, CC } = require("chrome");
-const { setTimeout } = require("./timer");
-
-const { ns } = require("./namespace");
-
-const { curry, invoke } = require("./functional");
-
-const Sandbox = require("./sandbox");
-
-// JSON.stringify is buggy with cross-sandbox values,
-// it may return "{}" on functions. Use a replacer to match them correctly.
-const jsonFixer = function (k, v) typeof v === "function" ? undefined : v;
-
-/**
- * Defers invoking the function until the current call stack has cleared.
- *
- * @param {Function} fn
- * The function to defer.
- *
- * @returns {Function}
- * The deferred function
- */
-const defer = function(fn) function() {
- setTimeout(invoke, 0, fn, arguments, this)
-};
-
-/**
- * Adds a message listener.
- * This listener will receive messages sent from the remote frame.
- *
- * @param {String} name
- * The name of the message for which to add a listener.
- * @param {Function} listener
- * The listener function called when the message is received.
- */
-function addMessageListener(name, listener) {
- if (typeof listener !== "function")
- throw new Error(BAD_LISTENER);
-
- let listeners = frame(this).listeners;
-
- if (name in listeners) {
- if (~listeners[name].indexOf(listener))
- return;
- } else {
- listeners[name] = [];
- }
-
- listeners[name].push(listener);
-}
-
-/**
- * Removes a message listener previously added by calling addMessageListener.
- *
- * @param {String} name
- * The name of the message for which to remove a listener.
- * @param {Function} listener
- * The listener function has to be removed.
- */
-function removeMessageListener(name, listener) {
- if (typeof listener !== "function")
- throw new Error(BAD_LISTENER);
-
- let listeners = frame(this).listeners;
-
- if (!(name in listeners))
- return;
-
- let index = listeners[name].indexOf(listener);
-
- if (~index) {
- listeners[name].splice(index, 1);
- }
-}
-
-/**
- * Sends a message to the listeners.
- *
- * @param {Boolean} sync
- * Indicates if the call is synchronous or asynchronous
- * @param {String} name
- * The name of the message to send to the listeners.
- * @param {Object} [data=null]
- * A JSON object containing data to be delivered to the listeners.
- *
- * @returns {Array|undefined}
- * An array with the return values of the listeners if `sync` is `true`,
- * otherwise `undefined`.
- */
-function sendMessage(sync, name, data) {
- typeof data === "undefined" && (data = null);
-
- let listeners = frame(frame(this).receiver).listeners;
-
- let responses = [];
-
- let returnValue = sync ? responses : undefined;
-
- if (!(name in listeners))
- return returnValue;
-
- let json = JSON.parse(JSON.stringify(data, jsonFixer));
-
- for each(let listener in listeners[name]) {
- try {
- let response = listener.call(null, {
- sync : sync,
- name : name,
- json : json,
- target : null
- });
-
- if (sync) {
- if (typeof response === "undefined")
- responses.push(response);
- else
- responses.push(JSON.parse(JSON.stringify(response, jsonFixer)));
- }
-
- } catch (e) {
- console.exception(e);
- }
- }
- return returnValue;
-};
-
-let sendSyncMessage = curry(sendMessage, true);
-let sendAsyncMessage = curry(defer(sendMessage), false);
-
-let frame = ns({receiver: null, listeners: null});
-
-/**
- * The MessageManager object emulates the Message Manager API, without creating
- * new processes. It useful in mono process context, like Fennec.
- *
- * @see
- * https://developer.mozilla.org/en/The_message_manager
- */
-function MessageManager() {
-
- let sandbox = Sandbox.sandbox(null, { wantXrays : false });
-
- Object.defineProperties(sandbox, {
- addMessageListener: {value: addMessageListener.bind(sandbox)},
-
- removeMessageListener: { value: removeMessageListener.bind(sandbox)},
-
- sendAsyncMessage: {value: sendAsyncMessage.bind(sandbox)},
-
- sendSyncMessage: { value: sendSyncMessage.bind(sandbox) }
- });
-
- frame(this).receiver = sandbox;
- frame(sandbox).receiver = this;
-
- frame(this).listeners = {};
- frame(sandbox).listeners = {};
-}
-
-MessageManager.prototype = {
- constructor: MessageManager,
-
- addMessageListener : addMessageListener,
-
- removeMessageListener : removeMessageListener,
-
- sendAsyncMessage : sendAsyncMessage,
-
- /**
- * Loads a script into the remote frame.
- *
- * @param {String} uri
- * The URL of the script to load into the frame; this must be an absolute
- * local URL, but data: URLs are supported.
- * @param {Boolean} allowDelayedLoad
- * Not used.
- */
- loadFrameScript: function loadFrameScript(uri, async) {
- if (arguments.length < loadFrameScript.length)
- throw new Error("Not enough arguments");
-
- let sandbox = frame(this).receiver;
-
- try {
- Sandbox.load(sandbox, uri);
- } catch (e) {
- console.exception(e)
- }
- }
-}
-
-Object.freeze(MessageManager);
-Object.freeze(MessageManager.prototype);
-
-exports.MessageManager = MessageManager;
Oops, something went wrong.

0 comments on commit 55fccbc

Please sign in to comment.