OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_ | |
6 #define CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/hash_tables.h" | |
14 #include "content/browser/debugger/devtools_client_host.h" | |
15 | |
16 class DebuggerRemoteService; | |
17 class DevToolsClientHost; | |
18 class DevToolsClientHostImpl; | |
19 class TabContentsWrapper; | |
20 | |
21 // Proxies debugged tabs' TabContentsWrapper using their UIDs. | |
22 // Keeps track of tabs being debugged so that we can detach from | |
23 // them on remote debugger connection loss. | |
24 class InspectableTabProxy { | |
25 public: | |
26 typedef base::hash_map<int32, TabContentsWrapper*> TabMap; | |
27 typedef base::hash_map<int32, DevToolsClientHostImpl*> IdToClientHostMap; | |
28 | |
29 InspectableTabProxy(); | |
30 virtual ~InspectableTabProxy(); | |
31 | |
32 // Returns a map of SessionID to TabContentsWrapper for all Browser | |
33 // instances. Clients should not keep the result around for extended periods | |
34 // of time as tabs might get closed thus invalidating the map. | |
35 const TabMap& tab_map(); | |
36 | |
37 // Returns a DevToolsClientHostImpl for the given tab |id|. | |
38 DevToolsClientHostImpl* ClientHostForTabId(int32 id); | |
39 | |
40 // Creates a new DevToolsClientHost implementor instance. | |
41 // |id| is the UID of the tab to debug. | |
42 // |service| is the DebuggerRemoteService instance the DevToolsClient | |
43 // messages shall be dispatched to. | |
44 DevToolsClientHost* NewClientHost(int32 id, | |
45 DebuggerRemoteService* service); | |
46 | |
47 // Gets invoked when a remote debugger is detached. In this case we should | |
48 // send the corresponding message to the V8 debugger for each of the tabs | |
49 // the debugger is attached to, and invoke InspectedTabClosing(). | |
50 void OnRemoteDebuggerDetached(); | |
51 | |
52 private: | |
53 TabMap tab_map_; | |
54 IdToClientHostMap id_to_client_host_map_; | |
55 DISALLOW_COPY_AND_ASSIGN(InspectableTabProxy); | |
56 }; | |
57 | |
58 | |
59 // An internal implementation of DevToolsClientHost that delegates | |
60 // messages sent for DevToolsClient to a DebuggerShell instance. | |
61 class DevToolsClientHostImpl : public DevToolsClientHost { | |
62 public: | |
63 DevToolsClientHostImpl( | |
64 int32 id, | |
65 DebuggerRemoteService* service, | |
66 InspectableTabProxy::IdToClientHostMap* map); | |
67 virtual ~DevToolsClientHostImpl(); | |
68 | |
69 DebuggerRemoteService* debugger_remote_service() { | |
70 return service_; | |
71 } | |
72 | |
73 void CloseImpl(); | |
74 | |
75 // DevToolsClientHost interface | |
76 virtual void InspectedTabClosing() OVERRIDE; | |
77 virtual void SendMessageToClient(const IPC::Message& msg) OVERRIDE; | |
78 virtual void TabReplaced(TabContents* new_tab) OVERRIDE; | |
79 | |
80 private: | |
81 // Message handling routines | |
82 void OnDebuggerOutput(const std::string& msg); | |
83 virtual void FrameNavigating(const std::string& url) OVERRIDE; | |
84 void TabClosed(); | |
85 | |
86 int32 id_; | |
87 DebuggerRemoteService* service_; | |
88 InspectableTabProxy::IdToClientHostMap* map_; | |
89 }; | |
90 | |
91 #endif // CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_ | |
OLD | NEW |