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
* @param {WebInspector.Workspace} workspace
34
* @param {WebInspector.NetworkWorkspaceProvider} networkWorkspaceProvider
36
WebInspector.NetworkUISourceCodeProvider = function(workspace, networkWorkspaceProvider)
38
this._workspace = workspace;
39
this._networkWorkspaceProvider = networkWorkspaceProvider;
40
WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
41
this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset, this);
42
this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectDidReset, this._projectDidReset, this);
43
WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
45
this._processedURLs = {};
46
this._lastDynamicAnonymousScriptIndexForURL = {};
49
WebInspector.NetworkUISourceCodeProvider.prototype = {
52
function populateFrame(frame)
54
for (var i = 0; i < frame.childFrames.length; ++i)
55
populateFrame.call(this, frame.childFrames[i]);
57
var resources = frame.resources();
58
for (var i = 0; i < resources.length; ++i)
59
this._resourceAdded({data:resources[i]});
62
populateFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
66
* @param {WebInspector.Event} event
68
_parsedScriptSource: function(event)
70
var script = /** @type {WebInspector.Script} */ (event.data);
71
if (!script.sourceURL || script.isInlineScript())
73
if (WebInspector.experimentsSettings.snippetsSupport.isEnabled() && script.isSnippet())
75
var isDynamicAnonymousScript;
76
// Only add uiSourceCodes for
78
// - scripts with explicit sourceURL comment;
79
// - dynamic scripts (script elements with src attribute) when inspector is opened after the script was loaded.
80
if (!script.hasSourceURL && !script.isContentScript) {
81
if (WebInspector.resourceForURL(script.sourceURL) || WebInspector.networkLog.requestForURL(script.sourceURL))
84
// Filter out embedder injected content scripts.
85
if (script.isContentScript && !script.hasSourceURL) {
86
var parsedURL = new WebInspector.ParsedURL(script.sourceURL);
90
this._addFile(script.sourceURL, script, script.isContentScript);
94
* @param {WebInspector.Event} event
96
_resourceAdded: function(event)
98
var resource = /** @type {WebInspector.Resource} */ (event.data);
99
this._addFile(resource.url, resource);
103
* @param {string} url
104
* @param {WebInspector.ContentProvider} contentProvider
105
* @param {boolean=} isContentScript
107
_addFile: function(url, contentProvider, isContentScript)
109
var type = contentProvider.contentType();
110
if (type !== WebInspector.resourceTypes.Stylesheet && type !== WebInspector.resourceTypes.Document && type !== WebInspector.resourceTypes.Script)
112
if (this._processedURLs[url])
114
this._processedURLs[url] = true;
115
var isEditable = type !== WebInspector.resourceTypes.Document;
116
this._networkWorkspaceProvider.addFile(url, contentProvider, isEditable, isContentScript);
119
_projectWillReset: function()
121
this._processedURLs = {};
122
this._lastDynamicAnonymousScriptIndexForURL = {};
125
_projectDidReset: function()