Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 1 | // 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 Lippe | fe58ef2 | 2021-04-19 10:48:55 | [diff] [blame] | 5 | import * as Host from '../../core/host/host.js'; |
| 6 | import * as i18n from '../../core/i18n/i18n.js'; |
| 7 | import * as Platform from '../../core/platform/platform.js'; |
| 8 | import * as UI from '../../ui/legacy/legacy.js'; |
| 9 | import * as Network from '../network/network.js'; |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 10 | |
| 11 | import {AffectedItem, AffectedResourcesView} from './AffectedResourcesView.js'; |
Tim van der Lippe | aa1ed7a | 2021-03-31 14:38:27 | [diff] [blame] | 12 | |
Tim van der Lippe | bfbb58f | 2021-02-25 17:34:19 | [diff] [blame] | 13 | import type {AggregatedIssue} from './IssueAggregator.js'; |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 14 | import {IssueView} from './IssueView.js'; |
| 15 | |
Simon Zünd | 6f95e84 | 2021-03-01 07:41:55 | [diff] [blame] | 16 | const UIStrings = { |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 17 | /** |
pradhuman1 | c51536c | 2021-03-16 07:53:47 | [diff] [blame] | 18 | *@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 Beyer | 4083492 | 2021-05-10 08:34:22 | [diff] [blame^] | 20 | nCookies: '{n, plural, =1 {# cookie} other {# cookies}}', |
pradhuman1 | c51536c | 2021-03-16 07:53:47 | [diff] [blame] | 21 | /** |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 22 | *@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 Lippe | fe58ef2 | 2021-04-19 10:48:55 | [diff] [blame] | 34 | const str_ = i18n.i18n.registerUIStrings('panels/issues/AffectedCookiesView.ts', UIStrings); |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 35 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
| 36 | |
| 37 | export class AffectedCookiesView extends AffectedResourcesView { |
| 38 | private issue: AggregatedIssue; |
| 39 | constructor(parent: IssueView, issue: AggregatedIssue) { |
pradhuman1 | 663bf9a | 2021-04-09 15:01:22 | [diff] [blame] | 40 | super(parent); |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 41 | this.issue = issue; |
| 42 | } |
| 43 | |
Wolfgang Beyer | 4083492 | 2021-05-10 08:34:22 | [diff] [blame^] | 44 | protected getResourceNameWithCount(count: number): Platform.UIString.LocalizedString { |
pradhuman1 | c51536c | 2021-03-16 07:53:47 | [diff] [blame] | 45 | return i18nString(UIStrings.nCookies, {n: count}); |
| 46 | } |
| 47 | |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 48 | 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ünd | 92f35f5 | 2021-04-22 06:00:07 | [diff] [blame] | 75 | filterType: Network.NetworkLogView.FilterType.CookieDomain, |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 76 | filterValue: cookie.domain, |
| 77 | }, |
| 78 | { |
Simon Zünd | 92f35f5 | 2021-04-22 06:00:07 | [diff] [blame] | 79 | filterType: Network.NetworkLogView.FilterType.CookieName, |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 80 | filterValue: cookie.name, |
| 81 | }, |
| 82 | { |
Simon Zünd | 92f35f5 | 2021-04-22 06:00:07 | [diff] [blame] | 83 | filterType: Network.NetworkLogView.FilterType.CookiePath, |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 84 | 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 | } |