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

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

Issue 2163093003: [DevTools] Remove Object.values and Object.isEmpty from utilities.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 84
85 /** 85 /**
86 * @return {!Array.<!WebInspector.ResourceTreeFrame>} 86 * @return {!Array.<!WebInspector.ResourceTreeFrame>}
87 */ 87 */
88 WebInspector.ResourceTreeModel.frames = function() 88 WebInspector.ResourceTreeModel.frames = function()
89 { 89 {
90 var result = []; 90 var result = [];
91 for (var target of WebInspector.targetManager.targets()) 91 for (var target of WebInspector.targetManager.targets())
92 result = result.concat(Object.values(target.resourceTreeModel._frames)); 92 result = result.concat(Array.from(target.resourceTreeModel._frames.value s()));
lushnikov 2016/07/20 03:02:50 .valuesArray()
kozy 2016/07/20 17:55:18 Done.
93 return result; 93 return result;
94 } 94 }
95 95
96 /** 96 /**
97 * @param {string} url 97 * @param {string} url
98 * @return {?WebInspector.Resource} 98 * @return {?WebInspector.Resource}
99 */ 99 */
100 WebInspector.ResourceTreeModel.resourceForURL = function(url) 100 WebInspector.ResourceTreeModel.resourceForURL = function(url)
101 { 101 {
102 for (var target of WebInspector.targetManager.targets()) { 102 for (var target of WebInspector.targetManager.targets()) {
103 var mainFrame = target.resourceTreeModel.mainFrame; 103 var mainFrame = target.resourceTreeModel.mainFrame;
104 var result = mainFrame ? mainFrame.resourceForURL(url) : null; 104 var result = mainFrame ? mainFrame.resourceForURL(url) : null;
105 if (result) 105 if (result)
106 return result; 106 return result;
107 } 107 }
108 return null; 108 return null;
109 } 109 }
110 110
111 WebInspector.ResourceTreeModel.prototype = { 111 WebInspector.ResourceTreeModel.prototype = {
112 _fetchResourceTree: function() 112 _fetchResourceTree: function()
113 { 113 {
114 /** @type {!Object.<string, !WebInspector.ResourceTreeFrame>} */ 114 /** @type {!Map<string, !WebInspector.ResourceTreeFrame>} */
115 this._frames = {}; 115 this._frames = new Map();
116 this._cachedResourcesProcessed = false; 116 this._cachedResourcesProcessed = false;
117 this._agent.getResourceTree(this._processCachedResources.bind(this)); 117 this._agent.getResourceTree(this._processCachedResources.bind(this));
118 }, 118 },
119 119
120 _processCachedResources: function(error, mainFramePayload) 120 _processCachedResources: function(error, mainFramePayload)
121 { 121 {
122 if (error) { 122 if (error) {
123 this._cachedResourcesProcessed = true; 123 this._cachedResourcesProcessed = true;
124 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.CachedResourcesLoaded); 124 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTy pes.CachedResourcesLoaded);
125 return; 125 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 InspectorFrontendHost.inspectedURLChanged(this._inspectedPageURL); 169 InspectorFrontendHost.inspectedURLChanged(this._inspectedPageURL);
170 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. InspectedURLChanged, this._inspectedPageURL); 170 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. InspectedURLChanged, this._inspectedPageURL);
171 }, 171 },
172 172
173 /** 173 /**
174 * @param {!WebInspector.ResourceTreeFrame} frame 174 * @param {!WebInspector.ResourceTreeFrame} frame
175 * @param {boolean=} aboutToNavigate 175 * @param {boolean=} aboutToNavigate
176 */ 176 */
177 _addFrame: function(frame, aboutToNavigate) 177 _addFrame: function(frame, aboutToNavigate)
178 { 178 {
179 this._frames[frame.id] = frame; 179 this._frames.set(frame.id, frame);
180 if (frame.isMainFrame()) 180 if (frame.isMainFrame())
181 this.mainFrame = frame; 181 this.mainFrame = frame;
182 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameAdded, frame); 182 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameAdded, frame);
183 if (!aboutToNavigate) 183 if (!aboutToNavigate)
184 this._addSecurityOrigin(frame.securityOrigin); 184 this._addSecurityOrigin(frame.securityOrigin);
185 }, 185 },
186 186
187 /** 187 /**
188 * @param {string} securityOrigin 188 * @param {string} securityOrigin
189 */ 189 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 /** 242 /**
243 * @param {!PageAgent.FrameId} frameId 243 * @param {!PageAgent.FrameId} frameId
244 * @param {?PageAgent.FrameId} parentFrameId 244 * @param {?PageAgent.FrameId} parentFrameId
245 * @return {?WebInspector.ResourceTreeFrame} 245 * @return {?WebInspector.ResourceTreeFrame}
246 */ 246 */
247 _frameAttached: function(frameId, parentFrameId) 247 _frameAttached: function(frameId, parentFrameId)
248 { 248 {
249 // Do nothing unless cached resource tree is processed - it will overwri te everything. 249 // Do nothing unless cached resource tree is processed - it will overwri te everything.
250 if (!this._cachedResourcesProcessed && parentFrameId) 250 if (!this._cachedResourcesProcessed && parentFrameId)
251 return null; 251 return null;
252 if (this._frames[frameId]) 252 if (this._frames.has(frameId))
253 return null; 253 return null;
254 254
255 var parentFrame = parentFrameId ? this._frames[parentFrameId] : null; 255 var parentFrame = parentFrameId ? (this._frames.get(parentFrameId) || nu ll) : null;
lushnikov 2016/07/20 03:02:50 probably this could be written as var parentFrame
kozy 2016/07/20 17:55:18 .get method for Map<string, *> can be called only
256 var frame = new WebInspector.ResourceTreeFrame(this, parentFrame, frameI d); 256 var frame = new WebInspector.ResourceTreeFrame(this, parentFrame, frameI d);
257 if (frame.isMainFrame() && this.mainFrame) { 257 if (frame.isMainFrame() && this.mainFrame) {
258 this._handleMainFrameDetached(this.mainFrame); 258 this._handleMainFrameDetached(this.mainFrame);
259 // Navigation to the new backend process. 259 // Navigation to the new backend process.
260 this._frameDetached(this.mainFrame.id); 260 this._frameDetached(this.mainFrame.id);
261 } 261 }
262 this._addFrame(frame, true); 262 this._addFrame(frame, true);
263 return frame; 263 return frame;
264 }, 264 },
265 265
266 /** 266 /**
267 * @param {!PageAgent.Frame} framePayload 267 * @param {!PageAgent.Frame} framePayload
268 */ 268 */
269 _frameNavigated: function(framePayload) 269 _frameNavigated: function(framePayload)
270 { 270 {
271 // Do nothing unless cached resource tree is processed - it will overwri te everything. 271 // Do nothing unless cached resource tree is processed - it will overwri te everything.
272 if (!this._cachedResourcesProcessed && framePayload.parentId) 272 if (!this._cachedResourcesProcessed && framePayload.parentId)
273 return; 273 return;
274 var frame = this._frames[framePayload.id]; 274 var frame = this._frames.get(framePayload.id);
275 if (!frame) { 275 if (!frame) {
276 // Simulate missed "frameAttached" for a main frame navigation to th e new backend process. 276 // 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."); 277 console.assert(!framePayload.parentId, "Main frame shouldn't have pa rent frame id.");
278 frame = this._frameAttached(framePayload.id, framePayload.parentId | | ""); 278 frame = this._frameAttached(framePayload.id, framePayload.parentId | | "");
279 console.assert(frame); 279 console.assert(frame);
280 } 280 }
281 281
282 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame); 282 this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes. FrameWillNavigate, frame);
283 283
284 this._removeSecurityOrigin(frame.securityOrigin); 284 this._removeSecurityOrigin(frame.securityOrigin);
(...skipping 25 matching lines...) Expand all
310 310
311 /** 311 /**
312 * @param {!PageAgent.FrameId} frameId 312 * @param {!PageAgent.FrameId} frameId
313 */ 313 */
314 _frameDetached: function(frameId) 314 _frameDetached: function(frameId)
315 { 315 {
316 // Do nothing unless cached resource tree is processed - it will overwri te everything. 316 // Do nothing unless cached resource tree is processed - it will overwri te everything.
317 if (!this._cachedResourcesProcessed) 317 if (!this._cachedResourcesProcessed)
318 return; 318 return;
319 319
320 var frame = this._frames[frameId]; 320 var frame = this._frames.get(frameId);
321 if (!frame) 321 if (!frame)
322 return; 322 return;
323 323
324 this._removeSecurityOrigin(frame.securityOrigin); 324 this._removeSecurityOrigin(frame.securityOrigin);
325 if (frame.parentFrame) 325 if (frame.parentFrame)
326 frame.parentFrame._removeChildFrame(frame); 326 frame.parentFrame._removeChildFrame(frame);
327 else 327 else
328 frame._remove(); 328 frame._remove();
329 }, 329 },
330 330
331 /** 331 /**
332 * @param {!WebInspector.Event} event 332 * @param {!WebInspector.Event} event
333 */ 333 */
334 _onRequestFinished: function(event) 334 _onRequestFinished: function(event)
335 { 335 {
336 if (!this._cachedResourcesProcessed) 336 if (!this._cachedResourcesProcessed)
337 return; 337 return;
338 338
339 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); 339 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data);
340 if (request.failed || request.resourceType() === WebInspector.resourceTy pes.XHR) 340 if (request.failed || request.resourceType() === WebInspector.resourceTy pes.XHR)
341 return; 341 return;
342 342
343 var frame = this._frames[request.frameId]; 343 var frame = this._frames.get(request.frameId);
344 if (frame) 344 if (frame)
345 frame._addRequest(request); 345 frame._addRequest(request);
346 }, 346 },
347 347
348 /** 348 /**
349 * @param {!WebInspector.Event} event 349 * @param {!WebInspector.Event} event
350 */ 350 */
351 _onRequestUpdateDropped: function(event) 351 _onRequestUpdateDropped: function(event)
352 { 352 {
353 if (!this._cachedResourcesProcessed) 353 if (!this._cachedResourcesProcessed)
354 return; 354 return;
355 355
356 var frameId = event.data.frameId; 356 var frameId = event.data.frameId;
357 var frame = this._frames[frameId]; 357 var frame = this._frames.get(frameId);
358 if (!frame) 358 if (!frame)
359 return; 359 return;
360 360
361 var url = event.data.url; 361 var url = event.data.url;
362 if (frame._resourcesMap[url]) 362 if (frame._resourcesMap[url])
363 return; 363 return;
364 364
365 var resource = new WebInspector.Resource(this.target(), null, url, frame .url, frameId, event.data.loaderId, WebInspector.resourceTypes[event.data.resour ceType], event.data.mimeType); 365 var resource = new WebInspector.Resource(this.target(), null, url, frame .url, frameId, event.data.loaderId, WebInspector.resourceTypes[event.data.resour ceType], event.data.mimeType);
366 frame.addResource(resource); 366 frame.addResource(resource);
367 }, 367 },
368 368
369 /** 369 /**
370 * @param {!PageAgent.FrameId} frameId 370 * @param {!PageAgent.FrameId} frameId
371 * @return {!WebInspector.ResourceTreeFrame} 371 * @return {!WebInspector.ResourceTreeFrame}
372 */ 372 */
373 frameForId: function(frameId) 373 frameForId: function(frameId)
374 { 374 {
375 return this._frames[frameId]; 375 return this._frames.get(frameId);
376 }, 376 },
377 377
378 /** 378 /**
379 * @param {function(!WebInspector.Resource)} callback 379 * @param {function(!WebInspector.Resource)} callback
380 * @return {boolean} 380 * @return {boolean}
381 */ 381 */
382 forAllResources: function(callback) 382 forAllResources: function(callback)
383 { 383 {
384 if (this.mainFrame) 384 if (this.mainFrame)
385 return this.mainFrame._callForFrameResources(callback); 385 return this.mainFrame._callForFrameResources(callback);
386 return false; 386 return false;
387 }, 387 },
388 388
389 /** 389 /**
390 * @return {!Array.<!WebInspector.ResourceTreeFrame>} 390 * @return {!Array<!WebInspector.ResourceTreeFrame>}
391 */ 391 */
392 frames: function() 392 frames: function()
393 { 393 {
394 return Object.values(this._frames); 394 return Array.from(this._frames.values());
lushnikov 2016/07/20 03:02:50 this._frames.valuesArray()
kozy 2016/07/20 17:55:18 Done.
395 }, 395 },
396 396
397 /** 397 /**
398 * @param {string} url 398 * @param {string} url
399 * @return {?WebInspector.Resource} 399 * @return {?WebInspector.Resource}
400 */ 400 */
401 resourceForURL: function(url) 401 resourceForURL: function(url)
402 { 402 {
403 // Workers call into this with no frames available. 403 // Workers call into this with no frames available.
404 return this.mainFrame ? this.mainFrame.resourceForURL(url) : null; 404 return this.mainFrame ? this.mainFrame.resourceForURL(url) : null;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 { 718 {
719 var frames = this._childFrames; 719 var frames = this._childFrames;
720 this._childFrames = []; 720 this._childFrames = [];
721 for (var i = 0; i < frames.length; ++i) 721 for (var i = 0; i < frames.length; ++i)
722 frames[i]._remove(); 722 frames[i]._remove();
723 }, 723 },
724 724
725 _remove: function() 725 _remove: function()
726 { 726 {
727 this._removeChildFrames(); 727 this._removeChildFrames();
728 delete this._model._frames[this.id]; 728 this._model._frames.delete(this.id);
729 this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.Even tTypes.FrameDetached, this); 729 this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.Even tTypes.FrameDetached, this);
730 }, 730 },
731 731
732 /** 732 /**
733 * @param {!WebInspector.Resource} resource 733 * @param {!WebInspector.Resource} resource
734 */ 734 */
735 addResource: function(resource) 735 addResource: function(resource)
736 { 736 {
737 if (this._resourcesMap[resource.url] === resource) { 737 if (this._resourcesMap[resource.url] === resource) {
738 // Already in the tree, we just got an extra update. 738 // Already in the tree, we just got an extra update.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 985
986 /** 986 /**
987 * @override 987 * @override
988 */ 988 */
989 navigationRequested: function() 989 navigationRequested: function()
990 { 990 {
991 // Frontend is not interested in interstitials. 991 // Frontend is not interested in interstitials.
992 } 992 }
993 993
994 } 994 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698