 Chromium Code Reviews
 Chromium Code Reviews Issue 2773583002:
  [DevTools] Introduce a sidebar with a drop-down
    
  
    Issue 2773583002:
  [DevTools] Introduce a sidebar with a drop-down 
  | OLD | NEW | 
|---|---|
| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 * @return {?SDK.ResourceTreeFrame} | 64 * @return {?SDK.ResourceTreeFrame} | 
| 65 */ | 65 */ | 
| 66 static frameForRequest(request) { | 66 static frameForRequest(request) { | 
| 67 var resourceTreeModel = request.networkManager().target().model(SDK.Resource TreeModel); | 67 var resourceTreeModel = request.networkManager().target().model(SDK.Resource TreeModel); | 
| 68 if (!resourceTreeModel) | 68 if (!resourceTreeModel) | 
| 69 return null; | 69 return null; | 
| 70 return resourceTreeModel.frameForId(request.frameId); | 70 return resourceTreeModel.frameForId(request.frameId); | 
| 71 } | 71 } | 
| 72 | 72 | 
| 73 /** | 73 /** | 
| 74 * @param {!SDK.ResourceTreeFrame} frame | |
| 75 * @return {?SDK.ResourceTreeFrame} | |
| 76 */ | |
| 77 static _parentFrameAcrossTargets(frame) { | |
| 78 var parentFrame = frame.parentFrame; | |
| 79 if (parentFrame) | |
| 80 return parentFrame; | |
| 81 var parentTarget = frame.resourceTreeModel().target().parentTarget(); | |
| 82 var otherModel = parentTarget && parentTarget.model(SDK.ResourceTreeModel); | |
| 83 if (!otherModel) | |
| 84 return null; | |
| 85 return otherModel.mainFrame; | |
| 86 } | |
| 87 | |
| 88 /** | |
| 89 * @param {!SDK.ResourceTreeFrame} frame | |
| 90 * @return {!Array<!SDK.ResourceTreeFrame>} | |
| 91 */ | |
| 92 static framePath(frame) { | |
| 93 var path = []; | |
| 94 var currentFrame = frame; | |
| 95 while (currentFrame) { | |
| 96 path.push(currentFrame); | |
| 97 currentFrame = SDK.ResourceTreeModel._parentFrameAcrossTargets(currentFram e); | |
| 98 } | |
| 99 return path.reverse(); | |
| 100 } | |
| 101 | |
| 102 /** | |
| 103 * @param {?SDK.ResourceTreeFrame} a | |
| 
caseq
2017/05/26 22:20:19
Should it be nullable?
 | |
| 104 * @param {?SDK.ResourceTreeFrame} b | |
| 105 * @return {number} | |
| 106 */ | |
| 107 static _frameComparator(a, b) { | |
| 108 var framesA = a ? SDK.ResourceTreeModel.framePath(a) : []; | |
| 
caseq
2017/05/26 22:20:19
How about this:
var framePathA = SDK.ResourceTree
 | |
| 109 var framesB = b ? SDK.ResourceTreeModel.framePath(b) : []; | |
| 110 var frameA; | |
| 111 var frameB; | |
| 112 for (var i = 0;; i++) { | |
| 113 if (!framesA[i] || !framesB[i] || (framesA[i] !== framesB[i])) { | |
| 114 frameA = framesA[i]; | |
| 115 frameB = framesB[i]; | |
| 116 break; | |
| 117 } | |
| 118 } | |
| 119 if (!frameA && frameB) | |
| 120 return -1; | |
| 121 | |
| 122 if (!frameB && frameA) | |
| 123 return 1; | |
| 124 | |
| 125 if (frameA && frameB) | |
| 126 return frameA.id.localeCompare(frameB.id); | |
| 127 | |
| 128 return 0; | |
| 129 } | |
| 130 | |
| 131 /** | |
| 74 * @return {!Array.<!SDK.ResourceTreeFrame>} | 132 * @return {!Array.<!SDK.ResourceTreeFrame>} | 
| 75 */ | 133 */ | 
| 76 static frames() { | 134 static frames() { | 
| 77 var result = []; | 135 var result = []; | 
| 78 for (var resourceTreeModel of SDK.targetManager.models(SDK.ResourceTreeModel )) | 136 for (var resourceTreeModel of SDK.targetManager.models(SDK.ResourceTreeModel )) | 
| 79 result = result.concat(resourceTreeModel._frames.valuesArray()); | 137 result = result.concat(resourceTreeModel._frames.valuesArray()); | 
| 138 result.sort(SDK.ResourceTreeModel._frameComparator); | |
| 80 return result; | 139 return result; | 
| 81 } | 140 } | 
| 82 | 141 | 
| 83 /** | 142 /** | 
| 84 * @param {string} url | 143 * @param {string} url | 
| 85 * @return {?SDK.Resource} | 144 * @return {?SDK.Resource} | 
| 86 */ | 145 */ | 
| 87 static resourceForURL(url) { | 146 static resourceForURL(url) { | 
| 88 for (var resourceTreeModel of SDK.targetManager.models(SDK.ResourceTreeModel )) { | 147 for (var resourceTreeModel of SDK.targetManager.models(SDK.ResourceTreeModel )) { | 
| 89 var mainFrame = resourceTreeModel.mainFrame; | 148 var mainFrame = resourceTreeModel.mainFrame; | 
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 * @param {string=} data | 479 * @param {string=} data | 
| 421 */ | 480 */ | 
| 422 function myCallback(protocolError, url, errors, data) { | 481 function myCallback(protocolError, url, errors, data) { | 
| 423 if (protocolError) { | 482 if (protocolError) { | 
| 424 callback(url, null, []); | 483 callback(url, null, []); | 
| 425 return; | 484 return; | 
| 426 } | 485 } | 
| 427 callback(url, data || null, errors); | 486 callback(url, data || null, errors); | 
| 428 } | 487 } | 
| 429 } | 488 } | 
| 489 | |
| 430 /** | 490 /** | 
| 431 * @param {!SDK.ExecutionContext} a | 491 * @param {!SDK.ExecutionContext} a | 
| 432 * @param {!SDK.ExecutionContext} b | 492 * @param {!SDK.ExecutionContext} b | 
| 433 * @return {number} | 493 * @return {number} | 
| 434 */ | 494 */ | 
| 435 _executionContextComparator(a, b) { | 495 _executionContextComparator(a, b) { | 
| 436 /** | |
| 437 * @param {!SDK.ResourceTreeFrame} frame | |
| 438 */ | |
| 439 function framePath(frame) { | |
| 440 var currentFrame = frame; | |
| 441 var parents = []; | |
| 442 while (currentFrame) { | |
| 443 parents.push(currentFrame); | |
| 444 currentFrame = currentFrame.parentFrame; | |
| 445 } | |
| 446 return parents.reverse(); | |
| 447 } | |
| 448 | |
| 449 if (a.target() !== b.target()) | 496 if (a.target() !== b.target()) | 
| 450 return SDK.ExecutionContext.comparator(a, b); | 497 return SDK.ExecutionContext.comparator(a, b); | 
| 451 | 498 | 
| 452 var framesA = a.frameId ? framePath(this.frameForId(a.frameId)) : []; | 499 var frameA = a.frameId ? this.frameForId(a.frameId) : null; | 
| 453 var framesB = b.frameId ? framePath(this.frameForId(b.frameId)) : []; | 500 var frameB = b.frameId ? this.frameForId(b.frameId) : null; | 
| 454 var frameA; | |
| 455 var frameB; | |
| 456 for (var i = 0;; i++) { | |
| 457 if (!framesA[i] || !framesB[i] || (framesA[i] !== framesB[i])) { | |
| 458 frameA = framesA[i]; | |
| 459 frameB = framesB[i]; | |
| 460 break; | |
| 461 } | |
| 462 } | |
| 463 if (!frameA && frameB) | |
| 464 return -1; | |
| 465 | 501 | 
| 466 if (!frameB && frameA) | 502 if (!frameA && !frameB) | 
| 467 return 1; | 503 return SDK.ExecutionContext.comparator(a, b); | 
| 468 | 504 | 
| 469 if (frameA && frameB) | 505 return SDK.ResourceTreeModel._frameComparator(frameA, frameB); | 
| 470 return frameA.id.localeCompare(frameB.id); | |
| 471 | |
| 472 return SDK.ExecutionContext.comparator(a, b); | |
| 473 } | 506 } | 
| 474 | 507 | 
| 475 _updateSecurityOrigins() { | 508 _updateSecurityOrigins() { | 
| 476 var securityOrigins = new Set(); | 509 var securityOrigins = new Set(); | 
| 477 var mainSecurityOrigin = null; | 510 var mainSecurityOrigin = null; | 
| 478 for (var frame of this._frames.values()) { | 511 for (var frame of this._frames.values()) { | 
| 479 var origin = frame.securityOrigin; | 512 var origin = frame.securityOrigin; | 
| 480 if (!origin) | 513 if (!origin) | 
| 481 continue; | 514 continue; | 
| 482 securityOrigins.add(origin); | 515 securityOrigins.add(origin); | 
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 this._resourceTreeModel.dispatchEventToListeners(SDK.ResourceTreeModel.Event s.InterstitialHidden); | 932 this._resourceTreeModel.dispatchEventToListeners(SDK.ResourceTreeModel.Event s.InterstitialHidden); | 
| 900 } | 933 } | 
| 901 | 934 | 
| 902 /** | 935 /** | 
| 903 * @override | 936 * @override | 
| 904 */ | 937 */ | 
| 905 navigationRequested() { | 938 navigationRequested() { | 
| 906 // Frontend is not interested in when navigations are requested. | 939 // Frontend is not interested in when navigations are requested. | 
| 907 } | 940 } | 
| 908 }; | 941 }; | 
| OLD | NEW |