| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 namespace WorkerAgentState { | 47 namespace WorkerAgentState { |
| 48 static const char workerInspectionEnabled[] = "workerInspectionEnabled"; | 48 static const char workerInspectionEnabled[] = "workerInspectionEnabled"; |
| 49 static const char autoconnectToWorkers[] = "autoconnectToWorkers"; | 49 static const char autoconnectToWorkers[] = "autoconnectToWorkers"; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class InspectorWorkerAgent::WorkerFrontendChannel FINAL : public WorkerGlobalSco
peProxy::PageInspector { | 52 class InspectorWorkerAgent::WorkerFrontendChannel FINAL : public WorkerGlobalSco
peProxy::PageInspector { |
| 53 WTF_MAKE_FAST_ALLOCATED; | 53 WTF_MAKE_FAST_ALLOCATED; |
| 54 public: | 54 public: |
| 55 explicit WorkerFrontendChannel(InspectorFrontend* frontend, WorkerGlobalScop
eProxy* proxy) | 55 explicit WorkerFrontendChannel(InspectorFrontend::Worker* frontend, WorkerGl
obalScopeProxy* proxy) |
| 56 : m_frontend(frontend) | 56 : m_frontend(frontend) |
| 57 , m_proxy(proxy) | 57 , m_proxy(proxy) |
| 58 , m_id(s_nextId++) | 58 , m_id(s_nextId++) |
| 59 , m_connected(false) | 59 , m_connected(false) |
| 60 { | 60 { |
| 61 } | 61 } |
| 62 virtual ~WorkerFrontendChannel() | 62 virtual ~WorkerFrontendChannel() |
| 63 { | 63 { |
| 64 disconnectFromWorkerGlobalScope(); | 64 disconnectFromWorkerGlobalScope(); |
| 65 } | 65 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 private: | 86 private: |
| 87 // WorkerGlobalScopeProxy::PageInspector implementation | 87 // WorkerGlobalScopeProxy::PageInspector implementation |
| 88 virtual void dispatchMessageFromWorker(const String& message) OVERRIDE | 88 virtual void dispatchMessageFromWorker(const String& message) OVERRIDE |
| 89 { | 89 { |
| 90 RefPtr<JSONValue> value = parseJSON(message); | 90 RefPtr<JSONValue> value = parseJSON(message); |
| 91 if (!value) | 91 if (!value) |
| 92 return; | 92 return; |
| 93 RefPtr<JSONObject> messageObject = value->asObject(); | 93 RefPtr<JSONObject> messageObject = value->asObject(); |
| 94 if (!messageObject) | 94 if (!messageObject) |
| 95 return; | 95 return; |
| 96 m_frontend->worker()->dispatchMessageFromWorker(m_id, messageObject); | 96 m_frontend->dispatchMessageFromWorker(m_id, messageObject); |
| 97 } | 97 } |
| 98 | 98 |
| 99 InspectorFrontend* m_frontend; | 99 InspectorFrontend::Worker* m_frontend; |
| 100 WorkerGlobalScopeProxy* m_proxy; | 100 WorkerGlobalScopeProxy* m_proxy; |
| 101 int m_id; | 101 int m_id; |
| 102 bool m_connected; | 102 bool m_connected; |
| 103 static int s_nextId; | 103 static int s_nextId; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 int InspectorWorkerAgent::WorkerFrontendChannel::s_nextId = 1; | 106 int InspectorWorkerAgent::WorkerFrontendChannel::s_nextId = 1; |
| 107 | 107 |
| 108 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create() | 108 PassOwnPtrWillBeRawPtr<InspectorWorkerAgent> InspectorWorkerAgent::create() |
| 109 { | 109 { |
| 110 return adoptPtrWillBeNoop(new InspectorWorkerAgent()); | 110 return adoptPtrWillBeNoop(new InspectorWorkerAgent()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 InspectorWorkerAgent::InspectorWorkerAgent() | 113 InspectorWorkerAgent::InspectorWorkerAgent() |
| 114 : InspectorBaseAgent<InspectorWorkerAgent>("Worker") | 114 : InspectorBaseAgent<InspectorWorkerAgent>("Worker") |
| 115 , m_inspectorFrontend(0) | 115 , m_frontend(0) |
| 116 { | 116 { |
| 117 } | 117 } |
| 118 | 118 |
| 119 InspectorWorkerAgent::~InspectorWorkerAgent() | 119 InspectorWorkerAgent::~InspectorWorkerAgent() |
| 120 { | 120 { |
| 121 #if !ENABLE(OILPAN) | 121 #if !ENABLE(OILPAN) |
| 122 m_instrumentingAgents->setInspectorWorkerAgent(0); | 122 m_instrumentingAgents->setInspectorWorkerAgent(0); |
| 123 #endif | 123 #endif |
| 124 } | 124 } |
| 125 | 125 |
| 126 void InspectorWorkerAgent::init() | 126 void InspectorWorkerAgent::init() |
| 127 { | 127 { |
| 128 m_instrumentingAgents->setInspectorWorkerAgent(this); | 128 m_instrumentingAgents->setInspectorWorkerAgent(this); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void InspectorWorkerAgent::setFrontend(InspectorFrontend* frontend) | 131 void InspectorWorkerAgent::setFrontend(InspectorFrontend* frontend) |
| 132 { | 132 { |
| 133 m_inspectorFrontend = frontend; | 133 m_frontend = frontend->worker(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void InspectorWorkerAgent::restore() | 136 void InspectorWorkerAgent::restore() |
| 137 { | 137 { |
| 138 if (m_state->getBoolean(WorkerAgentState::workerInspectionEnabled)) | 138 if (m_state->getBoolean(WorkerAgentState::workerInspectionEnabled)) |
| 139 createWorkerFrontendChannelsForExistingWorkers(); | 139 createWorkerFrontendChannelsForExistingWorkers(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void InspectorWorkerAgent::clearFrontend() | 142 void InspectorWorkerAgent::clearFrontend() |
| 143 { | 143 { |
| 144 m_state->setBoolean(WorkerAgentState::autoconnectToWorkers, false); | 144 m_state->setBoolean(WorkerAgentState::autoconnectToWorkers, false); |
| 145 disable(0); | 145 disable(0); |
| 146 m_inspectorFrontend = 0; | 146 m_frontend = 0; |
| 147 } | 147 } |
| 148 | 148 |
| 149 void InspectorWorkerAgent::enable(ErrorString*) | 149 void InspectorWorkerAgent::enable(ErrorString*) |
| 150 { | 150 { |
| 151 m_state->setBoolean(WorkerAgentState::workerInspectionEnabled, true); | 151 m_state->setBoolean(WorkerAgentState::workerInspectionEnabled, true); |
| 152 if (!m_inspectorFrontend) | 152 if (!m_frontend) |
| 153 return; | 153 return; |
| 154 createWorkerFrontendChannelsForExistingWorkers(); | 154 createWorkerFrontendChannelsForExistingWorkers(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void InspectorWorkerAgent::disable(ErrorString*) | 157 void InspectorWorkerAgent::disable(ErrorString*) |
| 158 { | 158 { |
| 159 m_state->setBoolean(WorkerAgentState::workerInspectionEnabled, false); | 159 m_state->setBoolean(WorkerAgentState::workerInspectionEnabled, false); |
| 160 if (!m_inspectorFrontend) | 160 if (!m_frontend) |
| 161 return; | 161 return; |
| 162 destroyWorkerFrontendChannels(); | 162 destroyWorkerFrontendChannels(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void InspectorWorkerAgent::canInspectWorkers(ErrorString*, bool* result) | 165 void InspectorWorkerAgent::canInspectWorkers(ErrorString*, bool* result) |
| 166 { | 166 { |
| 167 *result = true; | 167 *result = true; |
| 168 } | 168 } |
| 169 | 169 |
| 170 void InspectorWorkerAgent::connectToWorker(ErrorString* error, int workerId) | 170 void InspectorWorkerAgent::connectToWorker(ErrorString* error, int workerId) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 | 210 |
| 211 bool InspectorWorkerAgent::shouldPauseDedicatedWorkerOnStart() | 211 bool InspectorWorkerAgent::shouldPauseDedicatedWorkerOnStart() |
| 212 { | 212 { |
| 213 return m_state->getBoolean(WorkerAgentState::autoconnectToWorkers); | 213 return m_state->getBoolean(WorkerAgentState::autoconnectToWorkers); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void InspectorWorkerAgent::didStartWorkerGlobalScope(WorkerGlobalScopeProxy* wor
kerGlobalScopeProxy, const KURL& url) | 216 void InspectorWorkerAgent::didStartWorkerGlobalScope(WorkerGlobalScopeProxy* wor
kerGlobalScopeProxy, const KURL& url) |
| 217 { | 217 { |
| 218 m_dedicatedWorkers.set(workerGlobalScopeProxy, url.string()); | 218 m_dedicatedWorkers.set(workerGlobalScopeProxy, url.string()); |
| 219 if (m_inspectorFrontend && m_state->getBoolean(WorkerAgentState::workerInspe
ctionEnabled)) | 219 if (m_frontend && m_state->getBoolean(WorkerAgentState::workerInspectionEnab
led)) |
| 220 createWorkerFrontendChannel(workerGlobalScopeProxy, url.string()); | 220 createWorkerFrontendChannel(workerGlobalScopeProxy, url.string()); |
| 221 if (!m_tracingSessionId.isEmpty()) | 221 if (!m_tracingSessionId.isEmpty()) |
| 222 workerGlobalScopeProxy->writeTimelineStartedEvent(m_tracingSessionId); | 222 workerGlobalScopeProxy->writeTimelineStartedEvent(m_tracingSessionId); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void InspectorWorkerAgent::workerGlobalScopeTerminated(WorkerGlobalScopeProxy* p
roxy) | 225 void InspectorWorkerAgent::workerGlobalScopeTerminated(WorkerGlobalScopeProxy* p
roxy) |
| 226 { | 226 { |
| 227 m_dedicatedWorkers.remove(proxy); | 227 m_dedicatedWorkers.remove(proxy); |
| 228 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { | 228 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { |
| 229 if (proxy == it->value->proxy()) { | 229 if (proxy == it->value->proxy()) { |
| 230 m_inspectorFrontend->worker()->workerTerminated(it->key); | 230 m_frontend->workerTerminated(it->key); |
| 231 delete it->value; | 231 delete it->value; |
| 232 m_idToChannel.remove(it); | 232 m_idToChannel.remove(it); |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 void InspectorWorkerAgent::createWorkerFrontendChannelsForExistingWorkers() | 238 void InspectorWorkerAgent::createWorkerFrontendChannelsForExistingWorkers() |
| 239 { | 239 { |
| 240 for (DedicatedWorkers::iterator it = m_dedicatedWorkers.begin(); it != m_ded
icatedWorkers.end(); ++it) | 240 for (DedicatedWorkers::iterator it = m_dedicatedWorkers.begin(); it != m_ded
icatedWorkers.end(); ++it) |
| 241 createWorkerFrontendChannel(it->key, it->value); | 241 createWorkerFrontendChannel(it->key, it->value); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void InspectorWorkerAgent::destroyWorkerFrontendChannels() | 244 void InspectorWorkerAgent::destroyWorkerFrontendChannels() |
| 245 { | 245 { |
| 246 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { | 246 for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChanne
l.end(); ++it) { |
| 247 it->value->disconnectFromWorkerGlobalScope(); | 247 it->value->disconnectFromWorkerGlobalScope(); |
| 248 delete it->value; | 248 delete it->value; |
| 249 } | 249 } |
| 250 m_idToChannel.clear(); | 250 m_idToChannel.clear(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void InspectorWorkerAgent::createWorkerFrontendChannel(WorkerGlobalScopeProxy* w
orkerGlobalScopeProxy, const String& url) | 253 void InspectorWorkerAgent::createWorkerFrontendChannel(WorkerGlobalScopeProxy* w
orkerGlobalScopeProxy, const String& url) |
| 254 { | 254 { |
| 255 WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_inspectorFronte
nd, workerGlobalScopeProxy); | 255 WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_frontend, worke
rGlobalScopeProxy); |
| 256 m_idToChannel.set(channel->id(), channel); | 256 m_idToChannel.set(channel->id(), channel); |
| 257 | 257 |
| 258 ASSERT(m_inspectorFrontend); | 258 ASSERT(m_frontend); |
| 259 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec
tToWorkers); | 259 bool autoconnectToWorkers = m_state->getBoolean(WorkerAgentState::autoconnec
tToWorkers); |
| 260 if (autoconnectToWorkers) | 260 if (autoconnectToWorkers) |
| 261 channel->connectToWorkerGlobalScope(); | 261 channel->connectToWorkerGlobalScope(); |
| 262 m_inspectorFrontend->worker()->workerCreated(channel->id(), url, autoconnect
ToWorkers); | 262 m_frontend->workerCreated(channel->id(), url, autoconnectToWorkers); |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace blink | 265 } // namespace blink |
| OLD | NEW |