~jconti/ubuntu/oneiric/webkit/fix_doc_path

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2011-04-07 09:14:12 UTC
  • mfrom: (1.1.22 upstream)
  • Revision ID: james.westby@ubuntu.com-20110407091412-m259xj2i5mub8u1g
Tags: 1.3.13-0ubuntu1
* New upstream release
* debian/patches/03_fixing_jit_arm_crashes.patch:
  - Applied upstream
* debian/patches/03_gtk_doc.patch:
  - Fix documentation build

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
WebInspector.DebuggerPresentationModel = function()
32
32
{
33
 
    this._breakpoints = {};
34
 
    this._sourceLocationToBreakpointId = {};
 
33
    this.reset();
35
34
 
36
 
    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointAdded, this._breakpointAdded, this);
37
 
    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointRemoved, this._breakpointRemoved, this);
 
35
    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this);
 
36
    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
 
37
    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._failedToParseScriptSource, this);
 
38
    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ScriptSourceChanged, this._scriptSourceChanged, this);
38
39
    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointResolved, this._breakpointResolved, this);
39
40
}
40
41
 
41
42
WebInspector.DebuggerPresentationModel.Events = {
 
43
    SourceFileAdded: "source-file-added",
 
44
    SourceFileChanged: "source-file-changed",
42
45
    BreakpointAdded: "breakpoint-added",
43
46
    BreakpointRemoved: "breakpoint-removed"
44
47
}
45
48
 
46
49
WebInspector.DebuggerPresentationModel.prototype = {
47
 
    breakpointsForSourceName: function(sourceName)
48
 
    {
 
50
    _debuggerWasEnabled: function()
 
51
    {
 
52
        this._restoreBreakpoints();
 
53
    },
 
54
 
 
55
    sourceFile: function(sourceFileId)
 
56
    {
 
57
        return this._sourceFiles[sourceFileId];
 
58
    },
 
59
 
 
60
    requestSourceFileContent: function(sourceFileId, callback)
 
61
    {
 
62
        var sourceFile = this._sourceFiles[sourceFileId];
 
63
        var script = sourceFile._script;
 
64
        var resource = sourceFile._resource;
 
65
        if (resource) {
 
66
            // FIXME: move provider's load functions here.
 
67
            var provider = new WebInspector.SourceFrameDelegateForScriptsPanel(null, null, script);
 
68
            if (resource.finished)
 
69
                provider._loadResourceContent(resource, callback);
 
70
            else
 
71
                provider._loadAndConcatenateScriptsContent(callback);
 
72
        } else {
 
73
            function didRequestSource(source)
 
74
            {
 
75
                callback("text/javascript", source);
 
76
            }
 
77
            script.requestSource(didRequestSource);
 
78
        }
 
79
    },
 
80
 
 
81
    _parsedScriptSource: function(event)
 
82
    {
 
83
        this._addScript(event.data);
 
84
    },
 
85
 
 
86
    _failedToParseScriptSource: function(event)
 
87
    {
 
88
        this._addScript(event.data);
 
89
    },
 
90
 
 
91
    _addScript: function(script)
 
92
    {
 
93
        var sourceFileId = script.sourceURL || script.sourceID;
 
94
        if (sourceFileId in this._sourceFiles)
 
95
            return;
 
96
 
 
97
        var sourceFile = {};
 
98
        sourceFile.id = sourceFileId;
 
99
        sourceFile.url = script.sourceURL;
 
100
        sourceFile.isExtensionScript = script.worldType === WebInspector.Script.WorldType.EXTENSIONS_WORLD;
 
101
        sourceFile._script = script;
 
102
        sourceFile._resource = script.sourceURL ? this._resourceForURL(script.sourceURL) : null;
 
103
        this._sourceFiles[sourceFileId] = sourceFile;
 
104
 
 
105
        if (!sourceFile._resource || sourceFile._resource.finished)
 
106
            this._sourceFileAdded(sourceFile);
 
107
        else {
 
108
            sourceFile._pending = true;
 
109
            function resourceFinished()
 
110
            {
 
111
                if (sourceFile._pending) {
 
112
                    delete sourceFile._pending;
 
113
                    this._sourceFileAdded(sourceFile);
 
114
                } else {
 
115
                    // Source file was forcibly added before resource was finished.
 
116
                    this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.SourceFileChanged, sourceFile);
 
117
                }
 
118
            }
 
119
            sourceFile._resource.addEventListener("finished", resourceFinished.bind(this));
 
120
        }
 
121
    },
 
122
 
 
123
    _ensureSourceFileAdded: function(script)
 
124
    {
 
125
        var sourceFile = this._sourceFiles[script.sourceURL || script.sourceID];
 
126
        if (!sourceFile._resource || sourceFile._resource.finished)
 
127
            return;
 
128
 
 
129
        if (sourceFile._pending) {
 
130
            delete sourceFile._pending;
 
131
            this._sourceFileAdded(sourceFile);
 
132
        } else {
 
133
            // FIXME: dispatch event only if source file content changed.
 
134
            this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.SourceFileChanged, sourceFile);
 
135
        }
 
136
    },
 
