blob: 948f7e5f760d20c908c8b9873851d719c7750a6d [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';
8import * as UI from '../ui/ui.js';
9
10import {AffectedItem, AffectedResourcesView} from './AffectedResourcesView.js';
11import {AggregatedIssue} from './IssueAggregator.js'; // eslint-disable-line no-unused-vars
12import {IssueView} from './IssueView.js';
13
14export const UIStrings = {
15 /**
16 *@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.
17 */
18 cookie: 'cookie',
19 /**
20 *@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.
21 */
22 cookies: 'cookies',
23 /**
24 *@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.
25 */
26 name: 'Name',
27 /**
28 *@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
29 */
30 domain: 'Domain',
31 /**
32 *@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
33 */
34 path: 'Path',
35};
36const str_ = i18n.i18n.registerUIStrings('issues/AffectedCookiesView.ts', UIStrings);
37const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
38
39export class AffectedCookiesView extends AffectedResourcesView {
40 private issue: AggregatedIssue;
41 constructor(parent: IssueView, issue: AggregatedIssue) {
42 super(parent, {singular: i18nString(UIStrings.cookie), plural: i18nString(UIStrings.cookies)});
43 this.issue = issue;
44 }
45
46 private appendAffectedCookies(cookies: Iterable<{cookie: Protocol.Audits.AffectedCookie, hasRequest: boolean}>):
47 void {
48 const header = document.createElement('tr');
49 this.appendColumnTitle(header, i18nString(UIStrings.name));
50 this.appendColumnTitle(
51 header, i18nString(UIStrings.domain) + ' & ' + i18nString(UIStrings.path),
52 'affected-resource-cookie-info-header');
53
54 this.affectedResources.appendChild(header);
55
56 let count = 0;
57 for (const cookie of cookies) {
58 count++;
59 this.appendAffectedCookie(cookie.cookie, cookie.hasRequest);
60 }
61 this.updateAffectedResourceCount(count);
62 }
63
64 private appendAffectedCookie(cookie: Protocol.Audits.AffectedCookie, hasAssociatedRequest: boolean): void {
65 const element = document.createElement('tr');
66 element.classList.add('affected-resource-cookie');
67 const name = document.createElement('td');
68 if (hasAssociatedRequest) {
69 name.appendChild(UI.UIUtils.createTextButton(cookie.name, () => {
70 Host.userMetrics.issuesPanelResourceOpened(this.issue.getCategory(), AffectedItem.Cookie);
71 Network.NetworkPanel.NetworkPanel.revealAndFilter([
72 {
73 filterType: 'cookie-domain',
74 filterValue: cookie.domain,
75 },
76 {
77 filterType: 'cookie-name',
78 filterValue: cookie.name,
79 },
80 {
81 filterType: 'cookie-path',
82 filterValue: cookie.path,
83 },
84 ]);
85 }, 'link-style devtools-link'));
86 } else {
87 name.textContent = cookie.name;
88 }
89 element.appendChild(name);
90 this.appendIssueDetailCell(element, `${cookie.domain}${cookie.path}`, 'affected-resource-cookie-info');
91
92 this.affectedResources.appendChild(element);
93 }
94
95 update(): void {
96 this.clear();
97 this.appendAffectedCookies(this.issue.cookiesWithRequestIndicator());
98 }
99}