blob: 029a85119fe79f75145b124c1d43dafa5edd049f [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
Sigurd Schneider30722582021-06-16 06:54:165import * as Common from '../../core/common/common.js';
Tim van der Lippefe58ef22021-04-19 10:48:556import * as Host from '../../core/host/host.js';
7import * as i18n from '../../core/i18n/i18n.js';
Jack Franklina75ae7c2021-05-11 13:22:548import type * as Platform from '../../core/platform/platform.js';
Tim van der Lippefe58ef22021-04-19 10:48:559import * as UI from '../../ui/legacy/legacy.js';
Sigurd Schneider30722582021-06-16 06:54:1610import * as NetworkForward from '../../panels/network/forward/forward.js';
Tim van der Lippe229a54f2021-05-14 16:59:0511import type * as Protocol from '../../generated/protocol.js';
Sigurd Schneidera86d1162021-02-16 12:20:2912import {AffectedItem, AffectedResourcesView} from './AffectedResourcesView.js';
Tim van der Lippebfbb58f2021-02-25 17:34:1913import type {AggregatedIssue} from './IssueAggregator.js';
Jack Franklina75ae7c2021-05-11 13:22:5414import type {IssueView} from './IssueView.js';
Sigurd Schneidera86d1162021-02-16 12:20:2915
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',
Simon Zünd27aa3642021-07-30 07:27:4633 /**
34 *@description Label for the the number of affected `Set-Cookie` lines associated with a DevTools issue. `Set-Cookie` is a specific header line in an HTTP network request and consists of a single line of text.
35 */
36 nRawCookieLines: '{n, plural, =1 {1 Raw `Set-Cookie` header} other {# Raw `Set-Cookie` headers}}',
Sigurd Schneidera86d1162021-02-16 12:20:2937};
Tim van der Lippefe58ef22021-04-19 10:48:5538const str_ = i18n.i18n.registerUIStrings('panels/issues/AffectedCookiesView.ts', UIStrings);
Sigurd Schneidera86d1162021-02-16 12:20:2939const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
40
41export class AffectedCookiesView extends AffectedResourcesView {
42 private issue: AggregatedIssue;
43 constructor(parent: IssueView, issue: AggregatedIssue) {
pradhuman1663bf9a2021-04-09 15:01:2244 super(parent);
Sigurd Schneidera86d1162021-02-16 12:20:2945 this.issue = issue;
46 }
47
Wolfgang Beyer40834922021-05-10 08:34:2248 protected getResourceNameWithCount(count: number): Platform.UIString.LocalizedString {
pradhuman1c51536c2021-03-16 07:53:4749 return i18nString(UIStrings.nCookies, {n: count});
50 }
51
Sigurd Schneidera86d1162021-02-16 12:20:2952 private appendAffectedCookies(cookies: Iterable<{cookie: Protocol.Audits.AffectedCookie, hasRequest: boolean}>):
53 void {
54 const header = document.createElement('tr');
55 this.appendColumnTitle(header, i18nString(UIStrings.name));
56 this.appendColumnTitle(
57 header, i18nString(UIStrings.domain) + ' & ' + i18nString(UIStrings.path),
58 'affected-resource-cookie-info-header');
59
60 this.affectedResources.appendChild(header);
61
62 let count = 0;
63 for (const cookie of cookies) {
64 count++;
65 this.appendAffectedCookie(cookie.cookie, cookie.hasRequest);
66 }
67 this.updateAffectedResourceCount(count);
68 }
69
70 private appendAffectedCookie(cookie: Protocol.Audits.AffectedCookie, hasAssociatedRequest: boolean): void {
71 const element = document.createElement('tr');
72 element.classList.add('affected-resource-cookie');
73 const name = document.createElement('td');
74 if (hasAssociatedRequest) {
75 name.appendChild(UI.UIUtils.createTextButton(cookie.name, () => {
76 Host.userMetrics.issuesPanelResourceOpened(this.issue.getCategory(), AffectedItem.Cookie);
Sigurd Schneider30722582021-06-16 06:54:1677 Common.Revealer.reveal(NetworkForward.UIFilter.UIRequestFilter.filters([
Sigurd Schneidera86d1162021-02-16 12:20:2978 {
Sigurd Schneider30722582021-06-16 06:54:1679 filterType: NetworkForward.UIFilter.FilterType.CookieDomain,
Sigurd Schneidera86d1162021-02-16 12:20:2980 filterValue: cookie.domain,
81 },
82 {
Sigurd Schneider30722582021-06-16 06:54:1683 filterType: NetworkForward.UIFilter.FilterType.CookieName,
Sigurd Schneidera86d1162021-02-16 12:20:2984 filterValue: cookie.name,
85 },
86 {
Sigurd Schneider30722582021-06-16 06:54:1687 filterType: NetworkForward.UIFilter.FilterType.CookiePath,
Sigurd Schneidera86d1162021-02-16 12:20:2988 filterValue: cookie.path,
89 },
Sigurd Schneider30722582021-06-16 06:54:1690 ]));
Sigurd Schneidera86d1162021-02-16 12:20:2991 }, 'link-style devtools-link'));
92 } else {
93 name.textContent = cookie.name;
94 }
95 element.appendChild(name);
96 this.appendIssueDetailCell(element, `${cookie.domain}${cookie.path}`, 'affected-resource-cookie-info');
97
98 this.affectedResources.appendChild(element);
99 }
100
101 update(): void {
102 this.clear();
103 this.appendAffectedCookies(this.issue.cookiesWithRequestIndicator());
104 }
105}
Simon Zünd27aa3642021-07-30 07:27:46106
107export class AffectedRawCookieLinesView extends AffectedResourcesView {
108 private issue: AggregatedIssue;
109 constructor(parent: IssueView, issue: AggregatedIssue) {
110 super(parent);
111 this.issue = issue;
112 }
113
114 protected override getResourceNameWithCount(count: number): Platform.UIString.LocalizedString {
115 return i18nString(UIStrings.nRawCookieLines, {n: count});
116 }
117
118 override update(): void {
119 this.clear();
120 const rawCookieLines = this.issue.getRawCookieLines();
121 for (const rawCookieLine of rawCookieLines) {
122 const row = document.createElement('tr');
123 row.classList.add('affected-resource-directive');
124 this.appendIssueDetailCell(row, rawCookieLine);
125 this.affectedResources.appendChild(row);
126 }
127 this.updateAffectedResourceCount(rawCookieLines.size);
128 }
129}