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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/ContentProviderBasedProject.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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 11 matching lines...) Expand all
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 /** 31 /**
32 * @implements {WebInspector.Project} 32 * @implements {Workspace.Project}
33 * @unrestricted 33 * @unrestricted
34 */ 34 */
35 WebInspector.ContentProviderBasedProject = class extends WebInspector.ProjectSto re { 35 Bindings.ContentProviderBasedProject = class extends Workspace.ProjectStore {
36 /** 36 /**
37 * @param {!WebInspector.Workspace} workspace 37 * @param {!Workspace.Workspace} workspace
38 * @param {string} id 38 * @param {string} id
39 * @param {!WebInspector.projectTypes} type 39 * @param {!Workspace.projectTypes} type
40 * @param {string} displayName 40 * @param {string} displayName
41 */ 41 */
42 constructor(workspace, id, type, displayName) { 42 constructor(workspace, id, type, displayName) {
43 super(workspace, id, type, displayName); 43 super(workspace, id, type, displayName);
44 /** @type {!Object.<string, !WebInspector.ContentProvider>} */ 44 /** @type {!Object.<string, !Common.ContentProvider>} */
45 this._contentProviders = {}; 45 this._contentProviders = {};
46 workspace.addProject(this); 46 workspace.addProject(this);
47 } 47 }
48 48
49 /** 49 /**
50 * @override 50 * @override
51 * @param {!WebInspector.UISourceCode} uiSourceCode 51 * @param {!Workspace.UISourceCode} uiSourceCode
52 * @param {function(?string)} callback 52 * @param {function(?string)} callback
53 */ 53 */
54 requestFileContent(uiSourceCode, callback) { 54 requestFileContent(uiSourceCode, callback) {
55 var contentProvider = this._contentProviders[uiSourceCode.url()]; 55 var contentProvider = this._contentProviders[uiSourceCode.url()];
56 contentProvider.requestContent().then(callback); 56 contentProvider.requestContent().then(callback);
57 } 57 }
58 58
59 /** 59 /**
60 * @override 60 * @override
61 * @param {!WebInspector.UISourceCode} uiSourceCode 61 * @param {!Workspace.UISourceCode} uiSourceCode
62 * @return {!Promise<?WebInspector.UISourceCodeMetadata>} 62 * @return {!Promise<?Workspace.UISourceCodeMetadata>}
63 */ 63 */
64 requestMetadata(uiSourceCode) { 64 requestMetadata(uiSourceCode) {
65 return Promise.resolve(uiSourceCode[WebInspector.ContentProviderBasedProject ._metadata]); 65 return Promise.resolve(uiSourceCode[Bindings.ContentProviderBasedProject._me tadata]);
66 } 66 }
67 67
68 /** 68 /**
69 * @override 69 * @override
70 * @return {boolean} 70 * @return {boolean}
71 */ 71 */
72 canSetFileContent() { 72 canSetFileContent() {
73 return false; 73 return false;
74 } 74 }
75 75
76 /** 76 /**
77 * @override 77 * @override
78 * @param {!WebInspector.UISourceCode} uiSourceCode 78 * @param {!Workspace.UISourceCode} uiSourceCode
79 * @param {string} newContent 79 * @param {string} newContent
80 * @param {function(?string)} callback 80 * @param {function(?string)} callback
81 */ 81 */
82 setFileContent(uiSourceCode, newContent, callback) { 82 setFileContent(uiSourceCode, newContent, callback) {
83 callback(null); 83 callback(null);
84 } 84 }
85 85
86 /** 86 /**
87 * @override 87 * @override
88 * @return {boolean} 88 * @return {boolean}
89 */ 89 */
90 canRename() { 90 canRename() {
91 return false; 91 return false;
92 } 92 }
93 93
94 /** 94 /**
95 * @override 95 * @override
96 * @param {!WebInspector.UISourceCode} uiSourceCode 96 * @param {!Workspace.UISourceCode} uiSourceCode
97 * @param {string} newName 97 * @param {string} newName
98 * @param {function(boolean, string=, string=, !WebInspector.ResourceType=)} c allback 98 * @param {function(boolean, string=, string=, !Common.ResourceType=)} callbac k
99 */ 99 */
100 rename(uiSourceCode, newName, callback) { 100 rename(uiSourceCode, newName, callback) {
101 var path = uiSourceCode.url(); 101 var path = uiSourceCode.url();
102 this.performRename(path, newName, innerCallback.bind(this)); 102 this.performRename(path, newName, innerCallback.bind(this));
103 103
104 /** 104 /**
105 * @param {boolean} success 105 * @param {boolean} success
106 * @param {string=} newName 106 * @param {string=} newName
107 * @this {WebInspector.ContentProviderBasedProject} 107 * @this {Bindings.ContentProviderBasedProject}
108 */ 108 */
109 function innerCallback(success, newName) { 109 function innerCallback(success, newName) {
110 if (success && newName) { 110 if (success && newName) {
111 var copyOfPath = path.split('/'); 111 var copyOfPath = path.split('/');
112 copyOfPath[copyOfPath.length - 1] = newName; 112 copyOfPath[copyOfPath.length - 1] = newName;
113 var newPath = copyOfPath.join('/'); 113 var newPath = copyOfPath.join('/');
114 this._contentProviders[newPath] = this._contentProviders[path]; 114 this._contentProviders[newPath] = this._contentProviders[path];
115 delete this._contentProviders[path]; 115 delete this._contentProviders[path];
116 this.renameUISourceCode(uiSourceCode, newName); 116 this.renameUISourceCode(uiSourceCode, newName);
117 } 117 }
118 callback(success, newName); 118 callback(success, newName);
119 } 119 }
120 } 120 }
121 121
122 /** 122 /**
123 * @override 123 * @override
124 * @param {string} path 124 * @param {string} path
125 */ 125 */
126 excludeFolder(path) { 126 excludeFolder(path) {
127 } 127 }
128 128
129 /** 129 /**
130 * @override 130 * @override
131 * @param {string} path 131 * @param {string} path
132 * @param {?string} name 132 * @param {?string} name
133 * @param {string} content 133 * @param {string} content
134 * @param {function(?WebInspector.UISourceCode)} callback 134 * @param {function(?Workspace.UISourceCode)} callback
135 */ 135 */
136 createFile(path, name, content, callback) { 136 createFile(path, name, content, callback) {
137 } 137 }
138 138
139 /** 139 /**
140 * @override 140 * @override
141 * @param {string} path 141 * @param {string} path
142 */ 142 */
143 deleteFile(path) { 143 deleteFile(path) {
144 } 144 }
145 145
146 /** 146 /**
147 * @override 147 * @override
148 */ 148 */
149 remove() { 149 remove() {
150 } 150 }
151 151
152 /** 152 /**
153 * @param {string} path 153 * @param {string} path
154 * @param {string} newName 154 * @param {string} newName
155 * @param {function(boolean, string=)} callback 155 * @param {function(boolean, string=)} callback
156 */ 156 */
157 performRename(path, newName, callback) { 157 performRename(path, newName, callback) {
158 callback(false); 158 callback(false);
159 } 159 }
160 160
161 /** 161 /**
162 * @override 162 * @override
163 * @param {!WebInspector.UISourceCode} uiSourceCode 163 * @param {!Workspace.UISourceCode} uiSourceCode
164 * @param {string} query 164 * @param {string} query
165 * @param {boolean} caseSensitive 165 * @param {boolean} caseSensitive
166 * @param {boolean} isRegex 166 * @param {boolean} isRegex
167 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb ack 167 * @param {function(!Array.<!Common.ContentProvider.SearchMatch>)} callback
168 */ 168 */
169 searchInFileContent(uiSourceCode, query, caseSensitive, isRegex, callback) { 169 searchInFileContent(uiSourceCode, query, caseSensitive, isRegex, callback) {
170 var contentProvider = this._contentProviders[uiSourceCode.url()]; 170 var contentProvider = this._contentProviders[uiSourceCode.url()];
171 contentProvider.searchInContent(query, caseSensitive, isRegex, callback); 171 contentProvider.searchInContent(query, caseSensitive, isRegex, callback);
172 } 172 }
173 173
174 /** 174 /**
175 * @override 175 * @override
176 * @param {!WebInspector.ProjectSearchConfig} searchConfig 176 * @param {!Workspace.ProjectSearchConfig} searchConfig
177 * @param {!Array.<string>} filesMathingFileQuery 177 * @param {!Array.<string>} filesMathingFileQuery
178 * @param {!WebInspector.Progress} progress 178 * @param {!Common.Progress} progress
179 * @param {function(!Array.<string>)} callback 179 * @param {function(!Array.<string>)} callback
180 */ 180 */
181 findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress, callback) { 181 findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress, callback) {
182 var result = []; 182 var result = [];
183 var paths = filesMathingFileQuery; 183 var paths = filesMathingFileQuery;
184 var totalCount = paths.length; 184 var totalCount = paths.length;
185 if (totalCount === 0) { 185 if (totalCount === 0) {
186 // searchInContent should call back later. 186 // searchInContent should call back later.
187 setTimeout(doneCallback, 0); 187 setTimeout(doneCallback, 0);
188 return; 188 return;
189 } 189 }
190 190
191 var barrier = new CallbackBarrier(); 191 var barrier = new CallbackBarrier();
192 progress.setTotalWork(paths.length); 192 progress.setTotalWork(paths.length);
193 for (var i = 0; i < paths.length; ++i) 193 for (var i = 0; i < paths.length; ++i)
194 searchInContent.call(this, paths[i], barrier.createCallback(searchInConten tCallback.bind(null, paths[i]))); 194 searchInContent.call(this, paths[i], barrier.createCallback(searchInConten tCallback.bind(null, paths[i])));
195 barrier.callWhenDone(doneCallback); 195 barrier.callWhenDone(doneCallback);
196 196
197 /** 197 /**
198 * @param {string} path 198 * @param {string} path
199 * @param {function(boolean)} callback 199 * @param {function(boolean)} callback
200 * @this {WebInspector.ContentProviderBasedProject} 200 * @this {Bindings.ContentProviderBasedProject}
201 */ 201 */
202 function searchInContent(path, callback) { 202 function searchInContent(path, callback) {
203 var queriesToRun = searchConfig.queries().slice(); 203 var queriesToRun = searchConfig.queries().slice();
204 searchNextQuery.call(this); 204 searchNextQuery.call(this);
205 205
206 /** 206 /**
207 * @this {WebInspector.ContentProviderBasedProject} 207 * @this {Bindings.ContentProviderBasedProject}
208 */ 208 */
209 function searchNextQuery() { 209 function searchNextQuery() {
210 if (!queriesToRun.length) { 210 if (!queriesToRun.length) {
211 callback(true); 211 callback(true);
212 return; 212 return;
213 } 213 }
214 var query = queriesToRun.shift(); 214 var query = queriesToRun.shift();
215 this._contentProviders[path].searchInContent( 215 this._contentProviders[path].searchInContent(
216 query, !searchConfig.ignoreCase(), searchConfig.isRegex(), contentCa llback.bind(this)); 216 query, !searchConfig.ignoreCase(), searchConfig.isRegex(), contentCa llback.bind(this));
217 } 217 }
218 218
219 /** 219 /**
220 * @param {!Array.<!WebInspector.ContentProvider.SearchMatch>} searchMatch es 220 * @param {!Array.<!Common.ContentProvider.SearchMatch>} searchMatches
221 * @this {WebInspector.ContentProviderBasedProject} 221 * @this {Bindings.ContentProviderBasedProject}
222 */ 222 */
223 function contentCallback(searchMatches) { 223 function contentCallback(searchMatches) {
224 if (!searchMatches.length) { 224 if (!searchMatches.length) {
225 callback(false); 225 callback(false);
226 return; 226 return;
227 } 227 }
228 searchNextQuery.call(this); 228 searchNextQuery.call(this);
229 } 229 }
230 } 230 }
231 231
232 /** 232 /**
233 * @param {string} path 233 * @param {string} path
234 * @param {boolean} matches 234 * @param {boolean} matches
235 */ 235 */
236 function searchInContentCallback(path, matches) { 236 function searchInContentCallback(path, matches) {
237 if (matches) 237 if (matches)
238 result.push(path); 238 result.push(path);
239 progress.worked(1); 239 progress.worked(1);
240 } 240 }
241 241
242 function doneCallback() { 242 function doneCallback() {
243 callback(result); 243 callback(result);
244 progress.done(); 244 progress.done();
245 } 245 }
246 } 246 }
247 247
248 /** 248 /**
249 * @override 249 * @override
250 * @param {!WebInspector.Progress} progress 250 * @param {!Common.Progress} progress
251 */ 251 */
252 indexContent(progress) { 252 indexContent(progress) {
253 setImmediate(progress.done.bind(progress)); 253 setImmediate(progress.done.bind(progress));
254 } 254 }
255 255
256 /** 256 /**
257 * @param {!WebInspector.UISourceCode} uiSourceCode 257 * @param {!Workspace.UISourceCode} uiSourceCode
258 * @param {!WebInspector.ContentProvider} contentProvider 258 * @param {!Common.ContentProvider} contentProvider
259 * @param {?WebInspector.UISourceCodeMetadata} metadata 259 * @param {?Workspace.UISourceCodeMetadata} metadata
260 */ 260 */
261 addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) { 261 addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) {
262 this._contentProviders[uiSourceCode.url()] = contentProvider; 262 this._contentProviders[uiSourceCode.url()] = contentProvider;
263 uiSourceCode[WebInspector.ContentProviderBasedProject._metadata] = metadata; 263 uiSourceCode[Bindings.ContentProviderBasedProject._metadata] = metadata;
264 this.addUISourceCode(uiSourceCode, true); 264 this.addUISourceCode(uiSourceCode, true);
265 } 265 }
266 266
267 /** 267 /**
268 * @param {string} url 268 * @param {string} url
269 * @param {!WebInspector.ContentProvider} contentProvider 269 * @param {!Common.ContentProvider} contentProvider
270 * @return {!WebInspector.UISourceCode} 270 * @return {!Workspace.UISourceCode}
271 */ 271 */
272 addContentProvider(url, contentProvider) { 272 addContentProvider(url, contentProvider) {
273 var uiSourceCode = this.createUISourceCode(url, contentProvider.contentType( )); 273 var uiSourceCode = this.createUISourceCode(url, contentProvider.contentType( ));
274 this.addUISourceCodeWithProvider(uiSourceCode, contentProvider, null); 274 this.addUISourceCodeWithProvider(uiSourceCode, contentProvider, null);
275 return uiSourceCode; 275 return uiSourceCode;
276 } 276 }
277 277
278 /** 278 /**
279 * @param {string} path 279 * @param {string} path
280 */ 280 */
281 removeFile(path) { 281 removeFile(path) {
282 delete this._contentProviders[path]; 282 delete this._contentProviders[path];
283 this.removeUISourceCode(path); 283 this.removeUISourceCode(path);
284 } 284 }
285 285
286 reset() { 286 reset() {
287 this._contentProviders = {}; 287 this._contentProviders = {};
288 this.removeProject(); 288 this.removeProject();
289 this.workspace().addProject(this); 289 this.workspace().addProject(this);
290 } 290 }
291 291
292 dispose() { 292 dispose() {
293 this._contentProviders = {}; 293 this._contentProviders = {};
294 this.removeProject(); 294 this.removeProject();
295 } 295 }
296 }; 296 };
297 297
298 WebInspector.ContentProviderBasedProject._metadata = Symbol('ContentProviderBase dProject.Metadata'); 298 Bindings.ContentProviderBasedProject._metadata = Symbol('ContentProviderBasedPro ject.Metadata');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698