Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(chromium): remove obsolete target related code #1417

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
});
this._session.on('Target.targetCreated', this._targetCreated.bind(this));
this._session.on('Target.targetDestroyed', this._targetDestroyed.bind(this));
this._session.on('Target.targetInfoChanged', this._targetInfoChanged.bind(this));
this._session.on('Target.attachedToTarget', this._onAttachedToTarget.bind(this));
this._firstPagePromise = new Promise(f => this._firstPageCallback = f);
}
Expand Down Expand Up @@ -163,13 +162,6 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
target._didClose();
}

_targetInfoChanged(event: Protocol.Target.targetInfoChangedPayload) {
const target = this._targets.get(event.targetInfo.targetId)!;
if (!target)
return;
target._targetInfoChanged(event.targetInfo);
}

async _closePage(page: Page) {
await this._session.send('Target.closeTarget', { targetId: CRTarget.fromPage(page)._targetId });
}
Expand Down Expand Up @@ -267,7 +259,7 @@ export class CRBrowserContext extends BrowserContextBase {
}

pages(): Page[] {
return this._targets().filter(target => target.type() === 'page').map(target => target._initializedPage()).filter(pageOrNull => !!pageOrNull) as Page[];
return this._targets().filter(target => target.type() === 'page').map(target => target._initializedPage).filter(pageOrNull => !!pageOrNull) as Page[];
}

async newPage(): Promise<Page> {
Expand Down Expand Up @@ -401,7 +393,7 @@ export class CRBrowserContext extends BrowserContextBase {
}

backgroundPages(): Page[] {
return this._targets().filter(target => target.type() === 'background_page').map(target => target._initializedPage()).filter(pageOrNull => !!pageOrNull) as Page[];
return this._targets().filter(target => target.type() === 'background_page').map(target => target._initializedPage).filter(pageOrNull => !!pageOrNull) as Page[];
}

async newCDPSession(page: Page): Promise<CRSession> {
Expand Down
16 changes: 7 additions & 9 deletions src/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ import { CRTarget } from './crTarget';
const UTILITY_WORLD_NAME = '__playwright_utility_world__';

export class CRPage implements PageDelegate {
_client: CRSession;
_initialized = false;
readonly _client: CRSession;
private readonly _page: Page;
readonly _networkManager: CRNetworkManager;
private _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
private readonly _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
private _eventListeners: RegisteredListener[] = [];
rawMouse: RawMouseImpl;
rawKeyboard: RawKeyboardImpl;
private _browser: CRBrowser;
private _pdf: CRPDF;
private _coverage: CRCoverage;
readonly rawMouse: RawMouseImpl;
readonly rawKeyboard: RawKeyboardImpl;
private readonly _browser: CRBrowser;
private readonly _pdf: CRPDF;
private readonly _coverage: CRCoverage;
private readonly _browserContext: CRBrowserContext;

constructor(client: CRSession, browser: CRBrowser, browserContext: CRBrowserContext) {
Expand Down Expand Up @@ -144,7 +143,6 @@ export class CRPage implements PageDelegate {
promises.push(this.evaluateOnNewDocument(source));
promises.push(this._client.send('Runtime.runIfWaitingForDebugger'));
await Promise.all(promises);
this._initialized = true;
}

didClose() {
Expand Down
24 changes: 5 additions & 19 deletions src/chromium/crTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import { CRExecutionContext } from './crExecutionContext';
const targetSymbol = Symbol('target');

export class CRTarget {
private _targetInfo: Protocol.Target.TargetInfo;
private readonly _targetInfo: Protocol.Target.TargetInfo;
private readonly _browser: CRBrowser;
private readonly _browserContext: CRBrowserContext;
readonly _targetId: string;
readonly sessionFactory: () => Promise<CRSession>;
private _pagePromiseCallback: ((pageOrError: Page | Error) => void) | null = null;
private _pagePromise: Promise<Page | Error> | null = null;
_crPage: CRPage | null = null;
private readonly _pagePromise: Promise<Page | Error> | null = null;
readonly _crPage: CRPage | null = null;
_initializedPage: Page | null = null;
private _workerPromise: Promise<Worker> | null = null;

static fromPage(page: Page): CRTarget {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class CRTarget {
const page = this._crPage.page();
(page as any)[targetSymbol] = this;
session.once(CRSessionEvents.Disconnected, () => page._didDisconnect());
this._pagePromise = this._crPage.initialize().then(() => page).catch(e => e);
this._pagePromise = this._crPage.initialize().then(() => this._initializedPage = page).catch(e => e);
}
}

Expand All @@ -70,12 +70,6 @@ export class CRTarget {
this._crPage.didClose();
}

_initializedPage(): Page | null {
if (this._crPage && this._crPage._initialized)
return this._crPage.page();
return null;
}

async pageOrError(): Promise<Page | Error> {
if (CRTarget.isPageType(this.type()))
return this._pagePromise!;
Expand All @@ -100,10 +94,6 @@ export class CRTarget {
return this._workerPromise;
}

url(): string {
return this._targetInfo.url;
}

type(): 'page' | 'background_page' | 'service_worker' | 'shared_worker' | 'other' | 'browser' {
const type = this._targetInfo.type;
if (type === 'page' || type === 'background_page' || type === 'service_worker' || type === 'shared_worker' || type === 'browser')
Expand All @@ -121,8 +111,4 @@ export class CRTarget {
return null;
return this._browser._targets.get(openerId)!;
}

_targetInfoChanged(targetInfo: Protocol.Target.TargetInfo) {
this._targetInfo = targetInfo;
}
}