blob: 117c0656921bffe13e0554a1dec45d645741d26b [file] [log] [blame]
Sigurd Schneidera86d1162021-02-16 12:20:291// Copyright 2021 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
5import * as Host from '../host/host.js';
6import * as i18n from '../i18n/i18n.js';
7import * as Network from '../network/network.js';
pradhuman1c51536c2021-03-16 07:53:478import * as Platform from '../platform/platform.js';
Sigurd Schneidera86d1162021-02-16 12:20:299import * as UI from '../ui/ui.js';
10
11import {AffectedItem, AffectedResourcesView} from './AffectedResourcesView.js';
Tim van der Lippebfbb58f2021-02-25 17:34:1912import type {AggregatedIssue} from './IssueAggregator.js';
Sigurd Schneidera86d1162021-02-16 12:20:2913import {IssueView} from './IssueView.js';
14
Simon Zünd6f95e842021-03-01 07:41:5515const UIStrings = {
Sigurd Schneidera86d1162021-02-16 12:20:2916 /**
pradhuman1c51536c2021-03-16 07:53:4717 *@description Noun, singular or plural. Label for the kind and number of affected resources associated with a DevTools issue. A cookie is a small piece of data that a server sends to the user's web browser. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies.
18 */
19 nCookies: '{n, plural, =1 { cookie} other { cookies}}',
20 /**
Sigurd Schneidera86d1162021-02-16 12:20:2921 *@description Noun, singular. Label for the kind and number of affected resources associated with a DevTools issue. A cookie is a small piece of data that a server sends to the user's web browser. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies.
22 */
23 cookie: 'cookie',
24 /**
25 *@description Noun, plural. Label for the kind and number of affected resources associated with a DevTools issue. A cookie is a small piece of data that a server sends to the user's web browser. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies.
26 */
27 cookies: 'cookies',
28 /**
29 *@description Noun, singular. Label for a column in a table which lists cookies in the affected resources section of a DevTools issue. Each cookie has a name.
30 */
31 name: 'Name',
32 /**
33 *@description Noun, singular. Label for a column in a table which lists cookies in the affected resources section of a DevTools issue. Cookies may have a 'Domain' attribute: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies.#define_where_cookies_are_sent
34 */
35 domain: 'Domain',
36 /**
37 *@description Noun, singular. Label for a column in a table which lists cookies in the affected resources section of a DevTools issue. Cookies may have a 'Path' attribute: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies.#define_where_cookies_are_sent
38 */
39 path: 'Path',
40};
41const str_ = i18n.i18n.registerUIStrings('issues/AffectedCookiesView.ts', UIStrings);
42const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
43
44export class AffectedCookiesView extends AffectedResourcesView {
45 private issue: AggregatedIssue;
46 constructor(parent: IssueView, issue: AggregatedIssue) {
47 super(parent, {singular: i18nString(UIStrings.cookie), plural: i18nString(UIStrings.cookies)});
48 this.issue = issue;
49 }
50
pradhuman1c51536c2021-03-16 07:53:4751 protected getResourceName(count: number): Platform.UIString.LocalizedString {
52 return i18nString(UIStrings.nCookies, {n: count});
53 }
54
Sigurd Schneidera86d1162021-02-16 12:20:2955 private appendAffectedCookies(cookies: Iterable<{cookie: Protocol.Audits.AffectedCookie, hasRequest: boolean}>):
56 void {
57 const header = document.createElement('tr');
58 this.appendColumnTitle(header, i18nString(UIStrings.name));
59 this.appendColumnTitle(
60 header, i18nString(UIStrings.domain) + ' & ' + i18nString(UIStrings.path),
61 'affected-resource-cookie-info-header');
62
63 this.affectedResources.appendChild(header);
64
65 let count = 0;
66 for (const cookie of cookies) {
67 count++;
68 this.appendAffectedCookie(cookie.cookie, cookie.hasRequest);
69 }
70 this.updateAffectedResourceCount(count);
71 }
72
73 private appendAffectedCookie(cookie: Protocol.Audits.AffectedCookie, hasAssociatedRequest: boolean): void {
74 const element = document.createElement('tr');
75 element.classList.add('affected-resource-cookie');
76 const name = document.createElement('td');
77 if (hasAssociatedRequest) {
78 name.appendChild(UI.UIUtils.createTextButton(cookie.name, () => {
79 Host.userMetrics.issuesPanelResourceOpened(this.issue.getCategory(), AffectedItem.Cookie);
80 Network.NetworkPanel.NetworkPanel.revealAndFilter([
81 {
Jan Schefflerd6c1d402021-02-26 16:56:3882 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
83 // @ts-expect-error
Sigurd Schneidera86d1162021-02-16 12:20:2984 filterType: 'cookie-domain',
85 filterValue: cookie.domain,
86 },
87 {
Jan Schefflerd6c1d402021-02-26 16:56:3888 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
89 // @ts-expect-error
Sigurd Schneidera86d1162021-02-16 12:20:2990 filterType: 'cookie-name',
91 filterValue: cookie.name,
92 },
93 {
Jan Schefflerd6c1d402021-02-26 16:56:3894 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
95 // @ts-expect-error
Sigurd Schneidera86d1162021-02-16 12:20:2996 filterType: 'cookie-path',
97 filterValue: cookie.path,
98 },
99 ]);
100 }, 'link-style devtools-link'));
101 } else {
102 name.textContent = cookie.name;
103 }
104 element.appendChild(name);
105 this.appendIssueDetailCell(element, `${cookie.domain}${cookie.path}`, 'affected-resource-cookie-info');
106
107 this.affectedResources.appendChild(element);
108 }
109
110 update(): void {
111 this.clear();
112 this.appendAffectedCookies(this.issue.cookiesWithRequestIndicator());
113 }
114}