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 |