137
 
 
138
    _resourceForURL: function(url)
 
139
    {
 
140
        return WebInspector.networkManager.inflightResourceForURL(url) || WebInspector.resourceForURL(url);
 
141
    },
 
142
 
 
143
    _scriptSourceChanged: function(event)
 
144
    {
 
145
        var sourceID = event.data.sourceID;
 
146
        var oldSource = event.data.oldSource;
 
147
        var script = WebInspector.debuggerModel.scriptForSourceID(sourceID);
 
148
 
 
149
        var resource = WebInspector.resourceForURL(script.sourceURL);
 
150
        if (resource) {
 
151
            var revertHandle = WebInspector.debuggerModel.editScriptSource.bind(WebInspector.debuggerModel, script.sourceID, oldSource);
 
152
            resource.setContent(script.source, revertHandle);
 
153
        }
 
154
 
 
155
        var sourceFileId = script.sourceURL || script.sourceID;
 
156
 
 
157
        // Clear and re-create breakpoints according to text diff.
 
158
        var diff = Array.diff(oldSource.split("\n"), script.source.split("\n"));
 
159
        for (var id in this._presentationBreakpoints) {
 
160
            var breakpoint = this._presentationBreakpoints[id];
 
161
            if (breakpoint.sourceFileId !== sourceFileId)
 
162
                continue;
 
163
            var lineNumber = breakpoint.lineNumber;
 
164
            this.removeBreakpoint(sourceFileId, lineNumber);
 
165
 
 
166
            var newLineNumber = diff.left[lineNumber].row;
 
167
            if (newLineNumber === undefined) {
 
168
                for (var i = lineNumber - 1; i >= 0; --i) {
 
169
                    if (diff.left[i].row === undefined)
 
170
                        continue;
 
171
                    var shiftedLineNumber = diff.left[i].row + lineNumber - i;
 
172
                    if (shiftedLineNumber < diff.right.length) {
 
173
                        var originalLineNumber = diff.right[shiftedLineNumber].row;
 
174
                        if (originalLineNumber === lineNumber || originalLineNumber === undefined)
 
175
                            newLineNumber = shiftedLineNumber;
 
176
                    }
 
177
                    break;
 
178
                }
 
179
            }
 
180
            if (newLineNumber !== undefined)
 
181
                this.setBreakpoint(sourceFileId, newLineNumber, breakpoint.condition, breakpoint.enabled);
 
182
        }
 
183
 
 
184
        var sourceFile = this._sourceFiles[sourceFileId];
 
185
        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.SourceFileChanged, sourceFile);
 
186
    },
 
187
 
 
188
    _sourceFileAdded: function(sourceFile)
 
