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 |
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 * @unrestricted |
| 32 */ |
| 33 WebInspector.RequestResponseView = class extends WebInspector.RequestContentView
{ |
| 34 /** |
| 35 * @param {!WebInspector.NetworkRequest} request |
| 36 */ |
| 37 constructor(request) { |
| 38 super(request); |
| 39 } |
30 | 40 |
31 /** | 41 get sourceView() { |
32 * @constructor | 42 if (this._sourceView || !WebInspector.RequestView.hasTextContent(this.reques
t)) |
33 * @extends {WebInspector.RequestContentView} | 43 return this._sourceView; |
34 * @param {!WebInspector.NetworkRequest} request | |
35 */ | |
36 WebInspector.RequestResponseView = function(request) | |
37 { | |
38 WebInspector.RequestContentView.call(this, request); | |
39 }; | |
40 | 44 |
41 WebInspector.RequestResponseView.prototype = { | 45 var contentProvider = new WebInspector.RequestResponseView.ContentProvider(t
his.request); |
42 get sourceView() | 46 var highlighterType = this.request.resourceType().canonicalMimeType() || thi
s.request.mimeType; |
43 { | 47 this._sourceView = WebInspector.ResourceSourceFrame.createSearchableView(con
tentProvider, highlighterType); |
44 if (this._sourceView || !WebInspector.RequestView.hasTextContent(this.re
quest)) | 48 return this._sourceView; |
45 return this._sourceView; | 49 } |
46 | 50 |
47 var contentProvider = new WebInspector.RequestResponseView.ContentProvid
er(this.request); | 51 /** |
48 var highlighterType = this.request.resourceType().canonicalMimeType() ||
this.request.mimeType; | 52 * @param {string} message |
49 this._sourceView = WebInspector.ResourceSourceFrame.createSearchableView
(contentProvider, highlighterType); | 53 * @return {!WebInspector.EmptyWidget} |
50 return this._sourceView; | 54 */ |
51 }, | 55 _createMessageView(message) { |
| 56 return new WebInspector.EmptyWidget(message); |
| 57 } |
52 | 58 |
53 /** | 59 /** |
54 * @param {string} message | 60 * @override |
55 * @return {!WebInspector.EmptyWidget} | 61 */ |
56 */ | 62 contentLoaded() { |
57 _createMessageView: function(message) | 63 if ((!this.request.content || !this.sourceView) && !this.request.contentErro
r()) { |
58 { | 64 if (!this._emptyWidget) { |
59 return new WebInspector.EmptyWidget(message); | 65 this._emptyWidget = |
60 }, | 66 this._createMessageView(WebInspector.UIString('This request has no r
esponse data available.')); |
| 67 this._emptyWidget.show(this.element); |
| 68 } |
| 69 } else { |
| 70 if (this._emptyWidget) { |
| 71 this._emptyWidget.detach(); |
| 72 delete this._emptyWidget; |
| 73 } |
61 | 74 |
62 contentLoaded: function() | 75 if (this.request.content && this.sourceView) { |
63 { | 76 this.sourceView.show(this.element); |
64 if ((!this.request.content || !this.sourceView) && !this.request.content
Error()) { | 77 } else { |
65 if (!this._emptyWidget) { | 78 if (!this._errorView) |
66 this._emptyWidget = this._createMessageView(WebInspector.UIStrin
g("This request has no response data available.")); | 79 this._errorView = this._createMessageView(WebInspector.UIString('Faile
d to load response data')); |
67 this._emptyWidget.show(this.element); | 80 this._errorView.show(this.element); |
68 } | 81 } |
69 } else { | 82 } |
70 if (this._emptyWidget) { | 83 } |
71 this._emptyWidget.detach(); | |
72 delete this._emptyWidget; | |
73 } | |
74 | |
75 if (this.request.content && this.sourceView) { | |
76 this.sourceView.show(this.element); | |
77 } else { | |
78 if (!this._errorView) | |
79 this._errorView = this._createMessageView(WebInspector.UIStr
ing("Failed to load response data")); | |
80 this._errorView.show(this.element); | |
81 } | |
82 } | |
83 }, | |
84 | |
85 __proto__: WebInspector.RequestContentView.prototype | |
86 }; | 84 }; |
87 | 85 |
88 /** | 86 /** |
89 * @constructor | |
90 * @implements {WebInspector.ContentProvider} | 87 * @implements {WebInspector.ContentProvider} |
91 * @param {!WebInspector.NetworkRequest} request | 88 * @unrestricted |
92 */ | 89 */ |
93 WebInspector.RequestResponseView.ContentProvider = function(request) { | 90 WebInspector.RequestResponseView.ContentProvider = class { |
| 91 /** |
| 92 * @param {!WebInspector.NetworkRequest} request |
| 93 */ |
| 94 constructor(request) { |
94 this._request = request; | 95 this._request = request; |
| 96 } |
| 97 |
| 98 /** |
| 99 * @override |
| 100 * @return {string} |
| 101 */ |
| 102 contentURL() { |
| 103 return this._request.contentURL(); |
| 104 } |
| 105 |
| 106 /** |
| 107 * @override |
| 108 * @return {!WebInspector.ResourceType} |
| 109 */ |
| 110 contentType() { |
| 111 return this._request.resourceType(); |
| 112 } |
| 113 |
| 114 /** |
| 115 * @override |
| 116 * @return {!Promise<?string>} |
| 117 */ |
| 118 requestContent() { |
| 119 /** |
| 120 * @param {?string} content |
| 121 * @this {WebInspector.RequestResponseView.ContentProvider} |
| 122 */ |
| 123 function decodeContent(content) { |
| 124 return this._request.contentEncoded ? window.atob(content || '') : content
; |
| 125 } |
| 126 |
| 127 return this._request.requestContent().then(decodeContent.bind(this)); |
| 128 } |
| 129 |
| 130 /** |
| 131 * @override |
| 132 * @param {string} query |
| 133 * @param {boolean} caseSensitive |
| 134 * @param {boolean} isRegex |
| 135 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 136 */ |
| 137 searchInContent(query, caseSensitive, isRegex, callback) { |
| 138 this._request.searchInContent(query, caseSensitive, isRegex, callback); |
| 139 } |
95 }; | 140 }; |
96 | |
97 WebInspector.RequestResponseView.ContentProvider.prototype = { | |
98 /** | |
99 * @override | |
100 * @return {string} | |
101 */ | |
102 contentURL: function() | |
103 { | |
104 return this._request.contentURL(); | |
105 }, | |
106 | |
107 /** | |
108 * @override | |
109 * @return {!WebInspector.ResourceType} | |
110 */ | |
111 contentType: function() | |
112 { | |
113 return this._request.resourceType(); | |
114 }, | |
115 | |
116 /** | |
117 * @override | |
118 * @return {!Promise<?string>} | |
119 */ | |
120 requestContent: function() | |
121 { | |
122 /** | |
123 * @param {?string} content | |
124 * @this {WebInspector.RequestResponseView.ContentProvider} | |
125 */ | |
126 function decodeContent(content) | |
127 { | |
128 return this._request.contentEncoded ? window.atob(content || "") : c
ontent; | |
129 } | |
130 | |
131 return this._request.requestContent() | |
132 .then(decodeContent.bind(this)); | |
133 }, | |
134 | |
135 /** | |
136 * @override | |
137 * @param {string} query | |
138 * @param {boolean} caseSensitive | |
139 * @param {boolean} isRegex | |
140 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback | |
141 */ | |
142 searchInContent: function(query, caseSensitive, isRegex, callback) | |
143 { | |
144 this._request.searchInContent(query, caseSensitive, isRegex, callback); | |
145 } | |
146 }; | |
OLD | NEW |