blob: 165e477a6d0e63354b4bd56506d709d6ef451a70 [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
Tim van der Lippefe58ef22021-04-19 10:48:555import * as Host from '../../core/host/host.js';
6import * as i18n from '../../core/i18n/i18n.js';
7import * as Platform from '../../core/platform/platform.js';
8import * as UI from '../../ui/legacy/legacy.js';
9import * as Network from '../network/network.js';
Sigurd Schneidera86d1162021-02-16 12:20:2910
11import {AffectedItem, AffectedResourcesView} from './AffectedResourcesView.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2712
Tim van der Lippebfbb58f2021-02-25 17:34:1913import type {AggregatedIssue} from './IssueAggregator.js';
Sigurd Schneidera86d1162021-02-16 12:20:2914import {IssueView} from './IssueView.js';
15
Simon Zünd6f95e842021-03-01 07:41:5516const UIStrings = {
Sigurd Schneidera86d1162021-02-16 12:20:2917 /**
pradhuman1c51536c2021-03-16 07:53:4718 *@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.
19 */
Wolfgang Beyer40834922021-05-10 08:34:2220 nCookies: '{n, plural, =1 {# cookie} other {# cookies}}',
pradhuman1c51536c2021-03-16 07:53:4721 /**
Sigurd Schneidera86d1162021-02-16 12:20:2922 *@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.
23 */
24 name: 'Name',
25 /**
26 *@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
27 */
28 domain: 'Domain',
29 /**
30 *@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
31 */
32 path: 'Path',
33};
Tim van der Lippefe58ef22021-04-19 10:48:5534const str_ = i18n.i18n.registerUIStrings('panels/issues/AffectedCookiesView.ts', UIStrings);
Sigurd Schneidera86d1162021-02-16 12:20:2935const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
36
37export class AffectedCookiesView extends AffectedResourcesView {
38 private issue: AggregatedIssue;
39 constructor(parent: IssueView, issue: AggregatedIssue) {
pradhuman1663bf9a2021-04-09 15:01:2240 super(parent);
Sigurd Schneidera86d1162021-02-16 12:20:2941 this.issue = issue;
42 }
43
Wolfgang Beyer40834922021-05-10 08:34:2244 protected getResourceNameWithCount(count: number): Platform.UIString.LocalizedString {
pradhuman1c51536c2021-03-16 07:53:4745 return i18nString(UIStrings.nCookies, {n: count});
46 }
47
Sigurd Schneidera86d1162021-02-16 12:20:2948 private appendAffectedCookies(cookies: Iterable<{cookie: Protocol.Audits.AffectedCookie, hasRequest: boolean}>):
49 void {
50 const header = document.createElement('tr');
51 this.appendColumnTitle(header, i18nString(UIStrings.name));
52 this.appendColumnTitle(
53 header, i18nString(UIStrings.domain) + ' & ' + i18nString(UIStrings.path),
54 'affected-resource-cookie-info-header');
55
56 this.affectedResources.appendChild(header);
57
58 let count = 0;
59 for (const cookie of cookies) {
60 count++;
61 this.appendAffectedCookie(cookie.cookie, cookie.hasRequest);
62 }
63 this.updateAffectedResourceCount(count);
64 }
65
66 private appendAffectedCookie(cookie: Protocol.Audits.AffectedCookie, hasAssociatedRequest: boolean): void {
67 const element = document.createElement('tr');
68 element.classList.add('affected-resource-cookie');
69 const name = document.createElement('td');
70 if (hasAssociatedRequest) {
71 name.appendChild(UI.UIUtils.createTextButton(cookie.name, () => {
72 Host.userMetrics.issuesPanelResourceOpened(this.issue.getCategory(), AffectedItem.Cookie);
73 Network.NetworkPanel.NetworkPanel.revealAndFilter([
74 {
Simon Zünd92f35f52021-04-22 06:00:0775 filterType: Network.NetworkLogView.FilterType.CookieDomain,
Sigurd Schneidera86d1162021-02-16 12:20:2976 filterValue: cookie.domain,
77 },
78 {
Simon Zünd92f35f52021-04-22 06:00:0779 filterType: Network.NetworkLogView.FilterType.CookieName,
Sigurd Schneidera86d1162021-02-16 12:20:2980 filterValue: cookie.name,
81 },
82 {
Simon Zünd92f35f52021-04-22 06:00:0783 filterType: Network.NetworkLogView.FilterType.CookiePath,
Sigurd Schneidera86d1162021-02-16 12:20:2984 filterValue: cookie.path,
85 },
86 ]);
87 }, 'link-style devtools-link'));
88 } else {
89 name.textContent = cookie.name;
90 }
91 element.appendChild(name);
92 this.appendIssueDetailCell(element, `${cookie.domain}${cookie.path}`, 'affected-resource-cookie-info');
93
94 this.affectedResources.appendChild(element);
95 }
96
97 update(): void {
98 this.clear();
99 this.appendAffectedCookies(this.issue.cookiesWithRequestIndicator());
100 }
101}