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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots 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
(...skipping 10 matching lines...) Expand all
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 /** 30 /**
31 * @implements {WebInspector.Searchable} 31 * @implements {UI.Searchable}
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.JSONView = class extends WebInspector.VBox { 34 Network.JSONView = class extends UI.VBox {
35 /** 35 /**
36 * @param {!WebInspector.ParsedJSON} parsedJSON 36 * @param {!Network.ParsedJSON} parsedJSON
37 */ 37 */
38 constructor(parsedJSON) { 38 constructor(parsedJSON) {
39 super(); 39 super();
40 this._parsedJSON = parsedJSON; 40 this._parsedJSON = parsedJSON;
41 this.element.classList.add('json-view'); 41 this.element.classList.add('json-view');
42 42
43 /** @type {?WebInspector.SearchableView} */ 43 /** @type {?UI.SearchableView} */
44 this._searchableView; 44 this._searchableView;
45 /** @type {!WebInspector.ObjectPropertiesSection} */ 45 /** @type {!Components.ObjectPropertiesSection} */
46 this._treeOutline; 46 this._treeOutline;
47 /** @type {number} */ 47 /** @type {number} */
48 this._currentSearchFocusIndex = 0; 48 this._currentSearchFocusIndex = 0;
49 /** @type {!Array.<!TreeElement>} */ 49 /** @type {!Array.<!TreeElement>} */
50 this._currentSearchTreeElements = []; 50 this._currentSearchTreeElements = [];
51 /** @type {?RegExp} */ 51 /** @type {?RegExp} */
52 this._searchRegex = null; 52 this._searchRegex = null;
53 } 53 }
54 54
55 /** 55 /**
56 * @param {!WebInspector.ParsedJSON} parsedJSON 56 * @param {!Network.ParsedJSON} parsedJSON
57 * @return {!WebInspector.SearchableView} 57 * @return {!UI.SearchableView}
58 */ 58 */
59 static createSearchableView(parsedJSON) { 59 static createSearchableView(parsedJSON) {
60 var jsonView = new WebInspector.JSONView(parsedJSON); 60 var jsonView = new Network.JSONView(parsedJSON);
61 var searchableView = new WebInspector.SearchableView(jsonView); 61 var searchableView = new UI.SearchableView(jsonView);
62 searchableView.setPlaceholder(WebInspector.UIString('Find')); 62 searchableView.setPlaceholder(Common.UIString('Find'));
63 jsonView._searchableView = searchableView; 63 jsonView._searchableView = searchableView;
64 jsonView.show(searchableView.element); 64 jsonView.show(searchableView.element);
65 jsonView.element.setAttribute('tabIndex', 0); 65 jsonView.element.setAttribute('tabIndex', 0);
66 return searchableView; 66 return searchableView;
67 } 67 }
68 68
69 /** 69 /**
70 * @param {?string} text 70 * @param {?string} text
71 * @return {!Promise<?WebInspector.ParsedJSON>} 71 * @return {!Promise<?Network.ParsedJSON>}
72 */ 72 */
73 static parseJSON(text) { 73 static parseJSON(text) {
74 var returnObj = null; 74 var returnObj = null;
75 if (text) 75 if (text)
76 returnObj = WebInspector.JSONView._extractJSON(/** @type {string} */ (text )); 76 returnObj = Network.JSONView._extractJSON(/** @type {string} */ (text));
77 if (!returnObj) 77 if (!returnObj)
78 return Promise.resolve(/** @type {?WebInspector.ParsedJSON} */ (null)); 78 return Promise.resolve(/** @type {?Network.ParsedJSON} */ (null));
79 return WebInspector.formatterWorkerPool.runTask('relaxedJSONParser', {conten t: returnObj.data}) 79 return Common.formatterWorkerPool.runTask('relaxedJSONParser', {content: ret urnObj.data})
80 .then(handleReturnedJSON); 80 .then(handleReturnedJSON);
81 81
82 /** 82 /**
83 * @param {?MessageEvent} event 83 * @param {?MessageEvent} event
84 * @return {?WebInspector.ParsedJSON} 84 * @return {?Network.ParsedJSON}
85 */ 85 */
86 function handleReturnedJSON(event) { 86 function handleReturnedJSON(event) {
87 if (!event || !event.data) 87 if (!event || !event.data)
88 return null; 88 return null;
89 returnObj.data = event.data; 89 returnObj.data = event.data;
90 return returnObj; 90 return returnObj;
91 } 91 }
92 } 92 }
93 93
94 /** 94 /**
95 * @param {string} text 95 * @param {string} text
96 * @return {?WebInspector.ParsedJSON} 96 * @return {?Network.ParsedJSON}
97 */ 97 */
98 static _extractJSON(text) { 98 static _extractJSON(text) {
99 // Do not treat HTML as JSON. 99 // Do not treat HTML as JSON.
100 if (text.startsWith('<')) 100 if (text.startsWith('<'))
101 return null; 101 return null;
102 var inner = WebInspector.JSONView._findBrackets(text, '{', '}'); 102 var inner = Network.JSONView._findBrackets(text, '{', '}');
103 var inner2 = WebInspector.JSONView._findBrackets(text, '[', ']'); 103 var inner2 = Network.JSONView._findBrackets(text, '[', ']');
104 inner = inner2.length > inner.length ? inner2 : inner; 104 inner = inner2.length > inner.length ? inner2 : inner;
105 105
106 // Return on blank payloads or on payloads significantly smaller than origin al text. 106 // Return on blank payloads or on payloads significantly smaller than origin al text.
107 if (inner.length === -1 || text.length - inner.length > 80) 107 if (inner.length === -1 || text.length - inner.length > 80)
108 return null; 108 return null;
109 109
110 var prefix = text.substring(0, inner.start); 110 var prefix = text.substring(0, inner.start);
111 var suffix = text.substring(inner.end + 1); 111 var suffix = text.substring(inner.end + 1);
112 text = text.substring(inner.start, inner.end + 1); 112 text = text.substring(inner.start, inner.end + 1);
113 113
114 // Only process valid JSONP. 114 // Only process valid JSONP.
115 if (suffix.trim().length && !(suffix.trim().startsWith(')') && prefix.trim() .endsWith('('))) 115 if (suffix.trim().length && !(suffix.trim().startsWith(')') && prefix.trim() .endsWith('(')))
116 return null; 116 return null;
117 117
118 return new WebInspector.ParsedJSON(text, prefix, suffix); 118 return new Network.ParsedJSON(text, prefix, suffix);
119 } 119 }
120 120
121 /** 121 /**
122 * @param {string} text 122 * @param {string} text
123 * @param {string} open 123 * @param {string} open
124 * @param {string} close 124 * @param {string} close
125 * @return {{start: number, end: number, length: number}} 125 * @return {{start: number, end: number, length: number}}
126 */ 126 */
127 static _findBrackets(text, open, close) { 127 static _findBrackets(text, open, close) {
128 var start = text.indexOf(open); 128 var start = text.indexOf(open);
129 var end = text.lastIndexOf(close); 129 var end = text.lastIndexOf(close);
130 var length = end - start - 1; 130 var length = end - start - 1;
131 if (start === -1 || end === -1 || end < start) 131 if (start === -1 || end === -1 || end < start)
132 length = -1; 132 length = -1;
133 return {start: start, end: end, length: length}; 133 return {start: start, end: end, length: length};
134 } 134 }
135 135
136 /** 136 /**
137 * @override 137 * @override
138 */ 138 */
139 wasShown() { 139 wasShown() {
140 this._initialize(); 140 this._initialize();
141 } 141 }
142 142
143 _initialize() { 143 _initialize() {
144 if (this._initialized) 144 if (this._initialized)
145 return; 145 return;
146 this._initialized = true; 146 this._initialized = true;
147 147
148 var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.data); 148 var obj = SDK.RemoteObject.fromLocalObject(this._parsedJSON.data);
149 var title = this._parsedJSON.prefix + obj.description + this._parsedJSON.suf fix; 149 var title = this._parsedJSON.prefix + obj.description + this._parsedJSON.suf fix;
150 this._treeOutline = new WebInspector.ObjectPropertiesSection(obj, title); 150 this._treeOutline = new Components.ObjectPropertiesSection(obj, title);
151 this._treeOutline.setEditable(false); 151 this._treeOutline.setEditable(false);
152 this._treeOutline.expand(); 152 this._treeOutline.expand();
153 this.element.appendChild(this._treeOutline.element); 153 this.element.appendChild(this._treeOutline.element);
154 } 154 }
155 155
156 /** 156 /**
157 * @param {number} index 157 * @param {number} index
158 */ 158 */
159 _jumpToMatch(index) { 159 _jumpToMatch(index) {
160 if (!this._searchRegex) 160 if (!this._searchRegex)
161 return; 161 return;
162 var previousFocusElement = this._currentSearchTreeElements[this._currentSear chFocusIndex]; 162 var previousFocusElement = this._currentSearchTreeElements[this._currentSear chFocusIndex];
163 if (previousFocusElement) 163 if (previousFocusElement)
164 previousFocusElement.setSearchRegex(this._searchRegex); 164 previousFocusElement.setSearchRegex(this._searchRegex);
165 165
166 var newFocusElement = this._currentSearchTreeElements[index]; 166 var newFocusElement = this._currentSearchTreeElements[index];
167 if (newFocusElement) { 167 if (newFocusElement) {
168 this._updateSearchIndex(index); 168 this._updateSearchIndex(index);
169 newFocusElement.setSearchRegex(this._searchRegex, WebInspector.highlighted CurrentSearchResultClassName); 169 newFocusElement.setSearchRegex(this._searchRegex, UI.highlightedCurrentSea rchResultClassName);
170 newFocusElement.reveal(); 170 newFocusElement.reveal();
171 } else { 171 } else {
172 this._updateSearchIndex(0); 172 this._updateSearchIndex(0);
173 } 173 }
174 } 174 }
175 175
176 /** 176 /**
177 * @param {number} count 177 * @param {number} count
178 */ 178 */
179 _updateSearchCount(count) { 179 _updateSearchCount(count) {
(...skipping 13 matching lines...) Expand all
193 } 193 }
194 194
195 /** 195 /**
196 * @override 196 * @override
197 */ 197 */
198 searchCanceled() { 198 searchCanceled() {
199 this._searchRegex = null; 199 this._searchRegex = null;
200 this._currentSearchTreeElements = []; 200 this._currentSearchTreeElements = [];
201 201
202 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) { 202 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) {
203 if (!(element instanceof WebInspector.ObjectPropertyTreeElement)) 203 if (!(element instanceof Components.ObjectPropertyTreeElement))
204 continue; 204 continue;
205 element.revertHighlightChanges(); 205 element.revertHighlightChanges();
206 } 206 }
207 this._updateSearchCount(0); 207 this._updateSearchCount(0);
208 this._updateSearchIndex(0); 208 this._updateSearchIndex(0);
209 } 209 }
210 210
211 /** 211 /**
212 * @override 212 * @override
213 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 213 * @param {!UI.SearchableView.SearchConfig} searchConfig
214 * @param {boolean} shouldJump 214 * @param {boolean} shouldJump
215 * @param {boolean=} jumpBackwards 215 * @param {boolean=} jumpBackwards
216 */ 216 */
217 performSearch(searchConfig, shouldJump, jumpBackwards) { 217 performSearch(searchConfig, shouldJump, jumpBackwards) {
218 var newIndex = this._currentSearchFocusIndex; 218 var newIndex = this._currentSearchFocusIndex;
219 var previousSearchFocusElement = this._currentSearchTreeElements[newIndex]; 219 var previousSearchFocusElement = this._currentSearchTreeElements[newIndex];
220 this.searchCanceled(); 220 this.searchCanceled();
221 this._searchRegex = searchConfig.toSearchRegex(true); 221 this._searchRegex = searchConfig.toSearchRegex(true);
222 222
223 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) { 223 for (var element = this._treeOutline.rootElement(); element; element = eleme nt.traverseNextTreeElement(false)) {
224 if (!(element instanceof WebInspector.ObjectPropertyTreeElement)) 224 if (!(element instanceof Components.ObjectPropertyTreeElement))
225 continue; 225 continue;
226 var hasMatch = element.setSearchRegex(this._searchRegex); 226 var hasMatch = element.setSearchRegex(this._searchRegex);
227 if (hasMatch) 227 if (hasMatch)
228 this._currentSearchTreeElements.push(element); 228 this._currentSearchTreeElements.push(element);
229 if (previousSearchFocusElement === element) { 229 if (previousSearchFocusElement === element) {
230 var currentIndex = this._currentSearchTreeElements.length - 1; 230 var currentIndex = this._currentSearchTreeElements.length - 1;
231 if (hasMatch || jumpBackwards) 231 if (hasMatch || jumpBackwards)
232 newIndex = currentIndex; 232 newIndex = currentIndex;
233 else 233 else
234 newIndex = currentIndex + 1; 234 newIndex = currentIndex + 1;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 */ 279 */
280 supportsRegexSearch() { 280 supportsRegexSearch() {
281 return true; 281 return true;
282 } 282 }
283 }; 283 };
284 284
285 285
286 /** 286 /**
287 * @unrestricted 287 * @unrestricted
288 */ 288 */
289 WebInspector.ParsedJSON = class { 289 Network.ParsedJSON = class {
290 /** 290 /**
291 * @param {*} data 291 * @param {*} data
292 * @param {string} prefix 292 * @param {string} prefix
293 * @param {string} suffix 293 * @param {string} suffix
294 */ 294 */
295 constructor(data, prefix, suffix) { 295 constructor(data, prefix, suffix) {
296 this.data = data; 296 this.data = data;
297 this.prefix = prefix; 297 this.prefix = prefix;
298 this.suffix = suffix; 298 this.suffix = suffix;
299 } 299 }
300 }; 300 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698