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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/workspace/FileSystemMapping.js

Issue 2780903003: DevTools: [Workspaces] remove support for .devtools file (Closed)
Patch Set: rebaseline Created 3 years, 8 months 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) 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
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fi leSystemRemoved, this), 49 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fi leSystemRemoved, this),
50 ]; 50 ];
51 fileSystemManager.waitForFileSystems().then(this._fileSystemsLoaded.bind(thi s)); 51 fileSystemManager.waitForFileSystems().then(this._fileSystemsLoaded.bind(thi s));
52 } 52 }
53 53
54 /** 54 /**
55 * @param {!Array<!Workspace.IsolatedFileSystem>} fileSystems 55 * @param {!Array<!Workspace.IsolatedFileSystem>} fileSystems
56 */ 56 */
57 _fileSystemsLoaded(fileSystems) { 57 _fileSystemsLoaded(fileSystems) {
58 for (var fileSystem of fileSystems) 58 for (var fileSystem of fileSystems)
59 this._addMappingsForFilesystem(fileSystem); 59 this.addFileSystem(fileSystem.path());
60 } 60 }
61 61
62 /** 62 /**
63 * @param {!Common.Event} event 63 * @param {!Common.Event} event
64 */ 64 */
65 _fileSystemAdded(event) { 65 _fileSystemAdded(event) {
66 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); 66 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data);
67 this._addMappingsForFilesystem(fileSystem); 67 this.addFileSystem(fileSystem.path());
68 } 68 }
69 69
70 /** 70 /**
71 * @param {!Workspace.IsolatedFileSystem} fileSystem
72 */
73 _addMappingsForFilesystem(fileSystem) {
74 this.addFileSystem(fileSystem.path());
75
76 var mappings = fileSystem.projectProperty('mappings');
77 for (var i = 0; Array.isArray(mappings) && i < mappings.length; ++i) {
78 var mapping = mappings[i];
79 if (!mapping || typeof mapping !== 'object')
80 continue;
81 var folder = mapping['folder'];
82 var url = mapping['url'];
83 if (typeof folder !== 'string' || typeof url !== 'string')
84 continue;
85 this.addNonConfigurableFileMapping(fileSystem.path(), url, folder);
86 }
87 }
88
89 /**
90 * @param {!Common.Event} event 71 * @param {!Common.Event} event
91 */ 72 */
92 _fileSystemRemoved(event) { 73 _fileSystemRemoved(event) {
93 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); 74 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data);
94 this.removeFileSystem(fileSystem.path()); 75 this.removeFileSystem(fileSystem.path());
95 } 76 }
96 77
97 _loadFromSettings() { 78 _loadFromSettings() {
98 var savedMapping = this._fileSystemMappingSetting.get(); 79 var savedMapping = this._fileSystemMappingSetting.get();
99 this._fileSystemMappings = {}; 80 this._fileSystemMappings = {};
100 for (var fileSystemPath in savedMapping) { 81 for (var fileSystemPath in savedMapping) {
101 var savedFileSystemMappings = savedMapping[fileSystemPath]; 82 var savedFileSystemMappings = savedMapping[fileSystemPath];
102 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath); 83 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath);
103 this._fileSystemMappings[fileSystemPath] = []; 84 this._fileSystemMappings[fileSystemPath] = [];
104 var fileSystemMappings = this._fileSystemMappings[fileSystemPath]; 85 var fileSystemMappings = this._fileSystemMappings[fileSystemPath];
105 86
106 for (var i = 0; i < savedFileSystemMappings.length; ++i) { 87 for (var i = 0; i < savedFileSystemMappings.length; ++i) {
107 var savedEntry = savedFileSystemMappings[i]; 88 var savedEntry = savedFileSystemMappings[i];
108 var entry = 89 var entry = new Workspace.FileSystemMapping.Entry(fileSystemPath, savedE ntry.urlPrefix, savedEntry.pathPrefix);
109 new Workspace.FileSystemMapping.Entry(fileSystemPath, savedEntry.url Prefix, savedEntry.pathPrefix, true);
110 fileSystemMappings.push(entry); 90 fileSystemMappings.push(entry);
111 } 91 }
112 } 92 }
113 93
114 this._rebuildIndexes(); 94 this._rebuildIndexes();
115 } 95 }
116 96
117 _saveToSettings() { 97 _saveToSettings() {
118 var setting = {}; 98 var setting = {};
119 for (var fileSystemPath in this._fileSystemMappings) { 99 for (var fileSystemPath in this._fileSystemMappings) {
120 setting[fileSystemPath] = []; 100 setting[fileSystemPath] = [];
121 var entries = this._fileSystemMappings[fileSystemPath]; 101 var entries = this._fileSystemMappings[fileSystemPath];
122 for (var entry of entries) { 102 for (var entry of entries)
123 if (entry.configurable) 103 setting[fileSystemPath].push(entry);
124 setting[fileSystemPath].push(entry);
125 }
126 } 104 }
127 this._fileSystemMappingSetting.set(setting); 105 this._fileSystemMappingSetting.set(setting);
128 } 106 }
129 107
130 _rebuildIndexes() { 108 _rebuildIndexes() {
131 // We are building an index here to search for the longest url prefix match faster. 109 // We are building an index here to search for the longest url prefix match faster.
132 this._mappingForURLPrefix = {}; 110 this._mappingForURLPrefix = {};
133 this._urlPrefixes = []; 111 this._urlPrefixes = [];
134 for (var fileSystemPath in this._fileSystemMappings) { 112 for (var fileSystemPath in this._fileSystemMappings) {
135 var fileSystemMapping = this._fileSystemMappings[fileSystemPath]; 113 var fileSystemMapping = this._fileSystemMappings[fileSystemPath];
136 for (var i = 0; i < fileSystemMapping.length; ++i) { 114 for (var i = 0; i < fileSystemMapping.length; ++i) {
137 var entry = fileSystemMapping[i]; 115 var entry = fileSystemMapping[i];
138 // Resolve conflict in favor of configurable mapping.
139 if (this._mappingForURLPrefix[entry.urlPrefix] && !entry.configurable)
140 continue;
141 this._mappingForURLPrefix[entry.urlPrefix] = entry; 116 this._mappingForURLPrefix[entry.urlPrefix] = entry;
142 if (this._urlPrefixes.indexOf(entry.urlPrefix) === -1) 117 if (this._urlPrefixes.indexOf(entry.urlPrefix) === -1)
143 this._urlPrefixes.push(entry.urlPrefix); 118 this._urlPrefixes.push(entry.urlPrefix);
144 } 119 }
145 } 120 }
146 this._urlPrefixes.sort(); 121 this._urlPrefixes.sort();
147 } 122 }
148 123
149 /** 124 /**
150 * @param {string} fileSystemPath 125 * @param {string} fileSystemPath
(...skipping 22 matching lines...) Expand all
173 * @param {string} urlPrefix 148 * @param {string} urlPrefix
174 * @param {string} pathPrefix 149 * @param {string} pathPrefix
175 */ 150 */
176 addFileMapping(fileSystemPath, urlPrefix, pathPrefix) { 151 addFileMapping(fileSystemPath, urlPrefix, pathPrefix) {
177 if (!urlPrefix.endsWith('/')) 152 if (!urlPrefix.endsWith('/'))
178 urlPrefix += '/'; 153 urlPrefix += '/';
179 if (!pathPrefix.endsWith('/')) 154 if (!pathPrefix.endsWith('/'))
180 pathPrefix += '/'; 155 pathPrefix += '/';
181 if (!pathPrefix.startsWith('/')) 156 if (!pathPrefix.startsWith('/'))
182 pathPrefix = '/' + pathPrefix; 157 pathPrefix = '/' + pathPrefix;
183 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, true); 158 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix);
184 this._saveToSettings(); 159 this._saveToSettings();
185 } 160 }
186 161
187 /** 162 /**
188 * @param {string} fileSystemPath 163 * @param {string} fileSystemPath
189 * @param {string} urlPrefix 164 * @param {string} urlPrefix
190 * @param {string} pathPrefix 165 * @param {string} pathPrefix
191 */ 166 */
192 addNonConfigurableFileMapping(fileSystemPath, urlPrefix, pathPrefix) { 167 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix) {
193 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, false); 168 var entry = new Workspace.FileSystemMapping.Entry(fileSystemPath, urlPrefix, pathPrefix);
194 }
195
196 /**
197 * @param {string} fileSystemPath
198 * @param {string} urlPrefix
199 * @param {string} pathPrefix
200 * @param {boolean} configurable
201 */
202 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, configurable) {
203 var entry = new Workspace.FileSystemMapping.Entry(fileSystemPath, urlPrefix, pathPrefix, configurable);
204 this._fileSystemMappings[fileSystemPath].push(entry); 169 this._fileSystemMappings[fileSystemPath].push(entry);
205 this._rebuildIndexes(); 170 this._rebuildIndexes();
206 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping Added, entry); 171 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping Added, entry);
207 } 172 }
208 173
209 /** 174 /**
210 * @param {string} fileSystemPath 175 * @param {string} fileSystemPath
211 * @param {string} urlPrefix 176 * @param {string} urlPrefix
212 * @param {string} pathPrefix 177 * @param {string} pathPrefix
213 */ 178 */
(...skipping 26 matching lines...) Expand all
240 * @return {?Workspace.FileSystemMapping.Entry} 205 * @return {?Workspace.FileSystemMapping.Entry}
241 */ 206 */
242 _mappingEntryForPath(fileSystemPath, filePath) { 207 _mappingEntryForPath(fileSystemPath, filePath) {
243 var entries = this._fileSystemMappings[fileSystemPath]; 208 var entries = this._fileSystemMappings[fileSystemPath];
244 if (!entries) 209 if (!entries)
245 return null; 210 return null;
246 211
247 var entry = null; 212 var entry = null;
248 for (var i = 0; i < entries.length; ++i) { 213 for (var i = 0; i < entries.length; ++i) {
249 var pathPrefix = entries[i].pathPrefix; 214 var pathPrefix = entries[i].pathPrefix;
250 if (entry && entry.configurable && !entries[i].configurable)
251 continue;
252 // We are looking for the longest pathPrefix match. 215 // We are looking for the longest pathPrefix match.
253 if (entry && entry.pathPrefix.length > pathPrefix.length) 216 if (entry && entry.pathPrefix.length > pathPrefix.length)
254 continue; 217 continue;
255 if (filePath.startsWith(pathPrefix)) 218 if (filePath.startsWith(pathPrefix))
256 entry = entries[i]; 219 entry = entries[i];
257 } 220 }
258 return entry; 221 return entry;
259 } 222 }
260 223
261 /** 224 /**
262 * @param {string} fileSystemPath 225 * @param {string} fileSystemPath
263 * @param {string} pathPrefix 226 * @param {string} pathPrefix
264 * @return {?Workspace.FileSystemMapping.Entry} 227 * @return {?Workspace.FileSystemMapping.Entry}
265 */ 228 */
266 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) { 229 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) {
267 var entries = this._fileSystemMappings[fileSystemPath]; 230 var entries = this._fileSystemMappings[fileSystemPath];
268 for (var i = 0; i < entries.length; ++i) { 231 for (var i = 0; i < entries.length; ++i) {
269 if (entries[i].configurable && pathPrefix === entries[i].pathPrefix) 232 if (pathPrefix === entries[i].pathPrefix)
270 return entries[i]; 233 return entries[i];
271 } 234 }
272 return null; 235 return null;
273 } 236 }
274 237
275 /** 238 /**
276 * @param {string} fileSystemPath 239 * @param {string} fileSystemPath
277 * @return {!Array.<!Workspace.FileSystemMapping.Entry>} 240 * @return {!Array.<!Workspace.FileSystemMapping.Entry>}
278 */ 241 */
279 mappingEntries(fileSystemPath) { 242 mappingEntries(fileSystemPath) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (!entry) 276 if (!entry)
314 return ''; 277 return '';
315 return entry.urlPrefix + relativePath.substring(entry.pathPrefix.length); 278 return entry.urlPrefix + relativePath.substring(entry.pathPrefix.length);
316 } 279 }
317 280
318 /** 281 /**
319 * @param {string} url 282 * @param {string} url
320 */ 283 */
321 removeMappingForURL(url) { 284 removeMappingForURL(url) {
322 var entry = this._mappingEntryForURL(url); 285 var entry = this._mappingEntryForURL(url);
323 if (!entry || !entry.configurable) 286 if (!entry)
324 return; 287 return;
325 this._fileSystemMappings[entry.fileSystemPath].remove(entry); 288 this._fileSystemMappings[entry.fileSystemPath].remove(entry);
326 this._saveToSettings(); 289 this._saveToSettings();
327 } 290 }
328 291
329 /** 292 /**
330 * @param {string} url 293 * @param {string} url
331 * @param {string} fileSystemPath 294 * @param {string} fileSystemPath
332 * @param {string} filePath 295 * @param {string} filePath
333 */ 296 */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 }; 330 };
368 331
369 /** 332 /**
370 * @unrestricted 333 * @unrestricted
371 */ 334 */
372 Workspace.FileSystemMapping.Entry = class { 335 Workspace.FileSystemMapping.Entry = class {
373 /** 336 /**
374 * @param {string} fileSystemPath 337 * @param {string} fileSystemPath
375 * @param {string} urlPrefix 338 * @param {string} urlPrefix
376 * @param {string} pathPrefix 339 * @param {string} pathPrefix
377 * @param {boolean} configurable
378 */ 340 */
379 constructor(fileSystemPath, urlPrefix, pathPrefix, configurable) { 341 constructor(fileSystemPath, urlPrefix, pathPrefix) {
380 this.fileSystemPath = fileSystemPath; 342 this.fileSystemPath = fileSystemPath;
381 this.urlPrefix = urlPrefix; 343 this.urlPrefix = urlPrefix;
382 this.pathPrefix = pathPrefix; 344 this.pathPrefix = pathPrefix;
383 this.configurable = configurable;
384 } 345 }
385 }; 346 };
386 347
387 /** 348 /**
388 * @type {!Workspace.FileSystemMapping} 349 * @type {!Workspace.FileSystemMapping}
389 */ 350 */
390 Workspace.fileSystemMapping; 351 Workspace.fileSystemMapping;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698