OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 /** | |
32 * @constructor | |
33 */ | |
34 WebInspector.ThreadsToolbar = function() | |
35 { | |
36 this.element = document.createElement("div"); | |
37 this.element.className = "status-bar scripts-debug-toolbar threads-toolbar h
idden"; | |
38 this._comboBox = new WebInspector.StatusBarComboBox(this._onComboBoxSelectio
nChange.bind(this)); | |
39 this.element.appendChild(this._comboBox.element); | |
40 | |
41 this._reset(); | |
42 if (WebInspector.experimentsSettings.workersInMainWindow.isEnabled()) { | |
43 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.E
vents.WorkerAdded, this._workerAdded, this); | |
44 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.E
vents.WorkerRemoved, this._workerRemoved, this); | |
45 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.E
vents.WorkersCleared, this._workersCleared, this); | |
46 } | |
47 } | |
48 | |
49 WebInspector.ThreadsToolbar.prototype = { | |
50 | |
51 _reset: function() | |
52 { | |
53 if (!WebInspector.experimentsSettings.workersInMainWindow.isEnabled()) | |
54 return; | |
55 | |
56 this._threadIdToOption = {}; | |
57 | |
58 var connectedThreads = WebInspector.workerManager.threadsList(); | |
59 for (var i = 0; i < connectedThreads.length; ++i) { | |
60 var threadId = connectedThreads[i]; | |
61 this._addOption(threadId, WebInspector.workerManager.threadUrl(threa
dId)); | |
62 } | |
63 | |
64 this._alterVisibility(); | |
65 this._comboBox.select(this._threadIdToOption[WebInspector.workerManager.
selectedThreadId()]); | |
66 }, | |
67 | |
68 /** | |
69 * @param {number} workerId | |
70 * @param {string} url | |
71 */ | |
72 _addOption: function(workerId, url) | |
73 { | |
74 var option = this._comboBox.createOption(url, "", String(workerId)); | |
75 this._threadIdToOption[workerId] = option; | |
76 }, | |
77 | |
78 /** | |
79 * @param {!WebInspector.Event} event | |
80 */ | |
81 _workerAdded: function(event) | |
82 { | |
83 var data = /** @type {{workerId: number, url: string}} */ (event.data); | |
84 this._addOption(data.workerId, data.url); | |
85 this._alterVisibility(); | |
86 }, | |
87 | |
88 /** | |
89 * @param {!WebInspector.Event} event | |
90 */ | |
91 _workerRemoved: function(event) | |
92 { | |
93 var data = /** @type {{workerId: number, url: string}} */ (event.data); | |
94 this._comboBox.removeOption(this._threadIdToOption[data.workerId]); | |
95 delete this._threadIdToOption[data.workerId]; | |
96 this._alterVisibility(); | |
97 }, | |
98 | |
99 _workersCleared: function() | |
100 { | |
101 this._comboBox.removeOptions(); | |
102 this._reset(); | |
103 }, | |
104 | |
105 _onComboBoxSelectionChange: function() | |
106 { | |
107 var selectedOption = this._comboBox.selectedOption(); | |
108 if (!selectedOption) | |
109 return; | |
110 | |
111 WebInspector.workerManager.setSelectedThreadId(parseInt(selectedOption.v
alue, 10)); | |
112 }, | |
113 | |
114 _alterVisibility: function() | |
115 { | |
116 var hidden = this._comboBox.size() === 1; | |
117 this.element.classList.toggle("hidden", hidden); | |
118 } | |
119 | |
120 } | |
OLD | NEW |