Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 * @implements {WebInspector.TargetManager.Observer} | 8 * @implements {WebInspector.TargetManager.Observer} |
| 9 */ | 9 */ |
| 10 WebInspector.ThreadsSidebarPane = function() | 10 WebInspector.ThreadsSidebarPane = function() |
| 11 { | 11 { |
| 12 WebInspector.VBox.call(this); | 12 WebInspector.VBox.call(this); |
| 13 | 13 |
| 14 /** @type {!Map.<!WebInspector.DebuggerModel, !WebInspector.UIList.Item>} */ | 14 /** @type {!Map<!WebInspector.DebuggerModel, !WebInspector.UIList.Item>} */ |
| 15 this._debuggerModelToListItems = new Map(); | 15 this._debuggerModelToListItems = new Map(); |
| 16 /** @type {!Map.<!WebInspector.UIList.Item, !WebInspector.Target>} */ | 16 /** @type {!Map<!WebInspector.UIList.Item, !WebInspector.Target>} */ |
| 17 this._listItemsToTargets = new Map(); | 17 this._listItemsToTargets = new Map(); |
| 18 /** @type {?WebInspector.UIList.Item} */ | 18 /** @type {?WebInspector.UIList.Item} */ |
| 19 this._selectedListItem = null; | 19 this._selectedListItem = null; |
| 20 /** @type {!Map<!WebInspector.PendingSubTarget, !WebInspector.UIList.Item>} */ | |
| 21 this._subtargetToListItem = new Map(); | |
| 22 /** @type {?WebInspector.PendingSubTarget} */ | |
| 23 this._mainTargetConnection = null; | |
| 24 | |
| 20 this.threadList = new WebInspector.UIList(); | 25 this.threadList = new WebInspector.UIList(); |
| 21 this.threadList.show(this.element); | 26 this.threadList.show(this.element); |
| 22 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerPaused, this._onDebuggerStateChanged, this ); | 27 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerPaused, this._onDebuggerStateChanged, this ); |
| 23 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerResumed, this._onDebuggerStateChanged, thi s); | 28 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerResumed, this._onDebuggerStateChanged, thi s); |
| 24 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextCha nged, this); | 29 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextCha nged, this); |
| 25 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChanged, this); | 30 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChanged, this); |
| 26 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.NameChanged, this._targetNameChanged, this); | 31 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.NameChanged, this._targetNameChanged, this); |
| 32 WebInspector.targetManager.addModelListener(WebInspector.SubTargetsManager, WebInspector.SubTargetsManager.Events.SubTargetAdded, this._subTargetAdded, this ); | |
| 33 WebInspector.targetManager.addModelListener(WebInspector.SubTargetsManager, WebInspector.SubTargetsManager.Events.SubTargetRemoved, this._subTargetRemoved, this); | |
| 34 WebInspector.targetManager.addModelListener(WebInspector.SubTargetsManager, WebInspector.SubTargetsManager.Events.SubTargetAttached, this._subTargetAdded, t his); | |
| 35 WebInspector.targetManager.addModelListener(WebInspector.SubTargetsManager, WebInspector.SubTargetsManager.Events.SubTargetDetached, this._targetDetached, t his); | |
| 27 WebInspector.targetManager.observeTargets(this); | 36 WebInspector.targetManager.observeTargets(this); |
| 37 | |
| 38 var subtargets = []; | |
| 39 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.Target)) | |
| 40 subtargets = subtargets.concat(WebInspector.SubTargetsManager.fromTarget (target).subTargets()); | |
| 41 | |
| 42 subtargets | |
| 43 .sort(WebInspector.ThreadsSidebarPane._subTargetsComparator) | |
| 44 .forEach(subtarget => this._addListItem(subtarget)); | |
| 28 }; | 45 }; |
| 29 | 46 |
| 30 WebInspector.ThreadsSidebarPane.prototype = { | 47 WebInspector.ThreadsSidebarPane.prototype = { |
| 31 /** | 48 /** |
| 49 * @param {!WebInspector.Event} event | |
| 50 */ | |
| 51 _subTargetAdded: function(event) | |
| 52 { | |
| 53 this._addListItem(/** @type {!WebInspector.PendingSubTarget} */ (event.d ata)); | |
| 54 }, | |
| 55 | |
| 56 /** | |
| 57 * @param {!WebInspector.Event} event | |
| 58 */ | |
| 59 _subTargetRemoved: function(event) | |
| 60 { | |
| 61 this._removeListItem(/** @type {!WebInspector.PendingSubTarget} */ (even t.data)); | |
| 62 }, | |
| 63 | |
| 64 /** | |
| 65 * @param {!WebInspector.Event} event | |
| 66 */ | |
| 67 _targetDetached: function(event) | |
| 68 { | |
| 69 this._targetRemoved(/** @type {!WebInspector.PendingSubTarget} */ (event .data)); | |
| 70 }, | |
| 71 | |
| 72 /** | |
| 73 * @param {!WebInspector.PendingSubTarget} subTarget | |
| 74 */ | |
| 75 _addListItem: function(subTarget) | |
| 76 { | |
| 77 var target = subTarget.target(); | |
| 78 if (!subTarget.isRemote() && !(target && target.hasJSCapability())) | |
| 79 return; | |
| 80 | |
| 81 var listItem = this._subtargetToListItem.get(subTarget); | |
| 82 if (!listItem) { | |
| 83 listItem = new WebInspector.UIList.Item("", "", false); | |
| 84 this._subtargetToListItem.set(subTarget, listItem); | |
| 85 this.threadList.addItem(listItem); | |
| 86 listItem.element.addEventListener("click", this._onListItemClick.bin d(this, listItem), false); | |
| 87 } | |
| 88 if (!target) { | |
| 89 this._setupConnectionItem(listItem, subTarget); | |
| 90 return; | |
| 91 } | |
| 92 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | |
| 93 if (!debuggerModel) | |
| 94 return; | |
| 95 var currentTarget = WebInspector.context.flavor(WebInspector.Target); | |
| 96 if (currentTarget === target) | |
| 97 this._selectListItem(listItem); | |
| 98 | |
| 99 this._debuggerModelToListItems.set(debuggerModel, listItem); | |
| 100 this._listItemsToTargets.set(listItem, target); | |
| 101 this._updateDebuggerState(debuggerModel); | |
| 102 this._setupTargetItem(listItem, target, subTarget); | |
| 103 }, | |
| 104 | |
| 105 /** | |
| 32 * @override | 106 * @override |
| 33 * @param {!WebInspector.Target} target | 107 * @param {!WebInspector.Target} target |
| 34 */ | 108 */ |
| 35 targetAdded: function(target) | 109 targetAdded: function(target) |
| 36 { | 110 { |
| 37 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | 111 if (target !== WebInspector.targetManager.mainTarget()) |
| 38 if (!debuggerModel) | |
| 39 return; | 112 return; |
| 40 | 113 if (this._mainTargetConnection) |
| 41 var listItem = new WebInspector.UIList.Item(this._titleForTarget(target) , ""); | 114 this._targetRemoved(this._mainTargetConnection); |
| 42 listItem.element.addEventListener("click", this._onListItemClick.bind(th is, listItem), false); | 115 this._mainTargetConnection = new WebInspector.ThreadsSidebarPane.MainTar getConnection(target); |
| 43 var currentTarget = WebInspector.context.flavor(WebInspector.Target); | 116 this._addListItem(this._mainTargetConnection); |
| 44 if (currentTarget === target) | |
| 45 this._selectListItem(listItem); | |
| 46 | |
| 47 this._debuggerModelToListItems.set(debuggerModel, listItem); | |
| 48 this._listItemsToTargets.set(listItem, target); | |
| 49 this.threadList.addItem(listItem); | |
| 50 this._updateDebuggerState(debuggerModel); | |
| 51 }, | 117 }, |
| 52 | 118 |
| 53 /** | 119 /** |
| 54 * @override | 120 * @override |
| 55 * @param {!WebInspector.Target} target | 121 * @param {!WebInspector.Target} target |
| 56 */ | 122 */ |
| 57 targetRemoved: function(target) | 123 targetRemoved: function(target) |
| 58 { | 124 { |
| 59 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | 125 var subtargetManager = WebInspector.SubTargetsManager.fromTarget(target) ; |
| 60 if (!debuggerModel) | 126 var subtargets = subtargetManager ? subtargetManager.subTargets() : []; |
| 61 return; | 127 for (var subTarget of subtargets) { |
| 62 var listItem = this._debuggerModelToListItems.remove(debuggerModel); | 128 if (subTarget.target()) |
| 63 if (listItem) { | 129 this._targetRemoved(subTarget); |
| 64 this._listItemsToTargets.remove(listItem); | |
| 65 this.threadList.removeItem(listItem); | |
| 66 } | 130 } |
| 131 if (target === WebInspector.targetManager.mainTarget() && this._mainTarg etConnection) | |
| 132 this._targetRemoved(this._mainTargetConnection); | |
| 67 }, | 133 }, |
| 68 | 134 |
| 69 /** | 135 /** |
| 70 * @param {!WebInspector.Event} event | 136 * @param {!WebInspector.Event} event |
| 71 */ | 137 */ |
| 72 _targetNameChanged: function(event) | 138 _targetNameChanged: function(event) |
| 73 { | 139 { |
| 74 var target = /** @type {!WebInspector.Target} */ (event.data); | 140 var target = /** @type {!WebInspector.Target} */ (event.data); |
| 75 var listItem = this._listItemForTarget(target); | 141 var listItem = this._listItemForTarget(target); |
| 76 if (listItem) | 142 if (listItem) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 220 |
| 155 this._selectedListItem = listItem; | 221 this._selectedListItem = listItem; |
| 156 listItem.setSelected(true); | 222 listItem.setSelected(true); |
| 157 }, | 223 }, |
| 158 | 224 |
| 159 /** | 225 /** |
| 160 * @param {!WebInspector.UIList.Item} listItem | 226 * @param {!WebInspector.UIList.Item} listItem |
| 161 */ | 227 */ |
| 162 _onListItemClick: function(listItem) | 228 _onListItemClick: function(listItem) |
| 163 { | 229 { |
| 164 WebInspector.context.setFlavor(WebInspector.Target, this._listItemsToTar gets.get(listItem)); | 230 var target = this._listItemsToTargets.get(listItem); |
| 231 if (!target) | |
| 232 return; | |
| 233 WebInspector.context.setFlavor(WebInspector.Target, target); | |
| 165 listItem.element.scrollIntoViewIfNeeded(); | 234 listItem.element.scrollIntoViewIfNeeded(); |
| 166 }, | 235 }, |
| 167 | 236 |
| 237 /** | |
| 238 * @param {!WebInspector.UIList.Item} item | |
| 239 * @param {!WebInspector.Target} target | |
| 240 * @param {?WebInspector.PendingSubTarget} subtarget | |
| 241 */ | |
| 242 _setupTargetItem: function(item, target, subtarget) | |
| 243 { | |
| 244 this._listItemsToTargets.set(item, target); | |
| 245 item.setTitle(this._titleForTarget(target)); | |
| 246 item.setSubtitle(""); | |
| 247 item.setDimmed(false); | |
| 248 if (subtarget && subtarget.isRemote()) | |
| 249 item.setAction("Disconnect", () => subtarget.disconnect()); | |
| 250 else | |
| 251 item.setAction(null, null); | |
| 252 }, | |
| 253 | |
| 254 /** | |
| 255 * @param {!WebInspector.UIList.Item} item | |
| 256 * @param {!WebInspector.PendingSubTarget} subtarget | |
| 257 */ | |
| 258 _setupConnectionItem: function(item, subtarget) | |
|
dgozman
2016/11/01 22:07:39
If we'd have pending.isConnected(), we can merge t
eostroukhov
2016/11/02 21:55:53
Done.
| |
| 259 { | |
| 260 item.setTitle(subtarget.name()); | |
| 261 item.setSubtitle(""); | |
| 262 if (subtarget.isRemote()) | |
| 263 item.setAction("Connect", (() => subtarget.connect().then(target => WebInspector.context.setFlavor(WebInspector.Target, target)))); | |
| 264 else | |
| 265 item.setAction(null, null); | |
| 266 item.setDimmed(true); | |
| 267 }, | |
| 268 | |
| 269 /** | |
| 270 * @param {!WebInspector.PendingSubTarget} subtarget | |
| 271 */ | |
| 272 _targetRemoved: function(subtarget) | |
| 273 { | |
| 274 var item = this._subtargetToListItem.get(subtarget); | |
| 275 var target = this._listItemsToTargets.remove(item); | |
| 276 if (!target) | |
| 277 return; | |
| 278 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | |
| 279 console.assert(debuggerModel); | |
| 280 this._debuggerModelToListItems.remove(debuggerModel); | |
| 281 this._listItemsToTargets.remove(item); | |
| 282 if (subtarget.isRemote()) | |
| 283 this._setupConnectionItem(item, subtarget); | |
| 284 else | |
| 285 this._removeListItem(subtarget); | |
| 286 }, | |
| 287 | |
| 288 /** | |
| 289 * @param {!WebInspector.PendingSubTarget} subtarget | |
| 290 */ | |
| 291 _removeListItem: function(subtarget) | |
| 292 { | |
| 293 var item = this._subtargetToListItem.get(subtarget); | |
| 294 if (!item) | |
| 295 return; | |
| 296 this.threadList.removeItem(item); | |
| 297 this._subtargetToListItem.delete(subtarget); | |
| 298 this._listItemsToTargets.delete(item); | |
| 299 }, | |
| 168 | 300 |
| 169 __proto__: WebInspector.VBox.prototype | 301 __proto__: WebInspector.VBox.prototype |
| 170 }; | 302 }; |
| 303 | |
| 304 /** | |
| 305 * @return {boolean} | |
| 306 */ | |
| 307 WebInspector.ThreadsSidebarPane.isShown = function() | |
| 308 { | |
| 309 if (WebInspector.targetManager.targets(WebInspector.Target.Capability.JS).le ngth > 1) | |
| 310 return true; | |
| 311 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.Target)) | |
| 312 { | |
| 313 if (WebInspector.SubTargetsManager.fromTarget(target).subTargets().some( subTarget => subTarget.isRemote())) | |
| 314 return true; | |
| 315 } | |
| 316 return false; | |
| 317 }; | |
| 318 | |
| 319 | |
| 320 /** | |
| 321 * @constructor | |
| 322 * @extends {WebInspector.PendingSubTarget} | |
| 323 */ | |
| 324 WebInspector.ThreadsSidebarPane.MainTargetConnection = function(target) | |
| 325 { | |
| 326 WebInspector.PendingSubTarget.call(this, "main-target-list-node-" + target.i d(), target.title, false, null); | |
| 327 | |
| 328 this._target = target; | |
| 329 }; | |
| 330 | |
| 331 WebInspector.ThreadsSidebarPane.MainTargetConnection.prototype = { | |
| 332 /** | |
| 333 * @override | |
| 334 * @return {!WebInspector.Target} | |
| 335 */ | |
| 336 target: function() | |
| 337 { | |
| 338 return this._target; | |
| 339 }, | |
| 340 | |
| 341 /** | |
| 342 * @override | |
| 343 * @return {string} | |
| 344 */ | |
| 345 name: function() | |
| 346 { | |
| 347 return this._target.name(); | |
| 348 }, | |
| 349 | |
| 350 /** | |
| 351 * @override | |
| 352 * @return {boolean} | |
| 353 */ | |
| 354 isRemote: function() | |
|
dgozman
2016/11/01 22:07:39
Already passing false in constructor.
eostroukhov
2016/11/02 21:55:53
Done.
| |
| 355 { | |
| 356 return false; | |
| 357 }, | |
| 358 | |
| 359 __proto__: WebInspector.PendingSubTarget.prototype, | |
| 360 }; | |
| 361 | |
| 362 /** | |
| 363 * Sorts show tha connected targets appear first, followed by pending subtargets . | |
| 364 * | |
| 365 * @param {!WebInspector.PendingSubTarget} c1 | |
| 366 * @param {!WebInspector.PendingSubTarget} c2 | |
| 367 * @return {number} | |
| 368 */ | |
| 369 WebInspector.ThreadsSidebarPane._subTargetsComparator = function(c1, c2) | |
| 370 { | |
| 371 var t1 = c1.target(); | |
| 372 var t2 = c2.target(); | |
| 373 var name1 = t1 ? t1.name() : c1.name(); | |
| 374 var name2 = t2 ? t2.name() : c2.name(); | |
| 375 if (!!t1 === !!t2) { // both are null | |
| 376 return name1.toLowerCase().localeCompare(name2.toLowerCase()); | |
| 377 } else if (t1) { | |
| 378 return -1; | |
| 379 } | |
| 380 return 1; | |
| 381 }; | |
| OLD | NEW |