OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_IMPL_H_ | |
6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/singleton.h" | |
13 #include "content/browser/debugger/devtools_agent_host.h" | |
14 #include "content/common/content_export.h" | |
15 #include "content/public/browser/devtools_client_host.h" | |
16 #include "content/public/browser/devtools_manager.h" | |
17 | |
18 class GURL; | |
19 | |
20 namespace IPC { | |
21 class Message; | |
22 } | |
23 | |
24 namespace content { | |
25 | |
26 class DevToolsAgentHost; | |
27 class RenderViewHost; | |
28 | |
29 // This class is a singleton that manages DevToolsClientHost instances and | |
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 CONTENT_EXPORT DevToolsManagerImpl | |
36 : public DevToolsAgentHost::CloseListener, | |
37 public DevToolsManager { | |
38 public: | |
39 // Returns single instance of this class. The instance is destroyed on the | |
40 // browser main loop exit so this method MUST NOT be called after that point. | |
41 static DevToolsManagerImpl* GetInstance(); | |
42 | |
43 DevToolsManagerImpl(); | |
44 virtual ~DevToolsManagerImpl(); | |
45 | |
46 void DispatchOnInspectorFrontend(DevToolsAgentHost* agent_host, | |
47 const std::string& message); | |
48 | |
49 void SaveAgentRuntimeState(DevToolsAgentHost* agent_host, | |
50 const std::string& state); | |
51 | |
52 // Sends 'Attach' message to the agent using |dest_rvh| in case | |
53 // there is a DevToolsClientHost registered for the |inspected_rvh|. | |
54 void OnNavigatingToPendingEntry(RenderViewHost* inspected_rvh, | |
55 RenderViewHost* dest_rvh, | |
56 const GURL& gurl); | |
57 void OnCancelPendingNavigation(RenderViewHost* pending, | |
58 RenderViewHost* current); | |
59 | |
60 // DevToolsManager implementation | |
61 virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from, | |
62 const std::string& message) OVERRIDE; | |
63 virtual void ContentsReplaced(WebContents* old_contents, | |
64 WebContents* new_contents) OVERRIDE; | |
65 virtual void CloseAllClientHosts() OVERRIDE; | |
66 virtual void AttachClientHost(int client_host_cookie, | |
67 DevToolsAgentHost* to_agent) OVERRIDE; | |
68 virtual DevToolsClientHost* GetDevToolsClientHostFor( | |
69 DevToolsAgentHost* agent_host) OVERRIDE; | |
70 virtual DevToolsAgentHost* GetDevToolsAgentHostFor( | |
71 DevToolsClientHost* client_host) OVERRIDE; | |
72 virtual void RegisterDevToolsClientHostFor( | |
73 DevToolsAgentHost* agent_host, | |
74 DevToolsClientHost* client_host) OVERRIDE; | |
75 virtual void UnregisterDevToolsClientHostFor( | |
76 DevToolsAgentHost* agent_host) OVERRIDE; | |
77 virtual int DetachClientHost(DevToolsAgentHost* from_agent) OVERRIDE; | |
78 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE; | |
79 virtual void InspectElement(DevToolsAgentHost* agent_host, | |
80 int x, int y) OVERRIDE; | |
81 virtual void AddMessageToConsole(DevToolsAgentHost* agent_host, | |
82 ConsoleMessageLevel level, | |
83 const std::string& message) OVERRIDE; | |
84 | |
85 private: | |
86 friend struct DefaultSingletonTraits<DevToolsManagerImpl>; | |
87 | |
88 // DevToolsAgentHost::CloseListener implementation. | |
89 virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE; | |
90 | |
91 void BindClientHost(DevToolsAgentHost* agent_host, | |
92 DevToolsClientHost* client_host); | |
93 void UnbindClientHost(DevToolsAgentHost* agent_host, | |
94 DevToolsClientHost* client_host); | |
95 | |
96 // Detaches client host and returns cookie that can be used in | |
97 // AttachClientHost. | |
98 int DetachClientHost(RenderViewHost* from_rvh); | |
99 | |
100 // Attaches orphan client host to new render view host. | |
101 void AttachClientHost(int client_host_cookie, | |
102 RenderViewHost* to_rvh); | |
103 | |
104 // These two maps are for tracking dependencies between inspected contents and | |
105 // their DevToolsClientHosts. They are useful for routing devtools messages | |
106 // and allow us to have at most one devtools client host per contents. | |
107 // | |
108 // DevToolsManagerImpl starts listening to DevToolsClientHosts when they are | |
109 // put into these maps and removes them when they are closing. | |
110 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> | |
111 AgentToClientHostMap; | |
112 AgentToClientHostMap agent_to_client_host_; | |
113 | |
114 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*> | |
115 ClientToAgentHostMap; | |
116 ClientToAgentHostMap client_to_agent_host_; | |
117 | |
118 typedef std::map<DevToolsAgentHost*, std::string> AgentRuntimeStates; | |
119 AgentRuntimeStates agent_runtime_states_; | |
120 | |
121 typedef std::map<int, std::pair<DevToolsClientHost*, std::string> > | |
122 OrphanClientHosts; | |
123 OrphanClientHosts orphan_client_hosts_; | |
124 int last_orphan_cookie_; | |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl); | |
127 }; | |
128 | |
129 } // namespace content | |
130 | |
131 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_ | |
OLD | NEW |