chrome-devtools-frontend 1.0.1567721 → 1.0.1568864

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
  // Copyright 2023 The Chromium Authors
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
- /* eslint-disable @devtools/no-lit-render-outside-of-view */
5
4
 
6
5
  import '../../../../ui/kit/kit.js';
7
6
  import '../../../../ui/components/report_view/report_view.js';
@@ -13,20 +12,16 @@ import type * as Platform from '../../../../core/platform/platform.js';
13
12
  import {assertNotNullOrUndefined} from '../../../../core/platform/platform.js';
14
13
  import * as SDK from '../../../../core/sdk/sdk.js';
15
14
  import * as Protocol from '../../../../generated/protocol.js';
16
- import * as LegacyWrapper from '../../../../ui/components/legacy_wrapper/legacy_wrapper.js';
17
- import * as RenderCoordinator from '../../../../ui/components/render_coordinator/render_coordinator.js';
18
15
  import * as UI from '../../../../ui/legacy/legacy.js';
19
- import * as Lit from '../../../../ui/lit/lit.js';
16
+ import {html, type LitTemplate, nothing, render} from '../../../../ui/lit/lit.js';
20
17
  import * as VisualLogging from '../../../../ui/visual_logging/visual_logging.js';
21
18
  import * as PreloadingHelper from '../helper/helper.js';
22
19
 
23
- import * as MismatchedPreloadingGrid from './MismatchedPreloadingGrid.js';
20
+ import {MismatchedPreloadingGrid, type MismatchedPreloadingGridData} from './MismatchedPreloadingGrid.js';
24
21
  import preloadingGridStyles from './preloadingGrid.css.js';
25
22
  import {prefetchFailureReason, prerenderFailureReason} from './PreloadingString.js';
26
23
  import usedPreloadingStyles from './usedPreloadingView.css.js';
27
24
 
