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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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
31 /** 30 /**
32 * @constructor 31 * @unrestricted
33 * @extends {WebInspector.RequestContentView}
34 * @param {!WebInspector.NetworkRequest} request
35 * @param {!WebInspector.Widget} responseView
36 */ 32 */
37 WebInspector.RequestPreviewView = function(request, responseView) 33 WebInspector.RequestPreviewView = class extends WebInspector.RequestContentView {
38 { 34 /**
39 WebInspector.RequestContentView.call(this, request); 35 * @param {!WebInspector.NetworkRequest} request
36 * @param {!WebInspector.Widget} responseView
37 */
38 constructor(request, responseView) {
39 super(request);
40 this._responseView = responseView; 40 this._responseView = responseView;
41 /** @type {?WebInspector.Widget} */ 41 /** @type {?WebInspector.Widget} */
42 this._previewView = null; 42 this._previewView = null;
43 }; 43 }
44 44
45 WebInspector.RequestPreviewView.prototype = { 45 /**
46 contentLoaded: function() 46 * @override
47 { 47 */
48 if (!this.request.content && !this.request.contentError()) { 48 contentLoaded() {
49 if (!this._emptyWidget) { 49 if (!this.request.content && !this.request.contentError()) {
50 this._emptyWidget = this._createEmptyWidget(); 50 if (!this._emptyWidget) {
51 this._emptyWidget.show(this.element); 51 this._emptyWidget = this._createEmptyWidget();
52 this._previewView = this._emptyWidget; 52 this._emptyWidget.show(this.element);
53 } 53 this._previewView = this._emptyWidget;
54 return; 54 }
55 } 55 return;
56 if (this._emptyWidget) { 56 }
57 this._emptyWidget.detach(); 57 if (this._emptyWidget) {
58 delete this._emptyWidget; 58 this._emptyWidget.detach();
59 this._previewView = null; 59 delete this._emptyWidget;
60 } 60 this._previewView = null;
61 }
61 62
62 if (!this._previewView) 63 if (!this._previewView)
63 this._createPreviewView(handlePreviewView.bind(this)); 64 this._createPreviewView(handlePreviewView.bind(this));
64 else 65 else
65 this._previewView.show(this.element); 66 this._previewView.show(this.element);
66
67 /**
68 * @param {!WebInspector.Widget} view
69 * @this {WebInspector.RequestPreviewView}
70 */
71 function handlePreviewView(view)
72 {
73 this._previewView = view;
74 view.show(this.element);
75 if (view instanceof WebInspector.SimpleView) {
76 var toolbar = new WebInspector.Toolbar("network-item-preview-too lbar", this.element);
77 for (var item of /** @type {!WebInspector.SimpleView} */ (this._ previewView).syncToolbarItems())
78 toolbar.appendToolbarItem(item);
79 }
80 this._previewViewHandledForTest(view);
81 }
82 },
83 67
84 /** 68 /**
85 * @param {!WebInspector.Widget} view 69 * @param {!WebInspector.Widget} view
70 * @this {WebInspector.RequestPreviewView}
86 */ 71 */
87 _previewViewHandledForTest: function(view) { }, 72 function handlePreviewView(view) {
73 this._previewView = view;
74 view.show(this.element);
75 if (view instanceof WebInspector.SimpleView) {
76 var toolbar = new WebInspector.Toolbar('network-item-preview-toolbar', t his.element);
77 for (var item of /** @type {!WebInspector.SimpleView} */ (this._previewV iew).syncToolbarItems())
78 toolbar.appendToolbarItem(item);
79 }
80 this._previewViewHandledForTest(view);
81 }
82 }
83
84 /**
85 * @param {!WebInspector.Widget} view
86 */
87 _previewViewHandledForTest(view) {
88 }
89
90 /**
91 * @return {!WebInspector.EmptyWidget}
92 */
93 _createEmptyWidget() {
94 return this._createMessageView(WebInspector.UIString('This request has no pr eview available.'));
95 }
96
97 /**
98 * @param {string} message
99 * @return {!WebInspector.EmptyWidget}
100 */
101 _createMessageView(message) {
102 return new WebInspector.EmptyWidget(message);
103 }
104
105 /**
106 * @return {string}
107 */
108 _requestContent() {
109 var content = this.request.content;
110 return this.request.contentEncoded ? window.atob(content || '') : (content | | '');
111 }
112
113 /**
114 * @param {?WebInspector.ParsedJSON} parsedJSON
115 * @return {?WebInspector.SearchableView}
116 */
117 _jsonView(parsedJSON) {
118 if (!parsedJSON || typeof parsedJSON.data !== 'object')
119 return null;
120 return WebInspector.JSONView.createSearchableView(/** @type {!WebInspector.P arsedJSON} */ (parsedJSON));
121 }
122
123 /**
124 * @return {?WebInspector.SearchableView}
125 */
126 _xmlView() {
127 var parsedXML = WebInspector.XMLView.parseXML(this._requestContent(), this.r equest.mimeType);
128 return parsedXML ? WebInspector.XMLView.createSearchableView(parsedXML) : nu ll;
129 }
130
131 /**
132 * @return {?WebInspector.RequestHTMLView}
133 */
134 _htmlErrorPreview() {
135 var whitelist = ['text/html', 'text/plain', 'application/xhtml+xml'];
136 if (whitelist.indexOf(this.request.mimeType) === -1)
137 return null;
138
139 var dataURL = this.request.asDataURL();
140 if (dataURL === null)
141 return null;
142
143 return new WebInspector.RequestHTMLView(this.request, dataURL);
144 }
145
146 /**
147 * @param {function(!WebInspector.Widget)} callback
148 */
149 _createPreviewView(callback) {
150 if (this.request.contentError()) {
151 callback(this._createMessageView(WebInspector.UIString('Failed to load res ponse data')));
152 return;
153 }
154
155 var xmlView = this._xmlView();
156 if (xmlView) {
157 callback(xmlView);
158 return;
159 }
160
161 WebInspector.JSONView.parseJSON(this._requestContent()).then(chooseView.bind (this)).then(callback);
88 162
89 /** 163 /**
90 * @return {!WebInspector.EmptyWidget} 164 * @this {WebInspector.RequestPreviewView}
165 * @param {?WebInspector.ParsedJSON} jsonData
166 * @return {!WebInspector.Widget}
91 */ 167 */
92 _createEmptyWidget: function() 168 function chooseView(jsonData) {
93 { 169 if (jsonData) {
94 return this._createMessageView(WebInspector.UIString("This request has n o preview available.")); 170 var jsonView = this._jsonView(jsonData);
95 }, 171 if (jsonView)
172 return jsonView;
173 }
96 174
97 /** 175 if (this.request.hasErrorStatusCode() || this.request.resourceType() === W ebInspector.resourceTypes.XHR) {
98 * @param {string} message 176 var htmlErrorPreview = this._htmlErrorPreview();
99 * @return {!WebInspector.EmptyWidget} 177 if (htmlErrorPreview)
100 */ 178 return htmlErrorPreview;
101 _createMessageView: function(message) 179 }
102 {
103 return new WebInspector.EmptyWidget(message);
104 },
105 180
106 /** 181 if (this._responseView.sourceView)
107 * @return {string} 182 return this._responseView.sourceView;
108 */
109 _requestContent: function()
110 {
111 var content = this.request.content;
112 return this.request.contentEncoded ? window.atob(content || "") : (conte nt || "");
113 },
114 183
115 /** 184 if (this.request.resourceType() === WebInspector.resourceTypes.Other)
116 * @param {?WebInspector.ParsedJSON} parsedJSON 185 return this._createEmptyWidget();
117 * @return {?WebInspector.SearchableView}
118 */
119 _jsonView: function(parsedJSON)
120 {
121 if (!parsedJSON || typeof parsedJSON.data !== "object")
122 return null;
123 return WebInspector.JSONView.createSearchableView(/** @type {!WebInspect or.ParsedJSON} */ (parsedJSON));
124 },
125 186
126 /** 187 return WebInspector.RequestView.nonSourceViewForRequest(this.request);
127 * @return {?WebInspector.SearchableView} 188 }
128 */ 189 }
129 _xmlView: function()
130 {
131 var parsedXML = WebInspector.XMLView.parseXML(this._requestContent(), th is.request.mimeType);
132 return parsedXML ? WebInspector.XMLView.createSearchableView(parsedXML) : null;
133 },
134
135 /**
136 * @return {?WebInspector.RequestHTMLView}
137 */
138 _htmlErrorPreview: function()
139 {
140 var whitelist = ["text/html", "text/plain", "application/xhtml+xml"];
141 if (whitelist.indexOf(this.request.mimeType) === -1)
142 return null;
143
144 var dataURL = this.request.asDataURL();
145 if (dataURL === null)
146 return null;
147
148 return new WebInspector.RequestHTMLView(this.request, dataURL);
149 },
150
151 /**
152 * @param {function(!WebInspector.Widget)} callback
153 */
154 _createPreviewView: function(callback)
155 {
156 if (this.request.contentError()) {
157 callback(this._createMessageView(WebInspector.UIString("Failed to lo ad response data")));
158 return;
159 }
160
161 var xmlView = this._xmlView();
162 if (xmlView) {
163 callback(xmlView);
164 return;
165 }
166
167 WebInspector.JSONView.parseJSON(this._requestContent()).then(chooseView. bind(this)).then(callback);
168
169 /**
170 * @this {WebInspector.RequestPreviewView}
171 * @param {?WebInspector.ParsedJSON} jsonData
172 * @return {!WebInspector.Widget}
173 */
174 function chooseView(jsonData)
175 {
176 if (jsonData) {
177 var jsonView = this._jsonView(jsonData);
178 if (jsonView)
179 return jsonView;
180 }
181
182 if (this.request.hasErrorStatusCode() || this.request.resourceType() === WebInspector.resourceTypes.XHR) {
183 var htmlErrorPreview = this._htmlErrorPreview();
184 if (htmlErrorPreview)
185 return htmlErrorPreview;
186 }
187
188 if (this._responseView.sourceView)
189 return this._responseView.sourceView;
190
191 if (this.request.resourceType() === WebInspector.resourceTypes.Other )
192 return this._createEmptyWidget();
193
194 return WebInspector.RequestView.nonSourceViewForRequest(this.request );
195 }
196 },
197
198 __proto__: WebInspector.RequestContentView.prototype
199 }; 190 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698