OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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.Object} | |
34 */ | 32 */ |
35 WebInspector.IsolatedFileSystemManager = function() | 33 WebInspector.IsolatedFileSystemManager = class extends WebInspector.Object { |
36 { | 34 constructor() { |
37 WebInspector.Object.call(this); | 35 super(); |
38 | 36 |
39 /** @type {!Map<string, !WebInspector.IsolatedFileSystem>} */ | 37 /** @type {!Map<string, !WebInspector.IsolatedFileSystem>} */ |
40 this._fileSystems = new Map(); | 38 this._fileSystems = new Map(); |
41 /** @type {!Map<number, function(!Array.<string>)>} */ | 39 /** @type {!Map<number, function(!Array.<string>)>} */ |
42 this._callbacks = new Map(); | 40 this._callbacks = new Map(); |
43 /** @type {!Map<number, !WebInspector.Progress>} */ | 41 /** @type {!Map<number, !WebInspector.Progress>} */ |
44 this._progresses = new Map(); | 42 this._progresses = new Map(); |
45 | 43 |
46 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.FileSystemRemoved, this._onFileSystemRemoved, this); | 44 InspectorFrontendHost.events.addEventListener( |
47 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.FileSystemAdded, this._onFileSystemAdded, this); | 45 InspectorFrontendHostAPI.Events.FileSystemRemoved, this._onFileSystemRem
oved, this); |
48 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.FileSystemFilesChanged, this._onFileSystemFilesChanged, this); | 46 InspectorFrontendHost.events.addEventListener( |
49 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.IndexingTotalWorkCalculated, this._onIndexingTotalWorkCalculated, this); | 47 InspectorFrontendHostAPI.Events.FileSystemAdded, this._onFileSystemAdded
, this); |
50 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.IndexingWorked, this._onIndexingWorked, this); | 48 InspectorFrontendHost.events.addEventListener( |
51 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.IndexingDone, this._onIndexingDone, this); | 49 InspectorFrontendHostAPI.Events.FileSystemFilesChanged, this._onFileSyst
emFilesChanged, this); |
52 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SearchCompleted, this._onSearchCompleted, this); | 50 InspectorFrontendHost.events.addEventListener( |
| 51 InspectorFrontendHostAPI.Events.IndexingTotalWorkCalculated, this._onInd
exingTotalWorkCalculated, this); |
| 52 InspectorFrontendHost.events.addEventListener( |
| 53 InspectorFrontendHostAPI.Events.IndexingWorked, this._onIndexingWorked,
this); |
| 54 InspectorFrontendHost.events.addEventListener( |
| 55 InspectorFrontendHostAPI.Events.IndexingDone, this._onIndexingDone, this
); |
| 56 InspectorFrontendHost.events.addEventListener( |
| 57 InspectorFrontendHostAPI.Events.SearchCompleted, this._onSearchCompleted
, this); |
53 | 58 |
54 this._initExcludePatterSetting(); | 59 this._initExcludePatterSetting(); |
55 | 60 |
56 this._fileSystemsLoadedPromise = this._requestFileSystems(); | 61 this._fileSystemsLoadedPromise = this._requestFileSystems(); |
| 62 } |
| 63 |
| 64 /** |
| 65 * @return {!Promise<!Array<!WebInspector.IsolatedFileSystem>>} |
| 66 */ |
| 67 _requestFileSystems() { |
| 68 var fulfill; |
| 69 var promise = new Promise(f => fulfill = f); |
| 70 InspectorFrontendHost.events.addEventListener( |
| 71 InspectorFrontendHostAPI.Events.FileSystemsLoaded, onFileSystemsLoaded,
this); |
| 72 InspectorFrontendHost.requestFileSystems(); |
| 73 return promise; |
| 74 |
| 75 /** |
| 76 * @param {!WebInspector.Event} event |
| 77 * @this {WebInspector.IsolatedFileSystemManager} |
| 78 */ |
| 79 function onFileSystemsLoaded(event) { |
| 80 var fileSystems = /** @type {!Array.<!WebInspector.IsolatedFileSystemManag
er.FileSystem>} */ (event.data); |
| 81 var promises = []; |
| 82 for (var i = 0; i < fileSystems.length; ++i) |
| 83 promises.push(this._innerAddFileSystem(fileSystems[i], false)); |
| 84 Promise.all(promises).then(onFileSystemsAdded); |
| 85 } |
| 86 |
| 87 /** |
| 88 * @param {!Array<?WebInspector.IsolatedFileSystem>} fileSystems |
| 89 */ |
| 90 function onFileSystemsAdded(fileSystems) { |
| 91 fulfill(fileSystems.filter(fs => !!fs)); |
| 92 } |
| 93 } |
| 94 |
| 95 addFileSystem() { |
| 96 InspectorFrontendHost.addFileSystem(''); |
| 97 } |
| 98 |
| 99 /** |
| 100 * @param {!WebInspector.IsolatedFileSystem} fileSystem |
| 101 */ |
| 102 removeFileSystem(fileSystem) { |
| 103 InspectorFrontendHost.removeFileSystem(fileSystem.embedderPath()); |
| 104 } |
| 105 |
| 106 /** |
| 107 * @return {!Promise<!Array<!WebInspector.IsolatedFileSystem>>} |
| 108 */ |
| 109 waitForFileSystems() { |
| 110 return this._fileSystemsLoadedPromise; |
| 111 } |
| 112 |
| 113 /** |
| 114 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem |
| 115 * @param {boolean} dispatchEvent |
| 116 * @return {!Promise<?WebInspector.IsolatedFileSystem>} |
| 117 */ |
| 118 _innerAddFileSystem(fileSystem, dispatchEvent) { |
| 119 var embedderPath = fileSystem.fileSystemPath; |
| 120 var fileSystemURL = WebInspector.ParsedURL.platformPathToURL(fileSystem.file
SystemPath); |
| 121 var promise = WebInspector.IsolatedFileSystem.create( |
| 122 this, fileSystemURL, embedderPath, fileSystem.fileSystemName, fileSystem
.rootURL); |
| 123 return promise.then(storeFileSystem.bind(this)); |
| 124 |
| 125 /** |
| 126 * @param {?WebInspector.IsolatedFileSystem} fileSystem |
| 127 * @this {WebInspector.IsolatedFileSystemManager} |
| 128 */ |
| 129 function storeFileSystem(fileSystem) { |
| 130 if (!fileSystem) |
| 131 return null; |
| 132 this._fileSystems.set(fileSystemURL, fileSystem); |
| 133 if (dispatchEvent) |
| 134 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Eve
nts.FileSystemAdded, fileSystem); |
| 135 return fileSystem; |
| 136 } |
| 137 } |
| 138 |
| 139 /** |
| 140 * @param {!WebInspector.Event} event |
| 141 */ |
| 142 _onFileSystemAdded(event) { |
| 143 var errorMessage = /** @type {string} */ (event.data['errorMessage']); |
| 144 var fileSystem = /** @type {?WebInspector.IsolatedFileSystemManager.FileSyst
em} */ (event.data['fileSystem']); |
| 145 if (errorMessage) |
| 146 WebInspector.console.error(errorMessage); |
| 147 else if (fileSystem) |
| 148 this._innerAddFileSystem(fileSystem, true); |
| 149 } |
| 150 |
| 151 /** |
| 152 * @param {!WebInspector.Event} event |
| 153 */ |
| 154 _onFileSystemRemoved(event) { |
| 155 var embedderPath = /** @type {string} */ (event.data); |
| 156 var fileSystemPath = WebInspector.ParsedURL.platformPathToURL(embedderPath); |
| 157 var isolatedFileSystem = this._fileSystems.get(fileSystemPath); |
| 158 if (!isolatedFileSystem) |
| 159 return; |
| 160 this._fileSystems.delete(fileSystemPath); |
| 161 isolatedFileSystem.fileSystemRemoved(); |
| 162 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.
FileSystemRemoved, isolatedFileSystem); |
| 163 } |
| 164 |
| 165 /** |
| 166 * @param {!WebInspector.Event} event |
| 167 */ |
| 168 _onFileSystemFilesChanged(event) { |
| 169 var embedderPaths = /** @type {!Array<string>} */ (event.data); |
| 170 var paths = embedderPaths.map(embedderPath => WebInspector.ParsedURL.platfor
mPathToURL(embedderPath)); |
| 171 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.
FileSystemFilesChanged, paths); |
| 172 } |
| 173 |
| 174 /** |
| 175 * @return {!Array<!WebInspector.IsolatedFileSystem>} |
| 176 */ |
| 177 fileSystems() { |
| 178 return this._fileSystems.valuesArray(); |
| 179 } |
| 180 |
| 181 /** |
| 182 * @param {string} fileSystemPath |
| 183 * @return {?WebInspector.IsolatedFileSystem} |
| 184 */ |
| 185 fileSystem(fileSystemPath) { |
| 186 return this._fileSystems.get(fileSystemPath) || null; |
| 187 } |
| 188 |
| 189 _initExcludePatterSetting() { |
| 190 var defaultCommonExcludedFolders = [ |
| 191 '/node_modules/', '/bower_components/', '/\\.devtools', '/\\.git/', '/\\.s
ass-cache/', '/\\.hg/', '/\\.idea/', |
| 192 '/\\.svn/', '/\\.cache/', '/\\.project/' |
| 193 ]; |
| 194 var defaultWinExcludedFolders = ['/Thumbs.db$', '/ehthumbs.db$', '/Desktop.i
ni$', '/\\$RECYCLE.BIN/']; |
| 195 var defaultMacExcludedFolders = [ |
| 196 '/\\.DS_Store$', '/\\.Trashes$', '/\\.Spotlight-V100$', '/\\.AppleDouble$'
, '/\\.LSOverride$', '/Icon$', |
| 197 '/\\._.*$' |
| 198 ]; |
| 199 var defaultLinuxExcludedFolders = ['/.*~$']; |
| 200 var defaultExcludedFolders = defaultCommonExcludedFolders; |
| 201 if (WebInspector.isWin()) |
| 202 defaultExcludedFolders = defaultExcludedFolders.concat(defaultWinExcludedF
olders); |
| 203 else if (WebInspector.isMac()) |
| 204 defaultExcludedFolders = defaultExcludedFolders.concat(defaultMacExcludedF
olders); |
| 205 else |
| 206 defaultExcludedFolders = defaultExcludedFolders.concat(defaultLinuxExclude
dFolders); |
| 207 var defaultExcludedFoldersPattern = defaultExcludedFolders.join('|'); |
| 208 this._workspaceFolderExcludePatternSetting = WebInspector.settings.createReg
ExpSetting( |
| 209 'workspaceFolderExcludePattern', defaultExcludedFoldersPattern, WebInspe
ctor.isWin() ? 'i' : ''); |
| 210 } |
| 211 |
| 212 /** |
| 213 * @return {!WebInspector.Setting} |
| 214 */ |
| 215 workspaceFolderExcludePatternSetting() { |
| 216 return this._workspaceFolderExcludePatternSetting; |
| 217 } |
| 218 |
| 219 /** |
| 220 * @param {function(!Array.<string>)} callback |
| 221 * @return {number} |
| 222 */ |
| 223 registerCallback(callback) { |
| 224 var requestId = ++WebInspector.IsolatedFileSystemManager._lastRequestId; |
| 225 this._callbacks.set(requestId, callback); |
| 226 return requestId; |
| 227 } |
| 228 |
| 229 /** |
| 230 * @param {!WebInspector.Progress} progress |
| 231 * @return {number} |
| 232 */ |
| 233 registerProgress(progress) { |
| 234 var requestId = ++WebInspector.IsolatedFileSystemManager._lastRequestId; |
| 235 this._progresses.set(requestId, progress); |
| 236 return requestId; |
| 237 } |
| 238 |
| 239 /** |
| 240 * @param {!WebInspector.Event} event |
| 241 */ |
| 242 _onIndexingTotalWorkCalculated(event) { |
| 243 var requestId = /** @type {number} */ (event.data['requestId']); |
| 244 var totalWork = /** @type {number} */ (event.data['totalWork']); |
| 245 |
| 246 var progress = this._progresses.get(requestId); |
| 247 if (!progress) |
| 248 return; |
| 249 progress.setTotalWork(totalWork); |
| 250 } |
| 251 |
| 252 /** |
| 253 * @param {!WebInspector.Event} event |
| 254 */ |
| 255 _onIndexingWorked(event) { |
| 256 var requestId = /** @type {number} */ (event.data['requestId']); |
| 257 var worked = /** @type {number} */ (event.data['worked']); |
| 258 |
| 259 var progress = this._progresses.get(requestId); |
| 260 if (!progress) |
| 261 return; |
| 262 progress.worked(worked); |
| 263 if (progress.isCanceled()) { |
| 264 InspectorFrontendHost.stopIndexing(requestId); |
| 265 this._onIndexingDone(event); |
| 266 } |
| 267 } |
| 268 |
| 269 /** |
| 270 * @param {!WebInspector.Event} event |
| 271 */ |
| 272 _onIndexingDone(event) { |
| 273 var requestId = /** @type {number} */ (event.data['requestId']); |
| 274 |
| 275 var progress = this._progresses.get(requestId); |
| 276 if (!progress) |
| 277 return; |
| 278 progress.done(); |
| 279 this._progresses.delete(requestId); |
| 280 } |
| 281 |
| 282 /** |
| 283 * @param {!WebInspector.Event} event |
| 284 */ |
| 285 _onSearchCompleted(event) { |
| 286 var requestId = /** @type {number} */ (event.data['requestId']); |
| 287 var files = /** @type {!Array.<string>} */ (event.data['files']); |
| 288 |
| 289 var callback = this._callbacks.get(requestId); |
| 290 if (!callback) |
| 291 return; |
| 292 callback.call(null, files); |
| 293 this._callbacks.delete(requestId); |
| 294 } |
57 }; | 295 }; |
58 | 296 |
59 /** @typedef {!{fileSystemName: string, rootURL: string, fileSystemPath: string}
} */ | 297 /** @typedef {!{fileSystemName: string, rootURL: string, fileSystemPath: string}
} */ |
60 WebInspector.IsolatedFileSystemManager.FileSystem; | 298 WebInspector.IsolatedFileSystemManager.FileSystem; |
61 | 299 |
62 /** @enum {symbol} */ | 300 /** @enum {symbol} */ |
63 WebInspector.IsolatedFileSystemManager.Events = { | 301 WebInspector.IsolatedFileSystemManager.Events = { |
64 FileSystemAdded: Symbol("FileSystemAdded"), | 302 FileSystemAdded: Symbol('FileSystemAdded'), |
65 FileSystemRemoved: Symbol("FileSystemRemoved"), | 303 FileSystemRemoved: Symbol('FileSystemRemoved'), |
66 FileSystemFilesChanged: Symbol("FileSystemFilesChanged"), | 304 FileSystemFilesChanged: Symbol('FileSystemFilesChanged'), |
67 ExcludedFolderAdded: Symbol("ExcludedFolderAdded"), | 305 ExcludedFolderAdded: Symbol('ExcludedFolderAdded'), |
68 ExcludedFolderRemoved: Symbol("ExcludedFolderRemoved") | 306 ExcludedFolderRemoved: Symbol('ExcludedFolderRemoved') |
69 }; | 307 }; |
70 | 308 |
71 WebInspector.IsolatedFileSystemManager._lastRequestId = 0; | 309 WebInspector.IsolatedFileSystemManager._lastRequestId = 0; |
72 | 310 |
73 WebInspector.IsolatedFileSystemManager.prototype = { | |
74 /** | |
75 * @return {!Promise<!Array<!WebInspector.IsolatedFileSystem>>} | |
76 */ | |
77 _requestFileSystems: function() | |
78 { | |
79 var fulfill; | |
80 var promise = new Promise(f => fulfill = f); | |
81 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E
vents.FileSystemsLoaded, onFileSystemsLoaded, this); | |
82 InspectorFrontendHost.requestFileSystems(); | |
83 return promise; | |
84 | |
85 /** | |
86 * @param {!WebInspector.Event} event | |
87 * @this {WebInspector.IsolatedFileSystemManager} | |
88 */ | |
89 function onFileSystemsLoaded(event) | |
90 { | |
91 var fileSystems = /** @type {!Array.<!WebInspector.IsolatedFileSyste
mManager.FileSystem>} */ (event.data); | |
92 var promises = []; | |
93 for (var i = 0; i < fileSystems.length; ++i) | |
94 promises.push(this._innerAddFileSystem(fileSystems[i], false)); | |
95 Promise.all(promises).then(onFileSystemsAdded); | |
96 } | |
97 | |
98 /** | |
99 * @param {!Array<?WebInspector.IsolatedFileSystem>} fileSystems | |
100 */ | |
101 function onFileSystemsAdded(fileSystems) | |
102 { | |
103 fulfill(fileSystems.filter(fs => !!fs)); | |
104 } | |
105 }, | |
106 | |
107 addFileSystem: function() | |
108 { | |
109 InspectorFrontendHost.addFileSystem(""); | |
110 }, | |
111 | |
112 /** | |
113 * @param {!WebInspector.IsolatedFileSystem} fileSystem | |
114 */ | |
115 removeFileSystem: function(fileSystem) | |
116 { | |
117 InspectorFrontendHost.removeFileSystem(fileSystem.embedderPath()); | |
118 }, | |
119 | |
120 /** | |
121 * @return {!Promise<!Array<!WebInspector.IsolatedFileSystem>>} | |
122 */ | |
123 waitForFileSystems: function() | |
124 { | |
125 return this._fileSystemsLoadedPromise; | |
126 }, | |
127 | |
128 /** | |
129 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem | |
130 * @param {boolean} dispatchEvent | |
131 * @return {!Promise<?WebInspector.IsolatedFileSystem>} | |
132 */ | |
133 _innerAddFileSystem: function(fileSystem, dispatchEvent) | |
134 { | |
135 var embedderPath = fileSystem.fileSystemPath; | |
136 var fileSystemURL = WebInspector.ParsedURL.platformPathToURL(fileSystem.
fileSystemPath); | |
137 var promise = WebInspector.IsolatedFileSystem.create(this, fileSystemURL
, embedderPath, fileSystem.fileSystemName, fileSystem.rootURL); | |
138 return promise.then(storeFileSystem.bind(this)); | |
139 | |
140 /** | |
141 * @param {?WebInspector.IsolatedFileSystem} fileSystem | |
142 * @this {WebInspector.IsolatedFileSystemManager} | |
143 */ | |
144 function storeFileSystem(fileSystem) | |
145 { | |
146 if (!fileSystem) | |
147 return null; | |
148 this._fileSystems.set(fileSystemURL, fileSystem); | |
149 if (dispatchEvent) | |
150 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemMan
ager.Events.FileSystemAdded, fileSystem); | |
151 return fileSystem; | |
152 } | |
153 }, | |
154 | |
155 /** | |
156 * @param {!WebInspector.Event} event | |
157 */ | |
158 _onFileSystemAdded: function(event) | |
159 { | |
160 var errorMessage = /** @type {string} */ (event.data["errorMessage"]); | |
161 var fileSystem = /** @type {?WebInspector.IsolatedFileSystemManager.File
System} */ (event.data["fileSystem"]); | |
162 if (errorMessage) | |
163 WebInspector.console.error(errorMessage); | |
164 else if (fileSystem) | |
165 this._innerAddFileSystem(fileSystem, true); | |
166 }, | |
167 | |
168 /** | |
169 * @param {!WebInspector.Event} event | |
170 */ | |
171 _onFileSystemRemoved: function(event) | |
172 { | |
173 var embedderPath = /** @type {string} */ (event.data); | |
174 var fileSystemPath = WebInspector.ParsedURL.platformPathToURL(embedderPa
th); | |
175 var isolatedFileSystem = this._fileSystems.get(fileSystemPath); | |
176 if (!isolatedFileSystem) | |
177 return; | |
178 this._fileSystems.delete(fileSystemPath); | |
179 isolatedFileSystem.fileSystemRemoved(); | |
180 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Eve
nts.FileSystemRemoved, isolatedFileSystem); | |
181 }, | |
182 | |
183 /** | |
184 * @param {!WebInspector.Event} event | |
185 */ | |
186 _onFileSystemFilesChanged: function(event) | |
187 { | |
188 var embedderPaths = /** @type {!Array<string>} */ (event.data); | |
189 var paths = embedderPaths.map(embedderPath => WebInspector.ParsedURL.pla
tformPathToURL(embedderPath)); | |
190 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Eve
nts.FileSystemFilesChanged, paths); | |
191 }, | |
192 | |
193 /** | |
194 * @return {!Array<!WebInspector.IsolatedFileSystem>} | |
195 */ | |
196 fileSystems: function() | |
197 { | |
198 return this._fileSystems.valuesArray(); | |
199 }, | |
200 | |
201 /** | |
202 * @param {string} fileSystemPath | |
203 * @return {?WebInspector.IsolatedFileSystem} | |
204 */ | |
205 fileSystem: function(fileSystemPath) | |
206 { | |
207 return this._fileSystems.get(fileSystemPath) || null; | |
208 }, | |
209 | |
210 _initExcludePatterSetting: function() | |
211 { | |
212 var defaultCommonExcludedFolders = [ | |
213 "/node_modules/", | |
214 "/bower_components/", | |
215 "/\\.devtools", | |
216 "/\\.git/", | |
217 "/\\.sass-cache/", | |
218 "/\\.hg/", | |
219 "/\\.idea/", | |
220 "/\\.svn/", | |
221 "/\\.cache/", | |
222 "/\\.project/" | |
223 ]; | |
224 var defaultWinExcludedFolders = [ | |
225 "/Thumbs.db$", | |
226 "/ehthumbs.db$", | |
227 "/Desktop.ini$", | |
228 "/\\$RECYCLE.BIN/" | |
229 ]; | |
230 var defaultMacExcludedFolders = [ | |
231 "/\\.DS_Store$", | |
232 "/\\.Trashes$", | |
233 "/\\.Spotlight-V100$", | |
234 "/\\.AppleDouble$", | |
235 "/\\.LSOverride$", | |
236 "/Icon$", | |
237 "/\\._.*$" | |
238 ]; | |
239 var defaultLinuxExcludedFolders = [ | |
240 "/.*~$" | |
241 ]; | |
242 var defaultExcludedFolders = defaultCommonExcludedFolders; | |
243 if (WebInspector.isWin()) | |
244 defaultExcludedFolders = defaultExcludedFolders.concat(defaultWinExc
ludedFolders); | |
245 else if (WebInspector.isMac()) | |
246 defaultExcludedFolders = defaultExcludedFolders.concat(defaultMacExc
ludedFolders); | |
247 else | |
248 defaultExcludedFolders = defaultExcludedFolders.concat(defaultLinuxE
xcludedFolders); | |
249 var defaultExcludedFoldersPattern = defaultExcludedFolders.join("|"); | |
250 this._workspaceFolderExcludePatternSetting = WebInspector.settings.creat
eRegExpSetting("workspaceFolderExcludePattern", defaultExcludedFoldersPattern, W
ebInspector.isWin() ? "i" : ""); | |
251 }, | |
252 | |
253 /** | |
254 * @return {!WebInspector.Setting} | |
255 */ | |
256 workspaceFolderExcludePatternSetting: function() | |
257 { | |
258 return this._workspaceFolderExcludePatternSetting; | |
259 }, | |
260 | |
261 /** | |
262 * @param {function(!Array.<string>)} callback | |
263 * @return {number} | |
264 */ | |
265 registerCallback: function(callback) | |
266 { | |
267 var requestId = ++WebInspector.IsolatedFileSystemManager._lastRequestId; | |
268 this._callbacks.set(requestId, callback); | |
269 return requestId; | |
270 }, | |
271 | |
272 /** | |
273 * @param {!WebInspector.Progress} progress | |
274 * @return {number} | |
275 */ | |
276 registerProgress: function(progress) | |
277 { | |
278 var requestId = ++WebInspector.IsolatedFileSystemManager._lastRequestId; | |
279 this._progresses.set(requestId, progress); | |
280 return requestId; | |
281 }, | |
282 | |
283 /** | |
284 * @param {!WebInspector.Event} event | |
285 */ | |
286 _onIndexingTotalWorkCalculated: function(event) | |
287 { | |
288 var requestId = /** @type {number} */ (event.data["requestId"]); | |
289 var totalWork = /** @type {number} */ (event.data["totalWork"]); | |
290 | |
291 var progress = this._progresses.get(requestId); | |
292 if (!progress) | |
293 return; | |
294 progress.setTotalWork(totalWork); | |
295 }, | |
296 | |
297 /** | |
298 * @param {!WebInspector.Event} event | |
299 */ | |
300 _onIndexingWorked: function(event) | |
301 { | |
302 var requestId = /** @type {number} */ (event.data["requestId"]); | |
303 var worked = /** @type {number} */ (event.data["worked"]); | |
304 | |
305 var progress = this._progresses.get(requestId); | |
306 if (!progress) | |
307 return; | |
308 progress.worked(worked); | |
309 if (progress.isCanceled()) { | |
310 InspectorFrontendHost.stopIndexing(requestId); | |
311 this._onIndexingDone(event); | |
312 } | |
313 }, | |
314 | |
315 /** | |
316 * @param {!WebInspector.Event} event | |
317 */ | |
318 _onIndexingDone: function(event) | |
319 { | |
320 var requestId = /** @type {number} */ (event.data["requestId"]); | |
321 | |
322 var progress = this._progresses.get(requestId); | |
323 if (!progress) | |
324 return; | |
325 progress.done(); | |
326 this._progresses.delete(requestId); | |
327 }, | |
328 | |
329 /** | |
330 * @param {!WebInspector.Event} event | |
331 */ | |
332 _onSearchCompleted: function(event) | |
333 { | |
334 var requestId = /** @type {number} */ (event.data["requestId"]); | |
335 var files = /** @type {!Array.<string>} */ (event.data["files"]); | |
336 | |
337 var callback = this._callbacks.get(requestId); | |
338 if (!callback) | |
339 return; | |
340 callback.call(null, files); | |
341 this._callbacks.delete(requestId); | |
342 }, | |
343 | |
344 __proto__: WebInspector.Object.prototype | |
345 }; | |
346 | |
347 /** | 311 /** |
348 * @type {!WebInspector.IsolatedFileSystemManager} | 312 * @type {!WebInspector.IsolatedFileSystemManager} |
349 */ | 313 */ |
350 WebInspector.isolatedFileSystemManager; | 314 WebInspector.isolatedFileSystemManager; |
OLD | NEW |