mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 17:27:22 +08:00
PreviewFactory.js const highlighterType is being set as 1 of 2 variables but the order in which it checked these variables was incorrect. The current mimeType should be checked prior to the canonicalMimeType9(). Reversed the order. FormatterWorker.js Directly visited minified asset files are given a mimeType of application/javascript on page load. On our FormatterWorker file, we did not have a case that would format this mimeType. Added the mimeType of ‘application/javascript’ to our switch statement allowing it to format with the same settings currently set on mimeType ‘text/javascript’. Pretty printing of directly visited minified asset files did not work on both tabs. https://www.loom.com/share/e127dff2f6bf41b4bce00e6b0ed9c55f R=jacktfranklin@chromium.org Fixed: 1019785 Change-Id: Ib43e9c255129da95492bdfeaba7651964685626f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2572038 Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
// Copyright 2017 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as Common from '../common/common.js';
|
|
import * as TextUtils from '../text_utils/text_utils.js'; // eslint-disable-line no-unused-vars
|
|
import * as UI from '../ui/ui.js';
|
|
|
|
import {FontView} from './FontView.js';
|
|
import {ImageView} from './ImageView.js';
|
|
import {JSONView} from './JSONView.js';
|
|
import {ResourceSourceFrame} from './ResourceSourceFrame.js';
|
|
import {XMLView} from './XMLView.js';
|
|
|
|
export class PreviewFactory {
|
|
/**
|
|
* @param {!TextUtils.ContentProvider.ContentProvider} provider
|
|
* @param {string} mimeType
|
|
* @returns {!Promise<?UI.Widget.Widget>}
|
|
*/
|
|
static async createPreview(provider, mimeType) {
|
|
let resourceType = Common.ResourceType.ResourceType.fromMimeType(mimeType);
|
|
if (resourceType === Common.ResourceType.resourceTypes.Other) {
|
|
resourceType = provider.contentType();
|
|
}
|
|
|
|
switch (resourceType) {
|
|
case Common.ResourceType.resourceTypes.Image:
|
|
return new ImageView(mimeType, provider);
|
|
case Common.ResourceType.resourceTypes.Font:
|
|
return new FontView(mimeType, provider);
|
|
}
|
|
|
|
const deferredContent = await provider.requestContent();
|
|
if (deferredContent.content === null) {
|
|
return new UI.EmptyWidget.EmptyWidget(deferredContent.error);
|
|
}
|
|
if (!deferredContent.content) {
|
|
return new UI.EmptyWidget.EmptyWidget(Common.UIString.UIString('Nothing to preview'));
|
|
}
|
|
|
|
let content = deferredContent.content;
|
|
if (await provider.contentEncoded()) {
|
|
content = window.atob(content);
|
|
}
|
|
|
|
const parsedXML = XMLView.parseXML(content, mimeType);
|
|
if (parsedXML) {
|
|
return XMLView.createSearchableView(parsedXML);
|
|
}
|
|
|
|
const jsonView = await JSONView.createView(content);
|
|
if (jsonView) {
|
|
return jsonView;
|
|
}
|
|
|
|
if (resourceType.isTextType()) {
|
|
const highlighterType =
|
|
mimeType.replace(/;.*/, '') /* remove charset */ || provider.contentType().canonicalMimeType();
|
|
return ResourceSourceFrame.createSearchableView(provider, highlighterType, true /* autoPrettyPrint */);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|