Files
react-native-devtools-frontend/front_end/network/NetworkFrameGrouper.js
T
Tim van der Lippe 70842f313f Replace title property setter with Tooltip install invocation
ui/Tooltip.js overrides the HTMLElement prototype to override the
title property. Rather than using this property, we shoul be
calling Tooltip.install directly. This makes sure that new
components are not relying on the behavior of the legacy
prototype patching.

These usages have been manually audited using the following regexes:

Search: ([\S]+)\.title = ([^;]+);
Replace: UI.Tooltip.Tooltip.install($1, $2);

Note that there are classes in DevTools that also have a title
property. Most notably `TreeElement`. We should not be replacing
these, as they do not inherit from HTMLElement. Luckily, we are
running TypeScript to make sure we don't call `Tooltip.install`
with a non-HTMLElement.

A follow-up CL will clean up the getters.

R=jacktfranklin@chromium.org

Bug: 1150762
No-presubmit: True
Change-Id: I5928e75c70293531849e0576f4fb2a2a8b3e02d2
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2555060
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
2020-11-23 17:16:46 +00:00

88 lines
2.5 KiB
JavaScript

// 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.
import * as Common from '../common/common.js';
import * as DataGrid from '../data_grid/data_grid.js'; // eslint-disable-line no-unused-vars
import * as SDK from '../sdk/sdk.js';
import * as UI from '../ui/ui.js';
import {NetworkGroupNode} from './NetworkDataGridNode.js';
import {GroupLookupInterface, NetworkLogView} from './NetworkLogView.js'; // eslint-disable-line no-unused-vars
/**
* @implements {GroupLookupInterface}
*/
export class NetworkFrameGrouper {
/**
* @param {!NetworkLogView} parentView
*/
constructor(parentView) {
this._parentView = parentView;
/** @type {!Map<!SDK.ResourceTreeModel.ResourceTreeFrame, !FrameGroupNode>} */
this._activeGroups = new Map();
}
/**
* @override
* @param {!SDK.NetworkRequest.NetworkRequest} request
* @return {?NetworkGroupNode}
*/
groupNodeForRequest(request) {
const frame = SDK.ResourceTreeModel.ResourceTreeModel.frameForRequest(request);
if (!frame || frame.isTopFrame()) {
return null;
}
let groupNode = this._activeGroups.get(frame);
if (groupNode) {
return groupNode;
}
groupNode = new FrameGroupNode(this._parentView, frame);
this._activeGroups.set(frame, groupNode);
return groupNode;
}
/**
* @override
*/
reset() {
this._activeGroups.clear();
}
}
export class FrameGroupNode extends NetworkGroupNode {
/**
* @param {!NetworkLogView} parentView
* @param {!SDK.ResourceTreeModel.ResourceTreeFrame} frame
*/
constructor(parentView, frame) {
super(parentView);
this._frame = frame;
}
/**
* @override
*/
displayName() {
return new Common.ParsedURL.ParsedURL(this._frame.url).domain() || this._frame.name || '<iframe>';
}
/**
* @override
* @param {!Element} cell
* @param {string} columnId
*/
renderCell(/** @type {!HTMLElement} */ cell, columnId) {
super.renderCell(cell, columnId);
const columnIndex =
/** @type {!DataGrid.DataGrid.DataGridImpl<?>} */ (this.dataGrid).indexOfVisibleColumn(columnId);
if (columnIndex === 0) {
const name = this.displayName();
cell.appendChild(UI.Icon.Icon.create('largeicon-navigator-frame', 'network-frame-group-icon'));
UI.UIUtils.createTextChild(cell, name);
UI.Tooltip.Tooltip.install(cell, name);
this.setCellAccessibleName(cell.textContent || '', cell, columnId);
}
}
}