OLD | NEW |
---|---|
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 /** | 71 /** |
72 * @param {!SDK.Target} target | 72 * @param {!SDK.Target} target |
73 * @param {!Workspace.Workspace} workspace | 73 * @param {!Workspace.Workspace} workspace |
74 * @param {?SDK.ResourceTreeModel} resourceTreeModel | 74 * @param {?SDK.ResourceTreeModel} resourceTreeModel |
75 */ | 75 */ |
76 constructor(target, workspace, resourceTreeModel) { | 76 constructor(target, workspace, resourceTreeModel) { |
77 this._target = target; | 77 this._target = target; |
78 this._workspace = workspace; | 78 this._workspace = workspace; |
79 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */ | 79 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */ |
80 this._workspaceProjects = new Map(); | 80 this._workspaceProjects = new Map(); |
81 this._resourceTreeModel = resourceTreeModel; | |
82 target[Bindings.NetworkProject._networkProjectSymbol] = this; | 81 target[Bindings.NetworkProject._networkProjectSymbol] = this; |
83 | 82 |
84 this._eventListeners = []; | 83 this._eventListeners = []; |
85 | 84 |
86 if (resourceTreeModel) { | 85 if (resourceTreeModel) { |
87 this._eventListeners.push( | 86 this._eventListeners.push( |
88 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Resour ceAdded, this._resourceAdded, this), | 87 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Resour ceAdded, this._resourceAdded, this), |
89 resourceTreeModel.addEventListener( | 88 resourceTreeModel.addEventListener( |
90 SDK.ResourceTreeModel.Events.FrameWillNavigate, this._frameWillNav igate, this), | 89 SDK.ResourceTreeModel.Events.FrameWillNavigate, this._frameWillNav igate, this), |
91 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameD etached, this._frameDetached, this)); | 90 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameD etached, this._frameDetached, this)); |
92 } | 91 } |
93 | 92 |
94 this._debuggerModel = target.model(SDK.DebuggerModel); | 93 this._debuggerModel = target.model(SDK.DebuggerModel); |
95 /** @type {!Set<!SDK.Script>} */ | 94 /** @type {!Set<!SDK.Script>} */ |
96 this._acceptedScripts = new Set(); | 95 this._acceptedScripts = new Set(); |
97 if (this._debuggerModel) { | 96 if (this._debuggerModel) { |
98 var runtimeModel = this._debuggerModel.runtimeModel(); | 97 var runtimeModel = this._debuggerModel.runtimeModel(); |
99 this._eventListeners.push( | 98 this._eventListeners.push( |
100 runtimeModel.addEventListener( | 99 runtimeModel.addEventListener( |
101 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this), | 100 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this), |
102 this._debuggerModel.addEventListener( | 101 this._debuggerModel.addEventListener( |
103 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl eared, this), | 102 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl eared, this), |
104 this._debuggerModel.addEventListener( | 103 this._debuggerModel.addEventListener( |
105 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this), | 104 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this), |
106 this._debuggerModel.addEventListener( | 105 this._debuggerModel.addEventListener( |
107 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); | 106 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); |
108 } | 107 } |
109 var cssModel = target.model(SDK.CSSModel); | |
110 if (cssModel) { | |
111 this._eventListeners.push( | |
112 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this), | |
113 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this)); | |
114 } | |
115 } | 108 } |
116 | 109 |
117 /** | 110 /** |
118 * @param {!SDK.Target} target | 111 * @param {!SDK.Target} target |
119 * @param {string} frameId | 112 * @param {string} frameId |
120 * @param {boolean} isContentScripts | 113 * @param {boolean} isContentScripts |
121 * @return {string} | 114 * @return {string} |
122 */ | 115 */ |
123 static projectId(target, frameId, isContentScripts) { | 116 static projectId(target, frameId, isContentScripts) { |
124 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : ''); | 117 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : ''); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); | 210 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); |
218 var attribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymb ol]; | 211 var attribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymb ol]; |
219 if (!resourceTreeModel || !attribution) | 212 if (!resourceTreeModel || !attribution) |
220 return []; | 213 return []; |
221 var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel .frameForId(frameId)); | 214 var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel .frameForId(frameId)); |
222 return frames.filter(frame => !!frame); | 215 return frames.filter(frame => !!frame); |
223 } | 216 } |
224 | 217 |
225 /** | 218 /** |
226 * @param {!Workspace.UISourceCode} uiSourceCode | 219 * @param {!Workspace.UISourceCode} uiSourceCode |
220 */ | |
221 static forceCanonicalMimeType(uiSourceCode) { | |
222 uiSourceCode[Bindings.NetworkProject._forceCanonicalMimeType] = true; | |
dgozman
2017/05/17 16:46:20
I feel like we should incorporate mime type into m
lushnikov
2017/05/20 01:24:18
Done - here: https://codereview.chromium.org/28890
| |
223 } | |
224 | |
225 /** | |
226 * @param {!Workspace.UISourceCode} uiSourceCode | |
227 * @return {string} | 227 * @return {string} |
228 */ | 228 */ |
229 static uiSourceCodeMimeType(uiSourceCode) { | 229 static uiSourceCodeMimeType(uiSourceCode) { |
230 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol]) | 230 if (uiSourceCode[Bindings.NetworkProject._forceCanonicalMimeType]) |
231 return uiSourceCode.contentType().canonicalMimeType(); | 231 return uiSourceCode.contentType().canonicalMimeType(); |
232 | 232 |
233 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol]; | 233 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol]; |
234 if (resource) | 234 if (resource) |
235 return resource.mimeType; | 235 return resource.mimeType; |
236 var mimeType = Common.ResourceType.mimeFromURL(uiSourceCode.url()); | 236 var mimeType = Common.ResourceType.mimeFromURL(uiSourceCode.url()); |
237 return mimeType || uiSourceCode.contentType().canonicalMimeType(); | 237 return mimeType || uiSourceCode.contentType().canonicalMimeType(); |
238 } | 238 } |
239 | 239 |
240 /** | 240 /** |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 */ | 301 */ |
302 _parsedScriptSource(event) { | 302 _parsedScriptSource(event) { |
303 var script = /** @type {!SDK.Script} */ (event.data); | 303 var script = /** @type {!SDK.Script} */ (event.data); |
304 if (!this._acceptsScript(script)) | 304 if (!this._acceptsScript(script)) |
305 return; | 305 return; |
306 this._acceptedScripts.add(script); | 306 this._acceptedScripts.add(script); |
307 var originalContentProvider = script.originalContentProvider(); | 307 var originalContentProvider = script.originalContentProvider(); |
308 var frameId = Bindings.frameIdForScript(script); | 308 var frameId = Bindings.frameIdForScript(script); |
309 script[Bindings.NetworkProject._frameIdSymbol] = frameId; | 309 script[Bindings.NetworkProject._frameIdSymbol] = frameId; |
310 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript()); | 310 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript()); |
311 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; | 311 Bindings.NetworkProject.forceCanonicalMimeType(uiSourceCode); |
312 var metadata = this._fetchMetadata(frameId, uiSourceCode.url()); | 312 var metadata = Bindings.metadataForURL(this._target, frameId, uiSourceCode.u rl()); |
313 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata); | 313 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata); |
314 } | 314 } |
315 | 315 |
316 /** | 316 /** |
317 * @param {!Common.Event} event | 317 * @param {!Common.Event} event |
318 */ | 318 */ |
319 _executionContextDestroyed(event) { | 319 _executionContextDestroyed(event) { |
320 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); | 320 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
321 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t); | 321 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t); |
322 this._removeScripts(scripts); | 322 this._removeScripts(scripts); |
(...skipping 13 matching lines...) Expand all Loading... | |
336 } | 336 } |
337 | 337 |
338 /** | 338 /** |
339 * @param {!Common.Event} event | 339 * @param {!Common.Event} event |
340 */ | 340 */ |
341 _globalObjectCleared(event) { | 341 _globalObjectCleared(event) { |
342 this._removeScripts(Array.from(this._acceptedScripts)); | 342 this._removeScripts(Array.from(this._acceptedScripts)); |
343 } | 343 } |
344 | 344 |
345 /** | 345 /** |
346 * @param {!SDK.CSSStyleSheetHeader} header | |
347 */ | |
348 _acceptsHeader(header) { | |
349 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' ) | |
350 return false; | |
351 if (!header.resourceURL()) | |
352 return false; | |
353 return true; | |
354 } | |
355 | |
356 /** | |
357 * @param {!Common.Event} event | |
358 */ | |
359 _styleSheetAdded(event) { | |
360 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | |
361 if (!this._acceptsHeader(header)) | |
362 return; | |
363 | |
364 var originalContentProvider = header.originalContentProvider(); | |
365 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false); | |
366 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; | |
367 var metadata = this._fetchMetadata(header.frameId, uiSourceCode.url()); | |
368 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata); | |
369 } | |
370 | |
371 /** | |
372 * @param {!Common.Event} event | |
373 */ | |
374 _styleSheetRemoved(event) { | |
375 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | |
376 if (!this._acceptsHeader(header)) | |
377 return; | |
378 this._removeFileForURL(header.resourceURL(), header.frameId, false); | |
379 } | |
380 | |
381 /** | |
382 * @param {!Common.Event} event | 346 * @param {!Common.Event} event |
383 */ | 347 */ |
384 _resourceAdded(event) { | 348 _resourceAdded(event) { |
385 var resource = /** @type {!SDK.Resource} */ (event.data); | 349 var resource = /** @type {!SDK.Resource} */ (event.data); |
386 this._addResource(resource); | 350 this._addResource(resource); |
387 } | 351 } |
388 | 352 |
389 /** | 353 /** |
390 * @param {!SDK.Resource} resource | 354 * @param {!SDK.Resource} resource |
391 */ | 355 */ |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 */ | 421 */ |
458 _createFile(contentProvider, frameId, isContentScript) { | 422 _createFile(contentProvider, frameId, isContentScript) { |
459 var url = contentProvider.contentURL(); | 423 var url = contentProvider.contentURL(); |
460 var project = this._workspaceProject(frameId, isContentScript); | 424 var project = this._workspaceProject(frameId, isContentScript); |
461 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); | 425 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); |
462 if (frameId) | 426 if (frameId) |
463 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId); | 427 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId); |
464 return uiSourceCode; | 428 return uiSourceCode; |
465 } | 429 } |
466 | 430 |
467 /** | |
468 * @param {string} frameId | |
469 * @param {string} url | |
470 * @return {?Workspace.UISourceCodeMetadata} | |
471 */ | |
472 _fetchMetadata(frameId, url) { | |
473 if (!this._resourceTreeModel) | |
474 return null; | |
475 var frame = this._resourceTreeModel.frameForId(frameId); | |
476 if (!frame) | |
477 return null; | |
478 return Bindings.resourceMetadata(frame.resourceForURL(url)); | |
479 } | |
480 | |
481 _dispose() { | 431 _dispose() { |
482 this._reset(); | 432 this._reset(); |
483 Common.EventTarget.removeEventListeners(this._eventListeners); | 433 Common.EventTarget.removeEventListeners(this._eventListeners); |
484 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; | 434 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; |
485 } | 435 } |
486 | 436 |
487 _reset() { | 437 _reset() { |
488 for (var project of this._workspaceProjects.values()) | 438 for (var project of this._workspaceProjects.values()) |
489 project.removeProject(); | 439 project.removeProject(); |
490 this._workspaceProjects.clear(); | 440 this._workspaceProjects.clear(); |
491 } | 441 } |
492 | 442 |
493 /** | 443 /** |
444 * @param {!SDK.Target} target | |
445 * @param {!Workspace.Workspace} workspace | |
446 * @param {string} url | |
447 * @param {string} frameId | |
448 * @return {?Workspace.UISourceCode} | |
449 */ | |
450 static uiSourceCodeForResourceURL(target, workspace, url, frameId) { | |
451 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram eId, false), url); | |
452 } | |
453 | |
454 /** | |
494 * @param {!Workspace.Workspace} workspace | 455 * @param {!Workspace.Workspace} workspace |
495 * @param {string} url | 456 * @param {string} url |
496 * @param {!SDK.Script} script | 457 * @param {!SDK.Script} script |
497 * @return {?Workspace.UISourceCode} | 458 * @return {?Workspace.UISourceCode} |
498 */ | 459 */ |
499 static uiSourceCodeForScriptURL(workspace, url, script) { | 460 static uiSourceCodeForScriptURL(workspace, url, script) { |
500 var target = script.debuggerModel.target(); | 461 var target = script.debuggerModel.target(); |
501 var executionContext = script.executionContext(); | 462 var executionContext = script.executionContext(); |
502 var frameId = executionContext ? executionContext.frameId || '' : ''; | 463 var frameId = executionContext ? executionContext.frameId || '' : ''; |
503 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram eId, false), url) || | 464 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram eId, false), url) || |
504 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frameId , true), url); | 465 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frameId , true), url); |
505 } | 466 } |
506 | |
507 /** | |
508 * @param {!Workspace.Workspace} workspace | |
509 * @param {string} url | |
510 * @param {!SDK.CSSStyleSheetHeader} header | |
511 * @return {?Workspace.UISourceCode} | |
512 */ | |
513 static uiSourceCodeForStyleURL(workspace, url, header) { | |
514 return workspace.uiSourceCode( | |
515 Bindings.NetworkProject.projectId(header.cssModel().target(), header.fra meId, false), url); | |
516 } | |
517 | |
518 /** | |
519 * @param {!Workspace.UISourceCode} uiSourceCode | |
520 * @return {?SDK.CSSStyleSheetHeader} | |
521 */ | |
522 static styleHeaderForUISourceCode(uiSourceCode) { | |
523 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol]; | |
524 } | |
525 }; | 467 }; |
526 | 468 |
527 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 469 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
528 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 470 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
529 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 471 Bindings.NetworkProject._forceCanonicalMimeType = Symbol('Bindings.NetworkProjec t._forceCanonicalMimeType'); |
530 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | |
531 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 472 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
532 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); | 473 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); |
533 | 474 |
534 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); | 475 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); |
OLD | NEW |