Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp

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

Powered by Google App Engine
This is Rietveld 408576698