зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 60840d7cfef1 (bug 1587541) for Documentation opt failure. CLOSED TREE
This commit is contained in:
Родитель
17939666b8
Коммит
8e31f424cf
|
@ -35,9 +35,6 @@ add_task(async function testExecuteScript() {
|
|||
currentWindow: true,
|
||||
});
|
||||
let frames = await browser.webNavigation.getAllFrames({ tabId: tab.id });
|
||||
browser.test.assertEq(3, frames.length, "Expect exactly three frames");
|
||||
browser.test.assertEq(0, frames[0].frameId, "Main frame has frameId:0");
|
||||
browser.test.assertTrue(frames[1].frameId > 0, "Subframe has a valid id");
|
||||
|
||||
browser.test.log(
|
||||
`FRAMES: ${frames[1].frameId} ${JSON.stringify(frames)}\n`
|
||||
|
@ -354,7 +351,7 @@ add_task(async function testExecuteScript() {
|
|||
browser.test.assertEq(1, result.length, "Expected one result");
|
||||
browser.test.assertTrue(
|
||||
/\/file_iframe_document\.html$/.test(result[0]),
|
||||
`Result for main frame (frameId:0) is correct: ${result[0]}`
|
||||
`Result for frameId[0] is correct: ${result[0]}`
|
||||
);
|
||||
}),
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = ["ExtensionContent", "ExtensionContentChild"];
|
||||
var EXPORTED_SYMBOLS = ["ExtensionContent"];
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
|
@ -1171,42 +1171,59 @@ var ExtensionContent = {
|
|||
},
|
||||
|
||||
// Used to executeScript, insertCSS and removeCSS.
|
||||
async handleActorExecute({ options, windows }) {
|
||||
let policy = WebExtensionPolicy.getByID(options.extensionId);
|
||||
let matcher = new WebExtensionContentScript(policy, options);
|
||||
|
||||
Object.assign(matcher, {
|
||||
wantReturnValue: options.wantReturnValue,
|
||||
removeCSS: options.removeCSS,
|
||||
cssOrigin: options.cssOrigin,
|
||||
jsCode: options.jsCode,
|
||||
});
|
||||
let script = contentScripts.get(matcher);
|
||||
|
||||
// Add the cssCode to the script, so that it can be converted into a cached URL.
|
||||
await script.addCSSCode(options.cssCode);
|
||||
delete options.cssCode;
|
||||
|
||||
const executeInWin = innerId => {
|
||||
let wg = WindowGlobalChild.getByInnerWindowId(innerId);
|
||||
let bc = wg && !wg.isClosed && wg.isCurrentGlobal && wg.browsingContext;
|
||||
|
||||
if (bc && script.matchesWindow(bc.window)) {
|
||||
return script.injectInto(bc.window);
|
||||
async handleExtensionExecute(global, target, options, script) {
|
||||
let executeInWin = window => {
|
||||
if (script.matchesWindow(window)) {
|
||||
return script.injectInto(window);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
let all = Promise.all(windows.map(executeInWin).filter(p => p));
|
||||
let result = await all.catch(e => Promise.reject({ message: e.message }));
|
||||
let promises;
|
||||
try {
|
||||
promises = Array.from(
|
||||
this.enumerateWindows(global.docShell),
|
||||
executeInWin
|
||||
).filter(promise => promise);
|
||||
} catch (e) {
|
||||
Cu.reportError(e);
|
||||
return Promise.reject({ message: "An unexpected error occurred" });
|
||||
}
|
||||
|
||||
if (!promises.length) {
|
||||
if (options.frameID) {
|
||||
return Promise.reject({
|
||||
message: `Frame not found, or missing host permission`,
|
||||
});
|
||||
}
|
||||
|
||||
let frames = options.allFrames ? ", and any iframes" : "";
|
||||
return Promise.reject({
|
||||
message: `Missing host permission for the tab${frames}`,
|
||||
});
|
||||
}
|
||||
if (!options.allFrames && promises.length > 1) {
|
||||
return Promise.reject({
|
||||
message: `Internal error: Script matched multiple windows`,
|
||||
});
|
||||
}
|
||||
|
||||
let result = await Promise.all(promises);
|
||||
|
||||
try {
|
||||
// Check if the result can be structured-cloned before sending back.
|
||||
return Cu.cloneInto(result, this);
|
||||
// Make sure we can structured-clone the result value before
|
||||
// we try to send it back over the message manager.
|
||||
Cu.cloneInto(result, target);
|
||||
} catch (e) {
|
||||
let path = options.jsPaths.slice(-1)[0] ?? "<anonymous code>";
|
||||
let message = `Script '${path}' result is non-structured-clonable data`;
|
||||
return Promise.reject({ message, fileName: path });
|
||||
const { jsPaths } = options;
|
||||
const fileName = jsPaths.length
|
||||
? jsPaths[jsPaths.length - 1]
|
||||
: "<anonymous code>";
|
||||
const message = `Script '${fileName}' result is non-structured-clonable data`;
|
||||
return Promise.reject({ message, fileName });
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
handleWebNavigationGetFrame(global, { frameId }) {
|
||||
|
@ -1228,6 +1245,30 @@ var ExtensionContent = {
|
|||
);
|
||||
case "Extension:DetectLanguage":
|
||||
return this.handleDetectLanguage(global, target);
|
||||
case "Extension:Execute":
|
||||
let policy = WebExtensionPolicy.getByID(recipient.extensionId);
|
||||
|
||||
let matcher = new WebExtensionContentScript(policy, data.options);
|
||||
|
||||
Object.assign(matcher, {
|
||||
wantReturnValue: data.options.wantReturnValue,
|
||||
removeCSS: data.options.removeCSS,
|
||||
cssOrigin: data.options.cssOrigin,
|
||||
jsCode: data.options.jsCode,
|
||||
});
|
||||
|
||||
let script = contentScripts.get(matcher);
|
||||
|
||||
// Add the cssCode to the script, so that it can be converted into a cached URL.
|
||||
await script.addCSSCode(data.options.cssCode);
|
||||
delete data.options.cssCode;
|
||||
|
||||
return this.handleExtensionExecute(
|
||||
global,
|
||||
target,
|
||||
data.options,
|
||||
script
|
||||
);
|
||||
case "WebNavigation:GetFrame":
|
||||
return this.handleWebNavigationGetFrame(global, data.options);
|
||||
case "WebNavigation:GetAllFrames":
|
||||
|
@ -1254,18 +1295,3 @@ var ExtensionContent = {
|
|||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Child side of the ExtensionContent process actor, handles some tabs.* APIs.
|
||||
*/
|
||||
class ExtensionContentChild extends JSProcessActorChild {
|
||||
receiveMessage({ name, data }) {
|
||||
if (!isContentScriptProcess) {
|
||||
return;
|
||||
}
|
||||
switch (name) {
|
||||
case "Execute":
|
||||
return ExtensionContent.handleActorExecute(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ class ExtensionGlobal {
|
|||
|
||||
MessageChannel.addListener(global, "Extension:Capture", this);
|
||||
MessageChannel.addListener(global, "Extension:DetectLanguage", this);
|
||||
MessageChannel.addListener(global, "Extension:Execute", this);
|
||||
MessageChannel.addListener(global, "WebNavigation:GetFrame", this);
|
||||
MessageChannel.addListener(global, "WebNavigation:GetAllFrames", this);
|
||||
}
|
||||
|
@ -103,6 +104,11 @@ class ExtensionGlobal {
|
|||
}
|
||||
return;
|
||||
}
|
||||
// Prevent script compilation in the parent process when we would never
|
||||
// use them.
|
||||
if (!isContentScriptProcess && messageName === "Extension:Execute") {
|
||||
return;
|
||||
}
|
||||
|
||||
// SetFrameData does not have a recipient extension, or it would be
|
||||
// an extension process. Anything following this point must have
|
||||
|
|
|
@ -308,15 +308,6 @@ class TabBase {
|
|||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {BrowsingContext} browsingContext
|
||||
* Returns the BrowsingContext for the given tab.
|
||||
* @readonly
|
||||
*/
|
||||
get browsingContext() {
|
||||
return this.browser?.browsingContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {FrameLoader} frameLoader
|
||||
* Returns the frameloader for the given tab.
|
||||
|
@ -686,62 +677,6 @@ class TabBase {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query each content process hosting subframes of the tab, return results.
|
||||
* @param {string} message
|
||||
* @param {object} options
|
||||
* @param {number} options.frameID
|
||||
* @param {boolean} options.allFrames
|
||||
* @returns {Promise[]}
|
||||
*/
|
||||
async queryContent(message, options) {
|
||||
let { allFrames, frameID } = options;
|
||||
|
||||
/** @type {Map<nsIDOMProcessParent, innerWindowId[]>} */
|
||||
let byProcess = new DefaultMap(() => []);
|
||||
|
||||
// Recursively walk the tab's BC tree, find all frames, group by process.
|
||||
function visit(bc) {
|
||||
let win = bc.currentWindowGlobal;
|
||||
if (win?.domProcess && (!frameID || frameID === bc.id)) {
|
||||
byProcess.get(win.domProcess).push(win.innerWindowId);
|
||||
}
|
||||
if (allFrames || (frameID && !byProcess.size)) {
|
||||
bc.children.forEach(visit);
|
||||
}
|
||||
}
|
||||
visit(this.browsingContext);
|
||||
|
||||
let promises = Array.from(byProcess.entries(), ([proc, windows]) =>
|
||||
proc.getActor("ExtensionContent").sendQuery(message, { windows, options })
|
||||
);
|
||||
|
||||
let results = await Promise.all(promises).catch(err => {
|
||||
if (err.name === "DataCloneError") {
|
||||
let fileName = options.jsPaths.slice(-1)[0] ?? "<anonymous code>";
|
||||
let message = `Script '${fileName}' result is non-structured-clonable data`;
|
||||
return Promise.reject({ message, fileName });
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
results = results.flat();
|
||||
|
||||
if (!results.length) {
|
||||
if (frameID) {
|
||||
throw new ExtensionError("Frame not found, or missing host permission");
|
||||
}
|
||||
|
||||
let frames = allFrames ? ", and any iframes" : "";
|
||||
throw new ExtensionError(`Missing host permission for the tab${frames}`);
|
||||
}
|
||||
|
||||
if (!allFrames && results.length > 1) {
|
||||
throw new ExtensionError("Internal error: multiple windows matched");
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a script or stylesheet in the given tab, and returns a promise
|
||||
* which resolves when the operation has completed.
|
||||
|
@ -766,7 +701,6 @@ class TabBase {
|
|||
jsPaths: [],
|
||||
cssPaths: [],
|
||||
removeCSS: method == "removeCSS",
|
||||
extensionId: context.extension.id,
|
||||
};
|
||||
|
||||
// We require a `code` or a `file` property, but we can't accept both.
|
||||
|
@ -820,7 +754,8 @@ class TabBase {
|
|||
}
|
||||
|
||||
options.wantReturnValue = true;
|
||||
return this.queryContent("Execute", options);
|
||||
|
||||
return this.sendMessage(context, "Extension:Execute", { options });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,6 @@ add_task(async function test_content_script_cross_origin_frame() {
|
|||
all_frames: true,
|
||||
js: ["cs.js"],
|
||||
}],
|
||||
permissions: ["http://example.net/"],
|
||||
},
|
||||
|
||||
background() {
|
||||
|
@ -29,26 +28,6 @@ add_task(async function test_content_script_cross_origin_frame() {
|
|||
browser.test.assertTrue(frameId > 0, "sender frameId is ok");
|
||||
browser.test.assertTrue(url.endsWith("file_sample.html"), "url is ok");
|
||||
|
||||
let shared = await browser.tabs.executeScript(tab.id, {
|
||||
allFrames: true,
|
||||
code: `window.sharedVal`,
|
||||
});
|
||||
browser.test.assertEq(shared[0], 357, "CS runs in a shared Sandbox");
|
||||
|
||||
let code = "does.not.exist";
|
||||
await browser.test.assertRejects(
|
||||
browser.tabs.executeScript(tab.id, { allFrames: true, code }),
|
||||
/does is not defined/,
|
||||
"Got the expected rejection from tabs.executeScript"
|
||||
);
|
||||
|
||||
code = "() => {}";
|
||||
await browser.test.assertRejects(
|
||||
browser.tabs.executeScript(tab.id, { allFrames: true, code }),
|
||||
/Script .* result is non-structured-clonable data/,
|
||||
"Got the expected rejection from tabs.executeScript"
|
||||
);
|
||||
|
||||
let result = await browser.tabs.sendMessage(tab.id, num);
|
||||
port.postMessage(result);
|
||||
port.disconnect();
|
||||
|
@ -71,8 +50,6 @@ add_task(async function test_content_script_cross_origin_frame() {
|
|||
})
|
||||
|
||||
let response;
|
||||
window.sharedVal = 357;
|
||||
|
||||
let port = browser.runtime.connect();
|
||||
port.onMessage.addListener(num => {
|
||||
response = num;
|
||||
|
|
|
@ -51,11 +51,6 @@ let JSPROCESSACTORS = {
|
|||
moduleURI: "resource://gre/modules/ContentPrefServiceChild.jsm",
|
||||
},
|
||||
},
|
||||
ExtensionContent: {
|
||||
child: {
|
||||
moduleURI: "resource://gre/modules/ExtensionContent.jsm",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -740,8 +740,6 @@ module.exports = {
|
|||
WebrtcGlobalInformation: false,
|
||||
WheelEvent: false,
|
||||
Window: false,
|
||||
WindowGlobalChild: false,
|
||||
WindowGlobalParent: false,
|
||||
WindowRoot: false,
|
||||
Worker: false,
|
||||
Worklet: false,
|
||||
|
|
Загрузка…
Ссылка в новой задаче