OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/browser/devtools/devtools_agent_host_impl.h" | 5 #include "content/browser/devtools/devtools_agent_host_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( | 68 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( |
69 DevToolsExternalAgentProxyDelegate* delegate) { | 69 DevToolsExternalAgentProxyDelegate* delegate) { |
70 return new ForwardingAgentHost(delegate); | 70 return new ForwardingAgentHost(delegate); |
71 } | 71 } |
72 | 72 |
73 void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { | 73 void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { |
74 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 74 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
75 if (client_) { | 75 if (client_) { |
76 client_->AgentHostClosed(this, true); | 76 client_->AgentHostClosed(this, true); |
77 Detach(); | 77 Detach(); |
| 78 } else { |
| 79 DevToolsManager::GetInstance()->OnClientAttached(); |
78 } | 80 } |
79 client_ = client; | 81 client_ = client; |
80 Attach(); | 82 Attach(); |
81 DevToolsManager::GetInstance()->AgentHostChanged(this); | |
82 } | 83 } |
83 | 84 |
84 void DevToolsAgentHostImpl::DetachClient() { | 85 void DevToolsAgentHostImpl::DetachClient() { |
85 if (!client_) | 86 if (!client_) |
86 return; | 87 return; |
87 | 88 |
88 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 89 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
89 client_ = NULL; | 90 client_ = NULL; |
| 91 DevToolsManager::GetInstance()->OnClientDetached(); |
90 Detach(); | 92 Detach(); |
91 DevToolsManager::GetInstance()->AgentHostChanged(this); | |
92 } | 93 } |
93 | 94 |
94 bool DevToolsAgentHostImpl::IsAttached() { | 95 bool DevToolsAgentHostImpl::IsAttached() { |
95 return !!client_; | 96 return !!client_; |
96 } | 97 } |
97 | 98 |
98 void DevToolsAgentHostImpl::InspectElement(int x, int y) { | 99 void DevToolsAgentHostImpl::InspectElement(int x, int y) { |
99 } | 100 } |
100 | 101 |
101 std::string DevToolsAgentHostImpl::GetId() { | 102 std::string DevToolsAgentHostImpl::GetId() { |
(...skipping 15 matching lines...) Expand all Loading... |
117 } | 118 } |
118 | 119 |
119 void DevToolsAgentHostImpl::HostClosed() { | 120 void DevToolsAgentHostImpl::HostClosed() { |
120 if (!client_) | 121 if (!client_) |
121 return; | 122 return; |
122 | 123 |
123 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 124 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
124 // Clear |client_| before notifying it. | 125 // Clear |client_| before notifying it. |
125 DevToolsAgentHostClient* client = client_; | 126 DevToolsAgentHostClient* client = client_; |
126 client_ = NULL; | 127 client_ = NULL; |
| 128 DevToolsManager::GetInstance()->OnClientDetached(); |
127 client->AgentHostClosed(this, false); | 129 client->AgentHostClosed(this, false); |
128 DevToolsManager::GetInstance()->AgentHostChanged(this); | |
129 } | 130 } |
130 | 131 |
131 void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) { | 132 void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) { |
132 if (!client_) | 133 if (!client_) |
133 return; | 134 return; |
134 client_->DispatchProtocolMessage(this, message); | 135 client_->DispatchProtocolMessage(this, message); |
135 } | 136 } |
136 | 137 |
137 // static | 138 // static |
138 void DevToolsAgentHost::DetachAllClients() { | 139 void DevToolsAgentHost::DetachAllClients() { |
139 if (g_instances == NULL) | 140 if (g_instances == NULL) |
140 return; | 141 return; |
141 | 142 |
142 // Make a copy, since detaching may lead to agent destruction, which | 143 // Make a copy, since detaching may lead to agent destruction, which |
143 // removes it from the instances. | 144 // removes it from the instances. |
144 Instances copy = g_instances.Get(); | 145 Instances copy = g_instances.Get(); |
145 for (Instances::iterator it(copy.begin()); it != copy.end(); ++it) { | 146 for (Instances::iterator it(copy.begin()); it != copy.end(); ++it) { |
146 DevToolsAgentHostImpl* agent_host = it->second; | 147 DevToolsAgentHostImpl* agent_host = it->second; |
147 if (agent_host->client_) { | 148 if (agent_host->client_) { |
148 scoped_refptr<DevToolsAgentHostImpl> protect(agent_host); | 149 scoped_refptr<DevToolsAgentHostImpl> protect(agent_host); |
149 // Clear |client_| before notifying it. | 150 // Clear |client_| before notifying it. |
150 DevToolsAgentHostClient* client = agent_host->client_; | 151 DevToolsAgentHostClient* client = agent_host->client_; |
151 agent_host->client_ = NULL; | 152 agent_host->client_ = NULL; |
| 153 DevToolsManager::GetInstance()->OnClientDetached(); |
152 client->AgentHostClosed(agent_host, true); | 154 client->AgentHostClosed(agent_host, true); |
153 agent_host->Detach(); | 155 agent_host->Detach(); |
154 DevToolsManager::GetInstance()->AgentHostChanged(protect); | |
155 } | 156 } |
156 } | 157 } |
157 } | 158 } |
158 | 159 |
159 // static | 160 // static |
160 void DevToolsAgentHost::AddAgentStateCallback( | 161 void DevToolsAgentHost::AddAgentStateCallback( |
161 const AgentStateCallback& callback) { | 162 const AgentStateCallback& callback) { |
162 g_callbacks.Get().push_back(&callback); | 163 g_callbacks.Get().push_back(&callback); |
163 } | 164 } |
164 | 165 |
(...skipping 21 matching lines...) Expand all Loading... |
186 (*it)->Run(agent_host, attached); | 187 (*it)->Run(agent_host, attached); |
187 } | 188 } |
188 | 189 |
189 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { | 190 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { |
190 DevToolsManager* manager = DevToolsManager::GetInstance(); | 191 DevToolsManager* manager = DevToolsManager::GetInstance(); |
191 if (manager->delegate()) | 192 if (manager->delegate()) |
192 manager->delegate()->Inspect(browser_context, this); | 193 manager->delegate()->Inspect(browser_context, this); |
193 } | 194 } |
194 | 195 |
195 } // namespace content | 196 } // namespace content |
OLD | NEW |