189
    {
 
190
        sourceFile._breakpoints = [];
 
191
        var breakpoints = WebInspector.debuggerModel.breakpoints;
 
192
        for (var id in breakpoints) {
 
193
            if (!(id in this._presentationBreakpoints))
 
194
                this._breakpointAdded(breakpoints[id]);
 
195
        }
 
196
        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.SourceFileAdded, sourceFile);
 
197
    },
 
198
 
 
199
    continueToLine: function(sourceFileId, lineNumber)
 
200
    {
 
201
        var location = this._sourceLocationToActualLocation(sourceFileId, lineNumber);
 
202
        if (location.sourceID)
 
203
            WebInspector.debuggerModel.continueToLocation(location.sourceID, location.lineNumber, location.columnNumber);
 
204
    },
 
205
 
 
206
    breakpointsForSourceFileId: function(sourceFileId)
 
207
    {
 
208
        var sourceFile = this.sourceFile(sourceFileId);
 
209
        if (!sourceFile)
 
210
            return [];
49
211
        var breakpoints = [];
50
 
        for (var id in this._breakpoints) {
51
 
            var breakpoint = this._breakpoints[id];
52
 
            if (breakpoint.sourceName === sourceName)
53
 
                breakpoints.push(breakpoint);
54
 
        }
 
212
        for (var lineNumber in sourceFile._breakpoints)
 
213
            breakpoints.push(sourceFile._breakpoints[lineNumber]);
55
214
        return breakpoints;
56
215
    },
57
216
 
58
 
    _breakpointAdded: function(event)
