OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010-2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2010-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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 247 |
248 void unmuteWarningsAndDeprecations() | 248 void unmuteWarningsAndDeprecations() |
249 { | 249 { |
250 FrameConsole::unmute(); | 250 FrameConsole::unmute(); |
251 UseCounter::unmuteForInspector(); | 251 UseCounter::unmuteForInspector(); |
252 } | 252 } |
253 }; | 253 }; |
254 | 254 |
255 class DebuggerTask : public InspectorTaskRunner::Task { | 255 class DebuggerTask : public InspectorTaskRunner::Task { |
256 public: | 256 public: |
257 DebuggerTask(int sessionId, PassOwnPtr<WebDevToolsAgent::MessageDescriptor>
descriptor) | 257 DebuggerTask(PassOwnPtr<WebDevToolsAgent::MessageDescriptor> descriptor) |
258 : m_sessionId(sessionId) | 258 : m_descriptor(descriptor) |
259 , m_descriptor(descriptor) | |
260 { | 259 { |
261 } | 260 } |
262 | 261 |
263 ~DebuggerTask() override {} | 262 ~DebuggerTask() override {} |
264 virtual void run() | 263 virtual void run() |
265 { | 264 { |
266 WebDevToolsAgent* webagent = m_descriptor->agent(); | 265 WebDevToolsAgent* webagent = m_descriptor->agent(); |
267 if (!webagent) | 266 if (!webagent) |
268 return; | 267 return; |
269 | 268 |
270 WebDevToolsAgentImpl* agentImpl = static_cast<WebDevToolsAgentImpl*>(web
agent); | 269 WebDevToolsAgentImpl* agentImpl = static_cast<WebDevToolsAgentImpl*>(web
agent); |
271 if (agentImpl->m_attached) | 270 if (agentImpl->m_attached) |
272 agentImpl->dispatchMessageFromFrontend(m_sessionId, m_descriptor->me
ssage()); | 271 agentImpl->dispatchMessageFromFrontend(m_descriptor->message()); |
273 } | 272 } |
274 | 273 |
275 private: | 274 private: |
276 int m_sessionId; | |
277 OwnPtr<WebDevToolsAgent::MessageDescriptor> m_descriptor; | 275 OwnPtr<WebDevToolsAgent::MessageDescriptor> m_descriptor; |
278 }; | 276 }; |
279 | 277 |
280 // static | 278 // static |
281 PassOwnPtrWillBeRawPtr<WebDevToolsAgentImpl> WebDevToolsAgentImpl::create(WebLoc
alFrameImpl* frame, WebDevToolsAgentClient* client) | 279 PassOwnPtrWillBeRawPtr<WebDevToolsAgentImpl> WebDevToolsAgentImpl::create(WebLoc
alFrameImpl* frame, WebDevToolsAgentClient* client) |
282 { | 280 { |
283 WebViewImpl* view = frame->viewImpl(); | 281 WebViewImpl* view = frame->viewImpl(); |
284 // TODO(dgozman): sometimes view->mainFrameImpl() does return null, even tho
ugh |frame| is meant to be main frame. | 282 // TODO(dgozman): sometimes view->mainFrameImpl() does return null, even tho
ugh |frame| is meant to be main frame. |
285 // See http://crbug.com/526162. | 283 // See http://crbug.com/526162. |
286 bool isMainFrame = view && !frame->parent(); | 284 bool isMainFrame = view && !frame->parent(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 , m_inspectorAgent(nullptr) | 324 , m_inspectorAgent(nullptr) |
327 , m_domAgent(nullptr) | 325 , m_domAgent(nullptr) |
328 , m_pageAgent(nullptr) | 326 , m_pageAgent(nullptr) |
329 , m_resourceAgent(nullptr) | 327 , m_resourceAgent(nullptr) |
330 , m_layerTreeAgent(nullptr) | 328 , m_layerTreeAgent(nullptr) |
331 , m_tracingAgent(nullptr) | 329 , m_tracingAgent(nullptr) |
332 , m_pageRuntimeAgent(nullptr) | 330 , m_pageRuntimeAgent(nullptr) |
333 , m_pageConsoleAgent(nullptr) | 331 , m_pageConsoleAgent(nullptr) |
334 , m_agents(m_instrumentingAgents.get(), m_state.get()) | 332 , m_agents(m_instrumentingAgents.get(), m_state.get()) |
335 , m_deferredAgentsInitialized(false) | 333 , m_deferredAgentsInitialized(false) |
336 , m_sessionId(0) | |
337 { | 334 { |
338 ASSERT(isMainThread()); | 335 ASSERT(isMainThread()); |
339 ASSERT(m_webLocalFrameImpl->frame()); | 336 ASSERT(m_webLocalFrameImpl->frame()); |
340 | 337 |
341 long processId = Platform::current()->getUniqueIdForProcess(); | 338 long processId = Platform::current()->getUniqueIdForProcess(); |
342 ASSERT(processId > 0); | 339 ASSERT(processId > 0); |
343 IdentifiersFactory::setProcessId(processId); | 340 IdentifiersFactory::setProcessId(processId); |
344 InjectedScriptManager* injectedScriptManager = m_injectedScriptManager.get()
; | 341 InjectedScriptManager* injectedScriptManager = m_injectedScriptManager.get()
; |
345 | 342 |
346 OwnPtrWillBeRawPtr<InspectorInspectorAgent> inspectorAgentPtr(InspectorInspe
ctorAgent::create(injectedScriptManager)); | 343 OwnPtrWillBeRawPtr<InspectorInspectorAgent> inspectorAgentPtr(InspectorInspe
ctorAgent::create(injectedScriptManager)); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 490 |
494 if (m_overlay) | 491 if (m_overlay) |
495 m_overlay->init(cssAgent, debuggerAgent, m_domAgent.get()); | 492 m_overlay->init(cssAgent, debuggerAgent, m_domAgent.get()); |
496 } | 493 } |
497 | 494 |
498 void WebDevToolsAgentImpl::registerAgent(PassOwnPtrWillBeRawPtr<InspectorAgent>
agent) | 495 void WebDevToolsAgentImpl::registerAgent(PassOwnPtrWillBeRawPtr<InspectorAgent>
agent) |
499 { | 496 { |
500 m_agents.append(agent); | 497 m_agents.append(agent); |
501 } | 498 } |
502 | 499 |
503 void WebDevToolsAgentImpl::attach(const WebString& hostId, int sessionId) | 500 void WebDevToolsAgentImpl::attach(const WebString& hostId) |
504 { | 501 { |
505 if (m_attached) | 502 if (m_attached) |
506 return; | 503 return; |
507 | 504 |
508 // Set the attached bit first so that sync notifications were delivered. | 505 // Set the attached bit first so that sync notifications were delivered. |
509 m_attached = true; | 506 m_attached = true; |
510 m_sessionId = sessionId; | |
511 | 507 |
512 initializeDeferredAgents(); | 508 initializeDeferredAgents(); |
513 m_resourceAgent->setHostId(hostId); | 509 m_resourceAgent->setHostId(hostId); |
514 | 510 |
515 m_inspectorFrontend = adoptPtr(new InspectorFrontend(this)); | 511 m_inspectorFrontend = adoptPtr(new InspectorFrontend(this)); |
516 // We can reconnect to existing front-end -> unmute state. | 512 // We can reconnect to existing front-end -> unmute state. |
517 m_state->unmute(); | 513 m_state->unmute(); |
518 m_agents.setFrontend(m_inspectorFrontend.get()); | 514 m_agents.setFrontend(m_inspectorFrontend.get()); |
519 | 515 |
520 InspectorInstrumentation::registerInstrumentingAgents(m_instrumentingAgents.
get()); | 516 InspectorInstrumentation::registerInstrumentingAgents(m_instrumentingAgents.
get()); |
521 InspectorInstrumentation::frontendCreated(); | 517 InspectorInstrumentation::frontendCreated(); |
522 | 518 |
523 m_inspectorBackendDispatcher = InspectorBackendDispatcher::create(this); | 519 m_inspectorBackendDispatcher = InspectorBackendDispatcher::create(this); |
524 m_agents.registerInDispatcher(m_inspectorBackendDispatcher.get()); | 520 m_agents.registerInDispatcher(m_inspectorBackendDispatcher.get()); |
525 | 521 |
526 Platform::current()->currentThread()->addTaskObserver(this); | 522 Platform::current()->currentThread()->addTaskObserver(this); |
527 } | 523 } |
528 | 524 |
529 void WebDevToolsAgentImpl::reattach(const WebString& hostId, int sessionId, cons
t WebString& savedState) | 525 void WebDevToolsAgentImpl::reattach(const WebString& hostId, const WebString& sa
vedState) |
530 { | 526 { |
531 if (m_attached) | 527 if (m_attached) |
532 return; | 528 return; |
533 | 529 |
534 attach(hostId, sessionId); | 530 attach(hostId); |
535 m_state->loadFromCookie(savedState); | 531 m_state->loadFromCookie(savedState); |
536 m_agents.restore(); | 532 m_agents.restore(); |
537 } | 533 } |
538 | 534 |
539 void WebDevToolsAgentImpl::detach() | 535 void WebDevToolsAgentImpl::detach() |
540 { | 536 { |
541 if (!m_attached) | 537 if (!m_attached) |
542 return; | 538 return; |
543 | 539 |
544 Platform::current()->currentThread()->removeTaskObserver(this); | 540 Platform::current()->currentThread()->removeTaskObserver(this); |
545 | 541 |
546 m_inspectorBackendDispatcher->clearFrontend(); | 542 m_inspectorBackendDispatcher->clearFrontend(); |
547 m_inspectorBackendDispatcher.clear(); | 543 m_inspectorBackendDispatcher.clear(); |
548 | 544 |
549 // Destroying agents would change the state, but we don't want that. | 545 // Destroying agents would change the state, but we don't want that. |
550 // Pre-disconnect state will be used to restore inspector agents. | 546 // Pre-disconnect state will be used to restore inspector agents. |
551 m_state->mute(); | 547 m_state->mute(); |
552 m_agents.clearFrontend(); | 548 m_agents.clearFrontend(); |
553 m_inspectorFrontend.clear(); | 549 m_inspectorFrontend.clear(); |
554 | 550 |
555 // Release overlay resources. | 551 // Release overlay resources. |
556 if (m_overlay) | 552 if (m_overlay) |
557 m_overlay->clear(); | 553 m_overlay->clear(); |
558 InspectorInstrumentation::frontendDeleted(); | 554 InspectorInstrumentation::frontendDeleted(); |
559 InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgent
s.get()); | 555 InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgent
s.get()); |
560 | 556 |
561 m_sessionId = 0; | |
562 m_attached = false; | 557 m_attached = false; |
563 } | 558 } |
564 | 559 |
565 void WebDevToolsAgentImpl::continueProgram() | 560 void WebDevToolsAgentImpl::continueProgram() |
566 { | 561 { |
567 ClientMessageLoopAdapter::continueProgram(); | 562 ClientMessageLoopAdapter::continueProgram(); |
568 } | 563 } |
569 | 564 |
570 void WebDevToolsAgentImpl::didCommitLoadForLocalFrame(LocalFrame* frame) | 565 void WebDevToolsAgentImpl::didCommitLoadForLocalFrame(LocalFrame* frame) |
571 { | 566 { |
(...skipping 24 matching lines...) Expand all Loading... |
596 void WebDevToolsAgentImpl::enableTracing(const String& categoryFilter) | 591 void WebDevToolsAgentImpl::enableTracing(const String& categoryFilter) |
597 { | 592 { |
598 m_client->enableTracing(categoryFilter); | 593 m_client->enableTracing(categoryFilter); |
599 } | 594 } |
600 | 595 |
601 void WebDevToolsAgentImpl::disableTracing() | 596 void WebDevToolsAgentImpl::disableTracing() |
602 { | 597 { |
603 m_client->disableTracing(); | 598 m_client->disableTracing(); |
604 } | 599 } |
605 | 600 |
606 void WebDevToolsAgentImpl::dispatchOnInspectorBackend(int sessionId, const WebSt
ring& message) | 601 void WebDevToolsAgentImpl::dispatchOnInspectorBackend(const WebString& message) |
607 { | 602 { |
608 if (!m_attached) | 603 if (!m_attached) |
609 return; | 604 return; |
610 if (WebDevToolsAgent::shouldInterruptForMessage(message)) | 605 if (WebDevToolsAgent::shouldInterruptForMessage(message)) |
611 MainThreadDebugger::instance()->taskRunner()->runPendingTasks(); | 606 MainThreadDebugger::instance()->taskRunner()->runPendingTasks(); |
612 else | 607 else |
613 dispatchMessageFromFrontend(sessionId, message); | 608 dispatchMessageFromFrontend(message); |
614 } | 609 } |
615 | 610 |
616 void WebDevToolsAgentImpl::dispatchMessageFromFrontend(int sessionId, const Stri
ng& message) | 611 void WebDevToolsAgentImpl::dispatchMessageFromFrontend(const String& message) |
617 { | 612 { |
618 InspectorTaskRunner::IgnoreInterruptsScope scope(MainThreadDebugger::instanc
e()->taskRunner()); | 613 InspectorTaskRunner::IgnoreInterruptsScope scope(MainThreadDebugger::instanc
e()->taskRunner()); |
619 if (m_inspectorBackendDispatcher) | 614 if (m_inspectorBackendDispatcher) |
620 m_inspectorBackendDispatcher->dispatch(sessionId, message); | 615 m_inspectorBackendDispatcher->dispatch(message); |
621 } | 616 } |
622 | 617 |
623 void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& pointInRootFrame) | 618 void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& pointInRootFrame) |
624 { | 619 { |
625 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move | HitTestR
equest::ReadOnly | HitTestRequest::AllowChildFrameContent; | 620 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move | HitTestR
equest::ReadOnly | HitTestRequest::AllowChildFrameContent; |
626 HitTestRequest request(hitType); | 621 HitTestRequest request(hitType); |
627 WebMouseEvent dummyEvent; | 622 WebMouseEvent dummyEvent; |
628 dummyEvent.type = WebInputEvent::MouseDown; | 623 dummyEvent.type = WebInputEvent::MouseDown; |
629 dummyEvent.x = pointInRootFrame.x; | 624 dummyEvent.x = pointInRootFrame.x; |
630 dummyEvent.y = pointInRootFrame.y; | 625 dummyEvent.y = pointInRootFrame.y; |
631 IntPoint transformedPoint = PlatformMouseEventBuilder(m_webLocalFrameImpl->f
rameView(), dummyEvent).position(); | 626 IntPoint transformedPoint = PlatformMouseEventBuilder(m_webLocalFrameImpl->f
rameView(), dummyEvent).position(); |
632 HitTestResult result(request, m_webLocalFrameImpl->frameView()->rootFrameToC
ontents(transformedPoint)); | 627 HitTestResult result(request, m_webLocalFrameImpl->frameView()->rootFrameToC
ontents(transformedPoint)); |
633 m_webLocalFrameImpl->frame()->contentLayoutObject()->hitTest(result); | 628 m_webLocalFrameImpl->frame()->contentLayoutObject()->hitTest(result); |
634 Node* node = result.innerNode(); | 629 Node* node = result.innerNode(); |
635 if (!node && m_webLocalFrameImpl->frame()->document()) | 630 if (!node && m_webLocalFrameImpl->frame()->document()) |
636 node = m_webLocalFrameImpl->frame()->document()->documentElement(); | 631 node = m_webLocalFrameImpl->frame()->document()->documentElement(); |
637 m_domAgent->inspect(node); | 632 m_domAgent->inspect(node); |
638 } | 633 } |
639 | 634 |
640 void WebDevToolsAgentImpl::sendProtocolResponse(int sessionId, int callId, PassR
efPtr<JSONObject> message) | 635 void WebDevToolsAgentImpl::sendProtocolResponse(int callId, PassRefPtr<JSONObjec
t> message) |
641 { | 636 { |
642 if (!m_attached) | 637 if (!m_attached) |
643 return; | 638 return; |
644 flushPendingProtocolNotifications(); | 639 flushPendingProtocolNotifications(); |
645 m_client->sendProtocolMessage(sessionId, callId, message->toJSONString(), m_
stateCookie); | 640 m_client->sendProtocolMessage(callId, message->toJSONString(), m_stateCookie
); |
646 m_stateCookie = String(); | 641 m_stateCookie = String(); |
647 } | 642 } |
648 | 643 |
649 void WebDevToolsAgentImpl::sendProtocolNotification(PassRefPtr<JSONObject> messa
ge) | 644 void WebDevToolsAgentImpl::sendProtocolNotification(PassRefPtr<JSONObject> messa
ge) |
650 { | 645 { |
651 if (!m_attached) | 646 if (!m_attached) |
652 return; | 647 return; |
653 m_notificationQueue.append(std::make_pair(m_sessionId, message)); | 648 m_notificationQueue.append(message); |
654 } | 649 } |
655 | 650 |
656 void WebDevToolsAgentImpl::flush() | 651 void WebDevToolsAgentImpl::flush() |
657 { | 652 { |
658 flushPendingProtocolNotifications(); | 653 flushPendingProtocolNotifications(); |
659 } | 654 } |
660 | 655 |
661 void WebDevToolsAgentImpl::updateInspectorStateCookie(const String& state) | 656 void WebDevToolsAgentImpl::updateInspectorStateCookie(const String& state) |
662 { | 657 { |
663 m_stateCookie = state; | 658 m_stateCookie = state; |
(...skipping 12 matching lines...) Expand all Loading... |
676 WebString WebDevToolsAgentImpl::evaluateInWebInspectorOverlay(const WebString& s
cript) | 671 WebString WebDevToolsAgentImpl::evaluateInWebInspectorOverlay(const WebString& s
cript) |
677 { | 672 { |
678 if (!m_overlay) | 673 if (!m_overlay) |
679 return WebString(); | 674 return WebString(); |
680 | 675 |
681 return m_overlay->evaluateInOverlayForTest(script); | 676 return m_overlay->evaluateInOverlayForTest(script); |
682 } | 677 } |
683 | 678 |
684 void WebDevToolsAgentImpl::flushPendingProtocolNotifications() | 679 void WebDevToolsAgentImpl::flushPendingProtocolNotifications() |
685 { | 680 { |
686 if (m_attached) { | 681 if (!m_attached) |
687 m_agents.flushPendingProtocolNotifications(); | 682 return; |
688 for (size_t i = 0; i < m_notificationQueue.size(); ++i) | 683 |
689 m_client->sendProtocolMessage(m_notificationQueue[i].first, 0, m_not
ificationQueue[i].second->toJSONString(), WebString()); | 684 m_agents.flushPendingProtocolNotifications(); |
690 } | 685 for (size_t i = 0; i < m_notificationQueue.size(); ++i) |
| 686 m_client->sendProtocolMessage(0, m_notificationQueue[i]->toJSONString(),
WebString()); |
691 m_notificationQueue.clear(); | 687 m_notificationQueue.clear(); |
692 } | 688 } |
693 | 689 |
694 void WebDevToolsAgentImpl::willProcessTask() | 690 void WebDevToolsAgentImpl::willProcessTask() |
695 { | 691 { |
696 if (!m_attached) | 692 if (!m_attached) |
697 return; | 693 return; |
698 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector
ProfilerAgent()) | 694 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector
ProfilerAgent()) |
699 profilerAgent->willProcessTask(); | 695 profilerAgent->willProcessTask(); |
700 } | 696 } |
701 | 697 |
702 void WebDevToolsAgentImpl::didProcessTask() | 698 void WebDevToolsAgentImpl::didProcessTask() |
703 { | 699 { |
704 if (!m_attached) | 700 if (!m_attached) |
705 return; | 701 return; |
706 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector
ProfilerAgent()) | 702 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector
ProfilerAgent()) |
707 profilerAgent->didProcessTask(); | 703 profilerAgent->didProcessTask(); |
708 flushPendingProtocolNotifications(); | 704 flushPendingProtocolNotifications(); |
709 } | 705 } |
710 | 706 |
711 void WebDevToolsAgent::interruptAndDispatch(int sessionId, MessageDescriptor* ra
wDescriptor) | 707 void WebDevToolsAgent::interruptAndDispatch(MessageDescriptor* rawDescriptor) |
712 { | 708 { |
713 // rawDescriptor can't be a PassOwnPtr because interruptAndDispatch is a Web
Kit API function. | 709 // rawDescriptor can't be a PassOwnPtr because interruptAndDispatch is a Web
Kit API function. |
714 OwnPtr<MessageDescriptor> descriptor = adoptPtr(rawDescriptor); | 710 OwnPtr<MessageDescriptor> descriptor = adoptPtr(rawDescriptor); |
715 OwnPtr<DebuggerTask> task = adoptPtr(new DebuggerTask(sessionId, descriptor.
release())); | 711 OwnPtr<DebuggerTask> task = adoptPtr(new DebuggerTask(descriptor.release()))
; |
716 MainThreadDebugger::interruptMainThreadAndRun(task.release()); | 712 MainThreadDebugger::interruptMainThreadAndRun(task.release()); |
717 } | 713 } |
718 | 714 |
719 bool WebDevToolsAgent::shouldInterruptForMessage(const WebString& message) | 715 bool WebDevToolsAgent::shouldInterruptForMessage(const WebString& message) |
720 { | 716 { |
721 String commandName; | 717 String commandName; |
722 if (!InspectorBackendDispatcher::getCommandName(message, &commandName)) | 718 if (!InspectorBackendDispatcher::getCommandName(message, &commandName)) |
723 return false; | 719 return false; |
724 return commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_pauseCmd) | 720 return commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_pauseCmd) |
725 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_setBreakpointCmd) | 721 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_setBreakpointCmd) |
726 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_setBreakpointByUrlCmd) | 722 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_setBreakpointByUrlCmd) |
727 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_removeBreakpointCmd) | 723 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_removeBreakpointCmd) |
728 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_setBreakpointsActiveCmd); | 724 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke
ndDispatcher::kDebugger_setBreakpointsActiveCmd); |
729 } | 725 } |
730 | 726 |
731 } // namespace blink | 727 } // namespace blink |
OLD | NEW |