28
- const {html} = Lit;
29
-
30
25
  const UIStrings = {
31
26
  /**
32
27
  * @description Header for preloading status.
@@ -139,6 +134,8 @@ const UIStrings = {
139
134
  const str_ = i18n.i18n.registerUIStrings('panels/application/preloading/components/UsedPreloadingView.ts', UIStrings);
140
135
  const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
141
136
 
137
+ const {widgetConfig} = UI.Widget;
138
+
142
139
  export interface UsedPreloadingViewData {
143
140
  pageURL: Platform.DevToolsPath.UrlString;
144
141
  previousAttempts: SDK.PreloadingModel.PreloadingAttempt[];
@@ -154,12 +151,290 @@ export const enum UsedKind {
154
151
  NO_PRELOADS = 'NoPreloads',
155
152
  }
156
153
 
154
+ type Badge = {
155
+ type: 'success',
156
+ count?: number,
157
+ }|{
158
+ type: 'failure',
159
+ count?: number,
160
+ }|{
161
+ type: 'neutral',
162
+ message: string,
163
+ };
164
+
165
+ interface MismatchedData {
166
+ pageURL: Platform.DevToolsPath.UrlString;
167
+ rows: MismatchedPreloadingGridData['rows'];
168
+ }
169
+
170
+ type AttemptWithMismatchedHeaders =
171
+ SDK.PreloadingModel.PrerenderAttempt|SDK.PreloadingModel.PrerenderUntilScriptAttempt;
172
+
173
+ interface SpeculativeLoadingStatusForThisPageData {
174
+ kind: UsedKind;
175
+ prefetch: SDK.PreloadingModel.PreloadingAttempt|undefined;
176
+ prerenderLike: SDK.PreloadingModel.PreloadingAttempt|undefined;
177
+ mismatchedData: MismatchedData|undefined;
178
+ attemptWithMismatchedHeaders: AttemptWithMismatchedHeaders|undefined;
179
+ }
180
+
181
+ function renderSpeculativeLoadingStatusForThisPageSections(
182
+ {kind, prefetch, prerenderLike, mismatchedData, attemptWithMismatchedHeaders}:
183
+ SpeculativeLoadingStatusForThisPageData): LitTemplate {
184
+ let badge: Badge;
185
+ let basicMessage: LitTemplate;
186
+ switch (kind) {
187
+ case UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED:
188
+ badge = {type: 'success'};
189
+ basicMessage = html`${i18nString(UIStrings.downgradedPrefetchUsed)}`;
190
+ break;
191
+ case UsedKind.PREFETCH_USED:
192
+ badge = {type: 'success'};
193
+ basicMessage = html`${i18nString(UIStrings.prefetchUsed)}`;
194
+ break;
195
+ case UsedKind.PRERENDER_USED:
196
+ badge = {type: 'success'};
197
+ basicMessage = html`${i18nString(UIStrings.prerenderUsed)}`;
198
+ break;
199
+ case UsedKind.PREFETCH_FAILED:
200
+ badge = {type: 'failure'};
201
+ basicMessage = html`${i18nString(UIStrings.prefetchFailed)}`;
202
+ break;
203
+ case UsedKind.PRERENDER_FAILED:
204
+ badge = {type: 'failure'};
205
+ basicMessage = html`${i18nString(UIStrings.prerenderFailed)}`;
206
+ break;
207
+ case UsedKind.NO_PRELOADS:
208
+ badge = {type: 'neutral', message: i18nString(UIStrings.badgeNoSpeculativeLoads)};
209
+ basicMessage = html`${i18nString(UIStrings.noPreloads)}`;
210
+ break;
211
+ }
212
+
213
+ let maybeFailureReasonMessage;
214
+ if (kind === UsedKind.PREFETCH_FAILED) {
215
+ assertNotNullOrUndefined(prefetch);
216
+ maybeFailureReasonMessage = prefetchFailureReason(prefetch as SDK.PreloadingModel.PrefetchAttempt);
217
+ } else if (kind === UsedKind.PRERENDER_FAILED || kind === UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED) {
218
+ assertNotNullOrUndefined(prerenderLike);
219
+ maybeFailureReasonMessage = prerenderFailureReason(
220
+ prerenderLike as SDK.PreloadingModel.PrerenderAttempt | SDK.PreloadingModel.PrerenderUntilScriptAttempt);
221
+ }
222
+
223
+ // Disabled until https://crbug.com/1079231 is fixed.
224
+ // clang-format off
225
+ return html`
226
+ <devtools-report-section-header>
227
+ ${i18nString(UIStrings.speculativeLoadingStatusForThisPage)}
228
+ </devtools-report-section-header>
229
+ <devtools-report-section>
230
+ <div>
231
+ <div class="status-badge-container">
232
+ ${renderBadge(badge)}
233
+ </div>
234
+ <div>
235
+ ${basicMessage}
236
+ </div>
237
+ </div>
238
+ </devtools-report-section>
239
+
240
+ ${maybeFailureReasonMessage !== undefined ? html`
241
+ <devtools-report-section-header>
242
+ ${i18nString(UIStrings.detailsFailureReason)}
243
+ </devtools-report-section-header>
244
+ <devtools-report-section>
245
+ ${maybeFailureReasonMessage}
246
+ </devtools-report-section>` : nothing}
247
+
248
+ ${mismatchedData ? renderMismatchedSections(mismatchedData) : nothing}
249
+ ${attemptWithMismatchedHeaders ?
250
+ renderMismatchedHTTPHeadersSections(attemptWithMismatchedHeaders) : nothing}`;
251
+ // clang-format on
252
+ }
253
+
254
+ function renderMismatchedSections(data: MismatchedData): LitTemplate {
255
+ // Disabled until https://crbug.com/1079231 is fixed.
256
+ // clang-format off
257
+ return html`
258
+ <devtools-report-section-header>
259
+ ${i18nString(UIStrings.currentURL)}
260
+ </devtools-report-section-header>
261
+ <devtools-report-section>
262
+ <x-link
263
+ class="link devtools-link"
264
+ href=${data.pageURL}
265
+ jslog=${VisualLogging.link()
266
+ .track({ click: true, keydown: 'Enter|Space' })
267
+ .context('current-url')}
268
+ >${data.pageURL}</x-link>
269
+ </devtools-report-section>
270
+
271
+ <devtools-report-section-header>
272
+ ${i18nString(UIStrings.preloadedURLs)}
273
+ </devtools-report-section-header>
274
+ <devtools-report-section jslog=${VisualLogging.section('preloaded-urls')}>
275
+ <devtools-widget .widgetConfig=${widgetConfig(MismatchedPreloadingGrid, {data})}>
276
+ </devtools-widget>
277
+ </devtools-report-section>`;
278
+ // clang-format on
279
+ }
280
+
281
+ function renderMismatchedHTTPHeadersSections(attempt: AttemptWithMismatchedHeaders): LitTemplate {
282
+ // Disabled until https://crbug.com/1079231 is fixed.
283
+ // clang-format off
284
+ return html`
285
+ <devtools-report-section-header>
286
+ ${i18nString(UIStrings.mismatchedHeadersDetail)}
287
+ </devtools-report-section-header>
288
+ <devtools-report-section>
289
+ <style>${preloadingGridStyles}</style>
290
+ <div class="preloading-container">
291
+ <devtools-data-grid striped inline>
292
+ <table>
293
+ <tr>
294
+ <th id="header-name" weight="30" sortable>
295
+ ${i18nString(UIStrings.headerName)}
296
+ </th>
297
+ <th id="initial-value" weight="30" sortable>
298
+ ${i18nString(UIStrings.initialNavigationValue)}
299
+ </th>
300
+ <th id="activation-value" weight="30" sortable>
301
+ ${i18nString(UIStrings.activationNavigationValue)}
302
+ </th>
303
+ </tr>
304
+ ${(attempt.mismatchedHeaders ?? []).map(mismatchedHeaders => html`
305
+ <tr>
306
+ <td>${mismatchedHeaders.headerName}</td>
307
+ <td>${mismatchedHeaders.initialValue ?? i18nString(UIStrings.missing)}</td>
308
+ <td>${mismatchedHeaders.activationValue ?? i18nString(UIStrings.missing)}</td>
309
+ </tr>
310
+ `)}
311
+ </table>
312
+ </devtools-data-grid>
313
+ </div>
314
+ </devtools-report-section>`;
315
+ // clang-format on
316
+ }
317
+
318
+ interface SpeculationsInitiatedByThisPageSummaryData {
319
+ badges: Badge[];
320
+ revealRuleSetView: () => void;
321
+ revealAttemptViewWithFilter: () => void;
322
+ }
323
+
324
+ interface ViewInput {
325
+ speculativeLoadingStatusData: SpeculativeLoadingStatusForThisPageData;
326
+ speculationsInitiatedSummaryData: SpeculationsInitiatedByThisPageSummaryData;
327
+ }
328
+
329
+ function renderSpeculationsInitiatedByThisPageSummarySections(
330
+ {badges, revealRuleSetView, revealAttemptViewWithFilter}: SpeculationsInitiatedByThisPageSummaryData): LitTemplate {
331
+ // Disabled until https://crbug.com/1079231 is fixed.
332
+ // clang-format off
333
+ return html`
334
+ <devtools-report-section-header>
335
+ ${i18nString(UIStrings.speculationsInitiatedByThisPage)}
336
+ </devtools-report-section-header>
337
+ <devtools-report-section>
338
+ <div>
339
+ <div class="status-badge-container">
340
+ ${badges.map(renderBadge)}
341
+ </div>
342
+
343
+ <div class="reveal-links">
344
+ <button class="link devtools-link" @click=${revealRuleSetView}
345
+ jslog=${VisualLogging.action('view-all-rules').track({click: true})}>
346
+ ${i18nString(UIStrings.viewAllRules)}
347
+ </button>
348
+
349
+ <button class="link devtools-link" @click=${revealAttemptViewWithFilter}
350
+ jslog=${VisualLogging.action('view-all-speculations').track({click: true})}>
351
+ ${i18nString(UIStrings.viewAllSpeculations)}
352
+ </button>
353
+ </div>
354
+ </div>
355
+ </devtools-report-section>`;
356
+ // clang-format on
357
+ }
358
+
359
+ function renderBadge(config: Badge): LitTemplate {
360
+ const badge = (klass: string, iconName: string, message: string): LitTemplate => {
361
+ // Disabled until https://crbug.com/1079231 is fixed.
362
+ // clang-format off
363
+ return html`
364
+ <span class=${klass}>
365
+ <devtools-icon name=${iconName}></devtools-icon>
366
+ <span>
367
+ ${message}
368
+ </span>
369
+ </span>
370
+ `;
371
+ // clang-format on
372
+ };
373
+ switch (config.type) {
374
+ case 'success': {
375
+ let message;
376
+ if (config.count === undefined) {
377
+ message = i18nString(UIStrings.badgeSuccess);
378
+ } else {
379
+ message = i18nString(UIStrings.badgeSuccessWithCount, {n: config.count});
380
+ }
381
+ return badge('status-badge status-badge-success', 'check-circle', message);
382
+ }
383
+ case 'failure': {
384
+ let message;
385
+ if (config.count === undefined) {
386
+ message = i18nString(UIStrings.badgeFailure);
387
+ } else {
388
+ message = i18nString(UIStrings.badgeFailureWithCount, {n: config.count});
389
+ }
390
+ return badge('status-badge status-badge-failure', 'cross-circle', message);
391
+ }
392
+ case 'neutral':
393
+ return badge('status-badge status-badge-neutral', 'clear', config.message);
394
+ }
395
+ }
396
+
397
+ type View = (input: ViewInput, output: undefined, target: HTMLElement|ShadowRoot) => void;
398
+
399
+ const DEFAULT_VIEW: View = (input, _output, target) => {
400
+ // Disabled until https://crbug.com/1079231 is fixed.
401
+ // clang-format off
402
+ render(html`
403
+ <style>${usedPreloadingStyles}</style>
404
+ <devtools-report>
405
+ ${renderSpeculativeLoadingStatusForThisPageSections(input.speculativeLoadingStatusData)}
406
+
407
+ <devtools-report-divider></devtools-report-divider>
408
+
409
+ ${renderSpeculationsInitiatedByThisPageSummarySections(input.speculationsInitiatedSummaryData)}
410
+
411
+ <devtools-report-divider></devtools-report-divider>
412
+
413
+ <devtools-report-section>
414
+ <x-link
415
+ class="link devtools-link"
416
+ href=${'https://developer.chrome.com/blog/prerender-pages/'}
417
+ jslog=${VisualLogging.link()
418
+ .track({ click: true, keydown: 'Enter|Space' })
419
+ .context('learn-more')}
420
+ >${i18nString(UIStrings.learnMore)}</x-link>
421
+ </devtools-report-section>
422
+ </devtools-report>`, target);
423
+ // clang-format on
424
+ };
425
+
157
426
  /**
158
427
  * TODO(kenoss): Rename this class and file once https://crrev.com/c/4933567 landed.
159
428
  * This also shows summary of speculations initiated by this page.
160
429
  **/
161
- export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableComponent<UI.Widget.VBox> {
162
- readonly #shadow = this.attachShadow({mode: 'open'});
430
+ export class UsedPreloadingView extends UI.Widget.VBox {
431
+ readonly #view: View;
432
+
433
+ constructor(view = DEFAULT_VIEW) {
434
+ super({useShadowDom: true});
435
+ this.#view = view;
436
+ }
437
+
163
438
  #data: UsedPreloadingViewData = {
164
439
  pageURL: '' as Platform.DevToolsPath.UrlString,
165
440
  previousAttempts: [],
@@ -168,41 +443,15 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
168
443
 
169
444
  set data(data: UsedPreloadingViewData) {
170
445
  this.#data = data;
171
- void this.#render();
172
- }
173
-
174
- async #render(): Promise<void> {
175
- await RenderCoordinator.write('UsedPreloadingView render', () => {
176
- Lit.render(this.#renderTemplate(), this.#shadow, {host: this});
177
- });
446
+ this.requestUpdate();
178
447
  }
179
448
 
180
- #renderTemplate(): Lit.LitTemplate {
181
- // Disabled until https://crbug.com/1079231 is fixed.
182
- // clang-format off
183
- return html`
184
- <style>${usedPreloadingStyles}</style>
185
- <devtools-report>
186
- ${this.#speculativeLoadingStatusForThisPageSections()}
187
-
188
- <devtools-report-divider></devtools-report-divider>
189
-
190
- ${this.#speculationsInitiatedByThisPageSummarySections()}
191
-
192
- <devtools-report-divider></devtools-report-divider>
193
-
194
- <devtools-report-section>
195
- <x-link
196
- class="link devtools-link"
197
- href=${'https://developer.chrome.com/blog/prerender-pages/'}
198
- jslog=${VisualLogging.link()
199
- .track({ click: true, keydown: 'Enter|Space' })
200
- .context('learn-more')}
201
- >${i18nString(UIStrings.learnMore)}</x-link>
202
- </devtools-report-section>
203
- </devtools-report>
204
- `;
205
- // clang-format on
449
+ override performUpdate(): void {
450
+ const viewInput: ViewInput = {
451
+ speculativeLoadingStatusData: this.#getSpeculativeLoadingStatusForThisPageData(),
452
+ speculationsInitiatedSummaryData: this.#getSpeculationsInitiatedByThisPageSummaryData(),
453
+ };
454
+ this.#view(viewInput, undefined, this.contentElement);
206
455
  }
207
456
 
208
457
  #isPrerenderLike(speculationAction: Protocol.Preload.SpeculationAction): boolean {
@@ -211,12 +460,11 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
211
460
  ].includes(speculationAction);
212
461
  }
213
462
 
214
- #isPrerenderAttempt(attempt: SDK.PreloadingModel.PreloadingAttempt):
215
- attempt is SDK.PreloadingModel.PrerenderAttempt|SDK.PreloadingModel.PrerenderUntilScriptAttempt {
463
+ #isPrerenderAttempt(attempt: SDK.PreloadingModel.PreloadingAttempt): attempt is AttemptWithMismatchedHeaders {
216
464
  return this.#isPrerenderLike(attempt.action);
217
465
  }
218
466
 
219
- #speculativeLoadingStatusForThisPageSections(): Lit.LitTemplate {
467
+ #getSpeculativeLoadingStatusForThisPageData(): SpeculativeLoadingStatusForThisPageData {
220
468
  const pageURL = Common.ParsedURL.ParsedURL.urlWithoutHash(this.#data.pageURL);
221
469
  const forThisPage = this.#data.previousAttempts.filter(
222
470
  attempt => Common.ParsedURL.ParsedURL.urlWithoutHash(attempt.key.url) === pageURL);
@@ -244,84 +492,18 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
244
492
  kind = UsedKind.NO_PRELOADS;
245
493
  }
