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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/ResourceScriptMapping.js

Issue 2958403002: [WIP] DevTools: move UISourceCode creation into ResourceScriptMapping
Patch Set: pass everything but breakpointmanager Created 3 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 */ 33 */
34 Bindings.ResourceScriptMapping = class { 34 Bindings.ResourceScriptMapping = class {
35 /** 35 /**
36 * @param {!SDK.DebuggerModel} debuggerModel 36 * @param {!SDK.DebuggerModel} debuggerModel
37 * @param {!Workspace.Workspace} workspace 37 * @param {!Workspace.Workspace} workspace
38 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding 38 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
39 */ 39 */
40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) { 40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) {
41 this._debuggerModel = debuggerModel; 41 this._debuggerModel = debuggerModel;
42 this._workspace = workspace; 42 this._workspace = workspace;
43 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */
44 this._workspaceProjects = new Map();
45 /** @type {!Set<!SDK.Script>} */
46 this._acceptedScripts = new Set();
47
43 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; 48 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding;
44 /** @type {!Set<!Workspace.UISourceCode>} */ 49 /** @type {!Set<!Workspace.UISourceCode>} */
45 this._boundUISourceCodes = new Set(); 50 this._boundUISourceCodes = new Set();
46 51
47 /** @type {!Map.<!Workspace.UISourceCode, !Bindings.ResourceScriptFile>} */ 52 /** @type {!Map.<!Workspace.UISourceCode, !Bindings.ResourceScriptFile>} */
48 this._uiSourceCodeToScriptFile = new Map(); 53 this._uiSourceCodeToScriptFile = new Map();
49 54
55 var runtimeModel = this._debuggerModel.runtimeModel();
50 this._eventListeners = [ 56 this._eventListeners = [
57 runtimeModel.addEventListener(
58 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._executionCont extDestroyed, this),
51 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleare d, this._debuggerReset, this), 59 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleare d, this._debuggerReset, this),
52 debuggerModel.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSource , this._parsedScriptSource, this), 60 debuggerModel.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSource , this._parsedScriptSource, this),
53 debuggerModel.addEventListener( 61 debuggerModel.addEventListener(
54 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScript Source, this), 62 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScript Source, this),
55 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, t his._uiSourceCodeAdded, this),
56 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRemoved, this._uiSourceCodeRemoved, this)
57 ]; 63 ];
58 } 64 }
59 65
60 /** 66 /**
67 * @param {!SDK.Target} target
68 * @param {string} frameId
69 * @param {boolean} isContentScripts
70 * @return {string}
71 */
72 static projectId(target, frameId, isContentScripts) {
73 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : '');
74 }
75
76 /**
61 * @override 77 * @override
62 * @param {!SDK.DebuggerModel.Location} rawLocation 78 * @param {!SDK.DebuggerModel.Location} rawLocation
63 * @return {?Workspace.UILocation} 79 * @return {?Workspace.UILocation}
64 */ 80 */
65 rawLocationToUILocation(rawLocation) { 81 rawLocationToUILocation(rawLocation) {
66 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL ocation); 82 var script = rawLocation.script();
67 var script = debuggerModelLocation.script(); 83 if (!script || !this._acceptsScript(script))
68 if (!script)
69 return null; 84 return null;
70 var uiSourceCode = this._workspaceUISourceCodeForScript(script); 85 var frameId = script[Bindings.ResourceScriptMapping._frameIdSymbol];
86 var project = this._workspaceProject(frameId, script.isContentScript());
87 var uiSourceCode = project.uiSourceCodeForURL(script.contentURL());
71 if (!uiSourceCode) 88 if (!uiSourceCode)
72 return null; 89 return null;
73 var scriptFile = this.scriptFile(uiSourceCode); 90 var scriptFile = this.scriptFile(uiSourceCode);
74 if (scriptFile && 91 if (scriptFile &&
75 ((scriptFile.hasDivergedFromVM() && !scriptFile.isMergingToVM()) || scri ptFile.isDivergingFromVM())) 92 ((scriptFile.hasDivergedFromVM() && !scriptFile.isMergingToVM()) || scri ptFile.isDivergingFromVM()))
76 return null; 93 return null;
77 var lineNumber = debuggerModelLocation.lineNumber - (script.isInlineScriptWi thSourceURL() ? script.lineOffset : 0); 94 var lineNumber = rawLocation.lineNumber - (script.isInlineScriptWithSourceUR L() ? script.lineOffset : 0);
78 var columnNumber = debuggerModelLocation.columnNumber || 0; 95 var columnNumber = rawLocation.columnNumber || 0;
79 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber) 96 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber)
80 columnNumber -= script.columnOffset; 97 columnNumber -= script.columnOffset;
81 return uiSourceCode.uiLocation(lineNumber, columnNumber); 98 return uiSourceCode.uiLocation(lineNumber, columnNumber);
82 } 99 }
83 100
84 /** 101 /**
85 * @override 102 * @override
86 * @param {!Workspace.UISourceCode} uiSourceCode 103 * @param {!Workspace.UISourceCode} uiSourceCode
87 * @param {number} lineNumber 104 * @param {number} lineNumber
88 * @param {number} columnNumber 105 * @param {number} columnNumber
89 * @return {?SDK.DebuggerModel.Location} 106 * @return {?SDK.DebuggerModel.Location}
90 */ 107 */
91 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { 108 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) {
92 var scripts = this._scriptsForUISourceCode(uiSourceCode); 109 var scriptFile = this.scriptFile(uiSourceCode);
93 if (!scripts.length) 110 if (!scriptFile)
94 return null; 111 return null;
95 var script = scripts[scripts.length - 1]; 112 var script = scriptFile._script;
96 if (script.isInlineScriptWithSourceURL()) { 113 if (script.isInlineScriptWithSourceURL()) {
97 return this._debuggerModel.createRawLocationByURL( 114 return this._debuggerModel.createRawLocationByURL(
98 script.sourceURL, lineNumber + script.lineOffset, 115 script.sourceURL, lineNumber + script.lineOffset,
99 lineNumber ? columnNumber : columnNumber + script.columnOffset); 116 lineNumber ? columnNumber : columnNumber + script.columnOffset);
100 } 117 }
101 return this._debuggerModel.createRawLocationByURL(script.sourceURL, lineNumb er, columnNumber); 118 return this._debuggerModel.createRawLocationByURL(script.sourceURL, lineNumb er, columnNumber);
102 } 119 }
103 120
104 /** 121 /**
122 * @param {!SDK.Script} script
123 * @return {boolean}
124 */
125 _acceptsScript(script) {
126 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
127 return false;
128 // Filter out embedder injected content scripts.
129 if (script.isContentScript() && !script.hasSourceURL) {
130 var parsedURL = new Common.ParsedURL(script.sourceURL);
131 if (!parsedURL.isValid)
132 return false;
133 }
134 return true;
135 }
136
137 /**
105 * @param {!Common.Event} event 138 * @param {!Common.Event} event
106 */ 139 */
107 _parsedScriptSource(event) { 140 _parsedScriptSource(event) {
108 var script = /** @type {!SDK.Script} */ (event.data); 141 var script = /** @type {!SDK.Script} */ (event.data);
109 if (script.isAnonymousScript()) 142 if (!this._acceptsScript(script))
110 return; 143 return;
144 this._acceptedScripts.add(script);
145 var originalContentProvider = script.originalContentProvider();
146 var frameId = Bindings.frameIdForScript(script);
147 script[Bindings.ResourceScriptMapping._frameIdSymbol] = frameId;
111 148
112 var uiSourceCode = this._workspaceUISourceCodeForScript(script); 149 var project = this._workspaceProject(frameId, script.isContentScript());
113 if (!uiSourceCode) 150 var uiSourceCode = project.uiSourceCodeForURL(script.contentURL());
114 return; 151 if (uiSourceCode)
152 this._unbindUISourceCode(uiSourceCode);
153 uiSourceCode = project.createUISourceCode(script.contentURL(), originalConte ntProvider.contentType());
154 if (frameId)
155 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId);
115 156
116 this._bindUISourceCodeToScripts(uiSourceCode, [script]); 157 var scriptFile = new Bindings.ResourceScriptFile(this, uiSourceCode, script) ;
158 this._uiSourceCodeToScriptFile.set(uiSourceCode, scriptFile);
159 this._debuggerWorkspaceBinding.updateLocations(script);
160 this._boundUISourceCodes.add(uiSourceCode);
161
162 var metadata = Bindings.metadataForURL(this._debuggerModel.target(), frameId , uiSourceCode.url());
163 project.addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, m etadata, 'text/javascript');
164 }
165
166 /**
167 * @param {string} frameId
168 * @param {boolean} isContentScripts
169 * @return {!Bindings.ContentProviderBasedProject}
170 */
171 _workspaceProject(frameId, isContentScripts) {
172 var projectId = Bindings.ResourceScriptMapping.projectId(this._debuggerModel .target(), frameId, isContentScripts);
173 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network;
174
175 var project = this._workspaceProjects.get(projectId);
176 if (project)
177 return project;
178
179 project = new Bindings.ContentProviderBasedProject(
180 this._workspace, projectId, projectType, '', false /* isServiceProject * /);
181 Bindings.NetworkProject.setTargetForProject(project, this._debuggerModel.tar get());
182 this._workspaceProjects.set(projectId, project);
183 return project;
117 } 184 }
118 185
119 /** 186 /**
120 * @param {!Workspace.UISourceCode} uiSourceCode 187 * @param {!Workspace.UISourceCode} uiSourceCode
121 * @return {?Bindings.ResourceScriptFile} 188 * @return {?Bindings.ResourceScriptFile}
122 */ 189 */
123 scriptFile(uiSourceCode) { 190 scriptFile(uiSourceCode) {
124 return this._uiSourceCodeToScriptFile.get(uiSourceCode) || null; 191 return this._uiSourceCodeToScriptFile.get(uiSourceCode) || null;
125 } 192 }
126 193
127 /** 194 /**
128 * @param {!Workspace.UISourceCode} uiSourceCode 195 * @param {!SDK.Script} script
129 * @param {?Bindings.ResourceScriptFile} scriptFile
130 */ 196 */
131 _setScriptFile(uiSourceCode, scriptFile) { 197 _updateLocations(script) {
132 if (scriptFile) 198 this._debuggerWorkspaceBinding.updateLocations(script);
133 this._uiSourceCodeToScriptFile.set(uiSourceCode, scriptFile);
134 else
135 this._uiSourceCodeToScriptFile.remove(uiSourceCode);
136 } 199 }
137 200
138 /** 201 /**
139 * @param {!Common.Event} event
140 */
141 _uiSourceCodeAdded(event) {
142 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
143 if (uiSourceCode.project().isServiceProject())
144 return;
145 var scripts = this._scriptsForUISourceCode(uiSourceCode);
146 if (!scripts.length)
147 return;
148
149 this._bindUISourceCodeToScripts(uiSourceCode, scripts);
150 }
151
152 /**
153 * @param {!Common.Event} event
154 */
155 _uiSourceCodeRemoved(event) {
156 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
157 if (uiSourceCode.project().isServiceProject() || !this._boundUISourceCodes.h as(uiSourceCode))
158 return;
159
160 this._unbindUISourceCode(uiSourceCode);
161 }
162
163 /**
164 * @param {!Workspace.UISourceCode} uiSourceCode
165 */
166 _updateLocations(uiSourceCode) {
167 var scripts = this._scriptsForUISourceCode(uiSourceCode);
168 if (!scripts.length)
169 return;
170 for (var i = 0; i < scripts.length; ++i)
171 this._debuggerWorkspaceBinding.updateLocations(scripts[i]);
172 }
173
174 /**
175 * @param {!SDK.Script} script
176 * @return {?Workspace.UISourceCode}
177 */
178 _workspaceUISourceCodeForScript(script) {
179 if (script.isAnonymousScript())
180 return null;
181 return Bindings.NetworkProject.uiSourceCodeForScriptURL(this._workspace, scr ipt.sourceURL, script);
182 }
183
184 /**
185 * @param {!Workspace.UISourceCode} uiSourceCode
186 * @return {!Array.<!SDK.Script>}
187 */
188 _scriptsForUISourceCode(uiSourceCode) {
189 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
190 if (target !== this._debuggerModel.target())
191 return [];
192 return this._debuggerModel.scriptsForSourceURL(uiSourceCode.url());
193 }
194
195 /**
196 * @param {!Workspace.UISourceCode} uiSourceCode
197 * @param {!Array.<!SDK.Script>} scripts
198 */
199 _bindUISourceCodeToScripts(uiSourceCode, scripts) {
200 console.assert(scripts.length);
201 // Due to different listeners order, a script file could be created just bef ore uiSourceCode
202 // for the corresponding script was created. Check that we don't create scri ptFile twice.
203 var boundScriptFile = this.scriptFile(uiSourceCode);
204 if (boundScriptFile && boundScriptFile._hasScripts(scripts))
205 return;
206
207 var scriptFile = new Bindings.ResourceScriptFile(this, uiSourceCode, scripts );
208 this._setScriptFile(uiSourceCode, scriptFile);
209 for (var i = 0; i < scripts.length; ++i)
210 this._debuggerWorkspaceBinding.updateLocations(scripts[i]);
211 this._boundUISourceCodes.add(uiSourceCode);
212 }
213
214 /**
215 * @param {!Workspace.UISourceCode} uiSourceCode 202 * @param {!Workspace.UISourceCode} uiSourceCode
216 */ 203 */
217 _unbindUISourceCode(uiSourceCode) { 204 _unbindUISourceCode(uiSourceCode) {
218 var scriptFile = this.scriptFile(uiSourceCode); 205 var scriptFile = this.scriptFile(uiSourceCode);
219 if (scriptFile) { 206 if (scriptFile) {
220 scriptFile.dispose(); 207 scriptFile.dispose();
221 this._setScriptFile(uiSourceCode, null); 208 this._uiSourceCodeToScriptFile.delete(uiSourceCode);
222 } 209 }
223 this._boundUISourceCodes.delete(uiSourceCode); 210 this._boundUISourceCodes.delete(uiSourceCode);
224 if (scriptFile._script) 211 if (scriptFile._script)
225 this._debuggerWorkspaceBinding.updateLocations(scriptFile._script); 212 this._debuggerWorkspaceBinding.updateLocations(scriptFile._script);
226 } 213 }
227 214
228 _debuggerReset() { 215 _debuggerReset() {
216 this._removeScripts(Array.from(this._acceptedScripts));
217 console.assert(!this._boundUISourceCodes.size);
229 for (var uiSourceCode of this._boundUISourceCodes.valuesArray()) 218 for (var uiSourceCode of this._boundUISourceCodes.valuesArray())
230 this._unbindUISourceCode(uiSourceCode); 219 this._unbindUISourceCode(/** @type {!Workspace.UISourceCode} */ (uiSourceC ode));
231 this._boundUISourceCodes.clear(); 220 this._boundUISourceCodes.clear();
232 console.assert(!this._uiSourceCodeToScriptFile.size); 221 console.assert(!this._uiSourceCodeToScriptFile.size);
233 } 222 }
234 223
224 /**
225 * @param {!Common.Event} event
226 */
227 _executionContextDestroyed(event) {
228 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
229 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t);
230 this._removeScripts(scripts);
231 }
232
233 /**
234 * @param {!Array<!SDK.Script>} scripts
235 */
236 _removeScripts(scripts) {
237 for (var script of scripts) {
238 if (!this._acceptedScripts.has(script))
239 continue;
240 this._acceptedScripts.delete(script);
241 var frameId = script[Bindings.ResourceScriptMapping._frameIdSymbol];
242 var project = this._workspaceProjects.get(
243 Bindings.ResourceScriptMapping.projectId(this._debuggerModel.target(), frameId, script.isContentScript()));
244 var uiSourceCode = project.uiSourceCodeForURL(script.contentURL());
245 this._unbindUISourceCode(/** @type {!Workspace.UISourceCode} */ (uiSourceC ode));
246 project.removeFile(script.contentURL());
247 }
248 }
249
250 _resetForTest() {
251 for (var project of this._workspaceProjects.values())
252 project.removeProject();
253 this._workspaceProjects.clear();
254 }
255
235 dispose() { 256 dispose() {
236 Common.EventTarget.removeEventListeners(this._eventListeners); 257 Common.EventTarget.removeEventListeners(this._eventListeners);
237 this._debuggerReset(); 258 this._debuggerReset();
259 for (var project of this._workspaceProjects.values())
260 project.removeProject();
261 this._workspaceProjects.clear();
238 } 262 }
239 }; 263 };
240 264
241 /** 265 /**
242 * @unrestricted 266 * @unrestricted
243 */ 267 */
244 Bindings.ResourceScriptFile = class extends Common.Object { 268 Bindings.ResourceScriptFile = class extends Common.Object {
245 /** 269 /**
246 * @param {!Bindings.ResourceScriptMapping} resourceScriptMapping 270 * @param {!Bindings.ResourceScriptMapping} resourceScriptMapping
247 * @param {!Workspace.UISourceCode} uiSourceCode 271 * @param {!Workspace.UISourceCode} uiSourceCode
248 * @param {!Array.<!SDK.Script>} scripts 272 * @param {!SDK.Script} script
249 */ 273 */
250 constructor(resourceScriptMapping, uiSourceCode, scripts) { 274 constructor(resourceScriptMapping, uiSourceCode, script) {
251 super(); 275 super();
252 console.assert(scripts.length);
253
254 this._resourceScriptMapping = resourceScriptMapping; 276 this._resourceScriptMapping = resourceScriptMapping;
255 this._uiSourceCode = uiSourceCode; 277 this._uiSourceCode = uiSourceCode;
256 278 this._script = script;
257 if (this._uiSourceCode.contentType().isScript())
258 this._script = scripts[scripts.length - 1];
259 279
260 this._uiSourceCode.addEventListener( 280 this._uiSourceCode.addEventListener(
261 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this); 281 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this);
262 this._uiSourceCode.addEventListener( 282 this._uiSourceCode.addEventListener(
263 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this); 283 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this);
264 } 284 }
265 285
266 /** 286 /**
267 * @param {!Array.<!SDK.Script>} scripts 287 * @param {!SDK.Script} script
268 * @return {boolean} 288 * @return {boolean}
269 */ 289 */
270 _hasScripts(scripts) { 290 _hasScript(script) {
271 return this._script && this._script === scripts[0]; 291 return this._script === script;
272 } 292 }
273 293
274 /** 294 /**
275 * @return {boolean} 295 * @return {boolean}
276 */ 296 */
277 _isDiverged() { 297 _isDiverged() {
278 if (this._uiSourceCode.isDirty()) 298 if (this._uiSourceCode.isDirty())
279 return true; 299 return true;
280 if (!this._script)
281 return false;
282 if (typeof this._scriptSource === 'undefined') 300 if (typeof this._scriptSource === 'undefined')
283 return false; 301 return false;
284 var workingCopy = this._uiSourceCode.workingCopy(); 302 var workingCopy = this._uiSourceCode.workingCopy();
285 if (!workingCopy) 303 if (!workingCopy)
286 return false; 304 return false;
287 305
288 // Match ignoring sourceURL. 306 // Match ignoring sourceURL.
289 if (!workingCopy.startsWith(this._scriptSource.trimRight())) 307 if (!workingCopy.startsWith(this._scriptSource.trimRight()))
290 return true; 308 return true;
291 var suffix = this._uiSourceCode.workingCopy().substr(this._scriptSource.leng th); 309 var suffix = this._uiSourceCode.workingCopy().substr(this._scriptSource.leng th);
292 return !!suffix.length && !suffix.match(SDK.Script.sourceURLRegex); 310 return !!suffix.length && !suffix.match(SDK.Script.sourceURLRegex);
293 } 311 }
294 312
295 /** 313 /**
296 * @param {!Common.Event} event 314 * @param {!Common.Event} event
297 */ 315 */
298 _workingCopyChanged(event) { 316 _workingCopyChanged(event) {
299 this._update(); 317 this._update();
300 } 318 }
301 319
302 /** 320 /**
303 * @param {!Common.Event} event 321 * @param {!Common.Event} event
304 */ 322 */
305 _workingCopyCommitted(event) { 323 _workingCopyCommitted(event) {
306 if (this._uiSourceCode.project().canSetFileContent()) 324 if (this._uiSourceCode.project().canSetFileContent())
307 return; 325 return;
308 if (!this._script)
309 return;
310 var debuggerModel = this._resourceScriptMapping._debuggerModel; 326 var debuggerModel = this._resourceScriptMapping._debuggerModel;
311 var source = this._uiSourceCode.workingCopy(); 327 var source = this._uiSourceCode.workingCopy();
312 debuggerModel.setScriptSource(this._script.scriptId, source, scriptSourceWas Set.bind(this)); 328 debuggerModel.setScriptSource(this._script.scriptId, source, scriptSourceWas Set.bind(this));
313 329
314 /** 330 /**
315 * @param {?string} error 331 * @param {?string} error
316 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails 332 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
317 * @this {Bindings.ResourceScriptFile} 333 * @this {Bindings.ResourceScriptFile}
318 */ 334 */
319 function scriptSourceWasSet(error, exceptionDetails) { 335 function scriptSourceWasSet(error, exceptionDetails) {
(...skipping 16 matching lines...) Expand all
336 352
337 _update() { 353 _update() {
338 if (this._isDiverged() && !this._hasDivergedFromVM) 354 if (this._isDiverged() && !this._hasDivergedFromVM)
339 this._divergeFromVM(); 355 this._divergeFromVM();
340 else if (!this._isDiverged() && this._hasDivergedFromVM) 356 else if (!this._isDiverged() && this._hasDivergedFromVM)
341 this._mergeToVM(); 357 this._mergeToVM();
342 } 358 }
343 359
344 _divergeFromVM() { 360 _divergeFromVM() {
345 this._isDivergingFromVM = true; 361 this._isDivergingFromVM = true;
346 this._resourceScriptMapping._updateLocations(this._uiSourceCode); 362 this._resourceScriptMapping._updateLocations(this._script);
347 delete this._isDivergingFromVM; 363 delete this._isDivergingFromVM;
348 this._hasDivergedFromVM = true; 364 this._hasDivergedFromVM = true;
349 this.dispatchEventToListeners(Bindings.ResourceScriptFile.Events.DidDivergeF romVM, this._uiSourceCode); 365 this.dispatchEventToListeners(Bindings.ResourceScriptFile.Events.DidDivergeF romVM, this._uiSourceCode);
350 } 366 }
351 367
352 _mergeToVM() { 368 _mergeToVM() {
353 delete this._hasDivergedFromVM; 369 delete this._hasDivergedFromVM;
354 this._isMergingToVM = true; 370 this._isMergingToVM = true;
355 this._resourceScriptMapping._updateLocations(this._uiSourceCode); 371 this._resourceScriptMapping._updateLocations(this._script);
356 delete this._isMergingToVM; 372 delete this._isMergingToVM;
357 this.dispatchEventToListeners(Bindings.ResourceScriptFile.Events.DidMergeToV M, this._uiSourceCode); 373 this.dispatchEventToListeners(Bindings.ResourceScriptFile.Events.DidMergeToV M, this._uiSourceCode);
358 } 374 }
359 375
360 /** 376 /**
361 * @return {boolean} 377 * @return {boolean}
362 */ 378 */
363 hasDivergedFromVM() { 379 hasDivergedFromVM() {
364 return this._hasDivergedFromVM; 380 return this._hasDivergedFromVM;
365 } 381 }
366 382
367 /** 383 /**
368 * @return {boolean} 384 * @return {boolean}
369 */ 385 */
370 isDivergingFromVM() { 386 isDivergingFromVM() {
371 return this._isDivergingFromVM; 387 return this._isDivergingFromVM;
372 } 388 }
373 389
374 /** 390 /**
375 * @return {boolean} 391 * @return {boolean}
376 */ 392 */
377 isMergingToVM() { 393 isMergingToVM() {
378 return this._isMergingToVM; 394 return this._isMergingToVM;
379 } 395 }
380 396
381 checkMapping() { 397 checkMapping() {
382 if (!this._script || typeof this._scriptSource !== 'undefined') { 398 if (typeof this._scriptSource !== 'undefined') {
383 this._mappingCheckedForTest(); 399 this._mappingCheckedForTest();
384 return; 400 return;
385 } 401 }
386 this._script.requestContent().then(callback.bind(this)); 402 this._script.requestContent().then(callback.bind(this));
387 403
388 /** 404 /**
389 * @param {?string} source 405 * @param {?string} source
390 * @this {Bindings.ResourceScriptFile} 406 * @this {Bindings.ResourceScriptFile}
391 */ 407 */
392 function callback(source) { 408 function callback(source) {
(...skipping 10 matching lines...) Expand all
403 this._uiSourceCode.removeEventListener( 419 this._uiSourceCode.removeEventListener(
404 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this); 420 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this);
405 this._uiSourceCode.removeEventListener( 421 this._uiSourceCode.removeEventListener(
406 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this); 422 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this);
407 } 423 }
408 424
409 /** 425 /**
410 * @param {string} sourceMapURL 426 * @param {string} sourceMapURL
411 */ 427 */
412 addSourceMapURL(sourceMapURL) { 428 addSourceMapURL(sourceMapURL) {
413 if (!this._script)
414 return;
415 this._script.debuggerModel.setSourceMapURL(this._script, sourceMapURL); 429 this._script.debuggerModel.setSourceMapURL(this._script, sourceMapURL);
416 } 430 }
417 431
418 /** 432 /**
419 * @return {boolean} 433 * @return {boolean}
420 */ 434 */
421 hasSourceMapURL() { 435 hasSourceMapURL() {
422 return this._script && !!this._script.sourceMapURL; 436 return !!this._script.sourceMapURL;
423 } 437 }
424 }; 438 };
425 439
426 /** @enum {symbol} */ 440 /** @enum {symbol} */
427 Bindings.ResourceScriptFile.Events = { 441 Bindings.ResourceScriptFile.Events = {
428 DidMergeToVM: Symbol('DidMergeToVM'), 442 DidMergeToVM: Symbol('DidMergeToVM'),
429 DidDivergeFromVM: Symbol('DidDivergeFromVM'), 443 DidDivergeFromVM: Symbol('DidDivergeFromVM'),
430 }; 444 };
445
446 Bindings.ResourceScriptMapping._frameIdSymbol = Symbol('frameid');
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698