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

Side by Side Diff: content/browser/devtools/render_view_devtools_agent_host.cc

Issue 12319114: Extract debugger target enumeration into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@debugger
Patch Set: Rebase Created 7 years, 9 months 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
OLDNEW
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
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 std::string DevToolsAgentHost::DisconnectRenderViewHost(RenderViewHost* rvh) {
108 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(rvh); 108 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(rvh);
109 if (!agent_host) 109 if (!agent_host)
110 return -1; 110 return std::string();
111 agent_host->DisconnectRenderViewHost(); 111 agent_host->DisconnectRenderViewHost();
112 return agent_host->id(); 112 return agent_host->GetId();
113 } 113 }
114 114
115 // static 115 // static
116 void DevToolsAgentHost::ConnectRenderViewHost(int cookie, 116 void DevToolsAgentHost::ConnectRenderViewHost(const std::string& cookie,
117 RenderViewHost* rvh) { 117 RenderViewHost* rvh) {
118 for (Instances::iterator it = g_instances.Get().begin(); 118 for (Instances::iterator it = g_instances.Get().begin();
119 it != g_instances.Get().end(); ++it) { 119 it != g_instances.Get().end(); ++it) {
120 if (cookie == (*it)->id()) { 120 if (cookie == (*it)->GetId()) {
121 (*it)->ConnectRenderViewHost(rvh, true); 121 (*it)->ConnectRenderViewHost(rvh, true);
122 break; 122 break;
123 } 123 }
124 } 124 }
125 } 125 }
126 126
127 //static
128 std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() {
129 std::vector<RenderViewHost*> result;
130 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
131 !it.IsAtEnd(); it.Advance()) {
132 RenderProcessHost* render_process_host = it.GetCurrentValue();
133 DCHECK(render_process_host);
134
135 // Ignore processes that don't have a connection, such as crashed contents.
136 if (!render_process_host->HasConnection())
137 continue;
138
139 RenderProcessHost::RenderWidgetHostsIterator rwit(
140 render_process_host->GetRenderWidgetHostsIterator());
141 for (; !rwit.IsAtEnd(); rwit.Advance()) {
142 const RenderWidgetHost* widget = rwit.GetCurrentValue();
143 DCHECK(widget);
144 if (!widget || !widget->IsRenderView())
145 continue;
146
147 RenderViewHost* rvh =
148 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
149 // Don't report swapped out views.
150 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out())
151 continue;
152
153 result.push_back(rvh);
154 }
155 }
156 return result;
157 }
158
127 // static 159 // static
128 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( 160 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation(
129 RenderViewHost* pending, 161 RenderViewHost* pending,
130 RenderViewHost* current) { 162 RenderViewHost* current) {
131 int cookie = DevToolsAgentHost::DisconnectRenderViewHost(pending); 163 std::string cookie = DevToolsAgentHost::DisconnectRenderViewHost(pending);
132 if (cookie != -1) 164 if (cookie != std::string())
133 DevToolsAgentHost::ConnectRenderViewHost(cookie, current); 165 DevToolsAgentHost::ConnectRenderViewHost(cookie, current);
134 } 166 }
135 167
136 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost( 168 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(
137 RenderViewHost* rvh) 169 RenderViewHost* rvh)
138 : overrides_handler_(new RendererOverridesHandler(this)) { 170 : overrides_handler_(new RendererOverridesHandler(this)) {
139 ConnectRenderViewHost(rvh, false); 171 ConnectRenderViewHost(rvh, false);
140 g_instances.Get().push_back(this); 172 g_instances.Get().push_back(this);
141 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); 173 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate();
142 if (delegate && delegate->GetAsWebContents()) 174 if (delegate && delegate->GetAsWebContents())
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 snapshot_bounds)) 372 snapshot_bounds))
341 return false; 373 return false;
342 374
343 return base::Base64Encode(base::StringPiece( 375 return base::Base64Encode(base::StringPiece(
344 reinterpret_cast<char*>(&*png.begin()), 376 reinterpret_cast<char*>(&*png.begin()),
345 png.size()), 377 png.size()),
346 base_64_data); 378 base_64_data);
347 } 379 }
348 380
349 } // namespace content 381 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_http_handler_impl.cc ('k') | content/public/browser/devtools_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698