Bug 1704458 - [devtools] Pass isFrameSwitching in DOCUMENT_EVENT resources. r=jdescottes.

This will be consumed by the toolbox to not update detached window title when
the user triggered a frame switching (i.e. selected a document in the frame switcher
menu in the toolbar).

Differential Revision: https://phabricator.services.mozilla.com/D115204
This commit is contained in:
Nicolas Chevobbe 2021-05-19 16:58:06 +00:00
Родитель b2ec877e46
Коммит bbb132d353
3 изменённых файлов: 44 добавлений и 26 удалений

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

@ -29,9 +29,14 @@ class DocumentEventWatcher {
const onDocumentEvent = (
name,
time,
// This is only passed for dom-loading event
shouldBeIgnoredAsRedundantWithTargetAvailable
{
time,
// This is only passed for dom-loading event
shouldBeIgnoredAsRedundantWithTargetAvailable,
// This will be `true` when the user selected a document in the frame picker tool,
// in the toolbox toolbar.
isFrameSwitching,
}
) => {
onAvailable([
{
@ -39,6 +44,7 @@ class DocumentEventWatcher {
name,
time,
shouldBeIgnoredAsRedundantWithTargetAvailable,
isFrameSwitching,
},
]);
};

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

@ -1420,6 +1420,7 @@ const browsingContextTargetPrototype = {
isTopLevel: isTopLevel,
isBFCache,
id: getWindowID(window),
isFrameSwitching,
});
},

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

@ -49,6 +49,7 @@ DocumentEventsListener.prototype = {
window,
isTopLevel,
shouldBeIgnoredAsRedundantWithTargetAvailable,
isFrameSwitching,
}) {
// Ignore iframes
if (!isTopLevel) {
@ -56,51 +57,61 @@ DocumentEventsListener.prototype = {
}
const time = window.performance.timing.navigationStart;
this.emit(
"dom-loading",
time,
// As dom-loading is often used to clear the panel on navigation, and is typically
// sent before any other resource, we need to add a hint so the client knows when
// then event can be ignored.
// We should also ignore them if the Target was created via a JSWindowActor and is
// destroyed when the WindowGlobal is destroyed (i.e. when we navigate or reload),
// as this will come late and is redundant with onTargetAvailable.
// As dom-loading is often used to clear the panel on navigation, and is typically
// sent before any other resource, we need to add a hint so the client knows when
// then event can be ignored.
// We should also ignore them if the Target was created via a JSWindowActor and is
// destroyed when the WindowGlobal is destroyed (i.e. when we navigate or reload),
// as this will come late and is redundant with onTargetAvailable.
shouldBeIgnoredAsRedundantWithTargetAvailable =
shouldBeIgnoredAsRedundantWithTargetAvailable ||
(this.targetActor.isTopLevelTarget &&
this.targetActor.followWindowGlobalLifeCycle)
);
(this.targetActor.isTopLevelTarget &&
this.targetActor.followWindowGlobalLifeCycle);
this.emit("dom-loading", {
time,
shouldBeIgnoredAsRedundantWithTargetAvailable,
isFrameSwitching,
});
const { readyState } = window.document;
if (readyState != "interactive" && readyState != "complete") {
window.addEventListener("DOMContentLoaded", this.onContentLoaded, {
window.addEventListener(
"DOMContentLoaded",
e => this.onContentLoaded(e, isFrameSwitching),
{
once: true,
}
);
} else {
this.onContentLoaded({ target: window.document }, isFrameSwitching);
}
if (readyState != "complete") {
window.addEventListener("load", e => this.onLoad(e, isFrameSwitching), {
once: true,
});
} else {
this.onContentLoaded({ target: window.document });
}
if (readyState != "complete") {
window.addEventListener("load", this.onLoad, { once: true });
} else {
this.onLoad({ target: window.document });
this.onLoad({ target: window.document }, isFrameSwitching);
}
},
onContentLoaded(event) {
onContentLoaded(event, isFrameSwitching) {
// milliseconds since the UNIX epoch, when the parser finished its work
// on the main document, that is when its Document.readyState changes to
// 'interactive' and the corresponding readystatechange event is thrown
const window = event.target.defaultView;
const time = window.performance.timing.domInteractive;
this.emit("dom-interactive", time);
this.emit("dom-interactive", { time, isFrameSwitching });
},
onLoad(event) {
onLoad(event, isFrameSwitching) {
// milliseconds since the UNIX epoch, when the parser finished its work
// on the main document, that is when its Document.readyState changes to
// 'complete' and the corresponding readystatechange event is thrown
const window = event.target.defaultView;
const time = window.performance.timing.domComplete;
this.emit("dom-complete", time);
this.emit("dom-complete", { time, isFrameSwitching });
},
destroy() {