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