Bug 1749449 - [devtools] Cleanup hasNativeConsoleAPI state through the codebase. r=jdescottes,devtools-backward-compat-reviewers.

This removes all the mention of this property which aren't
actually used to display the warning message in the end.

Differential Revision: https://phabricator.services.mozilla.com/D135587
This commit is contained in:
Nicolas Chevobbe 2022-01-11 15:17:24 +00:00
parent 4b0411240e
commit 19bf4f97d1
9 changed files with 3 additions and 84 deletions

View File

@ -73,7 +73,6 @@ class WindowGlobalTargetFront extends TargetMixin(
const event = Object.create(null);
event.url = packet.url;
event.title = packet.title;
event.nativeConsoleAPI = packet.nativeConsoleAPI;
event.isFrameSwitching = packet.isFrameSwitching;
// Keep the title unmodified when a developer toolbox switches frame

View File

@ -291,23 +291,6 @@ class WebConsoleFront extends FrontClassWithSpec(webconsoleSpec) {
return this._client.request(packet, onResponse);
}
/**
* Start the given Web Console listeners.
* TODO: remove once the front is retrieved via getFront, and we use form()
*
* @see this.LISTENERS
* @param array listeners
* Array of listeners you want to start. See this.LISTENERS for
* known listeners.
* @return request
* Request object that implements both Promise and EventEmitter interfaces
*/
async startListeners(listeners) {
const response = await super.startListeners(listeners);
this.hasNativeConsoleAPI = response.nativeConsoleAPI;
return response;
}
/**
* Close the WebConsoleFront.
*

View File

@ -107,12 +107,11 @@ The reply is:
"NetworkActivity",
"FileActivity"
],
"nativeConsoleAPI": true,
"from": "conn0.console9"
}
The reply tells which listeners were started and it includes a flag ``nativeConsoleAPI`` which tells if the ``window.console`` object was overridden by the scripts in the page or not.
The reply tells which listeners were started.
Tab navigation
@ -133,11 +132,10 @@ When page navigation starts the following packet is sent from the tab actor:
"type": "tabNavigated",
"state": "start",
"url": newURL,
"nativeConsoleAPI": true
}
The ``nativeConsoleAPI`` property tells if the ``window.console`` object is native or not for the top level window object for the given tab - this is always ``true`` when navigation starts. When navigation stops the following packet is sent:
When navigation stops the following packet is sent:
.. code-block::
@ -147,7 +145,6 @@ The ``nativeConsoleAPI`` property tells if the ``window.console`` object is nati
"state": "stop",
"url": newURL,
"title": newTitle,
"nativeConsoleAPI": true|false
}

View File

@ -4,8 +4,6 @@
"use strict";
/* global XPCNativeWrapper */
// protocol.js uses objects as exceptions in order to define
// error packets.
/* eslint-disable no-throw-literal */
@ -159,9 +157,6 @@ const windowGlobalTargetPrototype = {
* This event contains the following attributes:
* * url (string)
* The new URI being loaded.
* * nativeConsoleAPI (boolean)
* `false` if the console API of the page has been overridden (e.g. by Firebug)
* `true` if the Gecko implementation is used
* * state (string)
* `start` if we just start requesting the new URL
* `stop` if the new URL is done loading
@ -1535,7 +1530,6 @@ const windowGlobalTargetPrototype = {
if (!this.followWindowGlobalLifeCycle) {
this.emit("tabNavigated", {
url: newURI,
nativeConsoleAPI: true,
state: "start",
isFrameSwitching,
});
@ -1586,34 +1580,11 @@ const windowGlobalTargetPrototype = {
this.emit("tabNavigated", {
url: this.url,
title: this.title,
nativeConsoleAPI: this.hasNativeConsoleAPI(this.window),
state: "stop",
isFrameSwitching: isFrameSwitching,
});
},
/**
* Tells if the window.console object is native or overwritten by script in
* the page.
*
* @param nsIDOMWindow window
* The window object you want to check.
* @return boolean
* True if the window.console object is native, or false otherwise.
*/
hasNativeConsoleAPI(window) {
let isNative = false;
try {
// We are very explicitly examining the "console" property of
// the non-Xrayed object here.
const console = window.wrappedJSObject.console;
isNative = new XPCNativeWrapper(console).IS_NATIVE_CONSOLE;
} catch (ex) {
// ignore
}
return isNative;
},
/**
* Create or return the StyleSheetActor for a style sheet. This method
* is here because the Style Editor and Inspector share style sheet actors.

View File

@ -4,7 +4,6 @@
"use strict";
/* global XPCNativeWrapper */
const { ActorClassWithSpec, Actor } = require("devtools/shared/protocol");
const { webconsoleSpec } = require("devtools/shared/specs/webconsole");
@ -377,28 +376,6 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
return { actor: this.actorID };
},
hasNativeConsoleAPI: function(window) {
if (isWorker || !(window instanceof Ci.nsIDOMWindow)) {
// We can only use XPCNativeWrapper on non-worker nsIDOMWindow.
return true;
}
let isNative = false;
try {
// We are very explicitly examining the "console" property of
// the non-Xrayed object here.
const console = window.wrappedJSObject.console;
// In xpcshell tests, console ends up being undefined and XPCNativeWrapper
// crashes in debug builds.
if (console) {
isNative = new XPCNativeWrapper(console).IS_NATIVE_CONSOLE;
}
} catch (ex) {
// ignored
}
return isNative;
},
_findProtoChain: ThreadActor.prototype._findProtoChain,
_removeFromProtoChain: ThreadActor.prototype._removeFromProtoChain,
@ -789,8 +766,7 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
startedListeners.forEach(this._listeners.add, this._listeners);
return {
startedListeners: startedListeners,
nativeConsoleAPI: this.hasNativeConsoleAPI(this.global),
startedListeners,
};
},

View File

@ -51,7 +51,6 @@ function assertEvent(event, data) {
);
is(data.state, "start", "state is start");
is(data.url, URL2, "url property is correct");
is(data.nativeConsoleAPI, true, "nativeConsoleAPI is correct");
break;
case isE10s ? 5 : 4:
is(
@ -80,7 +79,6 @@ function assertEvent(event, data) {
is(event, "tabNavigated", "Finally, the receive the client event");
is(data.state, "stop", "state is stop");
is(data.url, URL2, "url property is correct");
is(data.nativeConsoleAPI, true, "nativeConsoleAPI is correct");
signalAllEventsReceived();
break;

View File

@ -138,7 +138,6 @@ const windowGlobalTargetSpecPrototype = {
type: "tabNavigated",
url: Option(0, "string"),
title: Option(0, "string"),
nativeConsoleAPI: Option(0, "boolean"),
state: Option(0, "string"),
isFrameSwitching: Option(0, "boolean"),
},

View File

@ -14,7 +14,6 @@ const {
types.addDictType("console.startlisteners", {
startedListeners: "array:string",
nativeConsoleAPI: "nullable:boolean",
});
types.addDictType("console.stoplisteners", {

View File

@ -23,7 +23,6 @@ async function startTest()
let {state, response} = await attachConsoleToTab(["PageError"]);
is(response.startedListeners.length, 1, "startedListeners.length");
is(response.startedListeners[0], "PageError", "startedListeners: PageError");
ok(response.nativeConsoleAPI, "nativeConsoleAPI");
await closeDebugger(state);
top.console_ = top.console;
@ -36,7 +35,6 @@ async function startTest()
isnot(startedListeners.indexOf("ConsoleAPI"), -1,
"startedListeners: ConsoleAPI");
is(startedListeners.indexOf("foo"), -1, "startedListeners: no foo");
ok(!response.nativeConsoleAPI, "!nativeConsoleAPI");
top.console = top.console_;
response = await state.webConsoleFront.stopListeners(["ConsoleAPI", "foo"]);
@ -48,7 +46,6 @@ async function startTest()
is(response.startedListeners.length, 1, "startedListeners.length");
is(response.startedListeners[0], "ConsoleAPI", "startedListeners: ConsoleAPI");
ok(response.nativeConsoleAPI, "nativeConsoleAPI");
top.console = top.console_;
delete top.console_;