Changeset 143451 in webkit


Ignore:
Timestamp:
Feb 20, 2013 4:33:20 AM (11 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: Make UISourceCode.path() an array of path segments.
https://bugs.webkit.org/show_bug.cgi?id=110229

Reviewed by Pavel Feldman.

Source/WebCore:

  • inspector/front-end/FileSystemProjectDelegate.js:

(WebInspector.FileSystemProjectDelegate.prototype._filePathForPath):
(WebInspector.FileSystemProjectDelegate.prototype.innerCallback):
(WebInspector.FileSystemProjectDelegate.prototype.requestFileContent):
(WebInspector.FileSystemProjectDelegate.prototype._contentTypeForPath):
(WebInspector.FileSystemProjectDelegate.prototype.populate.filesLoaded):
(WebInspector.FileSystemProjectDelegate.prototype.populate):

  • inspector/front-end/SimpleWorkspaceProvider.js:

(WebInspector.SimpleProjectDelegate.prototype.requestFileContent):
(WebInspector.SimpleProjectDelegate.prototype.searchInFileContent):
(WebInspector.SimpleProjectDelegate.prototype.addFile):
(WebInspector.SimpleProjectDelegate.prototype._ensureUniquePath):
(WebInspector.SimpleProjectDelegate.prototype.removeFile):
(WebInspector.SimpleWorkspaceProvider.pathForSplittedURL):
(WebInspector.SimpleWorkspaceProvider.prototype.addFileByName):
(WebInspector.SimpleWorkspaceProvider.prototype.removeFileByName):

  • inspector/front-end/UISourceCode.js:

(WebInspector.UISourceCode.prototype.uri):

  • inspector/front-end/Workspace.js:

(WebInspector.Project.prototype._fileAdded):
(WebInspector.Project.prototype._fileRemoved):
(WebInspector.Project.prototype.uiSourceCode):
(WebInspector.Workspace.prototype.uiSourceCodeForURL):
(WebInspector.Workspace.prototype.urlForPath):

LayoutTests:

  • inspector/workspace-mapping.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r143450 r143451  
     12013-02-19  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Make UISourceCode.path() an array of path segments.
     4        https://bugs.webkit.org/show_bug.cgi?id=110229
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/workspace-mapping.html:
     9
    1102013-02-20  Takashi Toyoshima  <toyoshim@chromium.org>
    211
  • trunk/LayoutTests/inspector/workspace-mapping.html

    r143448 r143451  
    3131
    3232        addUISourceCode: function(path) {
    33             var fileDescriptor = new WebInspector.FileDescriptor(path, path, path, WebInspector.resourceTypes.Script, true, false);
     33            var fileDescriptor = new WebInspector.FileDescriptor(path.split("/"), path, path, WebInspector.resourceTypes.Script, true, false);
    3434            this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileAdded, fileDescriptor);
    3535        },
  • trunk/Source/WebCore/ChangeLog

    r143449 r143451  
     12013-02-19  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Make UISourceCode.path() an array of path segments.
     4        https://bugs.webkit.org/show_bug.cgi?id=110229
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/front-end/FileSystemProjectDelegate.js:
     9        (WebInspector.FileSystemProjectDelegate.prototype._filePathForPath):
     10        (WebInspector.FileSystemProjectDelegate.prototype.innerCallback):
     11        (WebInspector.FileSystemProjectDelegate.prototype.requestFileContent):
     12        (WebInspector.FileSystemProjectDelegate.prototype._contentTypeForPath):
     13        (WebInspector.FileSystemProjectDelegate.prototype.populate.filesLoaded):
     14        (WebInspector.FileSystemProjectDelegate.prototype.populate):
     15        * inspector/front-end/SimpleWorkspaceProvider.js:
     16        (WebInspector.SimpleProjectDelegate.prototype.requestFileContent):
     17        (WebInspector.SimpleProjectDelegate.prototype.searchInFileContent):
     18        (WebInspector.SimpleProjectDelegate.prototype.addFile):
     19        (WebInspector.SimpleProjectDelegate.prototype._ensureUniquePath):
     20        (WebInspector.SimpleProjectDelegate.prototype.removeFile):
     21        (WebInspector.SimpleWorkspaceProvider.pathForSplittedURL):
     22        (WebInspector.SimpleWorkspaceProvider.prototype.addFileByName):
     23        (WebInspector.SimpleWorkspaceProvider.prototype.removeFileByName):
     24        * inspector/front-end/UISourceCode.js:
     25        (WebInspector.UISourceCode.prototype.uri):
     26        * inspector/front-end/Workspace.js:
     27        (WebInspector.Project.prototype._fileAdded):
     28        (WebInspector.Project.prototype._fileRemoved):
     29        (WebInspector.Project.prototype.uiSourceCode):
     30        (WebInspector.Workspace.prototype.uiSourceCodeForURL):
     31        (WebInspector.Workspace.prototype.urlForPath):
     32
    1332013-02-20  Yury Semikhatsky  <yurys@chromium.org>
    234
  • trunk/Source/WebCore/inspector/front-end/FileSystemProjectDelegate.js

    r143448 r143451  
    7070
    7171    /**
    72      * @param {string} path
     72     * @param {Array.<string>} path
    7373     * @return {string}
    7474     */
    7575    _filePathForPath: function(path)
    7676    {
    77         return "/" + path;
    78     },
    79 
    80     /**
    81      * @param {string} path
     77        return "/" + path.join("/");
     78    },
     79
     80    /**
     81     * @param {Array.<string>} path
    8282     * @param {function(?string,boolean,string)} callback
    8383     */
     
    9292        function innerCallback(content)
    9393        {
    94             var contentType = this._contentTypeForPath(filePath);
     94            var contentType = this._contentTypeForPath(path);
    9595            callback(content, false, contentType.canonicalMimeType());
    9696        }
     
    9898
    9999    /**
    100      * @param {string} path
     100     * @param {Array.<string>} path
    101101     * @param {string} newContent
    102102     * @param {function(?string)} callback
     
    109109
    110110    /**
    111      * @param {string} path
     111     * @param {Array.<string>} path
    112112     * @param {string} query
    113113     * @param {boolean} caseSensitive
     
    134134
    135135    /**
    136      * @param {string} path
     136     * @param {Array.<string>} path
    137137     * @return {WebInspector.ResourceType}
    138138     */
    139139    _contentTypeForPath: function(path)
    140140    {
    141         var splittedPath = path.split("/");
    142         var fileName = splittedPath[splittedPath.length - 1];
     141        var fileName = path[path.length - 1];
    143142        var extensionIndex = fileName.lastIndexOf(".");
    144143        var extension = "";
     
    162161        {
    163162            for (var i = 0; i < files.length; ++i) {
     163                var path = files[i].split("/");
     164                path.shift();
     165                console.assert(path.length);
    164166                var fullPath = this._fileSystem.path() + files[i];
    165                 var path = files[i].substr(1);
    166167                var url = this._workspace.urlForPath(fullPath);
    167168                var contentType = this._contentTypeForPath(path);
     
    181182
    182183    /**
    183      * @param {string} path
     184     * @param {Array.<string>} path
    184185     */
    185186    _removeFile: function(path)
  • trunk/Source/WebCore/inspector/front-end/SimpleWorkspaceProvider.js

    r143448 r143451  
    8686
    8787    /**
    88      * @param {string} path
     88     * @param {Array.<string>} path
    8989     * @param {function(?string,boolean,string)} callback
    9090     */
    9191    requestFileContent: function(path, callback)
    9292    {
    93         var contentProvider = this._contentProviders[path];
     93        var contentProvider = this._contentProviders[path.join("/")];
    9494        contentProvider.requestContent(callback);
    9595    },
    9696
    9797    /**
    98      * @param {string} path
     98     * @param {Array.<string>} path
    9999     * @param {string} newContent
    100100     * @param {function(?string)} callback
     
    106106
    107107    /**
    108      * @param {string} path
     108     * @param {Array.<string>} path
    109109     * @param {string} query
    110110     * @param {boolean} caseSensitive
     
    114114    searchInFileContent: function(path, query, caseSensitive, isRegex, callback)
    115115    {
    116         var contentProvider = this._contentProviders[path];
     116        var contentProvider = this._contentProviders[path.join("/")];
    117117        contentProvider.searchInContent(query, caseSensitive, isRegex, callback);
    118118    },
    119119
    120120    /**
    121      * @param {string} path
     121     * @param {Array.<string>} path
    122122     * @param {string} url
    123123     * @param {WebInspector.ContentProvider} contentProvider
    124124     * @param {boolean} isEditable
    125125     * @param {boolean=} isContentScript
    126      * @return {string}
     126     * @return {Array.<string>}
    127127     */
    128128    addFile: function(path, forceUniquePath, url, contentProvider, isEditable, isContentScript)
    129129    {
    130130        if (forceUniquePath)
    131             path = this._uniquePath(path);
     131            this._ensureUniquePath(path);
    132132        var fileDescriptor = new WebInspector.FileDescriptor(path, url, url, contentProvider.contentType(), isEditable, isContentScript);
    133         this._contentProviders[path] = contentProvider;
     133        this._contentProviders[path.join("/")] = contentProvider;
    134134        this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileAdded, fileDescriptor);
    135135        return path;
     
    137137
    138138    /**
    139      * @param {string} path
    140      * @return {string}
    141      */
    142     _uniquePath: function(path)
    143     {
    144         var uniquePath = path;
    145         while (this._contentProviders[uniquePath])
    146             uniquePath = path + " (" + (++this._lastUniqueSuffix) + ")";
    147         return uniquePath;
    148     },
    149 
    150     /**
    151      * @param {string} path
     139     * @param {Array.<string>} path
     140     */
     141    _ensureUniquePath: function(path)
     142     {
     143        var uniquePath = path.join("/");
     144        var suffix = "";
     145        while (this._contentProviders[uniquePath]) {
     146            suffix = " (" + (++this._lastUniqueSuffix) + ")";
     147            uniquePath = path + suffix;
     148        }
     149        path[path.length - 1] += suffix;
     150    },
     151
     152    /**
     153     * @param {Array.<string>} path
    152154     */
    153155    removeFile: function(path)
    154156    {
    155         delete this._contentProviders[path];
     157        delete this._contentProviders[path.join("/")];
    156158        this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileRemoved, path);
    157159    },
     
    212214/**
    213215 * @param {Array.<string>} splittedURL
    214  * @return {string}
     216 * @return {Array.<string>}
    215217 */
    216218WebInspector.SimpleWorkspaceProvider.pathForSplittedURL = function(splittedURL)
    217219{
    218     splittedURL.shift();
    219     return splittedURL.join("/");
     220    var result = splittedURL.slice();
     221    result.shift();
     222    return result;
    220223}
    221224
     
    285288    addFileByName: function(projectName, name, contentProvider, isEditable, isContentScript)
    286289    {
    287         return this._innerAddFile("", name, name, contentProvider, isEditable, false, isContentScript);
     290        return this._innerAddFile("", [name], name, contentProvider, isEditable, false, isContentScript);
    288291    },
    289292
    290293    /**
    291294     * @param {string} projectName
    292      * @param {string} path
     295     * @param {Array.<string>} path
    293296     * @param {WebInspector.ContentProvider} contentProvider
    294297     * @param {boolean} isEditable
     
    306309    /**
    307310     * @param {string} projectName
    308      * @param {string} path
    309      */
    310     removeFileByName: function(projectName, path)
     311     * @param {string} name
     312     */
     313    removeFileByName: function(projectName, name)
    311314    {
    312315        var projectDelegate = this._projectDelegate(projectName);
    313         projectDelegate.removeFile(path);
     316        projectDelegate.removeFile([name]);
    314317    },
    315318
  • trunk/Source/WebCore/inspector/front-end/UISourceCode.js

    r143202 r143451  
    3535 * @implements {WebInspector.ContentProvider}
    3636 * @param {WebInspector.Project} project
    37  * @param {string} path
     37 * @param {Array.<string>} path
    3838 * @param {string} url
    3939 * @param {WebInspector.ResourceType} contentType
     
    8282}
    8383
    84 /**
    85  * @param {string} projectId
    86  * @param {string} path
    87  * @return {string}
    88  */
    89 WebInspector.UISourceCode.uri = function(projectId, path)
    90 {
    91     if (!projectId)
    92         return path;
    93     if (!path)
    94         return projectId;
    95     return projectId + "/" + path;
    96 }
    97 
    98 /**
    99  * @param {string} projectId
    100  * @param {string} uri
    101  * @return {?string}
    102  */
    103 WebInspector.UISourceCode.path = function(projectId, uri)
    104 {
    105     if (!projectId)
    106         return uri;
    107     if (!uri.startsWith(projectId))
    108         return null;
    109     var path = uri.substr(projectId.length);
    110     if (path.length && path[0] === "/")
    111         path = path.substr(1);
    112     return path;
    113 }
    114 
    11584WebInspector.UISourceCode.prototype = {
    11685    /**
     
    12392
    12493    /**
     94     * @return {Array.<string>}
     95     */
     96    path: function()
     97    {
     98        return this._path;
     99    },
     100
     101    /**
    125102     * @return {string}
    126103     */
    127     path: function()
    128     {
    129         return this._path;
    130     },
    131 
    132     /**
    133      * @return {string}
    134      */
    135104    uri: function()
    136105    {
    137         return WebInspector.UISourceCode.uri(this._project.id(), this._path);
     106        if (!this._project.id())
     107            return this._path.join("/");
     108        if (!this._path.length)
     109            return this._project.id();
     110        return this._project.id() + "/" + this._path.join("/");
    138111    },
    139112
  • trunk/Source/WebCore/inspector/front-end/Workspace.js

    r143448 r143451  
    5050/**
    5151 * @constructor
    52  * @param {string} path
     52 * @param {Array.<string>} path
    5353 * @param {string} originURL
    5454 * @param {string} url
     
    9595
    9696    /**
    97      * @param {string} path
     97     * @param {Array.<string>} path
    9898     * @param {function(?string,boolean,string)} callback
    9999     */
     
    101101
    102102    /**
    103      * @param {string} path
     103     * @param {Array.<string>} path
    104104     * @param {string} newContent
    105105     * @param {function(?string)} callback
     
    108108
    109109    /**
    110      * @param {string} path
     110     * @param {Array.<string>} path
    111111     * @param {string} query
    112112     * @param {boolean} caseSensitive
     
    195195        uiSourceCode = new WebInspector.UISourceCode(this, fileDescriptor.path, fileDescriptor.originURL, fileDescriptor.url, fileDescriptor.contentType, fileDescriptor.isEditable);
    196196        uiSourceCode.isContentScript = fileDescriptor.isContentScript;
    197         this._uiSourceCodes[uiSourceCode.path()] = uiSourceCode;
     197        this._uiSourceCodes[uiSourceCode.path().join("/")] = uiSourceCode;
    198198        this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode);
    199199    },
     
    201201    _fileRemoved: function(event)
    202202    {
    203         var path = /** @type {string} */ (event.data);
     203        var path = /** @type {Array.<string>} */ (event.data);
    204204        var uiSourceCode = this.uiSourceCode(path);
    205205        if (!uiSourceCode)
    206206            return;
    207         delete this._uiSourceCodes[uiSourceCode.path()];
     207        delete this._uiSourceCodes[uiSourceCode.path().join("/")];
    208208        this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, uiSourceCode);
    209209    },
     
    216216
    217217    /**
    218      * @param {string} path
     218     * @param {Array.<string>} path
    219219     * @return {?WebInspector.UISourceCode}
    220220     */
    221221    uiSourceCode: function(path)
    222222    {
    223         return this._uiSourceCodes[path] || null;
     223        return this._uiSourceCodes[path.join("/")] || null;
    224224    },
    225225
     
    236236        }
    237237        return null;
    238     },
    239 
    240     /**
    241      * @param {string} uri
    242      * @return {?WebInspector.UISourceCode}
    243      */
    244     uiSourceCodeForURI: function(uri)
    245     {
    246         var path = WebInspector.UISourceCode.path(this.id(), uri);
    247         if (typeof path !== "string")
    248             return null;
    249         return this._uiSourceCodes[path];
    250238    },
    251239
     
    327315    /**
    328316     * @param {string} projectId
    329      * @param {string} path
     317     * @param {Array.<string>} path
    330318     * @return {?WebInspector.UISourceCode}
    331319     */
     
    346334            var project = networkProjects[i];
    347335            var uiSourceCode = project.uiSourceCodeForOriginURL(originURL);
    348             if (uiSourceCode)
    349                 return uiSourceCode;
    350         }
    351         return null;
    352     },
    353 
    354     /**
    355      * @param {string} uri
    356      * @return {?WebInspector.UISourceCode}
    357      */
    358     uiSourceCodeForURI: function(uri)
    359     {
    360         for (var projectId in this._projects) {
    361             var project = this._projects[projectId];
    362             var uiSourceCode = project.uiSourceCodeForURI(uri);
    363336            if (uiSourceCode)
    364337                return uiSourceCode;
     
    488461        var path = pathPrefix + url.substr(entry.urlPrefix.length);
    489462        var project = this.project(projectId);
    490         return project ? project.uiSourceCode(path) : null;
     463        return project ? project.uiSourceCode(path.split("/")) : null;
    491464    },
    492465
Note: See TracChangeset for help on using the changeset viewer.