Bug 1751203 - [devtools] Drop WebExtensionTargetActor.allowSource. r=jdescottes

As we are already filtering the JS Globals via _shouldAddNewGlobalAsDebuggee,
there is no need to filter out the JS Sources.
We do want all the sources for all the WebExtension globals.

Differential Revision: https://phabricator.services.mozilla.com/D136507
This commit is contained in:
Alexandre Poirot 2022-01-28 13:54:27 +00:00
Родитель 6416193cc6
Коммит fff697ff74
6 изменённых файлов: 8 добавлений и 153 удалений

Просмотреть файл

@ -98,7 +98,6 @@ skip-if = os != 'mac' # The tested ctrl+key shortcuts are OSX only
[browser_jsterm_document_no_xray.js]
[browser_jsterm_eager_evaluation_element_highlight.js]
[browser_jsterm_eager_evaluation_in_debugger_stackframe.js]
[browser_jsterm_eager_evaluation_on_webextension_target.js]
[browser_jsterm_eager_evaluation_warnings.js]
[browser_jsterm_eager_evaluation.js]
[browser_jsterm_editor.js]

Просмотреть файл

@ -1,79 +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 { DevToolsClient } = require("devtools/client/devtools-client");
const { DevToolsServer } = require("devtools/server/devtools-server");
add_task(async function test_webextension_target_allowSource_on_eager_eval() {
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "temporary",
background: function() {
this.browser.test.sendMessage("bg-ready");
},
});
await extension.startup();
await extension.awaitMessage("bg-ready");
// Init debugger server.
DevToolsServer.init();
DevToolsServer.registerAllActors();
// Create and connect a debugger client.
const transport = DevToolsServer.connectPipe();
const client = new DevToolsClient(transport);
await client.connect();
// Get AddonTarget.
const addonDescriptor = await client.mainRoot.getAddon({ id: extension.id });
ok(addonDescriptor, "webextension addon description has been found");
// Open a toolbox window for the addon target.
const toolbox = await gDevTools.showToolbox(addonDescriptor, {
toolId: "webconsole",
hostType: Toolbox.HostType.WINDOW,
});
await toolbox.selectTool("webconsole");
info("Start listening for console messages");
SpecialPowers.registerConsoleListener(msg => {
if (
msg.message &&
msg.message.includes("Unexpected invalid url: debugger eager eval code")
) {
ok(
false,
"webextension targetActor._allowSource should not log an error on debugger eager eval code"
);
}
});
registerCleanupFunction(() => {
SpecialPowers.postConsoleSentinel();
});
const hud = toolbox.getPanel("webconsole").hud;
setInputValue(hud, `browser`);
info("Wait for eager eval element");
await TestUtils.waitForCondition(() => getEagerEvaluationElement(hud));
// The following step will force Firefox to list the source actors, one of those
// source actors is going to be the one related to the js code evaluated by the
// eager evaluation and it does make sure that WebExtensionTargetPrototype._allowSource
// is going to be called with the source actor with url "debugger eager eval code".
info("Select the debugger panel to force webextension actor to list sources");
await toolbox.selectTool("jsdebugger");
// Wait for a bit so that the error message would have the time to be logged
// (and fail if the issue does regress again).
await wait(2000);
await toolbox.destroy();
await client.close();
await extension.unload();
});

Просмотреть файл

