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