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

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

Issue 2122353002: [DevTools] Make resource tree model optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 PageReloadRequested: "PageReloadRequested", 74 PageReloadRequested: "PageReloadRequested",
75 WillReloadPage: "WillReloadPage", 75 WillReloadPage: "WillReloadPage",
76 InspectedURLChanged: "InspectedURLChanged", 76 InspectedURLChanged: "InspectedURLChanged",
77 SecurityOriginAdded: "SecurityOriginAdded", 77 SecurityOriginAdded: "SecurityOriginAdded",
78 SecurityOriginRemoved: "SecurityOriginRemoved", 78 SecurityOriginRemoved: "SecurityOriginRemoved",
79 ScreencastFrame: "ScreencastFrame", 79 ScreencastFrame: "ScreencastFrame",
80 ScreencastVisibilityChanged: "ScreencastVisibilityChanged", 80 ScreencastVisibilityChanged: "ScreencastVisibilityChanged",
81 ColorPicked: "ColorPicked" 81 ColorPicked: "ColorPicked"
82 } 82 }
83 83
84 /**
85 * @param {!WebInspector.Target} target
86 * @return {?WebInspector.ResourceTreeModel}
87 */
88 WebInspector.ResourceTreeModel.fromTarget = function(target) {
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(Object.values(target.resourceTreeModel._frames)); 99 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target );
100 if (resourceTreeModel)
101 result = result.concat(Object.values(resourceTreeModel._frames));
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;
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 {!Object.<string, !WebInspector.ResourceTreeFrame>} */ 125 /** @type {!Object.<string, !WebInspector.ResourceTreeFrame>} */
115 this._frames = {}; 126 this._frames = {};
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) {
dgozman 2016/07/14 16:30:28 This check can be removed with your change.
eostroukhov-old 2016/07/20 23:46:15 (Looks like this comment is a duplicate of the com
123 this._cachedResourcesProcessed = true; 134 this._cachedResourcesProcessed = true;
124 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.CachedResourcesLoaded); 135 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.CachedResourcesLoaded);
125 return; 136 return;
126 } 137 }
127 138
128 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. WillLoadCachedResources); 139 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. WillLoadCachedResources);
129 this._inspectedPageURL = mainFramePayload.frame.url; 140 this._inspectedPageURL = mainFramePayload.frame.url;
130 141
131 // Do not process SW resources. 142 // Do not process SW resources.
132 if (this.target().hasBrowserCapability()) 143 if (this.target().hasBrowserCapability())
dgozman 2016/07/14 16:30:28 This check can be removed with your change.
eostroukhov-old 2016/07/20 23:46:16 Done.
133 this._addFramesRecursively(null, mainFramePayload); 144 this._addFramesRecursively(null, mainFramePayload);
134 else 145 else
135 this._addSecurityOrigin(mainFramePayload.frame.securityOrigin); 146 this._addSecurityOrigin(mainFramePayload.frame.securityOrigin);
136 147
137 this._dispatchInspectedURLChanged(); 148 this._dispatchInspectedURLChanged();
138 this._cachedResourcesProcessed = true; 149 this._cachedResourcesProcessed = true;
139 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded); 150 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. CachedResourcesLoaded);
140 }, 151 },
141 152
142 /** 153 /**
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 575
565 /** 576 /**
566 * @type {!Object.<string, !WebInspector.Resource>} 577 * @type {!Object.<string, !WebInspector.Resource>}
567 */ 578 */
568 this._resourcesMap = {}; 579 this._resourcesMap = {};
569 580
570 if (this._parentFrame) 581 if (this._parentFrame)
571 this._parentFrame._childFrames.push(this); 582 this._parentFrame._childFrames.push(this);
572 } 583 }
573 584
585
586 /**
587 * @param {!WebInspector.ExecutionContext|!WebInspector.CSSStyleSheetHeader|!Web Inspector.Resource} object
588 * @return {?WebInspector.ResourceTreeFrame}
589 */
590 WebInspector.ResourceTreeFrame._fromObject = function(object)
591 {
592 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(object.tar get());
593 var frameId = object.frameId;
594 if (!resourceTreeModel || !frameId)
595 return null;
596 return resourceTreeModel.frameForId(frameId);
597 }
598
574 /** 599 /**
575 * @param {!WebInspector.Script} script 600 * @param {!WebInspector.Script} script
576 * @return {?WebInspector.ResourceTreeFrame} 601 * @return {?WebInspector.ResourceTreeFrame}
577 */ 602 */
578 WebInspector.ResourceTreeFrame.fromScript = function(script) 603 WebInspector.ResourceTreeFrame.fromScript = function(script)
579 { 604 {
580 var executionContext = script.executionContext(); 605 var executionContext = script.executionContext();
581 if (!executionContext || !executionContext.frameId) 606 if (!executionContext)
582 return null; 607 return null;
583 return script.target().resourceTreeModel.frameForId(executionContext.frameId ); 608 return WebInspector.ResourceTreeFrame._fromObject(executionContext);
584 } 609 }
585 610
586 /** 611 /**
587 * @param {!WebInspector.CSSStyleSheetHeader} header 612 * @param {!WebInspector.CSSStyleSheetHeader} header
588 * @return {?WebInspector.ResourceTreeFrame} 613 * @return {?WebInspector.ResourceTreeFrame}
589 */ 614 */
590 WebInspector.ResourceTreeFrame.fromStyleSheet = function(header) 615 WebInspector.ResourceTreeFrame.fromStyleSheet = function(header)
591 { 616 {
592 return header.target().resourceTreeModel.frameForId(header.frameId); 617 return WebInspector.ResourceTreeFrame._fromObject(header);
593 } 618 }
594 619
595 /** 620 /**
596 * @param {!WebInspector.Resource} resource 621 * @param {!WebInspector.Resource} resource
597 * @return {?WebInspector.ResourceTreeFrame} 622 * @return {?WebInspector.ResourceTreeFrame}
598 */ 623 */
599 WebInspector.ResourceTreeFrame.fromResource = function(resource) 624 WebInspector.ResourceTreeFrame.fromResource = function(resource)
600 { 625 {
601 return resource.target().resourceTreeModel.frameForId(resource.frameId); 626 return WebInspector.ResourceTreeFrame._fromObject(resource);
602 } 627 }
603 628
604 WebInspector.ResourceTreeFrame.prototype = { 629 WebInspector.ResourceTreeFrame.prototype = {
605 /** 630 /**
606 * @return {!WebInspector.Target} 631 * @return {!WebInspector.Target}
607 */ 632 */
608 target: function() 633 target: function()
609 { 634 {
610 return this._model.target(); 635 return this._model.target();
611 }, 636 },
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 }, 996 },
972 997
973 /** 998 /**
974 * @override 999 * @override
975 */ 1000 */
976 interstitialHidden: function() 1001 interstitialHidden: function()
977 { 1002 {
978 // Frontend is not interested in interstitials. 1003 // Frontend is not interested in interstitials.
979 } 1004 }
980 } 1005 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698