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

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

Issue 2893523002: DevTools: make StyleSourceMapping in charge of managing UISourceCodes (Closed)
Patch Set: address comments Created 3 years, 6 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
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 29 matching lines...) Expand all
40 super(); 40 super();
41 this._workspace = workspace; 41 this._workspace = workspace;
42 targetManager.observeTargets(this); 42 targetManager.observeTargets(this);
43 } 43 }
44 44
45 /** 45 /**
46 * @override 46 * @override
47 * @param {!SDK.Target} target 47 * @param {!SDK.Target} target
48 */ 48 */
49 targetAdded(target) { 49 targetAdded(target) {
50 new Bindings.NetworkProject(target, this._workspace, target.model(SDK.Resour ceTreeModel)); 50 new Bindings.NetworkProject(target, this._workspace);
51 } 51 }
52 52
53 /** 53 /**
54 * @override 54 * @override
55 * @param {!SDK.Target} target 55 * @param {!SDK.Target} target
56 */ 56 */
57 targetRemoved(target) { 57 targetRemoved(target) {
58 Bindings.NetworkProject.forTarget(target)._dispose(); 58 Bindings.NetworkProject.forTarget(target)._dispose();
59 } 59 }
60 }; 60 };
61 61
62 Bindings.NetworkProjectManager.Events = { 62 Bindings.NetworkProjectManager.Events = {
63 FrameAttributionAdded: Symbol('FrameAttributionAdded'), 63 FrameAttributionAdded: Symbol('FrameAttributionAdded'),
64 FrameAttributionRemoved: Symbol('FrameAttributionRemoved') 64 FrameAttributionRemoved: Symbol('FrameAttributionRemoved')
65 }; 65 };
66 66
67 /** 67 /**
68 * @unrestricted 68 * @unrestricted
69 */ 69 */
70 Bindings.NetworkProject = class { 70 Bindings.NetworkProject = class {
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
75 */ 74 */
76 constructor(target, workspace, resourceTreeModel) { 75 constructor(target, workspace) {
77 this._target = target; 76 this._target = target;
78 this._workspace = workspace; 77 this._workspace = workspace;
79 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */ 78 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */
80 this._workspaceProjects = new Map(); 79 this._workspaceProjects = new Map();
81 this._resourceTreeModel = resourceTreeModel;
82 target[Bindings.NetworkProject._networkProjectSymbol] = this; 80 target[Bindings.NetworkProject._networkProjectSymbol] = this;
83 81
84 this._eventListeners = []; 82 this._eventListeners = [];
85 83
86 this._debuggerModel = target.model(SDK.DebuggerModel); 84 this._debuggerModel = target.model(SDK.DebuggerModel);
87 /** @type {!Set<!SDK.Script>} */ 85 /** @type {!Set<!SDK.Script>} */
88 this._acceptedScripts = new Set(); 86 this._acceptedScripts = new Set();
89 if (this._debuggerModel) { 87 if (this._debuggerModel) {
90 var runtimeModel = this._debuggerModel.runtimeModel(); 88 var runtimeModel = this._debuggerModel.runtimeModel();
91 this._eventListeners.push( 89 this._eventListeners.push(
92 runtimeModel.addEventListener( 90 runtimeModel.addEventListener(
93 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this), 91 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this),
94 this._debuggerModel.addEventListener( 92 this._debuggerModel.addEventListener(
95 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl eared, this), 93 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl eared, this),
96 this._debuggerModel.addEventListener( 94 this._debuggerModel.addEventListener(
97 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this), 95 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this),
98 this._debuggerModel.addEventListener( 96 this._debuggerModel.addEventListener(
99 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); 97 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this));
100 } 98 }
101 var cssModel = target.model(SDK.CSSModel);
102 if (cssModel) {
103 this._eventListeners.push(
104 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this),
105 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this));
106 }
107 } 99 }
108 100
109 /** 101 /**
110 * @param {!SDK.Target} target 102 * @param {!SDK.Target} target
111 * @param {string} frameId 103 * @param {string} frameId
112 * @param {boolean} isContentScripts 104 * @param {boolean} isContentScripts
113 * @return {string} 105 * @return {string}
114 */ 106 */
115 static projectId(target, frameId, isContentScripts) { 107 static projectId(target, frameId, isContentScripts) {
116 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : ''); 108 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : '');
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 */ 271 */
280 _parsedScriptSource(event) { 272 _parsedScriptSource(event) {
281 var script = /** @type {!SDK.Script} */ (event.data); 273 var script = /** @type {!SDK.Script} */ (event.data);
282 if (!this._acceptsScript(script)) 274 if (!this._acceptsScript(script))
283 return; 275 return;
284 this._acceptedScripts.add(script); 276 this._acceptedScripts.add(script);
285 var originalContentProvider = script.originalContentProvider(); 277 var originalContentProvider = script.originalContentProvider();
286 var frameId = Bindings.frameIdForScript(script); 278 var frameId = Bindings.frameIdForScript(script);
287 script[Bindings.NetworkProject._frameIdSymbol] = frameId; 279 script[Bindings.NetworkProject._frameIdSymbol] = frameId;
288 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript()); 280 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript());
289 var metadata = this._fetchMetadata(frameId, uiSourceCode.url()); 281 var metadata = Bindings.metadataForURL(this._target, frameId, uiSourceCode.u rl());
290 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata, 'text/javascript'); 282 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata, 'text/javascript');
291 } 283 }
292 284
293 /** 285 /**
294 * @param {!Common.Event} event 286 * @param {!Common.Event} event
295 */ 287 */
296 _executionContextDestroyed(event) { 288 _executionContextDestroyed(event) {
297 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 289 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
298 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t); 290 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t);
299 this._removeScripts(scripts); 291 this._removeScripts(scripts);
(...skipping 13 matching lines...) Expand all
313 } 305 }
314 306
315 /** 307 /**
316 * @param {!Common.Event} event 308 * @param {!Common.Event} event
317 */ 309 */
318 _globalObjectCleared(event) { 310 _globalObjectCleared(event) {
319 this._removeScripts(Array.from(this._acceptedScripts)); 311 this._removeScripts(Array.from(this._acceptedScripts));
320 } 312 }
321 313
322 /** 314 /**
323 * @param {!SDK.CSSStyleSheetHeader} header
324 */
325 _acceptsHeader(header) {
326 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' )
327 return false;
328 if (!header.resourceURL())
329 return false;
330 return true;
331 }
332
333 /**
334 * @param {!Common.Event} event
335 */
336 _styleSheetAdded(event) {
337 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
338 if (!this._acceptsHeader(header))
339 return;
340
341 var originalContentProvider = header.originalContentProvider();
342 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false);
343 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header;
344 var metadata = this._fetchMetadata(header.frameId, uiSourceCode.url());
345 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata, 'text/css');
346 }
347
348 /**
349 * @param {!Common.Event} event
350 */
351 _styleSheetRemoved(event) {
352 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
353 if (!this._acceptsHeader(header))
354 return;
355 this._removeFileForURL(header.resourceURL(), header.frameId, false);
356 }
357
358 /**
359 * @param {!Common.ContentProvider} contentProvider 315 * @param {!Common.ContentProvider} contentProvider
360 * @param {string} frameId 316 * @param {string} frameId
361 * @param {boolean} isContentScript 317 * @param {boolean} isContentScript
362 * @return {!Workspace.UISourceCode} 318 * @return {!Workspace.UISourceCode}
363 */ 319 */
364 _createFile(contentProvider, frameId, isContentScript) { 320 _createFile(contentProvider, frameId, isContentScript) {
365 var url = contentProvider.contentURL(); 321 var url = contentProvider.contentURL();
366 var project = this._workspaceProject(frameId, isContentScript); 322 var project = this._workspaceProject(frameId, isContentScript);
367 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); 323 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe());
368 if (frameId) 324 if (frameId)
369 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId); 325 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId);
370 return uiSourceCode; 326 return uiSourceCode;
371 } 327 }
372 328
373 /**
374 * @param {string} frameId
375 * @param {string} url
376 * @return {?Workspace.UISourceCodeMetadata}
377 */
378 _fetchMetadata(frameId, url) {
379 if (!this._resourceTreeModel)
380 return null;
381 var frame = this._resourceTreeModel.frameForId(frameId);
382 if (!frame)
383 return null;
384 return Bindings.resourceMetadata(frame.resourceForURL(url));
385 }
386
387 _dispose() { 329 _dispose() {
388 for (var project of this._workspaceProjects.values()) 330 for (var project of this._workspaceProjects.values())
389 project.removeProject(); 331 project.removeProject();
390 Common.EventTarget.removeEventListeners(this._eventListeners); 332 Common.EventTarget.removeEventListeners(this._eventListeners);
391 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; 333 delete this._target[Bindings.NetworkProject._networkProjectSymbol];
392 this._workspaceProjects.clear(); 334 this._workspaceProjects.clear();
393 } 335 }
394 336
395 _resetForTest() { 337 _resetForTest() {
396 for (var project of this._workspaceProjects.values()) 338 for (var project of this._workspaceProjects.values())
397 project.removeProject(); 339 project.removeProject();
398 this._workspaceProjects.clear(); 340 this._workspaceProjects.clear();
399 } 341 }
400 342
401 /** 343 /**
402 * @param {!Workspace.Workspace} workspace 344 * @param {!Workspace.Workspace} workspace
403 * @param {string} url 345 * @param {string} url
404 * @param {!SDK.Script} script 346 * @param {!SDK.Script} script
405 * @return {?Workspace.UISourceCode} 347 * @return {?Workspace.UISourceCode}
406 */ 348 */
407 static uiSourceCodeForScriptURL(workspace, url, script) { 349 static uiSourceCodeForScriptURL(workspace, url, script) {
408 var target = script.debuggerModel.target(); 350 var target = script.debuggerModel.target();
409 var executionContext = script.executionContext(); 351 var executionContext = script.executionContext();
410 var frameId = executionContext ? executionContext.frameId || '' : ''; 352 var frameId = executionContext ? executionContext.frameId || '' : '';
411 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram eId, false), url) || 353 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram eId, false), url) ||
412 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frameId , true), url); 354 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frameId , true), url);
413 } 355 }
414
415 /**
416 * @param {!Workspace.Workspace} workspace
417 * @param {string} url
418 * @param {!SDK.CSSStyleSheetHeader} header
419 * @return {?Workspace.UISourceCode}
420 */
421 static uiSourceCodeForStyleURL(workspace, url, header) {
422 return workspace.uiSourceCode(
423 Bindings.NetworkProject.projectId(header.cssModel().target(), header.fra meId, false), url);
424 }
425
426 /**
427 * @param {!Workspace.UISourceCode} uiSourceCode
428 * @return {?SDK.CSSStyleSheetHeader}
429 */
430 static styleHeaderForUISourceCode(uiSourceCode) {
431 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol];
432 }
433 }; 356 };
434 357
435 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); 358 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject');
436 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet');
437 Bindings.NetworkProject._targetSymbol = Symbol('target'); 359 Bindings.NetworkProject._targetSymbol = Symbol('target');
438 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); 360 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid');
439 361
440 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); 362 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698