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.
31 WebInspector.WorkersSidebarPane = function()
33 WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers"));
37 this._enableWorkersCheckbox = new WebInspector.Checkbox(
38 WebInspector.UIString("Debug"),
39 "sidebar-pane-subtitle",
40 WebInspector.UIString("Allow debugging workers. Enabling this option will replace native workers with the iframe-based JavaScript implementation"));
41 this.titleElement.insertBefore(this._enableWorkersCheckbox.element, this.titleElement.firstChild);
43 this._enableWorkersCheckbox.addEventListener(this._onTriggerInstrument.bind(this));
44 this._enableWorkersCheckbox.checked = false;
46 this._listElement = document.createElement("ol");
47 this._listElement.className = "workers-list";
49 this.bodyElement.appendChild(this._listElement);
50 this._treeOutline = new TreeOutline(this._listElement);
53 WebInspector.WorkersSidebarPane.prototype = {
54 addWorker: function(id, url, isShared)
56 if (id in this._workers)
58 var worker = new WebInspector.Worker(id, url, isShared);
59 this._workers[id] = worker;
61 var title = WebInspector.linkifyURL(url, WebInspector.displayNameForURL(url), "worker-item", true, url);
62 var treeElement = new TreeElement(null, worker, false);
63 treeElement.titleHTML = title;
64 this._treeOutline.appendChild(treeElement);
67 removeWorker: function(id)
69 if (id in this._workers) {
70 this._treeOutline.removeChild(this._treeOutline.findTreeElement(this._workers[id]));
71 delete this._workers[id];
75 setInstrumentation: function(enabled)
77 InspectorBackend.removeAllScriptsToEvaluateOnLoad();
79 InspectorBackend.addScriptToEvaluateOnLoad("(" + InjectedFakeWorker + ")");
84 this.setInstrumentation(this._enableWorkersCheckbox.checked);
85 this._treeOutline.removeChildren();
89 _onTriggerInstrument: function(event)
91 this.setInstrumentation(this._enableWorkersCheckbox.checked);
95 WebInspector.WorkersSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
97 WebInspector.Worker = function(id, url, shared)
101 this.shared = shared;
104 WebInspector.didCreateWorker = function()
106 var workersPane = WebInspector.panels.scripts.sidebarPanes.workers;
107 workersPane.addWorker.apply(workersPane, arguments);
110 WebInspector.didDestroyWorker = function()
112 var workersPane = WebInspector.panels.scripts.sidebarPanes.workers;
113 workersPane.removeWorker.apply(workersPane, arguments);