| 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" |
| 12 #include "content/browser/debugger/devtools_client_host.h" | 13 #include "content/browser/debugger/devtools_client_host.h" |
| 13 #include "content/common/notification_observer.h" | |
| 14 #include "content/common/notification_registrar.h" | |
| 15 | 14 |
| 16 namespace IPC { | 15 namespace IPC { |
| 17 class Message; | 16 class Message; |
| 18 } | 17 } |
| 19 | 18 |
| 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. |
| 31 class DevToolsManager : public DevToolsClientHost::CloseListener, | 35 class DevToolsManager : public DevToolsClientHost::CloseListener, |
| 32 public NotificationObserver { | 36 public DevToolsAgentHost::CloseListener { |
| 33 public: | 37 public: |
| 34 static DevToolsManager* GetInstance(); | 38 static DevToolsManager* GetInstance(); |
| 35 | 39 |
| 36 DevToolsManager(); | 40 DevToolsManager(); |
| 37 virtual ~DevToolsManager(); | 41 virtual ~DevToolsManager(); |
| 38 | 42 |
| 39 // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if | 43 // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if |
| 40 // there is no alive DevToolsClientHost registered for |inspected_rvh|. | 44 // there is no alive DevToolsClientHost registered for |inspected_rvh|. |
| 41 DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); | 45 DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); |
| 42 | 46 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 72 // AttachClientHost. | 76 // AttachClientHost. |
| 73 int DetachClientHost(RenderViewHost* from_rvh); | 77 int DetachClientHost(RenderViewHost* from_rvh); |
| 74 | 78 |
| 75 // Attaches orphan client host to new render view host. | 79 // Attaches orphan client host to new render view host. |
| 76 void AttachClientHost(int client_host_cookie, | 80 void AttachClientHost(int client_host_cookie, |
| 77 RenderViewHost* to_rvh); | 81 RenderViewHost* to_rvh); |
| 78 | 82 |
| 79 // Closes all open developer tools windows. | 83 // Closes all open developer tools windows. |
| 80 void CloseAllClientHosts(); | 84 void CloseAllClientHosts(); |
| 81 | 85 |
| 86 DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host); |
| 87 void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host); |
| 88 |
| 82 private: | 89 private: |
| 83 // DevToolsClientHost::CloseListener override. | 90 // DevToolsClientHost::CloseListener override. |
| 84 // This method will remove all references from the manager to the | 91 // This method will remove all references from the manager to the |
| 85 // DevToolsClientHost and unregister all listeners related to the | 92 // DevToolsClientHost and unregister all listeners related to the |
| 86 // DevToolsClientHost. | 93 // DevToolsClientHost. |
| 87 virtual void ClientHostClosing(DevToolsClientHost* host); | 94 virtual void ClientHostClosing(DevToolsClientHost* host); |
| 88 | 95 |
| 89 // Overridden from NotificationObserver: | 96 // DevToolsAgentHost::CloseListener implementation. |
| 90 virtual void Observe(int type, | 97 virtual void AgentHostClosing(DevToolsAgentHost* host); |
| 91 const NotificationSource& source, | |
| 92 const NotificationDetails& details); | |
| 93 | 98 |
| 94 // Returns RenderViewHost for the tab that is inspected by devtools | 99 // Returns DevToolsAgentHost inspected by the DevToolsClientHost. |
| 95 // client hosted by DevToolsClientHost. | 100 DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host); |
| 96 RenderViewHost* GetInspectedRenderViewHost(DevToolsClientHost* client_host); | |
| 97 | 101 |
| 98 void SendAttachToAgent(RenderViewHost* inspected_rvh); | 102 void SendAttachToAgent(DevToolsAgentHost*); |
| 99 void SendDetachToAgent(RenderViewHost* inspected_rvh); | 103 void SendDetachToAgent(DevToolsAgentHost*); |
| 100 | 104 |
| 101 void BindClientHost(RenderViewHost* inspected_rvh, | 105 void BindClientHost(DevToolsAgentHost* agent_host, |
| 102 DevToolsClientHost* client_host, | 106 DevToolsClientHost* client_host, |
| 103 const DevToolsRuntimeProperties& runtime_properties); | 107 const DevToolsRuntimeProperties& runtime_properties); |
| 104 | 108 void UnbindClientHost(DevToolsAgentHost* agent_host, |
| 105 void UnbindClientHost(RenderViewHost* inspected_rvh, | |
| 106 DevToolsClientHost* client_host); | 109 DevToolsClientHost* client_host); |
| 107 | 110 |
| 108 // These two maps are for tracking dependencies between inspected tabs and | 111 // These two maps are for tracking dependencies between inspected tabs and |
| 109 // their DevToolsClientHosts. They are useful for routing devtools messages | 112 // their DevToolsClientHosts. They are useful for routing devtools messages |
| 110 // and allow us to have at most one devtools client host per tab. | 113 // and allow us to have at most one devtools client host per tab. |
| 111 // | 114 // |
| 112 // DevToolsManager start listening to DevToolsClientHosts when they are put | 115 // DevToolsManager start listening to DevToolsClientHosts when they are put |
| 113 // into these maps and removes them when they are closing. | 116 // into these maps and removes them when they are closing. |
| 114 typedef std::map<RenderViewHost*, DevToolsClientHost*> | 117 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> |
| 115 InspectedRvhToClientHostMap; | 118 AgentToClientHostMap; |
| 116 InspectedRvhToClientHostMap inspected_rvh_to_client_host_; | 119 AgentToClientHostMap agent_to_client_host_; |
| 117 | 120 |
| 118 typedef std::map<DevToolsClientHost*, RenderViewHost*> | 121 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*> |
| 119 ClientHostToInspectedRvhMap; | 122 ClientHostToInspectedRvhMap; |
| 120 ClientHostToInspectedRvhMap client_host_to_inspected_rvh_; | 123 ClientHostToInspectedRvhMap client_to_agent_host_; |
| 121 | 124 |
| 122 typedef std::map<RenderViewHost*, DevToolsRuntimeProperties> | 125 typedef std::map<DevToolsAgentHost*, DevToolsRuntimeProperties> |
| 123 RuntimePropertiesMap; | 126 RuntimePropertiesMap; |
| 124 RuntimePropertiesMap runtime_properties_map_; | 127 RuntimePropertiesMap runtime_properties_map_; |
| 125 | 128 |
| 126 typedef std::map<int, | 129 typedef std::map<int, |
| 127 std::pair<DevToolsClientHost*, DevToolsRuntimeProperties> > | 130 std::pair<DevToolsClientHost*, DevToolsRuntimeProperties> > |
| 128 OrphanClientHosts; | 131 OrphanClientHosts; |
| 129 OrphanClientHosts orphan_client_hosts_; | 132 OrphanClientHosts orphan_client_hosts_; |
| 130 int last_orphan_cookie_; | 133 int last_orphan_cookie_; |
| 131 | 134 |
| 132 NotificationRegistrar registrar_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); | 135 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 138 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ |
| OLD | NEW |