// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import '../../../../ui/legacy/components/data_grid/data_grid.js'; import '../../../../ui/kit/kit.js'; import * as Common from '../../../../core/common/common.js'; import * as i18n from '../../../../core/i18n/i18n.js'; import type * as Platform from '../../../../core/platform/platform.js'; import * as SDK from '../../../../core/sdk/sdk.js'; import type * as Protocol from '../../../../generated/protocol.js'; import * as UI from '../../../../ui/legacy/legacy.js'; import * as Lit from '../../../../ui/lit/lit.js'; import preloadingGridStyles from './preloadingGrid.css.js'; import {capitalizedAction, composedStatus, ruleSetTagOrLocationShort, sortOrder} from './PreloadingString.js'; const {PreloadingStatus} = SDK.PreloadingModel; const UIStrings = { /** * @description Column header: Action of preloading (prefetch/prerender) */ action: 'Action', /** * @description Column header: A rule set of preloading */ ruleSet: 'Rule set', /** * @description Column header: Status of preloading attempt */ status: 'Status', /** * @description Status: Prerender failed, but prefetch is available */ prefetchFallbackReady: 'Prefetch fallback ready', } as const; const str_ = i18n.i18n.registerUIStrings('panels/application/preloading/components/PreloadingGrid.ts', UIStrings); export const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); const {render, html, nothing, Directives: {styleMap}} = Lit; // Shorten URL if a preloading attempt is same-origin. function urlShort(row: PreloadingGridRow, securityOrigin: string|null): string { const url = row.pipeline.getOriginallyTriggered().key.url; return securityOrigin && url.startsWith(securityOrigin) ? url.slice(securityOrigin.length) : url; } export interface PreloadingGridRow { id: string; pipeline: SDK.PreloadingModel.PreloadPipeline; ruleSets: Protocol.Preload.RuleSet[]; statusCode?: number; } export interface ViewInput { rows?: PreloadingGridRow[]; pageURL?: Platform.DevToolsPath.UrlString; onSelect?: ({rowId}: {rowId: string}) => void; } type View = (input: ViewInput, output: undefined, target: HTMLElement) => void; export const PRELOADING_GRID_DEFAULT_VIEW: View = (input, _output, target): void => { if (!input.rows || !input.pageURL) { render(nothing, target); return; } const {rows, pageURL} = input; const securityOrigin = pageURL === '' ? null : (new Common.ParsedURL.ParsedURL(pageURL)).securityOrigin(); // Disabled until https://crbug.com/1079231 is fixed. // clang-format off render(html`
| ${i18n.i18n.lockedString('URL')} | ${i18nString(UIStrings.action)} | ${i18nString(UIStrings.ruleSet)} | ${i18nString(UIStrings.status)} |
|---|---|---|---|
| ${urlShort(row, securityOrigin)} | ${capitalizedAction(attempt.action)} | ${row.ruleSets.length === 0 ? '' : ruleSetTagOrLocationShort(row.ruleSets[0], pageURL)} |
${(hasError || hasWarning) ? html`
|