| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "core/inspector/InspectorWorkerAgent.h" | 33 #include "core/inspector/InspectorWorkerAgent.h" |
| 34 | 34 |
| 35 #include "core/InspectorFrontend.h" | 35 #include "core/InspectorFrontend.h" |
| 36 #include "core/inspector/InspectorState.h" | 36 #include "core/inspector/InspectorState.h" |
| 37 #include "core/inspector/InstrumentingAgents.h" | 37 #include "core/inspector/InstrumentingAgents.h" |
| 38 #include "core/inspector/JSONParser.h" | 38 #include "core/inspector/JSONParser.h" |
| 39 #include "core/workers/WorkerGlobalScopeProxy.h" | 39 #include "core/workers/WorkerInspectorProxy.h" |
| 40 #include "platform/JSONValues.h" | 40 #include "platform/JSONValues.h" |
| 41 #include "platform/weborigin/KURL.h" | 41 #include "platform/weborigin/KURL.h" |
| 42 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
| 43 #include "wtf/RefPtr.h" | 43 #include "wtf/RefPtr.h" |
| 44 #include "wtf/text/WTFString.h" |
| 44 | 45 |
| 45 namespace blink { | 46 namespace blink { |
| 46 | 47 |
| 47 namespace WorkerAgentState { | 48 namespace WorkerAgentState { |
| 48 static const char workerInspectionEnabled[] = "workerInspectionEnabled"; | 49 static const char workerInspectionEnabled[] = "workerInspectionEnabled"; |
| 49 static const char autoconnectToWorkers[] = "autoconnectToWorkers"; | 50 static const char autoconnectToWorkers[] = "autoconnectToWorkers"; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 class InspectorWorkerAgent::WorkerFrontendChannel FINAL : public WorkerGlobalSco
peProxy::PageInspector { | 53 class InspectorWorkerAgent::WorkerFrontendChannel FINAL : public WorkerInspector
Proxy::PageInspector { |
| 53 WTF_MAKE_FAST_ALLOCATED; | 54 WTF_MAKE_FAST_ALLOCATED; |
| 54 public: | 55 public: |
| 55 explicit WorkerFrontendChannel(InspectorFrontend::Worker* frontend, WorkerGl
obalScopeProxy* proxy) | 56 explicit WorkerFrontendChannel(InspectorFrontend::Worker* frontend, WorkerIn
spectorProxy* proxy) |
| 56 : m_frontend(frontend) | 57 : m_frontend(frontend) |
| 57 , m_proxy(proxy) | 58 , m_proxy(proxy) |
| 58 , m_id(s_nextId++) | 59 , m_id(s_nextId++) |
| 59 , m_connected(false) | 60 , m_connected(false) |
| 60 { | 61 { |
| 61 } | 62 } |
| 62 virtual ~WorkerFrontendChannel() | 63 virtual ~WorkerFrontendChannel() |
| 63 { | 64 { |
| 64 disconnectFromWorkerGlobalScope(); | 65 disconnectFromWorker(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 int id() const { return m_id; } | 68 int id() const { return m_id; } |
| 68 WorkerGlobalScopeProxy* proxy() const { return m_proxy; } | 69 WorkerInspectorProxy* proxy() const { return m_proxy; } |
| 69 | 70 |
| 70 void connectToWorkerGlobalScope() | 71 void connectToWorker() |
| 71 { | 72 { |
| 72 if (m_connected) | 73 if (m_connected) |
| 73 return; | 74 return; |
| 74 m_connected = true; | 75 m_connected = true; |
| 75 m_proxy->connectToInspector(this); | 76 m_proxy->connectToInspector(this); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void disconnectFromWorkerGlobalScope() | 79 void disconnectFromWorker() |
| 79 { | 80 { |
| 80 if (!m_connected) | 81 if (!m_connected) |
| 81 return; | 82 return; |
| 82 m_connected = false; | 83 m_connected = false; |
| 83 m_proxy->disconnectFromInspector(); | 84 m_proxy->disconnectFromInspector(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 // WorkerGlobalScopeProxy::PageInspector implementation | 88 // WorkerInspectorProxy::PageInspector implementation |
| 88 virtual void dispatchMessageFromWorker(const String& message) OVERRIDE | 89 virtual void dispatchMessageFromWorker(const String& message) OVERRIDE |
| 89 { | 90 { |
| 90 RefPtr<JSONValue> value = parseJSON(message); | 91 RefPtr<JSONValue> value = parseJSON(message); |
| 91 if (!value) | 92 if (!value) |
| 92 return; | 93 return; |
| 93 RefPtr<JSONObject> messageObject = value->asObject(); | 94 RefPtr<JSONObject> messageObject = value->asObject(); |
| 94 if (!messageObject) | 95 if (!messageObject) |
| 95 return; | 96 return; |
| 96 m_frontend->dispatchMessageFromWorker(m_id, messageObject); | 97 m_frontend->dispatchMessageFromWorker(m_id, messageObject); |
| 97 } | 98 } |
| 98 | 99 |
| 99 InspectorFrontend::Worker* m_frontend; | 100 InspectorFrontend::Worker* m_frontend; |
| 100 WorkerGlobalScopeProxy* m_proxy; | 101 WorkerInspectorProxy* m_proxy; |
| 101 int m_id; | 102 int m_id; |
| 102 bool m_connected; | 103 bool m_connected; |
| 103 static int s_nextId; | 104 static int s_nextId; |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 int InspectorWorkerAgent::WorkerFrontendChannel::s_nextId = 1; | 107 int InspectorWorkerAgent::WorkerFrontendChannel::s_nextId = 1; |
| 107 | 108 |
| 108 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create() | 109 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create() |
| 109 { | 110 { |
| 110 return adoptPtrWillBeNoop(new InspectorWorkerAgent()); | 111 return adoptPtrWillBeNoop(new InspectorWorkerAgent()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 165 |
| 165 void InspectorWorkerAgent::canInspectWorkers(ErrorString*, bool* result) | 166 void InspectorWorkerAgent::canInspectWorkers(ErrorString*, bool* result) |
| 166 { | 167 { |
| 167 *result = true; | 168 *result = true; |
| 168 } | 169 } |
| 169 | 170 |
| 170 void InspectorWorkerAgent::connectToWorker(ErrorString* error, int workerId) | 171 void InspectorWorkerAgent::connectToWorker(ErrorString* error, int workerId) |
| 171 { | 172 { |
| 172 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); | 173 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); |
| 173 if (channel) | 174 if (channel) |
| 174 channel->connectToWorkerGlobalScope(); | 175 channel->connectToWorker(); |
| 175 else | 176 else |
| 176 *error = "Worker is gone"; | 177 *error = "Worker is gone"; |
| 177 } | 178 } |
| 178 | 179 |
| 179 void InspectorWorkerAgent::disconnectFromWorker(ErrorString* error, int workerId
) | 180 void InspectorWorkerAgent::disconnectFromWorker(ErrorString* error, int workerId
) |
| 180 { | 181 { |
| 181 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); | 182 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); |
| 182 if (channel) | 183 if (channel) |
| 183 channel->disconnectFromWorkerGlobalScope(); | 184 channel->disconnectFromWorker(); |
| 184 else | 185 else |
| 185 *error = "Worker is gone"; | 186 *error = "Worker is gone"; |
| 186 } | 187 } |
| 187 | 188 |
| 188 void InspectorWorkerAgent::sendMessageToWorker(ErrorString* error, int workerId,
const RefPtr<JSONObject>& message) | 189 void InspectorWorkerAgent::sendMessageToWorker(ErrorString* error, int workerId,
const RefPtr<JSONObject>& message) |
| 189 { | 190 { |
| 190 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); | 191 WorkerFrontendChannel* channel = m_idToChannel.get(workerId); |
| 191 if (channel) | 192 if (channel) |
| 192 channel->proxy()->sendMessageToInspector(message->toJSONString()); | 193 channel->proxy()->sendMessageToInspector(message->toJSONString()); |
| 193 else | 194 else |
| 194 *error = "Worker is gone"; | 195 *error = "Worker is gone"; |
| 195 } | 196 } |
| 196 | 197 |
| 197 void InspectorWorkerAgent::setAutoconnectToWorkers(ErrorString*, bool value) | 198 void InspectorWorkerAgent::setAutoconnectToWorkers(ErrorString*, bool value) |
| 198 { | 199 { |
| 199 m_state->setBoolean(WorkerAgentState::autoconnectToWorkers, value); | 200 m_state->setBoolean(WorkerAgentState::autoconnectToWorkers, value); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void InspectorWorkerAgent::setTracingSessionId(const String& sessionId) | 203 void InspectorWorkerAgent::setTracingSessionId(const String& sessionId) |
| 203 { | 204 { |
| 204 m_tracingSessionId = sessionId; | 205 m_tracingSessionId = sessionId; |
| 205 if (sessionId.isEmpty()) | 206 if (sessionId.isEmpty()) |
| 206 return; | 207 return; |
| 207 for (DedicatedWorkers::iterator it = m_dedicatedWorkers.begin(); it != m_ded
icatedWorkers.end(); ++it) | 208 for (WorkerIds::iterator it = m_workerIds.begin(); it != m_workerIds.end();
++it) |
| 208 it->key->writeTimelineStartedEvent(sessionId); | 209 it->key->writeTimelineStartedEvent(sessionId); |
| 209 } | 210 } |
| 210 | 211 |
| 211 bool InspectorWorkerAgent::shouldPauseDedicatedWorkerOnStart() | 212 bool InspectorWorkerAgent::shouldPauseDedicatedWorkerOnStart() |
| 212 { | 213 { |
| 213 return m_state->getBoolean(WorkerAgentState::autoconnectToWorkers); | 214 return m_state->getBoolean(WorkerAgentState::autoconnectToWorkers); |
| 214 } | 215 } |
| 215 | 216 |
| 216 void InspectorWorkerAgent::didStartWorkerGlobalScope(WorkerGlobalScopeProxy* wor
kerGlobalScopeProxy, const KURL& url) | 217 void InspectorWorkerAgent::didStartWorker(WorkerInspectorProxy* workerInspectorP
roxy, const KURL& url) |
| 217 { | 218 { |
| 218 m_dedicatedWorkers.set(workerGlobalScopeProxy, url.string()); | 219 m_workerIds.set(workerInspectorProxy, url.string()); |
| 219 if (m_frontend && m_state->getBoolean(WorkerAgentState::workerInspectionEnab
led)) | 220 if (m_frontend && m_state->getBoolean(WorkerAgentState::workerInspectionEnab
led)) |
| 220 createWorkerFrontendChannel(workerGlobalScopeProxy, url.string()); | 221 createWorkerFrontendChannel(workerInspectorProxy, url.string()); |
| 221 if (!m_tracingSessionId.isEmpty()) | 222 if (!m_tracingSessionId.isEmpty()) |
| 222 workerGlobalScopeProxy->writeTimelineStartedEvent(m_tracingSessionId); | 223 workerInspectorProxy->writeTimelineStartedEvent(m_tracingSessionId); |
| 223 } | 224 } |
| 224 | 225 |
| 225 void InspectorWorkerAgent::workerGlobalScopeTerminated(WorkerGlobalScopeProxy* p
roxy) | 226 void InspectorWorkerAgent::workerTerminated(WorkerInspectorProxy* proxy) |
| 226 { | 227 { |
| 227 m_dedicatedWorkers.remove(proxy); | 228 m_workerIds.remove(proxy); |
| 228 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { | 229 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { |
| 229 if (proxy == it->value->proxy()) { | 230 if (proxy == it->value->proxy()) { |
| 230 m_frontend->workerTerminated(it->key); | 231 m_frontend->workerTerminated(it->key); |
| 231 delete it->value; | 232 delete it->value; |
| 232 m_idToChannel.remove(it); | 233 m_idToChannel.remove(it); |
| 233 return; | 234 return; |
| 234 } | 235 } |
| 235 } | 236 } |
| 236 } | 237 } |
| 237 | 238 |
| 238 void InspectorWorkerAgent::createWorkerFrontendChannelsForExistingWorkers() | 239 void InspectorWorkerAgent::createWorkerFrontendChannelsForExistingWorkers() |
| 239 { | 240 { |
| 240 for (DedicatedWorkers::iterator it = m_dedicatedWorkers.begin(); it != m_ded
icatedWorkers.end(); ++it) | 241 for (WorkerIds::iterator it = m_workerIds.begin(); it != m_workerIds.end();
++it) |
| 241 createWorkerFrontendChannel(it->key, it->value); | 242 createWorkerFrontendChannel(it->key, it->value); |
| 242 } | 243 } |
| 243 | 244 |
| 244 void InspectorWorkerAgent::destroyWorkerFrontendChannels() | 245 void InspectorWorkerAgent::destroyWorkerFrontendChannels() |
| 245 { | 246 { |
| 246 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { | 247 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { |
| 247 it->value->disconnectFromWorkerGlobalScope(); | 248 it->value->disconnectFromWorker(); |
| 248 delete it->value; | 249 delete it->value; |
| 249 } | 250 } |
| 250 m_idToChannel.clear(); | 251 m_idToChannel.clear(); |
| 251 } | 252 } |
| 252 | 253 |
| 253 void InspectorWorkerAgent::createWorkerFrontendChannel(WorkerGlobalScopeProxy* w
orkerGlobalScopeProxy, const String& url) | 254 void InspectorWorkerAgent::createWorkerFrontendChannel(WorkerInspectorProxy* wor
kerInspectorProxy, const String& url) |
| 254 { | 255 { |
| 255 WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_frontend, worke
rGlobalScopeProxy); | 256 WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_frontend, worke
rInspectorProxy); |
| 256 m_idToChannel.set(channel->id(), channel); | 257 m_idToChannel.set(channel->id(), channel); |
| 257 | 258 |
| 258 ASSERT(m_frontend); | 259 ASSERT(m_frontend); |
| 259 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec
tToWorkers); | 260 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec
tToWorkers); |
| 260 if (autoconnectToWorkers) | 261 if (autoconnectToWorkers) |
| 261 channel->connectToWorkerGlobalScope(); | 262 channel->connectToWorker(); |
| 262 m_frontend->workerCreated(channel->id(), url, autoconnectToWorkers); | 263 m_frontend->workerCreated(channel->id(), url, autoconnectToWorkers); |
| 263 } | 264 } |
| 264 | 265 |
| 265 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |