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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/SourcesSearchScope.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 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 10 *
11 * 2. Redistributions in binary form must reproduce the above 11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
14 * distribution. 14 * distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 /** 28 /**
29 * @implements {WebInspector.SearchScope} 29 * @implements {Sources.SearchScope}
30 * @unrestricted 30 * @unrestricted
31 */ 31 */
32 WebInspector.SourcesSearchScope = class { 32 Sources.SourcesSearchScope = class {
33 constructor() { 33 constructor() {
34 // FIXME: Add title once it is used by search controller. 34 // FIXME: Add title once it is used by search controller.
35 this._searchId = 0; 35 this._searchId = 0;
36 } 36 }
37 37
38 /** 38 /**
39 * @param {!WebInspector.UISourceCode} uiSourceCode1 39 * @param {!Workspace.UISourceCode} uiSourceCode1
40 * @param {!WebInspector.UISourceCode} uiSourceCode2 40 * @param {!Workspace.UISourceCode} uiSourceCode2
41 * @return {number} 41 * @return {number}
42 */ 42 */
43 static _filesComparator(uiSourceCode1, uiSourceCode2) { 43 static _filesComparator(uiSourceCode1, uiSourceCode2) {
44 if (uiSourceCode1.isDirty() && !uiSourceCode2.isDirty()) 44 if (uiSourceCode1.isDirty() && !uiSourceCode2.isDirty())
45 return -1; 45 return -1;
46 if (!uiSourceCode1.isDirty() && uiSourceCode2.isDirty()) 46 if (!uiSourceCode1.isDirty() && uiSourceCode2.isDirty())
47 return 1; 47 return 1;
48 var url1 = uiSourceCode1.url(); 48 var url1 = uiSourceCode1.url();
49 var url2 = uiSourceCode2.url(); 49 var url2 = uiSourceCode2.url();
50 if (url1 && !url2) 50 if (url1 && !url2)
51 return -1; 51 return -1;
52 if (!url1 && url2) 52 if (!url1 && url2)
53 return 1; 53 return 1;
54 return String.naturalOrderComparator(uiSourceCode1.fullDisplayName(), uiSour ceCode2.fullDisplayName()); 54 return String.naturalOrderComparator(uiSourceCode1.fullDisplayName(), uiSour ceCode2.fullDisplayName());
55 } 55 }
56 56
57 /** 57 /**
58 * @override 58 * @override
59 * @param {!WebInspector.Progress} progress 59 * @param {!Common.Progress} progress
60 */ 60 */
61 performIndexing(progress) { 61 performIndexing(progress) {
62 this.stopSearch(); 62 this.stopSearch();
63 63
64 var projects = this._projects(); 64 var projects = this._projects();
65 var compositeProgress = new WebInspector.CompositeProgress(progress); 65 var compositeProgress = new Common.CompositeProgress(progress);
66 for (var i = 0; i < projects.length; ++i) { 66 for (var i = 0; i < projects.length; ++i) {
67 var project = projects[i]; 67 var project = projects[i];
68 var projectProgress = compositeProgress.createSubProgress(project.uiSource Codes().length); 68 var projectProgress = compositeProgress.createSubProgress(project.uiSource Codes().length);
69 project.indexContent(projectProgress); 69 project.indexContent(projectProgress);
70 } 70 }
71 } 71 }
72 72
73 /** 73 /**
74 * @return {!Array.<!WebInspector.Project>} 74 * @return {!Array.<!Workspace.Project>}
75 */ 75 */
76 _projects() { 76 _projects() {
77 /** 77 /**
78 * @param {!WebInspector.Project} project 78 * @param {!Workspace.Project} project
79 * @return {boolean} 79 * @return {boolean}
80 */ 80 */
81 function filterOutServiceProjects(project) { 81 function filterOutServiceProjects(project) {
82 return project.type() !== WebInspector.projectTypes.Service; 82 return project.type() !== Workspace.projectTypes.Service;
83 } 83 }
84 84
85 /** 85 /**
86 * @param {!WebInspector.Project} project 86 * @param {!Workspace.Project} project
87 * @return {boolean} 87 * @return {boolean}
88 */ 88 */
89 function filterOutContentScriptsIfNeeded(project) { 89 function filterOutContentScriptsIfNeeded(project) {
90 return WebInspector.moduleSetting('searchInContentScripts').get() || 90 return Common.moduleSetting('searchInContentScripts').get() ||
91 project.type() !== WebInspector.projectTypes.ContentScripts; 91 project.type() !== Workspace.projectTypes.ContentScripts;
92 } 92 }
93 93
94 return WebInspector.workspace.projects().filter(filterOutServiceProjects).fi lter(filterOutContentScriptsIfNeeded); 94 return Workspace.workspace.projects().filter(filterOutServiceProjects).filte r(filterOutContentScriptsIfNeeded);
95 } 95 }
96 96
97 /** 97 /**
98 * @override 98 * @override
99 * @param {!WebInspector.ProjectSearchConfig} searchConfig 99 * @param {!Workspace.ProjectSearchConfig} searchConfig
100 * @param {!WebInspector.Progress} progress 100 * @param {!Common.Progress} progress
101 * @param {function(!WebInspector.FileBasedSearchResult)} searchResultCallback 101 * @param {function(!Sources.FileBasedSearchResult)} searchResultCallback
102 * @param {function(boolean)} searchFinishedCallback 102 * @param {function(boolean)} searchFinishedCallback
103 */ 103 */
104 performSearch(searchConfig, progress, searchResultCallback, searchFinishedCall back) { 104 performSearch(searchConfig, progress, searchResultCallback, searchFinishedCall back) {
105 this.stopSearch(); 105 this.stopSearch();
106 this._searchResultCandidates = []; 106 this._searchResultCandidates = [];
107 this._searchResultCallback = searchResultCallback; 107 this._searchResultCallback = searchResultCallback;
108 this._searchFinishedCallback = searchFinishedCallback; 108 this._searchFinishedCallback = searchFinishedCallback;
109 this._searchConfig = searchConfig; 109 this._searchConfig = searchConfig;
110 110
111 var projects = this._projects(); 111 var projects = this._projects();
112 var barrier = new CallbackBarrier(); 112 var barrier = new CallbackBarrier();
113 var compositeProgress = new WebInspector.CompositeProgress(progress); 113 var compositeProgress = new Common.CompositeProgress(progress);
114 var searchContentProgress = compositeProgress.createSubProgress(); 114 var searchContentProgress = compositeProgress.createSubProgress();
115 var findMatchingFilesProgress = new WebInspector.CompositeProgress(composite Progress.createSubProgress()); 115 var findMatchingFilesProgress = new Common.CompositeProgress(compositeProgre ss.createSubProgress());
116 for (var i = 0; i < projects.length; ++i) { 116 for (var i = 0; i < projects.length; ++i) {
117 var project = projects[i]; 117 var project = projects[i];
118 var weight = project.uiSourceCodes().length; 118 var weight = project.uiSourceCodes().length;
119 var findMatchingFilesInProjectProgress = findMatchingFilesProgress.createS ubProgress(weight); 119 var findMatchingFilesInProjectProgress = findMatchingFilesProgress.createS ubProgress(weight);
120 var barrierCallback = barrier.createCallback(); 120 var barrierCallback = barrier.createCallback();
121 var filesMathingFileQuery = this._projectFilesMatchingFileQuery(project, s earchConfig); 121 var filesMathingFileQuery = this._projectFilesMatchingFileQuery(project, s earchConfig);
122 var callback = this._processMatchingFilesForProject.bind( 122 var callback = this._processMatchingFilesForProject.bind(
123 this, this._searchId, project, filesMathingFileQuery, barrierCallback) ; 123 this, this._searchId, project, filesMathingFileQuery, barrierCallback) ;
124 project.findFilesMatchingSearchRequest( 124 project.findFilesMatchingSearchRequest(
125 searchConfig, filesMathingFileQuery, findMatchingFilesInProjectProgres s, callback); 125 searchConfig, filesMathingFileQuery, findMatchingFilesInProjectProgres s, callback);
126 } 126 }
127 barrier.callWhenDone(this._processMatchingFiles.bind( 127 barrier.callWhenDone(this._processMatchingFiles.bind(
128 this, this._searchId, searchContentProgress, this._searchFinishedCallbac k.bind(this, true))); 128 this, this._searchId, searchContentProgress, this._searchFinishedCallbac k.bind(this, true)));
129 } 129 }
130 130
131 /** 131 /**
132 * @param {!WebInspector.Project} project 132 * @param {!Workspace.Project} project
133 * @param {!WebInspector.ProjectSearchConfig} searchConfig 133 * @param {!Workspace.ProjectSearchConfig} searchConfig
134 * @param {boolean=} dirtyOnly 134 * @param {boolean=} dirtyOnly
135 * @return {!Array.<string>} 135 * @return {!Array.<string>}
136 */ 136 */
137 _projectFilesMatchingFileQuery(project, searchConfig, dirtyOnly) { 137 _projectFilesMatchingFileQuery(project, searchConfig, dirtyOnly) {
138 var result = []; 138 var result = [];
139 var uiSourceCodes = project.uiSourceCodes(); 139 var uiSourceCodes = project.uiSourceCodes();
140 for (var i = 0; i < uiSourceCodes.length; ++i) { 140 for (var i = 0; i < uiSourceCodes.length; ++i) {
141 var uiSourceCode = uiSourceCodes[i]; 141 var uiSourceCode = uiSourceCodes[i];
142 var binding = WebInspector.persistence.binding(uiSourceCode); 142 var binding = Persistence.persistence.binding(uiSourceCode);
143 if (binding && binding.fileSystem === uiSourceCode) 143 if (binding && binding.fileSystem === uiSourceCode)
144 continue; 144 continue;
145 if (dirtyOnly && !uiSourceCode.isDirty()) 145 if (dirtyOnly && !uiSourceCode.isDirty())
146 continue; 146 continue;
147 if (this._searchConfig.filePathMatchesFileQuery(uiSourceCode.fullDisplayNa me())) 147 if (this._searchConfig.filePathMatchesFileQuery(uiSourceCode.fullDisplayNa me()))
148 result.push(uiSourceCode.url()); 148 result.push(uiSourceCode.url());
149 } 149 }
150 result.sort(String.naturalOrderComparator); 150 result.sort(String.naturalOrderComparator);
151 return result; 151 return result;
152 } 152 }
153 153
154 /** 154 /**
155 * @param {number} searchId 155 * @param {number} searchId
156 * @param {!WebInspector.Project} project 156 * @param {!Workspace.Project} project
157 * @param {!Array.<string>} filesMathingFileQuery 157 * @param {!Array.<string>} filesMathingFileQuery
158 * @param {function()} callback 158 * @param {function()} callback
159 * @param {!Array.<string>} files 159 * @param {!Array.<string>} files
160 */ 160 */
161 _processMatchingFilesForProject(searchId, project, filesMathingFileQuery, call back, files) { 161 _processMatchingFilesForProject(searchId, project, filesMathingFileQuery, call back, files) {
162 if (searchId !== this._searchId) { 162 if (searchId !== this._searchId) {
163 this._searchFinishedCallback(false); 163 this._searchFinishedCallback(false);
164 return; 164 return;
165 } 165 }
166 166
167 files.sort(String.naturalOrderComparator); 167 files.sort(String.naturalOrderComparator);
168 files = files.intersectOrdered(filesMathingFileQuery, String.naturalOrderCom parator); 168 files = files.intersectOrdered(filesMathingFileQuery, String.naturalOrderCom parator);
169 var dirtyFiles = this._projectFilesMatchingFileQuery(project, this._searchCo nfig, true); 169 var dirtyFiles = this._projectFilesMatchingFileQuery(project, this._searchCo nfig, true);
170 files = files.mergeOrdered(dirtyFiles, String.naturalOrderComparator); 170 files = files.mergeOrdered(dirtyFiles, String.naturalOrderComparator);
171 171
172 var uiSourceCodes = []; 172 var uiSourceCodes = [];
173 for (var i = 0; i < files.length; ++i) { 173 for (var i = 0; i < files.length; ++i) {
174 var uiSourceCode = project.uiSourceCodeForURL(files[i]); 174 var uiSourceCode = project.uiSourceCodeForURL(files[i]);
175 if (uiSourceCode) { 175 if (uiSourceCode) {
176 var script = WebInspector.DefaultScriptMapping.scriptForUISourceCode(uiS ourceCode); 176 var script = Bindings.DefaultScriptMapping.scriptForUISourceCode(uiSourc eCode);
177 if (script && !script.isAnonymousScript()) 177 if (script && !script.isAnonymousScript())
178 continue; 178 continue;
179 uiSourceCodes.push(uiSourceCode); 179 uiSourceCodes.push(uiSourceCode);
180 } 180 }
181 } 181 }
182 uiSourceCodes.sort(WebInspector.SourcesSearchScope._filesComparator); 182 uiSourceCodes.sort(Sources.SourcesSearchScope._filesComparator);
183 this._searchResultCandidates = 183 this._searchResultCandidates =
184 this._searchResultCandidates.mergeOrdered(uiSourceCodes, WebInspector.So urcesSearchScope._filesComparator); 184 this._searchResultCandidates.mergeOrdered(uiSourceCodes, Sources.Sources SearchScope._filesComparator);
185 callback(); 185 callback();
186 } 186 }
187 187
188 /** 188 /**
189 * @param {number} searchId 189 * @param {number} searchId
190 * @param {!WebInspector.Progress} progress 190 * @param {!Common.Progress} progress
191 * @param {function()} callback 191 * @param {function()} callback
192 */ 192 */
193 _processMatchingFiles(searchId, progress, callback) { 193 _processMatchingFiles(searchId, progress, callback) {
194 if (searchId !== this._searchId) { 194 if (searchId !== this._searchId) {
195 this._searchFinishedCallback(false); 195 this._searchFinishedCallback(false);
196 return; 196 return;
197 } 197 }
198 198
199 var files = this._searchResultCandidates; 199 var files = this._searchResultCandidates;
200 if (!files.length) { 200 if (!files.length) {
201 progress.done(); 201 progress.done();
202 callback(); 202 callback();
203 return; 203 return;
204 } 204 }
205 205
206 progress.setTotalWork(files.length); 206 progress.setTotalWork(files.length);
207 207
208 var fileIndex = 0; 208 var fileIndex = 0;
209 var maxFileContentRequests = 20; 209 var maxFileContentRequests = 20;
210 var callbacksLeft = 0; 210 var callbacksLeft = 0;
211 211
212 for (var i = 0; i < maxFileContentRequests && i < files.length; ++i) 212 for (var i = 0; i < maxFileContentRequests && i < files.length; ++i)
213 scheduleSearchInNextFileOrFinish.call(this); 213 scheduleSearchInNextFileOrFinish.call(this);
214 214
215 /** 215 /**
216 * @param {!WebInspector.UISourceCode} uiSourceCode 216 * @param {!Workspace.UISourceCode} uiSourceCode
217 * @this {WebInspector.SourcesSearchScope} 217 * @this {Sources.SourcesSearchScope}
218 */ 218 */
219 function searchInNextFile(uiSourceCode) { 219 function searchInNextFile(uiSourceCode) {
220 if (uiSourceCode.isDirty()) 220 if (uiSourceCode.isDirty())
221 contentLoaded.call(this, uiSourceCode, uiSourceCode.workingCopy()); 221 contentLoaded.call(this, uiSourceCode, uiSourceCode.workingCopy());
222 else 222 else
223 uiSourceCode.checkContentUpdated(true, contentUpdated.bind(this, uiSourc eCode)); 223 uiSourceCode.checkContentUpdated(true, contentUpdated.bind(this, uiSourc eCode));
224 } 224 }
225 225
226 /** 226 /**
227 * @param {!WebInspector.UISourceCode} uiSourceCode 227 * @param {!Workspace.UISourceCode} uiSourceCode
228 * @this {WebInspector.SourcesSearchScope} 228 * @this {Sources.SourcesSearchScope}
229 */ 229 */
230 function contentUpdated(uiSourceCode) { 230 function contentUpdated(uiSourceCode) {
231 uiSourceCode.requestContent().then(contentLoaded.bind(this, uiSourceCode)) ; 231 uiSourceCode.requestContent().then(contentLoaded.bind(this, uiSourceCode)) ;
232 } 232 }
233 233
234 /** 234 /**
235 * @this {WebInspector.SourcesSearchScope} 235 * @this {Sources.SourcesSearchScope}
236 */ 236 */
237 function scheduleSearchInNextFileOrFinish() { 237 function scheduleSearchInNextFileOrFinish() {
238 if (fileIndex >= files.length) { 238 if (fileIndex >= files.length) {
239 if (!callbacksLeft) { 239 if (!callbacksLeft) {
240 progress.done(); 240 progress.done();
241 callback(); 241 callback();
242 return; 242 return;
243 } 243 }
244 return; 244 return;
245 } 245 }
246 246
247 ++callbacksLeft; 247 ++callbacksLeft;
248 var uiSourceCode = files[fileIndex++]; 248 var uiSourceCode = files[fileIndex++];
249 setTimeout(searchInNextFile.bind(this, uiSourceCode), 0); 249 setTimeout(searchInNextFile.bind(this, uiSourceCode), 0);
250 } 250 }
251 251
252 /** 252 /**
253 * @param {!WebInspector.UISourceCode} uiSourceCode 253 * @param {!Workspace.UISourceCode} uiSourceCode
254 * @param {?string} content 254 * @param {?string} content
255 * @this {WebInspector.SourcesSearchScope} 255 * @this {Sources.SourcesSearchScope}
256 */ 256 */
257 function contentLoaded(uiSourceCode, content) { 257 function contentLoaded(uiSourceCode, content) {
258 /** 258 /**
259 * @param {!WebInspector.ContentProvider.SearchMatch} a 259 * @param {!Common.ContentProvider.SearchMatch} a
260 * @param {!WebInspector.ContentProvider.SearchMatch} b 260 * @param {!Common.ContentProvider.SearchMatch} b
261 */ 261 */
262 function matchesComparator(a, b) { 262 function matchesComparator(a, b) {
263 return a.lineNumber - b.lineNumber; 263 return a.lineNumber - b.lineNumber;
264 } 264 }
265 265
266 progress.worked(1); 266 progress.worked(1);
267 var matches = []; 267 var matches = [];
268 var queries = this._searchConfig.queries(); 268 var queries = this._searchConfig.queries();
269 if (content !== null) { 269 if (content !== null) {
270 for (var i = 0; i < queries.length; ++i) { 270 for (var i = 0; i < queries.length; ++i) {
271 var nextMatches = WebInspector.ContentProvider.performSearchInContent( 271 var nextMatches = Common.ContentProvider.performSearchInContent(
272 content, queries[i], !this._searchConfig.ignoreCase(), this._searc hConfig.isRegex()); 272 content, queries[i], !this._searchConfig.ignoreCase(), this._searc hConfig.isRegex());
273 matches = matches.mergeOrdered(nextMatches, matchesComparator); 273 matches = matches.mergeOrdered(nextMatches, matchesComparator);
274 } 274 }
275 } 275 }
276 if (matches) { 276 if (matches) {
277 var searchResult = new WebInspector.FileBasedSearchResult(uiSourceCode, matches); 277 var searchResult = new Sources.FileBasedSearchResult(uiSourceCode, match es);
278 this._searchResultCallback(searchResult); 278 this._searchResultCallback(searchResult);
279 } 279 }
280 280
281 --callbacksLeft; 281 --callbacksLeft;
282 scheduleSearchInNextFileOrFinish.call(this); 282 scheduleSearchInNextFileOrFinish.call(this);
283 } 283 }
284 } 284 }
285 285
286 /** 286 /**
287 * @override 287 * @override
288 */ 288 */
289 stopSearch() { 289 stopSearch() {
290 ++this._searchId; 290 ++this._searchId;
291 } 291 }
292 292
293 /** 293 /**
294 * @override 294 * @override
295 * @param {!WebInspector.ProjectSearchConfig} searchConfig 295 * @param {!Workspace.ProjectSearchConfig} searchConfig
296 * @return {!WebInspector.FileBasedSearchResultsPane} 296 * @return {!Sources.FileBasedSearchResultsPane}
297 */ 297 */
298 createSearchResultsPane(searchConfig) { 298 createSearchResultsPane(searchConfig) {
299 return new WebInspector.FileBasedSearchResultsPane(searchConfig); 299 return new Sources.FileBasedSearchResultsPane(searchConfig);
300 } 300 }
301 }; 301 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698