Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Unified Diff: third_party/WebKit/Source/devtools/front_end/network/RequestPreviewView.js

Issue 1912973002: [DevTools] JSONView parsing smarter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/network/RequestPreviewView.js
diff --git a/third_party/WebKit/Source/devtools/front_end/network/RequestPreviewView.js b/third_party/WebKit/Source/devtools/front_end/network/RequestPreviewView.js
index cb3e8be6b8615b270084d9e8a78cbedd2ffd3d4b..c09084858f60b23a5b83d39d81f8ac866edc3435 100644
--- a/third_party/WebKit/Source/devtools/front_end/network/RequestPreviewView.js
+++ b/third_party/WebKit/Source/devtools/front_end/network/RequestPreviewView.js
@@ -55,14 +55,23 @@ WebInspector.RequestPreviewView.prototype = {
delete this._emptyWidget;
}
- if (!this._previewView) {
- this._previewView = this._createPreviewView();
- this._previewView.show(this.element);
- if (this._previewView instanceof WebInspector.VBoxWithToolbarItems) {
- var toolbar = new WebInspector.Toolbar("network-item-preview-toolbar", this.element);
- for (var item of /** @type {!WebInspector.VBoxWithToolbarItems} */ (this._previewView).toolbarItems())
- toolbar.appendToolbarItem(item);
- }
+ if (!this._previewView)
+ this._createPreviewView(handlePreviewView.bind(this));
+ else
+ this.innerView = this._previewView;
+ }
+
+ /**
+ * @param {!WebInspector.Widget} view
+ * @this {WebInspector.RequestPreviewView}
+ */
+ function handlePreviewView(view) {
+ this._previewView = view;
+ this._previewView.show(this.element);
+ if (this._previewView instanceof WebInspector.VBoxWithToolbarItems) {
+ var toolbar = new WebInspector.Toolbar("network-item-preview-toolbar", this.element);
+ for (var item of /** @type {!WebInspector.VBoxWithToolbarItems} */ (this._previewView).toolbarItems())
+ toolbar.appendToolbarItem(item);
}
this.innerView = this._previewView;
}
@@ -92,12 +101,14 @@ WebInspector.RequestPreviewView.prototype = {
},
/**
+ * @param {?WebInspector.ParsedJSON} parsedJSON
* @return {?WebInspector.JSONView}
*/
- _jsonView: function()
+ _jsonView: function(parsedJSON)
{
- var parsedJSON = WebInspector.JSONView.parseJSON(this._requestContent());
- return parsedJSON && new WebInspector.JSONView(parsedJSON);
+ if (!parsedJSON || typeof parsedJSON.data !== "object")
+ return null;
+ return new WebInspector.JSONView(/** @type {!WebInspector.ParsedJSON} */ (parsedJSON));
},
/**
@@ -126,44 +137,49 @@ WebInspector.RequestPreviewView.prototype = {
return new WebInspector.RequestHTMLView(this.request, dataURL);
},
- _createPreviewView: function()
+ /**
+ * @param {function(!WebInspector.Widget)} callback
+ */
+ _createPreviewView: function(callback)
{
- if (this.request.contentError())
- return this._createMessageView(WebInspector.UIString("Failed to load response data"));
-
- var mimeType = this.request.mimeType || "";
- if (mimeType.endsWith("json") || mimeType.endsWith("javascript")) {
- var jsonView = this._jsonView();
- if (jsonView)
- return jsonView;
- }
-
- if (this.request.hasErrorStatusCode()) {
- var htmlErrorPreview = this._htmlErrorPreview();
- if (htmlErrorPreview)
- return htmlErrorPreview;
+ if (this.request.contentError()) {
+ callback(this._createMessageView(WebInspector.UIString("Failed to load response data")));
+ return;
}
var xmlView = this._xmlView();
if (xmlView)
return xmlView;
- if (this.request.resourceType() === WebInspector.resourceTypes.XHR) {
- var jsonView = this._jsonView();
- if (jsonView)
- return jsonView;
- var htmlErrorPreview = this._htmlErrorPreview();
- if (htmlErrorPreview)
- return htmlErrorPreview;
- }
+ WebInspector.JSONView.parseJSON(this._requestContent()).then(chooseView.bind(this)).then(callback);
+
+ /**
+ * @this {WebInspector.RequestPreviewView}
+ * @param {?WebInspector.ParsedJSON} jsonData
+ * @return {!WebInspector.Widget}
+ */
+ function chooseView(jsonData)
+ {
+ if (jsonData) {
+ var jsonView = this._jsonView(jsonData);
+ if (jsonView)
+ return jsonView;
+ }
- if (this._responseView.sourceView)
- return this._responseView.sourceView;
+ if (this.request.hasErrorStatusCode() || this.request.resourceType() === WebInspector.resourceTypes.XHR) {
+ var htmlErrorPreview = this._htmlErrorPreview();
+ if (htmlErrorPreview)
+ return htmlErrorPreview;
+ }
+
+ if (this._responseView.sourceView)
+ return this._responseView.sourceView;
- if (this.request.resourceType() === WebInspector.resourceTypes.Other)
- return this._createEmptyWidget();
+ if (this.request.resourceType() === WebInspector.resourceTypes.Other)
+ return this._createEmptyWidget();
- return WebInspector.RequestView.nonSourceViewForRequest(this.request);
+ return WebInspector.RequestView.nonSourceViewForRequest(this.request);
+ }
},
__proto__: WebInspector.RequestContentView.prototype

Powered by Google App Engine
This is Rietveld 408576698