59
 
    {
60
 
        var breakpoint = event.data;
 
217
    setBreakpoint: function(sourceFileId, lineNumber, condition, enabled)
 
218
    {
 
219
        function didSetBreakpoint(breakpoint)
 
220
        {
 
221
            if (breakpoint) {
 
222
                this._breakpointAdded(breakpoint);
 
223
                this._saveBreakpoints();
 
224
            }
 
225
        }
 
226
        var location = this._sourceLocationToActualLocation(sourceFileId, lineNumber);
 
227
        if (location.url)
 
228
            WebInspector.debuggerModel.setBreakpoint(location.url, location.lineNumber, location.columnNumber, condition, enabled, didSetBreakpoint.bind(this));
 
229
        else
 
230
            WebInspector.debuggerModel.setBreakpointBySourceId(location.sourceID, location.lineNumber, location.columnNumber, condition, enabled, didSetBreakpoint.bind(this));
 
231
    },
 
232
 
 
233
    setBreakpointEnabled: function(sourceFileId, lineNumber, enabled)
 
234
    {
 
235
        var breakpoint = this.removeBreakpoint(sourceFileId, lineNumber);
 
236
        this.setBreakpoint(sourceFileId, lineNumber, breakpoint.condition, enabled);
 
237
    },
 
238
 
 
239
    updateBreakpoint: function(sourceFileId, lineNumber, condition, enabled)
 
240
    {
 
241
        this.removeBreakpoint(sourceFileId, lineNumber);
 
242
        this.setBreakpoint(sourceFileId, lineNumber, condition, enabled);
 
243
    },
 
244
 
 
245
    removeBreakpoint: function(sourceFileId, lineNumber)
 
246
    {
 
247
        var breakpoint = this.findBreakpoint(sourceFileId, lineNumber);
 
248
        WebInspector.debuggerModel.removeBreakpoint(breakpoint._id);
 
249
        this._breakpointRemoved(breakpoint._id);
 
250
        this._saveBreakpoints();
 
251
        return breakpoint;
 
252
    },
 
253
 
 
254
    findBreakpoint: function(sourceFileId, lineNumber)
 
255
    {
 
256
        var sourceFile = this.sourceFile(sourceFileId);
 
257
        if (sourceFile)
 
258
            return sourceFile._breakpoints[lineNumber];
 
259
    },
 
260
 
 
261
    _breakpointAdded: function(breakpoint)
 
262
    {
61
263
        var location = breakpoint.locations.length ? breakpoint.locations[0] : breakpoint;
62
 
        var sourceLocation = this._actualLocationToSourceLocation(breakpoint.url || breakpoint.sourceID, location.lineNumber, location.columnNumber);
 
264
        var sourceLocation = this._actualLocationToSourceLocation(breakpoint.url, breakpoint.sourceID, location.lineNumber, location.columnNumber);
 
265
        if (!sourceLocation)
 
266
            return;
63
267
 
64
 
        var encodedSourceLocation = this._encodeSourceLocation(sourceLocation.sourceName, sourceLocation.lineNumber);
65
 
        if (encodedSourceLocation in this._sourceLocationToBreakpointId) {
66
 
            // We can't show more than one breakpoint on a single source frame line. Remove newly added breakpoint.
 
268
        if (this.findBreakpoint(sourceLocation.sourceFileId, sourceLocation.lineNumber)) {
 
269
            // We can't show more than one breakpoint on a single source file line.
67
270
            WebInspector.debuggerModel.removeBreakpoint(breakpoint.id);
68
271
            return;
69
272
        }
70
273
 
71
274
        var presentationBreakpoint = {
72
 
            sourceName: sourceLocation.sourceName,
 
275
            sourceFileId: sourceLocation.sourceFileId,
73
276
            lineNumber: sourceLocation.lineNumber,
74
277
            url: breakpoint.url,
75
278
            resolved: !!breakpoint.locations.length,
76
279
            condition: breakpoint.condition,
77
 
            enabled: breakpoint.enabled
 
280
            enabled: breakpoint.enabled,
 
281
            _id: breakpoint.id
78
282
        };
79
 
 
80
 
        this._sourceLocationToBreakpointId[encodedSourceLocation] = breakpoint.id;
81
 
        this._breakpoints[breakpoint.id] = presentationBreakpoint;
82
 
 
 
283
        if (location.sourceID) {
 
284
            var script = WebInspector.debuggerModel.scriptForSourceID(location.sourceID);
 
285
            presentationBreakpoint.loadSnippet = script.sourceLine.bind(script, location.lineNumber);
 
286
        }
 
287
 
 
288
        this._presentationBreakpoints[breakpoint.id] = presentationBreakpoint;
 
289
        var sourceFile = this.sourceFile(sourceLocation.sourceFileId);
 
290
        sourceFile._breakpoints[sourceLocation.lineNumber] = presentationBreakpoint;
83
291
        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointAdded, presentationBreakpoint);
84
292
    },
85
293
 
86
 
    _breakpointRemoved: function(event)
 
294
    _breakpointRemoved: function(breakpointId)
87
295
    {
88
 
        var breakpointId = event.data;
89
 
        var breakpoint = this._breakpoints[breakpointId];
90
 
        var encodedSourceLocation = this._encodeSourceLocation(breakpoint.sourceName, breakpoint.lineNumber);
91
 
        delete this._breakpoints[breakpointId];
92
 
        delete this._sourceLocationToBreakpointId[encodedSourceLocation];
 
296
        var breakpoint = this._presentationBreakpoints[breakpointId];
 
297
        delete this._presentationBreakpoints[breakpointId];
 
298
        var sourceFile = this.sourceFile(breakpoint.sourceFileId);
 
299
        delete sourceFile._breakpoints[breakpoint.lineNumber];
93
300
        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointRemoved, breakpoint);
94
301
    },
95
302
 
96
303
    _breakpointResolved: function(event)
97
304
    {
98
305
        var breakpoint = event.data;
99
 
        this._breakpointRemoved({ data: breakpoint.id });
100
 
        this._breakpointAdded({ data: breakpoint });
101
 
    },
102
 
 
103
 
    _encodeSourceLocation: function(sourceName, lineNumber)
104
 
    {
105
 
        return sourceName + ":" + lineNumber;
106
 
    },
107
 
 
108
 
    _actualLocationToSourceLocation: function(sourceName, lineNumber, columnNumber)
 
306
        if (!(breakpoint.id in this._presentationBreakpoints))
 
