mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1636924 - Remove unnecessary isTopLevel and type properties from onTargetAvailable/onTargetDestroyed callback parameter. r=ochameau.
Since targetFronts now have isTopLevel and targetType properties, we can directly use those, as the targetFront is included in the callback parameter. This patch remove those properties and refactor consumer code. Differential Revision: https://phabricator.services.mozilla.com/D74651
This commit is contained in:
parent
66e30e7da6
commit
2834d00a38
@ -307,8 +307,8 @@ class AccessibilityProxy {
|
||||
: this.accessibilityEventsMap;
|
||||
}
|
||||
|
||||
async _onTargetAvailable({ targetFront, isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
await this._updateTarget(targetFront);
|
||||
}
|
||||
}
|
||||
|
@ -162,8 +162,8 @@ AccessibilityPanel.prototype = {
|
||||
this._opening.then(() => this.refresh());
|
||||
},
|
||||
|
||||
async onTargetAvailable({ targetFront, isTopLevel, isTargetSwitching }) {
|
||||
if (isTopLevel) {
|
||||
async onTargetAvailable({ targetFront, isTargetSwitching }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
await this.accessibilityProxy.initializeProxyForPanel(targetFront);
|
||||
this.accessibilityProxy.currentTarget.on("navigate", this.onTabNavigated);
|
||||
}
|
||||
|
@ -126,16 +126,16 @@ window.Application = {
|
||||
targetFront.off("navigate", this.handleOnNavigate);
|
||||
},
|
||||
|
||||
onTargetAvailable({ targetFront, isTopLevel }) {
|
||||
if (!isTopLevel) {
|
||||
onTargetAvailable({ targetFront }) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return; // ignore target frames that are not top level for now
|
||||
}
|
||||
|
||||
this.setupTarget(targetFront);
|
||||
},
|
||||
|
||||
onTargetDestroyed({ targetFront, isTopLevel }) {
|
||||
if (!isTopLevel) {
|
||||
onTargetDestroyed({ targetFront }) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return; // ignore target frames that are not top level for now
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,9 @@ export async function onConnect(
|
||||
|
||||
async function onTargetAvailable({
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
isTargetSwitching,
|
||||
}): Promise<void> {
|
||||
if (!isTopLevel) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,8 +90,8 @@ async function onTargetAvailable({
|
||||
await clientCommands.checkIfAlreadyPaused();
|
||||
}
|
||||
|
||||
function onTargetDestroyed({ targetFront, isTopLevel }): void {
|
||||
if (isTopLevel) {
|
||||
function onTargetDestroyed({ targetFront }): void {
|
||||
if (targetFront.isTopLevel) {
|
||||
targetFront.off("will-navigate", actions.willNavigate);
|
||||
targetFront.off("navigate", actions.navigated);
|
||||
removeEventsTopTarget(targetFront);
|
||||
|
@ -130,9 +130,9 @@ DomPanel.prototype = {
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
onTargetAvailable: function({ isTopLevel, isTargetSwitching }) {
|
||||
onTargetAvailable: function({ targetFront }) {
|
||||
// Only care about top-level targets.
|
||||
if (!isTopLevel) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -722,8 +722,8 @@ Toolbox.prototype = {
|
||||
* This method will be called for the top-level target, as well as any potential
|
||||
* additional targets we may care about.
|
||||
*/
|
||||
async _onTargetAvailable({ type, targetFront, isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
// Attach to a new top-level target.
|
||||
// For now, register these event listeners only on the top level target
|
||||
targetFront.on("will-navigate", this._onWillNavigate);
|
||||
@ -736,19 +736,19 @@ Toolbox.prototype = {
|
||||
});
|
||||
}
|
||||
|
||||
await this._attachTarget({ type, targetFront, isTopLevel });
|
||||
await this._attachTarget(targetFront);
|
||||
|
||||
if (this.hostType !== Toolbox.HostType.PAGE) {
|
||||
await this.store.dispatch(registerTarget(targetFront));
|
||||
}
|
||||
|
||||
if (isTopLevel) {
|
||||
if (targetFront.isTopLevel) {
|
||||
this.emit("top-target-attached");
|
||||
}
|
||||
},
|
||||
|
||||
_onTargetDestroyed({ type, targetFront, isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
_onTargetDestroyed({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
this.detachTarget();
|
||||
}
|
||||
|
||||
@ -764,7 +764,7 @@ Toolbox.prototype = {
|
||||
* And we listen for thread actor events in order to update toolbox UI when
|
||||
* we hit a breakpoint.
|
||||
*/
|
||||
async _attachTarget({ type, targetFront, isTopLevel }) {
|
||||
async _attachTarget(targetFront) {
|
||||
await targetFront.attach();
|
||||
|
||||
// Start tracking network activity on toolbox open for targets such as tabs.
|
||||
@ -775,10 +775,13 @@ Toolbox.prototype = {
|
||||
// already tracked by the content process targets. At least in the context
|
||||
// of the Browser Toolbox.
|
||||
// We would have to revisit that for the content toolboxes.
|
||||
if (isTopLevel || type != TargetList.TYPES.FRAME) {
|
||||
if (
|
||||
targetFront.isTopLevel ||
|
||||
targetFront.targetType != TargetList.TYPES.FRAME
|
||||
) {
|
||||
const threadFront = await this._attachAndResumeThread(targetFront);
|
||||
this._startThreadFrontListeners(threadFront);
|
||||
if (isTopLevel) {
|
||||
if (targetFront.isTopLevel) {
|
||||
this._threadFront = threadFront;
|
||||
}
|
||||
}
|
||||
|
@ -445,8 +445,8 @@ class AnimationInspector {
|
||||
this.inspector.store.dispatch(updateSidebarSize(size));
|
||||
}
|
||||
|
||||
async onTargetAvailable({ isTopLevel, targetFront }) {
|
||||
if (isTopLevel) {
|
||||
async onTargetAvailable({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
this.animationsFront = await targetFront.getFront("animations");
|
||||
this.animationsFront.setWalkerActor(this.inspector.walker);
|
||||
this.animationsFront.on("mutations", this.onAnimationsMutation);
|
||||
|
@ -126,26 +126,26 @@ class ChangesView {
|
||||
changesFront.off("clear-changes", this.onClearChanges);
|
||||
}
|
||||
|
||||
async onTargetAvailable({ type, targetFront, isTopLevel }) {
|
||||
async onTargetAvailable({ targetFront }) {
|
||||
targetFront.watchFronts(
|
||||
"changes",
|
||||
this.onChangesFrontAvailable,
|
||||
this.onChangesFrontDestroyed
|
||||
);
|
||||
|
||||
if (isTopLevel) {
|
||||
if (targetFront.isTopLevel) {
|
||||
targetFront.on("will-navigate", this.onClearChanges);
|
||||
}
|
||||
}
|
||||
|
||||
async onTargetDestroyed({ type, targetFront, isTopLevel }) {
|
||||
async onTargetDestroyed({ targetFront }) {
|
||||
targetFront.unwatchFronts(
|
||||
"changes",
|
||||
this.onChangesFrontAvailable,
|
||||
this.onChangesFrontDestroyed
|
||||
);
|
||||
|
||||
if (isTopLevel) {
|
||||
if (targetFront.isTopLevel) {
|
||||
targetFront.off("will-navigate", this.onClearChanges);
|
||||
}
|
||||
}
|
||||
|
@ -213,9 +213,9 @@ Inspector.prototype = {
|
||||
return this._deferredOpen();
|
||||
},
|
||||
|
||||
async _onTargetAvailable({ type, targetFront, isTopLevel }) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
// Ignore all targets but the top level one
|
||||
if (!isTopLevel) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -229,9 +229,9 @@ Inspector.prototype = {
|
||||
]);
|
||||
},
|
||||
|
||||
_onTargetDestroyed({ type, targetFront, isTopLevel }) {
|
||||
_onTargetDestroyed({ targetFront }) {
|
||||
// Ignore all targets but the top level one
|
||||
if (!isTopLevel) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
targetFront.off("will-navigate", this._onBeforeNavigate);
|
||||
|
@ -59,7 +59,7 @@ class WalkerEventListener {
|
||||
);
|
||||
}
|
||||
|
||||
async _onTargetAvailable({ type, targetFront, isTopLevel }) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
const inspectorFront = await targetFront.getFront("inspector");
|
||||
const { walker } = inspectorFront;
|
||||
for (const [name, listener] of Object.entries(this._listenerMap)) {
|
||||
@ -67,7 +67,7 @@ class WalkerEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
_onTargetDestroyed({ type, targetFront, isTopLevel }) {
|
||||
_onTargetDestroyed({ targetFront }) {
|
||||
const inspectorFront = targetFront.getCachedFront("inspector");
|
||||
if (inspectorFront) {
|
||||
const { walker } = inspectorFront;
|
||||
|
@ -44,8 +44,8 @@ MemoryPanel.prototype = {
|
||||
return this;
|
||||
},
|
||||
|
||||
async _onTargetAvailable({ targetFront, isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
const front = await targetFront.getFront("memory");
|
||||
await front.attach();
|
||||
this.initializer.updateFront(front);
|
||||
|
@ -117,8 +117,8 @@ class FirefoxConnector {
|
||||
await this.addListeners();
|
||||
}
|
||||
|
||||
async onTargetAvailable({ targetFront, isTopLevel, isTargetSwitching }) {
|
||||
if (!isTopLevel) {
|
||||
async onTargetAvailable({ targetFront, isTargetSwitching }) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -116,11 +116,9 @@ PerformancePanel.prototype = {
|
||||
* @param {TargetFront} - targetFront
|
||||
* As we are watching only FRAME type for this panel,
|
||||
* the target should be a instance of BrowsingContextTarget.
|
||||
* @param {Boolean} - isTopLevel
|
||||
* true if the target is a full page.
|
||||
*/
|
||||
async _handleTargetAvailable({ targetFront, isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
async _handleTargetAvailable({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
const { PerformanceController, PerformanceView } = this.panelWin;
|
||||
const performanceFront = await targetFront.getFront("performance");
|
||||
|
||||
|
@ -1177,8 +1177,8 @@ class ResponsiveUI {
|
||||
return this.browserWindow;
|
||||
}
|
||||
|
||||
async onTargetAvailable({ isTopLevel, targetFront }) {
|
||||
if (isTopLevel) {
|
||||
async onTargetAvailable({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
this.responsiveFront = await targetFront.getFront("responsive");
|
||||
await this.restoreActorState();
|
||||
}
|
||||
|
@ -279,10 +279,10 @@ class StorageUI {
|
||||
);
|
||||
}
|
||||
|
||||
async _onTargetAvailable({ type, targetFront, isTopLevel }) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
// Only support top level target and navigation to new processes.
|
||||
// i.e. ignore additional targets created for remote <iframes>
|
||||
if (!isTopLevel) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -324,10 +324,10 @@ class StorageUI {
|
||||
}
|
||||
}
|
||||
|
||||
_onTargetDestroyed({ type, targetFront, isTopLevel }) {
|
||||
_onTargetDestroyed({ targetFront }) {
|
||||
// Only support top level target and navigation to new processes.
|
||||
// i.e. ignore additional targets created for remote <iframes>
|
||||
if (!isTopLevel) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1133,8 +1133,8 @@ StyleEditorUI.prototype = {
|
||||
this.selectStyleSheet(source, location.line - 1, location.column - 1);
|
||||
},
|
||||
|
||||
async _onTargetAvailable({ targetFront, isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
await this.initializeHighlighter(targetFront);
|
||||
|
||||
const stylesheetsFront = await targetFront.getFront("stylesheets");
|
||||
@ -1146,8 +1146,8 @@ StyleEditorUI.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
async _onTargetDestroyed({ isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
async _onTargetDestroyed({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
this._clear();
|
||||
}
|
||||
},
|
||||
|
@ -373,34 +373,25 @@ class WebConsoleUI {
|
||||
* i.e. it was already existing or has just been created.
|
||||
*
|
||||
* @private
|
||||
* @param string type
|
||||
* One of the string of TargetList.TYPES to describe which
|
||||
* type of target is available.
|
||||
* @param Front targetFront
|
||||
* The Front of the target that is available.
|
||||
* This Front inherits from TargetMixin and is typically
|
||||
* composed of a BrowsingContextTargetFront or ContentProcessTargetFront.
|
||||
* @param boolean isTopLevel
|
||||
* If true, means that this is the top level target.
|
||||
* This typically happens on startup, providing the current
|
||||
* top level target. But also on navigation, when we navigate
|
||||
* to an URL which has to be loaded in a distinct process.
|
||||
* A new top level target is created.
|
||||
*/
|
||||
async _onTargetAvailable({ type, targetFront, isTopLevel }) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
const dispatchTargetAvailable = () => {
|
||||
const store = this.wrapper && this.wrapper.getStore();
|
||||
if (store) {
|
||||
this.wrapper.getStore().dispatch({
|
||||
type: constants.TARGET_AVAILABLE,
|
||||
targetType: type,
|
||||
targetType: targetFront.targetType,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// This is a top level target. It may update on process switches
|
||||
// when navigating to another domain.
|
||||
if (isTopLevel) {
|
||||
if (targetFront.isTopLevel) {
|
||||
const fissionSupport = Services.prefs.getBoolPref(
|
||||
constants.PREFS.FEATURES.BROWSER_TOOLBOX_FISSION
|
||||
);
|
||||
@ -425,8 +416,9 @@ class WebConsoleUI {
|
||||
isContentToolbox &&
|
||||
Services.prefs.getBoolPref("devtools.contenttoolbox.fission");
|
||||
if (
|
||||
type != this.hud.targetList.TYPES.PROCESS &&
|
||||
(type != this.hud.targetList.TYPES.FRAME || !listenForFrames)
|
||||
targetFront.targetType != this.hud.targetList.TYPES.PROCESS &&
|
||||
(targetFront.targetType != this.hud.targetList.TYPES.FRAME ||
|
||||
!listenForFrames)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@ -442,8 +434,8 @@ class WebConsoleUI {
|
||||
* @private
|
||||
* See _onTargetAvailable for param's description.
|
||||
*/
|
||||
_onTargetDestroyed({ type, targetFront, isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
_onTargetDestroyed({ targetFront }) {
|
||||
if (targetFront.isTopLevel) {
|
||||
this.proxy.disconnect();
|
||||
this.proxy = null;
|
||||
} else {
|
||||
|
@ -6,9 +6,7 @@
|
||||
|
||||
module.exports = async function({
|
||||
targetList,
|
||||
targetType,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
isFissionEnabledOnContentToolbox,
|
||||
onAvailable,
|
||||
}) {
|
||||
@ -20,9 +18,9 @@ module.exports = async function({
|
||||
const isContentToolbox = targetList.targetFront.isLocalTab;
|
||||
const listenForFrames = isContentToolbox && isFissionEnabledOnContentToolbox;
|
||||
const isAllowed =
|
||||
isTopLevel ||
|
||||
targetType === targetList.TYPES.PROCESS ||
|
||||
(targetType === targetList.TYPES.FRAME && listenForFrames);
|
||||
targetFront.isTopLevel ||
|
||||
targetFront.targetType === targetList.TYPES.PROCESS ||
|
||||
(targetFront.targetType === targetList.TYPES.FRAME && listenForFrames);
|
||||
|
||||
if (!isAllowed) {
|
||||
return;
|
||||
|
@ -6,9 +6,7 @@
|
||||
|
||||
module.exports = async function({
|
||||
targetList,
|
||||
targetType,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
isFissionEnabledOnContentToolbox,
|
||||
onAvailable,
|
||||
}) {
|
||||
@ -20,9 +18,9 @@ module.exports = async function({
|
||||
const isContentToolbox = targetList.targetFront.isLocalTab;
|
||||
const listenForFrames = isContentToolbox && isFissionEnabledOnContentToolbox;
|
||||
const isAllowed =
|
||||
isTopLevel ||
|
||||
targetType === targetList.TYPES.PROCESS ||
|
||||
(targetType === targetList.TYPES.FRAME && listenForFrames);
|
||||
targetFront.isTopLevel ||
|
||||
targetFront.targetType === targetList.TYPES.PROCESS ||
|
||||
(targetFront.targetType === targetList.TYPES.FRAME && listenForFrames);
|
||||
|
||||
if (!isAllowed) {
|
||||
return;
|
||||
|
@ -4,17 +4,13 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = async function({
|
||||
targetList,
|
||||
targetType,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
onAvailable,
|
||||
}) {
|
||||
module.exports = async function({ targetList, targetFront, onAvailable }) {
|
||||
// Only allow the top level target and processes.
|
||||
// Frames can be ignored as logMessage are never sent to them anyway.
|
||||
// Also ignore workers as they are not supported yet. (see bug 1592584)
|
||||
const isAllowed = isTopLevel || targetType === targetList.TYPES.PROCESS;
|
||||
const isAllowed =
|
||||
targetFront.isTopLevel ||
|
||||
targetFront.targetType === targetList.TYPES.PROCESS;
|
||||
if (!isAllowed) {
|
||||
return;
|
||||
}
|
||||
|
@ -4,14 +4,8 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = async function({
|
||||
targetList,
|
||||
targetType,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
onAvailable,
|
||||
}) {
|
||||
if (!isTopLevel) {
|
||||
module.exports = async function({ targetList, targetFront, onAvailable }) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -136,21 +136,12 @@ class ResourceWatcher {
|
||||
/**
|
||||
* Method called by the TargetList for each already existing or target which has just been created.
|
||||
*
|
||||
* @param {string} type
|
||||
* One of the string of TargetList.TYPES to describe which
|
||||
* type of target is available.
|
||||
* @param {Front} targetFront
|
||||
* The Front of the target that is available.
|
||||
* This Front inherits from TargetMixin and is typically
|
||||
* composed of a BrowsingContextTargetFront or ContentProcessTargetFront.
|
||||
* @param {boolean} isTopLevel
|
||||
* If true, means that this is the top level target.
|
||||
* This typically happens on startup, providing the current
|
||||
* top level target. But also on navigation, when we navigate
|
||||
* to an URL which has to be loaded in a distinct process.
|
||||
* A new top level target is created.
|
||||
*/
|
||||
async _onTargetAvailable({ type, targetFront, isTopLevel }) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
// For each resource type...
|
||||
for (const resourceType of Object.values(ResourceWatcher.TYPES)) {
|
||||
// ...which has at least one listener...
|
||||
@ -158,12 +149,7 @@ class ResourceWatcher {
|
||||
continue;
|
||||
}
|
||||
// ...request existing resource and new one to come from this one target
|
||||
await this._watchResourcesForTarget(
|
||||
type,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
resourceType
|
||||
);
|
||||
await this._watchResourcesForTarget(targetFront, resourceType);
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +157,7 @@ class ResourceWatcher {
|
||||
* Method called by the TargetList when a target has just been destroyed
|
||||
* See _onTargetAvailable for arguments, they are the same.
|
||||
*/
|
||||
_onTargetDestroyed({ type, targetFront }) {
|
||||
_onTargetDestroyed({ targetFront }) {
|
||||
//TODO: Is there a point in doing anything?
|
||||
//
|
||||
// We could remove the available/destroyed event, but as the target is destroyed
|
||||
@ -269,14 +255,7 @@ class ResourceWatcher {
|
||||
for (const targetType of this.targetList.ALL_TYPES) {
|
||||
// XXX: May be expose a getReallyAllTarget() on TargetList?
|
||||
for (const target of this.targetList.getAllTargets(targetType)) {
|
||||
promises.push(
|
||||
this._watchResourcesForTarget(
|
||||
targetType,
|
||||
target,
|
||||
target == this.targetList.targetFront,
|
||||
resourceType
|
||||
)
|
||||
);
|
||||
promises.push(this._watchResourcesForTarget(target, resourceType));
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
@ -286,7 +265,7 @@ class ResourceWatcher {
|
||||
* Call backward compatibility code from `LegacyListeners` in order to listen for a given
|
||||
* type of resource from a given target.
|
||||
*/
|
||||
_watchResourcesForTarget(targetType, targetFront, isTopLevel, resourceType) {
|
||||
_watchResourcesForTarget(targetFront, resourceType) {
|
||||
const onAvailable = this._onResourceAvailable.bind(
|
||||
this,
|
||||
targetFront,
|
||||
@ -294,9 +273,7 @@ class ResourceWatcher {
|
||||
);
|
||||
return LegacyListeners[resourceType]({
|
||||
targetList: this.targetList,
|
||||
targetType,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
isFissionEnabledOnContentToolbox: this.contentToolboxFissionPrefValue,
|
||||
onAvailable,
|
||||
});
|
||||
@ -367,13 +344,11 @@ const LegacyListeners = {
|
||||
.PLATFORM_MESSAGES]: require("devtools/shared/resources/legacy-listeners/platform-messages"),
|
||||
async [ResourceWatcher.TYPES.DOCUMENT_EVENTS]({
|
||||
targetList,
|
||||
targetType,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
onAvailable,
|
||||
}) {
|
||||
// DocumentEventsListener of webconsole handles only top level document.
|
||||
if (!isTopLevel) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -127,28 +127,22 @@ class TargetList {
|
||||
|
||||
// Map the descriptor typeName to a target type.
|
||||
const targetType = this.getTargetType(targetFront);
|
||||
const isTopLevel = targetFront == this.targetFront;
|
||||
|
||||
targetFront.setTargetType(targetType);
|
||||
targetFront.setIsTopLevel(isTopLevel);
|
||||
targetFront.setIsTopLevel(targetFront == this.targetFront);
|
||||
|
||||
this._targets.add(targetFront);
|
||||
|
||||
// Notify the target front creation listeners
|
||||
await this._createListeners.emitAsync(targetType, {
|
||||
type: targetType,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
isTargetSwitching,
|
||||
});
|
||||
}
|
||||
|
||||
_onTargetDestroyed(targetFront, isTargetSwitching = false) {
|
||||
const targetType = targetFront.targetType;
|
||||
this._destroyListeners.emit(targetType, {
|
||||
type: targetType,
|
||||
this._destroyListeners.emit(targetFront.targetType, {
|
||||
targetFront,
|
||||
isTopLevel: targetFront.isTopLevel,
|
||||
isTargetSwitching,
|
||||
});
|
||||
this._targets.delete(targetFront);
|
||||
@ -301,10 +295,8 @@ class TargetList {
|
||||
* The type of target to listen for. Constant of TargetList.TYPES.
|
||||
* @param {Function} onAvailable
|
||||
* Callback fired when a target has been just created or was already available.
|
||||
* The function is called with three arguments:
|
||||
* - {String} type: The target type
|
||||
* The function is called with the following arguments:
|
||||
* - {TargetFront} targetFront: The target Front
|
||||
* - {Boolean} isTopLevel: Is this target the top level one?
|
||||
* - {Boolean} isTargetSwitching: Is this target relates to a navigation and
|
||||
* this replaced a previously available target, this flag will be true
|
||||
* @param {Function} onDestroy
|
||||
@ -327,9 +319,7 @@ class TargetList {
|
||||
// which may setup things regarding the existing targets
|
||||
// and listen callsite may care about the full initialization
|
||||
await onAvailable({
|
||||
type: targetFront.targetType,
|
||||
targetFront,
|
||||
isTopLevel: targetFront == this.targetFront,
|
||||
isTargetSwitching: false,
|
||||
});
|
||||
} catch (e) {
|
||||
|
@ -61,15 +61,15 @@ async function testBrowserFrames(mainRoot) {
|
||||
|
||||
// Assert that watchTargets will call the create callback for all existing frames
|
||||
const targets = [];
|
||||
const onAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable = ({ targetFront }) => {
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.FRAME,
|
||||
"We are only notified about frame targets"
|
||||
);
|
||||
ok(
|
||||
targetFront == target ? isTopLevel : !isTopLevel,
|
||||
"isTopLevel argument is correct"
|
||||
targetFront == target ? targetFront.isTopLevel : !targetFront.isTopLevel,
|
||||
"isTopLevel property is correct"
|
||||
);
|
||||
targets.push(targetFront);
|
||||
};
|
||||
@ -125,15 +125,15 @@ async function testTabFrames(mainRoot) {
|
||||
|
||||
// Assert that watchTargets will call the create callback for all existing frames
|
||||
const targets = [];
|
||||
const onAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable = ({ targetFront }) => {
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.FRAME,
|
||||
"We are only notified about frame targets"
|
||||
);
|
||||
ok(
|
||||
targetFront == target ? isTopLevel : !isTopLevel,
|
||||
"isTopLevel argument is correct"
|
||||
targetFront == target ? targetFront.isTopLevel : !targetFront.isTopLevel,
|
||||
"isTopLevel property is correct"
|
||||
);
|
||||
targets.push(targetFront);
|
||||
};
|
||||
|
@ -60,7 +60,7 @@ async function testPreffedOffMainProcess(mainRoot, mainProcess) {
|
||||
);
|
||||
|
||||
const processTargets = [];
|
||||
const onProcessAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onProcessAvailable = ({ targetFront }) => {
|
||||
processTargets.push(targetFront);
|
||||
};
|
||||
await targetList.watchTargets([TargetList.TYPES.PROCESS], onProcessAvailable);
|
||||
@ -68,13 +68,16 @@ async function testPreffedOffMainProcess(mainRoot, mainProcess) {
|
||||
targetList.unwatchTargets([TargetList.TYPES.PROCESS], onProcessAvailable);
|
||||
|
||||
const frameTargets = [];
|
||||
const onFrameAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onFrameAvailable = ({ targetFront }) => {
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.FRAME,
|
||||
"We are only notified about frame targets"
|
||||
);
|
||||
ok(isTopLevel, "We are only notified about the top level target");
|
||||
ok(
|
||||
targetFront.isTopLevel,
|
||||
"We are only notified about the top level target"
|
||||
);
|
||||
frameTargets.push(targetFront);
|
||||
};
|
||||
await targetList.watchTargets([TargetList.TYPES.FRAME], onFrameAvailable);
|
||||
@ -123,13 +126,16 @@ async function testPreffedOffTab(mainRoot) {
|
||||
targetList.unwatchTargets([TargetList.TYPES.PROCESS], onProcessAvailable);
|
||||
|
||||
const frameTargets = [];
|
||||
const onFrameAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onFrameAvailable = ({ targetFront }) => {
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.FRAME,
|
||||
"We are only notified about frame targets"
|
||||
);
|
||||
ok(isTopLevel, "We are only notified about the top level target");
|
||||
ok(
|
||||
targetFront.isTopLevel,
|
||||
"We are only notified about the top level target"
|
||||
);
|
||||
frameTargets.push(targetFront);
|
||||
};
|
||||
await targetList.watchTargets([TargetList.TYPES.FRAME], onFrameAvailable);
|
||||
|
@ -62,22 +62,22 @@ async function testProcesses(targetList, target) {
|
||||
|
||||
// Assert that watchTargets will call the create callback for all existing frames
|
||||
const targets = new Set();
|
||||
const onAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable = ({ targetFront }) => {
|
||||
if (targets.has(targetFront)) {
|
||||
ok(false, "The same target is notified multiple times via onAvailable");
|
||||
}
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.PROCESS,
|
||||
"We are only notified about process targets"
|
||||
);
|
||||
ok(
|
||||
targetFront == target ? isTopLevel : !isTopLevel,
|
||||
"isTopLevel argument is correct"
|
||||
targetFront == target ? targetFront.isTopLevel : !targetFront.isTopLevel,
|
||||
"isTopLevel property is correct"
|
||||
);
|
||||
targets.add(targetFront);
|
||||
};
|
||||
const onDestroyed = ({ type, targetFront, isTopLevel }) => {
|
||||
const onDestroyed = ({ targetFront }) => {
|
||||
if (!targets.has(targetFront)) {
|
||||
ok(
|
||||
false,
|
||||
@ -85,12 +85,12 @@ async function testProcesses(targetList, target) {
|
||||
);
|
||||
}
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.PROCESS,
|
||||
"We are only notified about process targets"
|
||||
);
|
||||
ok(
|
||||
!isTopLevel,
|
||||
!targetFront.isTopLevel,
|
||||
"We are never notified about the top level target destruction"
|
||||
);
|
||||
targets.delete(targetFront);
|
||||
@ -115,7 +115,7 @@ async function testProcesses(targetList, target) {
|
||||
const previousTargets = new Set(targets);
|
||||
// Assert that onAvailable is called for processes created *after* the call to watchTargets
|
||||
const onProcessCreated = new Promise(resolve => {
|
||||
const onAvailable2 = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable2 = ({ targetFront }) => {
|
||||
if (previousTargets.has(targetFront)) {
|
||||
return;
|
||||
}
|
||||
@ -139,7 +139,7 @@ async function testProcesses(targetList, target) {
|
||||
// Assert that onDestroyed is called for destroyed processes
|
||||
const onProcessDestroyed = new Promise(resolve => {
|
||||
const onAvailable3 = () => {};
|
||||
const onDestroyed3 = ({ type, targetFront, isTopLevel }) => {
|
||||
const onDestroyed3 = ({ targetFront }) => {
|
||||
resolve(targetFront);
|
||||
targetList.unwatchTargets(
|
||||
[TargetList.TYPES.PROCESS],
|
||||
|
@ -47,22 +47,19 @@ async function testSwitchToTarget(client) {
|
||||
|
||||
const frameTargets = [];
|
||||
let currentTarget = firstTarget;
|
||||
const onFrameAvailable = ({
|
||||
type,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
isTargetSwitching,
|
||||
}) => {
|
||||
const onFrameAvailable = ({ targetFront, isTargetSwitching }) => {
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.FRAME,
|
||||
"We are only notified about frame targets"
|
||||
);
|
||||
ok(
|
||||
targetFront == currentTarget ? isTopLevel : !isTopLevel,
|
||||
"isTopLevel argument is correct"
|
||||
targetFront == currentTarget
|
||||
? targetFront.isTopLevel
|
||||
: !targetFront.isTopLevel,
|
||||
"isTopLevel property is correct"
|
||||
);
|
||||
if (isTopLevel) {
|
||||
if (targetFront.isTopLevel) {
|
||||
// When calling watchTargets, this will be false, but it will be true when calling switchToTarget
|
||||
is(
|
||||
isTargetSwitching,
|
||||
@ -75,22 +72,19 @@ async function testSwitchToTarget(client) {
|
||||
frameTargets.push(targetFront);
|
||||
};
|
||||
const destroyedTargets = [];
|
||||
const onFrameDestroyed = ({
|
||||
type,
|
||||
targetFront,
|
||||
isTopLevel,
|
||||
isTargetSwitching,
|
||||
}) => {
|
||||
const onFrameDestroyed = ({ targetFront, isTargetSwitching }) => {
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.FRAME,
|
||||
"target-destroyed: We are only notified about frame targets"
|
||||
);
|
||||
ok(
|
||||
targetFront == firstTarget ? isTopLevel : !isTopLevel,
|
||||
"target-destroyed: isTopLevel argument is correct"
|
||||
targetFront == firstTarget
|
||||
? targetFront.isTopLevel
|
||||
: !targetFront.isTopLevel,
|
||||
"target-destroyed: isTopLevel property is correct"
|
||||
);
|
||||
if (isTopLevel) {
|
||||
if (targetFront.isTopLevel) {
|
||||
is(
|
||||
isTargetSwitching,
|
||||
true,
|
||||
|
@ -45,22 +45,22 @@ async function testWatchTargets(mainRoot) {
|
||||
"Check that onAvailable is called for processes already created *before* the call to watchTargets"
|
||||
);
|
||||
const targets = new Set();
|
||||
const onAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable = ({ targetFront }) => {
|
||||
if (targets.has(targetFront)) {
|
||||
ok(false, "The same target is notified multiple times via onAvailable");
|
||||
}
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.PROCESS,
|
||||
"We are only notified about process targets"
|
||||
);
|
||||
ok(
|
||||
targetFront == target ? isTopLevel : !isTopLevel,
|
||||
"isTopLevel argument is correct"
|
||||
targetFront == target ? targetFront.isTopLevel : !targetFront.isTopLevel,
|
||||
"isTopLevel property is correct"
|
||||
);
|
||||
targets.add(targetFront);
|
||||
};
|
||||
const onDestroyed = ({ type, targetFront, isTopLevel }) => {
|
||||
const onDestroyed = ({ targetFront }) => {
|
||||
if (!targets.has(targetFront)) {
|
||||
ok(
|
||||
false,
|
||||
@ -68,12 +68,12 @@ async function testWatchTargets(mainRoot) {
|
||||
);
|
||||
}
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.PROCESS,
|
||||
"We are only notified about process targets"
|
||||
);
|
||||
ok(
|
||||
!isTopLevel,
|
||||
!targetFront.isTopLevel,
|
||||
"We are not notified about the top level target destruction"
|
||||
);
|
||||
targets.delete(targetFront);
|
||||
@ -105,7 +105,7 @@ async function testWatchTargets(mainRoot) {
|
||||
);
|
||||
const previousTargets = new Set(targets);
|
||||
const onProcessCreated = new Promise(resolve => {
|
||||
const onAvailable2 = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable2 = ({ targetFront }) => {
|
||||
if (previousTargets.has(targetFront)) {
|
||||
return;
|
||||
}
|
||||
@ -130,7 +130,7 @@ async function testWatchTargets(mainRoot) {
|
||||
// Assert that onDestroyed is called for destroyed processes
|
||||
const onProcessDestroyed = new Promise(resolve => {
|
||||
const onAvailable3 = () => {};
|
||||
const onDestroyed3 = ({ type, targetFront, isTopLevel }) => {
|
||||
const onDestroyed3 = ({ targetFront }) => {
|
||||
resolve(targetFront);
|
||||
targetList.unwatchTargets(
|
||||
[TargetList.TYPES.PROCESS],
|
||||
@ -185,22 +185,25 @@ async function testContentProcessTarget(mainRoot) {
|
||||
// as listening for additional target is only enable for the parent process target.
|
||||
// See bug 1593928.
|
||||
const targets = new Set();
|
||||
const onAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable = ({ targetFront }) => {
|
||||
if (targets.has(targetFront)) {
|
||||
// This may fail if the top level target is reported by LegacyImplementation
|
||||
// to TargetList and emits an available event for it.
|
||||
ok(false, "The same target is notified multiple times via onAvailable");
|
||||
}
|
||||
is(
|
||||
type,
|
||||
targetFront.targetType,
|
||||
TargetList.TYPES.PROCESS,
|
||||
"We are only notified about process targets"
|
||||
);
|
||||
is(targetFront, target, "This is the existing top level target");
|
||||
ok(isTopLevel, "We are only notified about the top level target");
|
||||
ok(
|
||||
targetFront.isTopLevel,
|
||||
"We are only notified about the top level target"
|
||||
);
|
||||
targets.add(targetFront);
|
||||
};
|
||||
const onDestroyed = ({ type, targetFront, isTopLevel }) => {
|
||||
const onDestroyed = _ => {
|
||||
ok(false, "onDestroyed should never be called in this test");
|
||||
};
|
||||
await targetList.watchTargets(
|
||||
@ -235,7 +238,7 @@ async function testThrowingInOnAvailable(mainRoot) {
|
||||
);
|
||||
const targets = new Set();
|
||||
let thrown = false;
|
||||
const onAvailable = ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable = ({ targetFront }) => {
|
||||
if (!thrown) {
|
||||
thrown = true;
|
||||
throw new Error("Force an exception when processing the first target");
|
||||
|
@ -114,16 +114,16 @@ async function testBrowserWorkers(mainRoot) {
|
||||
"Check that watchTargets will call the create callback for all existing workers"
|
||||
);
|
||||
const targets = [];
|
||||
const onAvailable = async ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable = async ({ targetFront }) => {
|
||||
ok(
|
||||
type === TYPES.WORKER ||
|
||||
type === TYPES.SHARED_WORKER ||
|
||||
type === TYPES.SERVICE_WORKER,
|
||||
targetFront.targetType === TYPES.WORKER ||
|
||||
targetFront.targetType === TYPES.SHARED_WORKER ||
|
||||
targetFront.targetType === TYPES.SERVICE_WORKER,
|
||||
"We are only notified about worker targets"
|
||||
);
|
||||
ok(
|
||||
targetFront == target ? isTopLevel : !isTopLevel,
|
||||
"isTopLevel argument is correct"
|
||||
targetFront == target ? targetFront.isTopLevel : !targetFront.isTopLevel,
|
||||
"isTopLevel property is correct"
|
||||
);
|
||||
targets.push(targetFront);
|
||||
};
|
||||
@ -157,7 +157,7 @@ async function testBrowserWorkers(mainRoot) {
|
||||
|
||||
// Create a new worker and see if the worker target is reported
|
||||
const onWorkerCreated = new Promise(resolve => {
|
||||
const onAvailable2 = async ({ type, targetFront, isTopLevel }) => {
|
||||
const onAvailable2 = async ({ targetFront }) => {
|
||||
if (targets.includes(targetFront)) {
|
||||
return;
|
||||
}
|
||||
@ -213,9 +213,13 @@ async function testTabWorkers(mainRoot, tab) {
|
||||
|
||||
// Assert that watchTargets will call the create callback for all existing workers
|
||||
const targets = [];
|
||||
const onAvailable = async ({ type, targetFront, isTopLevel }) => {
|
||||
is(type, TYPES.WORKER, "We are only notified about worker targets");
|
||||
ok(!isTopLevel, "The workers are never top level");
|
||||
const onAvailable = async ({ targetFront }) => {
|
||||
is(
|
||||
targetFront.targetType,
|
||||
TYPES.WORKER,
|
||||
"We are only notified about worker targets"
|
||||
);
|
||||
ok(!targetFront.isTopLevel, "The workers are never top level");
|
||||
targets.push(targetFront);
|
||||
};
|
||||
await targetList.watchTargets([TYPES.WORKER], onAvailable);
|
||||
|
@ -787,8 +787,8 @@ class DevToolsExtensionPageContextParent extends ExtensionPageContextParent {
|
||||
super.shutdown();
|
||||
}
|
||||
|
||||
async _onTargetAvailable({ targetFront, isTopLevel }) {
|
||||
if (!isTopLevel) {
|
||||
async _onTargetAvailable({ targetFront }) {
|
||||
if (!targetFront.isTopLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user