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'; |
Jack Franklin | a75ae7c | 2021-05-11 13:22:54 | [diff] [blame] | 7 | import type * as Platform from '../../core/platform/platform.js'; |
Tim van der Lippe | fe58ef2 | 2021-04-19 10:48:55 | [diff] [blame] | 8 | import * as UI from '../../ui/legacy/legacy.js'; |
| 9 | import * as Network from '../network/network.js'; |
Tim van der Lippe | 229a54f | 2021-05-14 16:59:05 | [diff] [blame^] | 10 | import type * as Protocol from '../../generated/protocol.js'; |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 11 | |
| 12 | import {AffectedItem, AffectedResourcesView} from './AffectedResourcesView.js'; |
Tim van der Lippe | aa1ed7a | 2021-03-31 14:38:27 | [diff] [blame] | 13 | |
Tim van der Lippe | bfbb58f | 2021-02-25 17:34:19 | [diff] [blame] | 14 | import type {AggregatedIssue} from './IssueAggregator.js'; |
Jack Franklin | a75ae7c | 2021-05-11 13:22:54 | [diff] [blame] | 15 | import type {IssueView} from './IssueView.js'; |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 16 | |
Simon Zünd | 6f95e84 | 2021-03-01 07:41:55 | [diff] [blame] | 17 | const UIStrings = { |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 18 | /** |
pradhuman1 | c51536c | 2021-03-16 07:53:47 | [diff] [blame] | 19 | *@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. |
| 20 | */ |
Wolfgang Beyer | 4083492 | 2021-05-10 08:34:22 | [diff] [blame] | 21 | nCookies: '{n, plural, =1 {# cookie} other {# cookies}}', |
pradhuman1 | c51536c | 2021-03-16 07:53:47 | [diff] [blame] | 22 | /** |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 23 | *@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. |
| 24 | */ |
| 25 | name: 'Name', |
| 26 | /** |
| 27 | *@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 |
| 28 | */ |
| 29 | domain: 'Domain', |
| 30 | /** |
| 31 | *@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 |
| 32 | */ |
| 33 | path: 'Path', |
| 34 | }; |
Tim van der Lippe | fe58ef2 | 2021-04-19 10:48:55 | [diff] [blame] | 35 | const str_ = i18n.i18n.registerUIStrings('panels/issues/AffectedCookiesView.ts', UIStrings); |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 36 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
| 37 | |
| 38 | export class AffectedCookiesView extends AffectedResourcesView { |
| 39 | private issue: AggregatedIssue; |
| 40 | constructor(parent: IssueView, issue: AggregatedIssue) { |
pradhuman1 | 663bf9a | 2021-04-09 15:01:22 | [diff] [blame] | 41 | super(parent); |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 42 | this.issue = issue; |
| 43 | } |
| 44 | |
Wolfgang Beyer | 4083492 | 2021-05-10 08:34:22 | [diff] [blame] | 45 | protected getResourceNameWithCount(count: number): Platform.UIString.LocalizedString { |
pradhuman1 | c51536c | 2021-03-16 07:53:47 | [diff] [blame] | 46 | return i18nString(UIStrings.nCookies, {n: count}); |
| 47 | } |
| 48 | |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 49 | private appendAffectedCookies(cookies: Iterable<{cookie: Protocol.Audits.AffectedCookie, hasRequest: boolean}>): |
| 50 | void { |
| 51 | const header = document.createElement('tr'); |
| 52 | this.appendColumnTitle(header, i18nString(UIStrings.name)); |
| 53 | this.appendColumnTitle( |
| 54 | header, i18nString(UIStrings.domain) + ' & ' + i18nString(UIStrings.path), |
| 55 | 'affected-resource-cookie-info-header'); |
| 56 | |
| 57 | this.affectedResources.appendChild(header); |
| 58 | |
| 59 | let count = 0; |
| 60 | for (const cookie of cookies) { |
| 61 | count++; |
| 62 | this.appendAffectedCookie(cookie.cookie, cookie.hasRequest); |
| 63 | } |
| 64 | this.updateAffectedResourceCount(count); |
| 65 | } |
| 66 | |
| 67 | private appendAffectedCookie(cookie: Protocol.Audits.AffectedCookie, hasAssociatedRequest: boolean): void { |
| 68 | const element = document.createElement('tr'); |
| 69 | element.classList.add('affected-resource-cookie'); |
| 70 | const name = document.createElement('td'); |
| 71 | if (hasAssociatedRequest) { |
| 72 | name.appendChild(UI.UIUtils.createTextButton(cookie.name, () => { |
| 73 | Host.userMetrics.issuesPanelResourceOpened(this.issue.getCategory(), AffectedItem.Cookie); |
| 74 | Network.NetworkPanel.NetworkPanel.revealAndFilter([ |
| 75 | { |
Simon Zünd | 92f35f5 | 2021-04-22 06:00:07 | [diff] [blame] | 76 | filterType: Network.NetworkLogView.FilterType.CookieDomain, |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 77 | filterValue: cookie.domain, |
| 78 | }, |
| 79 | { |
Simon Zünd | 92f35f5 | 2021-04-22 06:00:07 | [diff] [blame] | 80 | filterType: Network.NetworkLogView.FilterType.CookieName, |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 81 | filterValue: cookie.name, |
| 82 | }, |
| 83 | { |
Simon Zünd | 92f35f5 | 2021-04-22 06:00:07 | [diff] [blame] | 84 | filterType: Network.NetworkLogView.FilterType.CookiePath, |
Sigurd Schneider | a86d116 | 2021-02-16 12:20:29 | [diff] [blame] | 85 | filterValue: cookie.path, |
| 86 | }, |
| 87 | ]); |
| 88 | }, 'link-style devtools-link')); |
| 89 | } else { |
| 90 | name.textContent = cookie.name; |
| 91 | } |
| 92 | element.appendChild(name); |
| 93 | this.appendIssueDetailCell(element, `${cookie.domain}${cookie.path}`, 'affected-resource-cookie-info'); |
| 94 | |
| 95 | this.affectedResources.appendChild(element); |
| 96 | } |
| 97 | |
| 98 | update(): void { |
| 99 | this.clear(); |
| 100 | this.appendAffectedCookies(this.issue.cookiesWithRequestIndicator()); |
| 101 | } |
| 102 | } |