Commit 0a9c4fe3 authored by Eugene Ostroukhov's avatar Eugene Ostroukhov Committed by Commit Bot

DevTools: restore HTML preview

Network panel will now preview all HTML responses.

Bug: 785050
Change-Id: I79b3c22300a4f132bf1b3e4842c06f291249a09d
Reviewed-on: https://chromium-review.googlesource.com/896367
Commit-Queue: Eugene Ostroukhov <eostroukhov@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533711}
parent d6326484
......@@ -69,10 +69,10 @@ Testing with MimeType: text/plain, and StatusCode: 200
Content: This
<b>is a </b><br /><br />test.
ResourceType(xhr): _SearchableContainer > SearchableView > widget vbox
ResourceType(fetch): _SearchableContainer > SearchableView > widget vbox
ResourceType(document): _SearchableContainer > SearchableView > widget vbox
ResourceType(other): _SearchableContainer > SearchableView > widget vbox
ResourceType(xhr): widget vbox html request-view
ResourceType(fetch): widget vbox html request-view
ResourceType(document): widget vbox html request-view
ResourceType(other): widget vbox html request-view
XML With Unknown MIME
Testing with MimeType: text/foobar, and StatusCode: 200
......
......@@ -2,12 +2,8 @@ Tests that resources with JSON MIME types are previewed with the JSON viewer.
Running: plainTextTest
Is Searchable: true
Type: ResourceSourceFrame
Should have found and highlighted all: foo
Normal search found 0 results in dom.
CodeMirror search found 2 results in dom.
Is Searchable: false
Type: RequestHTMLView
Running: jsonTest
Is Searchable: true
......
......@@ -54,22 +54,22 @@ Network.RequestPreviewView = class extends Network.RequestResponseView {
/**
* @return {!Promise<?UI.Widget>}
*/
async _htmlErrorPreview() {
async _htmlPreview() {
var contentData = await this.request.contentData();
if (contentData.error)
return new UI.EmptyWidget(Common.UIString('Failed to load response data'));
// We can assume the status code has been set already because fetching contentData should wait for request to be
// finished.
if (!this.request.hasErrorStatusCode())
return null;
var whitelist = new Set(['text/html', 'text/plain', 'application/xhtml+xml']);
if (!whitelist.has(this.request.mimeType))
return null;
var encodedContent = contentData.encoded ? contentData.content : btoa(contentData.content);
var dataURL = Common.ContentProvider.contentAsDataURL(encodedContent, this.request.mimeType, true, 'utf-8');
// http://crbug.com/767393 - DevTools should recognize JSON regardless of the content type
var jsonView = await SourceFrame.JSONView.createView(contentData.content);
if (jsonView)
return jsonView;
var dataURL = Common.ContentProvider.contentAsDataURL(
contentData.content, this.request.mimeType, contentData.encoded, contentData.encoded ? 'utf-8' : null);
return dataURL ? new Network.RequestHTMLView(dataURL) : null;
}
......@@ -78,7 +78,7 @@ Network.RequestPreviewView = class extends Network.RequestResponseView {
* @return {!Promise<!UI.Widget>}
*/
async createPreview() {
var htmlErrorPreview = await this._htmlErrorPreview();
var htmlErrorPreview = await this._htmlPreview();
if (htmlErrorPreview)
return htmlErrorPreview;
......
......@@ -169,11 +169,11 @@ Network.ResourceWebSocketFrameView = class extends UI.VBox {
this._currentSelectedNode = selectedNode;
var contentProvider = selectedNode.contentProvider();
var content = await contentProvider.requestContent();
var parsedJSON = await SourceFrame.JSONView.parseJSON(content);
var jsonView = await SourceFrame.JSONView.createView(content);
if (this._currentSelectedNode !== selectedNode)
return;
if (parsedJSON)
this._splitWidget.setSidebarWidget(SourceFrame.JSONView.createSearchableView(parsedJSON));
if (jsonView)
this._splitWidget.setSidebarWidget(jsonView);
else
this._splitWidget.setSidebarWidget(new SourceFrame.ResourceSourceFrame(contentProvider));
}
......
......@@ -29,7 +29,6 @@
*/
/**
* @implements {UI.Searchable}
* @unrestricted
*/
SourceFrame.JSONView = class extends UI.VBox {
/**
......@@ -37,6 +36,7 @@ SourceFrame.JSONView = class extends UI.VBox {
*/
constructor(parsedJSON) {
super();
this._initialized = false;
this.registerRequiredCSS('source_frame/jsonView.css');
this._parsedJSON = parsedJSON;
this.element.classList.add('json-view');
......@@ -54,10 +54,15 @@ SourceFrame.JSONView = class extends UI.VBox {
}
/**
* @param {!SourceFrame.ParsedJSON} parsedJSON
* @return {!UI.SearchableView}
* @param {string} content
* @return {!Promise<?SourceFrame.JSONView>}
*/
static createSearchableView(parsedJSON) {
static async createView(content) {
// We support non-strict JSON parsing by parsing an AST tree which is why we offload it to a worker.
var parsedJSON = await SourceFrame.JSONView._parseJSON(content);
if (!parsedJSON || typeof parsedJSON.data !== 'object')
return null;
var jsonView = new SourceFrame.JSONView(parsedJSON);
var searchableView = new UI.SearchableView(jsonView);
searchableView.setPlaceholder(Common.UIString('Find'));
......@@ -71,7 +76,7 @@ SourceFrame.JSONView = class extends UI.VBox {
* @param {?string} text
* @return {!Promise<?SourceFrame.ParsedJSON>}
*/
static parseJSON(text) {
static _parseJSON(text) {
var returnObj = null;
if (text)
returnObj = SourceFrame.JSONView._extractJSON(/** @type {string} */ (text));
......
......@@ -28,10 +28,9 @@ SourceFrame.PreviewFactory = class {
if (parsedXML)
return SourceFrame.XMLView.createSearchableView(parsedXML);
// We support non-strict JSON parsing by parsing an AST tree which is why we offload it to a worker.
var parsedJSON = await SourceFrame.JSONView.parseJSON(content);
if (parsedJSON && typeof parsedJSON.data === 'object')
return SourceFrame.JSONView.createSearchableView(/** @type {!SourceFrame.ParsedJSON} */ (parsedJSON));
var jsonView = await SourceFrame.JSONView.createView(content);
if (jsonView)
return jsonView;
if (resourceType.isTextType()) {
var highlighterType =
......
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