chore: rename CR/FF/WKFrameManager to CR/FF/WKPage (#333)

This commit is contained in:
Yury Semikhatsky 2019-12-23 11:39:57 -08:00 committed by GitHub
parent c301623e9e
commit 27ddb017e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 50 additions and 50 deletions

View file

@ -3,7 +3,7 @@
export { CRBrowser as ChromiumBrowser } from './crBrowser'; export { CRBrowser as ChromiumBrowser } from './crBrowser';
export { CRSession as ChromiumSession } from './crConnection'; export { CRSession as ChromiumSession } from './crConnection';
export { CRPage as ChromiumPage } from './crFrameManager'; export { ChromiumPage } from './crPage';
export { CRPlaywright as ChromiumPlaywright } from './crPlaywright'; export { CRPlaywright as ChromiumPlaywright } from './crPlaywright';
export { CRTarget as ChromiumTarget } from './crTarget'; export { CRTarget as ChromiumTarget } from './crTarget';
export { CRAccessibility as ChromiumAccessibility } from './features/crAccessibility'; export { CRAccessibility as ChromiumAccessibility } from './features/crAccessibility';

View file

@ -23,7 +23,7 @@ import { CRConnection, ConnectionEvents, CRSession } from './crConnection';
import { Page } from '../page'; import { Page } from '../page';
import { CRTarget } from './crTarget'; import { CRTarget } from './crTarget';
import { Protocol } from './protocol'; import { Protocol } from './protocol';
import { CRFrameManager } from './crFrameManager'; import { CRPage } from './crPage';
import * as browser from '../browser'; import * as browser from '../browser';
import * as network from '../network'; import * as network from '../network';
import { CROverrides } from './features/crOverrides'; import { CROverrides } from './features/crOverrides';
@ -82,7 +82,7 @@ export class CRBrowser extends browser.Browser {
const target = this._targets.get(targetId); const target = this._targets.get(targetId);
assert(await target._initializedPromise, 'Failed to create target for page'); assert(await target._initializedPromise, 'Failed to create target for page');
const page = await target.page(); const page = await target.page();
const session = (page._delegate as CRFrameManager)._client; const session = (page._delegate as CRPage)._client;
const promises: Promise<any>[] = [ overrides._applyOverrides(page) ]; const promises: Promise<any>[] = [ overrides._applyOverrides(page) ];
if (options.bypassCSP) if (options.bypassCSP)
promises.push(session.send('Page.setBypassCSP', { enabled: true })); promises.push(session.send('Page.setBypassCSP', { enabled: true }));
@ -93,7 +93,7 @@ export class CRBrowser extends browser.Browser {
if (options.javaScriptEnabled === false) if (options.javaScriptEnabled === false)
promises.push(session.send('Emulation.setScriptExecutionDisabled', { value: true })); promises.push(session.send('Emulation.setScriptExecutionDisabled', { value: true }));
if (options.userAgent) if (options.userAgent)
(page._delegate as CRFrameManager)._networkManager.setUserAgent(options.userAgent); (page._delegate as CRPage)._networkManager.setUserAgent(options.userAgent);
if (options.mediaType || options.colorScheme) { if (options.mediaType || options.colorScheme) {
const features = options.colorScheme ? [{ name: 'prefers-color-scheme', value: options.colorScheme }] : []; const features = options.colorScheme ? [{ name: 'prefers-color-scheme', value: options.colorScheme }] : [];
promises.push(session.send('Emulation.setEmulatedMedia', { media: options.mediaType || '', features })); promises.push(session.send('Emulation.setEmulatedMedia', { media: options.mediaType || '', features }));
@ -262,7 +262,7 @@ export class CRBrowser extends browser.Browser {
async startTracing(page: Page | undefined, options: { path?: string; screenshots?: boolean; categories?: string[]; } = {}) { async startTracing(page: Page | undefined, options: { path?: string; screenshots?: boolean; categories?: string[]; } = {}) {
assert(!this._tracingRecording, 'Cannot start recording trace while already recording trace.'); assert(!this._tracingRecording, 'Cannot start recording trace while already recording trace.');
this._tracingClient = page ? (page._delegate as CRFrameManager)._client : this._client; this._tracingClient = page ? (page._delegate as CRPage)._client : this._client;
const defaultCategories = [ const defaultCategories = [
'-*', 'devtools.timeline', 'v8.execute', 'disabled-by-default-devtools.timeline', '-*', 'devtools.timeline', 'v8.execute', 'disabled-by-default-devtools.timeline',

View file

@ -42,9 +42,9 @@ import { ConsoleMessage } from '../console';
const UTILITY_WORLD_NAME = '__playwright_utility_world__'; const UTILITY_WORLD_NAME = '__playwright_utility_world__';
export class CRFrameManager implements PageDelegate { export class CRPage implements PageDelegate {
_client: CRSession; _client: CRSession;
private _page: CRPage; private _page: ChromiumPage;
readonly _networkManager: CRNetworkManager; readonly _networkManager: CRNetworkManager;
private _contextIdToContext = new Map<number, dom.FrameExecutionContext>(); private _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
private _isolatedWorlds = new Set<string>(); private _isolatedWorlds = new Set<string>();
@ -58,7 +58,7 @@ export class CRFrameManager implements PageDelegate {
this._browser = browser; this._browser = browser;
this.rawKeyboard = new RawKeyboardImpl(client); this.rawKeyboard = new RawKeyboardImpl(client);
this.rawMouse = new RawMouseImpl(client); this.rawMouse = new RawMouseImpl(client);
this._page = new CRPage(client, this, browserContext); this._page = new ChromiumPage(client, this, browserContext);
this._networkManager = this._page._networkManager; this._networkManager = this._page._networkManager;
this._eventListeners = [ this._eventListeners = [
@ -449,7 +449,7 @@ export class CRFrameManager implements PageDelegate {
} }
} }
export class CRPage extends Page { export class ChromiumPage extends Page {
readonly accessibility: CRAccessibility; readonly accessibility: CRAccessibility;
readonly coverage: CRCoverage; readonly coverage: CRCoverage;
readonly interception: CRInterception; readonly interception: CRInterception;
@ -457,7 +457,7 @@ export class CRPage extends Page {
private _workers: CRWorkers; private _workers: CRWorkers;
_networkManager: CRNetworkManager; _networkManager: CRNetworkManager;
constructor(client: CRSession, delegate: CRFrameManager, browserContext: BrowserContext) { constructor(client: CRSession, delegate: CRPage, browserContext: BrowserContext) {
super(delegate, browserContext); super(delegate, browserContext);
this.accessibility = new CRAccessibility(client); this.accessibility = new CRAccessibility(client);
this.coverage = new CRCoverage(client); this.coverage = new CRCoverage(client);

View file

@ -23,7 +23,7 @@ import { CRWorker } from './features/crWorkers';
import { Page } from '../page'; import { Page } from '../page';
import { Protocol } from './protocol'; import { Protocol } from './protocol';
import { debugError } from '../helper'; import { debugError } from '../helper';
import { CRFrameManager } from './crFrameManager'; import { CRPage } from './crPage';
const targetSymbol = Symbol('target'); const targetSymbol = Symbol('target');
@ -34,7 +34,7 @@ export class CRTarget {
_targetId: string; _targetId: string;
private _sessionFactory: () => Promise<CRSession>; private _sessionFactory: () => Promise<CRSession>;
private _pagePromise: Promise<Page> | null = null; private _pagePromise: Promise<Page> | null = null;
private _frameManager: CRFrameManager | null = null; private _crPage: CRPage | null = null;
private _workerPromise: Promise<CRWorker> | null = null; private _workerPromise: Promise<CRWorker> | null = null;
_initializedPromise: Promise<boolean>; _initializedPromise: Promise<boolean>;
_initializedCallback: (value?: unknown) => void; _initializedCallback: (value?: unknown) => void;
@ -73,15 +73,15 @@ export class CRTarget {
} }
_didClose() { _didClose() {
if (this._frameManager) if (this._crPage)
this._frameManager.didClose(); this._crPage.didClose();
} }
async page(): Promise<Page | null> { async page(): Promise<Page | null> {
if ((this._targetInfo.type === 'page' || this._targetInfo.type === 'background_page') && !this._pagePromise) { if ((this._targetInfo.type === 'page' || this._targetInfo.type === 'background_page') && !this._pagePromise) {
this._pagePromise = this._sessionFactory().then(async client => { this._pagePromise = this._sessionFactory().then(async client => {
this._frameManager = new CRFrameManager(client, this._browser, this._browserContext); this._crPage = new CRPage(client, this._browser, this._browserContext);
const page = this._frameManager.page(); const page = this._crPage.page();
(page as any)[targetSymbol] = this; (page as any)[targetSymbol] = this;
client.once(CRSessionEvents.Disconnected, () => page._didDisconnect()); client.once(CRSessionEvents.Disconnected, () => page._didDisconnect());
client.on('Target.attachedToTarget', event => { client.on('Target.attachedToTarget', event => {
@ -90,7 +90,7 @@ export class CRTarget {
client.send('Target.detachFromTarget', { sessionId: event.sessionId }).catch(debugError); client.send('Target.detachFromTarget', { sessionId: event.sessionId }).catch(debugError);
} }
}); });
await this._frameManager.initialize(); await this._crPage.initialize();
await client.send('Target.setAutoAttach', {autoAttach: true, waitForDebuggerOnStart: false, flatten: true}); await client.send('Target.setAutoAttach', {autoAttach: true, waitForDebuggerOnStart: false, flatten: true});
return page; return page;
}); });

View file

@ -16,7 +16,7 @@
*/ */
import { BrowserContext } from '../../browserContext'; import { BrowserContext } from '../../browserContext';
import { CRFrameManager } from '../crFrameManager'; import { CRPage } from '../crPage';
import { Page } from '../../page'; import { Page } from '../../page';
export class CROverrides { export class CROverrides {
@ -30,7 +30,7 @@ export class CROverrides {
async setGeolocation(options: { longitude?: number; latitude?: number; accuracy?: (number | undefined); } | null) { async setGeolocation(options: { longitude?: number; latitude?: number; accuracy?: (number | undefined); } | null) {
if (!options) { if (!options) {
for (const page of await this._context.pages()) for (const page of await this._context.pages())
await (page._delegate as CRFrameManager)._client.send('Emulation.clearGeolocationOverride', {}); await (page._delegate as CRPage)._client.send('Emulation.clearGeolocationOverride', {});
this._geolocation = null; this._geolocation = null;
return; return;
} }
@ -44,11 +44,11 @@ export class CROverrides {
throw new Error(`Invalid accuracy "${accuracy}": precondition 0 <= ACCURACY failed.`); throw new Error(`Invalid accuracy "${accuracy}": precondition 0 <= ACCURACY failed.`);
this._geolocation = { longitude, latitude, accuracy }; this._geolocation = { longitude, latitude, accuracy };
for (const page of await this._context.pages()) for (const page of await this._context.pages())
await (page._delegate as CRFrameManager)._client.send('Emulation.setGeolocationOverride', this._geolocation); await (page._delegate as CRPage)._client.send('Emulation.setGeolocationOverride', this._geolocation);
} }
async _applyOverrides(page: Page): Promise<void> { async _applyOverrides(page: Page): Promise<void> {
if (this._geolocation) if (this._geolocation)
await (page._delegate as CRFrameManager)._client.send('Emulation.setGeolocationOverride', this._geolocation); await (page._delegate as CRPage)._client.send('Emulation.setGeolocationOverride', this._geolocation);
} }
} }

View file

@ -25,7 +25,7 @@ import * as js from '../../javascript';
import * as console from '../../console'; import * as console from '../../console';
import { CRExecutionContext } from '../crExecutionContext'; import { CRExecutionContext } from '../crExecutionContext';
import { toConsoleMessageLocation, exceptionToError } from '../crProtocolHelper'; import { toConsoleMessageLocation, exceptionToError } from '../crProtocolHelper';
import { CRPage } from '../crFrameManager'; import { ChromiumPage } from '../crPage';
type AddToConsoleCallback = (type: string, args: js.JSHandle[], location: console.ConsoleMessageLocation) => void; type AddToConsoleCallback = (type: string, args: js.JSHandle[], location: console.ConsoleMessageLocation) => void;
type HandleExceptionCallback = (error: Error) => void; type HandleExceptionCallback = (error: Error) => void;
@ -33,7 +33,7 @@ type HandleExceptionCallback = (error: Error) => void;
export class CRWorkers { export class CRWorkers {
private _workers = new Map<string, CRWorker>(); private _workers = new Map<string, CRWorker>();
constructor(client: CRSession, page: CRPage, addToConsole: AddToConsoleCallback, handleException: HandleExceptionCallback) { constructor(client: CRSession, page: ChromiumPage, addToConsole: AddToConsoleCallback, handleException: HandleExceptionCallback) {
client.on('Target.attachedToTarget', event => { client.on('Target.attachedToTarget', event => {
if (event.targetInfo.type !== 'worker') if (event.targetInfo.type !== 'worker')
return; return;

View file

@ -23,7 +23,7 @@ import * as network from '../network';
import { Page } from '../page'; import { Page } from '../page';
import { ConnectionTransport } from '../transport'; import { ConnectionTransport } from '../transport';
import { ConnectionEvents, FFConnection, FFSessionEvents } from './ffConnection'; import { ConnectionEvents, FFConnection, FFSessionEvents } from './ffConnection';
import { FFFrameManager } from './ffFrameManager'; import { FFPage } from './ffPage';
export class FFBrowser extends browser.Browser { export class FFBrowser extends browser.Browser {
_connection: FFConnection; _connection: FFConnection;
@ -156,7 +156,7 @@ export class FFBrowser extends browser.Browser {
}); });
const target = this._targets.get(targetId); const target = this._targets.get(targetId);
const page = await target.page(); const page = await target.page();
const session = (page._delegate as FFFrameManager)._session; const session = (page._delegate as FFPage)._session;
const promises: Promise<any>[] = []; const promises: Promise<any>[] = [];
if (options.viewport) if (options.viewport)
promises.push(page._delegate.setViewport(options.viewport)); promises.push(page._delegate.setViewport(options.viewport));
@ -222,7 +222,7 @@ export class FFBrowser extends browser.Browser {
export class Target { export class Target {
_pagePromise?: Promise<Page>; _pagePromise?: Promise<Page>;
private _frameManager: FFFrameManager | null = null; private _ffPage: FFPage | null = null;
private _browser: FFBrowser; private _browser: FFBrowser;
_context: BrowserContext; _context: BrowserContext;
private _connection: FFConnection; private _connection: FFConnection;
@ -242,8 +242,8 @@ export class Target {
} }
_didClose() { _didClose() {
if (this._frameManager) if (this._ffPage)
this._frameManager.didClose(); this._ffPage.didClose();
} }
opener(): Target | null { opener(): Target | null {
@ -266,10 +266,10 @@ export class Target {
if (this._type === 'page' && !this._pagePromise) { if (this._type === 'page' && !this._pagePromise) {
this._pagePromise = new Promise(async f => { this._pagePromise = new Promise(async f => {
const session = await this._connection.createSession(this._targetId); const session = await this._connection.createSession(this._targetId);
this._frameManager = new FFFrameManager(session, this._context); this._ffPage = new FFPage(session, this._context);
const page = this._frameManager._page; const page = this._ffPage._page;
session.once(FFSessionEvents.Disconnected, () => page._didDisconnect()); session.once(FFSessionEvents.Disconnected, () => page._didDisconnect());
await this._frameManager._initialize(); await this._ffPage._initialize();
f(page); f(page);
}); });
} }

View file

@ -33,7 +33,7 @@ import { FFAccessibility } from './features/ffAccessibility';
import * as network from '../network'; import * as network from '../network';
import * as types from '../types'; import * as types from '../types';
export class FFFrameManager implements PageDelegate { export class FFPage implements PageDelegate {
readonly rawMouse: RawMouseImpl; readonly rawMouse: RawMouseImpl;
readonly rawKeyboard: RawKeyboardImpl; readonly rawKeyboard: RawKeyboardImpl;
readonly _session: FFSession; readonly _session: FFSession;

View file

@ -125,7 +125,7 @@ export class WKBrowser extends browser.Browser {
const opener = this._targets.get(targetInfo.openerId); const opener = this._targets.get(targetInfo.openerId);
if (!opener) if (!opener)
return; return;
const openerPage = opener._frameManager ? opener._frameManager._page : null; const openerPage = opener._wkPage ? opener._wkPage._page : null;
if (!openerPage || !openerPage.listenerCount(Events.Page.Popup)) if (!openerPage || !openerPage.listenerCount(Events.Page.Popup))
return; return;
target.page().then(page => openerPage.emit(Events.Page.Popup, page)); target.page().then(page => openerPage.emit(Events.Page.Popup, page));

View file

@ -37,7 +37,7 @@ import { PNG } from 'pngjs';
const UTILITY_WORLD_NAME = '__playwright_utility_world__'; const UTILITY_WORLD_NAME = '__playwright_utility_world__';
const BINDING_CALL_MESSAGE = '__playwright_binding_call__'; const BINDING_CALL_MESSAGE = '__playwright_binding_call__';
export class WKFrameManager implements PageDelegate { export class WKPage implements PageDelegate {
readonly rawMouse: RawMouseImpl; readonly rawMouse: RawMouseImpl;
readonly rawKeyboard: RawKeyboardImpl; readonly rawKeyboard: RawKeyboardImpl;
_session: WKTargetSession; _session: WKTargetSession;
@ -106,7 +106,7 @@ export class WKFrameManager implements PageDelegate {
if (this._page._state.extraHTTPHeaders !== null) if (this._page._state.extraHTTPHeaders !== null)
promises.push(this._setExtraHTTPHeaders(session, this._page._state.extraHTTPHeaders)); promises.push(this._setExtraHTTPHeaders(session, this._page._state.extraHTTPHeaders));
if (this._page._state.viewport) if (this._page._state.viewport)
promises.push(WKFrameManager._setViewport(session, this._page._state.viewport)); promises.push(WKPage._setViewport(session, this._page._state.viewport));
await Promise.all(promises); await Promise.all(promises);
} }
@ -290,7 +290,7 @@ export class WKFrameManager implements PageDelegate {
} }
async setViewport(viewport: types.Viewport): Promise<void> { async setViewport(viewport: types.Viewport): Promise<void> {
return WKFrameManager._setViewport(this._session, viewport); return WKPage._setViewport(this._session, viewport);
} }
private static async _setViewport(session: WKTargetSession, viewport: types.Viewport): Promise<void> { private static async _setViewport(session: WKTargetSession, viewport: types.Viewport): Promise<void> {

View file

@ -19,7 +19,7 @@ import { BrowserContext } from '../browserContext';
import { Page } from '../page'; import { Page } from '../page';
import { Protocol } from './protocol'; import { Protocol } from './protocol';
import { WKTargetSession, WKTargetSessionEvents } from './wkConnection'; import { WKTargetSession, WKTargetSessionEvents } from './wkConnection';
import { WKFrameManager } from './wkFrameManager'; import { WKPage } from './wkPage';
import { WKBrowser } from './wkBrowser'; import { WKBrowser } from './wkBrowser';
export class WKTarget { export class WKTarget {
@ -29,7 +29,7 @@ export class WKTarget {
private readonly _session: WKTargetSession; private readonly _session: WKTargetSession;
private _pagePromise: Promise<Page> | null = null; private _pagePromise: Promise<Page> | null = null;
private _browser: WKBrowser; private _browser: WKBrowser;
_frameManager: WKFrameManager | null = null; _wkPage: WKPage | null = null;
constructor(browser: WKBrowser, session: WKTargetSession, targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext) { constructor(browser: WKBrowser, session: WKTargetSession, targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext) {
const {targetId, type} = targetInfo; const {targetId, type} = targetInfo;
@ -43,17 +43,17 @@ export class WKTarget {
} }
_didClose() { _didClose() {
if (this._frameManager) if (this._wkPage)
this._frameManager.didClose(); this._wkPage.didClose();
} }
async _initializeSession(session: WKTargetSession) { async _initializeSession(session: WKTargetSession) {
if (!this._frameManager) if (!this._wkPage)
return; return;
await this._frameManager._initializeSession(session).catch(e => { await this._wkPage._initializeSession(session).catch(e => {
// Swallow initialization errors due to newer target swap in, // Swallow initialization errors due to newer target swap in,
// since we will reinitialize again. // since we will reinitialize again.
if (this._frameManager) if (this._wkPage)
throw e; throw e;
}); });
} }
@ -62,29 +62,29 @@ export class WKTarget {
if (!oldTarget._pagePromise) if (!oldTarget._pagePromise)
return; return;
this._pagePromise = oldTarget._pagePromise; this._pagePromise = oldTarget._pagePromise;
this._frameManager = oldTarget._frameManager; this._wkPage = oldTarget._wkPage;
// Swapped out target should not be accessed by anyone. Reset page promise so that // Swapped out target should not be accessed by anyone. Reset page promise so that
// old target does not close the page on connection reset. // old target does not close the page on connection reset.
oldTarget._pagePromise = null; oldTarget._pagePromise = null;
oldTarget._frameManager = null; oldTarget._wkPage = null;
this._adoptPage(); this._adoptPage();
} }
private _adoptPage() { private _adoptPage() {
this._session.once(WKTargetSessionEvents.Disconnected, () => { this._session.once(WKTargetSessionEvents.Disconnected, () => {
// Once swapped out, we reset _page and won't call _didDisconnect for old session. // Once swapped out, we reset _page and won't call _didDisconnect for old session.
if (this._frameManager) if (this._wkPage)
this._frameManager._page._didDisconnect(); this._wkPage._page._didDisconnect();
}); });
this._frameManager.setSession(this._session); this._wkPage.setSession(this._session);
} }
async page(): Promise<Page> { async page(): Promise<Page> {
if (this._type === 'page' && !this._pagePromise) { if (this._type === 'page' && !this._pagePromise) {
this._frameManager = new WKFrameManager(this._browser, this._browserContext); this._wkPage = new WKPage(this._browser, this._browserContext);
// Reference local page variable as |this._frameManager| may be // Reference local page variable as |this._frameManager| may be
// cleared on swap. // cleared on swap.
const page = this._frameManager._page; const page = this._wkPage._page;
this._pagePromise = new Promise(async f => { this._pagePromise = new Promise(async f => {
this._adoptPage(); this._adoptPage();
await this._initializeSession(this._session); await this._initializeSession(this._session);