зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1596918: Part 1c - Make some more globals available to SpecialPowers.spawn tasks. r=mccr8
A number of additional globals are available to ContentTask.spawn tasks compared to SpecialPowers.spawn tasks. Most of these are available by accident, as a side-effect of running in a shared frame script global, or being evaled in the context of the content-task.js frame script, but several of them are pretty broadly useful, or difficult to obtain from a Sandbox environment without reaching into arbitrary nearby globals. This patch adds some of the more useful ones to the default task environment. Differential Revision: https://phabricator.services.mozilla.com/D53736 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
78e7bc3363
Коммит
a4d92243c6
|
@ -1709,12 +1709,17 @@ class SpecialPowersChild extends JSWindowActorChild {
|
|||
|
||||
sb.sandbox.SpecialPowers = this;
|
||||
sb.sandbox.ContentTaskUtils = ContentTaskUtils;
|
||||
Object.defineProperty(sb.sandbox, "content", {
|
||||
for (let [global, prop] of Object.entries({
|
||||
content: "contentWindow",
|
||||
docShell: "docShell",
|
||||
})) {
|
||||
Object.defineProperty(sb.sandbox, global, {
|
||||
get: () => {
|
||||
return this.contentWindow;
|
||||
return this[prop];
|
||||
},
|
||||
enumerable: true,
|
||||
});
|
||||
}
|
||||
|
||||
return sb.execute(task, args, caller);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/* 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";
|
||||
|
||||
var EXPORTED_SYMBOLS = ["EventUtils"];
|
||||
|
||||
/**
|
||||
* Loads a stub copy of EventUtils.js which can be used by things like
|
||||
* content tasks without holding any direct references to windows.
|
||||
*/
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
let EventUtils = {};
|
||||
|
||||
EventUtils.window = {};
|
||||
EventUtils.parent = EventUtils.window;
|
||||
EventUtils._EU_Ci = Ci;
|
||||
EventUtils._EU_Cc = Cc;
|
||||
|
||||
EventUtils.synthesizeClick = element =>
|
||||
new Promise(resolve => {
|
||||
element.addEventListener("click", () => resolve(), { once: true });
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
element,
|
||||
{ type: "mousedown", isSynthesized: false },
|
||||
element.ownerGlobal
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
element,
|
||||
{ type: "mouseup", isSynthesized: false },
|
||||
element.ownerGlobal
|
||||
);
|
||||
});
|
||||
|
||||
Services.scriptloader.loadSubScript(
|
||||
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js",
|
||||
EventUtils
|
||||
);
|
|
@ -18,6 +18,14 @@ ChromeUtils.defineModuleGetter(
|
|||
"resource://testing-common/Assert.jsm"
|
||||
);
|
||||
|
||||
const SANDBOX_GLOBALS = [
|
||||
"Blob",
|
||||
"ChromeUtils",
|
||||
"TextDecoder",
|
||||
"TextEncoder",
|
||||
"URL",
|
||||
];
|
||||
|
||||
let expectFail = false;
|
||||
function expectingFail(fn) {
|
||||
try {
|
||||
|
@ -38,7 +46,7 @@ class SpecialPowersSandbox {
|
|||
this.sandbox = Cu.Sandbox(
|
||||
Cu.getGlobalForObject({}),
|
||||
Object.assign(
|
||||
{ wantGlobalProperties: ["ChromeUtils"] },
|
||||
{ wantGlobalProperties: SANDBOX_GLOBALS },
|
||||
opts.sandboxOptions
|
||||
)
|
||||
);
|
||||
|
@ -53,11 +61,18 @@ class SpecialPowersSandbox {
|
|||
});
|
||||
}
|
||||
|
||||
for (let [symbol, url] of Object.entries(opts.imports || {})) {
|
||||
let imports = {
|
||||
EventUtils: "resource://specialpowers/SpecialPowersEventUtils.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
...opts.imports,
|
||||
};
|
||||
for (let [symbol, url] of Object.entries(imports)) {
|
||||
ChromeUtils.defineModuleGetter(this.sandbox, symbol, url);
|
||||
}
|
||||
|
||||
Object.assign(this.sandbox, {
|
||||
BrowsingContext,
|
||||
InspectorUtils,
|
||||
ok: (...args) => {
|
||||
this.Assert.ok(...args);
|
||||
},
|
||||
|
|
|
@ -20,6 +20,7 @@ FINAL_TARGET_FILES.content += [
|
|||
'content/MockFilePicker.jsm',
|
||||
'content/MockPermissionPrompt.jsm',
|
||||
'content/SpecialPowersChild.jsm',
|
||||
'content/SpecialPowersEventUtils.jsm',
|
||||
'content/SpecialPowersParent.jsm',
|
||||
'content/SpecialPowersSandbox.jsm',
|
||||
'content/WrapPrivileged.jsm',
|
||||
|
|
Загрузка…
Ссылка в новой задаче