246
494
 
247
- let badge;
248
- let basicMessage;
249
- switch (kind) {
250
- case UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED:
251
- badge = this.#badgeSuccess();
252
- basicMessage = html`${i18nString(UIStrings.downgradedPrefetchUsed)}`;
253
- break;
254
- case UsedKind.PREFETCH_USED:
255
- badge = this.#badgeSuccess();
256
- basicMessage = html`${i18nString(UIStrings.prefetchUsed)}`;
257
- break;
258
- case UsedKind.PRERENDER_USED:
259
- badge = this.#badgeSuccess();
260
- basicMessage = html`${i18nString(UIStrings.prerenderUsed)}`;
261
- break;
262
- case UsedKind.PREFETCH_FAILED:
263
- badge = this.#badgeFailure();
264
- basicMessage = html`${i18nString(UIStrings.prefetchFailed)}`;
265
- break;
266
- case UsedKind.PRERENDER_FAILED:
267
- badge = this.#badgeFailure();
268
- basicMessage = html`${i18nString(UIStrings.prerenderFailed)}`;
269
- break;
270
- case UsedKind.NO_PRELOADS:
271
- badge = this.#badgeNeutral(i18nString(UIStrings.badgeNoSpeculativeLoads));
272
- basicMessage = html`${i18nString(UIStrings.noPreloads)}`;
273
- break;
274
- }
275
-
276
- let maybeFailureReasonMessage;
277
- if (kind === UsedKind.PREFETCH_FAILED) {
278
- assertNotNullOrUndefined(prefetch);
279
- maybeFailureReasonMessage = prefetchFailureReason(prefetch as SDK.PreloadingModel.PrefetchAttempt);
280
- } else if (kind === UsedKind.PRERENDER_FAILED || kind === UsedKind.DOWNGRADED_PRERENDER_TO_PREFETCH_AND_USED) {
281
- assertNotNullOrUndefined(prerenderLike);
282
- maybeFailureReasonMessage = prerenderFailureReason(
283
- prerenderLike as SDK.PreloadingModel.PrerenderAttempt | SDK.PreloadingModel.PrerenderUntilScriptAttempt);
284
- }
285
-
286
- let maybeFailureReason: Lit.LitTemplate = Lit.nothing;
287
- if (maybeFailureReasonMessage !== undefined) {
288
- // Disabled until https://crbug.com/1079231 is fixed.
289
- // clang-format off
290
- maybeFailureReason = html`
291
- <devtools-report-section-header>${i18nString(UIStrings.detailsFailureReason)}</devtools-report-section-header>
292
- <devtools-report-section>
293
- ${maybeFailureReasonMessage}
294
- </devtools-report-section>
295
- `;
296
- // clang-format on
297
- }
298
-
299
- // Disabled until https://crbug.com/1079231 is fixed.
300
- // clang-format off
301
- return html`
302
- <devtools-report-section-header>${i18nString(UIStrings.speculativeLoadingStatusForThisPage)}</devtools-report-section-header>
303
- <devtools-report-section>
304
- <div>
305
- <div class="status-badge-container">
306
- ${badge}
307
- </div>
308
- <div>
309
- ${basicMessage}
310
- </div>
311
- </div>
312
- </devtools-report-section>
313
-
314
- ${maybeFailureReason}
315
-
316
- ${this.#maybeMismatchedSections(kind)}
317
- ${this.#maybeMismatchedHTTPHeadersSections()}
318
- `;
319
- // clang-format on
495
+ return {
496
+ kind,
497
+ prefetch,
498
+ prerenderLike,
499
+ mismatchedData: this.#getMismatchedData(kind),
500
+ attemptWithMismatchedHeaders: this.#getAttemptWithMismatchedHeaders(),
501
+ };
320
502
  }
