| OLD | NEW |
| (Empty) |
| 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 * @implements {WebInspector.ScriptSourceMapping} | |
| 34 * @param {!WebInspector.DebuggerModel} debuggerModel | |
| 35 * @param {!WebInspector.Workspace} workspace | |
| 36 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | |
| 37 */ | |
| 38 WebInspector.DefaultScriptMapping = function(debuggerModel, workspace, debuggerW
orkspaceBinding) | |
| 39 { | |
| 40 this._debuggerModel = debuggerModel; | |
| 41 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; | |
| 42 this._workspace = workspace; | |
| 43 this._projectId = WebInspector.DefaultScriptMapping.projectIdForTarget(debug
gerModel.target()); | |
| 44 this._projectDelegate = new WebInspector.DebuggerProjectDelegate(this._works
pace, this._projectId, WebInspector.projectTypes.Debugger); | |
| 45 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjec
tCleared, this._debuggerReset, this); | |
| 46 this._debuggerReset(); | |
| 47 } | |
| 48 | |
| 49 WebInspector.DefaultScriptMapping.prototype = { | |
| 50 /** | |
| 51 * @param {!WebInspector.RawLocation} rawLocation | |
| 52 * @return {!WebInspector.UILocation} | |
| 53 */ | |
| 54 rawLocationToUILocation: function(rawLocation) | |
| 55 { | |
| 56 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat
ion} */ (rawLocation); | |
| 57 var script = debuggerModelLocation.script(); | |
| 58 var uiSourceCode = this._uiSourceCodeForScriptId[script.scriptId]; | |
| 59 var lineNumber = debuggerModelLocation.lineNumber; | |
| 60 var columnNumber = debuggerModelLocation.columnNumber || 0; | |
| 61 return uiSourceCode.uiLocation(lineNumber, columnNumber); | |
| 62 }, | |
| 63 | |
| 64 /** | |
| 65 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 66 * @param {number} lineNumber | |
| 67 * @param {number} columnNumber | |
| 68 * @return {?WebInspector.DebuggerModel.Location} | |
| 69 */ | |
| 70 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) | |
| 71 { | |
| 72 var scriptId = this._scriptIdForUISourceCode.get(uiSourceCode); | |
| 73 var script = this._debuggerModel.scriptForId(scriptId); | |
| 74 return this._debuggerModel.createRawLocation(script, lineNumber, columnN
umber); | |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * @param {!WebInspector.Script} script | |
| 79 */ | |
| 80 addScript: function(script) | |
| 81 { | |
| 82 var path = this._projectDelegate.addScript(script); | |
| 83 var uiSourceCode = this._workspace.uiSourceCode(this._projectId, path); | |
| 84 if (!uiSourceCode) { | |
| 85 console.assert(uiSourceCode); | |
| 86 return; | |
| 87 } | |
| 88 this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode; | |
| 89 this._scriptIdForUISourceCode.put(uiSourceCode, script.scriptId); | |
| 90 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel.targ
et(), uiSourceCode, this); | |
| 91 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); | |
| 92 script.addEventListener(WebInspector.Script.Events.ScriptEdited, this._s
criptEdited.bind(this, script.scriptId)); | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * @return {boolean} | |
| 97 */ | |
| 98 isIdentity: function() | |
| 99 { | |
| 100 return true; | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 105 * @param {number} lineNumber | |
| 106 * @return {boolean} | |
| 107 */ | |
| 108 uiLineHasMapping: function(uiSourceCode, lineNumber) | |
| 109 { | |
| 110 return true; | |
| 111 }, | |
| 112 | |
| 113 /** | |
| 114 * @param {string} scriptId | |
| 115 * @param {!WebInspector.Event} event | |
| 116 */ | |
| 117 _scriptEdited: function(scriptId, event) | |
| 118 { | |
| 119 var content = /** @type {string} */(event.data); | |
| 120 this._uiSourceCodeForScriptId[scriptId].addRevision(content); | |
| 121 }, | |
| 122 | |
| 123 _debuggerReset: function() | |
| 124 { | |
| 125 /** @type {!Object.<string, !WebInspector.UISourceCode>} */ | |
| 126 this._uiSourceCodeForScriptId = {}; | |
| 127 this._scriptIdForUISourceCode = new Map(); | |
| 128 this._projectDelegate.reset(); | |
| 129 }, | |
| 130 | |
| 131 dispose: function() | |
| 132 { | |
| 133 this._workspace.removeProject(this._projectId); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 /** | |
| 138 * @param {!WebInspector.Target} target | |
| 139 * @return {string} | |
| 140 */ | |
| 141 WebInspector.DefaultScriptMapping.projectIdForTarget = function(target) | |
| 142 { | |
| 143 return "debugger:" + target.id(); | |
| 144 } | |
| 145 | |
| 146 /** | |
| 147 * @constructor | |
| 148 * @param {!WebInspector.Workspace} workspace | |
| 149 * @param {string} id | |
| 150 * @param {!WebInspector.projectTypes} type | |
| 151 * @extends {WebInspector.ContentProviderBasedProjectDelegate} | |
| 152 */ | |
| 153 WebInspector.DebuggerProjectDelegate = function(workspace, id, type) | |
| 154 { | |
| 155 WebInspector.ContentProviderBasedProjectDelegate.call(this, workspace, id, t
ype); | |
| 156 } | |
| 157 | |
| 158 WebInspector.DebuggerProjectDelegate.prototype = { | |
| 159 /** | |
| 160 * @return {string} | |
| 161 */ | |
| 162 displayName: function() | |
| 163 { | |
| 164 return ""; | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 168 * @param {!WebInspector.Script} script | |
| 169 * @return {string} | |
| 170 */ | |
| 171 addScript: function(script) | |
| 172 { | |
| 173 var contentProvider = script.isInlineScript() ? new WebInspector.Concate
natedScriptsContentProvider([script]) : script; | |
| 174 var splitURL = WebInspector.ParsedURL.splitURL(script.sourceURL); | |
| 175 var name = splitURL[splitURL.length - 1]; | |
| 176 name = "VM" + script.scriptId + (name ? " " + name : ""); | |
| 177 return this.addContentProvider("", name, script.sourceURL, contentProvid
er); | |
| 178 }, | |
| 179 | |
| 180 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype | |
| 181 } | |
| OLD | NEW |