Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(897)

Side by Side Diff: Source/devtools/front_end/sdk/ResourceScriptMapping.js

Issue 464963002: DevTools: Make UISourceCode Target-agnostic (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 * @implements {WebInspector.ScriptSourceMapping} 33 * @implements {WebInspector.ScriptSourceMapping}
34 * @param {!WebInspector.DebuggerModel} debuggerModel 34 * @param {!WebInspector.DebuggerModel} debuggerModel
35 * @param {!WebInspector.Workspace} workspace 35 * @param {!WebInspector.Workspace} workspace
36 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding 36 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
37 */ 37 */
38 WebInspector.ResourceScriptMapping = function(debuggerModel, workspace, debugger WorkspaceBinding) 38 WebInspector.ResourceScriptMapping = function(debuggerModel, workspace, debugger WorkspaceBinding)
39 { 39 {
40 this._target = debuggerModel.target(); 40 this._target = debuggerModel.target();
41 this._debuggerModel = debuggerModel; 41 this._debuggerModel = debuggerModel;
42 this._workspace = workspace; 42 this._workspace = workspace;
43 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAddedToWorkspace, this); 43 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this);
44 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this);
44 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; 45 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding;
45 this._boundURLs = new StringSet(); 46 this._boundURLs = new StringSet();
46 47
48 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.ResourceScriptFil e>} */
49 this._uiSourceCodeToScriptFile = new Map();
50
47 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjec tCleared, this._debuggerReset, this); 51 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjec tCleared, this._debuggerReset, this);
48 } 52 }
49 53
50 WebInspector.ResourceScriptMapping.prototype = { 54 WebInspector.ResourceScriptMapping.prototype = {
51 /** 55 /**
52 * @param {!WebInspector.RawLocation} rawLocation 56 * @param {!WebInspector.RawLocation} rawLocation
53 * @return {?WebInspector.UILocation} 57 * @return {?WebInspector.UILocation}
54 */ 58 */
55 rawLocationToUILocation: function(rawLocation) 59 rawLocationToUILocation: function(rawLocation)
56 { 60 {
57 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (rawLocation); 61 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (rawLocation);
58 var script = debuggerModelLocation.script(); 62 var script = debuggerModelLocation.script();
59 var uiSourceCode = this._workspaceUISourceCodeForScript(script); 63 var uiSourceCode = this._workspaceUISourceCodeForScript(script);
60 if (!uiSourceCode) 64 if (!uiSourceCode)
61 return null; 65 return null;
62 var scriptFile = uiSourceCode.scriptFileForTarget(this._target); 66 var scriptFile = this.scriptFile(uiSourceCode);
63 if (scriptFile && ((scriptFile.hasDivergedFromVM() && !scriptFile.isMerg ingToVM()) || scriptFile.isDivergingFromVM())) 67 if (scriptFile && ((scriptFile.hasDivergedFromVM() && !scriptFile.isMerg ingToVM()) || scriptFile.isDivergingFromVM()))
64 return null; 68 return null;
65 return uiSourceCode.uiLocation(debuggerModelLocation.lineNumber, debugge rModelLocation.columnNumber || 0); 69 return uiSourceCode.uiLocation(debuggerModelLocation.lineNumber, debugge rModelLocation.columnNumber || 0);
66 }, 70 },
67 71
68 /** 72 /**
69 * @param {!WebInspector.UISourceCode} uiSourceCode 73 * @param {!WebInspector.UISourceCode} uiSourceCode
70 * @param {number} lineNumber 74 * @param {number} lineNumber
71 * @param {number} columnNumber 75 * @param {number} columnNumber
72 * @return {?WebInspector.DebuggerModel.Location} 76 * @return {?WebInspector.DebuggerModel.Location}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 /** 109 /**
106 * @param {!WebInspector.UISourceCode} uiSourceCode 110 * @param {!WebInspector.UISourceCode} uiSourceCode
107 * @param {number} lineNumber 111 * @param {number} lineNumber
108 * @return {boolean} 112 * @return {boolean}
109 */ 113 */
110 uiLineHasMapping: function(uiSourceCode, lineNumber) 114 uiLineHasMapping: function(uiSourceCode, lineNumber)
111 { 115 {
112 return true; 116 return true;
113 }, 117 },
114 118
115 _uiSourceCodeAddedToWorkspace: function(event) 119 /**
120 * @param {!WebInspector.UISourceCode} uiSourceCode
121 * @return {?WebInspector.ResourceScriptFile}
122 */
123 scriptFile: function(uiSourceCode)
124 {
125 return this._uiSourceCodeToScriptFile.get(uiSourceCode) || null;
126 },
127
128 /**
129 * @param {!WebInspector.UISourceCode} uiSourceCode
130 * @param {?WebInspector.ResourceScriptFile} scriptFile
131 */
132 _setScriptFile: function(uiSourceCode, scriptFile)
133 {
134 if (scriptFile)
135 this._uiSourceCodeToScriptFile.put(uiSourceCode, scriptFile);
136 else
137 this._uiSourceCodeToScriptFile.remove(uiSourceCode);
138 },
139
140 /**
141 * @param {!WebInspector.Event} event
142 */
143 _uiSourceCodeAdded: function(event)
116 { 144 {
117 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data ); 145 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
146 if (!uiSourceCode.url)
147 return;
118 if (uiSourceCode.project().isServiceProject()) 148 if (uiSourceCode.project().isServiceProject())
119 return; 149 return;
120 if (!uiSourceCode.url)
121 return;
122 150
123 var scripts = this._scriptsForUISourceCode(uiSourceCode); 151 var scripts = this._scriptsForUISourceCode(uiSourceCode);
124 if (!scripts.length) 152 if (!scripts.length)
125 return; 153 return;
126 154
127 this._bindUISourceCodeToScripts(uiSourceCode, scripts); 155 this._bindUISourceCodeToScripts(uiSourceCode, scripts);
128 }, 156 },
129 157
130 /** 158 /**
159 * @param {!WebInspector.Event} event
160 */
161 _uiSourceCodeRemoved: function(event)
162 {
163 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
164 if (!uiSourceCode.url)
165 return;
166 if (uiSourceCode.project().isServiceProject())
167 return;
168
169 this._unbindUISourceCode(uiSourceCode);
170 },
171
172 /**
131 * @param {!WebInspector.UISourceCode} uiSourceCode 173 * @param {!WebInspector.UISourceCode} uiSourceCode
132 */ 174 */
133 _hasMergedToVM: function(uiSourceCode) 175 _hasMergedToVM: function(uiSourceCode)
134 { 176 {
135 var scripts = this._scriptsForUISourceCode(uiSourceCode); 177 var scripts = this._scriptsForUISourceCode(uiSourceCode);
136 if (!scripts.length) 178 if (!scripts.length)
137 return; 179 return;
138 for (var i = 0; i < scripts.length; ++i) 180 for (var i = 0; i < scripts.length; ++i)
139 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); 181 this._debuggerWorkspaceBinding.updateLocations(scripts[i]);
140 }, 182 },
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 }, 216 },
175 217
176 /** 218 /**
177 * @param {!WebInspector.UISourceCode} uiSourceCode 219 * @param {!WebInspector.UISourceCode} uiSourceCode
178 * @param {!Array.<!WebInspector.Script>} scripts 220 * @param {!Array.<!WebInspector.Script>} scripts
179 */ 221 */
180 _bindUISourceCodeToScripts: function(uiSourceCode, scripts) 222 _bindUISourceCodeToScripts: function(uiSourceCode, scripts)
181 { 223 {
182 console.assert(scripts.length); 224 console.assert(scripts.length);
183 var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode, scripts); 225 var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode, scripts);
184 uiSourceCode.setScriptFileForTarget(this._target, scriptFile); 226 this._setScriptFile(uiSourceCode, scriptFile);
185 for (var i = 0; i < scripts.length; ++i) 227 for (var i = 0; i < scripts.length; ++i)
186 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); 228 this._debuggerWorkspaceBinding.updateLocations(scripts[i]);
187 uiSourceCode.setSourceMappingForTarget(this._target, this); 229 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCo de, this);
188 this._boundURLs.add(uiSourceCode.url); 230 this._boundURLs.add(uiSourceCode.url);
189 }, 231 },
190 232
191 /** 233 /**
192 * @param {!WebInspector.UISourceCode} uiSourceCode 234 * @param {!WebInspector.UISourceCode} uiSourceCode
193 */ 235 */
194 _unbindUISourceCode: function(uiSourceCode) 236 _unbindUISourceCode: function(uiSourceCode)
195 { 237 {
196 var scriptFile = /** @type {!WebInspector.ResourceScriptFile} */ (uiSour ceCode.scriptFileForTarget(this._target)); 238 var scriptFile = this.scriptFile(uiSourceCode);
197 if (scriptFile) { 239 if (scriptFile) {
198 scriptFile.dispose(); 240 scriptFile.dispose();
199 uiSourceCode.setScriptFileForTarget(this._target, null); 241 this._setScriptFile(uiSourceCode, null);
200 } 242 }
201 uiSourceCode.setSourceMappingForTarget(this._target, null); 243 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCo de, null);
202 }, 244 },
203 245
204 _debuggerReset: function() 246 _debuggerReset: function()
205 { 247 {
206 var boundURLs = this._boundURLs.values(); 248 var boundURLs = this._boundURLs.values();
207 for (var i = 0; i < boundURLs.length; ++i) 249 for (var i = 0; i < boundURLs.length; ++i)
208 { 250 {
209 var uiSourceCode = this._workspace.uiSourceCodeForURL(boundURLs[i]); 251 var uiSourceCode = this._workspace.uiSourceCodeForURL(boundURLs[i]);
210 if (!uiSourceCode) 252 if (!uiSourceCode)
211 continue; 253 continue;
212 this._unbindUISourceCode(uiSourceCode); 254 this._unbindUISourceCode(uiSourceCode);
213 } 255 }
214 this._boundURLs.clear(); 256 this._boundURLs.clear();
215 }, 257 },
216 258
217 dispose: function() 259 dispose: function()
218 { 260 {
219 this._debuggerReset(); 261 this._debuggerReset();
220 this._workspace.removeEventListener(WebInspector.Workspace.Events.UISour ceCodeAdded, this._uiSourceCodeAddedToWorkspace, this); 262 this._workspace.removeEventListener(WebInspector.Workspace.Events.UISour ceCodeAdded, this._uiSourceCodeAdded, this);
263 this._workspace.removeEventListener(WebInspector.Workspace.Events.UISour ceCodeRemoved, this._uiSourceCodeRemoved, this);
221 } 264 }
222 265
223 } 266 }
224 267
225 /** 268 /**
226 * @constructor 269 * @constructor
227 * @extends {WebInspector.Object} 270 * @extends {WebInspector.Object}
228 * @param {!WebInspector.ResourceScriptMapping} resourceScriptMapping 271 * @param {!WebInspector.ResourceScriptMapping} resourceScriptMapping
229 * @param {!WebInspector.UISourceCode} uiSourceCode 272 * @param {!WebInspector.UISourceCode} uiSourceCode
230 * @param {!Array.<!WebInspector.Script>} scripts 273 * @param {!Array.<!WebInspector.Script>} scripts
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 */ 431 */
389 addSourceMapURL: function(sourceMapURL) 432 addSourceMapURL: function(sourceMapURL)
390 { 433 {
391 if (!this._script) 434 if (!this._script)
392 return; 435 return;
393 this._script.addSourceMapURL(sourceMapURL); 436 this._script.addSourceMapURL(sourceMapURL);
394 }, 437 },
395 438
396 __proto__: WebInspector.Object.prototype 439 __proto__: WebInspector.Object.prototype
397 } 440 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/LiveEditSupport.js ('k') | Source/devtools/front_end/sdk/ScriptSnippetModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698