Home | History | Annotate | Download | only in sdk
      1 /*
      2  * Copyright (C) 2012 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     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.
     29  */
     30 
     31 /**
     32  * @constructor
     33  * @extends {WebInspector.ContentProviderBasedProjectDelegate}
     34  * @param {!WebInspector.Workspace} workspace
     35  * @param {string} projectId
     36  * @param {string} projectName
     37  * @param {!WebInspector.projectTypes} projectType
     38  */
     39 WebInspector.NetworkProjectDelegate = function(workspace, projectId, projectName, projectType)
     40 {
     41     this._name = projectName;
     42     this._id = projectId;
     43     WebInspector.ContentProviderBasedProjectDelegate.call(this, workspace, projectId, projectType);
     44     this._lastUniqueSuffix = 0;
     45 }
     46 
     47 WebInspector.NetworkProjectDelegate.prototype = {
     48     /**
     49      * @return {string}
     50      */
     51     id: function()
     52     {
     53         return this._id;
     54     },
     55 
     56     /**
     57      * @return {string}
     58      */
     59     displayName: function()
     60     {
     61         if (typeof this._displayName !== "undefined")
     62             return this._displayName;
     63         if (!this._name) {
     64             this._displayName = WebInspector.UIString("(no domain)");
     65             return this._displayName;
     66         }
     67         var parsedURL = new WebInspector.ParsedURL(this._name);
     68         if (parsedURL.isValid) {
     69             this._displayName = parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "");
     70             if (!this._displayName)
     71                 this._displayName = this._name;
     72         }
     73         else
     74             this._displayName = this._name;
     75         return this._displayName;
     76     },
     77 
     78     /**
     79      * @param {string} parentPath
     80      * @param {string} name
     81      * @param {string} url
     82      * @param {!WebInspector.ContentProvider} contentProvider
     83      * @return {string}
     84      */
     85     addFile: function(parentPath, name, url, contentProvider)
     86     {
     87         return this.addContentProvider(parentPath, name, url, contentProvider);
     88     },
     89 
     90     __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype
     91 }
     92 
     93 /**
     94  * @constructor
     95  * @extends {WebInspector.Object}
     96  * @param {!WebInspector.Workspace} workspace
     97  */
     98 WebInspector.NetworkWorkspaceBinding = function(workspace)
     99 {
    100     this._workspace = workspace;
    101     this._projectDelegates = {};
    102 }
    103 
    104 WebInspector.NetworkWorkspaceBinding.prototype = {
    105     /**
    106      * @param {string} projectName
    107      * @param {boolean} isContentScripts
    108      * @return {!WebInspector.NetworkProjectDelegate}
    109      */
    110     _projectDelegate: function(projectName, isContentScripts)
    111     {
    112         var projectId = (isContentScripts ? "contentscripts:" : "") + projectName;
    113         var projectType = isContentScripts ? WebInspector.projectTypes.ContentScripts : WebInspector.projectTypes.Network;
    114 
    115         if (this._projectDelegates[projectId])
    116             return this._projectDelegates[projectId];
    117         var projectDelegate = new WebInspector.NetworkProjectDelegate(this._workspace, projectId, projectName, projectType);
    118         this._projectDelegates[projectId] = projectDelegate;
    119         return projectDelegate;
    120     },
    121 
    122     /**
    123      * @param {string} url
    124      * @param {!WebInspector.ContentProvider} contentProvider
    125      * @param {boolean=} isContentScript
    126      * @return {!WebInspector.UISourceCode}
    127      */
    128     addFileForURL: function(url, contentProvider, isContentScript)
    129     {
    130         var splitURL = WebInspector.ParsedURL.splitURL(url);
    131         var projectName = splitURL[0];
    132         var parentPath = splitURL.slice(1, splitURL.length - 1).join("/");
    133         var name = splitURL[splitURL.length - 1];
    134         var projectDelegate = this._projectDelegate(projectName, isContentScript || false);
    135         var path = projectDelegate.addFile(parentPath, name, url, contentProvider);
    136         var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (this._workspace.uiSourceCode(projectDelegate.id(), path));
    137         console.assert(uiSourceCode);
    138         return uiSourceCode;
    139     },
    140 
    141     reset: function()
    142     {
    143         for (var projectId in this._projectDelegates)
    144             this._projectDelegates[projectId].reset();
    145         this._projectDelegates = {};
    146     },
    147 
    148     __proto__: WebInspector.Object.prototype
    149 }
    150