2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef DebuggerAgentManager_h
32 #define DebuggerAgentManager_h
34 #include "WebCString.h"
35 #include "WebDevToolsAgent.h"
37 #include <wtf/HashMap.h>
38 #include <wtf/Noncopyable.h>
39 #include <wtf/Vector.h>
43 class PageGroupLoadDeferrer;
49 class DebuggerAgentImpl;
50 class DictionaryValue;
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.
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 : public Noncopyable {
68 static void debugAttach(DebuggerAgentImpl* debuggerAgent);
69 static void debugDetach(DebuggerAgentImpl* debuggerAgent);
70 static void pauseScript();
71 static void executeDebuggerCommand(const WebCore::String& command, int callerId);
72 static void setMessageLoopDispatchHandler(WebDevToolsAgent::MessageLoopDispatchHandler handler);
73 static void setExposeV8DebuggerProtocol(bool);
75 // Sets |hostId| as the frame context data. This id is used to filter scripts
76 // related to the inspected page.
77 static void setHostId(WebFrameImpl* webframe, int hostId);
79 static void onWebViewClosed(WebViewImpl* webview);
81 static void onNavigate();
83 class UtilityContextScope : public Noncopyable {
87 ASSERT(!s_inUtilityContext);
88 s_inUtilityContext = true;
90 ~UtilityContextScope()
92 if (s_debugBreakDelayed) {
93 v8::Debug::DebugBreak();
94 s_debugBreakDelayed = false;
96 s_inUtilityContext = false;
101 DebuggerAgentManager();
102 ~DebuggerAgentManager();
104 static void debugHostDispatchHandler();
105 static void onV8DebugMessage(const v8::Debug::Message& message);
106 static void sendCommandToV8(const WebCore::String& cmd,
107 v8::Debug::ClientData* data);
108 static void sendContinueCommandToV8();
110 static DebuggerAgentImpl* findAgentForCurrentV8Context();
111 static DebuggerAgentImpl* debuggerAgentForHostId(int hostId);
113 typedef HashMap<int, DebuggerAgentImpl*> AttachedAgentsMap;
114 static AttachedAgentsMap* s_attachedAgentsMap;
116 static WebDevToolsAgent::MessageLoopDispatchHandler s_messageLoopDispatchHandler;
117 static bool s_inHostDispatchHandler;
118 typedef HashMap<WebViewImpl*, WebCore::PageGroupLoadDeferrer*> DeferrersMap;
119 static DeferrersMap s_pageDeferrers;
121 static bool s_inUtilityContext;
122 static bool s_debugBreakDelayed;
123 static bool s_exposeV8DebuggerProtocol;
126 } // namespace WebKit