Commit 000b1305 authored by Eugene Ostroukhov's avatar Eugene Ostroukhov Committed by Commit Bot

DevTools: improve preview content type detection

1. Preview will now attempt to deduce content type from the mime type
   and not the resource type. Images loaded via fetch will now be
   properly shown.
2. "Response" type will now recognize SVG as a text file and show the
   source code.

Bug: 688563
Change-Id: Ie0ec2e46314e0d71ecc69e0517984bcdb3a2f755
Reviewed-on: https://chromium-review.googlesource.com/837731Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Eugene Ostroukhov <eostroukhov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526076}
parent 23f31a4e
......@@ -105,10 +105,10 @@ Binary Image File
Testing with MimeType: image/png, and StatusCode: 200
Content: Bin**NULL**ary File**NULL****NULL**
ResourceType(xhr): SearchableView > widget vbox
ResourceType(fetch): SearchableView > widget vbox
ResourceType(document): SearchableView > widget vbox
ResourceType(other): SearchableView > widget vbox
ResourceType(xhr): widget vbox image-view
ResourceType(fetch): widget vbox image-view
ResourceType(document): widget vbox image-view
ResourceType(other): widget vbox image-view
Binary Blank Image File
Testing with MimeType: image/png, and StatusCode: 200
......
......@@ -47,11 +47,17 @@ Network.RequestResponseView = class extends UI.VBox {
* @return {boolean}
*/
static _hasTextContent(request, contentData) {
if (request.resourceType().isTextType())
var mimeType = request.mimeType;
var resourceType = Common.ResourceType.fromMimeType(mimeType);
if (resourceType === Common.resourceTypes.Other)
resourceType = request.contentType();
if (resourceType === Common.resourceTypes.Image)
return mimeType.startsWith('image/svg');
if (resourceType.isTextType())
return true;
if (contentData.error)
return false;
if (request.resourceType() === Common.resourceTypes.Other)
if (resourceType === Common.resourceTypes.Other)
return !!contentData.content && !contentData.encoded;
return false;
}
......
......@@ -13,6 +13,17 @@ SourceFrame.PreviewFactory = class {
if (!content)
return new UI.EmptyWidget(Common.UIString('Nothing to preview'));
var 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);
}
var parsedXML = SourceFrame.XMLView.parseXML(content, mimeType);
if (parsedXML)
return SourceFrame.XMLView.createSearchableView(parsedXML);
......@@ -22,19 +33,11 @@ SourceFrame.PreviewFactory = class {
if (parsedJSON && typeof parsedJSON.data === 'object')
return SourceFrame.JSONView.createSearchableView(/** @type {!SourceFrame.ParsedJSON} */ (parsedJSON));
var resourceType = provider.contentType() || Common.resourceTypes.Other;
if (resourceType.isTextType()) {
var highlighterType = mimeType.replace(/;.*/, ''); // remove charset
return SourceFrame.ResourceSourceFrame.createSearchableView(provider, highlighterType);
}
switch (resourceType) {
case Common.resourceTypes.Image:
return new SourceFrame.ImageView(mimeType, provider);
case Common.resourceTypes.Font:
return new SourceFrame.FontView(mimeType, provider);
}
return null;
}
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment