2 * Copyright (C) 2010 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.
33 * @extends {WebInspector.SidebarPane}
35 WebInspector.WorkersSidebarPane = function()
37 WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers"));
39 this._enableWorkersCheckbox = new WebInspector.Checkbox(
40 WebInspector.UIString("Pause on start"),
42 WebInspector.UIString("Automatically attach to new workers and pause them. Enabling this option will force opening inspector for all new workers."));
43 this._enableWorkersCheckbox.element.id = "pause-workers-checkbox";
44 this.bodyElement.appendChild(this._enableWorkersCheckbox.element);
45 this._enableWorkersCheckbox.addEventListener(this._autoattachToWorkersClicked.bind(this));
46 this._enableWorkersCheckbox.checked = false;
48 var note = this.bodyElement.createChild("div");
49 note.id = "shared-workers-list";
50 note.classList.add("sidebar-label")
51 note.textContent = WebInspector.UIString("Shared workers can be inspected in the Task Manager");
53 var separator = this.bodyElement.createChild("div", "sidebar-separator");
54 separator.textContent = WebInspector.UIString("Dedicated worker inspectors");
56 this._workerListElement = document.createElement("ol");
57 this._workerListElement.tabIndex = 0;
58 this._workerListElement.classList.add("properties-tree");
59 this._workerListElement.classList.add("sidebar-label");
60 this.bodyElement.appendChild(this._workerListElement);
62 this._idToWorkerItem = {};
64 var threadList = WebInspector.workerManager.threadsList();
65 for (var i = 0; i < threadList.length; ++i) {
66 var threadId = threadList[i];
67 if (threadId === WebInspector.WorkerManager.MainThreadId)
70 this._addWorker(threadId, WebInspector.workerManager.threadUrl(threadId));
73 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this);
74 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this);
75 WebInspector.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkersCleared, this._workersCleared, this);
78 WebInspector.WorkersSidebarPane.prototype = {
79 _workerAdded: function(event)
81 this._addWorker(event.data.workerId, event.data.url);
84 _workerRemoved: function(event)
86 this._idToWorkerItem[event.data].remove();
87 delete this._idToWorkerItem[event.data];
90 _workersCleared: function(event)
92 this._idToWorkerItem = {};
93 this._workerListElement.removeChildren();
96 _addWorker: function(workerId, url)
98 var item = this._workerListElement.createChild("div", "dedicated-worker-item");
99 var link = item.createChild("a");
100 link.textContent = url;
102 link.target = "_blank";
103 link.addEventListener("click", this._workerItemClicked.bind(this, workerId), true);
104 this._idToWorkerItem[workerId] = item;
107 _workerItemClicked: function(workerId, event)
109 event.preventDefault();
110 WebInspector.workerFrontendManager.openWorkerInspector(workerId);
113 _autoattachToWorkersClicked: function(event)
115 WorkerAgent.setAutoconnectToWorkers(this._enableWorkersCheckbox.checked);
118 __proto__: WebInspector.SidebarPane.prototype