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.Target} target
35 * @param {!WebInspector.Workspace} workspace
36 * @param {string} projectId
37 * @param {string} projectURL
38 * @param {!WebInspector.projectTypes} projectType
40 WebInspector
.NetworkProjectDelegate = function(target
, workspace
, projectId
, projectURL
, projectType
)
42 this._url
= projectURL
;
43 this._target
= target
;
45 WebInspector
.ContentProviderBasedProjectDelegate
.call(this, workspace
, projectId
, projectType
);
48 WebInspector
.NetworkProjectDelegate
.prototype = {
50 * @return {!WebInspector.Target}
69 displayName: function()
71 if (typeof this._displayName
!== "undefined")
72 return this._displayName
;
74 var targetSuffix
= this._target
.isPage() ? "" : " \u2014 " + this._target
.name();
76 this._displayName
= WebInspector
.UIString("(no domain)") + targetSuffix
;
77 return this._displayName
;
79 var parsedURL
= new WebInspector
.ParsedURL(this._url
);
80 var prettyURL
= parsedURL
.isValid
? parsedURL
.host
+ (parsedURL
.port
? (":" + parsedURL
.port
) : "") : "";
81 this._displayName
= (prettyURL
|| this._url
) + targetSuffix
;
82 return this._displayName
;
95 * @param {string} parentPath
96 * @param {string} name
98 * @param {!WebInspector.ContentProvider} contentProvider
101 addFile: function(parentPath
, name
, url
, contentProvider
)
103 return this.addContentProvider(parentPath
, name
, url
, url
, contentProvider
);
106 __proto__
: WebInspector
.ContentProviderBasedProjectDelegate
.prototype
111 * @param {!WebInspector.TargetManager} targetManager
112 * @param {!WebInspector.Workspace} workspace
113 * @param {!WebInspector.NetworkMapping} networkMapping
114 * @implements {WebInspector.TargetManager.Observer}
116 WebInspector
.NetworkProjectManager = function(targetManager
, workspace
, networkMapping
)
118 this._workspace
= workspace
;
119 this._networkMapping
= networkMapping
;
120 targetManager
.observeTargets(this);
123 WebInspector
.NetworkProjectManager
.prototype = {
126 * @param {!WebInspector.Target} target
128 targetAdded: function(target
)
130 new WebInspector
.NetworkProject(target
, this._workspace
, this._networkMapping
);
135 * @param {!WebInspector.Target} target
137 targetRemoved: function(target
)
139 WebInspector
.NetworkProject
.forTarget(target
)._dispose();
145 * @extends {WebInspector.SDKObject}
146 * @param {!WebInspector.Target} target
147 * @param {!WebInspector.Workspace} workspace
148 * @param {!WebInspector.NetworkMapping} networkMapping
150 WebInspector
.NetworkProject = function(target
, workspace
, networkMapping
)
152 WebInspector
.SDKObject
.call(this, target
);
153 this._workspace
= workspace
;
154 this._networkMapping
= networkMapping
;
155 this._projectDelegates
= {};
156 this._processedURLs
= {};
157 target
[WebInspector
.NetworkProject
._networkProjectSymbol
] = this;
159 target
.resourceTreeModel
.addEventListener(WebInspector
.ResourceTreeModel
.EventTypes
.ResourceAdded
, this._resourceAdded
, this);
160 target
.resourceTreeModel
.addEventListener(WebInspector
.ResourceTreeModel
.EventTypes
.MainFrameNavigated
, this._mainFrameNavigated
, this);
162 var debuggerModel
= WebInspector
.DebuggerModel
.fromTarget(target
);
164 debuggerModel
.addEventListener(WebInspector
.DebuggerModel
.Events
.ParsedScriptSource
, this._parsedScriptSource
, this);
165 debuggerModel
.addEventListener(WebInspector
.DebuggerModel
.Events
.FailedToParseScriptSource
, this._parsedScriptSource
, this);
167 var cssModel
= WebInspector
.CSSStyleModel
.fromTarget(target
);
169 cssModel
.addEventListener(WebInspector
.CSSStyleModel
.Events
.StyleSheetAdded
, this._styleSheetAdded
, this);
170 cssModel
.addEventListener(WebInspector
.CSSStyleModel
.Events
.StyleSheetRemoved
, this._styleSheetRemoved
, this);
174 WebInspector
.NetworkProject
._networkProjectSymbol
= Symbol("networkProject");
175 WebInspector
.NetworkProject
._contentTypeSymbol
= Symbol("networkContentType");
178 * @param {!WebInspector.Target} target
179 * @param {string} projectURL
180 * @param {boolean} isContentScripts
183 WebInspector
.NetworkProject
.projectId = function(target
, projectURL
, isContentScripts
)
185 return target
.id() + ":" + (isContentScripts
? "contentscripts:" : "") + projectURL
;
189 * @param {!WebInspector.Project} project
190 * @return {?WebInspector.Target}
192 WebInspector
.NetworkProject
._targetForProject = function(project
)
194 var targetId
= parseInt(project
.id(), 10);
195 return WebInspector
.targetManager
.targetById(targetId
);
199 * @param {!WebInspector.Target} target
200 * @return {!WebInspector.NetworkProject}
202 WebInspector
.NetworkProject
.forTarget = function(target
)
204 return target
[WebInspector
.NetworkProject
._networkProjectSymbol
];
208 * @param {!WebInspector.UISourceCode} uiSourceCode
209 * @return {?WebInspector.Target} target
211 WebInspector
.NetworkProject
.targetForUISourceCode = function(uiSourceCode
)
213 if (uiSourceCode
.project().type() !== WebInspector
.projectTypes
.ContentScripts
&& uiSourceCode
.project().type() !== WebInspector
.projectTypes
.Network
)
216 return WebInspector
.NetworkProject
._targetForProject(uiSourceCode
.project());
220 * @param {!WebInspector.UISourceCode} uiSourceCode
221 * @return {(!WebInspector.ResourceType|undefined)}
223 WebInspector
.NetworkProject
.uiSourceCodeContentType = function(uiSourceCode
)
225 return uiSourceCode
[WebInspector
.NetworkProject
._contentTypeSymbol
];
228 WebInspector
.NetworkProject
.prototype = {
230 * @param {string} projectURL
231 * @param {boolean} isContentScripts
232 * @return {!WebInspector.NetworkProjectDelegate}
234 _projectDelegate: function(projectURL
, isContentScripts
)
236 var projectId
= WebInspector
.NetworkProject
.projectId(this.target(), projectURL
, isContentScripts
);
237 var projectType
= isContentScripts
? WebInspector
.projectTypes
.ContentScripts
: WebInspector
.projectTypes
.Network
;
239 if (this._projectDelegates
[projectId
])
240 return this._projectDelegates
[projectId
];
241 var projectDelegate
= new WebInspector
.NetworkProjectDelegate(this.target(), this._workspace
, projectId
, projectURL
, projectType
);
242 this._projectDelegates
[projectId
] = projectDelegate
;
243 return projectDelegate
;
247 * @param {string} url
248 * @param {!WebInspector.ContentProvider} contentProvider
249 * @param {boolean=} isContentScript
250 * @return {!WebInspector.UISourceCode}
252 addFileForURL: function(url
, contentProvider
, isContentScript
)
254 var splitURL
= WebInspector
.ParsedURL
.splitURLIntoPathComponents(url
);
255 var projectURL
= splitURL
[0];
256 var parentPath
= splitURL
.slice(1, -1).join("/");
257 var name
= splitURL
.peekLast() || "";
258 var projectDelegate
= this._projectDelegate(projectURL
, isContentScript
|| false);
259 var path
= projectDelegate
.addFile(parentPath
, name
, url
, contentProvider
);
260 var uiSourceCode
= /** @type {!WebInspector.UISourceCode} */ (this._workspace
.uiSourceCode(projectDelegate
.id(), path
));
261 console
.assert(uiSourceCode
);
266 * @param {string} url
268 _removeFileForURL: function(url
)
270 var splitURL
= WebInspector
.ParsedURL
.splitURLIntoPathComponents(url
);
271 var projectURL
= splitURL
[0];
272 var path
= splitURL
.slice(1).join("/");
273 var projectDelegate
= this._projectDelegates
[WebInspector
.NetworkProject
.projectId(this.target(), projectURL
, false)];
274 projectDelegate
.removeFile(path
);
277 _populate: function()
280 * @param {!WebInspector.ResourceTreeFrame} frame
281 * @this {WebInspector.NetworkProject}
283 function populateFrame(frame
)
285 for (var i
= 0; i
< frame
.childFrames
.length
; ++i
)
286 populateFrame
.call(this, frame
.childFrames
[i
]);
288 var resources
= frame
.resources();
289 for (var i
= 0; i
< resources
.length
; ++i
)
290 this._addResource(resources
[i
]);
293 var mainFrame
= this.target().resourceTreeModel
.mainFrame
;
295 populateFrame
.call(this, mainFrame
);
299 * @param {!WebInspector.Event} event
301 _parsedScriptSource: function(event
)
303 var script
= /** @type {!WebInspector.Script} */ (event
.data
);
304 if (!script
.sourceURL
|| (script
.isInlineScript() && !script
.hasSourceURL
))
306 // Filter out embedder injected content scripts.
307 if (script
.isContentScript() && !script
.hasSourceURL
) {
308 var parsedURL
= new WebInspector
.ParsedURL(script
.sourceURL
);
309 if (!parsedURL
.isValid
)
312 this._addFile(script
.sourceURL
, script
, script
.isContentScript());
316 * @param {!WebInspector.Event} event
318 _styleSheetAdded: function(event
)
320 var header
= /** @type {!WebInspector.CSSStyleSheetHeader} */ (event
.data
);
321 if (header
.isInline
&& !header
.hasSourceURL
&& header
.origin
!== "inspector")
324 this._addFile(header
.resourceURL(), header
, false);
328 * @param {!WebInspector.Event} event
330 _styleSheetRemoved: function(event
)
332 var header
= /** @type {!WebInspector.CSSStyleSheetHeader} */ (event
.data
);
333 if (header
.isInline
&& !header
.hasSourceURL
&& header
.origin
!== "inspector")
336 this._removeFile(header
.resourceURL());
340 * @param {!WebInspector.Event} event
342 _resourceAdded: function(event
)
344 var resource
= /** @type {!WebInspector.Resource} */ (event
.data
);
345 this._addResource(resource
);
349 * @param {!WebInspector.Resource} resource
351 _addResource: function(resource
)
353 if (resource
.resourceType() === WebInspector
.resourceTypes
.Document
)
354 this._addFile(resource
.url
, resource
);
358 * @param {!WebInspector.Event} event
360 _mainFrameNavigated: function(event
)
367 * @param {string} url
368 * @param {!WebInspector.ContentProvider} contentProvider
369 * @param {boolean=} isContentScript
371 _addFile: function(url
, contentProvider
, isContentScript
)
373 if (this._networkMapping
.hasMappingForURL(url
))
376 var type
= contentProvider
.contentType();
377 if (type
!== WebInspector
.resourceTypes
.Stylesheet
&& type
!== WebInspector
.resourceTypes
.Document
&& type
!== WebInspector
.resourceTypes
.Script
)
379 if (this._processedURLs
[url
])
381 this._processedURLs
[url
] = true;
382 var uiSourceCode
= this.addFileForURL(url
, contentProvider
, isContentScript
);
383 uiSourceCode
[WebInspector
.NetworkProject
._contentTypeSymbol
] = type
;
387 * @param {string} url
389 _removeFile: function(url
)
391 if (!this._processedURLs
[url
])
393 delete this._processedURLs
[url
];
394 this._removeFileForURL(url
);
400 var target
= this.target();
401 target
.resourceTreeModel
.removeEventListener(WebInspector
.ResourceTreeModel
.EventTypes
.ResourceAdded
, this._resourceAdded
, this);
402 target
.resourceTreeModel
.removeEventListener(WebInspector
.ResourceTreeModel
.EventTypes
.MainFrameNavigated
, this._mainFrameNavigated
, this);
403 var debuggerModel
= WebInspector
.DebuggerModel
.fromTarget(target
);
405 debuggerModel
.removeEventListener(WebInspector
.DebuggerModel
.Events
.ParsedScriptSource
, this._parsedScriptSource
, this);
406 debuggerModel
.removeEventListener(WebInspector
.DebuggerModel
.Events
.FailedToParseScriptSource
, this._parsedScriptSource
, this);
408 var cssModel
= WebInspector
.CSSStyleModel
.fromTarget(target
);
410 cssModel
.removeEventListener(WebInspector
.CSSStyleModel
.Events
.StyleSheetAdded
, this._styleSheetAdded
, this);
411 cssModel
.removeEventListener(WebInspector
.CSSStyleModel
.Events
.StyleSheetRemoved
, this._styleSheetRemoved
, this);
413 delete target
[WebInspector
.NetworkProject
._networkProjectSymbol
];
418 this._processedURLs
= {};
419 for (var projectId
in this._projectDelegates
)
420 this._projectDelegates
[projectId
].reset();
421 this._projectDelegates
= {};
424 __proto__
: WebInspector
.SDKObject
.prototype