2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 * @extends {WebInspector.ContentProviderBasedProjectDelegate}
34 * @param {!WebInspector.Workspace} workspace
35 * @param {string} projectId
36 * @param {string} projectName
37 * @param {!WebInspector.projectTypes} projectType
39 WebInspector.NetworkProjectDelegate = function(workspace, projectId, projectName, projectType)
41 this._name = projectName;
43 WebInspector.ContentProviderBasedProjectDelegate.call(this, workspace, projectId, projectType);
44 this._lastUniqueSuffix = 0;
47 WebInspector.NetworkProjectDelegate.prototype = {
59 displayName: function()
61 if (typeof this._displayName !== "undefined")
62 return this._displayName;
64 this._displayName = WebInspector.UIString("(no domain)");
65 return this._displayName;
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;
74 this._displayName = this._name;
75 return this._displayName;
87 * @param {string} parentPath
88 * @param {string} name
90 * @param {!WebInspector.ContentProvider} contentProvider
93 addFile: function(parentPath, name, url, contentProvider)
95 return this.addContentProvider(parentPath, name, url, url, contentProvider);
98 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype
103 * @extends {WebInspector.Object}
104 * @param {!WebInspector.Workspace} workspace
106 WebInspector.NetworkWorkspaceBinding = function(workspace)
108 this._workspace = workspace;
109 this._projectDelegates = {};
112 WebInspector.NetworkWorkspaceBinding.prototype = {
114 * @param {string} projectName
115 * @param {boolean} isContentScripts
116 * @return {!WebInspector.NetworkProjectDelegate}
118 _projectDelegate: function(projectName, isContentScripts)
120 var projectId = (isContentScripts ? "contentscripts:" : "") + projectName;
121 var projectType = isContentScripts ? WebInspector.projectTypes.ContentScripts : WebInspector.projectTypes.Network;
123 if (this._projectDelegates[projectId])
124 return this._projectDelegates[projectId];
125 var projectDelegate = new WebInspector.NetworkProjectDelegate(this._workspace, projectId, projectName, projectType);
126 this._projectDelegates[projectId] = projectDelegate;
127 return projectDelegate;
131 * @param {string} url
132 * @param {!WebInspector.ContentProvider} contentProvider
133 * @param {boolean=} isContentScript
134 * @return {!WebInspector.UISourceCode}
136 addFileForURL: function(url, contentProvider, isContentScript)
138 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
139 var projectName = splitURL[0];
140 var parentPath = splitURL.slice(1, -1).join("/");
141 var name = splitURL.peekLast() || "";
142 var projectDelegate = this._projectDelegate(projectName, isContentScript || false);
143 var path = projectDelegate.addFile(parentPath, name, url, contentProvider);
144 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (this._workspace.uiSourceCode(projectDelegate.id(), path));
145 console.assert(uiSourceCode);
150 * @param {string} url
152 removeFileForURL: function(url)
154 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
155 var projectName = splitURL[0];
156 var path = splitURL.slice(1).join("/");
157 var projectDelegate = this._projectDelegates[projectName];
158 projectDelegate.removeFile(path);
163 for (var projectId in this._projectDelegates)
164 this._projectDelegates[projectId].reset();
165 this._projectDelegates = {};
168 __proto__: WebInspector.Object.prototype