Skip to content

Commit 4234825

Browse files
Andrew PaseltinerDevtools-frontend LUCI CQ
authored andcommitted
Add column to indicate whether network request is ad-related
This is a boolean column that is hidden by default. Bug: 443993633 Change-Id: Ib9dcbdf08eceb06a195eaf58b588a99900132fc0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6976286 Reviewed-by: Adriana Ixba <aixba@chromium.org> Commit-Queue: Andrew Paseltiner <apaseltiner@chromium.org>
1 parent 829391b commit 4234825

5 files changed

Lines changed: 43 additions & 0 deletions

File tree

front_end/core/sdk/NetworkManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ export class NetworkDispatcher implements ProtocolProxyApi.NetworkDispatcher {
597597
networkRequest.mixedContentType = request.mixedContentType || Protocol.Security.MixedContentType.None;
598598
networkRequest.setReferrerPolicy(request.referrerPolicy);
599599
networkRequest.setIsSameSite(request.isSameSite || false);
600+
networkRequest.setIsAdRelated(request.isAdRelated || false);
600601
}
601602

602603
private updateNetworkRequestWithResponse(networkRequest: NetworkRequest, response: Protocol.Network.Response): void {

front_end/core/sdk/NetworkRequest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export class NetworkRequest extends Common.ObjectWrapper.ObjectWrapper<EventType
320320
directSocketInfo?: DirectSocketInfo;
321321
readonly #directSocketChunks: DirectSocketChunk[] = [];
322322
#isIpProtectionUsed: boolean;
323+
#isAdRelated: boolean;
323324

324325
constructor(
325326
requestId: string,
@@ -342,6 +343,7 @@ export class NetworkRequest extends Common.ObjectWrapper.ObjectWrapper<EventType
342343
this.#initiator = initiator;
343344
this.#hasUserGesture = hasUserGesture;
344345
this.#isIpProtectionUsed = false;
346+
this.#isAdRelated = false;
345347
}
346348

347349
static create(
@@ -1850,6 +1852,14 @@ export class NetworkRequest extends Common.ObjectWrapper.ObjectWrapper<EventType
18501852
return this.#isIpProtectionUsed;
18511853
}
18521854

1855+
setIsAdRelated(isAdRelated: boolean): void {
1856+
this.#isAdRelated = isAdRelated;
1857+
}
1858+
1859+
isAdRelated(): boolean {
1860+
return this.#isAdRelated;
1861+
}
1862+
18531863
getAssociatedData(key: string): object|null {
18541864
return this.#associatedData.get(key) || null;
18551865
}

front_end/panels/network/NetworkDataGridNode.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,24 @@ export class NetworkRequestNode extends NetworkNode {
771771
return aScore - bScore || aRequest.identityCompare(bRequest);
772772
}
773773

774+
static IsAdRelatedComparator(a: NetworkNode, b: NetworkNode): number {
775+
// TODO(allada) Handle this properly for group nodes.
776+
const aRequest = a.requestOrFirstKnownChildRequest();
777+
const bRequest = b.requestOrFirstKnownChildRequest();
778+
if (!aRequest || !bRequest) {
779+
return !aRequest ? -1 : 1;
780+
}
781+
const aIsAdRelated = aRequest.isAdRelated();
782+
const bIsAdRelated = bRequest.isAdRelated();
783+
if (aIsAdRelated > bIsAdRelated) {
784+
return 1;
785+
}
786+
if (bIsAdRelated > aIsAdRelated) {
787+
return -1;
788+
}
789+
return aRequest.identityCompare(bRequest);
790+
}
791+
774792
static RequestPropertyComparator(propertyName: string, a: NetworkNode, b: NetworkNode): number {
775793
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
776794
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1038,6 +1056,10 @@ export class NetworkRequestNode extends NetworkNode {
10381056
this.renderAddressSpaceCell(cell, this.requestInternal.remoteAddressSpace());
10391057
break;
10401058
}
1059+
case 'is-ad-related': {
1060+
this.setTextAndTitle(cell, this.requestInternal.isAdRelated().toLocaleString());
1061+
break;
1062+
}
10411063
case 'cookies': {
10421064
this.setTextAndTitle(cell, this.arrayLength(this.requestInternal.includedRequestCookies()));
10431065
break;

front_end/panels/network/NetworkLogViewColumns.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ const UIStrings = {
148148
* @description Text in Network Log View Columns of the Network panel
149149
*/
150150
remoteAddressSpace: 'Remote Address Space',
151+
/**
152+
* @description Text to show whether a request is ad-related
153+
*/
154+
isAdRelated: 'Is Ad-Related',
151155
} as const;
152156
const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogViewColumns.ts', UIStrings);
153157
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -1183,6 +1187,11 @@ const DEFAULT_COLUMNS = [
11831187
title: i18n.i18n.lockedLazyString('User-Agent'),
11841188
sortingFunction: NetworkRequestNode.RequestHeaderStringComparator.bind(null, 'user-agent'),
11851189
},
1190+
{
1191+
id: 'is-ad-related',
1192+
title: i18nLazyString(UIStrings.isAdRelated),
1193+
sortingFunction: NetworkRequestNode.IsAdRelatedComparator,
1194+
},
11861195
// This header is a placeholder to let datagrid know that it can be sorted by this column, but never shown.
11871196
{
11881197
id: 'waterfall',

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,7 @@ export const knownContextValues = new Set([
19341934
'invert-filter',
19351935
'ip-protection',
19361936
'is',
1937+
'is-ad-related',
19371938
'is-landscape',
19381939
'is-mobile',
19391940
'is-resident-credential',

0 commit comments

Comments
 (0)