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/render_view_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 RenderViewHost* rvh = (*it)->render_view_host_; | 97 RenderViewHost* rvh = (*it)->render_view_host_; |
98 if (rvh && rvh->GetDelegate() != delegate) | 98 if (rvh && rvh->GetDelegate() != delegate) |
99 continue; | 99 continue; |
100 if (devtools_manager->GetDevToolsClientHostFor(*it)) | 100 if (devtools_manager->GetDevToolsClientHostFor(*it)) |
101 return true; | 101 return true; |
102 } | 102 } |
103 return false; | 103 return false; |
104 } | 104 } |
105 | 105 |
106 // static | 106 // static |
107 int DevToolsAgentHost::DisconnectRenderViewHost(RenderViewHost* rvh) { | 107 const std::string DevToolsAgentHost::NullId; |
| 108 |
| 109 // static |
| 110 std::string DevToolsAgentHost::DisconnectRenderViewHost(RenderViewHost* rvh) { |
108 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(rvh); | 111 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(rvh); |
109 if (!agent_host) | 112 if (!agent_host) |
110 return -1; | 113 return NullId; |
111 agent_host->DisconnectRenderViewHost(); | 114 agent_host->DisconnectRenderViewHost(); |
112 return agent_host->id(); | 115 return agent_host->GetId(); |
113 } | 116 } |
114 | 117 |
115 // static | 118 // static |
116 void DevToolsAgentHost::ConnectRenderViewHost(int cookie, | 119 void DevToolsAgentHost::ConnectRenderViewHost(const std::string& cookie, |
117 RenderViewHost* rvh) { | 120 RenderViewHost* rvh) { |
118 for (Instances::iterator it = g_instances.Get().begin(); | 121 for (Instances::iterator it = g_instances.Get().begin(); |
119 it != g_instances.Get().end(); ++it) { | 122 it != g_instances.Get().end(); ++it) { |
120 if (cookie == (*it)->id()) { | 123 if (cookie == (*it)->GetId()) { |
121 (*it)->ConnectRenderViewHost(rvh, true); | 124 (*it)->ConnectRenderViewHost(rvh, true); |
122 break; | 125 break; |
123 } | 126 } |
124 } | 127 } |
125 } | 128 } |
126 | 129 |
| 130 //static |
| 131 std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() { |
| 132 std::vector<RenderViewHost*> result; |
| 133 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
| 134 !it.IsAtEnd(); it.Advance()) { |
| 135 RenderProcessHost* render_process_host = it.GetCurrentValue(); |
| 136 DCHECK(render_process_host); |
| 137 |
| 138 // Ignore processes that don't have a connection, such as crashed contents. |
| 139 if (!render_process_host->HasConnection()) |
| 140 continue; |
| 141 |
| 142 RenderProcessHost::RenderWidgetHostsIterator rwit( |
| 143 render_process_host->GetRenderWidgetHostsIterator()); |
| 144 for (; !rwit.IsAtEnd(); rwit.Advance()) { |
| 145 const RenderWidgetHost* widget = rwit.GetCurrentValue(); |
| 146 DCHECK(widget); |
| 147 if (!widget || !widget->IsRenderView()) |
| 148 continue; |
| 149 |
| 150 RenderViewHost* rvh = |
| 151 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); |
| 152 result.push_back(rvh); |
| 153 } |
| 154 } |
| 155 return result; |
| 156 } |
| 157 |
127 // static | 158 // static |
128 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( | 159 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( |
129 RenderViewHost* pending, | 160 RenderViewHost* pending, |
130 RenderViewHost* current) { | 161 RenderViewHost* current) { |
131 int cookie = DevToolsAgentHost::DisconnectRenderViewHost(pending); | 162 std::string cookie = DevToolsAgentHost::DisconnectRenderViewHost(pending); |
132 if (cookie != -1) | 163 if (cookie != NullId) |
133 DevToolsAgentHost::ConnectRenderViewHost(cookie, current); | 164 DevToolsAgentHost::ConnectRenderViewHost(cookie, current); |
134 } | 165 } |
135 | 166 |
136 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost( | 167 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost( |
137 RenderViewHost* rvh) | 168 RenderViewHost* rvh) |
138 : overrides_handler_(new RendererOverridesHandler(this)) { | 169 : overrides_handler_(new RendererOverridesHandler(this)) { |
139 ConnectRenderViewHost(rvh, false); | 170 ConnectRenderViewHost(rvh, false); |
140 g_instances.Get().push_back(this); | 171 g_instances.Get().push_back(this); |
141 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); | 172 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); |
142 if (delegate && delegate->GetAsWebContents()) | 173 if (delegate && delegate->GetAsWebContents()) |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 snapshot_bounds)) | 371 snapshot_bounds)) |
341 return false; | 372 return false; |
342 | 373 |
343 return base::Base64Encode(base::StringPiece( | 374 return base::Base64Encode(base::StringPiece( |
344 reinterpret_cast<char*>(&*png.begin()), | 375 reinterpret_cast<char*>(&*png.begin()), |
345 png.size()), | 376 png.size()), |
346 base_64_data); | 377 base_64_data); |
347 } | 378 } |
348 | 379 |
349 } // namespace content | 380 } // namespace content |
OLD | NEW |