From 452e532b31bba0c0ecb377b30f38321d95113485 Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Sat, 29 Apr 2017 19:11:49 +0200 Subject: [PATCH] squash 'resources/unpacked/devtools' changes from 51d81804a..30ad697c3 30ad697c3 [Devtools] New structure and colorize rows for network products d46aaf6cb [Devtools][Regression] Fixed websocket frame selection loss on frame received fb9c65293 DevTools: Don't focus layers panel when it is shown ba5491035 Reland of DevTools: fix aggregated donut chart cache population (patchset #1 id:1 of https://codereview.chromium.org/2839083002/ ) ef9fa0f54 Revert of DevTools: Show screenshots on the main flamechart (patchset #3 id:40001 of https://codereview.chromium.org/2830343004/ ) a75caaee6 [DevTools] Host paint profiles in PaintProfilerModel 97e80248b DevTools: clicking in console messages should not jump to bottom git-subtree-dir: resources/unpacked/devtools git-subtree-split: 30ad697c30890ace750ad6a594e19087ec9d4582 --- BUILD.gn | 15 +- front_end/console/ConsoleView.js | 16 +- front_end/inspector.json | 4 +- front_end/layer_viewer/PaintProfilerView.js | 4 +- front_end/layers/LayerPaintProfilerView.js | 2 +- front_end/layers/LayerTreeModel.js | 40 +++-- front_end/layers/LayersPanel.js | 1 - front_end/network/NetworkDataGridNode.js | 120 +++++++------- front_end/network/NetworkGroupers.js | 90 +++++++++++ front_end/network/NetworkLogView.js | 76 +++++---- front_end/network/NetworkLogViewColumns.js | 93 +++-------- front_end/network/NetworkPanel.js | 34 +--- front_end/network/module.json | 18 ++- front_end/network/networkLogView.css | 23 +++ .../NetworkProductGroupLookup.js | 148 ------------------ front_end/network_group_lookup/module.json | 34 ---- .../product_registry/ProductNameForURL.js | 95 ----------- front_end/product_registry/ProductRegistry.js | 43 +++++ front_end/product_registry/module.json | 7 +- .../ProductRegistryData.js | 2 +- .../ProductRegistryImpl.js | 143 +++++++++++++++++ front_end/product_registry_impl/module.json | 18 +++ .../sha1/README.chromium | 0 .../sha1/sha1.js | 2 +- front_end/sdk/PaintProfiler.js | 73 +++++---- front_end/timeline/TimelineDetailsView.js | 13 +- front_end/timeline/TimelineEventOverview.js | 34 +++- .../TimelineFlameChartDataProvider.js | 96 +++--------- .../timeline/TimelinePaintProfilerView.js | 21 ++- front_end/timeline/TimelineUIUtils.js | 22 +-- .../timeline_model/TimelineFrameModel.js | 5 +- front_end/timeline_model/TracingLayerTree.js | 15 +- 32 files changed, 629 insertions(+), 678 deletions(-) create mode 100644 front_end/network/NetworkGroupers.js delete mode 100644 front_end/network_group_lookup/NetworkProductGroupLookup.js delete mode 100644 front_end/network_group_lookup/module.json delete mode 100644 front_end/product_registry/ProductNameForURL.js create mode 100644 front_end/product_registry/ProductRegistry.js rename front_end/{product_registry => product_registry_impl}/ProductRegistryData.js (99%) create mode 100644 front_end/product_registry_impl/ProductRegistryImpl.js create mode 100644 front_end/product_registry_impl/module.json rename front_end/{product_registry => product_registry_impl}/sha1/README.chromium (100%) rename front_end/{product_registry => product_registry_impl}/sha1/sha1.js (99%) diff --git a/BUILD.gn b/BUILD.gn index 2edd250da3..f350f94033 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -313,6 +313,7 @@ all_devtools_files = [ "front_end/network/networkLogView.css", "front_end/network/NetworkLogView.js", "front_end/network/NetworkLogViewColumns.js", + "front_end/network/NetworkGroupers.js", "front_end/network/networkManageCustomHeadersView.css", "front_end/network/NetworkManageCustomHeadersView.js", "front_end/network/NetworkOverview.js", @@ -339,8 +340,6 @@ all_devtools_files = [ "front_end/network_conditions/module.json", "front_end/network_conditions/NetworkConditionsSelector.js", "front_end/network_conditions/networkConditionsSettingsTab.css", - "front_end/network_group_lookup/module.json", - "front_end/network_group_lookup/NetworkProductGroupLookup.js", "front_end/network_log/HAREntry.js", "front_end/network_log/module.json", "front_end/network_log/NetworkLog.js", @@ -378,9 +377,11 @@ all_devtools_files = [ "front_end/platform/module.json", "front_end/platform/utilities.js", "front_end/product_registry/module.json", - "front_end/product_registry/ProductNameForURL.js", - "front_end/product_registry/ProductRegistryData.js", - "front_end/product_registry/sha1/sha1.js", + "front_end/product_registry/ProductRegistry.js", + "front_end/product_registry_impl/module.json", + "front_end/product_registry_impl/ProductRegistryImpl.js", + "front_end/product_registry_impl/ProductRegistryData.js", + "front_end/product_registry_impl/sha1/sha1.js", "front_end/profiler/BottomUpProfileDataGrid.js", "front_end/profiler/CPUProfileFlameChart.js", "front_end/profiler/CPUProfileView.js", @@ -870,6 +871,7 @@ generated_resources = [ "$resources_out_dir/network/network_module.js", "$resources_out_dir/object_ui/object_ui_module.js", "$resources_out_dir/perf_ui/perf_ui_module.js", + "$resources_out_dir/product_registry/product_registry_module.js", "$resources_out_dir/profiler/profiler_module.js", "$resources_out_dir/quick_open/quick_open_module.js", "$resources_out_dir/resources/resources_module.js", @@ -892,8 +894,7 @@ generated_remote_modules = [ "$resources_out_dir/cm_modes/cm_modes_module.js", "$resources_out_dir/emulated_devices/emulated_devices_module.js", "$resources_out_dir/gonzales/gonzales_module.js", - "$resources_out_dir/network_group_lookup/network_group_lookup_module.js", - "$resources_out_dir/product_registry/product_registry_module.js", + "$resources_out_dir/product_registry_impl/product_registry_impl_module.js", "$resources_out_dir/screencast/screencast_module.js", ] diff --git a/front_end/console/ConsoleView.js b/front_end/console/ConsoleView.js index be61b1a8bb..4b64e34195 100644 --- a/front_end/console/ConsoleView.js +++ b/front_end/console/ConsoleView.js @@ -307,12 +307,8 @@ Console.ConsoleView = class extends UI.VBox { * @override */ focus() { - if (this._prompt.hasFocus()) - return; - // Set caret position before setting focus in order to avoid scrolling - // by focus(). - this._prompt.moveCaretToEndOfPrompt(); - this._prompt.focus(); + if (!this._prompt.hasFocus()) + this._prompt.focus(); } /** @@ -666,8 +662,14 @@ Console.ConsoleView = class extends UI.VBox { */ _messagesClicked(event) { var targetElement = event.deepElementFromPoint(); - if (!targetElement || targetElement.isComponentSelectionCollapsed()) + + // Do not focus prompt if messages have selection. + if (!targetElement || targetElement.isComponentSelectionCollapsed()) { + var clickedOutsideMessageList = event.target === this._messagesElement; + if (clickedOutsideMessageList) + this._prompt.moveCaretToEndOfPrompt(); this.focus(); + } var groupMessage = event.target.enclosingNodeOrSelfWithClass('console-group-title'); if (!groupMessage) return; diff --git a/front_end/inspector.json b/front_end/inspector.json index 6977ad6e04..597a0bf3f4 100644 --- a/front_end/inspector.json +++ b/front_end/inspector.json @@ -17,11 +17,11 @@ { "name": "services", "type": "autostart" }, { "name": "elements", "condition": "!v8only" }, { "name": "network", "condition": "!v8only" }, - { "name": "network_group_lookup", "condition": "!v8only", "type": "remote" }, { "name": "sources" }, { "name": "timeline", "condition": "!v8only" }, { "name": "timeline_model", "condition": "!v8only" }, - { "name": "product_registry", "condition": "!v8only", "type": "remote" }, + { "name": "product_registry", "condition": "!v8only" }, + { "name": "product_registry_impl", "condition": "!v8only", "type": "remote" }, { "name": "profiler" }, { "name": "resources", "condition": "!v8only" }, { "name": "audits", "condition": "!v8only" }, diff --git a/front_end/layer_viewer/PaintProfilerView.js b/front_end/layer_viewer/PaintProfilerView.js index b2371364f1..e34c95c2c8 100644 --- a/front_end/layer_viewer/PaintProfilerView.js +++ b/front_end/layer_viewer/PaintProfilerView.js @@ -370,11 +370,9 @@ LayerViewer.PaintProfilerCommandLogView = class extends UI.ThrottledWidget { } /** - * @param {?SDK.Target} target * @param {!Array.} log */ - setCommandLog(target, log) { - this._target = target; + setCommandLog(log) { this._log = log; /** @type {!Map} */ this._treeItemCache = new Map(); diff --git a/front_end/layers/LayerPaintProfilerView.js b/front_end/layers/LayerPaintProfilerView.js index e6bb3244de..629ff48c44 100644 --- a/front_end/layers/LayerPaintProfilerView.js +++ b/front_end/layers/LayerPaintProfilerView.js @@ -34,7 +34,7 @@ Layers.LayerPaintProfilerView = class extends UI.SplitWidget { * @this {Layers.LayerPaintProfilerView} */ function setSnapshotAndLog(snapshot, log) { - this._logTreeView.setCommandLog(snapshot && snapshot.target(), log || []); + this._logTreeView.setCommandLog(log || []); this._paintProfilerView.setSnapshotAndLog(snapshot, log || [], null); if (snapshot) snapshot.release(); diff --git a/front_end/layers/LayerTreeModel.js b/front_end/layers/LayerTreeModel.js index b620d46627..c39653bb4c 100644 --- a/front_end/layers/LayerTreeModel.js +++ b/front_end/layers/LayerTreeModel.js @@ -34,7 +34,9 @@ Layers.LayerTreeModel = class extends SDK.SDKModel { constructor(target) { super(target); + this._layerTreeAgent = target.layerTreeAgent(); target.registerLayerTreeDispatcher(new Layers.LayerTreeDispatcher(this)); + this._paintProfilerModel = /** @type {!SDK.PaintProfilerModel} */ (target.model(SDK.PaintProfilerModel)); var resourceTreeModel = target.model(SDK.ResourceTreeModel); if (resourceTreeModel) { resourceTreeModel.addEventListener( @@ -48,7 +50,7 @@ Layers.LayerTreeModel = class extends SDK.SDKModel { if (!this._enabled) return; this._enabled = false; - this.target().layerTreeAgent().disable(); + this._layerTreeAgent.disable(); } enable() { @@ -61,8 +63,8 @@ Layers.LayerTreeModel = class extends SDK.SDKModel { _forceEnable() { this._lastPaintRectByLayerId = {}; if (!this._layerTree) - this._layerTree = new Layers.AgentLayerTree(this.target()); - this.target().layerTreeAgent().enable(); + this._layerTree = new Layers.AgentLayerTree(this); + this._layerTreeAgent.enable(); } /** @@ -134,10 +136,11 @@ Layers.LayerTreeModel.Events = { */ Layers.AgentLayerTree = class extends SDK.LayerTreeBase { /** - * @param {?SDK.Target} target + * @param {!Layers.LayerTreeModel} layerTreeModel */ - constructor(target) { - super(target); + constructor(layerTreeModel) { + super(layerTreeModel.target()); + this._layerTreeModel = layerTreeModel; } /** @@ -186,7 +189,7 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase { if (layer) layer._reset(layers[i]); else - layer = new Layers.AgentLayer(this.target(), layers[i]); + layer = new Layers.AgentLayer(this._layerTreeModel, layers[i]); this._layersById[layerId] = layer; var backendNodeId = layers[i].backendNodeId; if (backendNodeId) @@ -218,11 +221,11 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase { */ Layers.AgentLayer = class { /** - * @param {?SDK.Target} target + * @param {!Layers.LayerTreeModel} layerTreeModel * @param {!Protocol.LayerTree.Layer} layerPayload */ - constructor(target, layerPayload) { - this._target = target; + constructor(layerTreeModel, layerPayload) { + this._layerTreeModel = layerTreeModel; this._reset(layerPayload); } @@ -401,14 +404,9 @@ Layers.AgentLayer = class { * @param {function(!Array.)} callback */ requestCompositingReasons(callback) { - if (!this._target) { - callback([]); - return; - } - var wrappedCallback = Protocol.inspectorBackend.wrapClientCallback( callback, 'Protocol.LayerTree.reasonsForCompositingLayer(): ', undefined, []); - this._target.layerTreeAgent().compositingReasons(this.id(), wrappedCallback); + this._layerTreeModel._layerTreeAgent.compositingReasons(this.id(), wrappedCallback); } /** @@ -436,11 +434,11 @@ Layers.AgentLayer = class { * @return {!Array>} */ snapshots() { - var rect = {x: 0, y: 0, width: this.width(), height: this.height()}; - var promise = this._target.layerTreeAgent().makeSnapshot( - this.id(), (error, snapshotId) => error || !this._target ? - null : - {rect: rect, snapshot: new SDK.PaintProfilerSnapshot(this._target, snapshotId)}); + var promise = this._layerTreeModel._paintProfilerModel.makeSnapshot(this.id()).then(snapshot => { + if (!snapshot) + return null; + return {rect: {x: 0, y: 0, width: this.width(), height: this.height()}, snapshot: snapshot}; + }); return [promise]; } diff --git a/front_end/layers/LayersPanel.js b/front_end/layers/LayersPanel.js index 034b230faf..5fd204b6b0 100644 --- a/front_end/layers/LayersPanel.js +++ b/front_end/layers/LayersPanel.js @@ -81,7 +81,6 @@ Layers.LayersPanel = class extends UI.PanelWithSidebar { super.wasShown(); if (this._model) this._model.enable(); - this._layerTreeOutline.focus(); } /** diff --git a/front_end/network/NetworkDataGridNode.js b/front_end/network/NetworkDataGridNode.js index a602a1f046..5936f76efa 100644 --- a/front_end/network/NetworkDataGridNode.js +++ b/front_end/network/NetworkDataGridNode.js @@ -38,14 +38,10 @@ Network.NetworkNode = class extends DataGrid.SortableDataGridNode { constructor(parentView) { super({}); this._parentView = parentView; - /** @type {!Map} */ - this._columnExtensions = new Map(); this._isHovered = false; this._showingInitiatorChain = false; /** @type {?SDK.NetworkRequest} */ this._requestOrFirstKnownChildRequest = null; - /** @type {!Map} */ - this._columnIcons = new Map(); /** @type {?Common.Color} */ this._backgroundColor = null; } @@ -88,14 +84,6 @@ Network.NetworkNode = class extends DataGrid.SortableDataGridNode { return /** @type {string} */ (color.asString(Common.Color.Format.HEX)); } - /** - * @param {?Common.Color} color - */ - setBackgroundColor(color) { - this._backgroundColor = color; - this._updateBackgroundColor(); - } - _updateBackgroundColor() { var element = this.existingElement(); if (!element) @@ -142,13 +130,6 @@ Network.NetworkNode = class extends DataGrid.SortableDataGridNode { return this._parentView.rowHeight(); } - /** - * @param {!Map} columnExtensions - */ - setColumnExtensions(columnExtensions) { - this._columnExtensions = columnExtensions; - } - /** * @param {boolean} hovered * @param {boolean} showInitiatorChain @@ -350,6 +331,22 @@ Network.NetworkRequestNode = class extends Network.NetworkNode { return aRequest.indentityCompare(bRequest); } + /** + * @param {!ProductRegistry.Registry} productRegistry + * @param {!Network.NetworkNode} a + * @param {!Network.NetworkNode} b + * @return {number} + */ + static ProductComparator(productRegistry, a, b) { + var aRequest = a.request(); + var bRequest = b.request(); + if (!aRequest || !bRequest) + return !aRequest ? -1 : 1; + var aName = productRegistry.nameForUrl(aRequest.parsedURL) || ''; + var bName = productRegistry.nameForUrl(bRequest.parsedURL) || ''; + return aName.localeCompare(bName) || aRequest.indentityCompare(bRequest); + } + /** * @param {!Network.NetworkNode} a * @param {!Network.NetworkNode} b @@ -565,24 +562,6 @@ Network.NetworkRequestNode = class extends Network.NetworkNode { return aValue > bValue ? 1 : -1; } - /** - * @param {!Map} extensionsMap - * @param {string} extensionId - * @param {!Network.NetworkNode} a - * @param {!Network.NetworkNode} b - * @return {number} - */ - static ExtensionColumnComparator(extensionsMap, extensionId, a, b) { - var aRequest = a.requestOrFirstKnownChildRequest(); - var bRequest = b.requestOrFirstKnownChildRequest(); - if (!aRequest || !bRequest) - return !aRequest ? -1 : 1; - var instance = extensionsMap.get(extensionId); - if (!instance) - return aRequest.indentityCompare(bRequest); - return instance.requestComparator(aRequest, bRequest); - } - /** * @override */ @@ -706,20 +685,10 @@ Network.NetworkRequestNode = class extends Network.NetworkNode { element.classList.toggle('network-error-row', this._isFailed()); element.classList.toggle('network-navigation-row', this._isNavigationRequest); - for (var rowDecorator of this._parentView.rowDecorators()) - rowDecorator.decorate(this); super.createCells(element); this._updateBackgroundColor(); } - /** - * @param {string} columnId - * @param {!UI.Icon} icon - */ - setIconForColumn(columnId, icon) { - this._columnIcons.set(columnId, icon); - } - /** * @param {!Element} element * @param {string} text @@ -736,21 +705,18 @@ Network.NetworkRequestNode = class extends Network.NetworkNode { */ createCell(columnIdentifier) { var cell = this.createTD(columnIdentifier); - var icon = this._columnIcons.get(columnIdentifier); - if (icon) - cell.appendChild(icon); - // If the key exists but the value is null it means the extension instance has not resolved yet. - // The view controller will force all rows to update when extension is resolved. - if (this._columnExtensions.has(columnIdentifier)) { - var instance = this._columnExtensions.get(columnIdentifier); - if (instance) - this._setTextAndTitle(cell, instance.lookupColumnValue(this._request)); - return cell; - } switch (columnIdentifier) { case 'name': this._renderNameCell(cell); break; + case 'product': + if (!Runtime.experiments.isEnabled('networkGroupingRequests')) { + this._setTextAndTitle(cell, this._request.responseHeaderValue(columnIdentifier) || ''); + break; + } + if (this.request()) + ProductRegistry.instance().then(this._renderProductCell.bind(this, cell)); + break; case 'method': this._setTextAndTitle(cell, this._request.requestMethod); break; @@ -898,6 +864,42 @@ Network.NetworkRequestNode = class extends Network.NetworkNode { cell.title = this._request.url(); } + /** + * @param {!Element} cell + * @param {!ProductRegistry.Registry} productRegistry + */ + _renderProductCell(cell, productRegistry) { + var request = this.request(); + if (!request) + return; + var entry = productRegistry.entryForUrl(request.parsedURL); + if (!entry) + return; + this._setTextAndTitle(cell, entry.name); + if (entry.type !== null) { + var element = this.existingElement(); + if (!element) + return; + switch (entry.type) { + case 0: + this._backgroundColor = Common.Color.fromRGBA([224, 247, 250, .6]); + cell.classList.add('product-ad'); + break; + case 1: + this._backgroundColor = Common.Color.fromRGBA([255, 252, 225, .6]); + cell.classList.add('product-tracking'); + break; + case 2: + this._backgroundColor = Common.Color.fromRGBA([211, 253, 211, .6]); + cell.classList.add('product-cdn'); + break; + default: + this._backgroundColor = null; + } + this._updateBackgroundColor(); + } + } + /** * @param {!Element} cell */ @@ -1100,8 +1102,6 @@ Network.NetworkGroupNode = class extends Network.NetworkNode { */ createCell(columnIdentifier) { var cell = this.createTD(columnIdentifier); - if (this._columnExtensions.has(columnIdentifier)) - return cell; if (columnIdentifier === 'name') { var leftPadding = this.leftPadding ? this.leftPadding + 'px' : ''; cell.style.setProperty('padding-left', leftPadding); diff --git a/front_end/network/NetworkGroupers.js b/front_end/network/NetworkGroupers.js new file mode 100644 index 0000000000..3f78ea0c42 --- /dev/null +++ b/front_end/network/NetworkGroupers.js @@ -0,0 +1,90 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * @implements {Network.GroupLookupInterface} + */ +Network.ProductGrouper = class { + constructor() { + /** @type {?ProductRegistry.Registry} */ + this._productRegistry = null; + } + + /** + * @override + * @return {!Promise} + */ + initialize() { + return ProductRegistry.instance().then(productRegistry => this._productRegistry = productRegistry); + } + + /** + * @override + * @param {!SDK.NetworkRequest} request + * @return {?*} + */ + groupForRequest(request) { + if (!this._productRegistry) + return null; + var productName = this._productRegistry.nameForUrl(request.parsedURL); + if (!productName) + return null; + return productName; + } + + /** + * @override + * @param {!*} key + * @return {string} + */ + groupName(key) { + return /** @type {string} */ (key); + } +}; + +/** + * @implements {Network.GroupLookupInterface} + */ +Network.FrameGrouper = class { + constructor() { + /** @type {?ProductRegistry.Registry} */ + this._productRegistry = null; + } + + /** + * @override + * @return {!Promise} + */ + initialize() { + return ProductRegistry.instance().then(productRegistry => this._productRegistry = productRegistry); + } + + /** + * @override + * @param {!SDK.NetworkRequest} request + * @return {?*} + */ + groupForRequest(request) { + var resourceTreeModel = request.networkManager().target().model(SDK.ResourceTreeModel); + if (!resourceTreeModel) + return null; + var frame = resourceTreeModel.frameForId(request.frameId); + if (!frame || frame.isMainFrame()) + return null; + return frame; + } + + /** + * @override + * @param {!*} frameArg + * @return {string} + */ + groupName(frameArg) { + var frame = /** @type {!SDK.ResourceTreeFrame} */ (frameArg); + var entry = this._productRegistry ? this._productRegistry.entryForFrame(frame) : null; + if (entry) + return entry.name; + return (new Common.ParsedURL(frame.url)).host || frame.name || '