15e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block/*
25e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * Copyright (C) 2010 Google Inc. All rights reserved.
35e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block *
45e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * Redistribution and use in source and binary forms, with or without
55e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * modification, are permitted provided that the following conditions are
65e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * met:
75e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block *
85e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block *     * Redistributions of source code must retain the above copyright
95e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * notice, this list of conditions and the following disclaimer.
105e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block *     * Redistributions in binary form must reproduce the above
115e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * copyright notice, this list of conditions and the following disclaimer
125e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * in the documentation and/or other materials provided with the
135e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * distribution.
145e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block *     * Neither the name of Google Inc. nor the names of its
155e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * contributors may be used to endorse or promote products derived from
165e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * this software without specific prior written permission.
175e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block *
185e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block */
305e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
315e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#ifndef DebuggerAgentManager_h
325e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#define DebuggerAgentManager_h
335e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
34dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "WebCString.h"
355e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include "WebDevToolsAgent.h"
365e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include <v8-debug.h>
37dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include <wtf/Forward.h>
385e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include <wtf/HashMap.h>
395e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include <wtf/Noncopyable.h>
40dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include <wtf/Vector.h>
415e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
425e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blocknamespace WebCore {
43dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockclass Page;
445e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockclass PageGroupLoadDeferrer;
455e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block}
465e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
475e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blocknamespace WebKit {
485e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
495e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockclass DebuggerAgentImpl;
505e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockclass DictionaryValue;
515e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockclass WebFrameImpl;
525e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockclass WebViewImpl;
535e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
545e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// There is single v8 instance per render process. Also there may be several
555e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// RenderViews and consequently devtools agents in the process that want to talk
565e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// to the v8 debugger. This class coordinates communication between the debug
575e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// agents and v8 debugger. It will set debug output handler as long as at least
585e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// one debugger agent is attached and remove it when last debugger agent is
595e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// detached. When message is received from debugger it will route it to the
605e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// right debugger agent if there is one otherwise the message will be ignored.
615e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block//
625e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// v8 may send a message(e.g. exception event) after which it
635e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// would expect some actions from the handler. If there is no appropriate
645e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// debugger agent to handle such messages the manager will perform the action
655e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block// itself, otherwise v8 may hang waiting for the action.
66ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochclass DebuggerAgentManager {
67ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch    WTF_MAKE_NONCOPYABLE(DebuggerAgentManager);
685e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockpublic:
695e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void debugAttach(DebuggerAgentImpl* debuggerAgent);
705e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void debugDetach(DebuggerAgentImpl* debuggerAgent);
715e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void pauseScript();
72dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch    static void executeDebuggerCommand(const WTF::String& command, int callerId);
735e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void setMessageLoopDispatchHandler(WebDevToolsAgent::MessageLoopDispatchHandler handler);
745af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke    static void setExposeV8DebuggerProtocol(bool);
755e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
765e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    // Sets |hostId| as the frame context data. This id is used to filter scripts
775e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    // related to the inspected page.
785e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void setHostId(WebFrameImpl* webframe, int hostId);
795e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
805e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void onWebViewClosed(WebViewImpl* webview);
815e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
825e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void onNavigate();
835e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
845e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockprivate:
855e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    DebuggerAgentManager();
865e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    ~DebuggerAgentManager();
875e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
885e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void debugHostDispatchHandler();
895e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void onV8DebugMessage(const v8::Debug::Message& message);
90dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch    static void sendCommandToV8(const WTF::String& cmd,
915e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block                                v8::Debug::ClientData* data);
925e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static void sendContinueCommandToV8();
935e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
945e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static DebuggerAgentImpl* findAgentForCurrentV8Context();
955e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static DebuggerAgentImpl* debuggerAgentForHostId(int hostId);
965e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
975e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    typedef HashMap<int, DebuggerAgentImpl*> AttachedAgentsMap;
985e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static AttachedAgentsMap* s_attachedAgentsMap;
995e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
1005e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static WebDevToolsAgent::MessageLoopDispatchHandler s_messageLoopDispatchHandler;
1015e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static bool s_inHostDispatchHandler;
1025e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    typedef HashMap<WebViewImpl*, WebCore::PageGroupLoadDeferrer*> DeferrersMap;
1035e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    static DeferrersMap s_pageDeferrers;
1045e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
1055af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke    static bool s_exposeV8DebuggerProtocol;
1065e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block};
1075e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
1085e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block} // namespace WebKit
1095e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
1105e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#endif
111