~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/inspector/front-end/NetworkUISourceCodeProvider.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * @param {WebInspector.Workspace} workspace
 
34
 * @param {WebInspector.NetworkWorkspaceProvider} networkWorkspaceProvider
 
35
 */
 
36
WebInspector.NetworkUISourceCodeProvider = function(workspace, networkWorkspaceProvider)
 
37
{
 
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);
 
44
 
 
45
    this._processedURLs = {};
 
46
    this._lastDynamicAnonymousScriptIndexForURL = {};
 
47
}
 
48
 
 
49
WebInspector.NetworkUISourceCodeProvider.prototype = {
 
50
    _populate: function()
 
51
    {
 
52
        function populateFrame(frame)
 
53
        {
 
54
            for (var i = 0; i < frame.childFrames.length; ++i)
 
55
                populateFrame.call(this, frame.childFrames[i]);
 
56
 
 
57
            var resources = frame.resources();
 
58
            for (var i = 0; i < resources.length; ++i)
 
59
                this._resourceAdded({data:resources[i]});
 
60
        }
 
61
 
 
62
        populateFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
 
63
    },
 
64
 
 
65
    /**
 
66
     * @param {WebInspector.Event} event
 
67
     */
 
68
    _parsedScriptSource: function(event)
 
69
    {
 
70
        var script = /** @type {WebInspector.Script} */ (event.data);
 
71
        if (!script.sourceURL || script.isInlineScript())
 
72
            return;
 
73
        if (WebInspector.experimentsSettings.snippetsSupport.isEnabled() && script.isSnippet())
 
74
            return;
 
75
        var isDynamicAnonymousScript;
 
76
        // Only add uiSourceCodes for
 
77
        // - content scripts;
 
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))
 
82
                return;
 
83
        }
 
84
        // Filter out embedder injected content scripts.
 
85
        if (script.isContentScript && !script.hasSourceURL) {
 
86
            var parsedURL = new WebInspector.ParsedURL(script.sourceURL);
 
87
            if (!parsedURL.host)
 
88
                return;
 
89
        }
 
90
        this._addFile(script.sourceURL, script, script.isContentScript);
 
91
    },
 
92
 
 
93
    /**
 
94
     * @param {WebInspector.Event} event
 
95
     */
 
96
    _resourceAdded: function(event)
 
97
    {
 
98
        var resource = /** @type {WebInspector.Resource} */ (event.data);
 
99
        this._addFile(resource.url, resource);
 
100
    },
 
101
 
 
102
    /**
 
103
     * @param {string} url
 
104
     * @param {WebInspector.ContentProvider} contentProvider
 
105
     * @param {boolean=} isContentScript
 
106
     */
 
107
    _addFile: function(url, contentProvider, isContentScript)
 
108
    {
 
109
        var type = contentProvider.contentType();
 
110
        if (type !== WebInspector.resourceTypes.Stylesheet && type !== WebInspector.resourceTypes.Document && type !== WebInspector.resourceTypes.Script)
 
111
            return;
 
112
        if (this._processedURLs[url])
 
113
            return;
 
114
        this._processedURLs[url] = true;
 
115
        var isEditable = type !== WebInspector.resourceTypes.Document;
 
116
        this._networkWorkspaceProvider.addFile(url, contentProvider, isEditable, isContentScript);
 
117
    },
 
118
 
 
119
    _projectWillReset: function()
 
120
    {
 
121
        this._processedURLs = {};
 
122
        this._lastDynamicAnonymousScriptIndexForURL = {};
 
123
    },
 
124
 
 
125
    _projectDidReset: function()
 
126
    {
 
127
        this._populate();
 
128
    }
 
129
}