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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/NavigatorView.js

Issue 2869293002: DevTools: make CompilerScriptMapping / SASSSourceMapping manage UISourceCodes (Closed)
Patch Set: use {add,remove}FrameAttribution instead of changeFrameAttribution Created 3 years, 7 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 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 10 *
(...skipping 22 matching lines...) Expand all
33 constructor() { 33 constructor() {
34 super(); 34 super();
35 this.registerRequiredCSS('sources/navigatorView.css'); 35 this.registerRequiredCSS('sources/navigatorView.css');
36 36
37 this._scriptsTree = new UI.TreeOutlineInShadow(); 37 this._scriptsTree = new UI.TreeOutlineInShadow();
38 this._scriptsTree.registerRequiredCSS('sources/navigatorTree.css'); 38 this._scriptsTree.registerRequiredCSS('sources/navigatorTree.css');
39 this._scriptsTree.setComparator(Sources.NavigatorView._treeElementsCompare); 39 this._scriptsTree.setComparator(Sources.NavigatorView._treeElementsCompare);
40 this.element.appendChild(this._scriptsTree.element); 40 this.element.appendChild(this._scriptsTree.element);
41 this.setDefaultFocusedElement(this._scriptsTree.element); 41 this.setDefaultFocusedElement(this._scriptsTree.element);
42 42
43 /** @type {!Map.<!Workspace.UISourceCode, !Array<!Sources.NavigatorUISourceC odeTreeNode>>} */ 43 /** @type {!Multimap<!Workspace.UISourceCode, !Sources.NavigatorUISourceCode TreeNode>} */
44 this._uiSourceCodeNodes = new Map(); 44 this._uiSourceCodeNodes = new Multimap();
45 /** @type {!Map.<string, !Sources.NavigatorFolderTreeNode>} */ 45 /** @type {!Map.<string, !Sources.NavigatorFolderTreeNode>} */
46 this._subfolderNodes = new Map(); 46 this._subfolderNodes = new Map();
47 47
48 this._rootNode = new Sources.NavigatorRootTreeNode(this); 48 this._rootNode = new Sources.NavigatorRootTreeNode(this);
49 this._rootNode.populate(); 49 this._rootNode.populate();
50 50
51 /** @type {!Map.<!SDK.ResourceTreeFrame, !Sources.NavigatorGroupTreeNode>} * / 51 /** @type {!Map.<!SDK.ResourceTreeFrame, !Sources.NavigatorGroupTreeNode>} * /
52 this._frameNodes = new Map(); 52 this._frameNodes = new Map();
53 53
54 this.element.addEventListener('contextmenu', this.handleContextMenu.bind(thi s), false); 54 this.element.addEventListener('contextmenu', this.handleContextMenu.bind(thi s), false);
(...skipping 12 matching lines...) Expand all
67 Persistence.persistence.addEventListener( 67 Persistence.persistence.addEventListener(
68 Persistence.Persistence.Events.BindingCreated, this._onBindingCreated, this); 68 Persistence.Persistence.Events.BindingCreated, this._onBindingCreated, this);
69 Persistence.persistence.addEventListener( 69 Persistence.persistence.addEventListener(
70 Persistence.Persistence.Events.BindingRemoved, this._onBindingRemoved, this); 70 Persistence.Persistence.Events.BindingRemoved, this._onBindingRemoved, this);
71 } 71 }
72 SDK.targetManager.addEventListener(SDK.TargetManager.Events.NameChanged, thi s._targetNameChanged, this); 72 SDK.targetManager.addEventListener(SDK.TargetManager.Events.NameChanged, thi s._targetNameChanged, this);
73 73
74 SDK.targetManager.observeTargets(this); 74 SDK.targetManager.observeTargets(this);
75 this._resetWorkspace(Workspace.workspace); 75 this._resetWorkspace(Workspace.workspace);
76 this._workspace.uiSourceCodes().forEach(this._addUISourceCode.bind(this)); 76 this._workspace.uiSourceCodes().forEach(this._addUISourceCode.bind(this));
77 Bindings.networkProjectManager.addEventListener(
78 Bindings.NetworkProjectManager.Events.FrameAttributionChanged, this._fra meAttributionChanged, this);
77 } 79 }
78 80
79 /** 81 /**
80 * @param {!UI.TreeElement} treeElement 82 * @param {!UI.TreeElement} treeElement
81 */ 83 */
82 static _treeElementOrder(treeElement) { 84 static _treeElementOrder(treeElement) {
83 if (treeElement._boostOrder) 85 if (treeElement._boostOrder)
84 return 0; 86 return 0;
85 87
86 if (!Sources.NavigatorView._typeOrders) { 88 if (!Sources.NavigatorView._typeOrders) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 this._addUISourceCode(binding.network); 177 this._addUISourceCode(binding.network);
176 } 178 }
177 179
178 /** 180 /**
179 * @param {!Common.Event} event 181 * @param {!Common.Event} event
180 */ 182 */
181 _onBindingChanged(event) { 183 _onBindingChanged(event) {
182 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); 184 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data);
183 185
184 // Update UISourceCode titles. 186 // Update UISourceCode titles.
185 var networkNodes = this._uiSourceCodeNodes.get(binding.network) || []; 187 var networkNodes = this._uiSourceCodeNodes.get(binding.network);
186 for (var networkNode of networkNodes) 188 for (var networkNode of networkNodes)
187 networkNode.updateTitle(); 189 networkNode.updateTitle();
188 var fileSystemNodes = this._uiSourceCodeNodes.get(binding.fileSystem) || []; 190 var fileSystemNodes = this._uiSourceCodeNodes.get(binding.fileSystem);
189 for (var fileSystemNode of fileSystemNodes) 191 for (var fileSystemNode of fileSystemNodes)
190 fileSystemNode.updateTitle(); 192 fileSystemNode.updateTitle();
191 193
192 // Update folder titles. 194 // Update folder titles.
193 var pathTokens = Persistence.FileSystemWorkspaceBinding.relativePath(binding .fileSystem); 195 var pathTokens = Persistence.FileSystemWorkspaceBinding.relativePath(binding .fileSystem);
194 var folderPath = ''; 196 var folderPath = '';
195 for (var i = 0; i < pathTokens.length - 1; ++i) { 197 for (var i = 0; i < pathTokens.length - 1; ++i) {
196 folderPath += pathTokens[i]; 198 folderPath += pathTokens[i];
197 var folderId = 199 var folderId =
198 this._folderNodeId(binding.fileSystem.project(), null, null, binding.f ileSystem.origin(), folderPath); 200 this._folderNodeId(binding.fileSystem.project(), null, null, binding.f ileSystem.origin(), folderPath);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 237
236 /** 238 /**
237 * @param {!Workspace.UISourceCode} uiSourceCode 239 * @param {!Workspace.UISourceCode} uiSourceCode
238 * @return {boolean} 240 * @return {boolean}
239 */ 241 */
240 accept(uiSourceCode) { 242 accept(uiSourceCode) {
241 return !uiSourceCode.project().isServiceProject(); 243 return !uiSourceCode.project().isServiceProject();
242 } 244 }
243 245
244 /** 246 /**
247 * @param {!Common.Event} event
248 */
249 _frameAttributionChanged(event) {
250 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data.uiSour ceCode);
251 var addedFrame = /** @type {?SDK.ResourceTreeFrame} */ (event.data.added);
252 var removedFrame = /** @type {?SDK.ResourceTreeFrame} */ (event.data.removed );
253 if (addedFrame)
254 this._addUISourceCodeNode(uiSourceCode, addedFrame);
255 if (removedFrame) {
256 var node = Array.from(this._uiSourceCodeNodes.get(uiSourceCode)).find(node => node.frame() === removedFrame);
dgozman 2017/05/11 23:55:16 Why Array.from? It's already an array.
lushnikov 2017/05/12 01:18:00 Nah, it's a set
257 this._removeUISourceCodeNode(node);
258 }
259 }
260
261 /**
245 * @param {!Workspace.UISourceCode} uiSourceCode 262 * @param {!Workspace.UISourceCode} uiSourceCode
246 */ 263 */
247 _addUISourceCode(uiSourceCode) { 264 _addUISourceCode(uiSourceCode) {
248 if (!this.accept(uiSourceCode)) 265 if (!this.accept(uiSourceCode))
249 return; 266 return;
250 267
251 var binding = Persistence.persistence.binding(uiSourceCode); 268 var binding = Persistence.persistence.binding(uiSourceCode);
252 if (!Runtime.experiments.isEnabled('persistence2') && binding && binding.net work === uiSourceCode) 269 if (!Runtime.experiments.isEnabled('persistence2') && binding && binding.net work === uiSourceCode)
253 return; 270 return;
254 271
272 var frames = Bindings.NetworkProject.framesForUISourceCode(uiSourceCode);
273 if (frames.length) {
274 for (var frame of frames)
275 this._addUISourceCodeNode(uiSourceCode, frame);
276 } else {
277 this._addUISourceCodeNode(uiSourceCode, null);
278 }
279 this.uiSourceCodeAdded(uiSourceCode);
280 }
281
282 /**
283 * @param {!Workspace.UISourceCode} uiSourceCode
284 * @param {?SDK.ResourceTreeFrame} frame
285 */
286 _addUISourceCodeNode(uiSourceCode, frame) {
255 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap(); 287 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap();
256 var path; 288 var path;
257 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) 289 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem)
258 path = Persistence.FileSystemWorkspaceBinding.relativePath(uiSourceCode).s lice(0, -1); 290 path = Persistence.FileSystemWorkspaceBinding.relativePath(uiSourceCode).s lice(0, -1);
259 else 291 else
260 path = Common.ParsedURL.extractPath(uiSourceCode.url()).split('/').slice(1 , -1); 292 path = Common.ParsedURL.extractPath(uiSourceCode.url()).split('/').slice(1 , -1);
261 293
262 var project = uiSourceCode.project(); 294 var project = uiSourceCode.project();
263 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); 295 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
264 var frames = Bindings.NetworkProject.framesForUISourceCode(uiSourceCode); 296 var folderNode =
265 var uiSourceCodeNodes = []; 297 this._folderNode(uiSourceCode, project, target, frame, uiSourceCode.orig in(), path, isFromSourceMap);
266 if (frames.length) { 298 var uiSourceCodeNode = new Sources.NavigatorUISourceCodeTreeNode(this, uiSou rceCode, frame);
267 for (var frame of frames) { 299 folderNode.appendChild(uiSourceCodeNode);
268 var folderNode = 300 this._uiSourceCodeNodes.set(uiSourceCode, uiSourceCodeNode);
269 this._folderNode(uiSourceCode, project, target, frame, uiSourceCode. origin(), path, isFromSourceMap);
270 var uiSourceCodeNode = new Sources.NavigatorUISourceCodeTreeNode(this, u iSourceCode, frame);
271 folderNode.appendChild(uiSourceCodeNode);
272 uiSourceCodeNodes.push(uiSourceCodeNode);
273 }
274 } else {
275 var folderNode =
276 this._folderNode(uiSourceCode, project, target, null, uiSourceCode.ori gin(), path, isFromSourceMap);
277 var uiSourceCodeNode = new Sources.NavigatorUISourceCodeTreeNode(this, uiS ourceCode, null);
278 folderNode.appendChild(uiSourceCodeNode);
279 uiSourceCodeNodes.push(uiSourceCodeNode);
280 }
281 this._uiSourceCodeNodes.set(uiSourceCode, uiSourceCodeNodes);
282 this.uiSourceCodeAdded(uiSourceCode);
283 } 301 }
284 302
285 /** 303 /**
286 * @param {!Workspace.UISourceCode} uiSourceCode 304 * @param {!Workspace.UISourceCode} uiSourceCode
287 */ 305 */
288 uiSourceCodeAdded(uiSourceCode) { 306 uiSourceCodeAdded(uiSourceCode) {
289 } 307 }
290 308
291 /** 309 /**
292 * @param {!Common.Event} event 310 * @param {!Common.Event} event
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 return (prettyURL || projectOrigin); 503 return (prettyURL || projectOrigin);
486 } 504 }
487 505
488 /** 506 /**
489 * @param {!Workspace.UISourceCode} uiSourceCode 507 * @param {!Workspace.UISourceCode} uiSourceCode
490 * @param {boolean=} select 508 * @param {boolean=} select
491 * @return {?Sources.NavigatorUISourceCodeTreeNode} 509 * @return {?Sources.NavigatorUISourceCodeTreeNode}
492 */ 510 */
493 revealUISourceCode(uiSourceCode, select) { 511 revealUISourceCode(uiSourceCode, select) {
494 var nodes = this._uiSourceCodeNodes.get(uiSourceCode); 512 var nodes = this._uiSourceCodeNodes.get(uiSourceCode);
495 if (!nodes) 513 var node = nodes.firstValue();
514 if (!node)
496 return null; 515 return null;
497 if (this._scriptsTree.selectedTreeElement) 516 if (this._scriptsTree.selectedTreeElement)
498 this._scriptsTree.selectedTreeElement.deselect(); 517 this._scriptsTree.selectedTreeElement.deselect();
499 this._lastSelectedUISourceCode = uiSourceCode; 518 this._lastSelectedUISourceCode = uiSourceCode;
500 // TODO(dgozman): figure out revealing multiple. 519 // TODO(dgozman): figure out revealing multiple.
501 nodes[0].reveal(select); 520 node.reveal(select);
502 return nodes[0]; 521 return node;
503 } 522 }
504 523
505 /** 524 /**
506 * @param {!Workspace.UISourceCode} uiSourceCode 525 * @param {!Workspace.UISourceCode} uiSourceCode
507 * @param {boolean} focusSource 526 * @param {boolean} focusSource
508 */ 527 */
509 _sourceSelected(uiSourceCode, focusSource) { 528 _sourceSelected(uiSourceCode, focusSource) {
510 this._lastSelectedUISourceCode = uiSourceCode; 529 this._lastSelectedUISourceCode = uiSourceCode;
511 Common.Revealer.reveal(uiSourceCode, !focusSource); 530 Common.Revealer.reveal(uiSourceCode, !focusSource);
512 } 531 }
513 532
514 /** 533 /**
515 * @param {!Workspace.UISourceCode} uiSourceCode 534 * @param {!Workspace.UISourceCode} uiSourceCode
516 */ 535 */
517 sourceDeleted(uiSourceCode) { 536 sourceDeleted(uiSourceCode) {
518 } 537 }
519 538
539
dgozman 2017/05/11 23:55:16 nit: extra blank line
lushnikov 2017/05/12 01:18:00 Done.
520 /** 540 /**
521 * @param {!Workspace.UISourceCode} uiSourceCode 541 * @param {!Workspace.UISourceCode} uiSourceCode
522 */ 542 */
523 _removeUISourceCode(uiSourceCode) { 543 _removeUISourceCode(uiSourceCode) {
524 var nodes = this._uiSourceCodeNodes.get(uiSourceCode) || []; 544 var nodes = this._uiSourceCodeNodes.get(uiSourceCode);
525 for (var i = 0; i < nodes.length; i++) { 545 for (var node of nodes)
526 var node = nodes[i]; 546 this._removeUISourceCodeNode(node);
547 }
527 548
528 var project = uiSourceCode.project(); 549 /**
529 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); 550 * @param {!Sources.NavigatorUISourceCodeTreeNode} node
530 var frame = node.frame(); 551 */
552 _removeUISourceCodeNode(node) {
553 var uiSourceCode = node.uiSourceCode();
554 this._uiSourceCodeNodes.remove(uiSourceCode, node);
dgozman 2017/05/11 23:55:16 You mutate the same collection in line 545. That's
lushnikov 2017/05/12 01:18:00 That's ok for sets (we have set here): http://stac
555 var project = uiSourceCode.project();
556 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
557 var frame = node.frame();
531 558
532 var parentNode = node.parent; 559 var parentNode = node.parent;
560 parentNode.removeChild(node);
561 node = parentNode;
562
563 while (node) {
564 parentNode = node.parent;
565 if (!parentNode || !node.isEmpty())
566 break;
567 if (!(node instanceof Sources.NavigatorGroupTreeNode || node instanceof So urces.NavigatorFolderTreeNode))
568 break;
569 if (node._type === Sources.NavigatorView.Types.Frame) {
570 this._discardFrame(/** @type {!SDK.ResourceTreeFrame} */ (frame));
571 break;
572 }
573
574 var folderId = this._folderNodeId(project, target, frame, uiSourceCode.ori gin(), node._folderPath);
575 this._subfolderNodes.delete(folderId);
533 parentNode.removeChild(node); 576 parentNode.removeChild(node);
534 node = parentNode; 577 node = parentNode;
535
536 while (node) {
537 parentNode = node.parent;
538 if (!parentNode || !node.isEmpty())
539 break;
540 if (!(node instanceof Sources.NavigatorGroupTreeNode || node instanceof Sources.NavigatorFolderTreeNode))
541 break;
542 if (node._type === Sources.NavigatorView.Types.Frame) {
543 this._discardFrame(/** @type {!SDK.ResourceTreeFrame} */ (frame));
544 break;
545 }
546
547 var folderId = this._folderNodeId(project, target, frame, uiSourceCode.o rigin(), node._folderPath);
548 this._subfolderNodes.delete(folderId);
549 parentNode.removeChild(node);
550 node = parentNode;
551 }
552 } 578 }
553 this._uiSourceCodeNodes.delete(uiSourceCode);
554 } 579 }
555 580
556 reset() { 581 reset() {
557 for (var entry of this._uiSourceCodeNodes) { 582 for (var node of this._uiSourceCodeNodes.valuesArray())
558 var nodes = /** @type {!Array<!Sources.NavigatorUISourceCodeTreeNode>} */ (entry[1]); 583 node.dispose();
559 for (var i = 0; i < nodes.length; i++)
560 nodes[i].dispose();
561 }
562 584
563 this._scriptsTree.removeChildren(); 585 this._scriptsTree.removeChildren();
564 this._uiSourceCodeNodes.clear(); 586 this._uiSourceCodeNodes.clear();
565 this._subfolderNodes.clear(); 587 this._subfolderNodes.clear();
566 this._frameNodes.clear(); 588 this._frameNodes.clear();
567 this._rootNode.reset(); 589 this._rootNode.reset();
568 } 590 }
569 591
570 /** 592 /**
571 * @param {!Event} event 593 * @param {!Event} event
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 /** 1617 /**
1596 * @param {string} title 1618 * @param {string} title
1597 * @override 1619 * @override
1598 */ 1620 */
1599 setTitle(title) { 1621 setTitle(title) {
1600 this._title = title; 1622 this._title = title;
1601 if (this._treeElement) 1623 if (this._treeElement)
1602 this._treeElement.title = this._title; 1624 this._treeElement.title = this._title;
1603 } 1625 }
1604 }; 1626 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698