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

« back to all changes in this revision

Viewing changes to Source/WebCore/inspector/front-end/Workspace.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
 */
 
34
WebInspector.WorkspaceController = function(workspace)
 
35
{
 
36
    this._workspace = workspace;
 
37
    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
 
38
    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
 
39
}
 
40
 
 
41
WebInspector.WorkspaceController.prototype = {
 
42
    _mainFrameNavigated: function()
 
43
    {
 
44
        WebInspector.Revision.filterOutStaleRevisions();
 
45
        this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectWillReset, this._workspace.project());
 
46
        this._workspace.project().reset();
 
47
        this._workspace.reset();
 
48
        this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectDidReset, this._workspace.project());
 
49
    },
 
50
 
 
51
    _frameAdded: function(event)
 
52
    {
 
53
        var frame = /** @type {WebInspector.ResourceTreeFrame} */ (event.data);
 
54
        if (frame.isMainFrame())
 
55
            WebInspector.Revision.filterOutStaleRevisions();
 
56
    }
 
57
}
 
58
 
 
59
/**
 
60
 * @constructor
 
61
 * @param {string} path
 
62
 * @param {WebInspector.ResourceType} contentType
 
63
 * @param {boolean} isEditable
 
64
 * @param {boolean=} isContentScript
 
65
 * @param {boolean=} isSnippet
 
66
 */
 
67
WebInspector.FileDescriptor = function(path, contentType, isEditable, isContentScript, isSnippet)
 
68
{
 
69
    this.path = path;
 
70
    this.contentType = contentType;
 
71
    this.isEditable = isEditable;
 
72
    this.isContentScript = isContentScript || false;
 
73
    this.isSnippet = isSnippet || false;
 
74
}
 
75
 
 
76
/**
 
77
 * @interface
 
78
 */
 
79
WebInspector.WorkspaceProvider = function() { }
 
80
 
 
81
WebInspector.WorkspaceProvider.Events = {
 
82
    FileAdded: "FileAdded",
 
83
    FileRemoved: "FileRemoved"
 
84
}
 
85
 
 
86
WebInspector.WorkspaceProvider.prototype = {
 
87
    /**
 
88
     * @param {string} path
 
89
     * @param {function(?string,boolean,string)} callback
 
90
     */
 
91
    requestFileContent: function(path, callback) { },
 
92
 
 
93
    /**
 
94
     * @param {string} query
 
95
     * @param {boolean} caseSensitive
 
96
     * @param {boolean} isRegex
 
97
     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
 
98
     */
 
99
    searchInFileContent: function(path, query, caseSensitive, isRegex, callback) { },
 
100
 
 
101
    /**
 
102
     * @param {string} eventType
 
103
     * @param {function(WebInspector.Event)} listener
 
104
     * @param {Object=} thisObject
 
105
     */
 
106
    addEventListener: function(eventType, listener, thisObject) { },
 
107
 
 
108
    /**
 
109
     * @param {string} eventType
 
110
     * @param {function(WebInspector.Event)} listener
 
111
     * @param {Object=} thisObject
 
112
     */
 
113
    removeEventListener: function(eventType, listener, thisObject) { }
 
114
}
 
115
 
 
116
/**
 
117
 * @type {?WebInspector.WorkspaceController}
 
118
 */
 
119
WebInspector.workspaceController = null;
 
120
 
 
121
/**
 
122
 * @param {WebInspector.Workspace} workspace
 
123
 * @param {WebInspector.WorkspaceProvider} workspaceProvider
 
124
 * @constructor
 
125
 */
 
126
WebInspector.Project = function(workspace, workspaceProvider)
 
127
{
 
128
    this._uiSourceCodes = [];
 
129
    this._workspace = workspace;
 
130
    this._workspaceProvider = workspaceProvider;
 
131
    this._workspaceProvider.addEventListener(WebInspector.WorkspaceProvider.Events.FileAdded, this._fileAdded, this);
 
132
    this._workspaceProvider.addEventListener(WebInspector.WorkspaceProvider.Events.FileRemoved, this._fileRemoved, this);
 
133
}
 
