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

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

Issue 1437283003: [DevTools] filter any messages from previous session in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 499
497 if (m_overlay) 500 if (m_overlay)
498 m_overlay->init(cssAgent, debuggerAgent, m_domAgent.get()); 501 m_overlay->init(cssAgent, debuggerAgent, m_domAgent.get());
499 } 502 }
500 503
501 void WebDevToolsAgentImpl::registerAgent(PassOwnPtrWillBeRawPtr<InspectorAgent> agent) 504 void WebDevToolsAgentImpl::registerAgent(PassOwnPtrWillBeRawPtr<InspectorAgent> agent)
502 { 505 {
503 m_agents.append(agent); 506 m_agents.append(agent);
504 } 507 }
505 508
506 void WebDevToolsAgentImpl::attach(const WebString& hostId) 509 void WebDevToolsAgentImpl::attach(const WebString& hostId, int sessionId)
507 { 510 {
508 if (m_attached) 511 if (m_attached)
509 return; 512 return;
510 513
511 // Set the attached bit first so that sync notifications were delivered. 514 // Set the attached bit first so that sync notifications were delivered.
512 m_attached = true; 515 m_attached = true;
516 m_sessionId = sessionId;
513 517
514 initializeDeferredAgents(); 518 initializeDeferredAgents();
515 m_resourceAgent->setHostId(hostId); 519 m_resourceAgent->setHostId(hostId);
516 520
517 m_inspectorFrontend = adoptPtr(new InspectorFrontend(this)); 521 m_inspectorFrontend = adoptPtr(new InspectorFrontend(this));
518 // We can reconnect to existing front-end -> unmute state. 522 // We can reconnect to existing front-end -> unmute state.
519 m_state->unmute(); 523 m_state->unmute();
520 m_agents.setFrontend(m_inspectorFrontend.get()); 524 m_agents.setFrontend(m_inspectorFrontend.get());
521 525
522 InspectorInstrumentation::registerInstrumentingAgents(m_instrumentingAgents. get()); 526 InspectorInstrumentation::registerInstrumentingAgents(m_instrumentingAgents. get());
523 InspectorInstrumentation::frontendCreated(); 527 InspectorInstrumentation::frontendCreated();
524 528
525 m_inspectorBackendDispatcher = InspectorBackendDispatcher::create(this); 529 m_inspectorBackendDispatcher = InspectorBackendDispatcher::create(this);
526 m_agents.registerInDispatcher(m_inspectorBackendDispatcher.get()); 530 m_agents.registerInDispatcher(m_inspectorBackendDispatcher.get());
527 531
528 Platform::current()->currentThread()->addTaskObserver(this); 532 Platform::current()->currentThread()->addTaskObserver(this);
529 } 533 }
530 534
531 void WebDevToolsAgentImpl::reattach(const WebString& hostId, const WebString& sa vedState) 535 void WebDevToolsAgentImpl::reattach(const WebString& hostId, int sessionId, cons t WebString& savedState)
532 { 536 {
533 if (m_attached) 537 if (m_attached)
534 return; 538 return;
535 539
536 attach(hostId); 540 attach(hostId, sessionId);
537 m_state->loadFromCookie(savedState); 541 m_state->loadFromCookie(savedState);
538 m_agents.restore(); 542 m_agents.restore();
539 } 543 }
540 544
541 void WebDevToolsAgentImpl::detach() 545 void WebDevToolsAgentImpl::detach()
542 { 546 {
543 if (!m_attached) 547 if (!m_attached)
544 return; 548 return;
545 549
546 Platform::current()->currentThread()->removeTaskObserver(this); 550 Platform::current()->currentThread()->removeTaskObserver(this);
547 551
548 m_inspectorBackendDispatcher->clearFrontend(); 552 m_inspectorBackendDispatcher->clearFrontend();
549 m_inspectorBackendDispatcher.clear(); 553 m_inspectorBackendDispatcher.clear();
550 554
551 // Destroying agents would change the state, but we don't want that. 555 // Destroying agents would change the state, but we don't want that.
552 // Pre-disconnect state will be used to restore inspector agents. 556 // Pre-disconnect state will be used to restore inspector agents.
553 m_state->mute(); 557 m_state->mute();
554 m_agents.clearFrontend(); 558 m_agents.clearFrontend();
555 m_inspectorFrontend.clear(); 559 m_inspectorFrontend.clear();
556 560
557 // Release overlay resources. 561 // Release overlay resources.
558 if (m_overlay) 562 if (m_overlay)
559 m_overlay->clear(); 563 m_overlay->clear();
560 InspectorInstrumentation::frontendDeleted(); 564 InspectorInstrumentation::frontendDeleted();
561 InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgent s.get()); 565 InspectorInstrumentation::unregisterInstrumentingAgents(m_instrumentingAgent s.get());
562 566
567 m_sessionId = 0;
563 m_attached = false; 568 m_attached = false;
564 } 569 }
565 570
566 void WebDevToolsAgentImpl::continueProgram() 571 void WebDevToolsAgentImpl::continueProgram()
567 { 572 {
568 ClientMessageLoopAdapter::continueProgram(); 573 ClientMessageLoopAdapter::continueProgram();
569 } 574 }
570 575
571 void WebDevToolsAgentImpl::didCommitLoadForLocalFrame(LocalFrame* frame) 576 void WebDevToolsAgentImpl::didCommitLoadForLocalFrame(LocalFrame* frame)
572 { 577 {
(...skipping 24 matching lines...) Expand all
597 void WebDevToolsAgentImpl::enableTracing(const String& categoryFilter) 602 void WebDevToolsAgentImpl::enableTracing(const String& categoryFilter)
598 { 603 {
599 m_client->enableTracing(categoryFilter); 604 m_client->enableTracing(categoryFilter);
600 } 605 }
601 606
602 void WebDevToolsAgentImpl::disableTracing() 607 void WebDevToolsAgentImpl::disableTracing()
603 { 608 {
604 m_client->disableTracing(); 609 m_client->disableTracing();
605 } 610 }
606 611
607 void WebDevToolsAgentImpl::dispatchOnInspectorBackend(const WebString& message) 612 void WebDevToolsAgentImpl::dispatchOnInspectorBackend(int sessionId, const WebSt ring& message)
608 { 613 {
609 if (!m_attached) 614 if (!m_attached)
610 return; 615 return;
611 if (WebDevToolsAgent::shouldInterruptForMessage(message)) 616 if (WebDevToolsAgent::shouldInterruptForMessage(message))
612 MainThreadDebugger::instance()->taskRunner()->runPendingTasks(); 617 MainThreadDebugger::instance()->taskRunner()->runPendingTasks();
613 else 618 else
614 dispatchMessageFromFrontend(message); 619 dispatchMessageFromFrontend(sessionId, message);
615 } 620 }
616 621
617 void WebDevToolsAgentImpl::dispatchMessageFromFrontend(const String& message) 622 void WebDevToolsAgentImpl::dispatchMessageFromFrontend(int sessionId, const Stri ng& message)
618 { 623 {
619 InspectorTaskRunner::IgnoreInterruptsScope scope(MainThreadDebugger::instanc e()->taskRunner()); 624 InspectorTaskRunner::IgnoreInterruptsScope scope(MainThreadDebugger::instanc e()->taskRunner());
620 if (m_inspectorBackendDispatcher) 625 if (m_inspectorBackendDispatcher)
621 m_inspectorBackendDispatcher->dispatch(message); 626 m_inspectorBackendDispatcher->dispatch(sessionId, message);
622 } 627 }
623 628
624 void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& pointInRootFrame) 629 void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& pointInRootFrame)
625 { 630 {
626 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move | HitTestR equest::ReadOnly | HitTestRequest::AllowChildFrameContent; 631 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move | HitTestR equest::ReadOnly | HitTestRequest::AllowChildFrameContent;
627 HitTestRequest request(hitType); 632 HitTestRequest request(hitType);
628 WebMouseEvent dummyEvent; 633 WebMouseEvent dummyEvent;
629 dummyEvent.type = WebInputEvent::MouseDown; 634 dummyEvent.type = WebInputEvent::MouseDown;
630 dummyEvent.x = pointInRootFrame.x; 635 dummyEvent.x = pointInRootFrame.x;
631 dummyEvent.y = pointInRootFrame.y; 636 dummyEvent.y = pointInRootFrame.y;
632 IntPoint transformedPoint = PlatformMouseEventBuilder(m_webLocalFrameImpl->f rameView(), dummyEvent).position(); 637 IntPoint transformedPoint = PlatformMouseEventBuilder(m_webLocalFrameImpl->f rameView(), dummyEvent).position();
633 HitTestResult result(request, m_webLocalFrameImpl->frameView()->rootFrameToC ontents(transformedPoint)); 638 HitTestResult result(request, m_webLocalFrameImpl->frameView()->rootFrameToC ontents(transformedPoint));
634 m_webLocalFrameImpl->frame()->contentLayoutObject()->hitTest(result); 639 m_webLocalFrameImpl->frame()->contentLayoutObject()->hitTest(result);
635 Node* node = result.innerNode(); 640 Node* node = result.innerNode();
636 if (!node && m_webLocalFrameImpl->frame()->document()) 641 if (!node && m_webLocalFrameImpl->frame()->document())
637 node = m_webLocalFrameImpl->frame()->document()->documentElement(); 642 node = m_webLocalFrameImpl->frame()->document()->documentElement();
638 m_domAgent->inspect(node); 643 m_domAgent->inspect(node);
639 } 644 }
640 645
641 void WebDevToolsAgentImpl::sendProtocolResponse(int callId, PassRefPtr<JSONObjec t> message) 646 void WebDevToolsAgentImpl::sendProtocolResponse(int sessionId, int callId, PassR efPtr<JSONObject> message)
642 { 647 {
643 if (!m_attached) 648 if (!m_attached)
644 return; 649 return;
645 flushPendingProtocolNotifications(); 650 flushPendingProtocolNotifications();
646 m_client->sendProtocolMessage(callId, message->toJSONString(), m_stateCookie ); 651 m_client->sendProtocolMessage(sessionId, callId, message->toJSONString(), m_ stateCookie);
647 m_stateCookie = String(); 652 m_stateCookie = String();
648 } 653 }
649 654
650 void WebDevToolsAgentImpl::sendProtocolNotification(PassRefPtr<JSONObject> messa ge) 655 void WebDevToolsAgentImpl::sendProtocolNotification(PassRefPtr<JSONObject> messa ge)
651 { 656 {
652 if (!m_attached) 657 if (!m_attached)
653 return; 658 return;
654 m_notificationQueue.append(message); 659 m_notificationQueue.append(std::make_pair(m_sessionId, message));
655 } 660 }
656 661
657 void WebDevToolsAgentImpl::flush() 662 void WebDevToolsAgentImpl::flush()
658 { 663 {
659 flushPendingProtocolNotifications(); 664 flushPendingProtocolNotifications();
660 } 665 }
661 666
662 void WebDevToolsAgentImpl::updateInspectorStateCookie(const String& state) 667 void WebDevToolsAgentImpl::updateInspectorStateCookie(const String& state)
663 { 668 {
664 m_stateCookie = state; 669 m_stateCookie = state;
(...skipping 12 matching lines...) Expand all
677 WebString WebDevToolsAgentImpl::evaluateInWebInspectorOverlay(const WebString& s cript) 682 WebString WebDevToolsAgentImpl::evaluateInWebInspectorOverlay(const WebString& s cript)
678 { 683 {
679 if (!m_overlay) 684 if (!m_overlay)
680 return WebString(); 685 return WebString();
681 686
682 return m_overlay->evaluateInOverlayForTest(script); 687 return m_overlay->evaluateInOverlayForTest(script);
683 } 688 }
684 689
685 void WebDevToolsAgentImpl::flushPendingProtocolNotifications() 690 void WebDevToolsAgentImpl::flushPendingProtocolNotifications()
686 { 691 {
687 if (!m_attached) 692 if (m_attached) {
688 return; 693 m_agents.flushPendingProtocolNotifications();
689 694 for (size_t i = 0; i < m_notificationQueue.size(); ++i)
690 m_agents.flushPendingProtocolNotifications(); 695 m_client->sendProtocolMessage(m_notificationQueue[i].first, 0, m_not ificationQueue[i].second->toJSONString(), WebString());
691 for (size_t i = 0; i < m_notificationQueue.size(); ++i) 696 }
692 m_client->sendProtocolMessage(0, m_notificationQueue[i]->toJSONString(), WebString());
693 m_notificationQueue.clear(); 697 m_notificationQueue.clear();
694 } 698 }
695 699
696 void WebDevToolsAgentImpl::willProcessTask() 700 void WebDevToolsAgentImpl::willProcessTask()
697 { 701 {
698 if (!m_attached) 702 if (!m_attached)
699 return; 703 return;
700 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector ProfilerAgent()) 704 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector ProfilerAgent())
701 profilerAgent->willProcessTask(); 705 profilerAgent->willProcessTask();
702 } 706 }
703 707
704 void WebDevToolsAgentImpl::didProcessTask() 708 void WebDevToolsAgentImpl::didProcessTask()
705 { 709 {
706 if (!m_attached) 710 if (!m_attached)
707 return; 711 return;
708 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector ProfilerAgent()) 712 if (InspectorProfilerAgent* profilerAgent = m_instrumentingAgents->inspector ProfilerAgent())
709 profilerAgent->didProcessTask(); 713 profilerAgent->didProcessTask();
710 flushPendingProtocolNotifications(); 714 flushPendingProtocolNotifications();
711 } 715 }
712 716
713 void WebDevToolsAgent::interruptAndDispatch(MessageDescriptor* rawDescriptor) 717 void WebDevToolsAgent::interruptAndDispatch(int sessionId, MessageDescriptor* ra wDescriptor)
714 { 718 {
715 // rawDescriptor can't be a PassOwnPtr because interruptAndDispatch is a Web Kit API function. 719 // rawDescriptor can't be a PassOwnPtr because interruptAndDispatch is a Web Kit API function.
716 OwnPtr<MessageDescriptor> descriptor = adoptPtr(rawDescriptor); 720 OwnPtr<MessageDescriptor> descriptor = adoptPtr(rawDescriptor);
717 OwnPtr<DebuggerTask> task = adoptPtr(new DebuggerTask(descriptor.release())) ; 721 OwnPtr<DebuggerTask> task = adoptPtr(new DebuggerTask(sessionId, descriptor. release()));
718 MainThreadDebugger::interruptMainThreadAndRun(task.release()); 722 MainThreadDebugger::interruptMainThreadAndRun(task.release());
719 } 723 }
720 724
721 bool WebDevToolsAgent::shouldInterruptForMessage(const WebString& message) 725 bool WebDevToolsAgent::shouldInterruptForMessage(const WebString& message)
722 { 726 {
723 String commandName; 727 String commandName;
724 if (!InspectorBackendDispatcher::getCommandName(message, &commandName)) 728 if (!InspectorBackendDispatcher::getCommandName(message, &commandName))
725 return false; 729 return false;
726 return commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_pauseCmd) 730 return commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_pauseCmd)
727 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_setBreakpointCmd) 731 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_setBreakpointCmd)
728 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_setBreakpointByUrlCmd) 732 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_setBreakpointByUrlCmd)
729 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_removeBreakpointCmd) 733 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_removeBreakpointCmd)
730 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_setBreakpointsActiveCmd); 734 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kDebugger_setBreakpointsActiveCmd);
731 } 735 }
732 736
733 } // namespace blink 737 } // 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