refactor: Pass FrameManager to NetworkManager constructor (#4907)

This commit is contained in:
Yury Semikhatsky 2019-09-04 18:11:58 -07:00 committed by Andrey Lushnikov
parent 73fd7ff822
commit c2651c2b5c
2 changed files with 5 additions and 12 deletions

View File

@ -35,8 +35,7 @@ class FrameManager extends EventEmitter {
super(); super();
this._client = client; this._client = client;
this._page = page; this._page = page;
this._networkManager = new NetworkManager(client, ignoreHTTPSErrors); this._networkManager = new NetworkManager(client, ignoreHTTPSErrors, this);
this._networkManager.setFrameManager(this);
this._timeoutSettings = timeoutSettings; this._timeoutSettings = timeoutSettings;
/** @type {!Map<string, !Frame>} */ /** @type {!Map<string, !Frame>} */
this._frames = new Map(); this._frames = new Map();

View File

@ -20,12 +20,13 @@ const {Events} = require('./Events');
class NetworkManager extends EventEmitter { class NetworkManager extends EventEmitter {
/** /**
* @param {!Puppeteer.CDPSession} client * @param {!Puppeteer.CDPSession} client
* @param {!Puppeteer.FrameManager} frameManager
*/ */
constructor(client, ignoreHTTPSErrors) { constructor(client, ignoreHTTPSErrors, frameManager) {
super(); super();
this._client = client; this._client = client;
this._ignoreHTTPSErrors = ignoreHTTPSErrors; this._ignoreHTTPSErrors = ignoreHTTPSErrors;
this._frameManager = null; this._frameManager = frameManager;
/** @type {!Map<string, !Request>} */ /** @type {!Map<string, !Request>} */
this._requestIdToRequest = new Map(); this._requestIdToRequest = new Map();
/** @type {!Map<string, !Protocol.Network.requestWillBeSentPayload>} */ /** @type {!Map<string, !Protocol.Network.requestWillBeSentPayload>} */
@ -60,13 +61,6 @@ class NetworkManager extends EventEmitter {
await this._client.send('Security.setIgnoreCertificateErrors', {ignore: true}); await this._client.send('Security.setIgnoreCertificateErrors', {ignore: true});
} }
/**
* @param {!Puppeteer.FrameManager} frameManager
*/
setFrameManager(frameManager) {
this._frameManager = frameManager;
}
/** /**
* @param {?{username: string, password: string}} credentials * @param {?{username: string, password: string}} credentials
*/ */
@ -234,7 +228,7 @@ class NetworkManager extends EventEmitter {
redirectChain = request._redirectChain; redirectChain = request._redirectChain;
} }
} }
const frame = event.frameId && this._frameManager ? this._frameManager.frame(event.frameId) : null; const frame = event.frameId ? this._frameManager.frame(event.frameId) : null;
const request = new Request(this._client, frame, interceptionId, this._userRequestInterceptionEnabled, event, redirectChain); const request = new Request(this._client, frame, interceptionId, this._userRequestInterceptionEnabled, event, redirectChain);
this._requestIdToRequest.set(event.requestId, request); this._requestIdToRequest.set(event.requestId, request);
this.emit(Events.NetworkManager.Request, request); this.emit(Events.NetworkManager.Request, request);