|
| 1 | +// Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +// Copyright 2024 The Chromium Authors. All rights reserved. |
| 3 | +// Use of this source code is governed by a BSD-style license that can be |
| 4 | +// found in the LICENSE file. |
| 5 | + |
| 6 | +import '../../../ui/components/icon_button/icon_button.js'; |
| 7 | + |
| 8 | +import * as Common from '../../../core/common/common.js'; |
| 9 | +import * as Buttons from '../../../ui/components/buttons/buttons.js'; |
| 10 | +import * as Lit from '../../../ui/lit/lit.js'; |
| 11 | +import * as VisualLogging from '../../../ui/visual_logging/visual_logging.js'; |
| 12 | + |
| 13 | +import networkEventCoverageInfobarStylesRaw from './NetworkEventCoverageInfobar.css.js'; |
| 14 | + |
| 15 | +const networkEventCoverageInfobarStyles = new CSSStyleSheet(); |
| 16 | +networkEventCoverageInfobarStyles.replaceSync(networkEventCoverageInfobarStylesRaw.cssText); |
| 17 | + |
| 18 | +const {html} = Lit; |
| 19 | + |
| 20 | +const DISMISSED_SETTING_NAME = 'network-event-coverage-infobar-dismissed'; |
| 21 | + |
| 22 | +export class NetworkEventCoverageInfobar extends HTMLElement { |
| 23 | + readonly #shadow = this.attachShadow({mode: 'open'}); |
| 24 | + #expanded = false; |
| 25 | + readonly #dismissedSetting = Common.Settings.Settings.instance().createSetting<boolean>(DISMISSED_SETTING_NAME, false); |
| 26 | + |
| 27 | + connectedCallback(): void { |
| 28 | + this.#shadow.adoptedStyleSheets = [networkEventCoverageInfobarStyles]; |
| 29 | + this.#render(); |
| 30 | + } |
| 31 | + |
| 32 | + #onToggleExpand(): void { |
| 33 | + this.#expanded = !this.#expanded; |
| 34 | + this.#render(); |
| 35 | + } |
| 36 | + |
| 37 | + #onClose(event: Event): void { |
| 38 | + event.stopPropagation(); |
| 39 | + this.#dismissedSetting.set(true); |
| 40 | + this.#render(); |
| 41 | + } |
| 42 | + |
| 43 | + #render(): void { |
| 44 | + if (this.#dismissedSetting.get()) { |
| 45 | + Lit.render(Lit.nothing, this.#shadow, {host: this}); |
| 46 | + return; |
| 47 | + } |
| 48 | + // clang-format off |
| 49 | + Lit.render( |
| 50 | + html` |
| 51 | + <div class="infobar" jslog=${VisualLogging.section('network-event-coverage-infobar')}> |
| 52 | + <div |
| 53 | + class="infobar-header" |
| 54 | + role="button" |
| 55 | + tabindex="0" |
| 56 | + aria-expanded=${this.#expanded ? 'true' : 'false'} |
| 57 | + @click=${this.#onToggleExpand} |
| 58 | + @keydown=${(e: KeyboardEvent) => { |
| 59 | + if (e.key === 'Enter' || e.key === ' ') { |
| 60 | + e.preventDefault(); |
| 61 | + this.#onToggleExpand(); |
| 62 | + } |
| 63 | + }} |
| 64 | + jslog=${VisualLogging.expand().track({click: true})} |
| 65 | + > |
| 66 | + <span class="arrow-icon ${this.#expanded ? 'expanded' : ''}"></span> |
| 67 | + <devtools-icon class="info-icon" .data=${{iconName: 'info', color: 'var(--sys-color-on-surface-yellow)', width: '16px', height: '16px'}}></devtools-icon> |
| 68 | + <span class="infobar-message">[FB-only] Network event coverage</span> |
| 69 | + <devtools-button |
| 70 | + class="close-button" |
| 71 | + title="Dismiss" |
| 72 | + .size=${Buttons.Button.Size.MICRO} |
| 73 | + .iconName=${'cross'} |
| 74 | + .variant=${Buttons.Button.Variant.ICON} |
| 75 | + .jslogContext=${'dismiss'} |
| 76 | + @click=${this.#onClose} |
| 77 | + ></devtools-button> |
| 78 | + </div> |
| 79 | + ${this.#expanded ? html` |
| 80 | + <div class="infobar-details"> |
| 81 | + We currently record events from React Native's default networking stack. This includes <Image>, but not FbImageNetworkFetcher. Therefore, only fetch() and XMLHttpRequest events may be visible. |
| 82 | + </div> |
| 83 | + ` : Lit.nothing} |
| 84 | + </div> |
| 85 | + `, |
| 86 | + this.#shadow, |
| 87 | + {host: this}, |
| 88 | + ); |
| 89 | + // clang-format on |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +customElements.define('devtools-network-event-coverage-infobar', NetworkEventCoverageInfobar); |
| 94 | + |
| 95 | +declare global { |
| 96 | + interface HTMLElementTagNameMap { |
| 97 | + 'devtools-network-event-coverage-infobar': NetworkEventCoverageInfobar; |
| 98 | + } |
| 99 | +} |
0 commit comments