2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
34 WebInspector.ThreadsToolbar = function()
36 this.element = document.createElement("div");
37 this.element.className = "status-bar scripts-debug-toolbar threads-toolbar hidden";
38 this._comboBox = new WebInspector.StatusBarComboBox(this._onComboBoxSelectionChange.bind(this));
39 this.element.appendChild(this._comboBox.element);
42 if (WebInspector.experimentsSettings.workersInMainWindow.isEnabled()) {
43 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this);
44 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this);
45 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkersCleared, this._workersCleared, this);
49 WebInspector.ThreadsToolbar.prototype = {
53 if (!WebInspector.experimentsSettings.workersInMainWindow.isEnabled())
56 this._threadIdToOption = {};
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(threadId));
64 this._alterVisibility();
65 this._comboBox.select(this._threadIdToOption[WebInspector.workerManager.selectedThreadId()]);
69 * @param {number} workerId
72 _addOption: function(workerId, url)
74 var option = this._comboBox.createOption(url, "", String(workerId));
75 this._threadIdToOption[workerId] = option;
79 * @param {!WebInspector.Event} event
81 _workerAdded: function(event)
83 var data = /** @type {{workerId: number, url: string}} */ (event.data);
84 this._addOption(data.workerId, data.url);
85 this._alterVisibility();
89 * @param {!WebInspector.Event} event
91 _workerRemoved: function(event)
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();
99 _workersCleared: function()
101 this._comboBox.removeOptions();
105 _onComboBoxSelectionChange: function()
107 var selectedOption = this._comboBox.selectedOption();
111 WebInspector.workerManager.setSelectedThreadId(parseInt(selectedOption.value, 10));
114 _alterVisibility: function()
116 var hidden = this._comboBox.size() === 1;
117 this.element.classList.toggle("hidden", hidden);