Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove E10S abstraction layer.

  • Loading branch information...
commit 55fccbc04ecb6746163e2481d647ced986519c52 1 parent 6a1a82e
@Gozala Gozala authored
View
46 packages/api-utils/lib/channel.js
@@ -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);
- }
- };
-};
-
View
45 packages/api-utils/lib/cuddlefish.js
@@ -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);
}
View
20 packages/api-utils/lib/env!.js
@@ -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);
- }
- };
-};
View
203 packages/api-utils/lib/message-manager.js
@@ -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;
View
76 packages/api-utils/lib/process.js
@@ -1,76 +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 { Cc, Ci } = require("chrome");
-const { createRemoteBrowser } = require("api-utils/window-utils");
-const { channel } = require("./channel");
-const packaging = require('@packaging');
-const { when } = require('./unload');
-const { MessageManager } = require('./message-manager');
-
-const addonService = '@mozilla.org/addon/service;1' in Cc ?
- Cc['@mozilla.org/addon/service;1'].getService(Ci.nsIAddonService) : null
-
-const ENABLE_E10S = packaging.enable_e10s;
-
-const isFennec = require("./xul-app").is("Fennec");
-
-function loadScript(target, uri, sync) {
- return 'loadScript' in target ? target.loadScript(uri, sync)
- : target.loadFrameScript(uri, sync)
-}
-
-function process(target, id, path, scope) {
- // Please note that even though `loadScript`, is executed before channel is
- // returned, users still are able to subscribe for messages before any message
- // will be sent. That's because `loadScript` queues script execution on the
- // other process, which means they will execute async (on the next turn of
- // event loop), while the channel for messages is returned immediately (in
- // the same turn of event loop).
-
- let load = loadScript.bind(null, target);
-
- load(packaging.uriPrefix + packaging.loader, false);
- load('data:,' + encodeURIComponent(
- 'let loader = Loader.new(' + JSON.stringify(packaging) + ');\n' +
- 'loader.main("' + id + '", "' + path + '");'), false);
-
- when(function (reason) {
- // Please note that it's important to unload remote loader
- // synchronously (using synchronous frame script), to make sure that we
- // don't stop during unload.
- // Bug 724433: Take care to nullify all globals set by `cuddlefish.js`
- // otherwise, we will leak any still defined global.
- // `dump` is set in Loader.new method, `dump = globals.dump;`
- load('data:,loader.unload("' + reason + '");' +
- 'loader = null; Loader = null; dump = null;', true);
- });
-
- return {
- channel: channel.bind(null, scope, target),
- loadScript: load
- };
-}
-
-exports.spawn = function spawn(id, path) {
- return function promise(deliver) {
- // If `nsIAddonService` is available we use it to create an add-on process,
- // otherwise we fallback to the remote browser's message manager.
- if (ENABLE_E10S && addonService) {
- console.log('!!!!!!!!!!!!!!!!!!!! Using addon process !!!!!!!!!!!!!!!!!!');
- deliver(process(addonService.createAddon(), id, path));
- } else if (isFennec) {
- deliver(process(new MessageManager(), id, path));
- } else {
- createRemoteBrowser(ENABLE_E10S)(function(browser) {
- let messageManager = browser.QueryInterface(Ci.nsIFrameLoaderOwner).
- frameLoader.messageManager
- let window = browser.ownerDocument.defaultView;
- deliver(process(messageManager, id, path, window));
- });
- }
- };
-};
View
85 packages/api-utils/lib/window-utils.js
@@ -5,8 +5,8 @@
"use strict";
const { Cc, Ci } = require("chrome");
-const { EventEmitter } = require('./events'),
- { Trait } = require('./traits');
+const { EventEmitter } = require('./events');
+const { Trait } = require('./traits');
const { when } = require('./unload');
const { getInnerId, getOuterId } = require('./window-utils');
const errors = require("./errors");
@@ -15,10 +15,6 @@ const windowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
const appShellService = Cc["@mozilla.org/appshell/appShellService;1"].
getService(Ci.nsIAppShellService);
-const observers = require('api-utils/observer-service');
-
-
-const XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
/**
* An iterator for XUL windows currently in the application.
@@ -196,82 +192,7 @@ exports.isBrowser = isBrowser;
exports.hiddenWindow = appShellService.hiddenDOMWindow;
-function createHiddenXULFrame() {
- return function promise(deliver) {
- let window = appShellService.hiddenDOMWindow;
-
- // Ensuring waiting for hidden window end of loading
- // (The hidden window is still loading on windows/thunderbird)
- if (window.document.readyState != "complete") {
- window.addEventListener("load", function onload() {
- window.removeEventListener("load", onload, false);
- // We recurse with same arguments, when the window is ready
- promise(deliver);
- }, false);
- return;
- }
-
- let document = window.document;
- let isXMLDoc = (document.contentType == "application/xhtml+xml" ||
- document.contentType == "application/vnd.mozilla.xul+xml")
-
- if (isXMLDoc) {
- deliver(window)
- }
- else {
- let frame = document.createElement('iframe');
- // This is ugly but we need window for XUL document in order to create
- // browser elements.
-
- // See bug 725323: hiddenWindow URL is different on each mozilla product
- let prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
- let hiddenWindowURL = prefs.getCharPref("browser.hiddenWindowChromeURL", "");
-
- frame.src = hiddenWindowURL;
- frame.setAttribute('src', hiddenWindowURL);
- frame.addEventListener('DOMContentLoaded', function onLoad(event) {
- frame.removeEventListener('DOMContentLoaded', onLoad, false);
- deliver(frame.contentWindow);
- }, false);
- document.documentElement.appendChild(frame);
- }
- }
-};
-exports.createHiddenXULFrame = createHiddenXULFrame;
-
-function createRemoteBrowser(remote) {
- return function promise(deliver) {
- createHiddenXULFrame()(function(hiddenWindow) {
- let document = hiddenWindow.document;
- let browser = document.createElementNS(XUL, "browser");
- // Remote="true" enable everything here:
- // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1347
- if (remote !== false)
- browser.setAttribute("remote","true");
- // Type="content" is mandatory to enable stuff here:
- // http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsFrameLoader.cpp#1776
- browser.setAttribute("type","content");
- // We remove XBL binding to avoid execution of code that is not going to work
- // because browser has no docShell attribute in remote mode (for example)
- browser.setAttribute("style","-moz-binding: none;");
- // Flex it in order to be visible (optional, for debug purpose)
- browser.setAttribute("flex", "1");
- document.documentElement.appendChild(browser);
-
- // Bug 724433: do not leak this <browser> DOM node
- when(function () {
- document.documentElement.removeChild(browser);
- });
-
- // Return browser
- deliver(browser);
- });
- };
-};
-exports.createRemoteBrowser = createRemoteBrowser;
-
-require("./unload").when(
+when(
function() {
gDocsToClose.slice().forEach(
function(doc) { doc.defaultView.close(); });
View
600 packages/api-utils/tests/test-message-manager.js
@@ -1,600 +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 { Loader } = require('./helpers');
-
-function createMessageManager() {
- let loader = Loader(module);
- let { MessageManager } = loader.require("api-utils/message-manager");
- let frame = loader.sandbox("api-utils/message-manager").frame;
-
- return [new MessageManager, frame];
-}
-
-
-exports["test MessageManager addMessageListener"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
- let remoteFrame = frame(mm).receiver;
-
- let listeners = frame(mm).listeners;
- let remoteListeners = frame(remoteFrame).listeners;
-
- let topic = "message-topic";
-
- let listener = function () {};
-
- assert.equal(topic in listeners, false,
- "No listeners for MessageManager");
- assert.equal(topic in remoteListeners, false,
- "No listeners for Remote Frame");
-
- mm.addMessageListener(topic, listener);
-
- assert.deepEqual(listeners[topic], [listener],
- "Listener is added properly");
- assert.equal(topic in remoteListeners, false,
- "No listeners for Remote Frame");
- }
-
-
-exports["test MessageManager addMessageListener with duplicates"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
- let topic = "message-topic";
- let listeners = frame(mm).listeners;
-
- let listener = function () {};
-
- mm.addMessageListener(topic, listener);
- mm.addMessageListener(topic, listener);
- mm.addMessageListener(topic, listener);
-
- assert.deepEqual(listeners[topic], [listener],
- "Same listener is added only once");
- }
-
-
-exports["test MessageManager addMessageListener exceptions"] =
- function(assert) {
- const BAD_LISTENER = "The event listener must be a function.";
-
- let [mm, frame] = createMessageManager();
- let listeners = frame(mm).listeners;
- let topic = "message-topic";
-
- assert.throws(
- function() mm.addMessageListener(),
- BAD_LISTENER
- );
-
- assert.throws(
- function() mm.addMessageListener(topic),
- BAD_LISTENER
- );
-
- assert.throws(
- function() mm.addMessageListener(topic, "something-else"),
- BAD_LISTENER
- );
- }
-
-exports["test MessageManager removeMessageListener"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
- let topic = "message-topic";
- let listeners = frame(mm).listeners;
-
- let listenerA = function () {};
- let listenerB = function () {};
- let listenerC = function () {};
-
- mm.removeMessageListener(topic, listenerA);
-
- assert.deepEqual(listeners, {},
- "No listeners yet");
-
- mm.addMessageListener(topic, listenerA);
- mm.addMessageListener(topic, listenerB);
- mm.addMessageListener(topic, listenerC);
-
- mm.removeMessageListener(topic, listenerB);
-
- assert.deepEqual(listeners[topic], [listenerA, listenerC],
- "Listener is removed properly");
- }
-
-
-exports["test MessageManager loadFrameScript with data URL"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
-
- assert.equal("TEST_VALUE" in remoteFrame, false,
- "TEST_VALUE is not defined in Remote Frame");
-
- mm.loadFrameScript("data:, const TEST_VALUE = 77;", true);
-
- assert.equal(remoteFrame.TEST_VALUE, 77,
- "TEST_VALUE is properly defined in Remote Frame");
- }
-
-
-exports["test MessageManager loadFrameScript with a File"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
-
- assert.equal("TEST_VALUE" in remoteFrame, false,
- "TEST_VALUE is not defined in Remote Frame");
-
- mm.loadFrameScript(require("self").data.url("test-message-manager.js"), true);
-
- assert.equal(remoteFrame.TEST_VALUE, 11,
- "TEST_VALUE is properly defined in Remote Frame");
- }
-
-exports["test MessageManager loadFrameScript exception"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
-
-
- assert.throws(
- function() mm.loadFrameScript("data:, const TEST_VALUE = 77;"),
- "Not enough arguments"
- );
-
- }
-
-exports["test Remote Frame addMessageListener"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
- let remoteFrame = frame(mm).receiver;
-
- let listeners = frame(remoteFrame).listeners;
- let managerListeners = frame(mm).listeners;
-
- let topic = "message-topic";
-
- let listener = function () {};
-
- assert.equal(topic in listeners, false,
- "No listeners for Remote Frame");
- assert.equal(topic in managerListeners, false,
- "No listeners for MessageManager");
-
- remoteFrame.addMessageListener(topic, listener);
-
- assert.deepEqual(listeners[topic], [listener],
- "Listener is added properly");
- assert.equal(topic in managerListeners, false,
- "No listeners for MessageManager");
- }
-
-
-exports["test Remote Frame addMessageListener with duplicates"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
- let listeners = frame(remoteFrame).listeners;
- let topic = "message-topic";
-
- let listener = function () {};
-
- assert.equal(topic in listeners, false,
- "No listeners in Remote Frame");
-
- remoteFrame.addMessageListener(topic, listener);
- remoteFrame.addMessageListener(topic, listener);
- remoteFrame.addMessageListener(topic, listener);
-
- assert.deepEqual(listeners[topic], [listener],
- "Listener is added properly");
- }
-
-
-exports["test Remote Frame addMessageListener exceptions"] =
- function(assert) {
- const BAD_LISTENER = "The event listener must be a function.";
-
- let [mm, frame] = createMessageManager();
- let remoteFrame = frame(mm).receiver;
- let listeners = frame(remoteFrame).listeners;
- let topic = "message-topic";
-
- assert.throws(
- function() mm.addMessageListener(),
- BAD_LISTENER
- );
-
- assert.throws(
- function() mm.addMessageListener(topic),
- BAD_LISTENER
- );
-
- assert.throws(
- function() mm.addMessageListener(topic, "something-else"),
- BAD_LISTENER
- );
- }
-
-
-exports["test Remote Frame removeMessageListener"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
- let listeners = frame(remoteFrame).listeners;
-
- let topic = "message-topic";
-
- let listenerA = function () {};
- let listenerB = function () {};
- let listenerC = function () {};
-
- remoteFrame.removeMessageListener(topic, listenerA);
-
- assert.deepEqual(listeners, {},
- "No listeners yet");
-
- remoteFrame.addMessageListener(topic, listenerA);
- remoteFrame.addMessageListener(topic, listenerB);
- remoteFrame.addMessageListener(topic, listenerC);
-
- remoteFrame.removeMessageListener(topic, listenerB);
-
- assert.deepEqual(listeners[topic], [listenerA, listenerC],
- "Listener is removed properly");
- }
-
-
-exports["test MessageManager sendAsyncMessage"] =
- function(assert, done) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
- let calls = 0;
-
- let topic = "message-topic";
-
- let listener = function(data) {
- calls++;
-
- assert.deepEqual(data, {
- sync : false,
- name : topic,
- json : {foo : "bar"},
- target : null
- }, "Data received as expected");
-
- assert.equal(calls, 1,
- "Listener called once");
-
- done();
- }
-
- remoteFrame.addMessageListener(topic, listener);
-
- let response = mm.sendAsyncMessage(topic, {foo : "bar"});
-
- assert.strictEqual(response, undefined,
- "No response for async messages");
-
- assert.equal(calls, 0,
- "Listener not called yet");
- }
-
-exports["test MessageManager sendAsyncMessage without listeners"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
-
- let topic = "message-topic";
-
- let response = mm.sendAsyncMessage(topic, {foo : "bar"});
-
- assert.strictEqual(response, undefined,
- "No response for async messages");
- }
-
-
-exports["test MessageManager sendAsyncMessage without arguments"] =
- function(assert, done) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
- let calls = 0;
-
- let topic = "message-topic";
-
- let listener = function(data) {
- calls++;
-
- assert.deepEqual(data, {
- sync : false,
- name : topic,
- json : null,
- target : null
- }, "Data received as expected");
-
- assert.equal(calls, 1,
- "Listener called once");
-
- done();
- }
-
- remoteFrame.addMessageListener(topic, listener);
-
- mm.sendAsyncMessage();
-
- mm.sendAsyncMessage(topic);
-
- assert.equal(calls, 0,
- "Listener not called yet");
- }
-
-
-exports["test Remote Frame sendAsyncMessage"] =
- function(assert, done) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
- let calls = 0;
-
- let topic = "message-topic";
-
- let listener = function(data) {
- calls++;
-
- assert.deepEqual(data, {
- sync : false,
- name : topic,
- json : {foo : "bar"},
- target : null
- }, "Data received as expected");
-
- assert.equal(calls, 1,
- "Listener called once");
-
- done();
- }
-
- mm.addMessageListener(topic, listener);
-
- let response = remoteFrame.sendAsyncMessage(topic, {foo : "bar"});
-
- assert.strictEqual(response, undefined,
- "No response for async messages");
-
- assert.equal(calls, 0,
- "Listener not called yet");
- }
-
-
-exports["test Remote Frame sendAsyncMessage without arguments"] =
- function(assert, done) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
- let calls = 0;
-
- let topic = "message-topic";
-
- let listener = function(data) {
- calls++;
-
- assert.deepEqual(data, {
- sync : false,
- name : topic,
- json : null,
- target : null
- }, "Data received as expected");
-
- assert.equal(calls, 1,
- "Listener called once");
-
- done();
- }
-
- mm.addMessageListener(topic, listener);
-
- remoteFrame.sendAsyncMessage();
-
- remoteFrame.sendAsyncMessage(topic);
-
- assert.equal(calls, 0,
- "Listener not called yet");
- }
-
-exports["test Remote Frame sendAsyncMessage without listeners"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
-
- let topic = "message-topic";
-
- let response = remoteFrame.sendAsyncMessage(topic, {foo : "bar"});
-
- assert.strictEqual(response, undefined,
- "No response for async messages");
- }
-
-exports["test Remote Frame sendSyncMessage"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
-
- let topic = "message-topic";
-
- let expectedData = {
- sync : true,
- name : topic,
- json : {foo : "bar"},
- target : null
- }
-
- let listenerA = function(data) {
- assert.deepEqual(data, expectedData,
- "Data received as expected");
-
- return "my value";
- }
-
- let listenerB = function(data) {
- assert.deepEqual(data, expectedData,
- "Data received as expected");
-
- return {complex : "object", method : function() "not allowed"};
- }
-
- let listenerC = function(data) {
- assert.deepEqual(data, expectedData,
- "Data received as expected");
- }
-
- mm.addMessageListener(topic, listenerA);
- mm.addMessageListener(topic, listenerB);
- mm.addMessageListener(topic, listenerC);
-
- let response = remoteFrame.sendSyncMessage(topic, {foo : "bar"});
-
- assert.deepEqual(response, ["my value", {complex : "object"}, undefined],
- "Response from sync messages as expected");
- }
-
-exports["test Remote Frame sendSyncMessage without arguments"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
-
- let topic = "message-topic";
-
- let expectedData = {
- sync : true,
- name : topic,
- json : null,
- target : null
- }
-
- let listener = function(data) {
- assert.deepEqual(data, expectedData,
- "Data received as expected");
- }
-
- mm.addMessageListener(topic, listener);
-
- let response = remoteFrame.sendSyncMessage();
-
- assert.deepEqual(response, [],
- "Empty response as expected");
-
- let response = remoteFrame.sendSyncMessage(topic);
-
- assert.deepEqual(response, [undefined],
- "Response from sync messages as expected");
- }
-
-exports["test Remote Frame sendSyncMessage without listeners"] =
- function(assert) {
- let [mm, frame] = createMessageManager();
-
- let remoteFrame = frame(mm).receiver;
- let obj = {foo : "bar"};
-
- let topic = "message-topic";
-
- let response = remoteFrame.sendSyncMessage(topic, obj);
-
- assert.deepEqual(response, [],
- "Response from sync messages as expected");
- }
-
-
-exports["test Message Manager / Remote Frame async pipeline"] =
- function(assert, done) {
- let [mm] = createMessageManager();
-
- let expectedMessages = ["alpha:remote", "alpha", "omega:remote", "omega"];
-
- mm.addMessageListener("handshake", function (data) {
- let messages = data.json.concat("alpha");
-
- mm.sendAsyncMessage("shutdown", messages);
- });
-
- mm.addMessageListener("shutdown", function (data) {
- let messages = data.json.concat("omega");
-
- assert.deepEqual(messages, expectedMessages,
- "messages delivered in the expected order");
-
- done();
- });
-
- mm.loadFrameScript(
- "data:, \
- addMessageListener('handshake', function (data) {\
- let messages = data.json.concat('alpha:remote');\
- sendAsyncMessage('handshake', messages);\
- });\
- addMessageListener('shutdown', function (data) {\
- let messages = data.json.concat('omega:remote');\
- sendAsyncMessage('shutdown', messages);\
- });\
- ", true);
-
- mm.sendAsyncMessage("handshake", []);
- }
-
-
-exports["test Message Manager / Remote Frame async / sync pipeline"] =
- function(assert, done) {
- let [mm] = createMessageManager();
-
- let expectedMessages = ["alpha:remote", "alpha", "omega:remote", "omega"];
-
- mm.addMessageListener("handshake",
- function (data) data.json.concat("alpha")
- );
-
- mm.addMessageListener("shutdown",
- function (data) data.json.concat("omega")
- );
-
- mm.addMessageListener("verify", function (data) {
-
- assert.deepEqual(data.json, expectedMessages,
- "messages delivered in the expected order");
-
- done();
- });
-
- mm.loadFrameScript(
- "data:, \
- addMessageListener('handshake', function (data) {\
- let messages = data.json.concat('alpha:remote');\
- \
- messages = sendSyncMessage('handshake', messages)[0];\
- messages.push('omega:remote');\
- messages = sendSyncMessage('shutdown', messages)[0];\
- \
- sendSyncMessage('verify', messages);\
- });\
- ", true);
-
- mm.sendAsyncMessage("handshake", []);
- }
-
-require("test").run(exports);
View
36 packages/api-utils/tests/test-process.js
@@ -1,36 +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 { Loader } = require("./helpers");
-const { jetpackID } = require('@packaging');
-
-// bug 707562: '#' char in packaging was causing loader to be undefined
-exports.testBug707562 = function(test) {
- test.waitUntilDone();
-
- let packaging = JSON.parse(JSON.stringify(require("@packaging")));
- packaging.metadata["api-utils"].author = "###";
-
- let loader = Loader(module, {}, packaging);
- let process = loader.require("process");
-
- // has spawn?
- test.assert(process.spawn, "'process' module exports 'spawn' method.");
-
- let promise = process.spawn("testID", "");
- test.assertFunction(promise, "spawn makes a promise.");
-
- promise(function(addon) {
- addon.channel("TEST:LOADED").input(function(data) {
- test.assert(data, "The loader was successfully created!");
- loader.unload();
- test.done();
- });
-
- addon.loadScript('data:,sendAsyncMessage("'+jetpackID+':TEST:LOADED", !!this.loader);', false);
- test.pass("spawn's promise was delivered! (which means a addon process object is available)).");
- });
-};
View
4 python-lib/cuddlefish/app-extension/bootstrap.js
@@ -13,8 +13,6 @@ const ioService = Cc['@mozilla.org/network/io-service;1'].
getService(Ci.nsIIOService);
const resourceHandler = ioService.getProtocolHandler('resource')
.QueryInterface(Ci.nsIResProtocolHandler);
-const XMLHttpRequest = CC('@mozilla.org/xmlextras/xmlhttprequest;1',
- 'nsIXMLHttpRequest');
const prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
QueryInterface(Ci.nsIPrefBranch2);
@@ -183,7 +181,7 @@ function startup(data, reason) {
// on add-on.
promise(function() {
try {
- loader.spawn(options.main, options.mainPath);
+ loader.main(options.main, options.mainPath);
} catch (error) {
// If at this stage we have an error only thing we can do is report about
// it via error console. Keep in mind that error won't automatically show
Please sign in to comment.
Something went wrong with that request. Please try again.