Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/network/NetworkLogView.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/network/NetworkLogView.js b/third_party/WebKit/Source/devtools/front_end/network/NetworkLogView.js |
| index 7c41cb9129e6dcc6a7784e9d7e9c1abe89d089fa..3eb3d70afef739d26fabaf20a8d7eb597adbc296 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/network/NetworkLogView.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/network/NetworkLogView.js |
| @@ -80,16 +80,19 @@ Network.NetworkLogView = class extends UI.VBox { |
| /** @type {number} */ |
| this._mainRequestDOMContentLoadedTime = -1; |
| this._matchedRequestCount = 0; |
| + /** @type {!Array<!Array<!Object>>} */ |
| this._highlightedSubstringChanges = []; |
| /** @type {!Array.<!Network.NetworkLogView.Filter>} */ |
| this._filters = []; |
| /** @type {?Network.NetworkLogView.Filter} */ |
| this._timeFilter = null; |
| + /** @type {?Network.NetworkDataGridNode} */ |
| this._hoveredNode = null; |
| - this._currentMatchedRequestNode = null; |
| - this._currentMatchedRequestIndex = -1; |
| + /** @type {?Network.NetworkLogEntry} */ |
| + this._currentMatchedLogEntry = null; |
| + this._currentMatchedLogEntryIndex = -1; |
| /** @type {!Components.Linkifier} */ |
| this.linkifier = new Components.Linkifier(); |
| @@ -335,6 +338,13 @@ Network.NetworkLogView = class extends UI.VBox { |
| } |
| /** |
| + * @return {!Array<!Network.NetworkLogEntry>} |
| + */ |
| + flatenChildren() { |
|
dgozman
2016/11/28 18:39:51
These are definitely not children of log view. fla
allada
2016/11/29 00:35:09
Done.
|
| + return this._dataGrid.rootNode().flatenChildren(); |
| + } |
| + |
| + /** |
| * @return {number} |
| */ |
| headerHeight() { |
| @@ -505,8 +515,9 @@ Network.NetworkLogView = class extends UI.VBox { |
| _setupDataGrid() { |
| this._dataGrid = this._columns.dataGrid(); |
| + var contextMenuHandler = this.handleContextMenuForLogEntry.bind(this); |
| this._dataGrid.setRowContextMenuCallback( |
| - (contextMenu, node) => this.handleContextMenuForRequest(contextMenu, node.request())); |
| + (contextMenu, node) => contextMenuHandler(contextMenu, /** @type {!Network.NetworkDataGridNode} */ (node))); |
| this._dataGrid.setStickToBottom(true); |
| this._dataGrid.setName('networkLog'); |
| this._dataGrid.setResizeMethod(UI.DataGrid.ResizeMethod.Last); |
| @@ -523,6 +534,7 @@ Network.NetworkLogView = class extends UI.VBox { |
| var node = this._dataGrid.dataGridNodeFromNode(event.target); |
| var highlightInitiatorChain = event.shiftKey; |
| this._setHoveredNode(node, highlightInitiatorChain); |
| + // TODO(allada) Support groupping initiator chain instead of first request. |
| this._highlightInitiatorChain((highlightInitiatorChain && node) ? node.request() : null); |
| } |
| @@ -538,6 +550,7 @@ Network.NetworkLogView = class extends UI.VBox { |
| setHoveredLogEntry(logEntry, highlightInitiatorChain) { |
| // TODO(allada) Move this into LogEntry/NetworkDataGridNode. |
| this._setHoveredNode(/** @type {?Network.NetworkDataGridNode} */ (logEntry), highlightInitiatorChain); |
| + // TODO(allada) Support groupping initiator chain instead of first request. |
| this._highlightInitiatorChain((logEntry && highlightInitiatorChain) ? logEntry.request() : null); |
| } |
| @@ -583,11 +596,19 @@ Network.NetworkLogView = class extends UI.VBox { |
| for (var node of this._nodesByRequestId.values()) { |
| if (!node.dataGrid) |
| continue; |
| - node.element().classList.toggle( |
| - 'network-node-on-initiator-path', |
| - node.request() !== request && initiatorGraph.initiators.has(node.request())); |
| - node.element().classList.toggle( |
| - 'network-node-on-initiated-path', node.request() !== request && initiatorGraph.initiated.has(node.request())); |
| + var hasInitiator = false; |
| + var hasInitiated = false; |
| + for (var childRequest of node.requests()) { |
| + if (childRequest === request) |
| + continue; |
| + hasInitiator = initiatorGraph.initiators.has(childRequest); |
| + hasInitiated = initiatorGraph.initiated.has(childRequest); |
| + if (hasInitiator || hasInitiated) |
| + break; |
| + } |
| + |
| + node.element().classList.toggle('network-node-on-initiator-path', hasInitiator); |
| + node.element().classList.toggle('network-node-on-initiated-path', hasInitiated); |
| } |
| } |
| @@ -605,19 +626,20 @@ Network.NetworkLogView = class extends UI.VBox { |
| var selectedTransferSize = 0; |
| var baseTime = -1; |
| var maxTime = -1; |
| - var nodes = this._nodesByRequestId.valuesArray(); |
| - for (var i = 0; i < nodes.length; ++i) { |
| - var request = nodes[i].request(); |
| - var requestTransferSize = request.transferSize; |
| - transferSize += requestTransferSize; |
| - if (!nodes[i][Network.NetworkLogView._isFilteredOutSymbol]) { |
| - selectedRequestsNumber++; |
| - selectedTransferSize += requestTransferSize; |
| + for (var node of this._nodesByRequestId.values()) { |
| + var isFilteredOut = node[Network.NetworkLogView._isFilteredOutSymbol]; |
| + for (var request of node.requests()) { |
| + var requestTransferSize = request.transferSize; |
| + transferSize += requestTransferSize; |
| + if (!isFilteredOut) { |
| + selectedRequestsNumber++; |
| + selectedTransferSize += requestTransferSize; |
| + } |
| + if (request.url === request.target().inspectedURL() && request.resourceType() === Common.resourceTypes.Document) |
| + baseTime = request.startTime; |
| + if (request.endTime > maxTime) |
| + maxTime = request.endTime; |
| } |
| - if (request.url === request.target().inspectedURL() && request.resourceType() === Common.resourceTypes.Document) |
| - baseTime = request.startTime; |
| - if (request.endTime > maxTime) |
| - maxTime = request.endTime; |
| } |
| var summaryBar = this._summaryBarElement; |
| @@ -780,13 +802,6 @@ Network.NetworkLogView = class extends UI.VBox { |
| this._columns.willHide(); |
| } |
| - /** |
| - * @return {!Array<!Network.NetworkDataGridNode>} |
| - */ |
| - flatNodesList() { |
| - return this._dataGrid.flatNodesList(); |
| - } |
| - |
| _refresh() { |
| this._needsRefresh = false; |
| @@ -805,6 +820,7 @@ Network.NetworkLogView = class extends UI.VBox { |
| var dataGrid = this._dataGrid; |
| var rootNode = dataGrid.rootNode(); |
| + |
| /** @type {!Array<!Network.NetworkDataGridNode> } */ |
| var nodesToInsert = []; |
| /** @type {!Array<!Network.NetworkDataGridNode> } */ |
| @@ -827,23 +843,22 @@ Network.NetworkLogView = class extends UI.VBox { |
| } |
| if (!isFilteredOut) |
| nodesToRefresh.push(node); |
| - var request = node.request(); |
| - this._timeCalculator.updateBoundaries(request); |
| - this._durationCalculator.updateBoundaries(request); |
| + for (var request of node.requests()) { |
| + this._timeCalculator.updateBoundaries(request); |
| + this._durationCalculator.updateBoundaries(request); |
| + } |
| } |
| - for (var i = 0; i < nodesToInsert.length; ++i) { |
| - var node = nodesToInsert[i]; |
| - var request = node.request(); |
| + for (var node of nodesToInsert) { |
| dataGrid.insertChild(node); |
| - node[Network.NetworkLogView._isMatchingSearchQuerySymbol] = this._matchRequest(request); |
| + node[Network.NetworkLogView._isMatchingSearchQuerySymbol] = this._matchLogEntry(node); |
| } |
| for (var node of nodesToRefresh) |
| node.refresh(); |
| this._highlightNthMatchedRequestForSearch( |
| - this._updateMatchCountAndFindMatchIndex(this._currentMatchedRequestNode), false); |
| + this._updateMatchCountAndFindMatchIndex(this._currentMatchedLogEntry), false); |
| this._staleRequestIds = {}; |
| this._updateSummaryBar(); |
| @@ -913,15 +928,15 @@ Network.NetworkLogView = class extends UI.VBox { |
| // In case of redirect request id is reassigned to a redirected |
| // request and we need to update _nodesByRequestId and search results. |
| var originalRequestNode = this._nodesByRequestId.get(request.requestId); |
| - if (originalRequestNode) |
| - this._nodesByRequestId.set(originalRequestNode.request().requestId, originalRequestNode); |
| + var originalRequest = originalRequestNode ? originalRequestNode.request() : null; |
| + if (originalRequest) |
| + this._nodesByRequestId.set(originalRequest.requestId, originalRequestNode); |
| + |
| this._nodesByRequestId.set(request.requestId, node); |
| // Pull all the redirects of the main request upon commit load. |
| - if (request.redirects) { |
| - for (var i = 0; i < request.redirects.length; ++i) |
| - this._refreshRequest(request.redirects[i]); |
| - } |
| + if (request.redirects) |
| + request.redirects.forEach(this._refreshRequest.bind(this)); |
| this._refreshRequest(request); |
| } |
| @@ -1032,9 +1047,13 @@ Network.NetworkLogView = class extends UI.VBox { |
| /** |
| * @param {!UI.ContextMenu} contextMenu |
| - * @param {!SDK.NetworkRequest} request |
| + * @param {!Network.NetworkLogEntry} logEntry |
| */ |
| - handleContextMenuForRequest(contextMenu, request) { |
| + handleContextMenuForLogEntry(contextMenu, logEntry) { |
| + // TODO(allada) Support groupped items context menu. |
| + var request = logEntry.request(); |
| + if (!request) |
| + return; |
| contextMenu.appendApplicableItems(request); |
| var copyMenu = contextMenu.appendSubMenuItem(Common.UIString('Copy')); |
| if (request) { |
| @@ -1103,11 +1122,18 @@ Network.NetworkLogView = class extends UI.VBox { |
| } |
| } |
| + /** |
| + * @return {!Array<!SDK.NetworkRequest>} |
| + */ |
| + _allRequests() { |
| + var requests = []; |
| + for (var node of this._nodesByRequestId.values()) |
| + requests = requests.concat(node.requests()); |
|
dgozman
2016/11/28 18:39:51
Should this be node.request() instead?
allada
2016/11/29 00:35:09
Done.
|
| + return requests; |
| + } |
| + |
| _harRequests() { |
| - var requests = this._nodesByRequestId.valuesArray().map(function(node) { |
| - return node.request(); |
| - }); |
| - var httpRequests = requests.filter(Network.NetworkLogView.HTTPRequestsFilter); |
| + var httpRequests = this._allRequests().filter(Network.NetworkLogView.HTTPRequestsFilter); |
| return httpRequests.filter(Network.NetworkLogView.FinishedRequestsFilter); |
| } |
| @@ -1150,17 +1176,14 @@ Network.NetworkLogView = class extends UI.VBox { |
| * @param {string} platform |
| */ |
| _copyCurlCommand(request, platform) { |
| - InspectorFrontendHost.copyText(this._generateCurlCommand(request, platform)); |
| + InspectorFrontendHost.copyText(this._generateCurlCommand(platform, request)); |
| } |
| /** |
| * @param {string} platform |
| */ |
| _copyAllCurlCommand(platform) { |
| - var requests = this._nodesByRequestId.valuesArray().map(node => node.request()); |
| - var commands = []; |
| - for (var request of requests) |
| - commands.push(this._generateCurlCommand(request, platform)); |
| + var commands = this._allRequests().map(this._generateCurlCommand.bind(this, platform)); |
| if (platform === 'win') |
| InspectorFrontendHost.copyText(commands.join(' &\r\n')); |
| else |
| @@ -1199,21 +1222,25 @@ Network.NetworkLogView = class extends UI.VBox { |
| } |
| /** |
| - * @param {!SDK.NetworkRequest} request |
| + * @param {!Network.NetworkLogEntry} logEntry |
| * @return {boolean} |
| */ |
| - _matchRequest(request) { |
| + _matchLogEntry(logEntry) { |
| var re = this._searchRegex; |
| if (!re) |
| return false; |
| - |
| - var text = this._networkLogLargeRowsSetting.get() ? request.path() + '/' + request.name() : request.name(); |
| - return re.test(text); |
| + var requests = logEntry.request() ? [logEntry.request()] : []; |
|
dgozman
2016/11/28 18:39:51
I don't get this line.
allada
2016/11/29 00:35:09
Done.
|
| + for (var request of requests) { |
| + var text = this._networkLogLargeRowsSetting.get() ? request.path() + '/' + request.name() : request.name(); |
| + if (re.test(text)) |
| + return true; |
| + } |
| + return false; |
| } |
| _clearSearchMatchedList() { |
| this._matchedRequestCount = -1; |
| - this._currentMatchedRequestNode = null; |
| + this._currentMatchedLogEntry = null; |
| this._removeAllHighlights(); |
| } |
| @@ -1226,7 +1253,7 @@ Network.NetworkLogView = class extends UI.VBox { |
| dataGridSorted() { |
| this._highlightNthMatchedRequestForSearch( |
| - this._updateMatchCountAndFindMatchIndex(this._currentMatchedRequestNode), false); |
| + this._updateMatchCountAndFindMatchIndex(this._currentMatchedLogEntry), false); |
| } |
| /** |
| @@ -1236,32 +1263,30 @@ Network.NetworkLogView = class extends UI.VBox { |
| _highlightNthMatchedRequestForSearch(n, reveal) { |
| this._removeAllHighlights(); |
| - /** @type {!Array.<!Network.NetworkDataGridNode>} */ |
| - var nodes = this._dataGrid.rootNode().children; |
| var matchCount = 0; |
| - var node = null; |
| - for (var i = 0; i < nodes.length; ++i) { |
| - if (nodes[i][Network.NetworkLogView._isMatchingSearchQuerySymbol]) { |
| - if (matchCount === n) { |
| - node = nodes[i]; |
| - break; |
| - } |
| - matchCount++; |
| + var request = null; |
| + for (var node of this.flatenChildren()) { |
| + if (!node[Network.NetworkLogView._isMatchingSearchQuerySymbol]) |
| + continue; |
| + if (matchCount === n) { |
| + // TODO(allada) This should support multiple requests. |
| + request = node.request(); |
| + break; |
| } |
| + matchCount++; |
| } |
| - if (!node) { |
| - this._currentMatchedRequestNode = null; |
| + if (!request) { |
| + this._currentMatchedLogEntry = null; |
| return; |
| } |
| - var request = node.request(); |
| if (reveal) |
| Common.Revealer.reveal(request); |
| var highlightedSubstringChanges = node.highlightMatchedSubstring(this._searchRegex); |
| this._highlightedSubstringChanges.push(highlightedSubstringChanges); |
| - this._currentMatchedRequestNode = node; |
| - this._currentMatchedRequestIndex = n; |
| + this._currentMatchedLogEntry = node; |
| + this._currentMatchedLogEntryIndex = n; |
| this.dispatchEventToListeners(Network.NetworkLogView.Events.SearchIndexUpdated, n); |
| } |
| @@ -1273,15 +1298,14 @@ Network.NetworkLogView = class extends UI.VBox { |
| */ |
| performSearch(searchConfig, shouldJump, jumpBackwards) { |
| var query = searchConfig.query; |
| - var currentMatchedRequestNode = this._currentMatchedRequestNode; |
| + var currentMatchedLogEntry = this._currentMatchedLogEntry; |
| this._clearSearchMatchedList(); |
| this._searchRegex = createPlainTextSearchRegex(query, 'i'); |
| - /** @type {!Array.<!Network.NetworkDataGridNode>} */ |
| - var nodes = this._dataGrid.rootNode().children; |
| - for (var i = 0; i < nodes.length; ++i) |
| - nodes[i][Network.NetworkLogView._isMatchingSearchQuerySymbol] = this._matchRequest(nodes[i].request()); |
| - var newMatchedRequestIndex = this._updateMatchCountAndFindMatchIndex(currentMatchedRequestNode); |
| + for (var node of this.flatenChildren()) |
| + node[Network.NetworkLogView._isMatchingSearchQuerySymbol] = this._matchLogEntry(node); |
| + |
| + var newMatchedRequestIndex = this._updateMatchCountAndFindMatchIndex(currentMatchedLogEntry); |
| if (!newMatchedRequestIndex && jumpBackwards) |
| newMatchedRequestIndex = this._matchedRequestCount - 1; |
| this._highlightNthMatchedRequestForSearch(newMatchedRequestIndex, shouldJump); |
| @@ -1304,18 +1328,16 @@ Network.NetworkLogView = class extends UI.VBox { |
| } |
| /** |
| - * @param {?Network.NetworkDataGridNode} node |
| + * @param {?Network.NetworkLogEntry} logEntry |
| * @return {number} |
| */ |
| - _updateMatchCountAndFindMatchIndex(node) { |
| - /** @type {!Array.<!Network.NetworkDataGridNode>} */ |
| - var nodes = this._dataGrid.rootNode().children; |
| + _updateMatchCountAndFindMatchIndex(logEntry) { |
| var matchCount = 0; |
| var matchIndex = 0; |
| - for (var i = 0; i < nodes.length; ++i) { |
| - if (!nodes[i][Network.NetworkLogView._isMatchingSearchQuerySymbol]) |
| + for (var item of this.flatenChildren()) { |
| + if (!item[Network.NetworkLogView._isMatchingSearchQuerySymbol]) |
| continue; |
| - if (node === nodes[i]) |
| + if (logEntry === item) |
| matchIndex = matchCount; |
| matchCount++; |
| } |
| @@ -1339,21 +1361,21 @@ Network.NetworkLogView = class extends UI.VBox { |
| * @return {boolean} |
| */ |
| _applyFilter(node) { |
| - var request = node.request(); |
| - if (this._timeFilter && !this._timeFilter(request)) |
| - return false; |
| - var categoryName = request.resourceType().category().title; |
| - if (!this._resourceCategoryFilterUI.accept(categoryName)) |
| - return false; |
| - if (this._dataURLFilterUI.checked() && request.parsedURL.isDataURL()) |
| - return false; |
| - if (request.statusText === 'Service Worker Fallback Required') |
| - return false; |
| - for (var i = 0; i < this._filters.length; ++i) { |
| - if (!this._filters[i](request)) |
| - return false; |
| + for (var request of node.requests()) { |
| + if (this._timeFilter && !this._timeFilter(request)) |
| + continue; |
| + var categoryName = request.resourceType().category().title; |
| + if (!this._resourceCategoryFilterUI.accept(categoryName)) |
| + continue; |
| + if (this._dataURLFilterUI.checked() && request.parsedURL.isDataURL()) |
| + continue; |
| + if (request.statusText === 'Service Worker Fallback Required') |
| + continue; |
| + if (this._filters.some(filter => !filter(request))) |
| + continue; |
| + return true; |
| } |
| - return true; |
| + return false; |
| } |
| /** |
| @@ -1494,7 +1516,7 @@ Network.NetworkLogView = class extends UI.VBox { |
| jumpToPreviousSearchResult() { |
| if (!this._matchedRequestCount) |
| return; |
| - var index = this._normalizeSearchResultIndex(this._currentMatchedRequestIndex - 1); |
| + var index = this._normalizeSearchResultIndex(this._currentMatchedLogEntryIndex - 1); |
| this._highlightNthMatchedRequestForSearch(index, true); |
| } |
| @@ -1504,7 +1526,7 @@ Network.NetworkLogView = class extends UI.VBox { |
| jumpToNextSearchResult() { |
| if (!this._matchedRequestCount) |
| return; |
| - var index = this._normalizeSearchResultIndex(this._currentMatchedRequestIndex + 1); |
| + var index = this._normalizeSearchResultIndex(this._currentMatchedLogEntryIndex + 1); |
| this._highlightNthMatchedRequestForSearch(index, true); |
| } |
| @@ -1546,11 +1568,11 @@ Network.NetworkLogView = class extends UI.VBox { |
| } |
| /** |
| - * @param {!SDK.NetworkRequest} request |
| * @param {string} platform |
| + * @param {!SDK.NetworkRequest} request |
| * @return {string} |
| */ |
| - _generateCurlCommand(request, platform) { |
| + _generateCurlCommand(platform, request) { |
| var command = ['curl']; |
| // These headers are derived from URL (except "version") and would be added by cURL anyway. |
| var ignoredHeaders = {'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1}; |