Changeset 87803 in webkit
- Timestamp:
- Jun 1, 2011 7:34:11 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r87802 r87803 1 2011-06-01 Yury Semikhatsky <yurys@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: allow opening inspector for existing workers 6 https://bugs.webkit.org/show_bug.cgi?id=61853 7 8 Added sidebar pane with a list of all workers. Each worker has a check box 9 that allows opening inspector for the worker. 10 11 * inspector/Inspector.json: 12 * inspector/InspectorInstrumentation.cpp: 13 (WebCore::InspectorInstrumentation::didStartWorkerContextImpl): 14 * inspector/InspectorInstrumentation.h: 15 (WebCore::InspectorInstrumentation::didStartWorkerContext): 16 * inspector/InspectorWorkerAgent.cpp: 17 (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::WorkerFrontendChannel): 18 (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::~WorkerFrontendChannel): 19 (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::connectToWorkerContext): 20 (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::disconnectFromWorkerContext): 21 (WebCore::InspectorWorkerAgent::clearFrontend): 22 (WebCore::InspectorWorkerAgent::connectToWorker): 23 (WebCore::InspectorWorkerAgent::disconnectFromWorker): 24 (WebCore::InspectorWorkerAgent::didStartWorkerContext): 25 * inspector/InspectorWorkerAgent.h: 26 * inspector/front-end/ScriptsPanel.js: 27 (WebInspector.ScriptsPanel): 28 * inspector/front-end/Settings.js: 29 * inspector/front-end/WorkerManager.js: 30 (WebInspector.WorkerManager): 31 (WebInspector.WorkerManager.prototype._workerCreated): 32 (WebInspector.WorkerManager.prototype._sendMessageToWorkerInspector): 33 (WebInspector.WorkerManager.prototype.openWorkerInspector): 34 (WebInspector.WorkerManager.prototype.closeWorkerInspector): 35 (WebInspector.WorkerManager.prototype._workerInspectorClosing): 36 (WebInspector.WorkerMessageForwarder): 37 (WebInspector.WorkerMessageForwarder.prototype.workerCreated): 38 (WebInspector.WorkerMessageForwarder.prototype.dispatchMessageFromWorker): 39 * inspector/front-end/WorkersSidebarPane.js: 40 (WebInspector.WorkersSidebarPane): 41 (WebInspector.WorkersSidebarPane.prototype.addWorker): 42 (WebInspector.WorkerListSidebarPane): 43 (WebInspector.WorkerListSidebarPane.prototype._workerAdded): 44 (WebInspector.WorkerListSidebarPane.prototype._workerRemoved): 45 (WebInspector.WorkerListSidebarPane.prototype._workerInspectorClosed): 46 (WebInspector.WorkerListSidebarPane.prototype._addWorker): 47 (WebInspector.WorkerListSidebarPane.prototype._createCheckbox): 48 (WebInspector.WorkerListSidebarPane.prototype._workerItemClicked): 49 * workers/Worker.cpp: 50 (WebCore::Worker::notifyFinished): 51 1 52 2011-06-01 Shishir Agrawal <shishir@chromium.org> 2 53 -
trunk/Source/WebCore/inspector/Inspector.json
r86959 r87803 1727 1727 { "name": "message", "type": "object" } 1728 1728 ] 1729 }, 1730 { 1731 "name": "connectToWorker", 1732 "parameters": [ 1733 { "name": "workerId", "type": "integer" } 1734 ] 1735 }, 1736 { 1737 "name": "disconnectFromWorker", 1738 "parameters": [ 1739 { "name": "workerId", "type": "integer" } 1740 ] 1729 1741 } 1730 1742 ], … … 1733 1745 "name": "workerCreated", 1734 1746 "parameters": [ 1735 { "name": "workerId", "type": "integer" } 1747 { "name": "workerId", "type": "integer" }, 1748 { "name": "url", "type": "string" } 1736 1749 ] 1737 1750 }, -
trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp
r87681 r87803 717 717 718 718 #if ENABLE(WORKERS) 719 void InspectorInstrumentation::didStartWorkerContextImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* workerContextProxy )719 void InspectorInstrumentation::didStartWorkerContextImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* workerContextProxy, const KURL& url) 720 720 { 721 721 if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent()) 722 workerAgent->didStartWorkerContext(workerContextProxy );722 workerAgent->didStartWorkerContext(workerContextProxy, url); 723 723 } 724 724 -
trunk/Source/WebCore/inspector/InspectorInstrumentation.h
r86752 r87803 162 162 #if ENABLE(WORKERS) 163 163 static bool willStartWorkerContext(ScriptExecutionContext*, WorkerContextProxy*); 164 static void didStartWorkerContext(ScriptExecutionContext*, WorkerContextProxy*, bool paused );164 static void didStartWorkerContext(ScriptExecutionContext*, WorkerContextProxy*, bool paused, const KURL&); 165 165 static void didCreateWorker(ScriptExecutionContext*, intptr_t id, const String& url, bool isSharedWorker); 166 166 static void didDestroyWorker(ScriptExecutionContext*, intptr_t id); … … 284 284 285 285 #if ENABLE(WORKERS) 286 static void didStartWorkerContextImpl(InstrumentingAgents*, WorkerContextProxy* );286 static void didStartWorkerContextImpl(InstrumentingAgents*, WorkerContextProxy*, const KURL&); 287 287 static void didCreateWorkerImpl(InstrumentingAgents*, intptr_t id, const String& url, bool isSharedWorker); 288 288 static void didDestroyWorkerImpl(InstrumentingAgents*, intptr_t id); … … 857 857 } 858 858 859 inline void InspectorInstrumentation::didStartWorkerContext(ScriptExecutionContext* context, WorkerContextProxy* proxy, bool paused )859 inline void InspectorInstrumentation::didStartWorkerContext(ScriptExecutionContext* context, WorkerContextProxy* proxy, bool paused, const KURL& url) 860 860 { 861 861 #if ENABLE(INSPECTOR) … … 864 864 FAST_RETURN_IF_NO_FRONTENDS(void()); 865 865 if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context)) 866 didStartWorkerContextImpl(instrumentingAgents, proxy );866 didStartWorkerContextImpl(instrumentingAgents, proxy, url); 867 867 #endif 868 868 } -
trunk/Source/WebCore/inspector/InspectorWorkerAgent.cpp
r87074 r87803 39 39 #include "InspectorValues.h" 40 40 #include "InstrumentingAgents.h" 41 #include "KURL.h" 41 42 #include "WorkerContextProxy.h" 42 43 #include <wtf/PassOwnPtr.h> … … 51 52 , m_proxy(proxy) 52 53 , m_id(s_nextId++) 54 , m_connected(false) 53 55 { 54 56 } 55 virtual ~WorkerFrontendChannel() { } 57 virtual ~WorkerFrontendChannel() 58 { 59 disconnectFromWorkerContext(); 60 } 56 61 57 62 int id() const { return m_id; } 58 63 WorkerContextProxy* proxy() const { return m_proxy; } 64 65 void connectToWorkerContext() 66 { 67 if (m_connected) 68 return; 69 m_connected = true; 70 m_proxy->connectToInspector(this); 71 } 72 73 void disconnectFromWorkerContext() 74 { 75 if (!m_connected) 76 return; 77 m_connected = false; 78 m_proxy->disconnectFromInspector(); 79 } 59 80 60 81 private: … … 74 95 WorkerContextProxy* m_proxy; 75 96 int m_id; 97 bool m_connected; 76 98 static int s_nextId; 77 99 }; … … 105 127 m_inspectorFrontend = 0; 106 128 m_instrumentingAgents->setInspectorWorkerAgent(0); 129 deleteAllValues(m_idToChannel); 130 m_idToChannel.clear(); 131 } 132 133 void InspectorWorkerAgent::connectToWorker(ErrorString* error, int workerId) 134 { 135 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); 136 if (channel) 137 channel->connectToWorkerContext(); 138 else 139 *error = "Worker is gone"; 140 } 141 142 void InspectorWorkerAgent::disconnectFromWorker(ErrorString* error, int workerId) 143 { 144 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); 145 if (channel) 146 channel->disconnectFromWorkerContext(); 147 else 148 *error = "Worker is gone"; 107 149 } 108 150 … … 116 158 } 117 159 118 void InspectorWorkerAgent::didStartWorkerContext(WorkerContextProxy* workerContextProxy )160 void InspectorWorkerAgent::didStartWorkerContext(WorkerContextProxy* workerContextProxy, const KURL& url) 119 161 { 120 162 WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_inspectorFrontend, workerContextProxy); 121 163 m_idToChannel.set(channel->id(), channel); 122 164 123 workerContextProxy->connectToInspector(channel); 124 if (m_inspectorFrontend) 125 m_inspectorFrontend->worker()->workerCreated(channel->id()); 165 ASSERT(m_inspectorFrontend); 166 m_inspectorFrontend->worker()->workerCreated(channel->id(), url.string()); 126 167 } 127 168 -
trunk/Source/WebCore/inspector/InspectorWorkerAgent.h
r87074 r87803 41 41 class InspectorObject; 42 42 class InstrumentingAgents; 43 class KURL; 43 44 class WorkerContextProxy; 44 45 … … 54 55 55 56 // Called from InspectorInstrumentation 56 void didStartWorkerContext(WorkerContextProxy* );57 void didStartWorkerContext(WorkerContextProxy*, const KURL&); 57 58 58 59 // Called from InspectorBackendDispatcher 60 void connectToWorker(ErrorString*, int workerId); 61 void disconnectFromWorker(ErrorString*, int workerId); 59 62 void sendMessageToWorker(ErrorString*, int workerId, PassRefPtr<InspectorObject> message); 60 63 -
trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js
r87166 r87803 108 108 109 109 this.sidebarPanes.workers = new WebInspector.WorkersSidebarPane(); 110 if (Preferences.canInspectWorkers && WebInspector.workerManager) 111 this.sidebarPanes.workerList = new WebInspector.WorkerListSidebarPane(WebInspector.workerManager); 112 110 113 111 114 for (var pane in this.sidebarPanes) -
trunk/Source/WebCore/inspector/front-end/Settings.js
r85312 r87803 52 52 detailedHeapProfiles: false, 53 53 saveAsAvailable: false, 54 useLowerCaseMenuTitlesOnWindows: false 54 useLowerCaseMenuTitlesOnWindows: false, 55 canInspectWorkers: false, 55 56 } 56 57 -
trunk/Source/WebCore/inspector/front-end/WorkerManager.js
r85847 r87803 31 31 WebInspector.WorkerManager = function() 32 32 { 33 this._workerIdToWindow = {}; 34 InspectorBackend.registerDomainDispatcher("Worker", new WebInspector.WorkerMessageForwarder(this)); 33 35 } 34 36 … … 42 44 var workerId = WebInspector.queryParamsObject["workerId"]; 43 45 if (!workerId) { 44 InspectorBackend.registerDomainDispatcher("Worker", new WebInspector.WorkerMessageForwarder());46 WebInspector.workerManager = new WebInspector.WorkerManager(); 45 47 return; 46 48 } 47 48 49 49 50 function receiveMessage(event) … … 66 67 } 67 68 69 WebInspector.WorkerManager.Events = { 70 WorkerAdded: "worker-added", 71 WorkerRemoved: "worker-removed", 72 WorkerInspectorClosed: "worker-inspector-closed" 73 } 68 74 69 WebInspector.WorkerMessageForwarder = function() 75 WebInspector.WorkerManager.prototype = { 76 _workerCreated: function(workerId, url) 77 { 78 this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerAdded, {workerId: workerId, url: url}); 79 }, 80 81 _sendMessageToWorkerInspector: function(workerId, message) 82 { 83 var workerInspectorWindow = this._workerIdToWindow[workerId]; 84 if (workerInspectorWindow) 85 workerInspectorWindow.postMessage(message, "*"); 86 }, 87 88 openWorkerInspector: function(workerId) 89 { 90 var url = location.href + "&workerId=" + workerId; 91 url = url.replace("docked=true&", ""); 92 var workerInspectorWindow = window.open(url); 93 this._workerIdToWindow[workerId] = workerInspectorWindow; 94 workerInspectorWindow.addEventListener("beforeunload", this._workerInspectorClosing.bind(this, workerId), true); 95 WorkerAgent.connectToWorker(workerId); 96 }, 97 98 closeWorkerInspector: function(workerId) 99 { 100 var workerInspectorWindow = this._workerIdToWindow[workerId]; 101 if (workerInspectorWindow) 102 workerInspectorWindow.close(); 103 }, 104 105 _workerInspectorClosing: function(workerId, event) 106 { 107 delete this._workerIdToWindow[workerId]; 108 WorkerAgent.disconnectFromWorker(workerId); 109 this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerInspectorClosed, workerId); 110 } 111 } 112 113 WebInspector.WorkerManager.prototype.__proto__ = WebInspector.Object.prototype; 114 115 WebInspector.WorkerMessageForwarder = function(workerManager) 70 116 { 117 this._workerManager = workerManager; 71 118 window.addEventListener("message", this._receiveMessage.bind(this), true); 72 this._workerIdToWindow = {};73 119 } 74 120 … … 85 131 }, 86 132 87 workerCreated: function(workerId )133 workerCreated: function(workerId, url) 88 134 { 89 var url = location.href + "&workerId=" + workerId; 90 url = url.replace("docked=true&", ""); 91 this._workerIdToWindow[workerId] = window.open(url); 135 this._workerManager._workerCreated(workerId, url); 92 136 }, 93 137 94 138 dispatchMessageFromWorker: function(workerId, message) 95 139 { 96 var win = this._workerIdToWindow[workerId]; 97 if (win) 98 win.postMessage(message, "*"); 140 this._workerManager._sendMessageToWorkerInspector(workerId, message); 99 141 } 100 142 } -
trunk/Source/WebCore/inspector/front-end/WorkersSidebarPane.js
r82281 r87803 32 32 { 33 33 WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers")); 34 34 35 35 this._workers = {}; 36 36 … … 54 54 addWorker: function(id, url, isShared) 55 55 { 56 if (id in this._workers) 56 if (id in this._workers) 57 57 return; 58 58 var worker = new WebInspector.Worker(id, url, isShared); … … 101 101 this.shared = shared; 102 102 } 103 104 105 106 WebInspector.WorkerListSidebarPane = function(workerManager) 107 { 108 WebInspector.SidebarPane.call(this, WebInspector.UIString("Worker inspectors")); 109 110 this._workerListElement = document.createElement("ol"); 111 this._workerListElement.tabIndex = 0; 112 this._workerListElement.addStyleClass("properties-tree"); 113 this._workerListTreeOutline = new TreeOutline(this._workerListElement); 114 this.bodyElement.appendChild(this._workerListElement); 115 116 this._idToWorkerItem = {}; 117 this._workerManager = workerManager; 118 119 workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this); 120 workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this); 121 workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerInspectorClosed, this._workerInspectorClosed, this); 122 } 123 124 WebInspector.WorkerListSidebarPane.prototype = { 125 _workerAdded: function(event) 126 { 127 this._addWorker(event.data.workerId, event.data.url); 128 }, 129 130 _workerRemoved: function(event) 131 { 132 var workerItem = this._idToWorkerItem[event.data]; 133 workerItem.element.parentElement.removeChild(workerItem.element); 134 }, 135 136 _workerInspectorClosed: function(event) 137 { 138 var workerItem = this._idToWorkerItem[event.data]; 139 workerItem.checkbox.checked = false; 140 }, 141 142 _addWorker: function(workerId, url) 143 { 144 var workerItem = {}; 145 workerItem.workerId = workerId; 146 workerItem.element = new TreeElement(url); 147 this._workerListTreeOutline.appendChild(workerItem.element); 148 workerItem.element.selectable = true; 149 150 workerItem.checkbox = this._createCheckbox(workerItem.element); 151 workerItem.checkbox.addEventListener("click", this._workerItemClicked.bind(this, workerItem), true); 152 153 this._idToWorkerItem[workerId] = workerItem; 154 }, 155 156 _createCheckbox: function(treeElement) 157 { 158 var checkbox = document.createElement("input"); 159 checkbox.className = "checkbox-elem"; 160 checkbox.type = "checkbox"; 161 treeElement.listItemElement.insertBefore(checkbox, treeElement.listItemElement.firstChild); 162 return checkbox; 163 }, 164 165 _workerItemClicked: function(workerItem, event) 166 { 167 if (event.target.checked) 168 this._workerManager.openWorkerInspector(workerItem.workerId); 169 else 170 this._workerManager.closeWorkerInspector(workerItem.workerId); 171 } 172 } 173 174 WebInspector.WorkerListSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype; -
trunk/Source/WebCore/workers/Worker.cpp
r85020 r87803 134 134 bool shouldStartPaused = InspectorInstrumentation::willStartWorkerContext(scriptExecutionContext(), m_contextProxy); 135 135 m_contextProxy->startWorkerContext(m_scriptLoader->url(), scriptExecutionContext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script()); 136 InspectorInstrumentation::didStartWorkerContext(scriptExecutionContext(), m_contextProxy, shouldStartPaused );136 InspectorInstrumentation::didStartWorkerContext(scriptExecutionContext(), m_contextProxy, shouldStartPaused, m_scriptLoader->url()); 137 137 InspectorInstrumentation::scriptImported(scriptExecutionContext(), m_scriptLoader->identifier(), m_scriptLoader->script()); 138 138 }
Note: See TracChangeset
for help on using the changeset viewer.