321
503
 
322
- #maybeMismatchedSections(kind: UsedKind): Lit.LitTemplate {
504
+ #getMismatchedData(kind: UsedKind): MismatchedData|undefined {
323
505
  if (kind !== UsedKind.NO_PRELOADS || this.#data.previousAttempts.length === 0) {
324
- return Lit.nothing;
506
+ return undefined;
325
507
  }
326
508
 
327
509
  const rows = this.#data.previousAttempts.map(attempt => {
@@ -331,43 +513,19 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
331
513
  status: attempt.status,
332
514
  };
333
515
  });
334
- const data = {
516
+ return {
335
517
  pageURL: this.#data.pageURL,
336
518
  rows,
337
519
  };
338
-
339
- // Disabled until https://crbug.com/1079231 is fixed.
340
- // clang-format off
341
- return html`
342
- <devtools-report-section-header>${i18nString(UIStrings.currentURL)}</devtools-report-section-header>
343
- <devtools-report-section>
344
- <x-link
345
- class="link devtools-link"
346
- href=${this.#data.pageURL}
347
- jslog=${VisualLogging.link()
348
- .track({ click: true, keydown: 'Enter|Space' })
349
- .context('current-url')}
350
- >${this.#data.pageURL}</x-link>
351
- </devtools-report-section>
352
-
353
- <devtools-report-section-header>${i18nString(UIStrings.preloadedURLs)}</devtools-report-section-header>
354
- <devtools-report-section
355
- jslog=${VisualLogging.section('preloaded-urls')}>
356
- <devtools-widget
357
- .widgetConfig=${UI.Widget.widgetConfig(MismatchedPreloadingGrid.MismatchedPreloadingGrid, {data})}
358
- ></devtools-widget>
359
- </devtools-report-section>
360
- `;
361
- // clang-format on
362
520
  }