134
 
 
135
WebInspector.Project.prototype = {
 
136
    reset: function()
 
137
    {
 
138
        this._workspaceProvider.reset();
 
139
        this._uiSourceCodes = [];
 
140
    },
 
141
 
 
142
    _fileAdded: function(event)
 
143
    {
 
144
        var fileDescriptor = /** @type {WebInspector.FileDescriptor} */ (event.data);
 
145
        var uiSourceCode = this.uiSourceCodeForURL(fileDescriptor.path);
 
146
        if (uiSourceCode) {
 
147
            // FIXME: Implement
 
148
            return;
 
149
        }
 
150
        uiSourceCode = new WebInspector.UISourceCode(this._workspace, fileDescriptor.path, fileDescriptor.contentType, fileDescriptor.isEditable);
 
151
        uiSourceCode.isContentScript = fileDescriptor.isContentScript;
 
152
        uiSourceCode.isSnippet = fileDescriptor.isSnippet;
 
153
        this._uiSourceCodes.push(uiSourceCode);
 
154
        this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode);
 
155
    },
 
156
 
 
157
    _fileRemoved: function(event)
 
158
    {
 
159
        var path = /** @type {string} */ (event.data);
 
160
        var uiSourceCode = this.uiSourceCodeForURL(path);
 
161
        if (!uiSourceCode)
 
162
            return;
 
163
        this._uiSourceCodes.splice(this._uiSourceCodes.indexOf(uiSourceCode), 1);
 
164
        this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, uiSourceCode);
 
165
    },
 
166
 
 
167
    /**
 
168
     * @param {string} url
 
169
     * @return {?WebInspector.UISourceCode}
 
170
     */
 
171
    uiSourceCodeForURL: function(url)
 
172
    {
 
173
        for (var i = 0; i < this._uiSourceCodes.length; ++i) {
 
174
            if (this._uiSourceCodes[i].url === url)
 
175
                return this._uiSourceCodes[i];
 
176
        }
 
177
        return null;
 
178
    },
 
179
 
 
180
    /**
 
181
     * @return {Array.<WebInspector.UISourceCode>}
 
182
     */
 
183
    uiSourceCodes: function()
 
184
    {
 
185
        return this._uiSourceCodes;
 
186
    },
 
187
 
 
188
    /**
 
189
     * @param {string} path
 
190
     * @param {function(?string,boolean,string)} callback
 
191
     */
 
192
    requestFileContent: function(path, callback)
 
193
    {
 
194
        this._workspaceProvider.requestFileContent(path, callback);
 
195
    },
 
196
 
 
197
    /**
 
198
     * @param {string} query
 
199
     * @param {boolean} caseSensitive
 
200
     * @param {boolean} isRegex
 
201
     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
 
202
     */
 
203
    searchInFileContent: function(path, query, caseSensitive, isRegex, callback)
 
204
    {
 
205
        this._workspaceProvider.searchInFileContent(path, query, caseSensitive, isRegex, callback);
 
206
    }
 
207
}
 
208
 
 
209
/**
 
210
 * @constructor
 
211
 * @implements {WebInspector.UISourceCodeProvider}
 
212
 * @extends {WebInspector.Object}
 
213
 */
 
214
WebInspector.Workspace = function()
 
215
{
 
216
    /** @type {Object.<string, WebInspector.ContentProvider>} */
 
217
    this._temporaryContentProviders = new Map();
 
218
}
 
219
 
 
220
WebInspector.Workspace.Events = {
 
221
    UISourceCodeContentCommitted: "UISourceCodeContentCommitted",
 
222
    ProjectWillReset: "ProjectWillReset",
 
223
    ProjectDidReset: "ProjectDidReset"
 
224
}
 
