summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-04-20 20:16:18 -0400
committerMatt A. Tobin <email@mattatobin.com>2018-04-20 20:16:18 -0400
commit94a484dd7e224ef6f4fc5994fa50478d41f72638 (patch)
tree5d91fbb0d1ebeeb1cf0a9ab266effb29ce4c1764
parent754ad610489603f80ea38bbd2cf18b28f0d8bf1d (diff)
parentb3bf60f4264b9acfbd2cb34fed4a66915012803c (diff)
downloadUXP-94a484dd7e224ef6f4fc5994fa50478d41f72638.tar
UXP-94a484dd7e224ef6f4fc5994fa50478d41f72638.tar.gz
UXP-94a484dd7e224ef6f4fc5994fa50478d41f72638.tar.lz
UXP-94a484dd7e224ef6f4fc5994fa50478d41f72638.tar.xz
UXP-94a484dd7e224ef6f4fc5994fa50478d41f72638.zip
Merge branch 'master' into xulrunner
-rw-r--r--application/palemoon/base/content/content.js108
-rw-r--r--application/palemoon/base/content/nsContextMenu.js3
-rw-r--r--browser/components/webextensions/ext-commands.js23
-rw-r--r--build/autoconf/compiler-opts.m413
-rw-r--r--toolkit/components/webextensions/ExtensionChild.jsm28
-rw-r--r--toolkit/components/webextensions/ExtensionCommon.jsm3
-rw-r--r--toolkit/components/webextensions/ExtensionContent.jsm2
-rw-r--r--toolkit/components/webextensions/LegacyExtensionsUtils.jsm2
-rw-r--r--toolkit/components/webextensions/ext-c-runtime.js5
-rw-r--r--toolkit/components/webextensions/schemas/runtime.json2
-rw-r--r--toolkit/components/webextensions/test/mochitest/mochitest.ini1
-rw-r--r--toolkit/components/webextensions/test/mochitest/test_ext_all_apis.js2
-rw-r--r--toolkit/components/webextensions/test/mochitest/test_ext_external_messaging.html111
-rw-r--r--toolkit/components/webextensions/test/mochitest/test_ext_sendmessage_reply2.html144
-rw-r--r--toolkit/components/webextensions/test/xpcshell/test_ext_legacy_extension_context.js4
-rw-r--r--toolkit/jetpack/moz.build12
-rw-r--r--toolkit/jetpack/sdk/addon/bootstrap.js2
-rw-r--r--widget/GfxInfoX11.cpp8
18 files changed, 404 insertions, 69 deletions
diff --git a/application/palemoon/base/content/content.js b/application/palemoon/base/content/content.js
index 19c8b0682..653dac3e3 100644
--- a/application/palemoon/base/content/content.js
+++ b/application/palemoon/base/content/content.js
@@ -60,6 +60,114 @@ addEventListener("blur", function(event) {
LoginManagerContent.onUsernameInput(event);
});
+// Provide gContextMenuContentData for 'sdk/context-menu'
+var handleContentContextMenu = function (event) {
+ let defaultPrevented = event.defaultPrevented;
+ if (!Services.prefs.getBoolPref("dom.event.contextmenu.enabled")) {
+ let plugin = null;
+ try {
+ plugin = event.target.QueryInterface(Ci.nsIObjectLoadingContent);
+ } catch (e) {}
+ if (plugin && plugin.displayedType == Ci.nsIObjectLoadingContent.TYPE_PLUGIN) {
+ // Don't open a context menu for plugins.
+ return;
+ }
+
+ defaultPrevented = false;
+ }
+
+ if (defaultPrevented)
+ return;
+
+ let addonInfo = {};
+ let subject = {
+ event: event,
+ addonInfo: addonInfo,
+ };
+ subject.wrappedJSObject = subject;
+ Services.obs.notifyObservers(subject, "content-contextmenu", null);
+
+ let doc = event.target.ownerDocument;
+ let docLocation = doc.mozDocumentURIIfNotForErrorPages;
+ docLocation = docLocation && docLocation.spec;
+ let charSet = doc.characterSet;
+ let baseURI = doc.baseURI;
+ let referrer = doc.referrer;
+ let referrerPolicy = doc.referrerPolicy;
+ let frameOuterWindowID = doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils)
+ .outerWindowID;
+ let loginFillInfo = LoginManagerContent.getFieldContext(event.target);
+
+ // The same-origin check will be done in nsContextMenu.openLinkInTab.
+ let parentAllowsMixedContent = !!docShell.mixedContentChannel;
+
+ // get referrer attribute from clicked link and parse it
+ // if per element referrer is enabled, the element referrer overrules
+ // the document wide referrer
+ if (Services.prefs.getBoolPref("network.http.enablePerElementReferrer")) {
+ let referrerAttrValue = Services.netUtils.parseAttributePolicyString(event.target.
+ getAttribute("referrerpolicy"));
+ if (referrerAttrValue !== Ci.nsIHttpChannel.REFERRER_POLICY_UNSET) {
+ referrerPolicy = referrerAttrValue;
+ }
+ }
+
+ // Media related cache info parent needs for saving
+ let contentType = null;
+ let contentDisposition = null;
+ if (event.target.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
+ event.target instanceof Ci.nsIImageLoadingContent &&
+ event.target.currentURI) {
+
+ try {
+ let imageCache =
+ Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
+ .getImgCacheForDocument(doc);
+ let props =
+ imageCache.findEntryProperties(event.target.currentURI, doc);
+ try {
+ contentType = props.get("type", Ci.nsISupportsCString).data;
+ } catch (e) {}
+ try {
+ contentDisposition =
+ props.get("content-disposition", Ci.nsISupportsCString).data;
+ } catch (e) {}
+ } catch (e) {}
+ }
+
+ let selectionInfo = BrowserUtils.getSelectionDetails(content);
+
+ let loadContext = docShell.QueryInterface(Ci.nsILoadContext);
+ let userContextId = loadContext.originAttributes.userContextId;
+
+ let browser = docShell.chromeEventHandler;
+ let mainWin = browser.ownerGlobal;
+
+ mainWin.gContextMenuContentData = {
+ isRemote: false,
+ event: event,
+ popupNode: event.target,
+ browser: browser,
+ addonInfo: addonInfo,
+ documentURIObject: doc.documentURIObject,
+ docLocation: docLocation,
+ charSet: charSet,
+ referrer: referrer,
+ referrerPolicy: referrerPolicy,
+ contentType: contentType,
+ contentDisposition: contentDisposition,
+ selectionInfo: selectionInfo,
+ loginFillInfo,
+ parentAllowsMixedContent,
+ userContextId,
+ };
+}
+
+Cc["@mozilla.org/eventlistenerservice;1"]
+ .getService(Ci.nsIEventListenerService)
+ .addSystemEventListener(global, "contextmenu", handleContentContextMenu, false);
+
// Lazily load the finder code
addMessageListener("Finder:Initialize", function () {
let {RemoteFinderListener} = Cu.import("resource://gre/modules/RemoteFinder.jsm", {});
diff --git a/application/palemoon/base/content/nsContextMenu.js b/application/palemoon/base/content/nsContextMenu.js
index 1fe592b52..3d5d40e4c 100644
--- a/application/palemoon/base/content/nsContextMenu.js
+++ b/application/palemoon/base/content/nsContextMenu.js
@@ -4,6 +4,8 @@
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+var gContextMenuContentData = null;
+
function nsContextMenu(aXulMenu, aIsShift) {
this.shouldDisplay = true;
this.initMenu(aXulMenu, aIsShift);
@@ -39,6 +41,7 @@ nsContextMenu.prototype = {
},
hiding: function CM_hiding() {
+ gContextMenuContentData = null;
InlineSpellCheckerUI.clearSuggestionsFromMenu();
InlineSpellCheckerUI.clearDictionaryListFromMenu();
InlineSpellCheckerUI.uninit();
diff --git a/browser/components/webextensions/ext-commands.js b/browser/components/webextensions/ext-commands.js
index 416544e86..3f0bf8d1a 100644
--- a/browser/components/webextensions/ext-commands.js
+++ b/browser/components/webextensions/ext-commands.js
@@ -74,15 +74,14 @@ CommandList.prototype = {
// For Windows, chrome.runtime expects 'win' while chrome.commands
// expects 'windows'. We can special case this for now.
let os = PlatformInfo.os == "win" ? "windows" : PlatformInfo.os;
- for (let name of Object.keys(manifest.commands)) {
- let command = manifest.commands[name];
- let shortcut = command.suggested_key[os] || command.suggested_key.default;
- if (shortcut) {
- commands.set(name, {
- description: command.description,
- shortcut: shortcut.replace(/\s+/g, ""),
- });
- }
+ for (let [name, command] of Object.entries(manifest.commands)) {
+ let suggested_key = command.suggested_key || {};
+ let shortcut = suggested_key[os] || suggested_key.default;
+ shortcut = shortcut ? shortcut.replace(/\s+/g, "") : null;
+ commands.set(name, {
+ description: command.description,
+ shortcut,
+ });
}
return commands;
},
@@ -96,8 +95,10 @@ CommandList.prototype = {
let keyset = doc.createElementNS(XUL_NS, "keyset");
keyset.id = `ext-keyset-id-${this.id}`;
this.commands.forEach((command, name) => {
- let keyElement = this.buildKey(doc, name, command.shortcut);
- keyset.appendChild(keyElement);
+ if (command.shortcut) {
+ let keyElement = this.buildKey(doc, name, command.shortcut);
+ keyset.appendChild(keyElement);
+ }
});
doc.documentElement.appendChild(keyset);
this.keysetsMap.set(window, keyset);
diff --git a/build/autoconf/compiler-opts.m4 b/build/autoconf/compiler-opts.m4
index 57a974435..c47d792f4 100644
--- a/build/autoconf/compiler-opts.m4
+++ b/build/autoconf/compiler-opts.m4
@@ -181,18 +181,15 @@ if test "$GNU_CC"; then
if test -z "$CLANG_CC"; then
case "$CC_VERSION" in
- 4.*)
+ 4.* | 5.*)
;;
*)
# Lifetime Dead Store Elimination level 2 (default in GCC6+) breaks Gecko.
- # Ideally, we'd use -flifetime-dse=1, but that means we'd forcefully
- # enable it on optimization levels where it would otherwise not be enabled.
- # So we disable it entirely. But since that would mean inconsistency with
- # GCC5, which has level 1 depending on optimization level, disable it on
- # GCC5 as well, because better safe than sorry.
+ # Instead of completely disabling this optimization on newer GCC's,
+ # we'll force them to use level 1 optimization with -flifetime-dse=1.
# Add it first so that a mozconfig can override by setting CFLAGS/CXXFLAGS.
- CFLAGS="-fno-lifetime-dse $CFLAGS"
- CXXFLAGS="-fno-lifetime-dse $CXXFLAGS"
+ CFLAGS="-flifetime-dse=1 $CFLAGS"
+ CXXFLAGS="-flifetime-dse=1 $CXXFLAGS"
;;
esac
fi
diff --git a/toolkit/components/webextensions/ExtensionChild.jsm b/toolkit/components/webextensions/ExtensionChild.jsm
index c953dd685..5dc4e2277 100644
--- a/toolkit/components/webextensions/ExtensionChild.jsm
+++ b/toolkit/components/webextensions/ExtensionChild.jsm
@@ -325,7 +325,7 @@ class Messenger {
return this.sendMessage(messageManager, msg, recipient, responseCallback);
}
- onMessage(name) {
+ _onMessage(name, filter) {
return new SingletonEventManager(this.context, name, callback => {
let listener = {
messageFilterPermissive: this.optionalFilter,
@@ -333,7 +333,8 @@ class Messenger {
filterMessage: (sender, recipient) => {
// Ignore the message if it was sent by this Messenger.
- return sender.contextId !== this.context.contextId;
+ return (sender.contextId !== this.context.contextId &&
+ filter(sender, recipient));
},
receiveMessage: ({target, data: message, sender, recipient}) => {
@@ -373,6 +374,14 @@ class Messenger {
}).api();
}
+ onMessage(name) {
+ return this._onMessage(name, sender => sender.id === this.sender.id);
+ }
+
+ onMessageExternal(name) {
+ return this._onMessage(name, sender => sender.id !== this.sender.id);
+ }
+
_connect(messageManager, port, recipient) {
let msg = {
name: port.name,
@@ -407,7 +416,7 @@ class Messenger {
return this._connect(messageManager, port, recipient);
}
- onConnect(name) {
+ _onConnect(name, filter) {
return new SingletonEventManager(this.context, name, callback => {
let listener = {
messageFilterPermissive: this.optionalFilter,
@@ -415,7 +424,8 @@ class Messenger {
filterMessage: (sender, recipient) => {
// Ignore the port if it was created by this Messenger.
- return sender.contextId !== this.context.contextId;
+ return (sender.contextId !== this.context.contextId &&
+ filter(sender, recipient));
},
receiveMessage: ({target, data: message, sender}) => {
@@ -438,6 +448,14 @@ class Messenger {
};
}).api();
}
+
+ onConnect(name) {
+ return this._onConnect(name, sender => sender.id === this.sender.id);
+ }
+
+ onConnectExternal(name) {
+ return this._onConnect(name, sender => sender.id !== this.sender.id);
+ }
}
var apiManager = new class extends SchemaAPIManager {
@@ -745,7 +763,7 @@ class ExtensionPageContextChild extends BaseContext {
// This is the MessageSender property passed to extension.
// It can be augmented by the "page-open" hook.
- let sender = {id: extension.uuid};
+ let sender = {id: extension.id};
if (viewType == "tab") {
sender.tabId = tabId;
this.tabId = tabId;
diff --git a/toolkit/components/webextensions/ExtensionCommon.jsm b/toolkit/components/webextensions/ExtensionCommon.jsm
index a339fb27e..9ec84b5c7 100644
--- a/toolkit/components/webextensions/ExtensionCommon.jsm
+++ b/toolkit/components/webextensions/ExtensionCommon.jsm
@@ -197,10 +197,9 @@ class BaseContext {
* @returns {Promise}
*/
sendMessage(target, messageName, data, options = {}) {
- options.recipient = options.recipient || {};
+ options.recipient = Object.assign({extensionId: this.extension.id}, options.recipient);
options.sender = options.sender || {};
- options.recipient.extensionId = this.extension.id;
options.sender.extensionId = this.extension.id;
options.sender.contextId = this.contextId;
diff --git a/toolkit/components/webextensions/ExtensionContent.jsm b/toolkit/components/webextensions/ExtensionContent.jsm
index 9b9a02091..5bdcde6f5 100644
--- a/toolkit/components/webextensions/ExtensionContent.jsm
+++ b/toolkit/components/webextensions/ExtensionContent.jsm
@@ -456,7 +456,7 @@ class ContentScriptContextChild extends BaseContext {
defineLazyGetter(ContentScriptContextChild.prototype, "messenger", function() {
// The |sender| parameter is passed directly to the extension.
- let sender = {id: this.extension.uuid, frameId: this.frameId, url: this.url};
+ let sender = {id: this.extension.id, frameId: this.frameId, url: this.url};
let filter = {extensionId: this.extension.id};
let optionalFilter = {frameId: this.frameId};
diff --git a/toolkit/components/webextensions/LegacyExtensionsUtils.jsm b/toolkit/components/webextensions/LegacyExtensionsUtils.jsm
index 7632548e3..e8d276fe9 100644
--- a/toolkit/components/webextensions/LegacyExtensionsUtils.jsm
+++ b/toolkit/components/webextensions/LegacyExtensionsUtils.jsm
@@ -64,7 +64,7 @@ var LegacyExtensionContext = class extends BaseContext {
{value: cloneScope, enumerable: true, configurable: true, writable: true}
);
- let sender = {id: targetExtension.uuid};
+ let sender = {id: targetExtension.id};
let filter = {extensionId: targetExtension.id};
// Legacy addons live in the main process. Messages from other addons are
// Messages from WebExtensions are sent to the main process and forwarded via
diff --git a/toolkit/components/webextensions/ext-c-runtime.js b/toolkit/components/webextensions/ext-c-runtime.js
index 8adca60ca..1dcac35da 100644
--- a/toolkit/components/webextensions/ext-c-runtime.js
+++ b/toolkit/components/webextensions/ext-c-runtime.js
@@ -9,6 +9,10 @@ function runtimeApiFactory(context) {
onMessage: context.messenger.onMessage("runtime.onMessage"),
+ onConnectExternal: context.messenger.onConnectExternal("runtime.onConnectExternal"),
+
+ onMessageExternal: context.messenger.onMessageExternal("runtime.onMessageExternal"),
+
connect: function(extensionId, connectInfo) {
let name = connectInfo !== null && connectInfo.name || "";
extensionId = extensionId || extension.id;
@@ -47,7 +51,6 @@ function runtimeApiFactory(context) {
if (options != null && typeof options != "object") {
return Promise.reject({message: "runtime.sendMessage's options argument is invalid"});
}
- // TODO(robwu): Validate option keys and values when we support it.
extensionId = extensionId || extension.id;
let recipient = {extensionId};
diff --git a/toolkit/components/webextensions/schemas/runtime.json b/toolkit/components/webextensions/schemas/runtime.json
index b3f12a768..575df7d27 100644
--- a/toolkit/components/webextensions/schemas/runtime.json
+++ b/toolkit/components/webextensions/schemas/runtime.json
@@ -535,7 +535,6 @@
},
{
"name": "onConnectExternal",
- "unsupported": true,
"type": "function",
"description": "Fired when a connection is made from another extension.",
"parameters": [
@@ -560,7 +559,6 @@
},
{
"name": "onMessageExternal",
- "unsupported": true,
"type": "function",
"description": "Fired when a message is sent from another extension/app. Cannot be used in a content script.",
"parameters": [
diff --git a/toolkit/components/webextensions/test/mochitest/mochitest.ini b/toolkit/components/webextensions/test/mochitest/mochitest.ini
index 45586237e..1f61060ad 100644
--- a/toolkit/components/webextensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/webextensions/test/mochitest/mochitest.ini
@@ -59,6 +59,7 @@ skip-if = os == 'android' # Android does not support tabs API. Bug 1260250
[test_ext_contentscript_teardown.html]
skip-if = (os == 'android') # Android does not support tabs API. Bug 1260250
[test_ext_exclude_include_globs.html]
+[test_ext_external_messaging.html]
[test_ext_i18n_css.html]
[test_ext_generate.html]
[test_ext_notifications.html]
diff --git a/toolkit/components/webextensions/test/mochitest/test_ext_all_apis.js b/toolkit/components/webextensions/test/mochitest/test_ext_all_apis.js
index 0f617c37e..25d04b36b 100644
--- a/toolkit/components/webextensions/test/mochitest/test_ext_all_apis.js
+++ b/toolkit/components/webextensions/test/mochitest/test_ext_all_apis.js
@@ -75,7 +75,9 @@ let expectedBackgroundApis = [
"runtime.getBackgroundPage",
"runtime.getBrowserInfo",
"runtime.getPlatformInfo",
+ "runtime.onConnectExternal",
"runtime.onInstalled",
+ "runtime.onMessageExternal",
"runtime.onStartup",
"runtime.onUpdateAvailable",
"runtime.openOptionsPage",
diff --git a/toolkit/components/webextensions/test/mochitest/test_ext_external_messaging.html b/toolkit/components/webextensions/test/mochitest/test_ext_external_messaging.html
new file mode 100644
index 000000000..dfc1f9427
--- /dev/null
+++ b/toolkit/components/webextensions/test/mochitest/test_ext_external_messaging.html
@@ -0,0 +1,111 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>WebExtension external messaging</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+ <script type="text/javascript" src="head.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="text/javascript">
+"use strict";
+
+function backgroundScript(id, otherId) {
+ browser.runtime.onMessage.addListener((msg, sender) => {
+ browser.test.fail(`Got unexpected message: ${uneval(msg)} ${uneval(sender)}`);
+ });
+
+ browser.runtime.onConnect.addListener(port => {
+ browser.test.fail(`Got unexpected connection: ${uneval(port.sender)}`);
+ });
+
+ browser.runtime.onMessageExternal.addListener((msg, sender) => {
+ browser.test.assertEq(otherId, sender.id, `${id}: Got expected external sender ID`);
+ browser.test.assertEq(`helo-${id}`, msg, "Got expected message");
+
+ browser.test.sendMessage("onMessage-done");
+
+ return Promise.resolve(`ehlo-${otherId}`);
+ });
+
+ browser.runtime.onConnectExternal.addListener(port => {
+ browser.test.assertEq(otherId, port.sender.id, `${id}: Got expected external connecter ID`);
+
+ port.onMessage.addListener(msg => {
+ browser.test.assertEq(`helo-${id}`, msg, "Got expected port message");
+
+ port.postMessage(`ehlo-${otherId}`);
+
+ browser.test.sendMessage("onConnect-done");
+ });
+ });
+
+ browser.test.onMessage.addListener(msg => {
+ if (msg === "go") {
+ browser.runtime.sendMessage(otherId, `helo-${otherId}`).then(result => {
+ browser.test.assertEq(`ehlo-${id}`, result, "Got expected reply");
+ browser.test.sendMessage("sendMessage-done");
+ });
+
+ let port = browser.runtime.connect(otherId);
+ port.postMessage(`helo-${otherId}`);
+
+ port.onMessage.addListener(msg => {
+ port.disconnect();
+
+ browser.test.assertEq(msg, `ehlo-${id}`, "Got expected port reply");
+ browser.test.sendMessage("connect-done");
+ });
+ }
+ });
+}
+
+function makeExtension(id, otherId) {
+ let args = `${JSON.stringify(id)}, ${JSON.stringify(otherId)}`;
+
+ let extensionData = {
+ background: `(${backgroundScript})(${args})`,
+ manifest: {
+ "applications": {"gecko": {id}},
+ },
+ };
+
+ return ExtensionTestUtils.loadExtension(extensionData);
+}
+
+add_task(function* test_contentscript() {
+ const ID1 = "foo-message@mochitest.mozilla.org";
+ const ID2 = "bar-message@mochitest.mozilla.org";
+
+ let extension1 = makeExtension(ID1, ID2);
+ let extension2 = makeExtension(ID2, ID1);
+
+ yield Promise.all([extension1.startup(), extension2.startup()]);
+
+ extension1.sendMessage("go");
+ extension2.sendMessage("go");
+
+ yield Promise.all([
+ extension1.awaitMessage("sendMessage-done"),
+ extension2.awaitMessage("sendMessage-done"),
+
+ extension1.awaitMessage("onMessage-done"),
+ extension2.awaitMessage("onMessage-done"),
+
+ extension1.awaitMessage("connect-done"),
+ extension2.awaitMessage("connect-done"),
+
+ extension1.awaitMessage("onConnect-done"),
+ extension2.awaitMessage("onConnect-done"),
+ ]);
+
+ yield extension1.unload();
+ yield extension2.unload();
+});
+</script>
+
+</body>
+</html>
diff --git a/toolkit/components/webextensions/test/mochitest/test_ext_sendmessage_reply2.html b/toolkit/components/webextensions/test/mochitest/test_ext_sendmessage_reply2.html
index 1ebc1b40f..5c350be2f 100644
--- a/toolkit/components/webextensions/test/mochitest/test_ext_sendmessage_reply2.html
+++ b/toolkit/components/webextensions/test/mochitest/test_ext_sendmessage_reply2.html
@@ -13,48 +13,119 @@
<script type="text/javascript">
"use strict";
-function backgroundScript(token) {
+function backgroundScript(token, id, otherId) {
+ browser.tabs.create({url: "tab.html"});
+
browser.runtime.onMessage.addListener((msg, sender, sendReply) => {
- browser.test.assertTrue(sender.tab.url.endsWith("file_sample.html"), "sender url correct");
+ browser.test.assertEq(id, sender.id, `${id}: Got expected sender ID`);
- if (msg == "done") {
- browser.test.notifyPass("sendmessage_reply");
- return;
+ if (msg === `content-${token}`) {
+ browser.test.assertTrue(sender.tab.url.endsWith("file_sample.html"),
+ `${id}: sender url correct`);
+
+ let tabId = sender.tab.id;
+ browser.tabs.sendMessage(tabId, `${token}-contentMessage`);
+
+ sendReply(`${token}-done`);
+ } else if (msg === `tab-${token}`) {
+ browser.runtime.sendMessage(otherId, `${otherId}-tabMessage`);
+ browser.runtime.sendMessage(`${token}-tabMessage`);
+
+ sendReply(`${token}-done`);
+ } else {
+ browser.test.fail(`${id}: Unexpected runtime message received: ${msg} ${uneval(sender)}`);
}
+ });
+
+ browser.runtime.onMessageExternal.addListener((msg, sender, sendReply) => {
+ browser.test.assertEq(otherId, sender.id, `${id}: Got expected external sender ID`);
+
+ if (msg === `content-${id}`) {
+ browser.test.assertTrue(sender.tab.url.endsWith("file_sample.html"),
+ `${id}: external sender url correct`);
+
+ sendReply(`${otherId}-done`);
+ } else if (msg === `tab-${id}`) {
+ sendReply(`${otherId}-done`);
+ } else if (msg !== `${id}-tabMessage`) {
+ browser.test.fail(`${id}: Unexpected runtime external message received: ${msg} ${uneval(sender)}`);
+ }
+ });
+}
+
+function contentScript(token, id, otherId) {
+ let gotContentMessage = false;
+ browser.runtime.onMessage.addListener((msg, sender, sendReply) => {
+ browser.test.assertEq(id, sender.id, `${id}: Got expected sender ID`);
+
+ browser.test.assertEq(`${token}-contentMessage`, msg,
+ `${id}: Correct content script message`);
+ if (msg === `${token}-contentMessage`) {
+ gotContentMessage = true;
+ }
+ });
+
+ Promise.all([
+ browser.runtime.sendMessage(otherId, `content-${otherId}`).then(resp => {
+ browser.test.assertEq(`${id}-done`, resp, `${id}: Correct content script external response token`);
+ }),
- let tabId = sender.tab.id;
- browser.tabs.sendMessage(tabId, `${token}-tabMessage`);
+ browser.runtime.sendMessage(`content-${token}`).then(resp => {
+ browser.test.assertEq(`${token}-done`, resp, `${id}: Correct content script response token`);
+ }),
+ ]).then(() => {
+ browser.test.assertTrue(gotContentMessage, `${id}: Got content script message`);
- browser.test.assertEq(msg, token, "token matches");
- sendReply(`${token}-done`);
+ browser.test.sendMessage("content-script-done");
});
}
-function contentScript(token) {
+function tabScript(token, id, otherId) {
let gotTabMessage = false;
- let badTabMessage = false;
browser.runtime.onMessage.addListener((msg, sender, sendReply) => {
- if (msg == `${token}-tabMessage`) {
+ browser.test.assertEq(id, sender.id, `${id}: Got expected sender ID`);
+
+ if (String(msg).startsWith("content-")) {
+ return;
+ }
+
+ browser.test.assertEq(`${token}-tabMessage`, msg,
+ `${id}: Correct tab script message`);
+ if (msg === `${token}-tabMessage`) {
gotTabMessage = true;
- } else {
- badTabMessage = true;
}
});
- browser.runtime.sendMessage(token, function(resp) {
- if (resp != `${token}-done` || !gotTabMessage || badTabMessage) {
- return; // test failed
- }
- browser.runtime.sendMessage("done");
+ Promise.all([
+ browser.runtime.sendMessage(otherId, `tab-${otherId}`).then(resp => {
+ browser.test.assertEq(`${id}-done`, resp, `${id}: Correct tab script external response token`);
+ }),
+
+ browser.runtime.sendMessage(`tab-${token}`).then(resp => {
+ browser.test.assertEq(`${token}-done`, resp, `${id}: Correct tab script response token`);
+ }),
+ ]).then(() => {
+ browser.test.assertTrue(gotTabMessage, `${id}: Got tab script message`);
+
+ window.close();
+
+ browser.test.sendMessage("tab-script-done");
});
}
-function makeExtension() {
+function makeExtension(id, otherId) {
let token = Math.random();
+
+ let args = `${token}, ${JSON.stringify(id)}, ${JSON.stringify(otherId)}`;
+
let extensionData = {
- background: `(${backgroundScript})(${token})`,
+ background: `(${backgroundScript})(${args})`,
manifest: {
+ "applications": {"gecko": {id}},
+
"permissions": ["tabs"],
+
+
"content_scripts": [{
"matches": ["http://mochi.test/*/file_sample.html"],
"js": ["content_script.js"],
@@ -63,29 +134,46 @@ function makeExtension() {
},
files: {
- "content_script.js": `(${contentScript})(${token})`,
+ "tab.html": `<!DOCTYPE html>
+ <html>
+ <head>
+ <meta charset="utf-8">
+ <script src="tab.js"><\/script>
+ </head>
+ </html>`,
+
+ "tab.js": `(${tabScript})(${args})`,
+
+ "content_script.js": `(${contentScript})(${args})`,
},
};
return extensionData;
}
add_task(function* test_contentscript() {
- let extension1 = ExtensionTestUtils.loadExtension(makeExtension());
- let extension2 = ExtensionTestUtils.loadExtension(makeExtension());
+ const ID1 = "sendmessage1@mochitest.mozilla.org";
+ const ID2 = "sendmessage2@mochitest.mozilla.org";
+
+ let extension1 = ExtensionTestUtils.loadExtension(makeExtension(ID1, ID2));
+ let extension2 = ExtensionTestUtils.loadExtension(makeExtension(ID2, ID1));
yield Promise.all([extension1.startup(), extension2.startup()]);
let win = window.open("file_sample.html");
- yield Promise.all([waitForLoad(win),
- extension1.awaitFinish("sendmessage_reply"),
- extension2.awaitFinish("sendmessage_reply")]);
+ yield waitForLoad(win);
+
+ yield Promise.all([
+ extension1.awaitMessage("content-script-done"),
+ extension2.awaitMessage("content-script-done"),
+ extension1.awaitMessage("tab-script-done"),
+ extension2.awaitMessage("tab-script-done"),
+ ]);
win.close();
yield extension1.unload();
yield extension2.unload();
- info("extensions unloaded");
});
</script>
diff --git a/toolkit/components/webextensions/test/xpcshell/test_ext_legacy_extension_context.js b/toolkit/components/webextensions/test/xpcshell/test_ext_legacy_extension_context.js
index 63d5361a1..770851472 100644
--- a/toolkit/components/webextensions/test/xpcshell/test_ext_legacy_extension_context.js
+++ b/toolkit/components/webextensions/test/xpcshell/test_ext_legacy_extension_context.js
@@ -108,7 +108,7 @@ add_task(function* test_legacy_extension_context() {
"Got the expected message");
ok(msgSender, "Got a message sender object");
- equal(msgSender.id, extensionInfo.uuid, "The sender has the expected id property");
+ equal(msgSender.id, extension.id, "The sender has the expected id property");
equal(msgSender.url, extensionInfo.bgURL, "The sender has the expected url property");
// Wait confirmation that the reply has been received.
@@ -136,7 +136,7 @@ add_task(function* test_legacy_extension_context() {
ok(port, "Got the Port API object");
ok(port.sender, "The port has a sender property");
- equal(port.sender.id, extensionInfo.uuid,
+ equal(port.sender.id, extension.id,
"The port sender has the expected id property");
equal(port.sender.url, extensionInfo.bgURL,
"The port sender has the expected url property");
diff --git a/toolkit/jetpack/moz.build b/toolkit/jetpack/moz.build
index ad11e90a3..2e5dbe5e8 100644
--- a/toolkit/jetpack/moz.build
+++ b/toolkit/jetpack/moz.build
@@ -128,9 +128,10 @@ EXTRA_JS_MODULES.commonjs += [
'test.js',
]
-EXTRA_JS_MODULES.commonjs.sdk += [
- 'sdk/webextension.js',
-]
+if CONFIG['MOZ_WEBEXTENSIONS']:
+ EXTRA_JS_MODULES.commonjs.sdk += [
+ 'sdk/webextension.js',
+ ]
EXTRA_JS_MODULES.commonjs.dev += [
'dev/debuggee.js',
@@ -228,7 +229,6 @@ EXTRA_PP_JS_MODULES.commonjs.sdk += [
]
EXTRA_JS_MODULES.commonjs.sdk.addon += [
- 'sdk/addon/bootstrap.js',
'sdk/addon/events.js',
'sdk/addon/host.js',
'sdk/addon/installer.js',
@@ -237,6 +237,10 @@ EXTRA_JS_MODULES.commonjs.sdk.addon += [
'sdk/addon/window.js',
]
+EXTRA_PP_JS_MODULES.commonjs.sdk.addon += [
+ 'sdk/addon/bootstrap.js',
+]
+
EXTRA_JS_MODULES.commonjs.sdk.browser += [
'sdk/browser/events.js',
]
diff --git a/toolkit/jetpack/sdk/addon/bootstrap.js b/toolkit/jetpack/sdk/addon/bootstrap.js
index 0397d91e5..6c5827f1e 100644
--- a/toolkit/jetpack/sdk/addon/bootstrap.js
+++ b/toolkit/jetpack/sdk/addon/bootstrap.js
@@ -134,8 +134,10 @@ Bootstrap.prototype = {
const main = command === "test" ? "sdk/test/runner" : null;
const prefsURI = `${baseURI}defaults/preferences/prefs.js`;
+#ifdef MOZ_WEBEXTENSIONS
// Init the 'sdk/webextension' module from the bootstrap addon parameter.
require("sdk/webextension").initFromBootstrapAddonParam(addon);
+#endif
const { startup } = require("sdk/addon/runner");
startup(reason, {loader, main, prefsURI});
diff --git a/widget/GfxInfoX11.cpp b/widget/GfxInfoX11.cpp
index 4297aaa93..48fc3dbb5 100644
--- a/widget/GfxInfoX11.cpp
+++ b/widget/GfxInfoX11.cpp
@@ -23,7 +23,7 @@ NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfoDebug)
#endif
// these global variables will be set when firing the glxtest process
-int glxtest_pipe = 0;
+int glxtest_pipe = -1;
pid_t glxtest_pid = 0;
nsresult
@@ -50,8 +50,8 @@ GfxInfo::GetData()
// to understand this function, see bug 639842. We retrieve the OpenGL driver information in a
// separate process to protect against bad drivers.
- // if glxtest_pipe == 0, that means that we already read the information
- if (!glxtest_pipe)
+ // if glxtest_pipe == -1, that means that we already read the information
+ if (glxtest_pipe == -1)
return;
enum { buf_size = 1024 };
@@ -60,7 +60,7 @@ GfxInfo::GetData()
&buf,
buf_size-1); // -1 because we'll append a zero
close(glxtest_pipe);
- glxtest_pipe = 0;
+ glxtest_pipe = -1;
// bytesread < 0 would mean that the above read() call failed.
// This should never happen. If it did, the outcome would be to blacklist anyway.