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 CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | |
6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/singleton.h" | |
14 #include "content/browser/debugger/devtools_agent_host.h" | |
15 #include "content/browser/debugger/devtools_client_host.h" | |
16 #include "content/common/content_export.h" | |
17 | |
18 class DevToolsAgentHost; | |
19 class GURL; | |
20 class RenderViewHost; | |
21 class TabContents; | |
22 | |
23 namespace IPC { | |
24 class Message; | |
25 } | |
26 | |
27 // This class is a singleton that manages DevToolsClientHost instances and | |
28 // routes messages between developer tools clients and agents. | |
29 // | |
30 // Methods below that accept inspected RenderViewHost as a parameter are | |
31 // just convenience methods that call corresponding methods accepting | |
32 // DevToolAgentHost. | |
33 class CONTENT_EXPORT DevToolsManager | |
34 : public DevToolsClientHost::CloseListener, | |
35 public DevToolsAgentHost::CloseListener { | |
36 public: | |
37 static DevToolsManager* GetInstance(); | |
38 | |
39 DevToolsManager(); | |
40 virtual ~DevToolsManager(); | |
41 | |
42 // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if | |
43 // there is no alive DevToolsClientHost registered for |inspected_rvh|. | |
44 DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); | |
45 | |
46 // Registers new DevToolsClientHost for |inspected_rvh|. There must be no | |
47 // other DevToolsClientHosts registered for the RenderViewHost at the moment. | |
48 void RegisterDevToolsClientHostFor(RenderViewHost* inspected_rvh, | |
49 DevToolsClientHost* client_host); | |
50 void UnregisterDevToolsClientHostFor(RenderViewHost* inspected_rvh); | |
51 | |
52 bool ForwardToDevToolsAgent(DevToolsClientHost* from, | |
53 const IPC::Message& message); | |
54 void ForwardToDevToolsClient(DevToolsAgentHost* agent_host, | |
55 const IPC::Message& message); | |
56 | |
57 void SaveAgentRuntimeState(DevToolsAgentHost* agent_host, | |
58 const std::string& state); | |
59 | |
60 // Sends 'Attach' message to the agent using |dest_rvh| in case | |
61 // there is a DevToolsClientHost registered for the |inspected_rvh|. | |
62 void OnNavigatingToPendingEntry(RenderViewHost* inspected_rvh, | |
63 RenderViewHost* dest_rvh, | |
64 const GURL& gurl); | |
65 void OnCancelPendingNavigation(RenderViewHost* pending, | |
66 RenderViewHost* current); | |
67 | |
68 // Invoked when a tab is replaced by another tab. This is triggered by | |
69 // TabStripModel::ReplaceTabContentsAt. | |
70 void TabReplaced(TabContents* old_tab, TabContents* new_tab); | |
71 | |
72 // Detaches client host and returns cookie that can be used in | |
73 // AttachClientHost. | |
74 int DetachClientHost(RenderViewHost* from_rvh); | |
75 | |
76 // Attaches orphan client host to new render view host. | |
77 void AttachClientHost(int client_host_cookie, | |
78 RenderViewHost* to_rvh); | |
79 | |
80 // Closes all open developer tools windows. | |
81 void CloseAllClientHosts(); | |
82 | |
83 void AttachClientHost(int client_host_cookie, | |
84 DevToolsAgentHost* to_agent); | |
85 DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host); | |
86 void RegisterDevToolsClientHostFor(DevToolsAgentHost* agent_host, | |
87 DevToolsClientHost* client_host); | |
88 void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host); | |
89 int DetachClientHost(DevToolsAgentHost* from_agent); | |
90 | |
91 private: | |
92 friend struct DefaultSingletonTraits<DevToolsManager>; | |
93 | |
94 // DevToolsClientHost::CloseListener override. | |
95 // This method will remove all references from the manager to the | |
96 // DevToolsClientHost and unregister all listeners related to the | |
97 // DevToolsClientHost. | |
98 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE; | |
99 | |
100 // DevToolsAgentHost::CloseListener implementation. | |
101 virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE; | |
102 | |
103 // Returns DevToolsAgentHost inspected by the DevToolsClientHost. | |
104 DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host); | |
105 | |
106 void BindClientHost(DevToolsAgentHost* agent_host, | |
107 DevToolsClientHost* client_host); | |
108 void UnbindClientHost(DevToolsAgentHost* agent_host, | |
109 DevToolsClientHost* client_host); | |
110 | |
111 // These two maps are for tracking dependencies between inspected tabs and | |
112 // their DevToolsClientHosts. They are useful for routing devtools messages | |
113 // and allow us to have at most one devtools client host per tab. | |
114 // | |
115 // DevToolsManager start listening to DevToolsClientHosts when they are put | |
116 // into these maps and removes them when they are closing. | |
117 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> | |
118 AgentToClientHostMap; | |
119 AgentToClientHostMap agent_to_client_host_; | |
120 | |
121 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*> | |
122 ClientHostToInspectedRvhMap; | |
123 ClientHostToInspectedRvhMap client_to_agent_host_; | |
124 | |
125 typedef std::map<DevToolsAgentHost*, std::string> AgentRuntimeStates; | |
126 AgentRuntimeStates agent_runtime_states_; | |
127 | |
128 typedef std::map<int, std::pair<DevToolsClientHost*, std::string> > | |
129 OrphanClientHosts; | |
130 OrphanClientHosts orphan_client_hosts_; | |
131 int last_orphan_cookie_; | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); | |
134 }; | |
135 | |
136 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | |
OLD | NEW |