| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.RequestPreviewView = class extends WebInspector.RequestContentView
{ | 34 Network.RequestPreviewView = class extends Network.RequestContentView { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.NetworkRequest} request | 36 * @param {!SDK.NetworkRequest} request |
| 37 * @param {!WebInspector.Widget} responseView | 37 * @param {!UI.Widget} responseView |
| 38 */ | 38 */ |
| 39 constructor(request, responseView) { | 39 constructor(request, responseView) { |
| 40 super(request); | 40 super(request); |
| 41 this._responseView = responseView; | 41 this._responseView = responseView; |
| 42 /** @type {?WebInspector.Widget} */ | 42 /** @type {?UI.Widget} */ |
| 43 this._previewView = null; | 43 this._previewView = null; |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * @override | 47 * @override |
| 48 */ | 48 */ |
| 49 contentLoaded() { | 49 contentLoaded() { |
| 50 if (!this.request.content && !this.request.contentError()) { | 50 if (!this.request.content && !this.request.contentError()) { |
| 51 if (!this._emptyWidget) { | 51 if (!this._emptyWidget) { |
| 52 this._emptyWidget = this._createEmptyWidget(); | 52 this._emptyWidget = this._createEmptyWidget(); |
| 53 this._emptyWidget.show(this.element); | 53 this._emptyWidget.show(this.element); |
| 54 this._previewView = this._emptyWidget; | 54 this._previewView = this._emptyWidget; |
| 55 } | 55 } |
| 56 return; | 56 return; |
| 57 } | 57 } |
| 58 if (this._emptyWidget) { | 58 if (this._emptyWidget) { |
| 59 this._emptyWidget.detach(); | 59 this._emptyWidget.detach(); |
| 60 delete this._emptyWidget; | 60 delete this._emptyWidget; |
| 61 this._previewView = null; | 61 this._previewView = null; |
| 62 } | 62 } |
| 63 | 63 |
| 64 if (!this._previewView) | 64 if (!this._previewView) |
| 65 this._createPreviewView(handlePreviewView.bind(this)); | 65 this._createPreviewView(handlePreviewView.bind(this)); |
| 66 else | 66 else |
| 67 this._previewView.show(this.element); | 67 this._previewView.show(this.element); |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * @param {!WebInspector.Widget} view | 70 * @param {!UI.Widget} view |
| 71 * @this {WebInspector.RequestPreviewView} | 71 * @this {Network.RequestPreviewView} |
| 72 */ | 72 */ |
| 73 function handlePreviewView(view) { | 73 function handlePreviewView(view) { |
| 74 this._previewView = view; | 74 this._previewView = view; |
| 75 view.show(this.element); | 75 view.show(this.element); |
| 76 if (view instanceof WebInspector.SimpleView) { | 76 if (view instanceof UI.SimpleView) { |
| 77 var toolbar = new WebInspector.Toolbar('network-item-preview-toolbar', t
his.element); | 77 var toolbar = new UI.Toolbar('network-item-preview-toolbar', this.elemen
t); |
| 78 for (var item of /** @type {!WebInspector.SimpleView} */ (this._previewV
iew).syncToolbarItems()) | 78 for (var item of /** @type {!UI.SimpleView} */ (this._previewView).syncT
oolbarItems()) |
| 79 toolbar.appendToolbarItem(item); | 79 toolbar.appendToolbarItem(item); |
| 80 } | 80 } |
| 81 this._previewViewHandledForTest(view); | 81 this._previewViewHandledForTest(view); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * @param {!WebInspector.Widget} view | 86 * @param {!UI.Widget} view |
| 87 */ | 87 */ |
| 88 _previewViewHandledForTest(view) { | 88 _previewViewHandledForTest(view) { |
| 89 } | 89 } |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * @return {!WebInspector.EmptyWidget} | 92 * @return {!UI.EmptyWidget} |
| 93 */ | 93 */ |
| 94 _createEmptyWidget() { | 94 _createEmptyWidget() { |
| 95 return this._createMessageView(WebInspector.UIString('This request has no pr
eview available.')); | 95 return this._createMessageView(Common.UIString('This request has no preview
available.')); |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * @param {string} message | 99 * @param {string} message |
| 100 * @return {!WebInspector.EmptyWidget} | 100 * @return {!UI.EmptyWidget} |
| 101 */ | 101 */ |
| 102 _createMessageView(message) { | 102 _createMessageView(message) { |
| 103 return new WebInspector.EmptyWidget(message); | 103 return new UI.EmptyWidget(message); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * @return {string} | 107 * @return {string} |
| 108 */ | 108 */ |
| 109 _requestContent() { | 109 _requestContent() { |
| 110 var content = this.request.content; | 110 var content = this.request.content; |
| 111 return this.request.contentEncoded ? window.atob(content || '') : (content |
| ''); | 111 return this.request.contentEncoded ? window.atob(content || '') : (content |
| ''); |
| 112 } | 112 } |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * @param {?WebInspector.ParsedJSON} parsedJSON | 115 * @param {?Network.ParsedJSON} parsedJSON |
| 116 * @return {?WebInspector.SearchableView} | 116 * @return {?UI.SearchableView} |
| 117 */ | 117 */ |
| 118 _jsonView(parsedJSON) { | 118 _jsonView(parsedJSON) { |
| 119 if (!parsedJSON || typeof parsedJSON.data !== 'object') | 119 if (!parsedJSON || typeof parsedJSON.data !== 'object') |
| 120 return null; | 120 return null; |
| 121 return WebInspector.JSONView.createSearchableView(/** @type {!WebInspector.P
arsedJSON} */ (parsedJSON)); | 121 return Network.JSONView.createSearchableView(/** @type {!Network.ParsedJSON}
*/ (parsedJSON)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * @return {?WebInspector.SearchableView} | 125 * @return {?UI.SearchableView} |
| 126 */ | 126 */ |
| 127 _xmlView() { | 127 _xmlView() { |
| 128 var parsedXML = WebInspector.XMLView.parseXML(this._requestContent(), this.r
equest.mimeType); | 128 var parsedXML = Network.XMLView.parseXML(this._requestContent(), this.reques
t.mimeType); |
| 129 return parsedXML ? WebInspector.XMLView.createSearchableView(parsedXML) : nu
ll; | 129 return parsedXML ? Network.XMLView.createSearchableView(parsedXML) : null; |
| 130 } | 130 } |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * @return {?WebInspector.RequestHTMLView} | 133 * @return {?Network.RequestHTMLView} |
| 134 */ | 134 */ |
| 135 _htmlErrorPreview() { | 135 _htmlErrorPreview() { |
| 136 var whitelist = ['text/html', 'text/plain', 'application/xhtml+xml']; | 136 var whitelist = ['text/html', 'text/plain', 'application/xhtml+xml']; |
| 137 if (whitelist.indexOf(this.request.mimeType) === -1) | 137 if (whitelist.indexOf(this.request.mimeType) === -1) |
| 138 return null; | 138 return null; |
| 139 | 139 |
| 140 var dataURL = this.request.asDataURL(); | 140 var dataURL = this.request.asDataURL(); |
| 141 if (dataURL === null) | 141 if (dataURL === null) |
| 142 return null; | 142 return null; |
| 143 | 143 |
| 144 return new WebInspector.RequestHTMLView(this.request, dataURL); | 144 return new Network.RequestHTMLView(this.request, dataURL); |
| 145 } | 145 } |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * @param {function(!WebInspector.Widget)} callback | 148 * @param {function(!UI.Widget)} callback |
| 149 */ | 149 */ |
| 150 _createPreviewView(callback) { | 150 _createPreviewView(callback) { |
| 151 if (this.request.contentError()) { | 151 if (this.request.contentError()) { |
| 152 callback(this._createMessageView(WebInspector.UIString('Failed to load res
ponse data'))); | 152 callback(this._createMessageView(Common.UIString('Failed to load response
data'))); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 | 155 |
| 156 var xmlView = this._xmlView(); | 156 var xmlView = this._xmlView(); |
| 157 if (xmlView) { | 157 if (xmlView) { |
| 158 callback(xmlView); | 158 callback(xmlView); |
| 159 return; | 159 return; |
| 160 } | 160 } |
| 161 | 161 |
| 162 WebInspector.JSONView.parseJSON(this._requestContent()).then(chooseView.bind
(this)).then(callback); | 162 Network.JSONView.parseJSON(this._requestContent()).then(chooseView.bind(this
)).then(callback); |
| 163 | 163 |
| 164 /** | 164 /** |
| 165 * @this {WebInspector.RequestPreviewView} | 165 * @this {Network.RequestPreviewView} |
| 166 * @param {?WebInspector.ParsedJSON} jsonData | 166 * @param {?Network.ParsedJSON} jsonData |
| 167 * @return {!WebInspector.Widget} | 167 * @return {!UI.Widget} |
| 168 */ | 168 */ |
| 169 function chooseView(jsonData) { | 169 function chooseView(jsonData) { |
| 170 if (jsonData) { | 170 if (jsonData) { |
| 171 var jsonView = this._jsonView(jsonData); | 171 var jsonView = this._jsonView(jsonData); |
| 172 if (jsonView) | 172 if (jsonView) |
| 173 return jsonView; | 173 return jsonView; |
| 174 } | 174 } |
| 175 | 175 |
| 176 if (this.request.hasErrorStatusCode() || this.request.resourceType() === W
ebInspector.resourceTypes.XHR) { | 176 if (this.request.hasErrorStatusCode() || this.request.resourceType() === C
ommon.resourceTypes.XHR) { |
| 177 var htmlErrorPreview = this._htmlErrorPreview(); | 177 var htmlErrorPreview = this._htmlErrorPreview(); |
| 178 if (htmlErrorPreview) | 178 if (htmlErrorPreview) |
| 179 return htmlErrorPreview; | 179 return htmlErrorPreview; |
| 180 } | 180 } |
| 181 | 181 |
| 182 if (this._responseView.sourceView) | 182 if (this._responseView.sourceView) |
| 183 return this._responseView.sourceView; | 183 return this._responseView.sourceView; |
| 184 | 184 |
| 185 if (this.request.resourceType() === WebInspector.resourceTypes.Other) | 185 if (this.request.resourceType() === Common.resourceTypes.Other) |
| 186 return this._createEmptyWidget(); | 186 return this._createEmptyWidget(); |
| 187 | 187 |
| 188 return WebInspector.RequestView.nonSourceViewForRequest(this.request); | 188 return Network.RequestView.nonSourceViewForRequest(this.request); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 }; | 191 }; |
| OLD | NEW |