Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ResourceTreeModel.js

Issue 2186753002: [DevTools] Track URL through the target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 this._agent = target.pageAgent(); 48 this._agent = target.pageAgent();
49 this._agent.enable(); 49 this._agent.enable();
50 this._securityOriginManager = securityOriginManager; 50 this._securityOriginManager = securityOriginManager;
51 51
52 this._fetchResourceTree(); 52 this._fetchResourceTree();
53 53
54 target.registerPageDispatcher(new WebInspector.PageDispatcher(this)); 54 target.registerPageDispatcher(new WebInspector.PageDispatcher(this));
55 55
56 this._inspectedPageURL = "";
57 this._pendingReloadOptions = null; 56 this._pendingReloadOptions = null;
58 this._reloadSuspensionCount = 0; 57 this._reloadSuspensionCount = 0;
59 58
60 target.runtimeModel.setExecutionContextComparator(this._executionContextComp arator.bind(this)); 59 target.runtimeModel.setExecutionContextComparator(this._executionContextComp arator.bind(this));
61 } 60 }
62 61
63 WebInspector.ResourceTreeModel.EventTypes = { 62 WebInspector.ResourceTreeModel.EventTypes = {
64 FrameAdded: "FrameAdded", 63 FrameAdded: "FrameAdded",
65 FrameNavigated: "FrameNavigated", 64 FrameNavigated: "FrameNavigated",
66 FrameDetached: "FrameDetached", 65 FrameDetached: "FrameDetached",
67 FrameResized: "FrameResized", 66 FrameResized: "FrameResized",
68 FrameWillNavigate: "FrameWillNavigate", 67 FrameWillNavigate: "FrameWillNavigate",
69 MainFrameNavigated: "MainFrameNavigated", 68 MainFrameNavigated: "MainFrameNavigated",
70 ResourceAdded: "ResourceAdded", 69 ResourceAdded: "ResourceAdded",
71 WillLoadCachedResources: "WillLoadCachedResources", 70 WillLoadCachedResources: "WillLoadCachedResources",
72 CachedResourcesLoaded: "CachedResourcesLoaded", 71 CachedResourcesLoaded: "CachedResourcesLoaded",
73 DOMContentLoaded: "DOMContentLoaded", 72 DOMContentLoaded: "DOMContentLoaded",
74 Load: "Load", 73 Load: "Load",
75 PageReloadRequested: "PageReloadRequested", 74 PageReloadRequested: "PageReloadRequested",
76 WillReloadPage: "WillReloadPage", 75 WillReloadPage: "WillReloadPage",
77 InspectedURLChanged: "InspectedURLChanged",
78 ScreencastFrame: "ScreencastFrame", 76 ScreencastFrame: "ScreencastFrame",
79 ScreencastVisibilityChanged: "ScreencastVisibilityChanged", 77 ScreencastVisibilityChanged: "ScreencastVisibilityChanged",
80 ColorPicked: "ColorPicked" 78 ColorPicked: "ColorPicked"
81 } 79 }
82 80
83 /** 81 /**
84 * @param {!WebInspector.Target} target 82 * @param {!WebInspector.Target} target
85 * @return {?WebInspector.ResourceTreeModel} 83 * @return {?WebInspector.ResourceTreeModel}
86 */ 84 */
87 WebInspector.ResourceTreeModel.fromTarget = function(target) 85 WebInspector.ResourceTreeModel.fromTarget = function(target)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 /** @type {!Map<string, !WebInspector.ResourceTreeFrame>} */ 119 /** @type {!Map<string, !WebInspector.ResourceTreeFrame>} */
122 this._frames = new Map(); 120 this._frames = new Map();
123 this._cachedResourcesProcessed = false; 121 this._cachedResourcesProcessed = false;
124 this._agent.getResourceTree(this._processCachedResources.bind(this)); 122 this._agent.getResourceTree(this._processCachedResources.bind(this));
125 }, 123 },
126 124
127 _processCachedResources: function(error, mainFramePayload) 125 _processCachedResources: function(error, mainFramePayload)
128 { 126 {
129 if (!error) { 127 if (!error) {
130 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.WillLoadCachedResources); 128 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.WillLoadCachedResources);
131 this._inspectedPageURL = mainFramePayload.frame.url;
132 this._addFramesRecursively(null, mainFramePayload); 129 this._addFramesRecursively(null, mainFramePayload);
133 this._dispatchInspectedURLChanged(); 130 this.target().setInspectedURL(mainFramePayload.frame.url);
134 } 131 }
135 this._cachedResourcesProcessed = true; 132 this._cachedResourcesProcessed = true;
136 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded); 133 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded);
137 }, 134 },
138 135
139 /** 136 /**
140 * @return {string}
141 */
142 inspectedPageURL: function()
143 {
144 return this._inspectedPageURL;
145 },
146
147 /**
148 * @return {string}
149 */
150 inspectedPageDomain: function()
151 {
152 var parsedURL = this._inspectedPageURL ? this._inspectedPageURL.asParsed URL() : null;
153 return parsedURL ? parsedURL.host : "";
154 },
155
156 /**
157 * @return {boolean} 137 * @return {boolean}
158 */ 138 */
159 cachedResourcesLoaded: function() 139 cachedResourcesLoaded: function()
160 { 140 {
161 return this._cachedResourcesProcessed; 141 return this._cachedResourcesProcessed;
162 }, 142 },
163 143
164 _dispatchInspectedURLChanged: function()
165 {
166 InspectorFrontendHost.inspectedURLChanged(this._inspectedPageURL);
167 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. InspectedURLChanged, this._inspectedPageURL);
168 },
169
170 /** 144 /**
171 * @param {!WebInspector.ResourceTreeFrame} frame 145 * @param {!WebInspector.ResourceTreeFrame} frame
172 * @param {boolean=} aboutToNavigate 146 * @param {boolean=} aboutToNavigate
173 */ 147 */
174 _addFrame: function(frame, aboutToNavigate) 148 _addFrame: function(frame, aboutToNavigate)
175 { 149 {
176 this._frames.set(frame.id, frame); 150 this._frames.set(frame.id, frame);
177 if (frame.isMainFrame()) { 151 if (frame.isMainFrame()) {
178 this.mainFrame = frame; 152 this.mainFrame = frame;
179 this._securityOriginManager.setMainSecurityOrigin(frame.url); 153 this._securityOriginManager.setMainSecurityOrigin(frame.url);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 frame = this._frameAttached(framePayload.id, framePayload.parentId | | ""); 215 frame = this._frameAttached(framePayload.id, framePayload.parentId | | "");
242 console.assert(frame); 216 console.assert(frame);
243 } 217 }
244 218
245 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame); 219 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame);
246 220
247 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin); 221 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin);
248 frame._navigate(framePayload); 222 frame._navigate(framePayload);
249 var addedOrigin = frame.securityOrigin; 223 var addedOrigin = frame.securityOrigin;
250 224
251 if (frame.isMainFrame())
252 this._inspectedPageURL = frame.url;
253
254 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameNavigated, frame); 225 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameNavigated, frame);
255 if (frame.isMainFrame()) { 226 if (frame.isMainFrame()) {
256 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.MainFrameNavigated, frame); 227 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.MainFrameNavigated, frame);
257 if (WebInspector.moduleSetting("preserveConsoleLog").get()) 228 if (WebInspector.moduleSetting("preserveConsoleLog").get())
258 WebInspector.console.log(WebInspector.UIString("Navigated to %s" , frame.url)); 229 WebInspector.console.log(WebInspector.UIString("Navigated to %s" , frame.url));
259 else 230 else
260 this.target().consoleModel.clear(); 231 this.target().consoleModel.clear();
261 } 232 }
262 if (addedOrigin) 233 if (addedOrigin)
263 this._securityOriginManager.addSecurityOrigin(addedOrigin); 234 this._securityOriginManager.addSecurityOrigin(addedOrigin);
264 235
265 // Fill frame with retained resources (the ones loaded using new loader) . 236 // Fill frame with retained resources (the ones loaded using new loader) .
266 var resources = frame.resources(); 237 var resources = frame.resources();
267 for (var i = 0; i < resources.length; ++i) 238 for (var i = 0; i < resources.length; ++i)
268 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.ResourceAdded, resources[i]); 239 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.ResourceAdded, resources[i]);
269 240
270 if (frame.isMainFrame()) 241 if (frame.isMainFrame())
271 this._dispatchInspectedURLChanged(); 242 this.target().setInspectedURL(frame.url);
272 }, 243 },
273 244
274 /** 245 /**
275 * @param {!PageAgent.FrameId} frameId 246 * @param {!PageAgent.FrameId} frameId
276 */ 247 */
277 _frameDetached: function(frameId) 248 _frameDetached: function(frameId)
278 { 249 {
279 // Do nothing unless cached resource tree is processed - it will overwri te everything. 250 // Do nothing unless cached resource tree is processed - it will overwri te everything.
280 if (!this._cachedResourcesProcessed) 251 if (!this._cachedResourcesProcessed)
281 return; 252 return;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 * @param {?WebInspector.ResourceTreeFrame} parentFrame 342 * @param {?WebInspector.ResourceTreeFrame} parentFrame
372 * @param {!PageAgent.FrameResourceTree} frameTreePayload 343 * @param {!PageAgent.FrameResourceTree} frameTreePayload
373 */ 344 */
374 _addFramesRecursively: function(parentFrame, frameTreePayload) 345 _addFramesRecursively: function(parentFrame, frameTreePayload)
375 { 346 {
376 var framePayload = frameTreePayload.frame; 347 var framePayload = frameTreePayload.frame;
377 var frame = new WebInspector.ResourceTreeFrame(this, parentFrame, frameP ayload.id, framePayload); 348 var frame = new WebInspector.ResourceTreeFrame(this, parentFrame, frameP ayload.id, framePayload);
378 this._addFrame(frame); 349 this._addFrame(frame);
379 350
380 var frameResource = this._createResourceFromFramePayload(framePayload, f ramePayload.url, WebInspector.resourceTypes.Document, framePayload.mimeType); 351 var frameResource = this._createResourceFromFramePayload(framePayload, f ramePayload.url, WebInspector.resourceTypes.Document, framePayload.mimeType);
381 if (frame.isMainFrame())
382 this._inspectedPageURL = frameResource.url;
383 frame.addResource(frameResource); 352 frame.addResource(frameResource);
384 353
385 for (var i = 0; frameTreePayload.childFrames && i < frameTreePayload.chi ldFrames.length; ++i) 354 for (var i = 0; frameTreePayload.childFrames && i < frameTreePayload.chi ldFrames.length; ++i)
386 this._addFramesRecursively(frame, frameTreePayload.childFrames[i]); 355 this._addFramesRecursively(frame, frameTreePayload.childFrames[i]);
387 356
388 for (var i = 0; i < frameTreePayload.resources.length; ++i) { 357 for (var i = 0; i < frameTreePayload.resources.length; ++i) {
389 var subresource = frameTreePayload.resources[i]; 358 var subresource = frameTreePayload.resources[i];
390 var resource = this._createResourceFromFramePayload(framePayload, su bresource.url, WebInspector.resourceTypes[subresource.type], subresource.mimeTyp e); 359 var resource = this._createResourceFromFramePayload(framePayload, su bresource.url, WebInspector.resourceTypes[subresource.type], subresource.mimeTyp e);
391 frame.addResource(resource); 360 frame.addResource(resource);
392 } 361 }
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 930
962 /** 931 /**
963 * @override 932 * @override
964 */ 933 */
965 navigationRequested: function() 934 navigationRequested: function()
966 { 935 {
967 // Frontend is not interested in interstitials. 936 // Frontend is not interested in interstitials.
968 } 937 }
969 938
970 } 939 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698