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 * @implements {WebInspector.DebuggerSourceMapping}
34 * @param {!WebInspector.DebuggerModel} debuggerModel
35 * @param {!WebInspector.Workspace} workspace
36 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
38 WebInspector
.DefaultScriptMapping = function(debuggerModel
, workspace
, debuggerWorkspaceBinding
)
40 this._debuggerModel
= debuggerModel
;
41 this._debuggerWorkspaceBinding
= debuggerWorkspaceBinding
;
42 this._workspace
= workspace
;
43 this._projectId
= WebInspector
.DefaultScriptMapping
.projectIdForTarget(debuggerModel
.target());
44 this._projectDelegate
= new WebInspector
.DebuggerProjectDelegate(this._workspace
, this._projectId
, WebInspector
.projectTypes
.Debugger
);
45 debuggerModel
.addEventListener(WebInspector
.DebuggerModel
.Events
.GlobalObjectCleared
, this._debuggerReset
, this);
46 this._debuggerReset();
49 WebInspector
.DefaultScriptMapping
.prototype = {
52 * @param {!WebInspector.DebuggerModel.Location} rawLocation
53 * @return {!WebInspector.UILocation}
55 rawLocationToUILocation: function(rawLocation
)
57 var debuggerModelLocation
= /** @type {!WebInspector.DebuggerModel.Location} */ (rawLocation
);
58 var script
= debuggerModelLocation
.script();
59 var uiSourceCode
= this._uiSourceCodeForScriptId
.get(script
.scriptId
);
60 var lineNumber
= debuggerModelLocation
.lineNumber
- (script
.isInlineScriptWithSourceURL() ? script
.lineOffset
: 0);
61 var columnNumber
= debuggerModelLocation
.columnNumber
|| 0;
62 if (script
.isInlineScriptWithSourceURL() && !lineNumber
&& columnNumber
)
63 columnNumber
-= script
.columnOffset
;
64 return uiSourceCode
.uiLocation(lineNumber
, columnNumber
);
69 * @param {!WebInspector.UISourceCode} uiSourceCode
70 * @param {number} lineNumber
71 * @param {number} columnNumber
72 * @return {?WebInspector.DebuggerModel.Location}
74 uiLocationToRawLocation: function(uiSourceCode
, lineNumber
, columnNumber
)
76 var scriptId
= this._scriptIdForUISourceCode
.get(uiSourceCode
);
77 var script
= this._debuggerModel
.scriptForId(scriptId
);
78 if (script
.isInlineScriptWithSourceURL())
79 return this._debuggerModel
.createRawLocation(script
, lineNumber
+ script
.lineOffset
, lineNumber
? columnNumber
: columnNumber
+ script
.columnOffset
);
80 return this._debuggerModel
.createRawLocation(script
, lineNumber
, columnNumber
);
84 * @param {!WebInspector.Script} script
86 addScript: function(script
)
88 var path
= this._projectDelegate
.addScript(script
);
89 var uiSourceCode
= this._workspace
.uiSourceCode(this._projectId
, path
);
90 console
.assert(uiSourceCode
);
91 uiSourceCode
= /** @type {!WebInspector.UISourceCode} */ (uiSourceCode
);
93 this._uiSourceCodeForScriptId
.set(script
.scriptId
, uiSourceCode
);
94 this._scriptIdForUISourceCode
.set(uiSourceCode
, script
.scriptId
);
95 this._debuggerWorkspaceBinding
.setSourceMapping(this._debuggerModel
.target(), uiSourceCode
, this);
96 this._debuggerWorkspaceBinding
.pushSourceMapping(script
, this);
97 script
.addEventListener(WebInspector
.Script
.Events
.ScriptEdited
, this._scriptEdited
, this);
104 isIdentity: function()
111 * @param {!WebInspector.UISourceCode} uiSourceCode
112 * @param {number} lineNumber
115 uiLineHasMapping: function(uiSourceCode
, lineNumber
)
121 * @param {!WebInspector.Event} event
123 _scriptEdited: function(event
)
125 var script
= /** @type {!WebInspector.Script} */(event
.target
);
126 var content
= /** @type {string} */(event
.data
);
127 this._uiSourceCodeForScriptId
.get(script
.scriptId
).addRevision(content
);
130 _debuggerReset: function()
132 /** @type {!Map.<string, !WebInspector.UISourceCode>} */
133 this._uiSourceCodeForScriptId
= new Map();
134 this._scriptIdForUISourceCode
= new Map();
135 this._projectDelegate
.reset();
140 this._workspace
.removeProject(this._projectId
);
145 * @param {!WebInspector.Target} target
148 WebInspector
.DefaultScriptMapping
.projectIdForTarget = function(target
)
150 return "debugger:" + target
.id();
155 * @param {!WebInspector.Workspace} workspace
157 * @param {!WebInspector.projectTypes} type
158 * @extends {WebInspector.ContentProviderBasedProjectDelegate}
160 WebInspector
.DebuggerProjectDelegate = function(workspace
, id
, type
)
162 WebInspector
.ContentProviderBasedProjectDelegate
.call(this, workspace
, id
, type
);
165 WebInspector
.DebuggerProjectDelegate
.prototype = {
170 displayName: function()
185 * @param {!WebInspector.Script} script
188 addScript: function(script
)
190 var splitURL
= WebInspector
.ParsedURL
.splitURLIntoPathComponents(script
.sourceURL
);
191 var name
= splitURL
[splitURL
.length
- 1];
192 name
= "VM" + script
.scriptId
+ (name
? " " + name
: "");
193 return this.addContentProvider("", name
, script
.sourceURL
, script
.sourceURL
, script
);
196 __proto__
: WebInspector
.ContentProviderBasedProjectDelegate
.prototype