OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ |
6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "content/browser/debugger/devtools_agent_host.h" | |
13 #include "content/browser/debugger/devtools_client_host.h" | 12 #include "content/browser/debugger/devtools_client_host.h" |
| 13 #include "content/common/notification_observer.h" |
| 14 #include "content/common/notification_registrar.h" |
14 | 15 |
15 namespace IPC { | 16 namespace IPC { |
16 class Message; | 17 class Message; |
17 } | 18 } |
18 | 19 |
19 class DevToolsAgentHost; | |
20 class DevToolsNetLogObserver; | 20 class DevToolsNetLogObserver; |
21 class GURL; | 21 class GURL; |
22 class IOThread; | 22 class IOThread; |
23 class PrefService; | 23 class PrefService; |
24 class RenderViewHost; | 24 class RenderViewHost; |
25 class TabContents; | 25 class TabContents; |
26 | 26 |
27 typedef std::map<std::string, std::string> DevToolsRuntimeProperties; | 27 typedef std::map<std::string, std::string> DevToolsRuntimeProperties; |
28 | 28 |
29 // This class is a singleton that manages DevToolsClientHost instances and | 29 // This class is a singleton that manages DevToolsClientHost instances and |
30 // routes messages between developer tools clients and agents. | 30 // routes messages between developer tools clients and agents. |
31 // | |
32 // Methods below that accept inspected RenderViewHost as a parameter are | |
33 // just convenience methods that call corresponding methods accepting | |
34 // DevToolAgentHost. | |
35 class DevToolsManager : public DevToolsClientHost::CloseListener, | 31 class DevToolsManager : public DevToolsClientHost::CloseListener, |
36 public DevToolsAgentHost::CloseListener { | 32 public NotificationObserver { |
37 public: | 33 public: |
38 static DevToolsManager* GetInstance(); | 34 static DevToolsManager* GetInstance(); |
39 | 35 |
40 DevToolsManager(); | 36 DevToolsManager(); |
41 virtual ~DevToolsManager(); | 37 virtual ~DevToolsManager(); |
42 | 38 |
43 // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if | 39 // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if |
44 // there is no alive DevToolsClientHost registered for |inspected_rvh|. | 40 // there is no alive DevToolsClientHost registered for |inspected_rvh|. |
45 DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); | 41 DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); |
46 | 42 |
(...skipping 29 matching lines...) Expand all Loading... |
76 // AttachClientHost. | 72 // AttachClientHost. |
77 int DetachClientHost(RenderViewHost* from_rvh); | 73 int DetachClientHost(RenderViewHost* from_rvh); |
78 | 74 |
79 // Attaches orphan client host to new render view host. | 75 // Attaches orphan client host to new render view host. |
80 void AttachClientHost(int client_host_cookie, | 76 void AttachClientHost(int client_host_cookie, |
81 RenderViewHost* to_rvh); | 77 RenderViewHost* to_rvh); |
82 | 78 |
83 // Closes all open developer tools windows. | 79 // Closes all open developer tools windows. |
84 void CloseAllClientHosts(); | 80 void CloseAllClientHosts(); |
85 | 81 |
86 DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host); | |
87 void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host); | |
88 | |
89 private: | 82 private: |
90 // DevToolsClientHost::CloseListener override. | 83 // DevToolsClientHost::CloseListener override. |
91 // This method will remove all references from the manager to the | 84 // This method will remove all references from the manager to the |
92 // DevToolsClientHost and unregister all listeners related to the | 85 // DevToolsClientHost and unregister all listeners related to the |
93 // DevToolsClientHost. | 86 // DevToolsClientHost. |
94 virtual void ClientHostClosing(DevToolsClientHost* host); | 87 virtual void ClientHostClosing(DevToolsClientHost* host); |
95 | 88 |
96 // DevToolsAgentHost::CloseListener implementation. | 89 // Overridden from NotificationObserver: |
97 virtual void AgentHostClosing(DevToolsAgentHost* host); | 90 virtual void Observe(int type, |
| 91 const NotificationSource& source, |
| 92 const NotificationDetails& details); |
98 | 93 |
99 // Returns DevToolsAgentHost inspected by the DevToolsClientHost. | 94 // Returns RenderViewHost for the tab that is inspected by devtools |
100 DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host); | 95 // client hosted by DevToolsClientHost. |
| 96 RenderViewHost* GetInspectedRenderViewHost(DevToolsClientHost* client_host); |
101 | 97 |
102 void SendAttachToAgent(DevToolsAgentHost*); | 98 void SendAttachToAgent(RenderViewHost* inspected_rvh); |
103 void SendDetachToAgent(DevToolsAgentHost*); | 99 void SendDetachToAgent(RenderViewHost* inspected_rvh); |
104 | 100 |
105 void BindClientHost(DevToolsAgentHost* agent_host, | 101 void BindClientHost(RenderViewHost* inspected_rvh, |
106 DevToolsClientHost* client_host, | 102 DevToolsClientHost* client_host, |
107 const DevToolsRuntimeProperties& runtime_properties); | 103 const DevToolsRuntimeProperties& runtime_properties); |
108 void UnbindClientHost(DevToolsAgentHost* agent_host, | 104 |
| 105 void UnbindClientHost(RenderViewHost* inspected_rvh, |
109 DevToolsClientHost* client_host); | 106 DevToolsClientHost* client_host); |
110 | 107 |
111 // These two maps are for tracking dependencies between inspected tabs and | 108 // These two maps are for tracking dependencies between inspected tabs and |
112 // their DevToolsClientHosts. They are useful for routing devtools messages | 109 // their DevToolsClientHosts. They are useful for routing devtools messages |
113 // and allow us to have at most one devtools client host per tab. | 110 // and allow us to have at most one devtools client host per tab. |
114 // | 111 // |
115 // DevToolsManager start listening to DevToolsClientHosts when they are put | 112 // DevToolsManager start listening to DevToolsClientHosts when they are put |
116 // into these maps and removes them when they are closing. | 113 // into these maps and removes them when they are closing. |
117 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> | 114 typedef std::map<RenderViewHost*, DevToolsClientHost*> |
118 AgentToClientHostMap; | 115 InspectedRvhToClientHostMap; |
119 AgentToClientHostMap agent_to_client_host_; | 116 InspectedRvhToClientHostMap inspected_rvh_to_client_host_; |
120 | 117 |
121 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*> | 118 typedef std::map<DevToolsClientHost*, RenderViewHost*> |
122 ClientHostToInspectedRvhMap; | 119 ClientHostToInspectedRvhMap; |
123 ClientHostToInspectedRvhMap client_to_agent_host_; | 120 ClientHostToInspectedRvhMap client_host_to_inspected_rvh_; |
124 | 121 |
125 typedef std::map<DevToolsAgentHost*, DevToolsRuntimeProperties> | 122 typedef std::map<RenderViewHost*, DevToolsRuntimeProperties> |
126 RuntimePropertiesMap; | 123 RuntimePropertiesMap; |
127 RuntimePropertiesMap runtime_properties_map_; | 124 RuntimePropertiesMap runtime_properties_map_; |
128 | 125 |
129 typedef std::map<int, | 126 typedef std::map<int, |
130 std::pair<DevToolsClientHost*, DevToolsRuntimeProperties> > | 127 std::pair<DevToolsClientHost*, DevToolsRuntimeProperties> > |
131 OrphanClientHosts; | 128 OrphanClientHosts; |
132 OrphanClientHosts orphan_client_hosts_; | 129 OrphanClientHosts orphan_client_hosts_; |
133 int last_orphan_cookie_; | 130 int last_orphan_cookie_; |
134 | 131 |
| 132 NotificationRegistrar registrar_; |
| 133 |
135 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); | 134 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); |
136 }; | 135 }; |
137 | 136 |
138 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 137 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |