Skip to content

Commit a29df5f

Browse files
committed
use the parent process descriptor instead of tab descriptors in Firefox 137
1 parent 8c32994 commit a29df5f

17 files changed

Lines changed: 217 additions & 95 deletions

src/adapter/adapter/addonManager.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { PreferenceActorProxy } from '../firefox/actorProxy/preference';
77
import { FirefoxDebugSession } from '../firefoxDebugSession';
88
import { PopupAutohideEventBody } from '../../common/customEvents';
99
import { isWindowsPlatform } from '../../common/util';
10-
import { TargetActorProxy } from '../firefox/actorProxy/target';
1110
import { DescriptorActorProxy } from '../firefox/actorProxy/descriptor';
1211

1312
const log = Log.create('AddonManager');
@@ -21,11 +20,12 @@ export const popupAutohidePreferenceKey = 'ui.popup.disable_autohide';
2120
*/
2221
export class AddonManager {
2322

23+
private resolveAddonId!: (addonId: string) => void;
24+
public readonly addonId = new Promise<string>(resolve => this.resolveAddonId = resolve);
25+
2426
private readonly config: ParsedAddonConfiguration;
2527

26-
private addonAttached = false;
2728
private descriptorActor: DescriptorActorProxy | undefined = undefined;
28-
private targetActor: TargetActorProxy | undefined = undefined;
2929

3030
constructor(
3131
private readonly debugSession: FirefoxDebugSession
@@ -41,11 +41,9 @@ export class AddonManager {
4141

4242
const addonPath = isWindowsPlatform() ? path.normalize(this.config.path) : this.config.path;
4343
let result = await addonsActor.installAddon(addonPath);
44-
if (!this.config.id) {
45-
this.config.id = result.addon.id;
46-
}
44+
this.resolveAddonId(result.addon.id);
4745

48-
this.fetchAddonsAndAttach(rootActor);
46+
await this.fetchDescriptor(rootActor);
4947

5048
if (this.config.popupAutohideButton) {
5149
const popupAutohide = !(await preferenceActor.getBoolPref(popupAutohidePreferenceKey));
@@ -54,34 +52,29 @@ export class AddonManager {
5452
}
5553

5654
public async reloadAddon(): Promise<void> {
57-
if (!this.targetActor) {
55+
if (!this.descriptorActor) {
5856
throw 'Addon isn\'t attached';
5957
}
6058

61-
await this.descriptorActor?.reload();
59+
await this.descriptorActor.reload();
6260
}
6361

64-
private async fetchAddonsAndAttach(rootActor: RootActorProxy): Promise<void> {
65-
66-
if (this.addonAttached) return;
67-
68-
let addons = await rootActor.fetchAddons();
69-
70-
if (this.addonAttached) return;
71-
72-
addons.forEach((addon) => {
73-
if (addon.id === this.config.id) {
74-
(async () => {
62+
private async fetchDescriptor(rootActor: RootActorProxy): Promise<void> {
7563

76-
this.descriptorActor = new DescriptorActorProxy(
77-
addon.actor,
78-
this.debugSession.firefoxDebugConnection
79-
);
64+
const addons = await rootActor.fetchAddons();
8065

81-
await this.debugSession.attachDescriptor(this.descriptorActor, false);
66+
addons.forEach(async addon => {
67+
if (addon.id === await this.addonId) {
68+
this.descriptorActor = new DescriptorActorProxy(
69+
addon.actor,
70+
'webExtension',
71+
this.debugSession.firefoxDebugConnection
72+
);
8273

83-
this.addonAttached = true;
84-
})();
74+
if (!this.debugSession.processDescriptorMode) {
75+
const adapter = await this.debugSession.attachDescriptor(this.descriptorActor);
76+
await adapter.watcherActor.watchResources(['console-message', 'error-message', 'source', 'thread-state']);
77+
}
8578
}
8679
});
8780
}

src/adapter/adapter/descriptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class DescriptorAdapter {
1717
private readonly configurators: Registry<ThreadConfigurationActorProxy>,
1818
private readonly breakpointLists: Registry<BreakpointListActorProxy>,
1919
public readonly descriptorActor: DescriptorActorProxy,
20-
private readonly watcherActor: WatcherActorProxy,
20+
public readonly watcherActor: WatcherActorProxy,
2121
private readonly configurator: ThreadConfigurationActorProxy,
2222
private readonly breakpointList: BreakpointListActorProxy
2323
) {

src/adapter/adapter/thread.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { ISourceActorProxy } from '../firefox/actorProxy/source';
1414

1515
let log = Log.create('ThreadAdapter');
1616

17+
export type TargetType = 'tab' | 'iframe' | 'worker' | 'backgroundScript' | 'contentScript';
18+
1719
/**
1820
* Adapter class for a thread
1921
*/
@@ -23,6 +25,9 @@ export class ThreadAdapter extends EventEmitter {
2325
public get actorName() {
2426
return this.actor.name;
2527
}
28+
public get url(): string | undefined {
29+
return this.targetActor.target.url;
30+
}
2631

2732
/**
2833
* All `SourceAdapter`s for this thread. They will be disposed when this `ThreadAdapter` is disposed.
@@ -54,11 +59,11 @@ export class ThreadAdapter extends EventEmitter {
5459
public threadPausedReason?: FirefoxDebugProtocol.ThreadPausedReason;
5560

5661
public constructor(
62+
public readonly type: TargetType,
63+
public readonly name: string,
5764
public readonly actor: IThreadActorProxy,
5865
public readonly targetActor: TargetActorProxy,
5966
private readonly consoleActor: ConsoleActorProxy,
60-
public readonly name: string,
61-
public readonly url: string | undefined,
6267
public readonly debugSession: FirefoxDebugSession
6368
) {
6469
super();

src/adapter/firefox/actorProxy/descriptor.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,29 @@ import { WatcherActorProxy } from './watcher';
55

66
let log = Log.create('DescriptorActorProxy');
77

8+
export type DescriptorType = 'tab' | 'webExtension' | 'process';
9+
810
/**
911
* Proxy class for a TabDescriptor or WebExtensionDescriptor actor
1012
*/
1113
export class DescriptorActorProxy extends BaseActorProxy {
1214

13-
constructor(name: string, connection: DebugConnection) {
15+
constructor(
16+
name: string,
17+
public readonly type: DescriptorType,
18+
connection: DebugConnection
19+
) {
1420
super(name, connection, log);
1521
}
1622

1723
public async getWatcher(): Promise<WatcherActorProxy> {
1824
return await this.sendCachedRequest(
1925
'getWatcher',
20-
{ type: 'getWatcher', isServerTargetSwitchingEnabled: true, isPopupDebuggingEnabled: false },
26+
{ type: 'getWatcher',
27+
enableWindowGlobalThreadActors: this.type === 'process' ? true : undefined,
28+
isServerTargetSwitchingEnabled: this.type !== 'process' ? true : undefined,
29+
isPopupDebuggingEnabled: this.type === 'tab' ? false : undefined,
30+
},
2131
(response: FirefoxDebugProtocol.GetWatcherResponse) =>
2232
new WatcherActorProxy(response.actor, !!response.traits.content_script, this.connection)
2333
);

src/adapter/firefox/actorProxy/root.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ export class RootActorProxy extends BaseActorProxy {
5858
};
5959
}
6060

61+
public async getProcess(id: number): Promise<DescriptorActorProxy> {
62+
return this.sendCachedRequest(
63+
`getProcess(${id})`,
64+
{ type: 'getProcess', id },
65+
(response: FirefoxDebugProtocol.GetProcessResponse) =>
66+
new DescriptorActorProxy(response.processDescriptor.actor, 'process', this.connection)
67+
)
68+
}
69+
6170
public async fetchTabs(): Promise<Map<string, DescriptorActorProxy>> {
6271
let tabsResponse: FirefoxDebugProtocol.TabsResponse = await this.sendRequest({ type: 'listTabs' });
6372
while (tabsResponse.tabs.length === 0) {
@@ -80,7 +89,7 @@ export class RootActorProxy extends BaseActorProxy {
8089

8190
log.debug(`Tab ${tab.actor} opened`);
8291

83-
tabDescriptorActor = new DescriptorActorProxy(tab.actor, this.connection);
92+
tabDescriptorActor = new DescriptorActorProxy(tab.actor, 'tab', this.connection);
8493

8594
this.emit('tabOpened', tabDescriptorActor);
8695
}

src/adapter/firefox/actorProxy/target.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export class TargetActorProxy extends BaseActorProxy {
1616
super(target.actor, connection, log);
1717
}
1818

19+
public reload() {
20+
return this.sendRequest({ type: 'reload' });
21+
}
22+
1923
public onConsoleMessages(cb: (consoleMessages: FirefoxDebugProtocol.ConsoleMessage[]) => void) {
2024
this.on('console-message', cb);
2125
}

src/adapter/firefox/actorProxy/watcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class WatcherActorProxy extends BaseActorProxy {
4747
await this.sendRequest({ type: 'watchTargets', targetType });
4848
}
4949

50-
public onTargetAvailable(cb: (target: [TargetActorProxy, IThreadActorProxy, ConsoleActorProxy, string | undefined]) => void) {
50+
public onTargetAvailable(cb: (target: [TargetActorProxy, IThreadActorProxy, ConsoleActorProxy]) => void) {
5151
this.on('targetAvailable', cb);
5252
}
5353

@@ -61,7 +61,7 @@ export class WatcherActorProxy extends BaseActorProxy {
6161
const threadActorProxy = new ThreadActorProxy(event.target.threadActor, this.connection);
6262
const sourcemappingThreadActorProxy = new SourceMappingThreadActorProxy(threadActorProxy, this.connection);
6363
const consoleActorProxy = new ConsoleActorProxy(event.target.consoleActor, this.connection);
64-
this.emit('targetAvailable', [targetActorProxy, sourcemappingThreadActorProxy, consoleActorProxy, event.target.url]);
64+
this.emit('targetAvailable', [targetActorProxy, sourcemappingThreadActorProxy, consoleActorProxy]);
6565
} else if (event.type === 'target-destroyed-form') {
6666
this.emit('targetDestroyed', event.target.actor);
6767
} else {

src/adapter/firefox/protocol.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ declare namespace FirefoxDebugProtocol {
3535
watchpoints?: boolean,
3636
webExtensionAddonConnect?: boolean,
3737
noPauseOnThreadActorAttach?: boolean
38+
supportsEnableWindowGlobalThreadActors?: boolean
3839
};
3940
}
4041

@@ -44,6 +45,21 @@ declare namespace FirefoxDebugProtocol {
4445
deviceActor: string;
4546
}
4647

48+
interface GetProcessResponse {
49+
processDescriptor: ProcessDescriptor;
50+
}
51+
52+
interface ProcessDescriptor {
53+
actor: string;
54+
id: number;
55+
isParent: boolean;
56+
isWindowlessParent: boolean;
57+
traits: {
58+
watcher: boolean;
59+
supportsReloadDescriptor: boolean;
60+
}
61+
}
62+
4763
interface TabsResponse extends Response {
4864
tabs: (Tab | TabDescriptor)[];
4965
}
@@ -354,13 +370,24 @@ declare namespace FirefoxDebugProtocol {
354370
}
355371

356372
interface TargetAvailableEvent extends Event {
373+
type: 'target-available-form';
357374
target: {
358375
url?: string;
359376
actor: string;
360377
consoleActor: string;
361378
threadActor: string;
379+
targetType?: 'process' | 'frame' | 'worker' | 'shared_worker' | 'service_worker' | 'content_script';
362380
isTopLevelTarget?: boolean;
363381
isFallbackExtensionDocument?: boolean;
382+
// set for all frame targets
383+
innerWindowId?: number;
384+
// set for iframe targets
385+
parentInnerWindowId?: number;
386+
// set for all frame targets
387+
topInnerWindowId?: number;
388+
// set for worker targets
389+
relatedDocumentInnerWindowId?: number;
390+
addonId?: string;
364391
};
365392
}
366393

src/adapter/firefoxDebugAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class FirefoxDebugAdapter extends DebugAdapterBase {
224224
log.debug(`${this.session.threads.count} threads`);
225225

226226
let threads = this.session.threads.map(
227-
(threadAdapter) => new Thread(threadAdapter.id, `${threadAdapter.name}: ${threadAdapter.url}`));
227+
(threadAdapter) => new Thread(threadAdapter.id, threadAdapter.name));
228228

229229
return { threads };
230230
}

0 commit comments

Comments
 (0)