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