Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org> | 3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org> |
| 4 * Copyright (C) 2011 Google Inc. All rights reserved. | 4 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 Network.NetworkNode = class extends DataGrid.SortableDataGridNode { | 34 Network.NetworkNode = class extends DataGrid.SortableDataGridNode { |
| 35 /** | 35 /** |
| 36 * @param {!Network.NetworkLogView} parentView | 36 * @param {!Network.NetworkLogView} parentView |
| 37 */ | 37 */ |
| 38 constructor(parentView) { | 38 constructor(parentView) { |
| 39 super({}); | 39 super({}); |
| 40 this._parentView = parentView; | 40 this._parentView = parentView; |
| 41 /** @type {!Map<string, ?Network.NetworkColumnExtensionInterface>} */ | |
| 42 this._columnExtensions = new Map(); | |
| 43 this._isHovered = false; | 41 this._isHovered = false; |
| 44 this._showingInitiatorChain = false; | 42 this._showingInitiatorChain = false; |
| 45 /** @type {?SDK.NetworkRequest} */ | 43 /** @type {?SDK.NetworkRequest} */ |
| 46 this._requestOrFirstKnownChildRequest = null; | 44 this._requestOrFirstKnownChildRequest = null; |
| 47 /** @type {!Map<string, !UI.Icon>} */ | |
| 48 this._columnIcons = new Map(); | |
| 49 /** @type {?Common.Color} */ | 45 /** @type {?Common.Color} */ |
| 50 this._backgroundColor = null; | 46 this._backgroundColor = null; |
| 51 } | 47 } |
| 52 | 48 |
| 53 /** | 49 /** |
| 54 * @return {!Network.NetworkNode._SupportedBackgroundColors} | 50 * @return {!Network.NetworkNode._SupportedBackgroundColors} |
| 55 */ | 51 */ |
| 56 static _themedBackgroundColors() { | 52 static _themedBackgroundColors() { |
| 57 if (Network.NetworkNode._themedBackgroundColorsCache) | 53 if (Network.NetworkNode._themedBackgroundColorsCache) |
| 58 return Network.NetworkNode._themedBackgroundColorsCache; | 54 return Network.NetworkNode._themedBackgroundColorsCache; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 81 if (this.isOnInitiatorPath()) | 77 if (this.isOnInitiatorPath()) |
| 82 color = color.blendWith(bgColors.InitiatorPath); | 78 color = color.blendWith(bgColors.InitiatorPath); |
| 83 if (this.isOnInitiatedPath()) | 79 if (this.isOnInitiatedPath()) |
| 84 color = color.blendWith(bgColors.InitiatedPath); | 80 color = color.blendWith(bgColors.InitiatedPath); |
| 85 if (this.selected) | 81 if (this.selected) |
| 86 color = color.blendWith(bgColors.Selected); | 82 color = color.blendWith(bgColors.Selected); |
| 87 | 83 |
| 88 return /** @type {string} */ (color.asString(Common.Color.Format.HEX)); | 84 return /** @type {string} */ (color.asString(Common.Color.Format.HEX)); |
| 89 } | 85 } |
| 90 | 86 |
| 91 /** | |
| 92 * @param {?Common.Color} color | |
| 93 */ | |
| 94 setBackgroundColor(color) { | |
| 95 this._backgroundColor = color; | |
| 96 this._updateBackgroundColor(); | |
| 97 } | |
| 98 | |
| 99 _updateBackgroundColor() { | 87 _updateBackgroundColor() { |
| 100 var element = this.existingElement(); | 88 var element = this.existingElement(); |
| 101 if (!element) | 89 if (!element) |
| 102 return; | 90 return; |
| 103 element.style.backgroundColor = this.backgroundColor(); | 91 element.style.backgroundColor = this.backgroundColor(); |
| 104 this._parentView.stylesChanged(); | 92 this._parentView.stylesChanged(); |
| 105 } | 93 } |
| 106 | 94 |
| 107 /** | 95 /** |
| 108 * @override | 96 * @override |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 136 | 124 |
| 137 /** | 125 /** |
| 138 * @override | 126 * @override |
| 139 * @return {number} | 127 * @return {number} |
| 140 */ | 128 */ |
| 141 nodeSelfHeight() { | 129 nodeSelfHeight() { |
| 142 return this._parentView.rowHeight(); | 130 return this._parentView.rowHeight(); |
| 143 } | 131 } |
| 144 | 132 |
| 145 /** | 133 /** |
| 146 * @param {!Map<string, ?Network.NetworkColumnExtensionInterface>} columnExten sions | |
| 147 */ | |
| 148 setColumnExtensions(columnExtensions) { | |
| 149 this._columnExtensions = columnExtensions; | |
| 150 } | |
| 151 | |
| 152 /** | |
| 153 * @param {boolean} hovered | 134 * @param {boolean} hovered |
| 154 * @param {boolean} showInitiatorChain | 135 * @param {boolean} showInitiatorChain |
| 155 */ | 136 */ |
| 156 setHovered(hovered, showInitiatorChain) { | 137 setHovered(hovered, showInitiatorChain) { |
| 157 if (this._isHovered === hovered && this._showingInitiatorChain === showIniti atorChain) | 138 if (this._isHovered === hovered && this._showingInitiatorChain === showIniti atorChain) |
| 158 return; | 139 return; |
| 159 if (this._isHovered !== hovered) { | 140 if (this._isHovered !== hovered) { |
| 160 this._isHovered = hovered; | 141 this._isHovered = hovered; |
| 161 if (this.attached()) | 142 if (this.attached()) |
| 162 this.element().classList.toggle('hover', hovered); | 143 this.element().classList.toggle('hover', hovered); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 if (bRemoteAddress > aRemoteAddress) | 329 if (bRemoteAddress > aRemoteAddress) |
| 349 return -1; | 330 return -1; |
| 350 return aRequest.indentityCompare(bRequest); | 331 return aRequest.indentityCompare(bRequest); |
| 351 } | 332 } |
| 352 | 333 |
| 353 /** | 334 /** |
| 354 * @param {!Network.NetworkNode} a | 335 * @param {!Network.NetworkNode} a |
| 355 * @param {!Network.NetworkNode} b | 336 * @param {!Network.NetworkNode} b |
| 356 * @return {number} | 337 * @return {number} |
| 357 */ | 338 */ |
| 339 static ProductComparitor(a, b) { | |
|
pfeldman
2017/04/27 22:20:48
ProductComparator.
allada
2017/04/28 01:20:06
Done.
| |
| 340 var aRequest = a.request(); | |
| 341 var bRequest = b.request(); | |
| 342 if (!aRequest || !bRequest) | |
| 343 return !aRequest ? -1 : 1; | |
| 344 var productRegistry = ProductRegistry.existingInstance(); | |
| 345 if (!productRegistry) | |
| 346 return aRequest.indentityCompare(bRequest); | |
| 347 var aName = productRegistry.nameForUrl(aRequest.parsedURL) || ''; | |
| 348 var bName = productRegistry.nameForUrl(bRequest.parsedURL) || ''; | |
| 349 return aName.compareTo(bName) || aRequest.indentityCompare(bRequest); | |
|
pfeldman
2017/04/27 22:20:48
localeCompare
allada
2017/04/28 01:20:06
Done.
| |
| 350 } | |
| 351 | |
| 352 /** | |
| 353 * @param {!Network.NetworkNode} a | |
| 354 * @param {!Network.NetworkNode} b | |
| 355 * @return {number} | |
| 356 */ | |
| 358 static SizeComparator(a, b) { | 357 static SizeComparator(a, b) { |
| 359 // TODO(allada) Handle this properly for group nodes. | 358 // TODO(allada) Handle this properly for group nodes. |
| 360 var aRequest = a.requestOrFirstKnownChildRequest(); | 359 var aRequest = a.requestOrFirstKnownChildRequest(); |
| 361 var bRequest = b.requestOrFirstKnownChildRequest(); | 360 var bRequest = b.requestOrFirstKnownChildRequest(); |
| 362 if (!aRequest || !bRequest) | 361 if (!aRequest || !bRequest) |
| 363 return !aRequest ? -1 : 1; | 362 return !aRequest ? -1 : 1; |
| 364 if (bRequest.cached() && !aRequest.cached()) | 363 if (bRequest.cached() && !aRequest.cached()) |
| 365 return 1; | 364 return 1; |
| 366 if (aRequest.cached() && !bRequest.cached()) | 365 if (aRequest.cached() && !bRequest.cached()) |
| 367 return -1; | 366 return -1; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 var aHeader = aRequest.responseHeaderValue(propertyName); | 558 var aHeader = aRequest.responseHeaderValue(propertyName); |
| 560 var bHeader = bRequest.responseHeaderValue(propertyName); | 559 var bHeader = bRequest.responseHeaderValue(propertyName); |
| 561 var aValue = aHeader ? new Date(aHeader).getTime() : -Infinity; | 560 var aValue = aHeader ? new Date(aHeader).getTime() : -Infinity; |
| 562 var bValue = bHeader ? new Date(bHeader).getTime() : -Infinity; | 561 var bValue = bHeader ? new Date(bHeader).getTime() : -Infinity; |
| 563 if (aValue === bValue) | 562 if (aValue === bValue) |
| 564 return aRequest.indentityCompare(bRequest); | 563 return aRequest.indentityCompare(bRequest); |
| 565 return aValue > bValue ? 1 : -1; | 564 return aValue > bValue ? 1 : -1; |
| 566 } | 565 } |
| 567 | 566 |
| 568 /** | 567 /** |
| 569 * @param {!Map<string, ?Network.NetworkColumnExtensionInterface>} extensionsM ap | |
| 570 * @param {string} extensionId | |
| 571 * @param {!Network.NetworkNode} a | |
| 572 * @param {!Network.NetworkNode} b | |
| 573 * @return {number} | |
| 574 */ | |
| 575 static ExtensionColumnComparator(extensionsMap, extensionId, a, b) { | |
| 576 var aRequest = a.requestOrFirstKnownChildRequest(); | |
| 577 var bRequest = b.requestOrFirstKnownChildRequest(); | |
| 578 if (!aRequest || !bRequest) | |
| 579 return !aRequest ? -1 : 1; | |
| 580 var instance = extensionsMap.get(extensionId); | |
| 581 if (!instance) | |
| 582 return aRequest.indentityCompare(bRequest); | |
| 583 return instance.requestComparator(aRequest, bRequest); | |
| 584 } | |
| 585 | |
| 586 /** | |
| 587 * @override | 568 * @override |
| 588 */ | 569 */ |
| 589 showingInitiatorChainChanged() { | 570 showingInitiatorChainChanged() { |
| 590 var showInitiatorChain = this.showingInitiatorChain(); | 571 var showInitiatorChain = this.showingInitiatorChain(); |
| 591 | 572 |
| 592 var initiatorGraph = NetworkLog.networkLog.initiatorGraphForRequest(this._re quest); | 573 var initiatorGraph = NetworkLog.networkLog.initiatorGraphForRequest(this._re quest); |
| 593 for (var request of initiatorGraph.initiators) { | 574 for (var request of initiatorGraph.initiators) { |
| 594 if (request === this._request) | 575 if (request === this._request) |
| 595 continue; | 576 continue; |
| 596 var node = this.parentView().nodeForRequest(request); | 577 var node = this.parentView().nodeForRequest(request); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 /** | 680 /** |
| 700 * @override | 681 * @override |
| 701 * @param {!Element} element | 682 * @param {!Element} element |
| 702 */ | 683 */ |
| 703 createCells(element) { | 684 createCells(element) { |
| 704 this._nameCell = null; | 685 this._nameCell = null; |
| 705 this._initiatorCell = null; | 686 this._initiatorCell = null; |
| 706 | 687 |
| 707 element.classList.toggle('network-error-row', this._isFailed()); | 688 element.classList.toggle('network-error-row', this._isFailed()); |
| 708 element.classList.toggle('network-navigation-row', this._isNavigationRequest ); | 689 element.classList.toggle('network-navigation-row', this._isNavigationRequest ); |
| 709 for (var rowDecorator of this._parentView.rowDecorators()) | |
| 710 rowDecorator.decorate(this); | |
| 711 super.createCells(element); | 690 super.createCells(element); |
| 712 this._updateBackgroundColor(); | 691 this._updateBackgroundColor(); |
| 713 } | 692 } |
| 714 | 693 |
| 715 /** | 694 /** |
| 716 * @param {string} columnId | |
| 717 * @param {!UI.Icon} icon | |
| 718 */ | |
| 719 setIconForColumn(columnId, icon) { | |
| 720 this._columnIcons.set(columnId, icon); | |
| 721 } | |
| 722 | |
| 723 /** | |
| 724 * @param {!Element} element | 695 * @param {!Element} element |
| 725 * @param {string} text | 696 * @param {string} text |
| 726 */ | 697 */ |
| 727 _setTextAndTitle(element, text) { | 698 _setTextAndTitle(element, text) { |
| 728 element.createTextChild(text); | 699 element.createTextChild(text); |
| 729 element.title = text; | 700 element.title = text; |
| 730 } | 701 } |
| 731 | 702 |
| 732 /** | 703 /** |
| 733 * @override | 704 * @override |
| 734 * @param {string} columnIdentifier | 705 * @param {string} columnIdentifier |
| 735 * @return {!Element} | 706 * @return {!Element} |
| 736 */ | 707 */ |
| 737 createCell(columnIdentifier) { | 708 createCell(columnIdentifier) { |
| 738 var cell = this.createTD(columnIdentifier); | 709 var cell = this.createTD(columnIdentifier); |
| 739 var icon = this._columnIcons.get(columnIdentifier); | |
| 740 if (icon) | |
| 741 cell.appendChild(icon); | |
| 742 // If the key exists but the value is null it means the extension instance h as not resolved yet. | |
| 743 // The view controller will force all rows to update when extension is resol ved. | |
| 744 if (this._columnExtensions.has(columnIdentifier)) { | |
| 745 var instance = this._columnExtensions.get(columnIdentifier); | |
| 746 if (instance) | |
| 747 this._setTextAndTitle(cell, instance.lookupColumnValue(this._request)); | |
| 748 return cell; | |
| 749 } | |
| 750 switch (columnIdentifier) { | 710 switch (columnIdentifier) { |
| 751 case 'name': | 711 case 'name': |
| 752 this._renderNameCell(cell); | 712 this._renderNameCell(cell); |
| 753 break; | 713 break; |
| 714 case 'product': | |
| 715 if (!Runtime.experiments.isEnabled('networkGroupingRequests')) { | |
| 716 this._setTextAndTitle(cell, this._request.responseHeaderValue(columnId entifier) || ''); | |
| 717 break; | |
| 718 } | |
| 719 this._parentView.initializeProductRegistryIfNeeded(); | |
| 720 this._renderProductCell(cell); | |
|
pfeldman
2017/04/27 22:20:48
This should be chained after the promise.
allada
2017/04/28 01:20:06
Done.
| |
| 721 break; | |
| 754 case 'method': | 722 case 'method': |
| 755 this._setTextAndTitle(cell, this._request.requestMethod); | 723 this._setTextAndTitle(cell, this._request.requestMethod); |
| 756 break; | 724 break; |
| 757 case 'status': | 725 case 'status': |
| 758 this._renderStatusCell(cell); | 726 this._renderStatusCell(cell); |
| 759 break; | 727 break; |
| 760 case 'protocol': | 728 case 'protocol': |
| 761 this._setTextAndTitle(cell, this._request.protocol); | 729 this._setTextAndTitle(cell, this._request.protocol); |
| 762 break; | 730 break; |
| 763 case 'scheme': | 731 case 'scheme': |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 | 862 |
| 895 cell.appendChild(iconElement); | 863 cell.appendChild(iconElement); |
| 896 cell.createTextChild(this._request.networkManager().target().decorateLabel(t his._request.name())); | 864 cell.createTextChild(this._request.networkManager().target().decorateLabel(t his._request.name())); |
| 897 this._appendSubtitle(cell, this._request.path()); | 865 this._appendSubtitle(cell, this._request.path()); |
| 898 cell.title = this._request.url(); | 866 cell.title = this._request.url(); |
| 899 } | 867 } |
| 900 | 868 |
| 901 /** | 869 /** |
| 902 * @param {!Element} cell | 870 * @param {!Element} cell |
| 903 */ | 871 */ |
| 872 _renderProductCell(cell) { | |
| 873 var productRegistry = ProductRegistry.existingInstance(); | |
|
pfeldman
2017/04/27 22:20:48
Don't use it here, just chain.
allada
2017/04/28 01:20:06
Done.
| |
| 874 var request = this.request(); | |
| 875 if (!productRegistry || !request) | |
| 876 return productRegistry; | |
| 877 var entry = productRegistry.entryForUrl(request.parsedURL); | |
| 878 if (!entry) | |
| 879 return; | |
| 880 this._setTextAndTitle(cell, entry.name); | |
| 881 if (entry.type !== null) { | |
| 882 var element = this.existingElement(); | |
| 883 if (!element) | |
| 884 return; | |
| 885 switch (entry.type) { | |
| 886 case 0: | |
| 887 this._backgroundColor = Common.Color.fromRGBA([224, 247, 250, .6]); | |
| 888 cell.classList.add('product-ad'); | |
| 889 break; | |
| 890 case 1: | |
| 891 this._backgroundColor = Common.Color.fromRGBA([255, 252, 225, .6]); | |
| 892 cell.classList.add('product-tracking'); | |
| 893 break; | |
| 894 case 2: | |
| 895 this._backgroundColor = Common.Color.fromRGBA([211, 253, 211, .6]); | |
| 896 cell.classList.add('product-cdn'); | |
| 897 break; | |
| 898 default: | |
| 899 this._backgroundColor = null; | |
| 900 } | |
| 901 } | |
| 902 } | |
| 903 | |
| 904 /** | |
| 905 * @param {!Element} cell | |
| 906 */ | |
| 904 _renderStatusCell(cell) { | 907 _renderStatusCell(cell) { |
| 905 cell.classList.toggle( | 908 cell.classList.toggle( |
| 906 'network-dim-cell', !this._isFailed() && (this._request.cached() || !thi s._request.statusCode)); | 909 'network-dim-cell', !this._isFailed() && (this._request.cached() || !thi s._request.statusCode)); |
| 907 | 910 |
| 908 if (this._request.failed && !this._request.canceled && !this._request.wasBlo cked()) { | 911 if (this._request.failed && !this._request.canceled && !this._request.wasBlo cked()) { |
| 909 var failText = Common.UIString('(failed)'); | 912 var failText = Common.UIString('(failed)'); |
| 910 if (this._request.localizedFailDescription) { | 913 if (this._request.localizedFailDescription) { |
| 911 cell.createTextChild(failText); | 914 cell.createTextChild(failText); |
| 912 this._appendSubtitle(cell, this._request.localizedFailDescription); | 915 this._appendSubtitle(cell, this._request.localizedFailDescription); |
| 913 cell.title = failText + ' ' + this._request.localizedFailDescription; | 916 cell.title = failText + ' ' + this._request.localizedFailDescription; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 element.title = text; | 1096 element.title = text; |
| 1094 } | 1097 } |
| 1095 | 1098 |
| 1096 /** | 1099 /** |
| 1097 * @override | 1100 * @override |
| 1098 * @param {string} columnIdentifier | 1101 * @param {string} columnIdentifier |
| 1099 * @return {!Element} | 1102 * @return {!Element} |
| 1100 */ | 1103 */ |
| 1101 createCell(columnIdentifier) { | 1104 createCell(columnIdentifier) { |
| 1102 var cell = this.createTD(columnIdentifier); | 1105 var cell = this.createTD(columnIdentifier); |
| 1103 if (this._columnExtensions.has(columnIdentifier)) | |
| 1104 return cell; | |
| 1105 if (columnIdentifier === 'name') { | 1106 if (columnIdentifier === 'name') { |
| 1106 var leftPadding = this.leftPadding ? this.leftPadding + 'px' : ''; | 1107 var leftPadding = this.leftPadding ? this.leftPadding + 'px' : ''; |
| 1107 cell.style.setProperty('padding-left', leftPadding); | 1108 cell.style.setProperty('padding-left', leftPadding); |
| 1108 cell.classList.add('disclosure'); | 1109 cell.classList.add('disclosure'); |
| 1109 this._setTextAndTitle(cell, this._displayName); | 1110 this._setTextAndTitle(cell, this._displayName); |
| 1110 } | 1111 } |
| 1111 return cell; | 1112 return cell; |
| 1112 } | 1113 } |
| 1113 | 1114 |
| 1114 /** | 1115 /** |
| 1115 * @override | 1116 * @override |
| 1116 * @param {boolean=} supressSelectedEvent | 1117 * @param {boolean=} supressSelectedEvent |
| 1117 */ | 1118 */ |
| 1118 select(supressSelectedEvent) { | 1119 select(supressSelectedEvent) { |
| 1119 if (this.expanded) { | 1120 if (this.expanded) { |
| 1120 this.collapse(); | 1121 this.collapse(); |
| 1121 return; | 1122 return; |
| 1122 } | 1123 } |
| 1123 this.expand(); | 1124 this.expand(); |
| 1124 } | 1125 } |
| 1125 }; | 1126 }; |
| OLD | NEW |