| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 this._emptyWidget = this._createEmptyWidget(); | 48 this._emptyWidget = this._createEmptyWidget(); |
| 49 this._emptyWidget.show(this.element); | 49 this._emptyWidget.show(this.element); |
| 50 this.innerView = this._emptyWidget; | 50 this.innerView = this._emptyWidget; |
| 51 } | 51 } |
| 52 } else { | 52 } else { |
| 53 if (this._emptyWidget) { | 53 if (this._emptyWidget) { |
| 54 this._emptyWidget.detach(); | 54 this._emptyWidget.detach(); |
| 55 delete this._emptyWidget; | 55 delete this._emptyWidget; |
| 56 } | 56 } |
| 57 | 57 |
| 58 if (!this._previewView) { | 58 if (!this._previewView) |
| 59 this._previewView = this._createPreviewView(); | 59 this._createPreviewView(handlePreviewView.bind(this)); |
| 60 this._previewView.show(this.element); | 60 else |
| 61 if (this._previewView instanceof WebInspector.VBoxWithToolbarIte
ms) { | 61 this.innerView = this._previewView; |
| 62 var toolbar = new WebInspector.Toolbar("network-item-preview
-toolbar", this.element); | 62 } |
| 63 for (var item of /** @type {!WebInspector.VBoxWithToolbarIte
ms} */ (this._previewView).toolbarItems()) | 63 |
| 64 toolbar.appendToolbarItem(item); | 64 /** |
| 65 } | 65 * @param {!WebInspector.Widget} view |
| 66 * @this {WebInspector.RequestPreviewView} |
| 67 */ |
| 68 function handlePreviewView(view) { |
| 69 this._previewView = view; |
| 70 this._previewView.show(this.element); |
| 71 if (this._previewView instanceof WebInspector.VBoxWithToolbarItems)
{ |
| 72 var toolbar = new WebInspector.Toolbar("network-item-preview-too
lbar", this.element); |
| 73 for (var item of /** @type {!WebInspector.VBoxWithToolbarItems}
*/ (this._previewView).toolbarItems()) |
| 74 toolbar.appendToolbarItem(item); |
| 66 } | 75 } |
| 67 this.innerView = this._previewView; | 76 this.innerView = this._previewView; |
| 68 } | 77 } |
| 69 }, | 78 }, |
| 70 | 79 |
| 71 _createEmptyWidget: function() | 80 _createEmptyWidget: function() |
| 72 { | 81 { |
| 73 return this._createMessageView(WebInspector.UIString("This request has n
o preview available.")); | 82 return this._createMessageView(WebInspector.UIString("This request has n
o preview available.")); |
| 74 }, | 83 }, |
| 75 | 84 |
| 76 /** | 85 /** |
| 77 * @param {string} message | 86 * @param {string} message |
| 78 * @return {!WebInspector.EmptyWidget} | 87 * @return {!WebInspector.EmptyWidget} |
| 79 */ | 88 */ |
| 80 _createMessageView: function(message) | 89 _createMessageView: function(message) |
| 81 { | 90 { |
| 82 return new WebInspector.EmptyWidget(message); | 91 return new WebInspector.EmptyWidget(message); |
| 83 }, | 92 }, |
| 84 | 93 |
| 85 /** | 94 /** |
| 86 * @return {string} | 95 * @return {string} |
| 87 */ | 96 */ |
| 88 _requestContent: function() | 97 _requestContent: function() |
| 89 { | 98 { |
| 90 var content = this.request.content; | 99 var content = this.request.content; |
| 91 return this.request.contentEncoded ? window.atob(content || "") : (conte
nt || ""); | 100 return this.request.contentEncoded ? window.atob(content || "") : (conte
nt || ""); |
| 92 }, | 101 }, |
| 93 | 102 |
| 94 /** | 103 /** |
| 104 * @param {?WebInspector.ParsedJSON} parsedJSON |
| 95 * @return {?WebInspector.JSONView} | 105 * @return {?WebInspector.JSONView} |
| 96 */ | 106 */ |
| 97 _jsonView: function() | 107 _jsonView: function(parsedJSON) |
| 98 { | 108 { |
| 99 var parsedJSON = WebInspector.JSONView.parseJSON(this._requestContent())
; | 109 if (!parsedJSON || typeof parsedJSON.data !== "object") |
| 100 return parsedJSON && new WebInspector.JSONView(parsedJSON); | 110 return null; |
| 111 return new WebInspector.JSONView(/** @type {!WebInspector.ParsedJSON} */
(parsedJSON)); |
| 101 }, | 112 }, |
| 102 | 113 |
| 103 /** | 114 /** |
| 104 * @return {?WebInspector.XMLView} | 115 * @return {?WebInspector.XMLView} |
| 105 */ | 116 */ |
| 106 _xmlView: function() | 117 _xmlView: function() |
| 107 { | 118 { |
| 108 var content = this._requestContent(); | 119 var content = this._requestContent(); |
| 109 var parsedXML = WebInspector.XMLView.parseXML(content, this.request.mime
Type); | 120 var parsedXML = WebInspector.XMLView.parseXML(content, this.request.mime
Type); |
| 110 return parsedXML ? new WebInspector.XMLView(parsedXML) : null; | 121 return parsedXML ? new WebInspector.XMLView(parsedXML) : null; |
| 111 }, | 122 }, |
| 112 | 123 |
| 113 /** | 124 /** |
| 114 * @return {?WebInspector.RequestHTMLView} | 125 * @return {?WebInspector.RequestHTMLView} |
| 115 */ | 126 */ |
| 116 _htmlErrorPreview: function() | 127 _htmlErrorPreview: function() |
| 117 { | 128 { |
| 118 var whitelist = ["text/html", "text/plain", "application/xhtml+xml"]; | 129 var whitelist = ["text/html", "text/plain", "application/xhtml+xml"]; |
| 119 if (whitelist.indexOf(this.request.mimeType) === -1) | 130 if (whitelist.indexOf(this.request.mimeType) === -1) |
| 120 return null; | 131 return null; |
| 121 | 132 |
| 122 var dataURL = this.request.asDataURL(); | 133 var dataURL = this.request.asDataURL(); |
| 123 if (dataURL === null) | 134 if (dataURL === null) |
| 124 return null; | 135 return null; |
| 125 | 136 |
| 126 return new WebInspector.RequestHTMLView(this.request, dataURL); | 137 return new WebInspector.RequestHTMLView(this.request, dataURL); |
| 127 }, | 138 }, |
| 128 | 139 |
| 129 _createPreviewView: function() | 140 /** |
| 141 * @param {function(!WebInspector.Widget)} callback |
| 142 */ |
| 143 _createPreviewView: function(callback) |
| 130 { | 144 { |
| 131 if (this.request.contentError()) | 145 if (this.request.contentError()) { |
| 132 return this._createMessageView(WebInspector.UIString("Failed to load
response data")); | 146 callback(this._createMessageView(WebInspector.UIString("Failed to lo
ad response data"))); |
| 133 | 147 return; |
| 134 var mimeType = this.request.mimeType || ""; | |
| 135 if (mimeType.endsWith("json") || mimeType.endsWith("javascript")) { | |
| 136 var jsonView = this._jsonView(); | |
| 137 if (jsonView) | |
| 138 return jsonView; | |
| 139 } | |
| 140 | |
| 141 if (this.request.hasErrorStatusCode()) { | |
| 142 var htmlErrorPreview = this._htmlErrorPreview(); | |
| 143 if (htmlErrorPreview) | |
| 144 return htmlErrorPreview; | |
| 145 } | 148 } |
| 146 | 149 |
| 147 var xmlView = this._xmlView(); | 150 var xmlView = this._xmlView(); |
| 148 if (xmlView) | 151 if (xmlView) |
| 149 return xmlView; | 152 return xmlView; |
| 150 | 153 |
| 151 if (this.request.resourceType() === WebInspector.resourceTypes.XHR) { | 154 WebInspector.JSONView.parseJSON(this._requestContent()).then(chooseView.
bind(this)).then(callback); |
| 152 var jsonView = this._jsonView(); | 155 |
| 153 if (jsonView) | 156 /** |
| 154 return jsonView; | 157 * @this {WebInspector.RequestPreviewView} |
| 155 var htmlErrorPreview = this._htmlErrorPreview(); | 158 * @param {?WebInspector.ParsedJSON} jsonData |
| 156 if (htmlErrorPreview) | 159 * @return {!WebInspector.Widget} |
| 157 return htmlErrorPreview; | 160 */ |
| 161 function chooseView(jsonData) |
| 162 { |
| 163 if (jsonData) { |
| 164 var jsonView = this._jsonView(jsonData); |
| 165 if (jsonView) |
| 166 return jsonView; |
| 167 } |
| 168 |
| 169 if (this.request.hasErrorStatusCode() || this.request.resourceType()
=== WebInspector.resourceTypes.XHR) { |
| 170 var htmlErrorPreview = this._htmlErrorPreview(); |
| 171 if (htmlErrorPreview) |
| 172 return htmlErrorPreview; |
| 173 } |
| 174 |
| 175 if (this._responseView.sourceView) |
| 176 return this._responseView.sourceView; |
| 177 |
| 178 if (this.request.resourceType() === WebInspector.resourceTypes.Other
) |
| 179 return this._createEmptyWidget(); |
| 180 |
| 181 return WebInspector.RequestView.nonSourceViewForRequest(this.request
); |
| 158 } | 182 } |
| 159 | |
| 160 if (this._responseView.sourceView) | |
| 161 return this._responseView.sourceView; | |
| 162 | |
| 163 if (this.request.resourceType() === WebInspector.resourceTypes.Other) | |
| 164 return this._createEmptyWidget(); | |
| 165 | |
| 166 return WebInspector.RequestView.nonSourceViewForRequest(this.request); | |
| 167 }, | 183 }, |
| 168 | 184 |
| 169 __proto__: WebInspector.RequestContentView.prototype | 185 __proto__: WebInspector.RequestContentView.prototype |
| 170 } | 186 } |
| OLD | NEW |