307
            return;
 
308
        this._breakpointRemoved(breakpoint.id);
 
309
        this._breakpointAdded(breakpoint);
 
310
    },
 
311
 
 
312
    _restoreBreakpoints: function()
 
313
    {
 
314
        function didSetBreakpoint(breakpoint)
 
315
        {
 
316
            if (breakpoint)
 
317
                this._breakpointAdded(breakpoint);
 
318
        }
 
319
        var breakpoints = WebInspector.settings.breakpoints;
 
320
        for (var i = 0; i < breakpoints.length; ++i) {
 
321
            var breakpoint = breakpoints[i];
 
322
            WebInspector.debuggerModel.setBreakpoint(breakpoint.url, breakpoint.lineNumber, breakpoint.columnNumber, breakpoint.condition, breakpoint.enabled, didSetBreakpoint.bind(this));
 
323
        }
 
324
    },
 
325
 
 
326
    _saveBreakpoints: function()
 
327
    {
 
328
        var serializedBreakpoints = [];
 
329
        var breakpoints = WebInspector.debuggerModel.breakpoints;
 
330
        for (var id in breakpoints) {
 
331
            var breakpoint = breakpoints[id];
 
332
            if (!breakpoint.url)
 
333
                continue;
 
334
            var serializedBreakpoint = {};
 
335
            serializedBreakpoint.url = breakpoint.url;
 
336
            serializedBreakpoint.lineNumber = breakpoint.lineNumber;
 
337
            serializedBreakpoint.columnNumber = breakpoint.columnNumber;
 
338
            serializedBreakpoint.condition = breakpoint.condition;
 
339
            serializedBreakpoint.enabled = breakpoint.enabled;
 
340
            serializedBreakpoints.push(serializedBreakpoint);
 
341
        }
 
342
        WebInspector.settings.breakpoints = serializedBreakpoints;
 
343
    },
 
344
 
 
345
    set selectedCallFrame(callFrame)
 
346
    {
 
347
        this._selectedCallFrame = callFrame;
 
348
        if (!callFrame)
 
349
            return;
 
350
 
 
351
        var script = WebInspector.debuggerModel.scriptForSourceID(callFrame.sourceID);
 
352
        this._ensureSourceFileAdded(script);
 
353
        callFrame.sourceLocation = this._actualLocationToSourceLocation(script.sourceURL, script.sourceID, callFrame.line, callFrame.column);
 
354
        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.CallFrameSelected, callFrame);
 
355
    },
 
356
 
 
357
    get selectedCallFrame()
 
358
    {
 
359
        return this._selectedCallFrame;
 
360
    },
 
361
 
 
362
    _actualLocationToSourceLocation: function(scriptURL, scriptId, lineNumber, columnNumber)
109
363
    {
110
364
        // TODO: use source mapping to obtain source location.
111
 
        return { sourceName: sourceName, lineNumber: lineNumber, columnNumber: columnNumber };
 
365
        var sourceFile = this._sourceFiles[scriptURL || scriptId];
 
366
        if (sourceFile && !sourceFile._pending)
 
367
            return { sourceFileId: sourceFile.id, lineNumber: lineNumber, columnNumber: columnNumber };
 
368
    },
 
369
 
 
370
    _sourceLocationToActualLocation: function(sourceFileId, lineNumber)
 
371
    {
 
372
        // TODO: use source mapping to obtain actual location.
 
373
        function filter(script)
 
374
        {
 
375
            return (script.sourceURL || script.sourceID) === sourceFileId;
 
376
        }
 
377
        var script = WebInspector.debuggerModel.queryScripts(filter)[0];
 
378
        return { url: script.sourceURL, sourceID: script.sourceID, lineNumber: lineNumber, columnNumber: 0 };
 
379
    },
 
380
 
 
381
    reset: function()
 
382
    {
 
383
        this._sourceFiles = {};
 
384
        this._presentationBreakpoints = {};
112
385
    }
113
386
}
114
387