Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / WorkersSidebarPane.js
1 /*
2  * Copyright (C) 2010 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  * @extends {WebInspector.SidebarPane}
34  */
35 WebInspector.WorkersSidebarPane = function()
36 {
37     WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers"));
38
39     this._enableWorkersCheckbox = new WebInspector.Checkbox(
40         WebInspector.UIString("Pause on start"),
41         "sidebar-label",
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;
47
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");
52
53     var separator = this.bodyElement.createChild("div", "sidebar-separator");
54     separator.textContent = WebInspector.UIString("Dedicated worker inspectors");
55
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);
61
62     this._idToWorkerItem = {};
63
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)
68             continue;
69
70         this._addWorker(threadId, WebInspector.workerManager.threadUrl(threadId));
71     }
72
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);
76 }
77
78 WebInspector.WorkersSidebarPane.prototype = {
79     _workerAdded: function(event)
80     {
81         this._addWorker(event.data.workerId, event.data.url);
82     },
83
84     _workerRemoved: function(event)
85     {
86         this._idToWorkerItem[event.data].remove();
87         delete this._idToWorkerItem[event.data];
88     },
89
90     _workersCleared: function(event)
91     {
92         this._idToWorkerItem = {};
93         this._workerListElement.removeChildren();
94     },
95
96     _addWorker: function(workerId, url)
97     {
98         var item = this._workerListElement.createChild("div", "dedicated-worker-item");
99         var link = item.createChild("a");
100         link.textContent = url;
101         link.href = "#";
102         link.target = "_blank";
103         link.addEventListener("click", this._workerItemClicked.bind(this, workerId), true);
104         this._idToWorkerItem[workerId] = item;
105     },
106
107     _workerItemClicked: function(workerId, event)
108     {
109         event.preventDefault();
110         WebInspector.workerFrontendManager.openWorkerInspector(workerId);
111     },
112
113     _autoattachToWorkersClicked: function(event)
114     {
115         WorkerAgent.setAutoconnectToWorkers(this._enableWorkersCheckbox.checked);
116     },
117
118     __proto__: WebInspector.SidebarPane.prototype
119 }