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

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: Extracted security origins from the ResourceTreeModel Created 4 years, 5 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()) {
92 result = result.concat(target.resourceTreeModel._frames.valuesArray()); 99 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target );
100 if (resourceTreeModel)
dgozman 2016/07/22 03:27:02 Use DOM capability instead.
eostroukhov-old 2016/07/22 23:27:43 Done.
101 result = result.concat(resourceTreeModel._frames.valuesArray());
102 }
93 return result; 103 return result;
94 } 104 }
95 105
96 /** 106 /**
97 * @param {string} url 107 * @param {string} url
98 * @return {?WebInspector.Resource} 108 * @return {?WebInspector.Resource}
99 */ 109 */
100 WebInspector.ResourceTreeModel.resourceForURL = function(url) 110 WebInspector.ResourceTreeModel.resourceForURL = function(url)
101 { 111 {
102 for (var target of WebInspector.targetManager.targets()) { 112 for (var target of WebInspector.targetManager.targets()) {
103 var mainFrame = target.resourceTreeModel.mainFrame; 113 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target );
114 var mainFrame = resourceTreeModel && resourceTreeModel.mainFrame;
dgozman 2016/07/22 03:27:03 ditto
eostroukhov-old 2016/07/22 23:27:43 Done.
104 var result = mainFrame ? mainFrame.resourceForURL(url) : null; 115 var result = mainFrame ? mainFrame.resourceForURL(url) : null;
105 if (result) 116 if (result)
106 return result; 117 return result;
107 } 118 }
108 return null; 119 return null;
109 } 120 }
110 121
111 WebInspector.ResourceTreeModel.prototype = { 122 WebInspector.ResourceTreeModel.prototype = {
112 _fetchResourceTree: function() 123 _fetchResourceTree: function()
113 { 124 {
114 /** @type {!Map<string, !WebInspector.ResourceTreeFrame>} */ 125 /** @type {!Map<string, !WebInspector.ResourceTreeFrame>} */
115 this._frames = new Map(); 126 this._frames = new Map();
116 this._cachedResourcesProcessed = false; 127 this._cachedResourcesProcessed = false;
117 this._agent.getResourceTree(this._processCachedResources.bind(this)); 128 this._agent.getResourceTree(this._processCachedResources.bind(this));
118 }, 129 },
119 130
120 _processCachedResources: function(error, mainFramePayload) 131 _processCachedResources: function(error, mainFramePayload)
121 { 132 {
122 if (error) { 133 if (!error) {
123 this._cachedResourcesProcessed = true; 134 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.WillLoadCachedResources);
124 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.CachedResourcesLoaded); 135 this._inspectedPageURL = mainFramePayload.frame.url;
125 return; 136 this._addFramesRecursively(null, mainFramePayload);
137 this._dispatchInspectedURLChanged();
126 } 138 }
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; 139 this._cachedResourcesProcessed = true;
139 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded); 140 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded);
140 }, 141 },
141 142
142 /** 143 /**
143 * @return {string} 144 * @return {string}
144 */ 145 */
145 inspectedPageURL: function() 146 inspectedPageURL: function()
146 { 147 {
147 return this._inspectedPageURL; 148 return this._inspectedPageURL;
(...skipping 26 matching lines...) Expand all
174 * @param {!WebInspector.ResourceTreeFrame} frame 175 * @param {!WebInspector.ResourceTreeFrame} frame
175 * @param {boolean=} aboutToNavigate 176 * @param {boolean=} aboutToNavigate
176 */ 177 */
177 _addFrame: function(frame, aboutToNavigate) 178 _addFrame: function(frame, aboutToNavigate)
178 { 179 {
179 this._frames.set(frame.id, frame); 180 this._frames.set(frame.id, frame);
180 if (frame.isMainFrame()) 181 if (frame.isMainFrame())
181 this.mainFrame = frame; 182 this.mainFrame = frame;
182 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameAdded, frame); 183 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameAdded, frame);
183 if (!aboutToNavigate) 184 if (!aboutToNavigate)
184 this._addSecurityOrigin(frame.securityOrigin); 185 this._securityOriginManager.addSecurityOrigin(frame.securityOrigin);
185 }, 186 },
186 187
187 /** 188 /**
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 189 * @param {!WebInspector.ResourceTreeFrame} mainFrame
225 */ 190 */
226 _handleMainFrameDetached: function(mainFrame) 191 _handleMainFrameDetached: function(mainFrame)
227 { 192 {
228 /** 193 /**
229 * @param {!WebInspector.ResourceTreeFrame} frame 194 * @param {!WebInspector.ResourceTreeFrame} frame
230 * @this {WebInspector.ResourceTreeModel} 195 * @this {WebInspector.ResourceTreeModel}
231 */ 196 */
232 function removeOriginForFrame(frame) 197 function removeOriginForFrame(frame)
233 { 198 {
234 for (var i = 0; i < frame.childFrames.length; ++i) 199 for (var i = 0; i < frame.childFrames.length; ++i)
235 removeOriginForFrame.call(this, frame.childFrames[i]); 200 removeOriginForFrame.call(this, frame.childFrames[i]);
236 if (!frame.isMainFrame()) 201 if (!frame.isMainFrame())
237 this._removeSecurityOrigin(frame.securityOrigin); 202 this._securityOriginManager.removeSecurityOrigin(frame.securityO rigin);
238 } 203 }
239 removeOriginForFrame.call(this, mainFrame); 204 removeOriginForFrame.call(this, mainFrame);
240 }, 205 },
241 206
242 /** 207 /**
243 * @param {!PageAgent.FrameId} frameId 208 * @param {!PageAgent.FrameId} frameId
244 * @param {?PageAgent.FrameId} parentFrameId 209 * @param {?PageAgent.FrameId} parentFrameId
245 * @return {?WebInspector.ResourceTreeFrame} 210 * @return {?WebInspector.ResourceTreeFrame}
246 */ 211 */
247 _frameAttached: function(frameId, parentFrameId) 212 _frameAttached: function(frameId, parentFrameId)
(...skipping 26 matching lines...) Expand all
274 var frame = this._frames.get(framePayload.id); 239 var frame = this._frames.get(framePayload.id);
275 if (!frame) { 240 if (!frame) {
276 // Simulate missed "frameAttached" for a main frame navigation to th e new backend process. 241 // 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."); 242 console.assert(!framePayload.parentId, "Main frame shouldn't have pa rent frame id.");
278 frame = this._frameAttached(framePayload.id, framePayload.parentId | | ""); 243 frame = this._frameAttached(framePayload.id, framePayload.parentId | | "");
279 console.assert(frame); 244 console.assert(frame);
280 } 245 }
281 246
282 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame); 247 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame);
283 248
284 this._removeSecurityOrigin(frame.securityOrigin); 249 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin);
285 frame._navigate(framePayload); 250 frame._navigate(framePayload);
286 var addedOrigin = frame.securityOrigin; 251 var addedOrigin = frame.securityOrigin;
287 252
288 if (frame.isMainFrame()) 253 if (frame.isMainFrame())
289 this._inspectedPageURL = frame.url; 254 this._inspectedPageURL = frame.url;
290 255
291 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameNavigated, frame); 256 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameNavigated, frame);
292 if (frame.isMainFrame()) { 257 if (frame.isMainFrame()) {
293 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.MainFrameNavigated, frame); 258 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.MainFrameNavigated, frame);
294 if (WebInspector.moduleSetting("preserveConsoleLog").get()) 259 if (WebInspector.moduleSetting("preserveConsoleLog").get())
295 WebInspector.console.log(WebInspector.UIString("Navigated to %s" , frame.url)); 260 WebInspector.console.log(WebInspector.UIString("Navigated to %s" , frame.url));
296 else 261 else
297 this.target().consoleModel.clear(); 262 this.target().consoleModel.clear();
298 } 263 }
299 if (addedOrigin) 264 if (addedOrigin)
300 this._addSecurityOrigin(addedOrigin); 265 this._securityOriginManager.addSecurityOrigin(addedOrigin);
301 266
302 // Fill frame with retained resources (the ones loaded using new loader) . 267 // Fill frame with retained resources (the ones loaded using new loader) .
303 var resources = frame.resources(); 268 var resources = frame.resources();
304 for (var i = 0; i < resources.length; ++i) 269 for (var i = 0; i < resources.length; ++i)
305 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.ResourceAdded, resources[i]); 270 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.ResourceAdded, resources[i]);
306 271
307 if (frame.isMainFrame()) 272 if (frame.isMainFrame())
308 this._dispatchInspectedURLChanged(); 273 this._dispatchInspectedURLChanged();
309 }, 274 },
310 275
311 /** 276 /**
312 * @param {!PageAgent.FrameId} frameId 277 * @param {!PageAgent.FrameId} frameId
313 */ 278 */
314 _frameDetached: function(frameId) 279 _frameDetached: function(frameId)
315 { 280 {
316 // Do nothing unless cached resource tree is processed - it will overwri te everything. 281 // Do nothing unless cached resource tree is processed - it will overwri te everything.
317 if (!this._cachedResourcesProcessed) 282 if (!this._cachedResourcesProcessed)
318 return; 283 return;
319 284
320 var frame = this._frames.get(frameId); 285 var frame = this._frames.get(frameId);
321 if (!frame) 286 if (!frame)
322 return; 287 return;
323 288
324 this._removeSecurityOrigin(frame.securityOrigin); 289 this._securityOriginManager.removeSecurityOrigin(frame.securityOrigin);
325 if (frame.parentFrame) 290 if (frame.parentFrame)
326 frame.parentFrame._removeChildFrame(frame); 291 frame.parentFrame._removeChildFrame(frame);
327 else 292 else
328 frame._remove(); 293 frame._remove();
329 }, 294 },
330 295
331 /** 296 /**
332 * @param {!WebInspector.Event} event 297 * @param {!WebInspector.Event} event
333 */ 298 */
334 _onRequestFinished: function(event) 299 _onRequestFinished: function(event)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 /** 535 /**
571 * @type {!Object.<string, !WebInspector.Resource>} 536 * @type {!Object.<string, !WebInspector.Resource>}
572 */ 537 */
573 this._resourcesMap = {}; 538 this._resourcesMap = {};
574 539
575 if (this._parentFrame) 540 if (this._parentFrame)
576 this._parentFrame._childFrames.push(this); 541 this._parentFrame._childFrames.push(this);
577 } 542 }
578 543
579 /** 544 /**
545 * @param {!WebInspector.ExecutionContext|!WebInspector.CSSStyleSheetHeader|!Web Inspector.Resource} object
546 * @return {?WebInspector.ResourceTreeFrame}
547 */
548 WebInspector.ResourceTreeFrame._fromObject = function(object)
549 {
550 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(object.tar get());
551 var frameId = object.frameId;
552 if (!resourceTreeModel || !frameId)
553 return null;
554 return resourceTreeModel.frameForId(frameId);
555 }
556
557 /**
580 * @param {!WebInspector.Script} script 558 * @param {!WebInspector.Script} script
581 * @return {?WebInspector.ResourceTreeFrame} 559 * @return {?WebInspector.ResourceTreeFrame}
582 */ 560 */
583 WebInspector.ResourceTreeFrame.fromScript = function(script) 561 WebInspector.ResourceTreeFrame.fromScript = function(script)
584 { 562 {
585 var executionContext = script.executionContext(); 563 var executionContext = script.executionContext();
586 if (!executionContext || !executionContext.frameId) 564 if (!executionContext)
587 return null; 565 return null;
588 return script.target().resourceTreeModel.frameForId(executionContext.frameId ); 566 return WebInspector.ResourceTreeFrame._fromObject(executionContext);
589 } 567 }
590 568
591 /** 569 /**
592 * @param {!WebInspector.CSSStyleSheetHeader} header 570 * @param {!WebInspector.CSSStyleSheetHeader} header
593 * @return {?WebInspector.ResourceTreeFrame} 571 * @return {?WebInspector.ResourceTreeFrame}
594 */ 572 */
595 WebInspector.ResourceTreeFrame.fromStyleSheet = function(header) 573 WebInspector.ResourceTreeFrame.fromStyleSheet = function(header)
596 { 574 {
597 return header.target().resourceTreeModel.frameForId(header.frameId); 575 return WebInspector.ResourceTreeFrame._fromObject(header);
598 } 576 }
599 577
600 /** 578 /**
601 * @param {!WebInspector.Resource} resource 579 * @param {!WebInspector.Resource} resource
602 * @return {?WebInspector.ResourceTreeFrame} 580 * @return {?WebInspector.ResourceTreeFrame}
603 */ 581 */
604 WebInspector.ResourceTreeFrame.fromResource = function(resource) 582 WebInspector.ResourceTreeFrame.fromResource = function(resource)
605 { 583 {
606 return resource.target().resourceTreeModel.frameForId(resource.frameId); 584 return WebInspector.ResourceTreeFrame._fromObject(resource);
607 } 585 }
608 586
609 WebInspector.ResourceTreeFrame.prototype = { 587 WebInspector.ResourceTreeFrame.prototype = {
610 /** 588 /**
611 * @return {!WebInspector.Target} 589 * @return {!WebInspector.Target}
612 */ 590 */
613 target: function() 591 target: function()
614 { 592 {
615 return this._model.target(); 593 return this._model.target();
616 }, 594 },
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 963
986 /** 964 /**
987 * @override 965 * @override
988 */ 966 */
989 navigationRequested: function() 967 navigationRequested: function()
990 { 968 {
991 // Frontend is not interested in interstitials. 969 // Frontend is not interested in interstitials.
992 } 970 }
993 971
994 } 972 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698