blob: af7f3239593a590d7514fdfd122400f2959737bb [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Tim van der Lipped41d8632020-01-23 15:15:1231import * as Common from '../common/common.js';
32import * as ProtocolModule from '../protocol/protocol.js';
33
Tim van der Lippe9293af72020-01-17 10:50:3734import {DOMModel} from './DOMModel.js';
35import {Events as NetworkManagerEvents, NetworkManager} from './NetworkManager.js';
36import {NetworkRequest} from './NetworkRequest.js'; // eslint-disable-line no-unused-vars
37import {Resource} from './Resource.js';
38import {ExecutionContext, RuntimeModel} from './RuntimeModel.js';
39import {Capability, SDKModel, Target} from './SDKModel.js'; // eslint-disable-line no-unused-vars
40import {SecurityOriginManager} from './SecurityOriginManager.js';
41
42export class ResourceTreeModel extends SDKModel {
Blink Reformat4c46d092018-04-07 15:32:3743 /**
Tim van der Lippe9293af72020-01-17 10:50:3744 * @param {!Target} target
Blink Reformat4c46d092018-04-07 15:32:3745 */
46 constructor(target) {
47 super(target);
48
Tim van der Lippe9293af72020-01-17 10:50:3749 const networkManager = target.model(NetworkManager);
Blink Reformat4c46d092018-04-07 15:32:3750 if (networkManager) {
Tim van der Lippe9293af72020-01-17 10:50:3751 networkManager.addEventListener(NetworkManagerEvents.RequestFinished, this._onRequestFinished, this);
52 networkManager.addEventListener(NetworkManagerEvents.RequestUpdateDropped, this._onRequestUpdateDropped, this);
Blink Reformat4c46d092018-04-07 15:32:3753 }
54 this._agent = target.pageAgent();
55 this._agent.enable();
Tim van der Lippe9293af72020-01-17 10:50:3756 this._securityOriginManager = target.model(SecurityOriginManager);
Blink Reformat4c46d092018-04-07 15:32:3757
Tim van der Lippe9293af72020-01-17 10:50:3758 target.registerPageDispatcher(new PageDispatcher(this));
Blink Reformat4c46d092018-04-07 15:32:3759
Tim van der Lippe9b7d21d2019-10-07 18:48:0760 /** @type {!Map<string, !ResourceTreeFrame>} */
Blink Reformat4c46d092018-04-07 15:32:3761 this._frames = new Map();
62 this._cachedResourcesProcessed = false;
63 this._pendingReloadOptions = null;
64 this._reloadSuspensionCount = 0;
65 this._isInterstitialShowing = false;
Tim van der Lippe9b7d21d2019-10-07 18:48:0766 /** @type {?ResourceTreeFrame} */
Blink Reformat4c46d092018-04-07 15:32:3767 this.mainFrame = null;
68
69 this._agent.getResourceTree().then(this._processCachedResources.bind(this));
70 }
71
72 /**
Tim van der Lippe9293af72020-01-17 10:50:3773 * @param {!NetworkRequest} request
Tim van der Lippe9b7d21d2019-10-07 18:48:0774 * @return {?ResourceTreeFrame}
Blink Reformat4c46d092018-04-07 15:32:3775 */
76 static frameForRequest(request) {
Tim van der Lippe9293af72020-01-17 10:50:3777 const networkManager = NetworkManager.forRequest(request);
Tim van der Lippe9b7d21d2019-10-07 18:48:0778 const resourceTreeModel = networkManager ? networkManager.target().model(ResourceTreeModel) : null;
Tim van der Lippe1d6e57a2019-09-30 11:55:3479 if (!resourceTreeModel) {
Blink Reformat4c46d092018-04-07 15:32:3780 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:3481 }
Blink Reformat4c46d092018-04-07 15:32:3782 return resourceTreeModel.frameForId(request.frameId);
83 }
84
85 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:0786 * @return {!Array.<!ResourceTreeFrame>}
Blink Reformat4c46d092018-04-07 15:32:3787 */
88 static frames() {
Simon Zünda0d40622020-02-12 13:16:4289 const result = [];
Paul Lewis4ae5f4f2020-01-23 10:19:3390 for (const resourceTreeModel of self.SDK.targetManager.models(ResourceTreeModel)) {
Simon Zünda0d40622020-02-12 13:16:4291 result.push(...resourceTreeModel._frames.values());
Tim van der Lippe1d6e57a2019-09-30 11:55:3492 }
Blink Reformat4c46d092018-04-07 15:32:3793 return result;
94 }
95
96 /**
97 * @param {string} url
Tim van der Lippe9293af72020-01-17 10:50:3798 * @return {?Resource}
Blink Reformat4c46d092018-04-07 15:32:3799 */
100 static resourceForURL(url) {
Paul Lewis4ae5f4f2020-01-23 10:19:33101 for (const resourceTreeModel of self.SDK.targetManager.models(ResourceTreeModel)) {
Blink Reformat4c46d092018-04-07 15:32:37102 const mainFrame = resourceTreeModel.mainFrame;
103 const result = mainFrame ? mainFrame.resourceForURL(url) : null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34104 if (result) {
Blink Reformat4c46d092018-04-07 15:32:37105 return result;
Tim van der Lippe1d6e57a2019-09-30 11:55:34106 }
Blink Reformat4c46d092018-04-07 15:32:37107 }
108 return null;
109 }
110
111 /**
112 * @param {boolean=} bypassCache
113 * @param {string=} scriptToEvaluateOnLoad
114 */
115 static reloadAllPages(bypassCache, scriptToEvaluateOnLoad) {
Paul Lewis4ae5f4f2020-01-23 10:19:33116 for (const resourceTreeModel of self.SDK.targetManager.models(ResourceTreeModel)) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34117 if (!resourceTreeModel.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37118 resourceTreeModel.reloadPage(bypassCache, scriptToEvaluateOnLoad);
Tim van der Lippe1d6e57a2019-09-30 11:55:34119 }
Blink Reformat4c46d092018-04-07 15:32:37120 }
121 }
122
123 /**
Tim van der Lippe9293af72020-01-17 10:50:37124 * @return {!DOMModel}
Blink Reformat4c46d092018-04-07 15:32:37125 */
126 domModel() {
Tim van der Lippe9293af72020-01-17 10:50:37127 return /** @type {!DOMModel} */ (this.target().model(DOMModel));
Blink Reformat4c46d092018-04-07 15:32:37128 }
129
130 /**
131 * @param {?Protocol.Page.FrameResourceTree} mainFramePayload
132 */
133 _processCachedResources(mainFramePayload) {
134 if (mainFramePayload) {
Tim van der Lippe9b7d21d2019-10-07 18:48:07135 this.dispatchEventToListeners(Events.WillLoadCachedResources);
Blink Reformat4c46d092018-04-07 15:32:37136 this._addFramesRecursively(null, mainFramePayload);
137 this.target().setInspectedURL(mainFramePayload.frame.url);
138 }
139 this._cachedResourcesProcessed = true;
Tim van der Lippe9293af72020-01-17 10:50:37140 const runtimeModel = this.target().model(RuntimeModel);
Blink Reformat4c46d092018-04-07 15:32:37141 if (runtimeModel) {
142 runtimeModel.setExecutionContextComparator(this._executionContextComparator.bind(this));
143 runtimeModel.fireExecutionContextOrderChanged();
144 }
Tim van der Lippe9b7d21d2019-10-07 18:48:07145 this.dispatchEventToListeners(Events.CachedResourcesLoaded, this);
Blink Reformat4c46d092018-04-07 15:32:37146 }
147
148 /**
149 * @return {boolean}
150 */
151 cachedResourcesLoaded() {
152 return this._cachedResourcesProcessed;
153 }
154
155 /**
156 * @return {boolean}
157 */
158 isInterstitialShowing() {
159 return this._isInterstitialShowing;
160 }
161
162 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07163 * @param {!ResourceTreeFrame} frame
Blink Reformat4c46d092018-04-07 15:32:37164 * @param {boolean=} aboutToNavigate
165 */
166 _addFrame(frame, aboutToNavigate) {
167 this._frames.set(frame.id, frame);
Tim van der Lippe1d6e57a2019-09-30 11:55:34168 if (frame.isMainFrame()) {
Blink Reformat4c46d092018-04-07 15:32:37169 this.mainFrame = frame;
Tim van der Lippe1d6e57a2019-09-30 11:55:34170 }
Tim van der Lippe9b7d21d2019-10-07 18:48:07171 this.dispatchEventToListeners(Events.FrameAdded, frame);
Blink Reformat4c46d092018-04-07 15:32:37172 this._updateSecurityOrigins();
173 }
174
175 /**
176 * @param {!Protocol.Page.FrameId} frameId
177 * @param {?Protocol.Page.FrameId} parentFrameId
178 * @param {!Protocol.Runtime.StackTrace=} stackTrace
Tim van der Lippe9b7d21d2019-10-07 18:48:07179 * @return {?ResourceTreeFrame}
Blink Reformat4c46d092018-04-07 15:32:37180 */
181 _frameAttached(frameId, parentFrameId, stackTrace) {
182 const parentFrame = parentFrameId ? (this._frames.get(parentFrameId) || null) : null;
183 // Do nothing unless cached resource tree is processed - it will overwrite everything.
Tim van der Lippe1d6e57a2019-09-30 11:55:34184 if (!this._cachedResourcesProcessed && parentFrame) {
Blink Reformat4c46d092018-04-07 15:32:37185 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34186 }
187 if (this._frames.has(frameId)) {
Blink Reformat4c46d092018-04-07 15:32:37188 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34189 }
Blink Reformat4c46d092018-04-07 15:32:37190
Tim van der Lippe9b7d21d2019-10-07 18:48:07191 const frame = new ResourceTreeFrame(this, parentFrame, frameId, null, stackTrace || null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34192 if (parentFrameId && !parentFrame) {
Blink Reformat4c46d092018-04-07 15:32:37193 frame._crossTargetParentFrameId = parentFrameId;
Tim van der Lippe1d6e57a2019-09-30 11:55:34194 }
Blink Reformat4c46d092018-04-07 15:32:37195 if (frame.isMainFrame() && this.mainFrame) {
196 // Navigation to the new backend process.
197 this._frameDetached(this.mainFrame.id);
198 }
199 this._addFrame(frame, true);
200 return frame;
201 }
202
203 /**
204 * @param {!Protocol.Page.Frame} framePayload
205 */
206 _frameNavigated(framePayload) {
207 const parentFrame = framePayload.parentId ? (this._frames.get(framePayload.parentId) || null) : null;
208 // Do nothing unless cached resource tree is processed - it will overwrite everything.
Tim van der Lippe1d6e57a2019-09-30 11:55:34209 if (!this._cachedResourcesProcessed && parentFrame) {
Blink Reformat4c46d092018-04-07 15:32:37210 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34211 }
Blink Reformat4c46d092018-04-07 15:32:37212 let frame = this._frames.get(framePayload.id);
213 if (!frame) {
214 // Simulate missed "frameAttached" for a main frame navigation to the new backend process.
215 frame = this._frameAttached(framePayload.id, framePayload.parentId || '');
216 console.assert(frame);
217 }
218
Tim van der Lippe9b7d21d2019-10-07 18:48:07219 this.dispatchEventToListeners(Events.FrameWillNavigate, frame);
Blink Reformat4c46d092018-04-07 15:32:37220 frame._navigate(framePayload);
Tim van der Lippe9b7d21d2019-10-07 18:48:07221 this.dispatchEventToListeners(Events.FrameNavigated, frame);
Blink Reformat4c46d092018-04-07 15:32:37222
Tim van der Lippe1d6e57a2019-09-30 11:55:34223 if (frame.isMainFrame()) {
Tim van der Lippe9b7d21d2019-10-07 18:48:07224 this.dispatchEventToListeners(Events.MainFrameNavigated, frame);
Tim van der Lippe1d6e57a2019-09-30 11:55:34225 }
Blink Reformat4c46d092018-04-07 15:32:37226
227 // Fill frame with retained resources (the ones loaded using new loader).
228 const resources = frame.resources();
Tim van der Lippe1d6e57a2019-09-30 11:55:34229 for (let i = 0; i < resources.length; ++i) {
Tim van der Lippe9b7d21d2019-10-07 18:48:07230 this.dispatchEventToListeners(Events.ResourceAdded, resources[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:34231 }
Blink Reformat4c46d092018-04-07 15:32:37232
Tim van der Lippe1d6e57a2019-09-30 11:55:34233 if (frame.isMainFrame()) {
Blink Reformat4c46d092018-04-07 15:32:37234 this.target().setInspectedURL(frame.url);
Tim van der Lippe1d6e57a2019-09-30 11:55:34235 }
Blink Reformat4c46d092018-04-07 15:32:37236 this._updateSecurityOrigins();
237 }
238
239 /**
240 * @param {!Protocol.Page.FrameId} frameId
241 */
242 _frameDetached(frameId) {
243 // Do nothing unless cached resource tree is processed - it will overwrite everything.
Tim van der Lippe1d6e57a2019-09-30 11:55:34244 if (!this._cachedResourcesProcessed) {
Blink Reformat4c46d092018-04-07 15:32:37245 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34246 }
Blink Reformat4c46d092018-04-07 15:32:37247
248 const frame = this._frames.get(frameId);
Tim van der Lippe1d6e57a2019-09-30 11:55:34249 if (!frame) {
Blink Reformat4c46d092018-04-07 15:32:37250 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34251 }
Blink Reformat4c46d092018-04-07 15:32:37252
Tim van der Lippe1d6e57a2019-09-30 11:55:34253 if (frame.parentFrame) {
Blink Reformat4c46d092018-04-07 15:32:37254 frame.parentFrame._removeChildFrame(frame);
Tim van der Lippe1d6e57a2019-09-30 11:55:34255 } else {
Blink Reformat4c46d092018-04-07 15:32:37256 frame._remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34257 }
Blink Reformat4c46d092018-04-07 15:32:37258 this._updateSecurityOrigins();
259 }
260
261 /**
262 * @param {!Common.Event} event
263 */
264 _onRequestFinished(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34265 if (!this._cachedResourcesProcessed) {
Blink Reformat4c46d092018-04-07 15:32:37266 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34267 }
Blink Reformat4c46d092018-04-07 15:32:37268
Tim van der Lippe9293af72020-01-17 10:50:37269 const request = /** @type {!NetworkRequest} */ (event.data);
Tim van der Lipped41d8632020-01-23 15:15:12270 if (request.failed || request.resourceType() === Common.ResourceType.resourceTypes.XHR) {
Blink Reformat4c46d092018-04-07 15:32:37271 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34272 }
Blink Reformat4c46d092018-04-07 15:32:37273
274 const frame = this._frames.get(request.frameId);
Tim van der Lippe1d6e57a2019-09-30 11:55:34275 if (frame) {
Blink Reformat4c46d092018-04-07 15:32:37276 frame._addRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34277 }
Blink Reformat4c46d092018-04-07 15:32:37278 }
279
280 /**
281 * @param {!Common.Event} event
282 */
283 _onRequestUpdateDropped(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34284 if (!this._cachedResourcesProcessed) {
Blink Reformat4c46d092018-04-07 15:32:37285 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34286 }
Blink Reformat4c46d092018-04-07 15:32:37287
288 const frameId = event.data.frameId;
289 const frame = this._frames.get(frameId);
Tim van der Lippe1d6e57a2019-09-30 11:55:34290 if (!frame) {
Blink Reformat4c46d092018-04-07 15:32:37291 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34292 }
Blink Reformat4c46d092018-04-07 15:32:37293
294 const url = event.data.url;
Tim van der Lippe1d6e57a2019-09-30 11:55:34295 if (frame._resourcesMap[url]) {
Blink Reformat4c46d092018-04-07 15:32:37296 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34297 }
Blink Reformat4c46d092018-04-07 15:32:37298
Tim van der Lippe9293af72020-01-17 10:50:37299 const resource = new Resource(
Tim van der Lipped41d8632020-01-23 15:15:12300 this, null, url, frame.url, frameId, event.data.loaderId,
301 Common.ResourceType.resourceTypes[event.data.resourceType], event.data.mimeType, event.data.lastModified, null);
Blink Reformat4c46d092018-04-07 15:32:37302 frame.addResource(resource);
303 }
304
305 /**
306 * @param {!Protocol.Page.FrameId} frameId
Tim van der Lippe9b7d21d2019-10-07 18:48:07307 * @return {!ResourceTreeFrame}
Blink Reformat4c46d092018-04-07 15:32:37308 */
309 frameForId(frameId) {
310 return this._frames.get(frameId);
311 }
312
313 /**
Tim van der Lippe9293af72020-01-17 10:50:37314 * @param {function(!Resource)} callback
Blink Reformat4c46d092018-04-07 15:32:37315 * @return {boolean}
316 */
317 forAllResources(callback) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34318 if (this.mainFrame) {
Blink Reformat4c46d092018-04-07 15:32:37319 return this.mainFrame._callForFrameResources(callback);
Tim van der Lippe1d6e57a2019-09-30 11:55:34320 }
Blink Reformat4c46d092018-04-07 15:32:37321 return false;
322 }
323
324 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07325 * @return {!Array<!ResourceTreeFrame>}
Blink Reformat4c46d092018-04-07 15:32:37326 */
327 frames() {
Simon Zünda0d40622020-02-12 13:16:42328 return [...this._frames.values()];
Blink Reformat4c46d092018-04-07 15:32:37329 }
330
331 /**
332 * @param {string} url
Tim van der Lippe9293af72020-01-17 10:50:37333 * @return {?Resource}
Blink Reformat4c46d092018-04-07 15:32:37334 */
335 resourceForURL(url) {
336 // Workers call into this with no frames available.
337 return this.mainFrame ? this.mainFrame.resourceForURL(url) : null;
338 }
339
340 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07341 * @param {?ResourceTreeFrame} parentFrame
Blink Reformat4c46d092018-04-07 15:32:37342 * @param {!Protocol.Page.FrameResourceTree} frameTreePayload
343 */
344 _addFramesRecursively(parentFrame, frameTreePayload) {
345 const framePayload = frameTreePayload.frame;
Tim van der Lippe9b7d21d2019-10-07 18:48:07346 const frame = new ResourceTreeFrame(this, parentFrame, framePayload.id, framePayload, null);
Tim van der Lippe1d6e57a2019-09-30 11:55:34347 if (!parentFrame && framePayload.parentId) {
Blink Reformat4c46d092018-04-07 15:32:37348 frame._crossTargetParentFrameId = framePayload.parentId;
Tim van der Lippe1d6e57a2019-09-30 11:55:34349 }
Blink Reformat4c46d092018-04-07 15:32:37350 this._addFrame(frame);
351
Tim van der Lippe1d6e57a2019-09-30 11:55:34352 for (let i = 0; frameTreePayload.childFrames && i < frameTreePayload.childFrames.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:37353 this._addFramesRecursively(frame, frameTreePayload.childFrames[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:34354 }
Blink Reformat4c46d092018-04-07 15:32:37355
356 for (let i = 0; i < frameTreePayload.resources.length; ++i) {
357 const subresource = frameTreePayload.resources[i];
358 const resource = this._createResourceFromFramePayload(
Tim van der Lipped41d8632020-01-23 15:15:12359 framePayload, subresource.url, Common.ResourceType.resourceTypes[subresource.type], subresource.mimeType,
Blink Reformat4c46d092018-04-07 15:32:37360 subresource.lastModified || null, subresource.contentSize || null);
361 frame.addResource(resource);
362 }
363
364 if (!frame._resourcesMap[framePayload.url]) {
365 const frameResource = this._createResourceFromFramePayload(
Tim van der Lipped41d8632020-01-23 15:15:12366 framePayload, framePayload.url, Common.ResourceType.resourceTypes.Document, framePayload.mimeType, null,
367 null);
Blink Reformat4c46d092018-04-07 15:32:37368 frame.addResource(frameResource);
369 }
370 }
371
372 /**
373 * @param {!Protocol.Page.Frame} frame
374 * @param {string} url
Tim van der Lipped41d8632020-01-23 15:15:12375 * @param {!Common.ResourceType.ResourceType} type
Blink Reformat4c46d092018-04-07 15:32:37376 * @param {string} mimeType
377 * @param {?number} lastModifiedTime
378 * @param {?number} contentSize
Tim van der Lippe9293af72020-01-17 10:50:37379 * @return {!Resource}
Blink Reformat4c46d092018-04-07 15:32:37380 */
381 _createResourceFromFramePayload(frame, url, type, mimeType, lastModifiedTime, contentSize) {
382 const lastModified = typeof lastModifiedTime === 'number' ? new Date(lastModifiedTime * 1000) : null;
Tim van der Lippe9293af72020-01-17 10:50:37383 return new Resource(
Blink Reformat4c46d092018-04-07 15:32:37384 this, null, url, frame.url, frame.id, frame.loaderId, type, mimeType, lastModified, contentSize);
385 }
386
387 suspendReload() {
388 this._reloadSuspensionCount++;
389 }
390
391 resumeReload() {
392 this._reloadSuspensionCount--;
393 console.assert(this._reloadSuspensionCount >= 0, 'Unbalanced call to ResourceTreeModel.resumeReload()');
Tim van der Lippe1d6e57a2019-09-30 11:55:34394 if (!this._reloadSuspensionCount && this._pendingReloadOptions) {
Blink Reformat4c46d092018-04-07 15:32:37395 this.reloadPage.apply(this, this._pendingReloadOptions);
Tim van der Lippe1d6e57a2019-09-30 11:55:34396 }
Blink Reformat4c46d092018-04-07 15:32:37397 }
398
399 /**
400 * @param {boolean=} bypassCache
401 * @param {string=} scriptToEvaluateOnLoad
402 */
403 reloadPage(bypassCache, scriptToEvaluateOnLoad) {
404 // Only dispatch PageReloadRequested upon first reload request to simplify client logic.
Tim van der Lippe1d6e57a2019-09-30 11:55:34405 if (!this._pendingReloadOptions) {
Tim van der Lippe9b7d21d2019-10-07 18:48:07406 this.dispatchEventToListeners(Events.PageReloadRequested, this);
Tim van der Lippe1d6e57a2019-09-30 11:55:34407 }
Blink Reformat4c46d092018-04-07 15:32:37408 if (this._reloadSuspensionCount) {
409 this._pendingReloadOptions = [bypassCache, scriptToEvaluateOnLoad];
410 return;
411 }
412 this._pendingReloadOptions = null;
Tim van der Lippe9b7d21d2019-10-07 18:48:07413 this.dispatchEventToListeners(Events.WillReloadPage);
Blink Reformat4c46d092018-04-07 15:32:37414 this._agent.reload(bypassCache, scriptToEvaluateOnLoad);
415 }
416
417 /**
418 * @param {string} url
419 * @return {!Promise}
420 */
421 navigate(url) {
422 return this._agent.navigate(url);
423 }
424
425 /**
Tim van der Lippeffa78622019-09-16 12:07:12426 * @return {!Promise<?{currentIndex: number, entries: !Array<!Protocol.Page.NavigationEntry>}>}
Blink Reformat4c46d092018-04-07 15:32:37427 */
428 async navigationHistory() {
429 const response = await this._agent.invoke_getNavigationHistory({});
Tim van der Lipped41d8632020-01-23 15:15:12430 if (response[ProtocolModule.InspectorBackend.ProtocolError]) {
Blink Reformat4c46d092018-04-07 15:32:37431 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34432 }
Blink Reformat4c46d092018-04-07 15:32:37433 return {currentIndex: response.currentIndex, entries: response.entries};
434 }
435
436 /**
437 * @param {!Protocol.Page.NavigationEntry} entry
438 */
439 navigateToHistoryEntry(entry) {
440 this._agent.navigateToHistoryEntry(entry.id);
441 }
442
443 /**
Pavel Feldmanb2bf4042018-12-18 03:39:58444 * @return {!Promise<{url: string, data: ?string, errors: !Array<!Protocol.Page.AppManifestError>}>}
Blink Reformat4c46d092018-04-07 15:32:37445 */
Pavel Feldmanb2bf4042018-12-18 03:39:58446 async fetchAppManifest() {
Blink Reformat4c46d092018-04-07 15:32:37447 const response = await this._agent.invoke_getAppManifest({});
Tim van der Lipped41d8632020-01-23 15:15:12448 if (response[ProtocolModule.InspectorBackend.ProtocolError]) {
Pavel Feldmanb2bf4042018-12-18 03:39:58449 return {url: response.url, data: null, errors: []};
Tim van der Lippe1d6e57a2019-09-30 11:55:34450 }
Pavel Feldmanb2bf4042018-12-18 03:39:58451 return {url: response.url, data: response.data || null, errors: response.errors};
Blink Reformat4c46d092018-04-07 15:32:37452 }
Pavel Feldman0c1a96a2019-04-11 03:02:17453
454 /**
Mandy Chenb7a76b22020-01-24 20:42:19455 * @return {!Promise<!Array<!Protocol.Page.InstallabilityError>>}
Pavel Feldman0c1a96a2019-04-11 03:02:17456 */
457 async getInstallabilityErrors() {
458 const response = await this._agent.invoke_getInstallabilityErrors({});
Mandy Chenb7a76b22020-01-24 20:42:19459 return response.installabilityErrors || [];
Pavel Feldman0c1a96a2019-04-11 03:02:17460 }
461
Blink Reformat4c46d092018-04-07 15:32:37462 /**
Jan Scheffler3c387a82019-12-16 07:50:29463 * @return {!Promise<{primaryIcon: ?string}>}
464 */
465 async getManifestIcons() {
466 const response = await this._agent.invoke_getManifestIcons({});
467 return {primaryIcon: response.primaryIcon || null};
468 }
469
470 /**
Tim van der Lippe9293af72020-01-17 10:50:37471 * @param {!ExecutionContext} a
Blink Reformat4c46d092018-04-07 15:32:37472 * @param {!SDK.ExecutionContext} b
473 * @return {number}
474 */
475 _executionContextComparator(a, b) {
476 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07477 * @param {!ResourceTreeFrame} frame
478 * @return {!Array<!ResourceTreeFrame>}
Blink Reformat4c46d092018-04-07 15:32:37479 */
480 function framePath(frame) {
481 let currentFrame = frame;
482 const parents = [];
483 while (currentFrame) {
484 parents.push(currentFrame);
485 currentFrame = currentFrame.parentFrame;
486 }
487 return parents.reverse();
488 }
489
Tim van der Lippe1d6e57a2019-09-30 11:55:34490 if (a.target() !== b.target()) {
Tim van der Lippe9293af72020-01-17 10:50:37491 return ExecutionContext.comparator(a, b);
Tim van der Lippe1d6e57a2019-09-30 11:55:34492 }
Blink Reformat4c46d092018-04-07 15:32:37493
494 const framesA = a.frameId ? framePath(this.frameForId(a.frameId)) : [];
495 const framesB = b.frameId ? framePath(this.frameForId(b.frameId)) : [];
496 let frameA;
497 let frameB;
498 for (let i = 0;; i++) {
499 if (!framesA[i] || !framesB[i] || (framesA[i] !== framesB[i])) {
500 frameA = framesA[i];
501 frameB = framesB[i];
502 break;
503 }
504 }
Tim van der Lippe1d6e57a2019-09-30 11:55:34505 if (!frameA && frameB) {
Blink Reformat4c46d092018-04-07 15:32:37506 return -1;
Tim van der Lippe1d6e57a2019-09-30 11:55:34507 }
Blink Reformat4c46d092018-04-07 15:32:37508
Tim van der Lippe1d6e57a2019-09-30 11:55:34509 if (!frameB && frameA) {
Blink Reformat4c46d092018-04-07 15:32:37510 return 1;
Tim van der Lippe1d6e57a2019-09-30 11:55:34511 }
Blink Reformat4c46d092018-04-07 15:32:37512
Tim van der Lippe1d6e57a2019-09-30 11:55:34513 if (frameA && frameB) {
Blink Reformat4c46d092018-04-07 15:32:37514 return frameA.id.localeCompare(frameB.id);
Tim van der Lippe1d6e57a2019-09-30 11:55:34515 }
Blink Reformat4c46d092018-04-07 15:32:37516
Tim van der Lippe9293af72020-01-17 10:50:37517 return ExecutionContext.comparator(a, b);
Blink Reformat4c46d092018-04-07 15:32:37518 }
519
Harley Li29038872019-03-27 20:50:04520 /**
521 * @return {!SDK.ResourceTreeModel.SecurityOriginData}
522 */
523 _getSecurityOriginData() {
Harley Liddf2b682019-03-08 22:35:23524 /** @type {!Set<string>} */
Blink Reformat4c46d092018-04-07 15:32:37525 const securityOrigins = new Set();
Harley Liddf2b682019-03-08 22:35:23526
Blink Reformat4c46d092018-04-07 15:32:37527 let mainSecurityOrigin = null;
Harley Liddf2b682019-03-08 22:35:23528 let unreachableMainSecurityOrigin = null;
Blink Reformat4c46d092018-04-07 15:32:37529 for (const frame of this._frames.values()) {
530 const origin = frame.securityOrigin;
Tim van der Lippe1d6e57a2019-09-30 11:55:34531 if (!origin) {
Blink Reformat4c46d092018-04-07 15:32:37532 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34533 }
Harley Liddf2b682019-03-08 22:35:23534
Blink Reformat4c46d092018-04-07 15:32:37535 securityOrigins.add(origin);
Harley Liddf2b682019-03-08 22:35:23536 if (frame.isMainFrame()) {
Blink Reformat4c46d092018-04-07 15:32:37537 mainSecurityOrigin = origin;
Harley Liddf2b682019-03-08 22:35:23538 if (frame.unreachableUrl()) {
Tim van der Lipped41d8632020-01-23 15:15:12539 const unreachableParsed = new Common.ParsedURL.ParsedURL(frame.unreachableUrl());
Harley Liddf2b682019-03-08 22:35:23540 unreachableMainSecurityOrigin = unreachableParsed.securityOrigin();
541 }
542 }
Blink Reformat4c46d092018-04-07 15:32:37543 }
Harley Li29038872019-03-27 20:50:04544 return {
545 securityOrigins: securityOrigins,
546 mainSecurityOrigin: mainSecurityOrigin,
547 unreachableMainSecurityOrigin: unreachableMainSecurityOrigin
548 };
549 }
550
551 _updateSecurityOrigins() {
552 const data = this._getSecurityOriginData();
553 this._securityOriginManager.setMainSecurityOrigin(
554 data.mainSecurityOrigin || '', data.unreachableMainSecurityOrigin || '');
555 this._securityOriginManager.updateSecurityOrigins(data.securityOrigins);
556 }
557
558 /**
559 * @return {?string}
560 */
561 getMainSecurityOrigin() {
562 const data = this._getSecurityOriginData();
563 return data.mainSecurityOrigin || data.unreachableMainSecurityOrigin;
Blink Reformat4c46d092018-04-07 15:32:37564 }
Tim van der Lippe9b7d21d2019-10-07 18:48:07565}
Harley Li29038872019-03-27 20:50:04566
Blink Reformat4c46d092018-04-07 15:32:37567/** @enum {symbol} */
Tim van der Lippe9b7d21d2019-10-07 18:48:07568export const Events = {
Blink Reformat4c46d092018-04-07 15:32:37569 FrameAdded: Symbol('FrameAdded'),
570 FrameNavigated: Symbol('FrameNavigated'),
571 FrameDetached: Symbol('FrameDetached'),
572 FrameResized: Symbol('FrameResized'),
573 FrameWillNavigate: Symbol('FrameWillNavigate'),
574 MainFrameNavigated: Symbol('MainFrameNavigated'),
575 ResourceAdded: Symbol('ResourceAdded'),
576 WillLoadCachedResources: Symbol('WillLoadCachedResources'),
577 CachedResourcesLoaded: Symbol('CachedResourcesLoaded'),
578 DOMContentLoaded: Symbol('DOMContentLoaded'),
579 LifecycleEvent: Symbol('LifecycleEvent'),
580 Load: Symbol('Load'),
581 PageReloadRequested: Symbol('PageReloadRequested'),
582 WillReloadPage: Symbol('WillReloadPage'),
583 InterstitialShown: Symbol('InterstitialShown'),
584 InterstitialHidden: Symbol('InterstitialHidden')
585};
586
Blink Reformat4c46d092018-04-07 15:32:37587/**
588 * @unrestricted
589 */
Tim van der Lippe9b7d21d2019-10-07 18:48:07590export class ResourceTreeFrame {
Blink Reformat4c46d092018-04-07 15:32:37591 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07592 * @param {!ResourceTreeModel} model
593 * @param {?ResourceTreeFrame} parentFrame
Blink Reformat4c46d092018-04-07 15:32:37594 * @param {!Protocol.Page.FrameId} frameId
595 * @param {?Protocol.Page.Frame} payload
596 * @param {?Protocol.Runtime.StackTrace} creationStackTrace
597 */
598 constructor(model, parentFrame, frameId, payload, creationStackTrace) {
599 this._model = model;
600 this._parentFrame = parentFrame;
601 this._id = frameId;
602 this._url = '';
603 this._crossTargetParentFrameId = null;
604
605 if (payload) {
606 this._loaderId = payload.loaderId;
607 this._name = payload.name;
608 this._url = payload.url;
609 this._securityOrigin = payload.securityOrigin;
610 this._mimeType = payload.mimeType;
Harley Liddf2b682019-03-08 22:35:23611 this._unreachableUrl = payload.unreachableUrl || '';
Blink Reformat4c46d092018-04-07 15:32:37612 }
613
614 this._creationStackTrace = creationStackTrace;
615
616 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07617 * @type {!Array.<!ResourceTreeFrame>}
Blink Reformat4c46d092018-04-07 15:32:37618 */
619 this._childFrames = [];
620
621 /**
Tim van der Lippe9293af72020-01-17 10:50:37622 * @type {!Object.<string, !Resource>}
Blink Reformat4c46d092018-04-07 15:32:37623 */
624 this._resourcesMap = {};
625
Tim van der Lippe1d6e57a2019-09-30 11:55:34626 if (this._parentFrame) {
Blink Reformat4c46d092018-04-07 15:32:37627 this._parentFrame._childFrames.push(this);
Tim van der Lippe1d6e57a2019-09-30 11:55:34628 }
Blink Reformat4c46d092018-04-07 15:32:37629 }
630
Harley Liddf2b682019-03-08 22:35:23631
632 /**
633 * @param {!Protocol.Page.Frame} framePayload
634 */
635 _navigate(framePayload) {
636 this._loaderId = framePayload.loaderId;
637 this._name = framePayload.name;
638 this._url = framePayload.url;
639 this._securityOrigin = framePayload.securityOrigin;
640 this._mimeType = framePayload.mimeType;
641 this._unreachableUrl = framePayload.unreachableUrl || '';
642 const mainResource = this._resourcesMap[this._url];
643 this._resourcesMap = {};
644 this._removeChildFrames();
Tim van der Lippe1d6e57a2019-09-30 11:55:34645 if (mainResource && mainResource.loaderId === this._loaderId) {
Harley Liddf2b682019-03-08 22:35:23646 this.addResource(mainResource);
Tim van der Lippe1d6e57a2019-09-30 11:55:34647 }
Harley Liddf2b682019-03-08 22:35:23648 }
649
Blink Reformat4c46d092018-04-07 15:32:37650 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07651 * @return {!ResourceTreeModel}
Blink Reformat4c46d092018-04-07 15:32:37652 */
653 resourceTreeModel() {
654 return this._model;
655 }
656
657 /**
658 * @return {string}
659 */
660 get id() {
661 return this._id;
662 }
663
664 /**
665 * @return {string}
666 */
667 get name() {
668 return this._name || '';
669 }
670
671 /**
672 * @return {string}
673 */
674 get url() {
675 return this._url;
676 }
677
678 /**
679 * @return {string}
680 */
681 get securityOrigin() {
682 return this._securityOrigin;
683 }
684
685 /**
686 * @return {string}
687 */
Harley Liddf2b682019-03-08 22:35:23688 unreachableUrl() {
689 return this._unreachableUrl;
690 }
691
692 /**
693 * @return {string}
694 */
Blink Reformat4c46d092018-04-07 15:32:37695 get loaderId() {
696 return this._loaderId;
697 }
698
699 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07700 * @return {?ResourceTreeFrame}
Blink Reformat4c46d092018-04-07 15:32:37701 */
702 get parentFrame() {
703 return this._parentFrame;
704 }
705
706 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07707 * @return {!Array.<!ResourceTreeFrame>}
Blink Reformat4c46d092018-04-07 15:32:37708 */
709 get childFrames() {
710 return this._childFrames;
711 }
712
713 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07714 * @return {?ResourceTreeFrame}
Blink Reformat4c46d092018-04-07 15:32:37715 */
716 crossTargetParentFrame() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34717 if (!this._crossTargetParentFrameId) {
Blink Reformat4c46d092018-04-07 15:32:37718 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34719 }
720 if (!this._model.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37721 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34722 }
Tim van der Lippe9b7d21d2019-10-07 18:48:07723 const parentModel = this._model.target().parentTarget().model(ResourceTreeModel);
Tim van der Lippe1d6e57a2019-09-30 11:55:34724 if (!parentModel) {
Blink Reformat4c46d092018-04-07 15:32:37725 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34726 }
Blink Reformat4c46d092018-04-07 15:32:37727 // Note that parent model has already processed cached resources:
728 // - when parent target was created, we issued getResourceTree call;
729 // - strictly after we issued setAutoAttach call;
730 // - both of them were handled in renderer in the same order;
731 // - cached resource tree got processed on parent model;
732 // - child target was created as a result of setAutoAttach call.
733 return parentModel._frames.get(this._crossTargetParentFrameId) || null;
734 }
735
736 /**
737 * @param {function(!Protocol.Runtime.CallFrame):boolean} searchFn
738 * @return {?Protocol.Runtime.CallFrame}
739 */
740 findCreationCallFrame(searchFn) {
741 let stackTrace = this._creationStackTrace;
742 while (stackTrace) {
743 const foundEntry = stackTrace.callFrames.find(searchFn);
Tim van der Lippe1d6e57a2019-09-30 11:55:34744 if (foundEntry) {
Blink Reformat4c46d092018-04-07 15:32:37745 return foundEntry;
Tim van der Lippe1d6e57a2019-09-30 11:55:34746 }
Blink Reformat4c46d092018-04-07 15:32:37747 stackTrace = this.parent;
748 }
749 return null;
750 }
751
752 /**
753 * @return {boolean}
754 */
755 isMainFrame() {
756 return !this._parentFrame;
757 }
758
759 isTopFrame() {
760 return !this._parentFrame && !this._crossTargetParentFrameId;
761 }
762
763 /**
Tim van der Lippe9293af72020-01-17 10:50:37764 * @return {!Resource}
Blink Reformat4c46d092018-04-07 15:32:37765 */
766 get mainResource() {
767 return this._resourcesMap[this._url];
768 }
769
770 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07771 * @param {!ResourceTreeFrame} frame
Blink Reformat4c46d092018-04-07 15:32:37772 */
773 _removeChildFrame(frame) {
774 this._childFrames.remove(frame);
775 frame._remove();
776 }
777
778 _removeChildFrames() {
779 const frames = this._childFrames;
780 this._childFrames = [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34781 for (let i = 0; i < frames.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:37782 frames[i]._remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34783 }
Blink Reformat4c46d092018-04-07 15:32:37784 }
785
786 _remove() {
787 this._removeChildFrames();
788 this._model._frames.delete(this.id);
Tim van der Lippe9b7d21d2019-10-07 18:48:07789 this._model.dispatchEventToListeners(Events.FrameDetached, this);
Blink Reformat4c46d092018-04-07 15:32:37790 }
791
792 /**
Tim van der Lippe9293af72020-01-17 10:50:37793 * @param {!Resource} resource
Blink Reformat4c46d092018-04-07 15:32:37794 */
795 addResource(resource) {
796 if (this._resourcesMap[resource.url] === resource) {
797 // Already in the tree, we just got an extra update.
798 return;
799 }
800 this._resourcesMap[resource.url] = resource;
Tim van der Lippe9b7d21d2019-10-07 18:48:07801 this._model.dispatchEventToListeners(Events.ResourceAdded, resource);
Blink Reformat4c46d092018-04-07 15:32:37802 }
803
804 /**
Tim van der Lippe9293af72020-01-17 10:50:37805 * @param {!NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37806 */
807 _addRequest(request) {
808 let resource = this._resourcesMap[request.url()];
809 if (resource && resource.request === request) {
810 // Already in the tree, we just got an extra update.
811 return;
812 }
Tim van der Lippe9293af72020-01-17 10:50:37813 resource = new Resource(
Blink Reformat4c46d092018-04-07 15:32:37814 this._model, request, request.url(), request.documentURL, request.frameId, request.loaderId,
815 request.resourceType(), request.mimeType, null, null);
816 this._resourcesMap[resource.url] = resource;
Tim van der Lippe9b7d21d2019-10-07 18:48:07817 this._model.dispatchEventToListeners(Events.ResourceAdded, resource);
Blink Reformat4c46d092018-04-07 15:32:37818 }
819
820 /**
Tim van der Lippe9293af72020-01-17 10:50:37821 * @return {!Array.<!Resource>}
Blink Reformat4c46d092018-04-07 15:32:37822 */
823 resources() {
824 const result = [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34825 for (const url in this._resourcesMap) {
Blink Reformat4c46d092018-04-07 15:32:37826 result.push(this._resourcesMap[url]);
Tim van der Lippe1d6e57a2019-09-30 11:55:34827 }
Blink Reformat4c46d092018-04-07 15:32:37828 return result;
829 }
830
831 /**
832 * @param {string} url
Tim van der Lippe9293af72020-01-17 10:50:37833 * @return {?Resource}
Blink Reformat4c46d092018-04-07 15:32:37834 */
835 resourceForURL(url) {
836 let resource = this._resourcesMap[url] || null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34837 if (resource) {
Blink Reformat4c46d092018-04-07 15:32:37838 return resource;
Tim van der Lippe1d6e57a2019-09-30 11:55:34839 }
840 for (let i = 0; !resource && i < this._childFrames.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:37841 resource = this._childFrames[i].resourceForURL(url);
Tim van der Lippe1d6e57a2019-09-30 11:55:34842 }
Blink Reformat4c46d092018-04-07 15:32:37843 return resource;
844 }
845
846 /**
Tim van der Lippe9293af72020-01-17 10:50:37847 * @param {function(!Resource)} callback
Blink Reformat4c46d092018-04-07 15:32:37848 * @return {boolean}
849 */
850 _callForFrameResources(callback) {
851 for (const url in this._resourcesMap) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34852 if (callback(this._resourcesMap[url])) {
Blink Reformat4c46d092018-04-07 15:32:37853 return true;
Tim van der Lippe1d6e57a2019-09-30 11:55:34854 }
Blink Reformat4c46d092018-04-07 15:32:37855 }
856
857 for (let i = 0; i < this._childFrames.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34858 if (this._childFrames[i]._callForFrameResources(callback)) {
Blink Reformat4c46d092018-04-07 15:32:37859 return true;
Tim van der Lippe1d6e57a2019-09-30 11:55:34860 }
Blink Reformat4c46d092018-04-07 15:32:37861 }
862 return false;
863 }
864
865 /**
866 * @return {string}
867 */
868 displayName() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34869 if (this.isTopFrame()) {
Tim van der Lipped41d8632020-01-23 15:15:12870 return Common.UIString.UIString('top');
Tim van der Lippe1d6e57a2019-09-30 11:55:34871 }
Tim van der Lipped41d8632020-01-23 15:15:12872 const subtitle = new Common.ParsedURL.ParsedURL(this._url).displayName;
Blink Reformat4c46d092018-04-07 15:32:37873 if (subtitle) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34874 if (!this._name) {
Blink Reformat4c46d092018-04-07 15:32:37875 return subtitle;
Tim van der Lippe1d6e57a2019-09-30 11:55:34876 }
Blink Reformat4c46d092018-04-07 15:32:37877 return this._name + ' (' + subtitle + ')';
878 }
Tim van der Lipped41d8632020-01-23 15:15:12879 return Common.UIString.UIString('<iframe>');
Blink Reformat4c46d092018-04-07 15:32:37880 }
Tim van der Lippe9b7d21d2019-10-07 18:48:07881}
Blink Reformat4c46d092018-04-07 15:32:37882
883/**
884 * @implements {Protocol.PageDispatcher}
885 * @unrestricted
886 */
Tim van der Lippe9b7d21d2019-10-07 18:48:07887export class PageDispatcher {
Blink Reformat4c46d092018-04-07 15:32:37888 /**
Tim van der Lippe9b7d21d2019-10-07 18:48:07889 * @param {!ResourceTreeModel} resourceTreeModel
Blink Reformat4c46d092018-04-07 15:32:37890 */
891 constructor(resourceTreeModel) {
892 this._resourceTreeModel = resourceTreeModel;
893 }
894
895 /**
896 * @override
897 * @param {number} time
898 */
899 domContentEventFired(time) {
Tim van der Lippe9b7d21d2019-10-07 18:48:07900 this._resourceTreeModel.dispatchEventToListeners(Events.DOMContentLoaded, time);
Blink Reformat4c46d092018-04-07 15:32:37901 }
902
903 /**
904 * @override
905 * @param {number} time
906 */
907 loadEventFired(time) {
908 this._resourceTreeModel.dispatchEventToListeners(
Tim van der Lippe9b7d21d2019-10-07 18:48:07909 Events.Load, {resourceTreeModel: this._resourceTreeModel, loadTime: time});
Blink Reformat4c46d092018-04-07 15:32:37910 }
911
912 /**
913 * @override
914 * @param {!Protocol.Page.FrameId} frameId
915 * @param {!Protocol.Network.LoaderId} loaderId
916 * @param {string} name
917 * @param {number} time
918 */
919 lifecycleEvent(frameId, loaderId, name, time) {
Tim van der Lippe9b7d21d2019-10-07 18:48:07920 this._resourceTreeModel.dispatchEventToListeners(Events.LifecycleEvent, {frameId, name});
Blink Reformat4c46d092018-04-07 15:32:37921 }
922
923 /**
924 * @override
925 * @param {!Protocol.Page.FrameId} frameId
926 * @param {!Protocol.Page.FrameId} parentFrameId
927 * @param {!Protocol.Runtime.StackTrace=} stackTrace
928 */
929 frameAttached(frameId, parentFrameId, stackTrace) {
930 this._resourceTreeModel._frameAttached(frameId, parentFrameId, stackTrace);
931 }
932
933 /**
934 * @override
935 * @param {!Protocol.Page.Frame} frame
936 */
937 frameNavigated(frame) {
938 this._resourceTreeModel._frameNavigated(frame);
939 }
940
941 /**
942 * @override
943 * @param {!Protocol.Page.FrameId} frameId
944 */
945 frameDetached(frameId) {
946 this._resourceTreeModel._frameDetached(frameId);
947 }
948
949 /**
950 * @override
951 * @param {!Protocol.Page.FrameId} frameId
952 */
953 frameStartedLoading(frameId) {
954 }
955
956 /**
957 * @override
958 * @param {!Protocol.Page.FrameId} frameId
959 */
960 frameStoppedLoading(frameId) {
961 }
962
963 /**
964 * @override
965 * @param {!Protocol.Page.FrameId} frameId
Andrey Kosyakov645b5a12019-03-26 01:41:41966 */
967 frameRequestedNavigation(frameId) {
968 }
969
970 /**
971 * @override
972 * @param {!Protocol.Page.FrameId} frameId
Blink Reformat4c46d092018-04-07 15:32:37973 * @param {number} delay
974 */
975 frameScheduledNavigation(frameId, delay) {
976 }
977
978 /**
979 * @override
980 * @param {!Protocol.Page.FrameId} frameId
981 */
982 frameClearedScheduledNavigation(frameId) {
983 }
984
985 /**
986 * @override
987 * @param {!Protocol.Page.FrameId} frameId
988 * @param {string} url
989 */
990 navigatedWithinDocument(frameId, url) {
991 }
992
993 /**
994 * @override
995 */
996 frameResized() {
Tim van der Lippe9b7d21d2019-10-07 18:48:07997 this._resourceTreeModel.dispatchEventToListeners(Events.FrameResized, null);
Blink Reformat4c46d092018-04-07 15:32:37998 }
999
1000 /**
1001 * @override
1002 * @param {string} url
1003 * @param {string} message
1004 * @param {string} dialogType
1005 * @param {boolean} hasBrowserHandler
1006 * @param {string=} prompt
1007 */
1008 javascriptDialogOpening(url, message, dialogType, hasBrowserHandler, prompt) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341009 if (!hasBrowserHandler) {
Blink Reformat4c46d092018-04-07 15:32:371010 this._resourceTreeModel._agent.handleJavaScriptDialog(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341011 }
Blink Reformat4c46d092018-04-07 15:32:371012 }
1013
1014 /**
1015 * @override
1016 * @param {boolean} result
1017 * @param {string} userInput
1018 */
1019 javascriptDialogClosed(result, userInput) {
1020 }
1021
1022 /**
1023 * @override
1024 * @param {string} data
1025 * @param {!Protocol.Page.ScreencastFrameMetadata} metadata
1026 * @param {number} sessionId
1027 */
1028 screencastFrame(data, metadata, sessionId) {
1029 }
1030
1031 /**
1032 * @override
1033 * @param {boolean} visible
1034 */
1035 screencastVisibilityChanged(visible) {
1036 }
1037
1038 /**
1039 * @override
1040 */
1041 interstitialShown() {
1042 this._resourceTreeModel._isInterstitialShowing = true;
Tim van der Lippe9b7d21d2019-10-07 18:48:071043 this._resourceTreeModel.dispatchEventToListeners(Events.InterstitialShown);
Blink Reformat4c46d092018-04-07 15:32:371044 }
1045
1046 /**
1047 * @override
1048 */
1049 interstitialHidden() {
1050 this._resourceTreeModel._isInterstitialShowing = false;
Tim van der Lippe9b7d21d2019-10-07 18:48:071051 this._resourceTreeModel.dispatchEventToListeners(Events.InterstitialHidden);
Blink Reformat4c46d092018-04-07 15:32:371052 }
1053
1054 /**
1055 * @override
1056 * @param {string} url
1057 * @param {string} windowName
1058 * @param {!Array<string>} windowFeatures
1059 * @param {boolean} userGesture
1060 */
1061 windowOpen(url, windowName, windowFeatures, userGesture) {
1062 }
Pavel Feldmana46ed3a2018-07-19 17:22:401063
1064 /**
1065 * @override
1066 * @param {string} url
1067 * @param {string} data
1068 */
1069 compilationCacheProduced(url, data) {
1070 }
Andrey Kosyakovffd1ef92019-04-26 19:36:051071
1072 /**
1073 * @override
Andrey Lushnikovf42bffc2019-06-27 23:27:211074 * @param {string} mode
1075 */
1076 fileChooserOpened(mode) {
1077 }
1078
1079 /**
1080 * @override
Andrey Kosyakovffd1ef92019-04-26 19:36:051081 * @param {!Protocol.Page.FrameId} frameId
1082 * @param {string} url
1083 */
1084 downloadWillBegin(frameId, url) {
1085 }
Tim van der Lippe9b7d21d2019-10-07 18:48:071086}
1087
Tim van der Lippe9293af72020-01-17 10:50:371088SDKModel.register(ResourceTreeModel, Capability.DOM, true);