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

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

Issue 2431223003: [DevTools]: Require explicit connection (Closed)
Patch Set: Reworked - again Created 4 years, 1 month 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 // 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.PendingConnection, !WebInspector.UIList.Item>} */
21 this._connectionToListItem = new Map();
22 /** @type {!Map<!WebInspector.Target, ?WebInspector.PendingConnection>} */
23 this._targetToConnection = new Map();
20 this.threadList = new WebInspector.UIList(); 24 this.threadList = new WebInspector.UIList();
21 this.threadList.show(this.element); 25 this.threadList.show(this.element);
22 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerPaused, this._onDebuggerStateChanged, this ); 26 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); 27 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); 28 WebInspector.targetManager.addModelListener(WebInspector.RuntimeModel, WebIn spector.RuntimeModel.Events.ExecutionContextChanged, this._onExecutionContextCha nged, this);
25 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChanged, this); 29 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targ etChanged, this);
26 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.NameChanged, this._targetNameChanged, this); 30 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.NameChanged, this._targetNameChanged, this);
31 WebInspector.targetManager.addModelListener(WebInspector.SubTargetsManager, WebInspector.SubTargetsManager.Events.SubTargetConnectionCreated, this._connecti onAdded, this);
32 WebInspector.targetManager.addModelListener(WebInspector.SubTargetsManager, WebInspector.SubTargetsManager.Events.SubTargetConnectionDestroyed, this._connec tionRemoved, this);
27 WebInspector.targetManager.observeTargets(this); 33 WebInspector.targetManager.observeTargets(this);
34
35 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.Target))
dgozman 2016/10/28 18:31:36 {} around body
eostroukhov 2016/11/01 20:28:15 Done.
36 for (var connection of WebInspector.SubTargetsManager.fromTarget(target) .targetConnections())
37 this._showConnection(connection);
28 }; 38 };
29 39
30 WebInspector.ThreadsSidebarPane.prototype = { 40 WebInspector.ThreadsSidebarPane.prototype = {
31 /** 41 /**
32 * @override 42 * @override
33 * @param {!WebInspector.Target} target 43 * @param {!WebInspector.Target} target
34 */ 44 */
35 targetAdded: function(target) 45 targetAdded: function(target)
36 { 46 {
37 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 47 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
38 if (!debuggerModel) 48 if (!debuggerModel)
39 return; 49 return;
40 50
41 var listItem = new WebInspector.UIList.Item(this._titleForTarget(target) , ""); 51 var connection = null;
42 listItem.element.addEventListener("click", this._onListItemClick.bind(th is, listItem), false); 52 for (var conn of this._connectionToListItem.keys()) {
dgozman 2016/10/28 18:31:36 no abbreviations
eostroukhov 2016/11/01 20:28:15 Done.
53 if (conn.target() !== target)
54 continue
dgozman 2016/10/28 18:31:36 missing semicolon
eostroukhov 2016/11/01 20:28:15 Done.
55 connection = conn;
56 break;
57 }
58 this._targetToConnection.set(target, connection);
59 var listItem = connection ? this._connectionToListItem.get(connection) : null;
60 if (!listItem)
61 listItem = this._createListItem();
62 this._setupTargetItem(listItem, target, connection);
43 var currentTarget = WebInspector.context.flavor(WebInspector.Target); 63 var currentTarget = WebInspector.context.flavor(WebInspector.Target);
44 if (currentTarget === target) 64 if (currentTarget === target)
45 this._selectListItem(listItem); 65 this._selectListItem(listItem);
46 66
47 this._debuggerModelToListItems.set(debuggerModel, listItem); 67 this._debuggerModelToListItems.set(debuggerModel, listItem);
48 this._listItemsToTargets.set(listItem, target); 68 this._listItemsToTargets.set(listItem, target);
49 this.threadList.addItem(listItem);
50 this._updateDebuggerState(debuggerModel); 69 this._updateDebuggerState(debuggerModel);
51 }, 70 },
52 71
53 /** 72 /**
54 * @override 73 * @override
55 * @param {!WebInspector.Target} target 74 * @param {!WebInspector.Target} target
56 */ 75 */
57 targetRemoved: function(target) 76 targetRemoved: function(target)
58 { 77 {
59 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 78 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
60 if (!debuggerModel) 79 if (!debuggerModel)
61 return; 80 return;
62 var listItem = this._debuggerModelToListItems.remove(debuggerModel); 81 var listItem = this._debuggerModelToListItems.remove(debuggerModel);
63 if (listItem) { 82 this._listItemsToTargets.remove(listItem);
64 this._listItemsToTargets.remove(listItem); 83 this._debuggerModelToListItems.remove(debuggerModel);
84 if (!listItem)
85 return;
86 var connection = this._targetToConnection.get(target);
87 this._targetToConnection.delete(target);
88 if (connection && this._connectionToListItem.get(connection) === listIte m) {
89 this._setupConnectionItem(listItem, connection);
90 } else {
65 this.threadList.removeItem(listItem); 91 this.threadList.removeItem(listItem);
66 } 92 }
67 }, 93 },
68 94
69 /** 95 /**
70 * @param {!WebInspector.Event} event 96 * @param {!WebInspector.Event} event
71 */ 97 */
72 _targetNameChanged: function(event) 98 _targetNameChanged: function(event)
73 { 99 {
74 var target = /** @type {!WebInspector.Target} */ (event.data); 100 var target = /** @type {!WebInspector.Target} */ (event.data);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 184
159 /** 185 /**
160 * @param {!WebInspector.UIList.Item} listItem 186 * @param {!WebInspector.UIList.Item} listItem
161 */ 187 */
162 _onListItemClick: function(listItem) 188 _onListItemClick: function(listItem)
163 { 189 {
164 WebInspector.context.setFlavor(WebInspector.Target, this._listItemsToTar gets.get(listItem)); 190 WebInspector.context.setFlavor(WebInspector.Target, this._listItemsToTar gets.get(listItem));
165 listItem.element.scrollIntoViewIfNeeded(); 191 listItem.element.scrollIntoViewIfNeeded();
166 }, 192 },
167 193
194 /**
195 * @param {!WebInspector.Event} event
196 */
197 _connectionAdded: function(event)
198 {
199 var connection =/** @type {!WebInspector.PendingConnection} */ (event.da ta);
200 this._showConnection(connection);
201 },
202
203 /**
204 * @param {!WebInspector.Event} event
205 */
206 _connectionRemoved: function(event)
207 {
208 var connection = /** @type {!WebInspector.PendingConnection} */ (event.d ata);
209 var listItem = this._connectionToListItem.get(connection);
210 this._connectionToListItem.delete(connection)
dgozman 2016/10/28 18:31:36 missing semicolon...
eostroukhov 2016/11/01 20:28:15 Done.
211 if (!listItem || this._listItemsToTargets.get(listItem))
212 return;
213 this.threadList.removeItem(listItem);
214 },
215
216 /**
217 * @return {!WebInspector.UIList.Item}
218 */
219 _createListItem: function()
220 {
221 var item = new WebInspector.UIList.Item("", "");
222 item.element.addEventListener("click", this._onListItemClick.bind(this, item), false);
223 this.threadList.addItem(item);
224 return item;
225 },
226
227 /**
228 * @param {!WebInspector.UIList.Item} item
229 * @param {!WebInspector.Target} target
230 * @param {?WebInspector.PendingConnection} connection
231 */
232 _setupTargetItem: function(item, target, connection)
233 {
234 item.setTitle(this._titleForTarget(target));
235 item.setSubtitle("");
236 item.setDimmed(false);
237 if (connection)
238 item.setAction("Disconnect", () => connection.disconnect());
239 else
240 item.setAction(null, null);
241 },
242
243 /**
244 * @param {!WebInspector.UIList.Item} item
245 * @param {!WebInspector.PendingConnection} connection
246 */
247 _setupConnectionItem: function(item, connection)
248 {
249 item.setTitle(connection.name());
250 item.setSubtitle("");
251 item.setAction("Connect", (() => connection.connect().then(() => this._o nListItemClick(item))));
252 item.setDimmed(true);
253 },
254
255 /**
256 * @param {!WebInspector.PendingConnection} connection
257 */
258 _showConnection: function(connection)
259 {
260 var listItem = this._createListItem();
261 this._setupConnectionItem(listItem, connection);
262 this._connectionToListItem.set(connection, listItem);
263 },
168 264
169 __proto__: WebInspector.VBox.prototype 265 __proto__: WebInspector.VBox.prototype
170 }; 266 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698