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

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

Issue 2172753002: [DevTools] No longer store security origins in ResourceTreeModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test failures 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.SDKModel} 33 * @extends {WebInspector.SDKModel}
34 * @param {!WebInspector.Target} target 34 * @param {!WebInspector.Target} target
35 * @param {?WebInspector.NetworkManager} networkManager 35 * @param {?WebInspector.NetworkManager} networkManager
36 * @param {!WebInspector.SecurityOriginManager} securityOriginManager
36 */ 37 */
37 WebInspector.ResourceTreeModel = function(target, networkManager) 38 WebInspector.ResourceTreeModel = function(target, networkManager, securityOrigin Manager)
38 { 39 {
39 WebInspector.SDKModel.call(this, WebInspector.ResourceTreeModel, target); 40 WebInspector.SDKModel.call(this, WebInspector.ResourceTreeModel, target);
40 if (networkManager) { 41 if (networkManager) {
41 networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.R equestFinished, 42 networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.R equestFinished,
42 this._onRequestFinished, this); 43 this._onRequestFinished, this);
43 networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.R equestUpdateDropped, 44 networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.R equestUpdateDropped,
44 this._onRequestUpdateDropped, this); 45 this._onRequestUpdateDropped, this);
45 } 46 }
46 47
47 this._agent = target.pageAgent(); 48 this._agent = target.pageAgent();
48 this._agent.enable(); 49 this._agent.enable();
50 this._securityOriginManager = securityOriginManager;
49 51
50 this._fetchResourceTree(); 52 this._fetchResourceTree();
51 53
52 target.registerPageDispatcher(new WebInspector.PageDispatcher(this)); 54 target.registerPageDispatcher(new WebInspector.PageDispatcher(this));
53 55
54 this._securityOriginFrameCount = {};
55 this._inspectedPageURL = ""; 56 this._inspectedPageURL = "";
56 this._pendingReloadOptions = null; 57 this._pendingReloadOptions = null;
57 this._reloadSuspensionCount = 0; 58 this._reloadSuspensionCount = 0;
58 59
59 target.runtimeModel.setExecutionContextComparator(this._executionContextComp arator.bind(this)); 60 target.runtimeModel.setExecutionContextComparator(this._executionContextComp arator.bind(this));
60 } 61 }
61 62
62 WebInspector.ResourceTreeModel.EventTypes = { 63 WebInspector.ResourceTreeModel.EventTypes = {
63 FrameAdded: "FrameAdded", 64 FrameAdded: "FrameAdded",
64 FrameNavigated: "FrameNavigated", 65 FrameNavigated: "FrameNavigated",
65 FrameDetached: "FrameDetached", 66 FrameDetached: "FrameDetached",
66 FrameResized: "FrameResized", 67 FrameResized: "FrameResized",
67 FrameWillNavigate: "FrameWillNavigate", 68 FrameWillNavigate: "FrameWillNavigate",
68 MainFrameNavigated: "MainFrameNavigated", 69 MainFrameNavigated: "MainFrameNavigated",
69 ResourceAdded: "ResourceAdded", 70 ResourceAdded: "ResourceAdded",
70 WillLoadCachedResources: "WillLoadCachedResources", 71 WillLoadCachedResources: "WillLoadCachedResources",
71 CachedResourcesLoaded: "CachedResourcesLoaded", 72 CachedResourcesLoaded: "CachedResourcesLoaded",
72 DOMContentLoaded: "DOMContentLoaded", 73 DOMContentLoaded: "DOMContentLoaded",
73 Load: "Load", 74 Load: "Load",
74 PageReloadRequested: "PageReloadRequested", 75 PageReloadRequested: "PageReloadRequested",
75 WillReloadPage: "WillReloadPage", 76 WillReloadPage: "WillReloadPage",
76 InspectedURLChanged: "InspectedURLChanged", 77 InspectedURLChanged: "InspectedURLChanged",
77 SecurityOriginAdded: "SecurityOriginAdded",
78 SecurityOriginRemoved: "SecurityOriginRemoved",
79 ScreencastFrame: "ScreencastFrame", 78 ScreencastFrame: "ScreencastFrame",
80 ScreencastVisibilityChanged: "ScreencastVisibilityChanged", 79 ScreencastVisibilityChanged: "ScreencastVisibilityChanged",
81 ColorPicked: "ColorPicked" 80 ColorPicked: "ColorPicked"
82 } 81 }
83 82
83 /**
84 * @param {!WebInspector.Target} target
85 * @return {?WebInspector.ResourceTreeModel}
86 */
87 WebInspector.ResourceTreeModel.fromTarget = function(target)
88 {
89 return /** @type {?WebInspector.ResourceTreeModel} */ (target.model(WebInspe ctor.ResourceTreeModel));
90 }
84 91
85 /** 92 /**
86 * @return {!Array.<!WebInspector.ResourceTreeFrame>} 93 * @return {!Array.<!WebInspector.ResourceTreeFrame>}
87 */ 94 */
88 WebInspector.ResourceTreeModel.frames = function() 95 WebInspector.ResourceTreeModel.frames = function()
89 { 96 {
90 var result = []; 97 var result = [];
91 for (var target of WebInspector.targetManager.targets()) 98 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.DOM))
92 result = result.concat(target.resourceTreeModel._frames.valuesArray()); 99 result = result.concat(WebInspector.ResourceTreeModel.fromTarget(target) ._frames.valuesArray());
93 return result; 100 return result;
94 } 101 }
95 102
96 /** 103 /**
97 * @param {string} url 104 * @param {string} url
98 * @return {?WebInspector.Resource} 105 * @return {?WebInspector.Resource}
99 */ 106 */
100 WebInspector.ResourceTreeModel.resourceForURL = function(url) 107 WebInspector.ResourceTreeModel.resourceForURL = function(url)
101 { 108 {
102 for (var target of WebInspector.targetManager.targets()) { 109 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.DOM)) {
103 var mainFrame = target.resourceTreeModel.mainFrame; 110 var mainFrame = WebInspector.ResourceTreeModel.fromTarget(target).mainFr ame;
104 var result = mainFrame ? mainFrame.resourceForURL(url) : null; 111 var result = mainFrame ? mainFrame.resourceForURL(url) : null;
105 if (result) 112 if (result)
106 return result; 113 return result;
107 } 114 }
108 return null; 115 return null;
109 } 116 }
110 117
111 WebInspector.ResourceTreeModel.prototype = { 118 WebInspector.ResourceTreeModel.prototype = {
112 _fetchResourceTree: function() 119 _fetchResourceTree: function()
113 { 120 {
114 /** @type {!Map<string, !WebInspector.ResourceTreeFrame>} */ 121 /** @type {!Map<string, !WebInspector.ResourceTreeFrame>} */
115 this._frames = new Map(); 122 this._frames = new Map();
116 this._cachedResourcesProcessed = false; 123 this._cachedResourcesProcessed = false;
117 this._agent.getResourceTree(this._processCachedResources.bind(this)); 124 this._agent.getResourceTree(this._processCachedResources.bind(this));
118 }, 125 },
119 126
120 _processCachedResources: function(error, mainFramePayload) 127 _processCachedResources: function(error, mainFramePayload)
121 { 128 {
122 if (error) { 129 if (!error) {
123 this._cachedResourcesProcessed = true; 130 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.WillLoadCachedResources);
124 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.CachedResourcesLoaded); 131 this._inspectedPageURL = mainFramePayload.frame.url;
125 return; 132 this._addFramesRecursively(null, mainFramePayload);
133 this._dispatchInspectedURLChanged();
126 } 134 }
127
128 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. WillLoadCachedResources);
129 this._inspectedPageURL = mainFramePayload.frame.url;
130
131 // Do not process SW resources.
132 if (this.target().hasBrowserCapability())
133 this._addFramesRecursively(null, mainFramePayload);
134 else
135 this._addSecurityOrigin(mainFramePayload.frame.securityOrigin);
136
137 this._dispatchInspectedURLChanged();
138 this._cachedResourcesProcessed = true; 135 this._cachedResourcesProcessed = true;
139 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded); 136 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded);
140 }, 137 },
141 138
142 /** 139 /**
143 * @return {string} 140 * @return {string}
144 */ 141 */
145 inspectedPageURL: function() 142 inspectedPageURL: function()
146 { 143 {
147 return this._inspectedPageURL; 144 return this._inspectedPageURL;
(...skipping 22 matching lines...) Expand all
170 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. InspectedURLChanged, this._inspectedPageURL); 167 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. InspectedURLChanged, this._inspectedPageURL);
171 }, 168 },
172 169
173 /** 170 /**
174 * @param {!WebInspector.ResourceTreeFrame} frame 171 * @param {!WebInspector.ResourceTreeFrame} frame
175 * @param {boolean=} aboutToNavigate 172 * @param {boolean=} aboutToNavigate
176 */ 173 */
177 _addFrame: function(frame, aboutToNavigate) 174 _addFrame: function(frame, aboutToNavigate)
178 { 175 {
179 this._frames.set(frame.id, frame); 176 this._frames.set(frame.id, frame);
180 if (frame.isMainFrame()) 177 if (frame.isMainFrame()) {
181 this.mainFrame = frame; 178 this.mainFrame = frame;
179 this._securityOriginManager.setMainSecurityOrigin(frame.url);
180 }
182 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameAdded, frame); 181 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameAdded, frame);
183 if (!aboutToNavigate) 182 if (!aboutToNavigate)
184 this._addSecurityOrigin(frame.securityOrigin); 183 this._securityOriginManager.addSecurityOrigin(frame.securityOrigin);
185 }, 184 },
186 185
187 /** 186 /**
188 * @param {string} securityOrigin
189 */
190 _addSecurityOrigin: function(securityOrigin)
191 {
192 if (!this._securityOriginFrameCount[securityOrigin]) {
193 this._securityOriginFrameCount[securityOrigin] = 1;
194 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.SecurityOriginAdded, securityOrigin);
195 return;
196 }
197 this._securityOriginFrameCount[securityOrigin] += 1;
198 },
199
200 /**
201 * @param {string|undefined} securityOrigin
202 */
203 _removeSecurityOrigin: function(securityOrigin)
204 {
205 if (typeof securityOrigin === "undefined")
206 return;
207 if (this._securityOriginFrameCount[securityOrigin] === 1) {
208 delete this._securityOriginFrameCount[securityOrigin];
209 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.SecurityOriginRemoved, securityOrigin);
210 return;
211 }
212 this._securityOriginFrameCount[securityOrigin] -= 1;
213 },
214
215 /**
216 * @return {!Array.<string>}
217 */
218 securityOrigins: function()
219 {
220 return Object.keys(this._securityOriginFrameCount);
221 },
222
223 /**
224 * @param {!WebInspector.ResourceTreeFrame} mainFrame 187 * @param {!WebInspector.ResourceTreeFrame} mainFrame
225 */ 188 */
226 _handleMainFrameDetached: function(mainFrame) 189 _handleMainFrameDetached: function(mainFrame)
227 { 190 {
228 /** 191 /**
229 * @param {!WebInspector.ResourceTreeFrame} frame 192 * @param {!WebInspector.ResourceTreeFrame} frame
230 * @this {WebInspector.ResourceTreeModel} 193 * @this {WebInspector.ResourceTreeModel}
231 */ 194 */
232 function removeOriginForFrame(frame) 195 function removeOriginForFrame(frame)
233 { 196 {
234 for (var i = 0; i < frame.childFrames.length; ++i) 197 for (var i = 0; i < frame.childFrames.length; ++i)
235 removeOriginForFrame.call(this, frame.childFrames[i]); 198 removeOriginForFrame.call(this, frame.childFrames[i]);
236 if (!frame.isMainFrame()) 199 if (!frame.isMainFrame())
237 this._removeSecurityOrigin(frame.securityOrigin); 200 this._securityOriginManager.removeSecurityOrigin(frame.securityO rigin);
238 } 201 }
239 removeOriginForFrame.call(this, mainFrame); 202 removeOriginForFrame.call(this, mainFrame);
240 }, 203 },
241 204
242 /** 205 /**
243 * @param {!PageAgent.FrameId} frameId 206 * @param {!PageAgent.FrameId} frameId
244 * @param {?PageAgent.FrameId} parentFrameId 207 * @param {?PageAgent.FrameId} parentFrameId
245 * @return {?WebInspector.ResourceTreeFrame} 208 * @return {?WebInspector.ResourceTreeFrame}
246 */ 209 */
247 _frameAttached: function(frameId, parentFrameId) 210 _frameAttached: function(frameId, parentFrameId)
(...skipping 26 matching lines...) Expand all
274 var frame = this._frames.get(framePayload.id); 237 var frame = this._frames.get(framePayload.id);
275 if (!frame) { 238 if (!frame) {
276 // Simulate missed "frameAttached" for a main frame navigation to th e new backend process. 239 // Simulate missed "frameAttached" for a main frame navigation to th e new backend process.
277 console.assert(!framePayload.parentId, "Main frame shouldn't have pa rent frame id."); 240 console.assert(!framePayload.parentId, "Main frame shouldn't have pa rent frame id.");
278 frame = this._frameAttached(framePayload.id, framePayload.parentId | | ""); 241 frame = this._frameAttached(framePayload.id, framePayload.parentId | | "");
279 console.assert(frame); 242 console.assert(frame);
280 } 243 }
281 244
282 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame); 245 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame);
283 246
284 this._removeSecurityOrigin(frame.securityOrigin); 247 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin);
285 frame._navigate(framePayload); 248 frame._navigate(framePayload);
286 var addedOrigin = frame.securityOrigin; 249 var addedOrigin = frame.securityOrigin;
287 250
288 if (frame.isMainFrame()) 251 if (frame.isMainFrame())
289 this._inspectedPageURL = frame.url; 252 this._inspectedPageURL = frame.url;
290 253
291 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameNavigated, frame); 254 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameNavigated, frame);
292 if (frame.isMainFrame()) { 255 if (frame.isMainFrame()) {
293 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.MainFrameNavigated, frame); 256 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.MainFrameNavigated, frame);
294 if (WebInspector.moduleSetting("preserveConsoleLog").get()) 257 if (WebInspector.moduleSetting("preserveConsoleLog").get())
295 WebInspector.console.log(WebInspector.UIString("Navigated to %s" , frame.url)); 258 WebInspector.console.log(WebInspector.UIString("Navigated to %s" , frame.url));
296 else 259 else
297 this.target().consoleModel.clear(); 260 this.target().consoleModel.clear();
298 } 261 }
299 if (addedOrigin) 262 if (addedOrigin)
300 this._addSecurityOrigin(addedOrigin); 263 this._securityOriginManager.addSecurityOrigin(addedOrigin);
301 264
302 // Fill frame with retained resources (the ones loaded using new loader) . 265 // Fill frame with retained resources (the ones loaded using new loader) .
303 var resources = frame.resources(); 266 var resources = frame.resources();
304 for (var i = 0; i < resources.length; ++i) 267 for (var i = 0; i < resources.length; ++i)
305 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.ResourceAdded, resources[i]); 268 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.ResourceAdded, resources[i]);
306 269
307 if (frame.isMainFrame()) 270 if (frame.isMainFrame())
308 this._dispatchInspectedURLChanged(); 271 this._dispatchInspectedURLChanged();
309 }, 272 },
310 273
311 /** 274 /**
312 * @param {!PageAgent.FrameId} frameId 275 * @param {!PageAgent.FrameId} frameId
313 */ 276 */
314 _frameDetached: function(frameId) 277 _frameDetached: function(frameId)
315 { 278 {
316 // Do nothing unless cached resource tree is processed - it will overwri te everything. 279 // Do nothing unless cached resource tree is processed - it will overwri te everything.
317 if (!this._cachedResourcesProcessed) 280 if (!this._cachedResourcesProcessed)
318 return; 281 return;
319 282
320 var frame = this._frames.get(frameId); 283 var frame = this._frames.get(frameId);
321 if (!frame) 284 if (!frame)
322 return; 285 return;
323 286
324 this._removeSecurityOrigin(frame.securityOrigin); 287 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin);
325 if (frame.parentFrame) 288 if (frame.parentFrame)
326 frame.parentFrame._removeChildFrame(frame); 289 frame.parentFrame._removeChildFrame(frame);
327 else 290 else
328 frame._remove(); 291 frame._remove();
329 }, 292 },
330 293
331 /** 294 /**
332 * @param {!WebInspector.Event} event 295 * @param {!WebInspector.Event} event
333 */ 296 */
334 _onRequestFinished: function(event) 297 _onRequestFinished: function(event)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 /** 533 /**
571 * @type {!Object.<string, !WebInspector.Resource>} 534 * @type {!Object.<string, !WebInspector.Resource>}
572 */ 535 */
573 this._resourcesMap = {}; 536 this._resourcesMap = {};
574 537
575 if (this._parentFrame) 538 if (this._parentFrame)
576 this._parentFrame._childFrames.push(this); 539 this._parentFrame._childFrames.push(this);
577 } 540 }
578 541
579 /** 542 /**
543 * @param {!WebInspector.ExecutionContext|!WebInspector.CSSStyleSheetHeader|!Web Inspector.Resource} object
544 * @return {?WebInspector.ResourceTreeFrame}
545 */
546 WebInspector.ResourceTreeFrame._fromObject = function(object)
547 {
548 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(object.tar get());
549 var frameId = object.frameId;
550 if (!resourceTreeModel || !frameId)
551 return null;
552 return resourceTreeModel.frameForId(frameId);
553 }
554
555 /**
580 * @param {!WebInspector.Script} script 556 * @param {!WebInspector.Script} script
581 * @return {?WebInspector.ResourceTreeFrame} 557 * @return {?WebInspector.ResourceTreeFrame}
582 */ 558 */
583 WebInspector.ResourceTreeFrame.fromScript = function(script) 559 WebInspector.ResourceTreeFrame.fromScript = function(script)
584 { 560 {
585 var executionContext = script.executionContext(); 561 var executionContext = script.executionContext();
586 if (!executionContext || !executionContext.frameId) 562 if (!executionContext)
587 return null; 563 return null;
588 return script.target().resourceTreeModel.frameForId(executionContext.frameId ); 564 return WebInspector.ResourceTreeFrame._fromObject(executionContext);
589 } 565 }
590 566
591 /** 567 /**
592 * @param {!WebInspector.CSSStyleSheetHeader} header 568 * @param {!WebInspector.CSSStyleSheetHeader} header
593 * @return {?WebInspector.ResourceTreeFrame} 569 * @return {?WebInspector.ResourceTreeFrame}
594 */ 570 */
595 WebInspector.ResourceTreeFrame.fromStyleSheet = function(header) 571 WebInspector.ResourceTreeFrame.fromStyleSheet = function(header)
596 { 572 {
597 return header.target().resourceTreeModel.frameForId(header.frameId); 573 return WebInspector.ResourceTreeFrame._fromObject(header);
598 } 574 }
599 575
600 /** 576 /**
601 * @param {!WebInspector.Resource} resource 577 * @param {!WebInspector.Resource} resource
602 * @return {?WebInspector.ResourceTreeFrame} 578 * @return {?WebInspector.ResourceTreeFrame}
603 */ 579 */
604 WebInspector.ResourceTreeFrame.fromResource = function(resource) 580 WebInspector.ResourceTreeFrame.fromResource = function(resource)
605 { 581 {
606 return resource.target().resourceTreeModel.frameForId(resource.frameId); 582 return WebInspector.ResourceTreeFrame._fromObject(resource);
607 } 583 }
608 584
609 WebInspector.ResourceTreeFrame.prototype = { 585 WebInspector.ResourceTreeFrame.prototype = {
610 /** 586 /**
611 * @return {!WebInspector.Target} 587 * @return {!WebInspector.Target}
612 */ 588 */
613 target: function() 589 target: function()
614 { 590 {
615 return this._model.target(); 591 return this._model.target();
616 }, 592 },
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 961
986 /** 962 /**
987 * @override 963 * @override
988 */ 964 */
989 navigationRequested: function() 965 navigationRequested: function()
990 { 966 {
991 // Frontend is not interested in interstitials. 967 // Frontend is not interested in interstitials.
992 } 968 }
993 969
994 } 970 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698