Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: content/browser/debugger/devtools_manager_impl.h

Issue 8549022: Define DevTools content API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: jam's comments addressed Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_IMPL_H_
6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ 6 #define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_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 "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "content/browser/debugger/devtools_agent_host.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" 15 #include "content/common/content_export.h"
16 #include "content/public/browser/devtools_client_host.h"
17 #include "content/public/browser/devtools_manager.h"
17 18
18 class DevToolsAgentHost;
19 class GURL; 19 class GURL;
20 class RenderViewHost; 20 class RenderViewHost;
21 class TabContents; 21 class TabContents;
22 22
23 namespace IPC { 23 namespace IPC {
24 class Message; 24 class Message;
25 } 25 }
26 26
27 namespace content {
28
29 class DevToolsAgentHost;
30
27 // This class is a singleton that manages DevToolsClientHost instances and 31 // This class is a singleton that manages DevToolsClientHost instances and
28 // routes messages between developer tools clients and agents. 32 // routes messages between developer tools clients and agents.
29 // 33 //
30 // Methods below that accept inspected RenderViewHost as a parameter are 34 // Methods below that accept inspected RenderViewHost as a parameter are
31 // just convenience methods that call corresponding methods accepting 35 // just convenience methods that call corresponding methods accepting
32 // DevToolAgentHost. 36 // DevToolAgentHost.
33 class CONTENT_EXPORT DevToolsManager 37 class CONTENT_EXPORT DevToolsManagerImpl
34 : public DevToolsClientHost::CloseListener, 38 : public DevToolsAgentHost::CloseListener,
35 public DevToolsAgentHost::CloseListener { 39 public DevToolsManager {
36 public: 40 public:
37 static DevToolsManager* GetInstance(); 41 // Returns single instance of this class. The instance is destroyed on the
42 // browser main loop exit so this method MUST NOT be called after that point.
43 static DevToolsManagerImpl* GetInstance();
38 44
39 DevToolsManager(); 45 DevToolsManagerImpl();
40 virtual ~DevToolsManager(); 46 virtual ~DevToolsManagerImpl();
41 47
42 // Returns DevToolsClientHost registered for |inspected_rvh| or NULL if 48 virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from,
43 // there is no alive DevToolsClientHost registered for |inspected_rvh|. 49 const std::string& message) OVERRIDE;
44 DevToolsClientHost* GetDevToolsClientHostFor(RenderViewHost* inspected_rvh); 50 void DispatchOnInspectorFrontend(DevToolsAgentHost* agent_host,
45 51 const std::string& message);
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 52
57 void SaveAgentRuntimeState(DevToolsAgentHost* agent_host, 53 void SaveAgentRuntimeState(DevToolsAgentHost* agent_host,
58 const std::string& state); 54 const std::string& state);
59 55
60 // Sends 'Attach' message to the agent using |dest_rvh| in case 56 // Sends 'Attach' message to the agent using |dest_rvh| in case
61 // there is a DevToolsClientHost registered for the |inspected_rvh|. 57 // there is a DevToolsClientHost registered for the |inspected_rvh|.
62 void OnNavigatingToPendingEntry(RenderViewHost* inspected_rvh, 58 void OnNavigatingToPendingEntry(RenderViewHost* inspected_rvh,
63 RenderViewHost* dest_rvh, 59 RenderViewHost* dest_rvh,
64 const GURL& gurl); 60 const GURL& gurl);
65 void OnCancelPendingNavigation(RenderViewHost* pending, 61 void OnCancelPendingNavigation(RenderViewHost* pending,
66 RenderViewHost* current); 62 RenderViewHost* current);
67 63
68 // Invoked when a tab is replaced by another tab. This is triggered by 64 // Invoked when a tab is replaced by another tab. This is triggered by
69 // TabStripModel::ReplaceTabContentsAt. 65 // TabStripModel::ReplaceTabContentsAt.
70 void TabReplaced(TabContents* old_tab, TabContents* new_tab); 66 virtual void TabReplaced(TabContents* old_tab, TabContents* new_tab) OVERRIDE;
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 67
80 // Closes all open developer tools windows. 68 // Closes all open developer tools windows.
81 void CloseAllClientHosts(); 69 virtual void CloseAllClientHosts() OVERRIDE;
82 70
83 void AttachClientHost(int client_host_cookie, 71 virtual void AttachClientHost(int client_host_cookie,
84 DevToolsAgentHost* to_agent); 72 DevToolsAgentHost* to_agent) OVERRIDE;
85 DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host); 73 virtual DevToolsClientHost* GetDevToolsClientHostFor(
86 void RegisterDevToolsClientHostFor(DevToolsAgentHost* agent_host, 74 DevToolsAgentHost* agent_host) OVERRIDE;
87 DevToolsClientHost* client_host); 75 virtual void RegisterDevToolsClientHostFor(
88 void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host); 76 DevToolsAgentHost* agent_host,
89 int DetachClientHost(DevToolsAgentHost* from_agent); 77 DevToolsClientHost* client_host) OVERRIDE;
78 virtual void UnregisterDevToolsClientHostFor(
79 DevToolsAgentHost* agent_host) OVERRIDE;
80 virtual int DetachClientHost(DevToolsAgentHost* from_agent) OVERRIDE;
90 81
91 private:
92 friend struct DefaultSingletonTraits<DevToolsManager>;
93
94 // DevToolsClientHost::CloseListener override.
95 // This method will remove all references from the manager to the 82 // This method will remove all references from the manager to the
96 // DevToolsClientHost and unregister all listeners related to the 83 // DevToolsClientHost and unregister all listeners related to the
97 // DevToolsClientHost. 84 // DevToolsClientHost.
98 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE; 85 virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE;
99 86
87 // Starts inspecting element at position (x, y) in the specified page.
88 virtual void InspectElement(DevToolsAgentHost* agent_host,
89 int x, int y) OVERRIDE;
90
91 private:
92 friend struct DefaultSingletonTraits<DevToolsManagerImpl>;
93
100 // DevToolsAgentHost::CloseListener implementation. 94 // DevToolsAgentHost::CloseListener implementation.
101 virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE; 95 virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE;
102 96
103 // Returns DevToolsAgentHost inspected by the DevToolsClientHost. 97 // Returns DevToolsAgentHost inspected by the DevToolsClientHost.
104 DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host); 98 DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host);
105 99
106 void BindClientHost(DevToolsAgentHost* agent_host, 100 void BindClientHost(DevToolsAgentHost* agent_host,
107 DevToolsClientHost* client_host); 101 DevToolsClientHost* client_host);
108 void UnbindClientHost(DevToolsAgentHost* agent_host, 102 void UnbindClientHost(DevToolsAgentHost* agent_host,
109 DevToolsClientHost* client_host); 103 DevToolsClientHost* client_host);
110 104
105 // Detaches client host and returns cookie that can be used in
106 // AttachClientHost.
107 int DetachClientHost(RenderViewHost* from_rvh);
108
109 // Attaches orphan client host to new render view host.
110 void AttachClientHost(int client_host_cookie,
111 RenderViewHost* to_rvh);
112
111 // These two maps are for tracking dependencies between inspected tabs and 113 // These two maps are for tracking dependencies between inspected tabs and
112 // their DevToolsClientHosts. They are useful for routing devtools messages 114 // their DevToolsClientHosts. They are useful for routing devtools messages
113 // and allow us to have at most one devtools client host per tab. 115 // and allow us to have at most one devtools client host per tab.
114 // 116 //
115 // DevToolsManager start listening to DevToolsClientHosts when they are put 117 // DevToolsManagerImpl starts listening to DevToolsClientHosts when they are
116 // into these maps and removes them when they are closing. 118 // put into these maps and removes them when they are closing.
117 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*> 119 typedef std::map<DevToolsAgentHost*, DevToolsClientHost*>
118 AgentToClientHostMap; 120 AgentToClientHostMap;
119 AgentToClientHostMap agent_to_client_host_; 121 AgentToClientHostMap agent_to_client_host_;
120 122
121 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*> 123 typedef std::map<DevToolsClientHost*, DevToolsAgentHost*>
122 ClientHostToInspectedRvhMap; 124 ClientHostToInspectedRvhMap;
123 ClientHostToInspectedRvhMap client_to_agent_host_; 125 ClientHostToInspectedRvhMap client_to_agent_host_;
124 126
125 typedef std::map<DevToolsAgentHost*, std::string> AgentRuntimeStates; 127 typedef std::map<DevToolsAgentHost*, std::string> AgentRuntimeStates;
126 AgentRuntimeStates agent_runtime_states_; 128 AgentRuntimeStates agent_runtime_states_;
127 129
128 typedef std::map<int, std::pair<DevToolsClientHost*, std::string> > 130 typedef std::map<int, std::pair<DevToolsClientHost*, std::string> >
129 OrphanClientHosts; 131 OrphanClientHosts;
130 OrphanClientHosts orphan_client_hosts_; 132 OrphanClientHosts orphan_client_hosts_;
131 int last_orphan_cookie_; 133 int last_orphan_cookie_;
132 134
133 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); 135 DISALLOW_COPY_AND_ASSIGN(DevToolsManagerImpl);
134 }; 136 };
135 137
136 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ 138 } // namespace content
139
140 #endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/debugger/devtools_manager.cc ('k') | content/browser/debugger/devtools_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698