| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/inspector/AsyncCallTracker.h" | 32 #include "core/inspector/AsyncCallTracker.h" |
| 33 | 33 |
| 34 #include "core/dom/ContextLifecycleObserver.h" | 34 #include "core/dom/ContextLifecycleObserver.h" |
| 35 #include "core/dom/ExecutionContext.h" | 35 #include "core/dom/ExecutionContext.h" |
| 36 #include "core/dom/ExecutionContextTask.h" | 36 #include "core/dom/ExecutionContextTask.h" |
| 37 #include "core/events/Event.h" | 37 #include "core/events/Event.h" |
| 38 #include "core/events/EventTarget.h" | 38 #include "core/events/EventTarget.h" |
| 39 #include "core/inspector/AsyncOperationMap.h" | 39 #include "core/inspector/AsyncOperationMap.h" |
| 40 #include "core/inspector/InspectorDebuggerAgent.h" | 40 #include "core/inspector/V8DebuggerAgent.h" |
| 41 #include "core/xmlhttprequest/XMLHttpRequest.h" | 41 #include "core/xmlhttprequest/XMLHttpRequest.h" |
| 42 #include "core/xmlhttprequest/XMLHttpRequestUpload.h" | 42 #include "core/xmlhttprequest/XMLHttpRequestUpload.h" |
| 43 #include "platform/ScriptForbiddenScope.h" | 43 #include "platform/ScriptForbiddenScope.h" |
| 44 #include "wtf/MainThread.h" | 44 #include "wtf/MainThread.h" |
| 45 #include "wtf/text/StringBuilder.h" | 45 #include "wtf/text/StringBuilder.h" |
| 46 #include "wtf/text/StringHash.h" | 46 #include "wtf/text/StringHash.h" |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 static const char setTimeoutName[] = "setTimeout"; | 50 static const char setTimeoutName[] = "setTimeout"; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) | 130 static XMLHttpRequest* toXmlHttpRequest(EventTarget* eventTarget) |
| 131 { | 131 { |
| 132 const AtomicString& interfaceName = eventTarget->interfaceName(); | 132 const AtomicString& interfaceName = eventTarget->interfaceName(); |
| 133 if (interfaceName == EventTargetNames::XMLHttpRequest) | 133 if (interfaceName == EventTargetNames::XMLHttpRequest) |
| 134 return static_cast<XMLHttpRequest*>(eventTarget); | 134 return static_cast<XMLHttpRequest*>(eventTarget); |
| 135 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) | 135 if (interfaceName == EventTargetNames::XMLHttpRequestUpload) |
| 136 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; | 136 return static_cast<XMLHttpRequestUpload*>(eventTarget)->xmlHttpRequest()
; |
| 137 return nullptr; | 137 return nullptr; |
| 138 } | 138 } |
| 139 | 139 |
| 140 AsyncCallTracker::AsyncCallTracker(InspectorDebuggerAgent* debuggerAgent, Instru
mentingAgents* instrumentingAgents) | 140 AsyncCallTracker::AsyncCallTracker(V8DebuggerAgent* debuggerAgent, Instrumenting
Agents* instrumentingAgents) |
| 141 : m_debuggerAgent(debuggerAgent) | 141 : m_debuggerAgent(debuggerAgent) |
| 142 , m_instrumentingAgents(instrumentingAgents) | 142 , m_instrumentingAgents(instrumentingAgents) |
| 143 { | 143 { |
| 144 m_debuggerAgent->addAsyncCallTrackingListener(this); | 144 m_debuggerAgent->addAsyncCallTrackingListener(this); |
| 145 } | 145 } |
| 146 | 146 |
| 147 AsyncCallTracker::~AsyncCallTracker() | 147 AsyncCallTracker::~AsyncCallTracker() |
| 148 { | 148 { |
| 149 #if !ENABLE(OILPAN) | 149 #if !ENABLE(OILPAN) |
| 150 m_debuggerAgent->removeAsyncCallTrackingListener(this); | 150 m_debuggerAgent->removeAsyncCallTrackingListener(this); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 bool AsyncCallTracker::willFireTimer(ExecutionContext* context, int timerId) | 191 bool AsyncCallTracker::willFireTimer(ExecutionContext* context, int timerId) |
| 192 { | 192 { |
| 193 ASSERT(context); | 193 ASSERT(context); |
| 194 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 194 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 195 ASSERT(timerId > 0); | 195 ASSERT(timerId > 0); |
| 196 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { | 196 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { |
| 197 willFireAsyncCall(data->m_timerCallChains.get(timerId)); | 197 willFireAsyncCall(data->m_timerCallChains.get(timerId)); |
| 198 if (!data->m_intervalTimerIds.contains(timerId)) | 198 if (!data->m_intervalTimerIds.contains(timerId)) |
| 199 data->m_timerCallChains.remove(timerId); | 199 data->m_timerCallChains.remove(timerId); |
| 200 } else { | 200 } else { |
| 201 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId); | 201 willFireAsyncCall(V8DebuggerAgent::unknownAsyncOperationId); |
| 202 } | 202 } |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void AsyncCallTracker::didRequestAnimationFrame(ExecutionContext* context, int c
allbackId) | 206 void AsyncCallTracker::didRequestAnimationFrame(ExecutionContext* context, int c
allbackId) |
| 207 { | 207 { |
| 208 ASSERT(context); | 208 ASSERT(context); |
| 209 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 209 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 210 int operationId = m_debuggerAgent->traceAsyncOperationStarting(requestAnimat
ionFrameName); | 210 int operationId = m_debuggerAgent->traceAsyncOperationStarting(requestAnimat
ionFrameName); |
| 211 ASSERT(callbackId > 0); | 211 ASSERT(callbackId > 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 225 | 225 |
| 226 bool AsyncCallTracker::willFireAnimationFrame(ExecutionContext* context, int cal
lbackId) | 226 bool AsyncCallTracker::willFireAnimationFrame(ExecutionContext* context, int cal
lbackId) |
| 227 { | 227 { |
| 228 ASSERT(context); | 228 ASSERT(context); |
| 229 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 229 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 230 ASSERT(callbackId > 0); | 230 ASSERT(callbackId > 0); |
| 231 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { | 231 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { |
| 232 willFireAsyncCall(data->m_animationFrameCallChains.get(callbackId)); | 232 willFireAsyncCall(data->m_animationFrameCallChains.get(callbackId)); |
| 233 data->m_animationFrameCallChains.remove(callbackId); | 233 data->m_animationFrameCallChains.remove(callbackId); |
| 234 } else { | 234 } else { |
| 235 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId); | 235 willFireAsyncCall(V8DebuggerAgent::unknownAsyncOperationId); |
| 236 } | 236 } |
| 237 return true; | 237 return true; |
| 238 } | 238 } |
| 239 | 239 |
| 240 void AsyncCallTracker::didEnqueueEvent(EventTarget* eventTarget, Event* event) | 240 void AsyncCallTracker::didEnqueueEvent(EventTarget* eventTarget, Event* event) |
| 241 { | 241 { |
| 242 ASSERT(eventTarget->executionContext()); | 242 ASSERT(eventTarget->executionContext()); |
| 243 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 243 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 244 OwnPtr<ScriptForbiddenScope::AllowUserAgentScript> allowScripting; | 244 OwnPtr<ScriptForbiddenScope::AllowUserAgentScript> allowScripting; |
| 245 if (isMainThread()) | 245 if (isMainThread()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 261 { | 261 { |
| 262 ASSERT(eventTarget->executionContext()); | 262 ASSERT(eventTarget->executionContext()); |
| 263 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 263 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 264 if (XMLHttpRequest* xhr = toXmlHttpRequest(eventTarget)) { | 264 if (XMLHttpRequest* xhr = toXmlHttpRequest(eventTarget)) { |
| 265 willHandleXHREvent(xhr, event); | 265 willHandleXHREvent(xhr, event); |
| 266 } else { | 266 } else { |
| 267 ExecutionContext* context = eventTarget->executionContext(); | 267 ExecutionContext* context = eventTarget->executionContext(); |
| 268 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | 268 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
| 269 willFireAsyncCall(data->m_eventCallChains.get(event)); | 269 willFireAsyncCall(data->m_eventCallChains.get(event)); |
| 270 else | 270 else |
| 271 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId); | 271 willFireAsyncCall(V8DebuggerAgent::unknownAsyncOperationId); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 void AsyncCallTracker::willLoadXHR(XMLHttpRequest* xhr, ThreadableLoaderClient*,
const AtomicString&, const KURL&, bool async, PassRefPtr<FormData>, const HTTPH
eaderMap&, bool) | 275 void AsyncCallTracker::willLoadXHR(XMLHttpRequest* xhr, ThreadableLoaderClient*,
const AtomicString&, const KURL&, bool async, PassRefPtr<FormData>, const HTTPH
eaderMap&, bool) |
| 276 { | 276 { |
| 277 ASSERT(xhr->executionContext()); | 277 ASSERT(xhr->executionContext()); |
| 278 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 278 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 279 if (!async) | 279 if (!async) |
| 280 return; | 280 return; |
| 281 int operationId = m_debuggerAgent->traceAsyncOperationStarting(xhrSendName); | 281 int operationId = m_debuggerAgent->traceAsyncOperationStarting(xhrSendName); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 292 } | 292 } |
| 293 | 293 |
| 294 void AsyncCallTracker::willHandleXHREvent(XMLHttpRequest* xhr, Event* event) | 294 void AsyncCallTracker::willHandleXHREvent(XMLHttpRequest* xhr, Event* event) |
| 295 { | 295 { |
| 296 ExecutionContext* context = xhr->executionContext(); | 296 ExecutionContext* context = xhr->executionContext(); |
| 297 ASSERT(context); | 297 ASSERT(context); |
| 298 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 298 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 299 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | 299 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
| 300 willFireAsyncCall(data->m_xhrCallChains.get(xhr)); | 300 willFireAsyncCall(data->m_xhrCallChains.get(xhr)); |
| 301 else | 301 else |
| 302 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId); | 302 willFireAsyncCall(V8DebuggerAgent::unknownAsyncOperationId); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void AsyncCallTracker::didEnqueueMutationRecord(ExecutionContext* context, Mutat
ionObserver* observer) | 305 void AsyncCallTracker::didEnqueueMutationRecord(ExecutionContext* context, Mutat
ionObserver* observer) |
| 306 { | 306 { |
| 307 ASSERT(context); | 307 ASSERT(context); |
| 308 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 308 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 309 ExecutionContextData* data = createContextDataIfNeeded(context); | 309 ExecutionContextData* data = createContextDataIfNeeded(context); |
| 310 if (data->m_mutationObserverCallChains.contains(observer)) | 310 if (data->m_mutationObserverCallChains.contains(observer)) |
| 311 return; | 311 return; |
| 312 int operationId = m_debuggerAgent->traceAsyncOperationStarting(enqueueMutati
onRecordName); | 312 int operationId = m_debuggerAgent->traceAsyncOperationStarting(enqueueMutati
onRecordName); |
| 313 data->m_mutationObserverCallChains.set(observer, operationId); | 313 data->m_mutationObserverCallChains.set(observer, operationId); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void AsyncCallTracker::didClearAllMutationRecords(ExecutionContext* context, Mut
ationObserver* observer) | 316 void AsyncCallTracker::didClearAllMutationRecords(ExecutionContext* context, Mut
ationObserver* observer) |
| 317 { | 317 { |
| 318 ASSERT(context); | 318 ASSERT(context); |
| 319 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 319 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 320 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | 320 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
| 321 data->m_mutationObserverCallChains.remove(observer); | 321 data->m_mutationObserverCallChains.remove(observer); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void AsyncCallTracker::willDeliverMutationRecords(ExecutionContext* context, Mut
ationObserver* observer) | 324 void AsyncCallTracker::willDeliverMutationRecords(ExecutionContext* context, Mut
ationObserver* observer) |
| 325 { | 325 { |
| 326 ASSERT(context); | 326 ASSERT(context); |
| 327 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 327 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 328 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { | 328 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { |
| 329 willFireAsyncCall(data->m_mutationObserverCallChains.get(observer)); | 329 willFireAsyncCall(data->m_mutationObserverCallChains.get(observer)); |
| 330 data->m_mutationObserverCallChains.remove(observer); | 330 data->m_mutationObserverCallChains.remove(observer); |
| 331 } else { | 331 } else { |
| 332 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId); | 332 willFireAsyncCall(V8DebuggerAgent::unknownAsyncOperationId); |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 | 335 |
| 336 void AsyncCallTracker::didPostExecutionContextTask(ExecutionContext* context, Ex
ecutionContextTask* task) | 336 void AsyncCallTracker::didPostExecutionContextTask(ExecutionContext* context, Ex
ecutionContextTask* task) |
| 337 { | 337 { |
| 338 ASSERT(context); | 338 ASSERT(context); |
| 339 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 339 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 340 if (task->taskNameForInstrumentation().isEmpty()) | 340 if (task->taskNameForInstrumentation().isEmpty()) |
| 341 return; | 341 return; |
| 342 int operationId = m_debuggerAgent->traceAsyncOperationStarting(task->taskNam
eForInstrumentation()); | 342 int operationId = m_debuggerAgent->traceAsyncOperationStarting(task->taskNam
eForInstrumentation()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 353 } | 353 } |
| 354 | 354 |
| 355 void AsyncCallTracker::willPerformExecutionContextTask(ExecutionContext* context
, ExecutionContextTask* task) | 355 void AsyncCallTracker::willPerformExecutionContextTask(ExecutionContext* context
, ExecutionContextTask* task) |
| 356 { | 356 { |
| 357 ASSERT(context); | 357 ASSERT(context); |
| 358 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 358 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 359 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { | 359 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) { |
| 360 willFireAsyncCall(data->m_executionContextTaskCallChains.get(task)); | 360 willFireAsyncCall(data->m_executionContextTaskCallChains.get(task)); |
| 361 data->m_executionContextTaskCallChains.remove(task); | 361 data->m_executionContextTaskCallChains.remove(task); |
| 362 } else { | 362 } else { |
| 363 willFireAsyncCall(InspectorDebuggerAgent::unknownAsyncOperationId); | 363 willFireAsyncCall(V8DebuggerAgent::unknownAsyncOperationId); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 int AsyncCallTracker::traceAsyncOperationStarting(ExecutionContext* context, con
st String& operationName, int prevOperationId) | 367 int AsyncCallTracker::traceAsyncOperationStarting(ExecutionContext* context, con
st String& operationName, int prevOperationId) |
| 368 { | 368 { |
| 369 ASSERT(context); | 369 ASSERT(context); |
| 370 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 370 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 371 if (prevOperationId) | 371 if (prevOperationId) |
| 372 traceAsyncOperationCompleted(context, prevOperationId); | 372 traceAsyncOperationCompleted(context, prevOperationId); |
| 373 int operationId = m_debuggerAgent->traceAsyncOperationStarting(operationName
); | 373 int operationId = m_debuggerAgent->traceAsyncOperationStarting(operationName
); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 399 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) | 399 if (ExecutionContextData* data = m_executionContextDataMap.get(context)) |
| 400 return data->m_asyncOperations.contains(operationId); | 400 return data->m_asyncOperations.contains(operationId); |
| 401 return false; | 401 return false; |
| 402 } | 402 } |
| 403 | 403 |
| 404 void AsyncCallTracker::traceAsyncCallbackStarting(ExecutionContext* context, int
operationId) | 404 void AsyncCallTracker::traceAsyncCallbackStarting(ExecutionContext* context, int
operationId) |
| 405 { | 405 { |
| 406 ASSERT(context); | 406 ASSERT(context); |
| 407 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 407 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 408 ASSERT(operationId <= 0 || isKnownAsyncOperationId(context, operationId)); | 408 ASSERT(operationId <= 0 || isKnownAsyncOperationId(context, operationId)); |
| 409 willFireAsyncCall(operationId > 0 ? operationId : InspectorDebuggerAgent::un
knownAsyncOperationId); | 409 willFireAsyncCall(operationId > 0 ? operationId : V8DebuggerAgent::unknownAs
yncOperationId); |
| 410 } | 410 } |
| 411 | 411 |
| 412 void AsyncCallTracker::didFireAsyncCall() | 412 void AsyncCallTracker::didFireAsyncCall() |
| 413 { | 413 { |
| 414 m_debuggerAgent->traceAsyncCallbackCompleted(); | 414 m_debuggerAgent->traceAsyncCallbackCompleted(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 void AsyncCallTracker::willFireAsyncCall(int operationId) | 417 void AsyncCallTracker::willFireAsyncCall(int operationId) |
| 418 { | 418 { |
| 419 m_debuggerAgent->traceAsyncCallbackStarting(operationId); | 419 m_debuggerAgent->traceAsyncCallbackStarting(operationId); |
| 420 } | 420 } |
| 421 | 421 |
| 422 AsyncCallTracker::ExecutionContextData* AsyncCallTracker::createContextDataIfNee
ded(ExecutionContext* context) | 422 AsyncCallTracker::ExecutionContextData* AsyncCallTracker::createContextDataIfNee
ded(ExecutionContext* context) |
| 423 { | 423 { |
| 424 ExecutionContextData* data = m_executionContextDataMap.get(context); | 424 ExecutionContextData* data = m_executionContextDataMap.get(context); |
| 425 if (!data) { | 425 if (!data) { |
| 426 data = m_executionContextDataMap.set(context, adoptPtrWillBeNoop(new Asy
ncCallTracker::ExecutionContextData(this, context))) | 426 data = m_executionContextDataMap.set(context, adoptPtrWillBeNoop(new Asy
ncCallTracker::ExecutionContextData(this, context))) |
| 427 .storedValue->value.get(); | 427 .storedValue->value.get(); |
| 428 } | 428 } |
| 429 return data; | 429 return data; |
| 430 } | 430 } |
| 431 | 431 |
| 432 DEFINE_TRACE(AsyncCallTracker) | 432 DEFINE_TRACE(AsyncCallTracker) |
| 433 { | 433 { |
| 434 #if ENABLE(OILPAN) | 434 #if ENABLE(OILPAN) |
| 435 visitor->trace(m_executionContextDataMap); | 435 visitor->trace(m_executionContextDataMap); |
| 436 visitor->trace(m_debuggerAgent); | 436 visitor->trace(m_debuggerAgent); |
| 437 visitor->trace(m_instrumentingAgents); | 437 visitor->trace(m_instrumentingAgents); |
| 438 #endif | 438 #endif |
| 439 InspectorDebuggerAgent::AsyncCallTrackingListener::trace(visitor); | 439 V8DebuggerAgent::AsyncCallTrackingListener::trace(visitor); |
| 440 } | 440 } |
| 441 | 441 |
| 442 } // namespace blink | 442 } // namespace blink |
| OLD | NEW |