Skip to content

Commit f8a58ef

Browse files
masnobleDevtools-frontend LUCI CQ
authored andcommitted
Add Cookie Impact Report view to the SecurityPanel
This adds the basic report to the panel. Strings are subject to change. There will also be a follow-up CL that will add the dataGrid and data retrieval: https://crrev.com/c/5980008 https://screenshot.googleplex.com/4Nf7KpTpW4ftfme.png Bug: 365737493 Change-Id: If850ec0002164fc0f261f492b4a85001c1d9eb7f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5937413 Reviewed-by: Shuran Huang <[email protected]> Commit-Queue: Joshua Thomas <[email protected]> Reviewed-by: Kim-Anh Tran <[email protected]>
1 parent 468cf96 commit f8a58ef

File tree

7 files changed

+183
-11
lines changed

7 files changed

+183
-11
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,11 +1673,13 @@ grd_files_debug_sources = [
16731673
"front_end/panels/search/searchResultsPane.css.js",
16741674
"front_end/panels/search/searchView.css.js",
16751675
"front_end/panels/security/CookieReportTreeElement.js",
1676+
"front_end/panels/security/CookieReportView.js",
16761677
"front_end/panels/security/OriginTreeElement.js",
16771678
"front_end/panels/security/SecurityModel.js",
16781679
"front_end/panels/security/SecurityPanel.js",
16791680
"front_end/panels/security/SecurityPanelSidebar.js",
16801681
"front_end/panels/security/SecurityPanelSidebarTreeElement.js",
1682+
"front_end/panels/security/cookieReportView.css.js",
16811683
"front_end/panels/security/lockIcon.css.js",
16821684
"front_end/panels/security/mainView.css.js",
16831685
"front_end/panels/security/originView.css.js",

front_end/panels/security/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import("../visibility.gni")
1010

1111
generate_css("css_files") {
1212
sources = [
13+
"cookieReportView.css",
1314
"lockIcon.css",
1415
"mainView.css",
1516
"originView.css",
@@ -20,6 +21,7 @@ generate_css("css_files") {
2021
devtools_module("security") {
2122
sources = [
2223
"CookieReportTreeElement.ts",
24+
"CookieReportView.ts",
2325
"OriginTreeElement.ts",
2426
"SecurityModel.ts",
2527
"SecurityPanel.ts",

front_end/panels/security/CookieReportTreeElement.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@ import * as IconButton from '../../ui/components/icon_button/icon_button.js';
55

66
import {SecurityPanelSidebarTreeElement} from './SecurityPanelSidebarTreeElement.js';
77

8-
export class ShowCookieReportEvent extends Event {
9-
static readonly eventName = 'showcookiereport';
10-
11-
constructor() {
12-
super(ShowCookieReportEvent.eventName, {bubbles: true, composed: true});
13-
}
14-
}
15-
168
export class CookieReportTreeElement extends SecurityPanelSidebarTreeElement {
179
constructor(title: string) {
1810
super(title);
1911
this.setLeadingIcons([IconButton.Icon.create('cookie', 'cookie-icon')]);
2012
}
2113

2214
override onselect(): boolean {
23-
this.listItemElement.dispatchEvent(new ShowCookieReportEvent());
15+
this.listItemElement.dispatchEvent(new CustomEvent('showCookieReport', {bubbles: true, composed: true}));
2416
return true;
2517
}
2618
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2024 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import * as i18n from '../../core/i18n/i18n.js';
6+
import * as UI from '../../ui/legacy/legacy.js';
7+
import * as LitHtml from '../../ui/lit-html/lit-html.js';
8+
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
9+
10+
import cookieReportViewStyles from './cookieReportView.css.js';
11+
12+
const {render, html, Directives: {ref}} = LitHtml;
13+
14+
const UIStrings = {
15+
/**
16+
*@description Title in the header for the third-party cookie report in the Security & Privacy Panel
17+
*/
18+
title: 'Third-party cookies',
19+
/**
20+
*@description Explaination in the header about the cookies listed in the report
21+
*/
22+
body:
23+
'Third-party cookies that might be restricted by users, depending on their settings. If a user chooses to restrict cookies, then this site might not work for them.',
24+
/**
25+
*@description A link the user can follow to learn more about third party cookie usage
26+
*/
27+
learnMoreLink: 'Learn more about how third-party cookies are used',
28+
/**
29+
*@description Status string in the cookie report for a third-party cookie that is allowed without any sort of exception. This is also used as filter chip text to allow the user to filter the table based on cookie status
30+
*/
31+
allowed: 'Allowed',
32+
/**
33+
*@description Status string in the cookie report for a third-party cookie that is allowed due to a grace period or heuristic exception. Otherwise, this would have been blocked. This is also used as filter chip text to allow the user to filter the table based on cookie status
34+
*/
35+
allowedByException: 'Allowed By Exception',
36+
/**
37+
*@description Status string in the cookie report for a third-party cookie that was blocked. This is also used as filter chip text to allow the user to filter the table based on cookie status
38+
*/
39+
blocked: 'Blocked',
40+
};
41+
const str_ = i18n.i18n.registerUIStrings('panels/security/CookieReportView.ts', UIStrings);
42+
export const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
43+
44+
export interface ViewInput {}
45+
export interface ViewOutput {
46+
namedBitSetFilterUI?: UI.FilterBar.NamedBitSetFilterUI;
47+
}
48+
49+
export interface CookieReportNodeData {
50+
name: string;
51+
domain: string;
52+
type: string;
53+
platform: string;
54+
status: string;
55+
recommendation: string;
56+
}
57+
58+
export type View = (input: ViewInput, output: ViewOutput, target: HTMLElement) => void;
59+
60+
const filterItems: UI.FilterBar.Item[] = [
61+
{
62+
name: UIStrings.blocked,
63+
label: () => i18nString(UIStrings.blocked),
64+
title: UIStrings.blocked,
65+
jslogContext: UIStrings.blocked,
66+
},
67+
{
68+
name: UIStrings.allowed,
69+
label: () => i18nString(UIStrings.allowed),
70+
title: UIStrings.allowed,
71+
jslogContext: UIStrings.allowed,
72+
},
73+
{
74+
name: UIStrings.allowedByException,
75+
label: () => i18nString(UIStrings.allowedByException),
76+
title: UIStrings.allowedByException,
77+
jslogContext: UIStrings.allowedByException,
78+
},
79+
];
80+
81+
export class CookieReportView extends UI.Widget.VBox {
82+
namedBitSetFilterUI?: UI.FilterBar.NamedBitSetFilterUI;
83+
#view: View;
84+
85+
constructor(element?: HTMLElement, view: View = (input, output, target) => {
86+
// clang-format off
87+
render(html `
88+
<div class="report overflow-auto">
89+
<div class="header">
90+
<div class="title">${i18nString(UIStrings.title)}</div>
91+
<div class="body">${i18nString(UIStrings.body)} <x-link class="x-link" href="https://developers.google.com/privacy-sandbox/cookies/prepare/audit-cookies" jslog=${VisualLogging.link('learn-more').track({click: true})}>${i18nString(UIStrings.learnMoreLink)}</x-link></div>
92+
</div>
93+
<devtools-named-bit-set-filter
94+
class="filter"
95+
.options=${{items: filterItems}}
96+
${ref((el?: Element) => {
97+
if(el instanceof UI.FilterBar.NamedBitSetFilterUIElement){
98+
output.namedBitSetFilterUI = el.getOrCreateNamedBitSetFilterUI();
99+
}
100+
})}
101+
></devtools-named-bit-set-filter>
102+
</div>
103+
`, target, {host: this});
104+
// clang-format on
105+
}) {
106+
super(true, undefined, element);
107+
this.#view = view;
108+
109+
this.doUpdate();
110+
}
111+
112+
doUpdate(): void {
113+
this.#view(this, this, this.contentElement);
114+
}
115+
116+
override wasShown(): void {
117+
super.wasShown();
118+
this.registerCSSFiles([cookieReportViewStyles]);
119+
}
120+
}

front_end/panels/security/SecurityPanel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as UI from '../../ui/legacy/legacy.js';
1414
import * as LitHtml from '../../ui/lit-html/lit-html.js';
1515
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
1616

17+
import {CookieReportView} from './CookieReportView.js';
1718
import lockIconStyles from './lockIcon.css.js';
1819
import mainViewStyles from './mainView.css.js';
1920
import {ShowOriginEvent} from './OriginTreeElement.js';
@@ -534,6 +535,7 @@ export type ViewInput = {
534535
panel: SecurityPanel,
535536
};
536537
export type ViewOutput = {
538+
setVisibleView: (view: UI.Widget.VBox) => void,
537539
splitWidget: UI.SplitWidget.SplitWidget,
538540
mainView: SecurityMainView,
539541
visibleView: UI.Widget.VBox|null,
@@ -560,7 +562,7 @@ export class SecurityPanel extends UI.Panel.Panel implements SDK.TargetManager.S
560562
<devtools-split-widget
561563
.options=${{vertical: true, settingName: 'security'}}
562564
${UI.Widget.widgetRef(UI.SplitWidget.SplitWidget, e => {output.splitWidget = e;})}>
563-
<devtools-widget
565+
<devtools-widget
564566
slot="main"
565567
.widgetClass=${SecurityMainView}
566568
.widgetParams=${[input.panel] as SecurityMainViewProps}
@@ -569,6 +571,7 @@ export class SecurityPanel extends UI.Panel.Panel implements SDK.TargetManager.S
569571
<devtools-widget
570572
slot="sidebar"
571573
.widgetClass=${SecurityPanelSidebar}
574+
@showCookieReport=${()=>output.setVisibleView(new CookieReportView())}
572575
${UI.Widget.widgetRef(SecurityPanelSidebar, e => {output.sidebar = e;})}>
573576
</devtools-widget>
574577
</devtools-split-widget>`,
@@ -654,6 +657,7 @@ export class SecurityPanel extends UI.Panel.Panel implements SDK.TargetManager.S
654657
// The sidebar element will trigger displaying the main view. Rather than making a redundant call to display the main view, we rely on this.
655658
this.sidebar.securityOverviewElement.select(true);
656659
}
660+
657661
showOrigin(origin: Platform.DevToolsPath.UrlString): void {
658662
const originState = this.origins.get(origin);
659663
if (!originState) {
@@ -821,7 +825,9 @@ export class SecurityPanel extends UI.Panel.Panel implements SDK.TargetManager.S
821825
const {frame} = event.data;
822826
const request = this.lastResponseReceivedForLoaderId.get(frame.loaderId);
823827

824-
this.selectAndSwitchToMainView();
828+
if (!(this.visibleView instanceof CookieReportView)) {
829+
this.selectAndSwitchToMainView();
830+
}
825831
this.sidebar.clearOrigins();
826832
this.origins.clear();
827833
this.lastResponseReceivedForLoaderId.clear();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2024 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
7+
.report {
8+
display: flex;
9+
flex-direction: column;
10+
width: 100%;
11+
height: 100%;
12+
max-height: 100%;
13+
gap: var(--sys-size-6);
14+
padding-top: var(--sys-size-5);
15+
padding-bottom: var(--sys-size-5);
16+
}
17+
18+
.header {
19+
display: flex;
20+
flex-direction: column;
21+
flex-shrink: 0;
22+
gap: var(--sys-size-5);
23+
padding-left: var(--sys-size-6);
24+
padding-right: var(--sys-size-6);
25+
min-width: var(--sys-size-31);
26+
27+
.title {
28+
font: var(--sys-typescale-headline4);
29+
}
30+
31+
.body {
32+
font: var(--sys-typescale-body4-regular);
33+
}
34+
}
35+
36+
.x-link {
37+
color: var(--sys-color-primary);
38+
text-decoration-line: underline;
39+
cursor: pointer;
40+
}
41+
42+
.filter {
43+
padding-left: var(--sys-size-5);
44+
padding-right: var(--sys-size-6);
45+
flex-shrink: 0;
46+
}

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,15 @@ export const knownContextValues = new Set([
211211
'75%',
212212
'8',
213213
'9',
214+
'Allowed By Exception',
215+
'Allowed',
216+
'AllowedByException',
214217
'ArrowDown',
215218
'ArrowLeft',
216219
'ArrowRight',
217220
'ArrowUp',
218221
'Backspace',
222+
'Blocked',
219223
'CSS',
220224
'CoLoR',
221225
'Delete',

0 commit comments

Comments
 (0)