363
521
 
364
- #maybeMismatchedHTTPHeadersSections(): Lit.LitTemplate {
522
+ #getAttemptWithMismatchedHeaders(): AttemptWithMismatchedHeaders|undefined {
365
523
  const attempt = this.#data.previousAttempts.find(
366
524
  attempt => this.#isPrerenderAttempt(attempt) && attempt.mismatchedHeaders !== null) as
367
525
  SDK.PreloadingModel.PrerenderAttempt |
368
526
  SDK.PreloadingModel.PrerenderUntilScriptAttempt | undefined;
369
527
  if (!attempt?.mismatchedHeaders) {
370
- return Lit.nothing;
528
+ return undefined;
371
529
  }
372
530
 
373
531
  if (attempt.key.url !== this.#data.pageURL) {
@@ -377,42 +535,10 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
377
535
  throw new Error('unreachable');
378
536
  }
379
537
 
380
- // Disabled until https://crbug.com/1079231 is fixed.
381
- // clang-format off
382
- return html`
383
- <devtools-report-section-header>${i18nString(UIStrings.mismatchedHeadersDetail)}</devtools-report-section-header>
384
- <devtools-report-section>
385
- <style>${preloadingGridStyles}</style>
386
- <div class="preloading-container">
387
- <devtools-data-grid striped inline>
388
- <table>
389
- <tr>
390
- <th id="header-name" weight="30" sortable>
391
- ${i18nString(UIStrings.headerName)}
392
- </th>
393
- <th id="initial-value" weight="30" sortable>
394
- ${i18nString(UIStrings.initialNavigationValue)}
395
- </th>
396
- <th id="activation-value" weight="30" sortable>
397
- ${i18nString(UIStrings.activationNavigationValue)}
398
- </th>
399
- </tr>
400
- ${attempt.mismatchedHeaders.map(mismatchedHeaders => html`
401
- <tr>
402
- <td>${mismatchedHeaders.headerName}</td>
403
- <td>${mismatchedHeaders.initialValue ?? i18nString(UIStrings.missing)}</td>
404
- <td>${mismatchedHeaders.activationValue ?? i18nString(UIStrings.missing)}</td>
405
- </tr>
406
- `)}
407
- </table>
408
- </devtools-data-grid>
409
- </div>
410
- </devtools-report-section>
411
- `;
412
- // clang-format on
538
+ return attempt;
413
539
  }
