OLD | NEW |
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 WebInspector.NetworkProject._networkProjectSymbol = Symbol("networkProject"); | 97 WebInspector.NetworkProject._networkProjectSymbol = Symbol("networkProject"); |
98 WebInspector.NetworkProject._resourceSymbol = Symbol("resource"); | 98 WebInspector.NetworkProject._resourceSymbol = Symbol("resource"); |
99 WebInspector.NetworkProject._scriptSymbol = Symbol("script"); | 99 WebInspector.NetworkProject._scriptSymbol = Symbol("script"); |
100 WebInspector.NetworkProject._styleSheetSymbol = Symbol("styleSheet"); | 100 WebInspector.NetworkProject._styleSheetSymbol = Symbol("styleSheet"); |
101 WebInspector.NetworkProject._targetSymbol = Symbol("target"); | 101 WebInspector.NetworkProject._targetSymbol = Symbol("target"); |
102 | 102 |
103 /** | 103 /** |
104 * @param {!WebInspector.Target} target | 104 * @param {!WebInspector.Target} target |
105 * @param {string} projectURL | |
106 * @param {boolean} isContentScripts | 105 * @param {boolean} isContentScripts |
107 * @return {string} | 106 * @return {string} |
108 */ | 107 */ |
109 WebInspector.NetworkProject.projectId = function(target, projectURL, isContentSc
ripts) | 108 WebInspector.NetworkProject.projectId = function(target, isContentScripts) |
110 { | 109 { |
111 return target.id() + ":" + (isContentScripts ? "contentscripts:" : "") + pro
jectURL; | 110 return target.id() + ":" + (isContentScripts ? "contentscripts:" : ""); |
112 } | 111 } |
113 | 112 |
114 /** | 113 /** |
115 * @param {!WebInspector.Target} target | 114 * @param {!WebInspector.Target} target |
116 * @return {!WebInspector.NetworkProject} | 115 * @return {!WebInspector.NetworkProject} |
117 */ | 116 */ |
118 WebInspector.NetworkProject.forTarget = function(target) | 117 WebInspector.NetworkProject.forTarget = function(target) |
119 { | 118 { |
120 return target[WebInspector.NetworkProject._networkProjectSymbol]; | 119 return target[WebInspector.NetworkProject._networkProjectSymbol]; |
121 } | 120 } |
122 | 121 |
123 /** | 122 /** |
| 123 * @param {!WebInspector.Project} project |
| 124 * @return {?WebInspector.Target} target |
| 125 */ |
| 126 WebInspector.NetworkProject.targetForProject = function(project) |
| 127 { |
| 128 return project[WebInspector.NetworkProject._targetSymbol] || null; |
| 129 } |
| 130 |
| 131 /** |
124 * @param {!WebInspector.UISourceCode} uiSourceCode | 132 * @param {!WebInspector.UISourceCode} uiSourceCode |
125 * @return {?WebInspector.Target} target | 133 * @return {?WebInspector.Target} target |
126 */ | 134 */ |
127 WebInspector.NetworkProject.targetForUISourceCode = function(uiSourceCode) | 135 WebInspector.NetworkProject.targetForUISourceCode = function(uiSourceCode) |
128 { | 136 { |
129 return uiSourceCode[WebInspector.NetworkProject._targetSymbol] || null; | 137 return uiSourceCode[WebInspector.NetworkProject._targetSymbol] || null; |
130 } | 138 } |
131 | 139 |
132 /** | 140 /** |
133 * @param {!WebInspector.UISourceCode} uiSourceCode | 141 * @param {!WebInspector.UISourceCode} uiSourceCode |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 var resource = uiSourceCode[WebInspector.NetworkProject._resourceSymbol]
; | 183 var resource = uiSourceCode[WebInspector.NetworkProject._resourceSymbol]
; |
176 if (resource) | 184 if (resource) |
177 frameId = resource.frameId; | 185 frameId = resource.frameId; |
178 } | 186 } |
179 | 187 |
180 return frameId ? target.resourceTreeModel.frameForId(frameId) : null; | 188 return frameId ? target.resourceTreeModel.frameForId(frameId) : null; |
181 } | 189 } |
182 | 190 |
183 WebInspector.NetworkProject.prototype = { | 191 WebInspector.NetworkProject.prototype = { |
184 /** | 192 /** |
185 * @param {string} projectURL | |
186 * @param {boolean} isContentScripts | 193 * @param {boolean} isContentScripts |
187 * @return {!WebInspector.ContentProviderBasedProject} | 194 * @return {!WebInspector.ContentProviderBasedProject} |
188 */ | 195 */ |
189 _workspaceProject: function(projectURL, isContentScripts) | 196 _workspaceProject: function(isContentScripts) |
190 { | 197 { |
191 var projectId = WebInspector.NetworkProject.projectId(this.target(), pro
jectURL, isContentScripts); | 198 var projectId = WebInspector.NetworkProject.projectId(this.target(), isC
ontentScripts); |
192 var projectType = isContentScripts ? WebInspector.projectTypes.ContentSc
ripts : WebInspector.projectTypes.Network; | 199 var projectType = isContentScripts ? WebInspector.projectTypes.ContentSc
ripts : WebInspector.projectTypes.Network; |
193 | 200 |
194 var project = this._workspaceProjects.get(projectId); | 201 var project = this._workspaceProjects.get(projectId); |
195 if (project) | 202 if (project) |
196 return project; | 203 return project; |
197 | 204 |
198 project = new WebInspector.ContentProviderBasedProject(this._workspace,
projectId, projectType, projectURL, this._computeDisplayName(projectURL)); | 205 project = new WebInspector.ContentProviderBasedProject(this._workspace,
projectId, projectType, ""); |
| 206 project[WebInspector.NetworkProject._targetSymbol] = this.target(); |
199 this._workspaceProjects.set(projectId, project); | 207 this._workspaceProjects.set(projectId, project); |
200 return project; | 208 return project; |
201 }, | 209 }, |
202 | 210 |
203 /** | 211 /** |
204 * @param {string} url | 212 * @param {string} url |
205 * @return {string} | |
206 */ | |
207 _computeDisplayName: function(url) | |
208 { | |
209 for (var context of this.target().runtimeModel.executionContexts()) { | |
210 if (context.name && context.origin && url.startsWith(context.origin)
) | |
211 return context.name; | |
212 } | |
213 | |
214 var targetSuffix = this.target().isPage() ? "" : " \u2014 " + this.targe
t().name(); | |
215 if (!url) | |
216 return WebInspector.UIString("(no domain)") + targetSuffix; | |
217 var parsedURL = new WebInspector.ParsedURL(url); | |
218 var prettyURL = parsedURL.isValid ? parsedURL.host + (parsedURL.port ? (
":" + parsedURL.port) : "") : ""; | |
219 return (prettyURL || url) + targetSuffix; | |
220 }, | |
221 | |
222 /** | |
223 * @param {string} url | |
224 * @param {!WebInspector.ContentProvider} contentProvider | 213 * @param {!WebInspector.ContentProvider} contentProvider |
225 * @param {boolean=} isContentScript | 214 * @param {boolean=} isContentScript |
226 * @return {?WebInspector.UISourceCode} | 215 * @return {?WebInspector.UISourceCode} |
227 */ | 216 */ |
228 addFileForURL: function(url, contentProvider, isContentScript) | 217 addFileForURL: function(url, contentProvider, isContentScript) |
229 { | 218 { |
230 return this._createFile(url, contentProvider, isContentScript || false,
true); | 219 return this._createFile(url, contentProvider, isContentScript || false,
true); |
231 }, | 220 }, |
232 | 221 |
233 /** | 222 /** |
234 * @param {string} url | 223 * @param {string} url |
235 */ | 224 */ |
236 _removeFileForURL: function(url) | 225 _removeFileForURL: function(url) |
237 { | 226 { |
238 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url); | 227 var project = this._workspaceProjects.get(WebInspector.NetworkProject.pr
ojectId(this.target(), false)); |
239 var projectURL = splitURL[0]; | |
240 var path = splitURL.slice(1).join("/"); | |
241 var project = this._workspaceProjects.get(WebInspector.NetworkProject.pr
ojectId(this.target(), projectURL, false)); | |
242 if (!project) | 228 if (!project) |
243 return; | 229 return; |
244 project.removeFile(path); | 230 project.removeFile(url); |
245 }, | 231 }, |
246 | 232 |
247 _populate: function() | 233 _populate: function() |
248 { | 234 { |
249 /** | 235 /** |
250 * @param {!WebInspector.ResourceTreeFrame} frame | 236 * @param {!WebInspector.ResourceTreeFrame} frame |
251 * @this {WebInspector.NetworkProject} | 237 * @this {WebInspector.NetworkProject} |
252 */ | 238 */ |
253 function populateFrame(frame) | 239 function populateFrame(frame) |
254 { | 240 { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 * @param {!WebInspector.ContentProvider} contentProvider | 372 * @param {!WebInspector.ContentProvider} contentProvider |
387 * @param {boolean} isContentScript | 373 * @param {boolean} isContentScript |
388 * @param {boolean} addIntoProject | 374 * @param {boolean} addIntoProject |
389 * @return {?WebInspector.UISourceCode} | 375 * @return {?WebInspector.UISourceCode} |
390 */ | 376 */ |
391 _createFile: function(url, contentProvider, isContentScript, addIntoProject) | 377 _createFile: function(url, contentProvider, isContentScript, addIntoProject) |
392 { | 378 { |
393 if (this._networkMapping.hasMappingForURL(url)) | 379 if (this._networkMapping.hasMappingForURL(url)) |
394 return null; | 380 return null; |
395 | 381 |
396 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url); | 382 var project = this._workspaceProject(isContentScript); |
397 var projectURL = splitURL[0]; | 383 var uiSourceCode = project.createUISourceCode(url, contentProvider.conte
ntType()); |
398 var parentPath = splitURL.slice(1, -1).join("/"); | |
399 var name = splitURL.peekLast() || ""; | |
400 var project = this._workspaceProject(projectURL, isContentScript); | |
401 var uiSourceCode = project.createUISourceCode(parentPath, name, url, con
tentProvider.contentType()); | |
402 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target(); | 384 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target(); |
403 if (addIntoProject) | 385 if (addIntoProject) |
404 project.addUISourceCodeWithProvider(uiSourceCode, contentProvider); | 386 project.addUISourceCodeWithProvider(uiSourceCode, contentProvider); |
405 return uiSourceCode; | 387 return uiSourceCode; |
406 }, | 388 }, |
407 | 389 |
408 _dispose: function() | 390 _dispose: function() |
409 { | 391 { |
410 this._reset(); | 392 this._reset(); |
411 var target = this.target(); | 393 var target = this.target(); |
(...skipping 14 matching lines...) Expand all Loading... |
426 | 408 |
427 _reset: function() | 409 _reset: function() |
428 { | 410 { |
429 for (var project of this._workspaceProjects.values()) | 411 for (var project of this._workspaceProjects.values()) |
430 project.reset(); | 412 project.reset(); |
431 this._workspaceProjects.clear(); | 413 this._workspaceProjects.clear(); |
432 }, | 414 }, |
433 | 415 |
434 __proto__: WebInspector.SDKObject.prototype | 416 __proto__: WebInspector.SDKObject.prototype |
435 } | 417 } |
OLD | NEW |