|
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/HashMap.h> |
|
38 #include <wtf/Noncopyable.h> |
|
39 #include <wtf/Vector.h> |
|
40 |
|
41 namespace WebCore { |
|
42 class Page; |
|
43 class PageGroupLoadDeferrer; |
|
44 class String; |
|
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 : public Noncopyable { |
|
67 public: |
|
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); |
|
74 |
|
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); |
|
78 |
|
79 static void onWebViewClosed(WebViewImpl* webview); |
|
80 |
|
81 static void onNavigate(); |
|
82 |
|
83 class UtilityContextScope : public Noncopyable { |
|
84 public: |
|
85 UtilityContextScope() |
|
86 { |
|
87 ASSERT(!s_inUtilityContext); |
|
88 s_inUtilityContext = true; |
|
89 } |
|
90 ~UtilityContextScope() |
|
91 { |
|
92 if (s_debugBreakDelayed) { |
|
93 v8::Debug::DebugBreak(); |
|
94 s_debugBreakDelayed = false; |
|
95 } |
|
96 s_inUtilityContext = false; |
|
97 } |
|
98 }; |
|
99 |
|
100 private: |
|
101 DebuggerAgentManager(); |
|
102 ~DebuggerAgentManager(); |
|
103 |
|
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(); |
|
109 |
|
110 static DebuggerAgentImpl* findAgentForCurrentV8Context(); |
|
111 static DebuggerAgentImpl* debuggerAgentForHostId(int hostId); |
|
112 |
|
113 typedef HashMap<int, DebuggerAgentImpl*> AttachedAgentsMap; |
|
114 static AttachedAgentsMap* s_attachedAgentsMap; |
|
115 |
|
116 static WebDevToolsAgent::MessageLoopDispatchHandler s_messageLoopDispatchHandler; |
|
117 static bool s_inHostDispatchHandler; |
|
118 typedef HashMap<WebViewImpl*, WebCore::PageGroupLoadDeferrer*> DeferrersMap; |
|
119 static DeferrersMap s_pageDeferrers; |
|
120 |
|
121 static bool s_inUtilityContext; |
|
122 static bool s_debugBreakDelayed; |
|
123 static bool s_exposeV8DebuggerProtocol; |
|
124 }; |
|
125 |
|
126 } // namespace WebKit |
|
127 |
|
128 #endif |