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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/FileSystemWorkspaceBinding.js

Issue 1523193002: DevTools: merge UISourceCode's parentPath, name, originURL and uri. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 5 years 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 WebInspector.FileSystemWorkspaceBinding._imageExtensions = WebInspector.Isolated FileSystem.ImageExtensions; 59 WebInspector.FileSystemWorkspaceBinding._imageExtensions = WebInspector.Isolated FileSystem.ImageExtensions;
60 60
61 WebInspector.FileSystemWorkspaceBinding._lastRequestId = 0; 61 WebInspector.FileSystemWorkspaceBinding._lastRequestId = 0;
62 62
63 /** 63 /**
64 * @param {string} fileSystemPath 64 * @param {string} fileSystemPath
65 * @return {string} 65 * @return {string}
66 */ 66 */
67 WebInspector.FileSystemWorkspaceBinding.projectId = function(fileSystemPath) 67 WebInspector.FileSystemWorkspaceBinding.projectId = function(fileSystemPath)
68 { 68 {
69 return "filesystem:" + fileSystemPath; 69 return "file://" + fileSystemPath;
70 } 70 }
71 71
72 /** 72 /**
73 * @param {!WebInspector.UISourceCode} uiSourceCode
74 * @return {!Array<string>}
75 */
76 WebInspector.FileSystemWorkspaceBinding.relativePath = function(uiSourceCode)
77 {
78 var baseURL = /** @type {!WebInspector.FileSystemWorkspaceBinding.FileSystem }*/(uiSourceCode.project())._fileSystemBaseURL;
79 return uiSourceCode.path().substring(baseURL.length).split("/");
80 }
81
82 /**
83 * @param {!WebInspector.Project} project
84 * @param {string} relativePath
85 * @return {string}
86 */
87 WebInspector.FileSystemWorkspaceBinding.completeURL = function(project, relative Path)
88 {
89 var fsProject = /** @type {!WebInspector.FileSystemWorkspaceBinding.FileSyst em}*/(project);
90 return fsProject._fileSystemBaseURL + relativePath;
91 }
92
93 /**
73 * @param {string} extension 94 * @param {string} extension
74 * @return {!WebInspector.ResourceType} 95 * @return {!WebInspector.ResourceType}
75 */ 96 */
76 WebInspector.FileSystemWorkspaceBinding._contentTypeForExtension = function(exte nsion) 97 WebInspector.FileSystemWorkspaceBinding._contentTypeForExtension = function(exte nsion)
77 { 98 {
78 if (WebInspector.FileSystemWorkspaceBinding._styleSheetExtensions.has(extens ion)) 99 if (WebInspector.FileSystemWorkspaceBinding._styleSheetExtensions.has(extens ion))
79 return WebInspector.resourceTypes.Stylesheet; 100 return WebInspector.resourceTypes.Stylesheet;
80 if (WebInspector.FileSystemWorkspaceBinding._documentExtensions.has(extensio n)) 101 if (WebInspector.FileSystemWorkspaceBinding._documentExtensions.has(extensio n))
81 return WebInspector.resourceTypes.Document; 102 return WebInspector.resourceTypes.Document;
82 if (WebInspector.FileSystemWorkspaceBinding._imageExtensions.has(extension)) 103 if (WebInspector.FileSystemWorkspaceBinding._imageExtensions.has(extension))
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 150 }
130 } 151 }
131 }, 152 },
132 153
133 /** 154 /**
134 * @param {string} projectId 155 * @param {string} projectId
135 * @return {string} 156 * @return {string}
136 */ 157 */
137 fileSystemPath: function(projectId) 158 fileSystemPath: function(projectId)
138 { 159 {
139 var fileSystemPath = projectId.substr("filesystem:".length); 160 return projectId.substr("file://".length);
140 var normalizedPath = WebInspector.IsolatedFileSystem.normalizePath(fileS ystemPath);
141 return projectId.substr("filesystem:".length);
142 }, 161 },
143 162
144 /** 163 /**
145 * @return {number} 164 * @return {number}
146 */ 165 */
147 _nextId: function() 166 _nextId: function()
148 { 167 {
149 return ++WebInspector.FileSystemWorkspaceBinding._lastRequestId; 168 return ++WebInspector.FileSystemWorkspaceBinding._lastRequestId;
150 }, 169 },
151 170
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 * @implements {WebInspector.Project} 272 * @implements {WebInspector.Project}
254 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding 273 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding
255 * @param {!WebInspector.IsolatedFileSystem} isolatedFileSystem 274 * @param {!WebInspector.IsolatedFileSystem} isolatedFileSystem
256 * @param {!WebInspector.Workspace} workspace 275 * @param {!WebInspector.Workspace} workspace
257 */ 276 */
258 WebInspector.FileSystemWorkspaceBinding.FileSystem = function(fileSystemWorkspac eBinding, isolatedFileSystem, workspace) 277 WebInspector.FileSystemWorkspaceBinding.FileSystem = function(fileSystemWorkspac eBinding, isolatedFileSystem, workspace)
259 { 278 {
260 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; 279 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding;
261 this._fileSystem = isolatedFileSystem; 280 this._fileSystem = isolatedFileSystem;
262 this._fileSystemBaseURL = "file://" + this._fileSystem.normalizedPath() + "/ "; 281 this._fileSystemBaseURL = "file://" + this._fileSystem.normalizedPath() + "/ ";
282 this._fileSystemPath = this._fileSystem.path();
263 283
264 var id = WebInspector.FileSystemWorkspaceBinding.projectId(this._fileSystem. path()); 284 var id = WebInspector.FileSystemWorkspaceBinding.projectId(this._fileSystemP ath);
265 console.assert(!workspace.project(id)); 285 console.assert(!workspace.project(id));
266 286
267 var url = "filesystem:" + this._fileSystem.normalizedPath();
268 var normalizedPath = isolatedFileSystem.normalizedPath(); 287 var normalizedPath = isolatedFileSystem.normalizedPath();
269 var displayName = normalizedPath.substr(normalizedPath.lastIndexOf("/") + 1) ; 288 var displayName = normalizedPath.substr(normalizedPath.lastIndexOf("/") + 1) ;
270 289
271 WebInspector.ProjectStore.call(this, workspace, id, WebInspector.projectType s.FileSystem, url, displayName); 290 WebInspector.ProjectStore.call(this, workspace, id, WebInspector.projectType s.FileSystem, displayName);
272 291
273 workspace.addProject(this); 292 workspace.addProject(this);
274 this.populate(); 293 this.populate();
275 } 294 }
276 295
277 WebInspector.FileSystemWorkspaceBinding.FileSystem.prototype = { 296 WebInspector.FileSystemWorkspaceBinding.FileSystem.prototype = {
278 /** 297 /**
279 * @return {string} 298 * @return {string}
280 */ 299 */
281 fileSystemPath: function() 300 fileSystemPath: function()
282 { 301 {
283 return this._fileSystem.path(); 302 return this._fileSystemPath;
284 }, 303 },
285 304
286 /** 305 /**
287 * @param {!WebInspector.UISourceCode} uiSourceCode 306 * @param {!WebInspector.UISourceCode} uiSourceCode
288 * @return {string} 307 * @return {string}
289 */ 308 */
290 _filePathForUISourceCode: function(uiSourceCode) 309 _filePathForUISourceCode: function(uiSourceCode)
291 { 310 {
292 return "/" + uiSourceCode.path(); 311 return uiSourceCode.path().substring(("file:// " + this._fileSystemPath) .length);
293 }, 312 },
294 313
295 /** 314 /**
296 * @override 315 * @override
297 * @param {!WebInspector.UISourceCode} uiSourceCode 316 * @param {!WebInspector.UISourceCode} uiSourceCode
298 * @param {function(?string)} callback 317 * @param {function(?string)} callback
299 */ 318 */
300 requestFileContent: function(uiSourceCode, callback) 319 requestFileContent: function(uiSourceCode, callback)
301 { 320 {
302 var filePath = this._filePathForUISourceCode(uiSourceCode); 321 var filePath = this._filePathForUISourceCode(uiSourceCode);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 475 }
457 }, 476 },
458 477
459 /** 478 /**
460 * @param {string} query 479 * @param {string} query
461 * @param {!WebInspector.Progress} progress 480 * @param {!WebInspector.Progress} progress
462 * @param {function(!Array.<string>)} callback 481 * @param {function(!Array.<string>)} callback
463 */ 482 */
464 _searchInPath: function(query, progress, callback) 483 _searchInPath: function(query, progress, callback)
465 { 484 {
466 var requestId = this._fileSystemWorkspaceBinding.registerCallback(innerC allback.bind(this)); 485 var requestId = this._fileSystemWorkspaceBinding.registerCallback(innerC allback);
467 InspectorFrontendHost.searchInPath(requestId, this._fileSystem.path(), q uery); 486 InspectorFrontendHost.searchInPath(requestId, this._fileSystem.path(), q uery);
468 487
469 /** 488 /**
470 * @param {!Array.<string>} files 489 * @param {!Array.<string>} files
471 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem}
472 */ 490 */
473 function innerCallback(files) 491 function innerCallback(files)
474 { 492 {
475 /** 493 /**
476 * @param {string} fullPath 494 * @param {string} fullPath
477 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem} 495 * @return {string}
478 */ 496 */
479 function trimAndNormalizeFileSystemPath(fullPath) 497 function trimAndNormalizeFileSystemPath(fullPath)
480 { 498 {
481 var trimmedPath = fullPath.substr(this._fileSystem.path().length + 1); 499 fullPath = "file://" + fullPath;
482 if (WebInspector.isWin()) 500 if (WebInspector.isWin())
483 trimmedPath = trimmedPath.replace(/\\/g, "/"); 501 fullPath = fullPath.replace(/\\/g, "/");
484 return trimmedPath; 502 return fullPath;
485 } 503 }
486 504
487 files = files.map(trimAndNormalizeFileSystemPath.bind(this)); 505 files = files.map(trimAndNormalizeFileSystemPath);
488 progress.worked(1); 506 progress.worked(1);
489 callback(files); 507 callback(files);
490 } 508 }
491 }, 509 },
492 510
493 /** 511 /**
494 * @override 512 * @override
495 * @param {!WebInspector.Progress} progress 513 * @param {!WebInspector.Progress} progress
496 */ 514 */
497 indexContent: function(progress) 515 indexContent: function(progress)
(...skipping 29 matching lines...) Expand all
527 { 545 {
528 this._fileSystem.requestFilesRecursive(path, this._addFile.bind(this), c allback); 546 this._fileSystem.requestFilesRecursive(path, this._addFile.bind(this), c allback);
529 }, 547 },
530 548
531 /** 549 /**
532 * @override 550 * @override
533 * @param {string} path 551 * @param {string} path
534 */ 552 */
535 excludeFolder: function(path) 553 excludeFolder: function(path)
536 { 554 {
537 this._fileSystem.addExcludedFolder(path); 555 var relativeFolder = path.substring(this._fileSystemBaseURL.length);
556 if (!relativeFolder.startsWith("/"))
557 relativeFolder = "/" + relativeFolder;
558 if (!relativeFolder.endsWith("/"))
559 relativeFolder += "/";
560 this._fileSystem.addExcludedFolder(relativeFolder);
561
538 var uiSourceCodes = this.uiSourceCodes().slice(); 562 var uiSourceCodes = this.uiSourceCodes().slice();
539 for (var i = 0; i < uiSourceCodes.length; ++i) { 563 for (var i = 0; i < uiSourceCodes.length; ++i) {
540 var uiSourceCode = uiSourceCodes[i]; 564 var uiSourceCode = uiSourceCodes[i];
541 if (uiSourceCode.path().startsWith(path.substr(1))) 565 if (uiSourceCode.path().startsWith(path))
542 this.removeUISourceCode(uiSourceCode.path()); 566 this.removeUISourceCode(uiSourceCode.path());
543 } 567 }
544 }, 568 },
545 569
546 /** 570 /**
547 * @override 571 * @override
548 * @param {string} path 572 * @param {string} path
549 * @param {?string} name 573 * @param {?string} name
550 * @param {string} content 574 * @param {string} content
551 * @param {function(?WebInspector.UISourceCode)} callback 575 * @param {function(?WebInspector.UISourceCode)} callback
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 626
603 /** 627 /**
604 * @param {string} filePath 628 * @param {string} filePath
605 * @return {!WebInspector.UISourceCode} 629 * @return {!WebInspector.UISourceCode}
606 */ 630 */
607 _addFile: function(filePath) 631 _addFile: function(filePath)
608 { 632 {
609 if (!filePath) 633 if (!filePath)
610 console.assert(false); 634 console.assert(false);
611 635
612 var slash = filePath.lastIndexOf("/"); 636 var extension = this._extensionForPath(filePath);
613 var parentPath = filePath.substring(0, slash);
614 var name = filePath.substring(slash + 1);
615
616 var extension = this._extensionForPath(name);
617 var contentType = WebInspector.FileSystemWorkspaceBinding._contentTypeFo rExtension(extension); 637 var contentType = WebInspector.FileSystemWorkspaceBinding._contentTypeFo rExtension(extension);
618 638
619 var uiSourceCode = this.createUISourceCode(parentPath, name, this._fileS ystemBaseURL + filePath, contentType); 639 var uiSourceCode = this.createUISourceCode(this._fileSystemBaseURL + fil ePath, contentType);
620 this.addUISourceCode(uiSourceCode); 640 this.addUISourceCode(uiSourceCode);
621 return uiSourceCode; 641 return uiSourceCode;
622 }, 642 },
623 643
624 /** 644 /**
625 * @param {string} path 645 * @param {string} path
626 */ 646 */
627 _fileChanged: function(path) 647 _fileChanged: function(path)
628 { 648 {
629 var uiSourceCode = this.uiSourceCode(path); 649 var uiSourceCode = this.uiSourceCode(path);
630 if (!uiSourceCode) { 650 if (!uiSourceCode) {
631 this._addFile(path); 651 this._addFile(path);
632 return; 652 return;
633 } 653 }
634 uiSourceCode.checkContentUpdated(); 654 uiSourceCode.checkContentUpdated();
635 }, 655 },
636 656
637 dispose: function() 657 dispose: function()
638 { 658 {
639 this.removeProject(); 659 this.removeProject();
640 }, 660 },
641 661
642 __proto__: WebInspector.ProjectStore.prototype 662 __proto__: WebInspector.ProjectStore.prototype
643 } 663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698