@ -24,7 +24,6 @@ const makeDebugger = require("devtools/server/actors/utils/make-debugger");
const {
webExtensionTargetSpec,
} = require("devtools/shared/specs/targets/webextension");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const Targets = require("devtools/server/actors/targets/index");
const TargetActorMixin = require("devtools/server/actors/targets/target-actor-mixin");
@ -135,9 +134,6 @@ webExtensionTargetPrototype.initialize = function(
},
});
// Bind the _allowSource helper to this, it is used in the
// WindowGlobalTargetActor to lazily create the SourcesManager instance.
this._allowSource = this._allowSource.bind(this);
this._onParentExit = this._onParentExit.bind(this);
this._chromeGlobal.addMessageListener(
@ -300,58 +296,6 @@ webExtensionTargetPrototype.isExtensionWindowDescendent = function(window) {
return rootWin.document.nodePrincipal.addonId == this.addonId;
};
/**
* Return true if the given source is associated with this addon and should be
* added to the visible sources (retrieved and used by the webbrowser actor module).
*/
webExtensionTargetPrototype._allowSource = function(source) {
// Use the source.element to detect the allowed source, if any.
if (source.element) {
try {
const domEl = unwrapDebuggerObjectGlobal(source.element);
return this.isExtensionWindowDescendent(domEl.ownerGlobal);
} catch (e) {
// If the source's window is dead then the above will throw.
DevToolsUtils.reportException("WebExtensionTarget.allowSource", e);
return false;
}
}
// Fallback to check the uri if there is no source.element associated to the source.
// Retrieve the first component of source.url in the form "url1 -> url2 -> ...".
const url = source.url.split(" -> ").pop();
// Filter out the code introduced by evaluating code in the webconsole.
if (url === "debugger eval code" || url === "debugger eager eval code") {
return false;
}
let uri;
// Try to decode the url.
try {
uri = Services.io.newURI(url);
} catch (err) {
Cu.reportError(`Unexpected invalid url: ${url}`);
return false;
}
// Filter out resource and chrome sources (which are related to the loaded internals).
if (["resource", "chrome", "file"].includes(uri.scheme)) {
return false;
}
try {
const addonID = this.aps.extensionURIToAddonId(uri);
return addonID == this.addonId;
} catch (err) {
// extensionURIToAddonId raises an exception on non-extension URLs.
return false;
}
};
/**
* Return true if the given global is associated with this addon and should be
* added as a debuggee, false otherwise.

Просмотреть файл

@ -350,12 +350,6 @@ const windowGlobalTargetPrototype = {
// filter console messages by addonID), set to an empty (no options) object by default.
consoleAPIListenerOptions: {},
// Optional SourcesManager filter function (e.g. used by the WebExtensionActor to filter
// sources by addonID), allow all sources by default.
_allowSource() {
return true;
},
/*
* Return a Debugger instance or create one if there is none yet
*/
@ -544,10 +538,7 @@ const windowGlobalTargetPrototype = {
get sourcesManager() {
if (!this._sourcesManager) {
this._sourcesManager = new SourcesManager(
this.threadActor,
this._allowSource
);
this._sourcesManager = new SourcesManager(this.threadActor);
}
return this._sourcesManager;
},

Просмотреть файл

@ -28,6 +28,9 @@ const {
const {
WatchpointMap,
} = require("devtools/server/actors/utils/watchpoint-map");
const {
isHiddenSource,
} = require("devtools/server/actors/utils/sources-manager");
const { logEvent } = require("devtools/server/actors/utils/logEvent");
@ -935,7 +938,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
packet.why = reason;
if (!sourceActor) {
// If the frame location is in a source that not pass the 'allowSource'
// If the frame location is in a source that not pass the 'isHiddenSource'
// check and thus has no actor, we do not bother pausing.
return undefined;
}
@ -2066,7 +2069,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
* @returns true, if the source was added; false otherwise.
*/
_addSource(source) {
if (!this.sourcesManager.allowSource(source)) {
if (isHiddenSource(source)) {
return false;
}

Просмотреть файл

@ -30,12 +30,9 @@ const MINIFIED_SOURCE_REGEXP = /\bmin\.js$/;
* the sources, etc for ThreadActors.
*/
class SourcesManager extends EventEmitter {
constructor(threadActor, allowSourceFn = () => true) {
constructor(threadActor) {
super();
this._thread = threadActor;
this.allowSource = source => {
return !isHiddenSource(source) && allowSourceFn(source);
};
this.blackBoxedSources = new Map();
@ -92,7 +89,7 @@ class SourcesManager extends EventEmitter {
createSourceActor(source) {
assert(source, "SourcesManager.prototype.source needs a source");
if (!this.allowSource(source)) {
if (isHiddenSource(source)) {
return null;
}