mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 13:44:39 +08:00
This fixes up some places in code that ignored `encoded` flag from the result of `Network.getResponseBody` and similar CDP commands, instead making own assumptions based on "common sense" (whether it's text content type, whether it can be parsed as-is and so on). This works fine for Chromium either way because it upholds these assumptions, but technically it's a violation of the protocol and makes devtools app easily incompatible with other CDP implementations. Change-Id: Ifbd3ad487e6f39a75795b362cc3828466ba4f775 Reviewed-on: https://chromium-review.googlesource.com/c/1230042 Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Commit-Queue: Dmitry Gozman <dgozman@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#598318} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 5b046432f18e81cc58d32191c8a8ad150c8b74ad
48 lines
1.6 KiB
JavaScript
48 lines
1.6 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.
|
|
|
|
SourceFrame.PreviewFactory = class {
|
|
/**
|
|
* @param {!Common.ContentProvider} provider
|
|
* @param {string} mimeType
|
|
* @returns {!Promise<?UI.Widget>}
|
|
*/
|
|
static async createPreview(provider, mimeType) {
|
|
let resourceType = Common.ResourceType.fromMimeType(mimeType);
|
|
if (resourceType === Common.resourceTypes.Other)
|
|
resourceType = provider.contentType();
|
|
|
|
switch (resourceType) {
|
|
case Common.resourceTypes.Image:
|
|
return new SourceFrame.ImageView(mimeType, provider);
|
|
case Common.resourceTypes.Font:
|
|
return new SourceFrame.FontView(mimeType, provider);
|
|
}
|
|
|
|
let content = await provider.requestContent();
|
|
if (!content)
|
|
return new UI.EmptyWidget(Common.UIString('Nothing to preview'));
|
|
|
|
if (await provider.contentEncoded())
|
|
content = window.atob(content);
|
|
|
|
const parsedXML = SourceFrame.XMLView.parseXML(content, mimeType);
|
|
if (parsedXML)
|
|
return SourceFrame.XMLView.createSearchableView(parsedXML);
|
|
|
|
const jsonView = await SourceFrame.JSONView.createView(content);
|
|
if (jsonView)
|
|
return jsonView;
|
|
|
|
if (resourceType.isTextType()) {
|
|
const highlighterType =
|
|
provider.contentType().canonicalMimeType() || mimeType.replace(/;.*/, ''); // remove charset
|
|
return SourceFrame.ResourceSourceFrame.createSearchableView(
|
|
provider, highlighterType, true /* autoPrettyPrint */);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
};
|