225
 
 
226
WebInspector.Workspace.prototype = {
 
227
    /**
 
228
     * @param {string} url
 
229
     * @return {?WebInspector.UISourceCode}
 
230
     */
 
231
    uiSourceCodeForURL: function(url)
 
232
    {
 
233
        return this._project.uiSourceCodeForURL(url);
 
234
    },
 
235
 
 
236
    /**
 
237
     * @param {string} projectName
 
238
     * @param {WebInspector.WorkspaceProvider} workspaceProvider
 
239
     */
 
240
    addProject: function(projectName, workspaceProvider)
 
241
    {
 
242
        // FIXME: support multiple projects identified by project name.
 
243
        this._project = new WebInspector.Project(this, workspaceProvider);
 
244
    },
 
245
 
 
246
    /**
 
247
     * @return {WebInspector.Project}
 
248
     */
 
249
    project: function()
 
250
    {
 
251
        return this._project;
 
252
    },
 
253
 
 
254
    /**
 
255
     * @return {Array.<WebInspector.UISourceCode>}
 
256
     */
 
257
    uiSourceCodes: function()
 
258
    {
 
259
        return this._project.uiSourceCodes();
 
260
    },
 
261
 
 
262
    /**
 
263
     * @param {string} path
 
264
     * @param {WebInspector.ContentProvider} contentProvider
 
265
     * @param {boolean} isEditable
 
266
     * @param {boolean=} isContentScript
 
267
     * @param {boolean=} isSnippet
 
268
     */
 
269
    addTemporaryUISourceCode: function(path, contentProvider, isEditable, isContentScript, isSnippet)
 
270
    {
 
271
        var uiSourceCode = new WebInspector.UISourceCode(this, path, contentProvider.contentType(), isEditable);
 
272
        this._temporaryContentProviders.put(uiSourceCode, contentProvider);
 
273
        uiSourceCode.isContentScript = isContentScript;
 
274
        uiSourceCode.isSnippet = isSnippet;
 
275
        uiSourceCode.isTemporary = true;
 
276
        this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeAdded, uiSourceCode);
 
277
        return uiSourceCode;
 
278
    },
 
279
 
 
280
    /**
 
281
     * @param {WebInspector.UISourceCode} uiSourceCode
 
282
     */
 
283
    removeTemporaryUISourceCode: function(uiSourceCode)
 
284
    {
 
285
        this._temporaryContentProviders.remove(uiSourceCode.url);
 
286
        this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, uiSourceCode);
 
287
    },
 
288
 
 
289
    /**
 
290
     * @param {WebInspector.UISourceCode} uiSourceCode
 
291
     * @param {function(?string,boolean,string)} callback
 
292
     */
 
293
    requestFileContent: function(uiSourceCode, callback)
 
294
    {
 
295
        if (this._temporaryContentProviders.get(uiSourceCode)) {
 
296
            this._temporaryContentProviders.get(uiSourceCode).requestContent(callback);
 
297
            return;
 
298
        }
 
299
        this._project.requestFileContent(uiSourceCode.url, callback);
 
300
    },
 
301
 
 
302
    /**
 
303
     * @param {WebInspector.UISourceCode} uiSourceCode
 
304
     * @param {string} query
 
305
     * @param {boolean} caseSensitive
 
306
     * @param {boolean} isRegex
 
307
     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
 
308
     */
 
309
    searchInFileContent: function(uiSourceCode, query, caseSensitive, isRegex, callback)
 
310
    {
 
311
        if (this._temporaryContentProviders.get(uiSourceCode)) {
 
312
            this._temporaryContentProviders.get(uiSourceCode).searchInContent(query, caseSensitive, isRegex, callback);
 
313
            return;
 
314
        }
 
315
        this._project.searchInFileContent(uiSourceCode.url, query, caseSensitive, isRegex, callback);
 
316
    },
 
317
 
 
318
    reset: function()
 
319
    {
 
320
        this._temporaryContentProviders = new Map();
 
321
    },
 
322
 
 
323
    __proto__: WebInspector.Object.prototype
 
324
}
 
325
 
 
326
/**
 
327
 * @type {?WebInspector.Workspace}
 
328
 */
 
329
WebInspector.workspace = null;