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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 var aRemoteAddress = aRequest.remoteAddress(); | 325 var aRemoteAddress = aRequest.remoteAddress(); |
345 var bRemoteAddress = bRequest.remoteAddress(); | 326 var bRemoteAddress = bRequest.remoteAddress(); |
346 if (aRemoteAddress > bRemoteAddress) | 327 if (aRemoteAddress > bRemoteAddress) |
347 return 1; | 328 return 1; |
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 /** |
| 335 * @param {!ProductRegistry.Registry} productRegistry |
| 336 * @param {!Network.NetworkNode} a |
| 337 * @param {!Network.NetworkNode} b |
| 338 * @return {number} |
| 339 */ |
| 340 static ProductComparator(productRegistry, a, b) { |
| 341 var aRequest = a.request(); |
| 342 var bRequest = b.request(); |
| 343 if (!aRequest || !bRequest) |
| 344 return !aRequest ? -1 : 1; |
| 345 var aName = productRegistry.nameForUrl(aRequest.parsedURL) || ''; |
| 346 var bName = productRegistry.nameForUrl(bRequest.parsedURL) || ''; |
| 347 return aName.localeCompare(bName) || aRequest.indentityCompare(bRequest); |
| 348 } |
| 349 |
| 350 /** |
354 * @param {!Network.NetworkNode} a | 351 * @param {!Network.NetworkNode} a |
355 * @param {!Network.NetworkNode} b | 352 * @param {!Network.NetworkNode} b |
356 * @return {number} | 353 * @return {number} |
357 */ | 354 */ |
358 static SizeComparator(a, b) { | 355 static SizeComparator(a, b) { |
359 // TODO(allada) Handle this properly for group nodes. | 356 // TODO(allada) Handle this properly for group nodes. |
360 var aRequest = a.requestOrFirstKnownChildRequest(); | 357 var aRequest = a.requestOrFirstKnownChildRequest(); |
361 var bRequest = b.requestOrFirstKnownChildRequest(); | 358 var bRequest = b.requestOrFirstKnownChildRequest(); |
362 if (!aRequest || !bRequest) | 359 if (!aRequest || !bRequest) |
363 return !aRequest ? -1 : 1; | 360 return !aRequest ? -1 : 1; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 var aHeader = aRequest.responseHeaderValue(propertyName); | 556 var aHeader = aRequest.responseHeaderValue(propertyName); |
560 var bHeader = bRequest.responseHeaderValue(propertyName); | 557 var bHeader = bRequest.responseHeaderValue(propertyName); |
561 var aValue = aHeader ? new Date(aHeader).getTime() : -Infinity; | 558 var aValue = aHeader ? new Date(aHeader).getTime() : -Infinity; |
562 var bValue = bHeader ? new Date(bHeader).getTime() : -Infinity; | 559 var bValue = bHeader ? new Date(bHeader).getTime() : -Infinity; |
563 if (aValue === bValue) | 560 if (aValue === bValue) |
564 return aRequest.indentityCompare(bRequest); | 561 return aRequest.indentityCompare(bRequest); |
565 return aValue > bValue ? 1 : -1; | 562 return aValue > bValue ? 1 : -1; |
566 } | 563 } |
567 | 564 |
568 /** | 565 /** |
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 | 566 * @override |
588 */ | 567 */ |
589 showingInitiatorChainChanged() { | 568 showingInitiatorChainChanged() { |
590 var showInitiatorChain = this.showingInitiatorChain(); | 569 var showInitiatorChain = this.showingInitiatorChain(); |
591 | 570 |
592 var initiatorGraph = NetworkLog.networkLog.initiatorGraphForRequest(this._re
quest); | 571 var initiatorGraph = NetworkLog.networkLog.initiatorGraphForRequest(this._re
quest); |
593 for (var request of initiatorGraph.initiators) { | 572 for (var request of initiatorGraph.initiators) { |
594 if (request === this._request) | 573 if (request === this._request) |
595 continue; | 574 continue; |
596 var node = this.parentView().nodeForRequest(request); | 575 var node = this.parentView().nodeForRequest(request); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 /** | 678 /** |
700 * @override | 679 * @override |
701 * @param {!Element} element | 680 * @param {!Element} element |
702 */ | 681 */ |
703 createCells(element) { | 682 createCells(element) { |
704 this._nameCell = null; | 683 this._nameCell = null; |
705 this._initiatorCell = null; | 684 this._initiatorCell = null; |
706 | 685 |
707 element.classList.toggle('network-error-row', this._isFailed()); | 686 element.classList.toggle('network-error-row', this._isFailed()); |
708 element.classList.toggle('network-navigation-row', this._isNavigationRequest
); | 687 element.classList.toggle('network-navigation-row', this._isNavigationRequest
); |
709 for (var rowDecorator of this._parentView.rowDecorators()) | |
710 rowDecorator.decorate(this); | |
711 super.createCells(element); | 688 super.createCells(element); |
712 this._updateBackgroundColor(); | 689 this._updateBackgroundColor(); |
713 } | 690 } |
714 | 691 |
715 /** | 692 /** |
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 | 693 * @param {!Element} element |
725 * @param {string} text | 694 * @param {string} text |
726 */ | 695 */ |
727 _setTextAndTitle(element, text) { | 696 _setTextAndTitle(element, text) { |
728 element.createTextChild(text); | 697 element.createTextChild(text); |
729 element.title = text; | 698 element.title = text; |
730 } | 699 } |
731 | 700 |
732 /** | 701 /** |
733 * @override | 702 * @override |
734 * @param {string} columnIdentifier | 703 * @param {string} columnIdentifier |
735 * @return {!Element} | 704 * @return {!Element} |
736 */ | 705 */ |
737 createCell(columnIdentifier) { | 706 createCell(columnIdentifier) { |
738 var cell = this.createTD(columnIdentifier); | 707 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) { | 708 switch (columnIdentifier) { |
751 case 'name': | 709 case 'name': |
752 this._renderNameCell(cell); | 710 this._renderNameCell(cell); |
753 break; | 711 break; |
| 712 case 'product': |
| 713 if (!Runtime.experiments.isEnabled('networkGroupingRequests')) { |
| 714 this._setTextAndTitle(cell, this._request.responseHeaderValue(columnId
entifier) || ''); |
| 715 break; |
| 716 } |
| 717 if (this.request()) |
| 718 ProductRegistry.instance().then(this._renderProductCell.bind(this, cel
l)); |
| 719 break; |
754 case 'method': | 720 case 'method': |
755 this._setTextAndTitle(cell, this._request.requestMethod); | 721 this._setTextAndTitle(cell, this._request.requestMethod); |
756 break; | 722 break; |
757 case 'status': | 723 case 'status': |
758 this._renderStatusCell(cell); | 724 this._renderStatusCell(cell); |
759 break; | 725 break; |
760 case 'protocol': | 726 case 'protocol': |
761 this._setTextAndTitle(cell, this._request.protocol); | 727 this._setTextAndTitle(cell, this._request.protocol); |
762 break; | 728 break; |
763 case 'scheme': | 729 case 'scheme': |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 iconElement.classList.add(this._request.resourceType().name()); | 859 iconElement.classList.add(this._request.resourceType().name()); |
894 | 860 |
895 cell.appendChild(iconElement); | 861 cell.appendChild(iconElement); |
896 cell.createTextChild(this._request.networkManager().target().decorateLabel(t
his._request.name())); | 862 cell.createTextChild(this._request.networkManager().target().decorateLabel(t
his._request.name())); |
897 this._appendSubtitle(cell, this._request.path()); | 863 this._appendSubtitle(cell, this._request.path()); |
898 cell.title = this._request.url(); | 864 cell.title = this._request.url(); |
899 } | 865 } |
900 | 866 |
901 /** | 867 /** |
902 * @param {!Element} cell | 868 * @param {!Element} cell |
| 869 * @param {!ProductRegistry.Registry} productRegistry |
| 870 */ |
| 871 _renderProductCell(cell, productRegistry) { |
| 872 var request = this.request(); |
| 873 if (!request) |
| 874 return; |
| 875 var entry = productRegistry.entryForUrl(request.parsedURL); |
| 876 if (!entry) |
| 877 return; |
| 878 this._setTextAndTitle(cell, entry.name); |
| 879 if (entry.type !== null) { |
| 880 var element = this.existingElement(); |
| 881 if (!element) |
| 882 return; |
| 883 switch (entry.type) { |
| 884 case 0: |
| 885 this._backgroundColor = Common.Color.fromRGBA([224, 247, 250, .6]); |
| 886 cell.classList.add('product-ad'); |
| 887 break; |
| 888 case 1: |
| 889 this._backgroundColor = Common.Color.fromRGBA([255, 252, 225, .6]); |
| 890 cell.classList.add('product-tracking'); |
| 891 break; |
| 892 case 2: |
| 893 this._backgroundColor = Common.Color.fromRGBA([211, 253, 211, .6]); |
| 894 cell.classList.add('product-cdn'); |
| 895 break; |
| 896 default: |
| 897 this._backgroundColor = null; |
| 898 } |
| 899 this._updateBackgroundColor(); |
| 900 } |
| 901 } |
| 902 |
| 903 /** |
| 904 * @param {!Element} cell |
903 */ | 905 */ |
904 _renderStatusCell(cell) { | 906 _renderStatusCell(cell) { |
905 cell.classList.toggle( | 907 cell.classList.toggle( |
906 'network-dim-cell', !this._isFailed() && (this._request.cached() || !thi
s._request.statusCode)); | 908 'network-dim-cell', !this._isFailed() && (this._request.cached() || !thi
s._request.statusCode)); |
907 | 909 |
908 if (this._request.failed && !this._request.canceled && !this._request.wasBlo
cked()) { | 910 if (this._request.failed && !this._request.canceled && !this._request.wasBlo
cked()) { |
909 var failText = Common.UIString('(failed)'); | 911 var failText = Common.UIString('(failed)'); |
910 if (this._request.localizedFailDescription) { | 912 if (this._request.localizedFailDescription) { |
911 cell.createTextChild(failText); | 913 cell.createTextChild(failText); |
912 this._appendSubtitle(cell, this._request.localizedFailDescription); | 914 this._appendSubtitle(cell, this._request.localizedFailDescription); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 element.title = text; | 1095 element.title = text; |
1094 } | 1096 } |
1095 | 1097 |
1096 /** | 1098 /** |
1097 * @override | 1099 * @override |
1098 * @param {string} columnIdentifier | 1100 * @param {string} columnIdentifier |
1099 * @return {!Element} | 1101 * @return {!Element} |
1100 */ | 1102 */ |
1101 createCell(columnIdentifier) { | 1103 createCell(columnIdentifier) { |
1102 var cell = this.createTD(columnIdentifier); | 1104 var cell = this.createTD(columnIdentifier); |
1103 if (this._columnExtensions.has(columnIdentifier)) | |
1104 return cell; | |
1105 if (columnIdentifier === 'name') { | 1105 if (columnIdentifier === 'name') { |
1106 var leftPadding = this.leftPadding ? this.leftPadding + 'px' : ''; | 1106 var leftPadding = this.leftPadding ? this.leftPadding + 'px' : ''; |
1107 cell.style.setProperty('padding-left', leftPadding); | 1107 cell.style.setProperty('padding-left', leftPadding); |
1108 cell.classList.add('disclosure'); | 1108 cell.classList.add('disclosure'); |
1109 this._setTextAndTitle(cell, this._displayName); | 1109 this._setTextAndTitle(cell, this._displayName); |
1110 } | 1110 } |
1111 return cell; | 1111 return cell; |
1112 } | 1112 } |
1113 | 1113 |
1114 /** | 1114 /** |
1115 * @override | 1115 * @override |
1116 * @param {boolean=} supressSelectedEvent | 1116 * @param {boolean=} supressSelectedEvent |
1117 */ | 1117 */ |
1118 select(supressSelectedEvent) { | 1118 select(supressSelectedEvent) { |
1119 if (this.expanded) { | 1119 if (this.expanded) { |
1120 this.collapse(); | 1120 this.collapse(); |
1121 return; | 1121 return; |
1122 } | 1122 } |
1123 this.expand(); | 1123 this.expand(); |
1124 } | 1124 } |
1125 }; | 1125 }; |
OLD | NEW |