414
540
 
415
- #speculationsInitiatedByThisPageSummarySections(): Lit.LitTemplate {
541
+ #getSpeculationsInitiatedByThisPageSummaryData(): SpeculationsInitiatedByThisPageSummaryData {
416
542
  const count = this.#data.currentAttempts.reduce((acc, attempt) => {
417
543
  acc.set(attempt.status, (acc.get(attempt.status) ?? 0) + 1);
418
544
  return acc;
@@ -422,21 +548,22 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
422
548
  const failureCount = count.get(SDK.PreloadingModel.PreloadingStatus.FAILURE) ?? 0;
423
549
  const inProgressCount = (count.get(SDK.PreloadingModel.PreloadingStatus.PENDING) ?? 0) +
424
550
  (count.get(SDK.PreloadingModel.PreloadingStatus.RUNNING) ?? 0);
425
- const badges = [];
551
+
552
+ const badges: Badge[] = [];
426
553
  if (this.#data.currentAttempts.length === 0) {
427
- badges.push(this.#badgeNeutral(i18nString(UIStrings.badgeNoSpeculativeLoads)));
554
+ badges.push({type: 'neutral', message: i18nString(UIStrings.badgeNoSpeculativeLoads)});
428
555
  }
429
556
  if (notTriggeredCount > 0) {
430
- badges.push(this.#badgeNeutral(i18nString(UIStrings.badgeNotTriggeredWithCount, {n: notTriggeredCount})));
557
+ badges.push({type: 'neutral', message: i18nString(UIStrings.badgeNotTriggeredWithCount, {n: notTriggeredCount})});
431
558
  }
432
559
  if (inProgressCount > 0) {
433
- badges.push(this.#badgeNeutral(i18nString(UIStrings.badgeInProgressWithCount, {n: inProgressCount})));
560
+ badges.push({type: 'neutral', message: i18nString(UIStrings.badgeInProgressWithCount, {n: inProgressCount})});
434
561
  }
435
562
  if (readyCount > 0) {
436
- badges.push(this.#badgeSuccess(readyCount));
563
+ badges.push({type: 'success', count: readyCount});
437
564
  }
438
565
  if (failureCount > 0) {
439
- badges.push(this.#badgeFailure(failureCount));
566
+ badges.push({type: 'failure', count: failureCount});
440
567
  }
441
568
 
442
569
  const revealRuleSetView = (): void => {
@@ -446,76 +573,6 @@ export class UsedPreloadingView extends LegacyWrapper.LegacyWrapper.WrappableCom
446
573
  void Common.Revealer.reveal(new PreloadingHelper.PreloadingForward.AttemptViewWithFilter(null));
447
574
  };
448
575
 
449
- // Disabled until https://crbug.com/1079231 is fixed.
450
- // clang-format off
451
- return html`
452
- <devtools-report-section-header>${i18nString(UIStrings.speculationsInitiatedByThisPage)}</devtools-report-section-header>
453
- <devtools-report-section>
454
- <div>
455
- <div class="status-badge-container">
456
- ${badges}
457
- </div>
458
-
459
- <div class="reveal-links">
460
- <button class="link devtools-link" @click=${revealRuleSetView}
461
- jslog=${VisualLogging.action('view-all-rules').track({click: true})}>
462
- ${i18nString(UIStrings.viewAllRules)}
463
- </button>
464
-
465
- <button class="link devtools-link" @click=${revealAttemptViewWithFilter}
466
- jslog=${VisualLogging.action('view-all-speculations').track({click: true})}>
467
- ${i18nString(UIStrings.viewAllSpeculations)}
468
- </button>
469
- </div>
470
- </div>
471
- </devtools-report-section>
472
- `;
473
- // clang-format on
474
- }
475
-
476
- #badgeSuccess(count?: number): Lit.LitTemplate {
477
- let message;
478
- if (count === undefined) {
479
- message = i18nString(UIStrings.badgeSuccess);
480
- } else {
481
- message = i18nString(UIStrings.badgeSuccessWithCount, {n: count});
482
- }
483
- return this.#badge('status-badge status-badge-success', 'check-circle', message);
484
- }
485
-
486
- #badgeFailure(count?: number): Lit.LitTemplate {
487
- let message;
488
- if (count === undefined) {
489
- message = i18nString(UIStrings.badgeFailure);
490
- } else {
491
- message = i18nString(UIStrings.badgeFailureWithCount, {n: count});
492
- }
493
- return this.#badge('status-badge status-badge-failure', 'cross-circle', message);
494
- }
495
-
496
- #badgeNeutral(message: string): Lit.LitTemplate {
497
- return this.#badge('status-badge status-badge-neutral', 'clear', message);
498
- }
499
-
500
- #badge(klass: string, iconName: string, message: string): Lit.LitTemplate {
501
- // Disabled until https://crbug.com/1079231 is fixed.
502
- // clang-format off
503
- return html`
504
- <span class=${klass}>
505
- <devtools-icon name=${iconName}></devtools-icon>
506
- <span>
507
- ${message}
508
- </span>
509
- </span>
510
- `;
511
- // clang-format on
512
- }
513
- }
514
-
515
- customElements.define('devtools-resources-used-preloading-view', UsedPreloadingView);
516
-
517
- declare global {
518
- interface HTMLElementTagNameMap {
519
- 'devtools-resources-used-preloading-view': UsedPreloadingView;
576
+ return {badges, revealRuleSetView, revealAttemptViewWithFilter};
520
577
  }
521
578
  }