Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef DebuggerAgentManager_h
     32 #define DebuggerAgentManager_h
     33 
     34 #include "WebCString.h"
     35 #include "WebDevToolsAgent.h"
     36 #include <v8-debug.h>
     37 #include <wtf/Forward.h>
     38 #include <wtf/HashMap.h>
     39 #include <wtf/Noncopyable.h>
     40 #include <wtf/Vector.h>
     41 
     42 namespace WebCore {
     43 class Page;
     44 class PageGroupLoadDeferrer;
     45 }
     46 
     47 namespace WebKit {
     48 
     49 class DebuggerAgentImpl;
     50 class DictionaryValue;
     51 class WebFrameImpl;
     52 class WebViewImpl;
     53 
     54 // There is single v8 instance per render process. Also there may be several
     55 // RenderViews and consequently devtools agents in the process that want to talk
     56 // to the v8 debugger. This class coordinates communication between the debug
     57 // agents and v8 debugger. It will set debug output handler as long as at least
     58 // one debugger agent is attached and remove it when last debugger agent is
     59 // detached. When message is received from debugger it will route it to the
     60 // right debugger agent if there is one otherwise the message will be ignored.
     61 //
     62 // v8 may send a message(e.g. exception event) after which it
     63 // would expect some actions from the handler. If there is no appropriate
     64 // debugger agent to handle such messages the manager will perform the action
     65 // itself, otherwise v8 may hang waiting for the action.
     66 class DebuggerAgentManager {
     67     WTF_MAKE_NONCOPYABLE(DebuggerAgentManager);
     68 public:
     69     static void debugAttach(DebuggerAgentImpl* debuggerAgent);
     70     static void debugDetach(DebuggerAgentImpl* debuggerAgent);
     71     static void pauseScript();
     72     static void executeDebuggerCommand(const WTF::String& command, int callerId);
     73     static void setMessageLoopDispatchHandler(WebDevToolsAgent::MessageLoopDispatchHandler handler);
     74     static void setExposeV8DebuggerProtocol(bool);
     75 
     76     // Sets |hostId| as the frame context data. This id is used to filter scripts
     77     // related to the inspected page.
     78     static void setHostId(WebFrameImpl* webframe, int hostId);
     79 
     80     static void onWebViewClosed(WebViewImpl* webview);
     81 
     82     static void onNavigate();
     83 
     84 private:
     85     DebuggerAgentManager();
     86     ~DebuggerAgentManager();
     87 
     88     static void debugHostDispatchHandler();
     89     static void onV8DebugMessage(const v8::Debug::Message& message);
     90     static void sendCommandToV8(const WTF::String& cmd,
     91                                 v8::Debug::ClientData* data);
     92     static void sendContinueCommandToV8();
     93 
     94     static DebuggerAgentImpl* findAgentForCurrentV8Context();
     95     static DebuggerAgentImpl* debuggerAgentForHostId(int hostId);
     96 
     97     typedef HashMap<int, DebuggerAgentImpl*> AttachedAgentsMap;
     98     static AttachedAgentsMap* s_attachedAgentsMap;
     99 
    100     static WebDevToolsAgent::MessageLoopDispatchHandler s_messageLoopDispatchHandler;
    101     static bool s_inHostDispatchHandler;
    102     typedef HashMap<WebViewImpl*, WebCore::PageGroupLoadDeferrer*> DeferrersMap;
    103     static DeferrersMap s_pageDeferrers;
    104 
    105     static bool s_exposeV8DebuggerProtocol;
    106 };
    107 
    108 } // namespace WebKit
    109 
    110 #endif
    111