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

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

Issue 2874613003: [DevTools] Support multiple clients in DevToolsAgentHost (Closed)
Patch Set: Created 3 years, 7 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_frame_devtools_agent_host.h" 5 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
6 6
7 #include <tuple> 7 #include <tuple>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/containers/flat_map.h" 10 #include "base/containers/flat_map.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 host_->GetRoutingID(), agent_->GetId(), session->session_id())); 175 host_->GetRoutingID(), agent_->GetId(), session->session_id()));
176 GrantPolicy(); 176 GrantPolicy();
177 SessionInfo& info = session_infos_[session->session_id()]; 177 SessionInfo& info = session_infos_[session->session_id()];
178 info.chunk_processor.reset(new DevToolsMessageChunkProcessor(base::Bind( 178 info.chunk_processor.reset(new DevToolsMessageChunkProcessor(base::Bind(
179 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendChunkedMessage, 179 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendChunkedMessage,
180 base::Unretained(this)))); 180 base::Unretained(this))));
181 } 181 }
182 182
183 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( 183 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach(
184 FrameHostHolder* old) { 184 FrameHostHolder* old) {
185 int session_id = agent_->session()->session_id(); 185 for (auto& session_it : agent_->sessions()) {
186 SessionInfo& info = session_infos_[session_id]; 186 int session_id = session_it.first;
187 info.chunk_processor.reset(new DevToolsMessageChunkProcessor(base::Bind( 187 SessionInfo& info = session_infos_[session_id];
188 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendChunkedMessage, 188 info.chunk_processor.reset(new DevToolsMessageChunkProcessor(base::Bind(
189 base::Unretained(this)))); 189 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendChunkedMessage,
190 SessionInfo* old_info = nullptr; 190 base::Unretained(this))));
191 if (old) { 191 SessionInfo* old_info = nullptr;
192 auto it = old->session_infos_.find(session_id); 192 if (old) {
193 old_info = it != old->session_infos_.end() ? &(it->second) : nullptr; 193 auto it = old->session_infos_.find(session_id);
194 } 194 old_info = it != old->session_infos_.end() ? &(it->second) : nullptr;
195 if (old_info) 195 }
196 info.chunk_processor->set_state_cookie( 196 if (old_info) {
197 old_info->chunk_processor->state_cookie()); 197 info.chunk_processor->set_state_cookie(
198 host_->Send(new DevToolsAgentMsg_Reattach( 198 old_info->chunk_processor->state_cookie());
199 host_->GetRoutingID(), agent_->GetId(), session_id, 199 }
200 info.chunk_processor->state_cookie())); 200 host_->Send(new DevToolsAgentMsg_Reattach(
201 if (old_info) { 201 host_->GetRoutingID(), agent_->GetId(), session_id,
202 if (IsBrowserSideNavigationEnabled()) { 202 info.chunk_processor->state_cookie()));
203 for (const auto& pair : 203 if (old_info) {
204 old_info->sent_messages_whose_reply_came_while_suspended) { 204 if (IsBrowserSideNavigationEnabled()) {
205 for (const auto& pair :
206 old_info->sent_messages_whose_reply_came_while_suspended) {
207 DispatchProtocolMessage(session_id, pair.first, pair.second.method,
208 pair.second.message);
209 }
210 }
211 for (const auto& pair : old_info->sent_messages) {
205 DispatchProtocolMessage(session_id, pair.first, pair.second.method, 212 DispatchProtocolMessage(session_id, pair.first, pair.second.method,
206 pair.second.message); 213 pair.second.message);
207 } 214 }
208 } 215 }
209 for (const auto& pair : old_info->sent_messages) {
210 DispatchProtocolMessage(session_id, pair.first, pair.second.method,
211 pair.second.message);
212 }
213 } 216 }
214 GrantPolicy(); 217 GrantPolicy();
215 } 218 }
216 219
217 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach(int session_id) { 220 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach(int session_id) {
218 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID(), session_id)); 221 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID(), session_id));
219 RevokePolicy(); 222 RevokePolicy();
220 session_infos_.erase(session_id); 223 session_infos_.erase(session_id);
221 } 224 }
222 225
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (it == session_infos_.end()) 290 if (it == session_infos_.end())
288 return; 291 return;
289 SessionInfo& info = it->second; 292 SessionInfo& info = it->second;
290 int id = info.chunk_processor->last_call_id(); 293 int id = info.chunk_processor->last_call_id();
291 MethodAndMessage sent_message = info.sent_messages[id]; 294 MethodAndMessage sent_message = info.sent_messages[id];
292 info.sent_messages.erase(id); 295 info.sent_messages.erase(id);
293 if (suspended_) { 296 if (suspended_) {
294 info.sent_messages_whose_reply_came_while_suspended[id] = sent_message; 297 info.sent_messages_whose_reply_came_while_suspended[id] = sent_message;
295 info.pending_messages.push_back(message); 298 info.pending_messages.push_back(message);
296 } else { 299 } else {
297 // Filter any messages from previous sessions. 300 auto session_it = agent_->sessions().find(session_id);
298 if (agent_->session() && agent_->session()->session_id() == session_id) 301 if (session_it != agent_->sessions().end())
299 agent_->session()->SendMessageToClient(message); 302 session_it->second->SendMessageToClient(message);
300 // |this| may be deleted at this point. 303 // |this| may be deleted at this point.
301 } 304 }
302 } 305 }
303 306
304 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { 307 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() {
305 suspended_ = true; 308 suspended_ = true;
306 } 309 }
307 310
308 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { 311 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() {
309 suspended_ = false; 312 suspended_ = false;
310 for (auto& it : session_infos_) { 313 for (auto& it : session_infos_) {
311 SessionInfo& info = it.second; 314 SessionInfo& info = it.second;
312 if (agent_->session() && agent_->session()->session_id() == it.first) { 315 auto session_it = agent_->sessions().find(it.first);
316 if (session_it != agent_->sessions().end()) {
313 for (const std::string& message : info.pending_messages) 317 for (const std::string& message : info.pending_messages)
314 agent_->session()->SendMessageToClient(message); 318 session_it->second->SendMessageToClient(message);
315 } 319 }
316 std::vector<std::string> empty; 320 std::vector<std::string> empty;
317 info.pending_messages.swap(empty); 321 info.pending_messages.swap(empty);
318 info.sent_messages_whose_reply_came_while_suspended.clear(); 322 info.sent_messages_whose_reply_came_while_suspended.clear();
319 } 323 }
320 } 324 }
321 325
322 // RenderFrameDevToolsAgentHost ------------------------------------------------ 326 // RenderFrameDevToolsAgentHost ------------------------------------------------
323 327
324 // static 328 // static
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 session->AddHandler(base::WrapUnique(new protocol::TargetHandler())); 592 session->AddHandler(base::WrapUnique(new protocol::TargetHandler()));
589 session->AddHandler(base::WrapUnique(new protocol::TracingHandler( 593 session->AddHandler(base::WrapUnique(new protocol::TracingHandler(
590 protocol::TracingHandler::Renderer, 594 protocol::TracingHandler::Renderer,
591 frame_tree_node_ ? frame_tree_node_->frame_tree_node_id() : 0, 595 frame_tree_node_ ? frame_tree_node_->frame_tree_node_id() : 0,
592 GetIOContext()))); 596 GetIOContext())));
593 597
594 if (current_) 598 if (current_)
595 current_->Attach(session); 599 current_->Attach(session);
596 if (pending_) 600 if (pending_)
597 pending_->Attach(session); 601 pending_->Attach(session);
598 OnClientAttached(); 602 if (sessions().size() == 1)
603 OnClientsAttached();
599 } 604 }
600 605
601 void RenderFrameDevToolsAgentHost::DetachSession(int session_id) { 606 void RenderFrameDevToolsAgentHost::DetachSession(int session_id) {
602 if (current_) 607 if (current_)
603 current_->Detach(session_id); 608 current_->Detach(session_id);
604 if (pending_) 609 if (pending_)
605 pending_->Detach(session_id); 610 pending_->Detach(session_id);
606 OnClientDetached(); 611 if (sessions().empty())
612 OnClientsDetached();
607 } 613 }
608 614
609 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( 615 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage(
610 DevToolsSession* session, 616 DevToolsSession* session,
611 const std::string& message) { 617 const std::string& message) {
612 int call_id = 0; 618 int call_id = 0;
613 std::string method; 619 std::string method;
614 if (session->Dispatch(message, &call_id, &method) != 620 if (session->Dispatch(message, &call_id, &method) !=
615 protocol::Response::kFallThrough) { 621 protocol::Response::kFallThrough) {
616 return true; 622 return true;
(...skipping 20 matching lines...) Expand all
637 void RenderFrameDevToolsAgentHost::InspectElement( 643 void RenderFrameDevToolsAgentHost::InspectElement(
638 DevToolsSession* session, 644 DevToolsSession* session,
639 int x, 645 int x,
640 int y) { 646 int y) {
641 if (current_) 647 if (current_)
642 current_->InspectElement(session->session_id(), x, y); 648 current_->InspectElement(session->session_id(), x, y);
643 if (pending_) 649 if (pending_)
644 pending_->InspectElement(session->session_id(), x, y); 650 pending_->InspectElement(session->session_id(), x, y);
645 } 651 }
646 652
647 void RenderFrameDevToolsAgentHost::OnClientAttached() { 653 void RenderFrameDevToolsAgentHost::OnClientsAttached() {
648 if (!web_contents()) 654 if (!web_contents())
649 return; 655 return;
650 656
651 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); 657 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder());
652 CreatePowerSaveBlocker(); 658 CreatePowerSaveBlocker();
653 } 659 }
654 660
655 void RenderFrameDevToolsAgentHost::OnClientDetached() { 661 void RenderFrameDevToolsAgentHost::OnClientsDetached() {
656 #if defined(OS_ANDROID) 662 #if defined(OS_ANDROID)
657 power_save_blocker_.reset(); 663 power_save_blocker_.reset();
658 #endif 664 #endif
659 frame_trace_recorder_.reset(); 665 frame_trace_recorder_.reset();
660 in_navigation_protocol_message_buffer_.clear(); 666 in_navigation_protocol_message_buffer_.clear();
661 } 667 }
662 668
663 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { 669 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() {
664 Instances::iterator it = std::find(g_instances.Get().begin(), 670 Instances::iterator it = std::find(g_instances.Get().begin(),
665 g_instances.Get().end(), 671 g_instances.Get().end(),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 FrameDeleted(rfh); 846 FrameDeleted(rfh);
841 else 847 else
842 DCHECK(CheckConsistency()); 848 DCHECK(CheckConsistency());
843 } 849 }
844 850
845 void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() { 851 void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() {
846 DCHECK(current_); 852 DCHECK(current_);
847 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); 853 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this);
848 UpdateProtocolHandlers(nullptr); 854 UpdateProtocolHandlers(nullptr);
849 if (IsAttached()) 855 if (IsAttached())
850 OnClientDetached(); 856 OnClientsDetached();
851 ForceDetach(false); 857 ForceDetachAllClients(false);
852 pending_.reset(); 858 pending_.reset();
853 current_.reset(); 859 current_.reset();
854 frame_tree_node_ = nullptr; 860 frame_tree_node_ = nullptr;
855 pending_handle_ = nullptr; 861 pending_handle_ = nullptr;
856 WebContentsObserver::Observe(nullptr); 862 WebContentsObserver::Observe(nullptr);
857 Release(); 863 Release();
858 } 864 }
859 865
860 bool RenderFrameDevToolsAgentHost::CheckConsistency() { 866 bool RenderFrameDevToolsAgentHost::CheckConsistency() {
861 if (current_ && pending_ && current_->host() == pending_->host()) 867 if (current_ && pending_ && current_->host() == pending_->host())
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 #if DCHECK_IS_ON() 1006 #if DCHECK_IS_ON()
1001 // TODO(dgozman): fix this for browser side navigation. 1007 // TODO(dgozman): fix this for browser side navigation.
1002 if (!IsBrowserSideNavigationEnabled()) { 1008 if (!IsBrowserSideNavigationEnabled()) {
1003 // Check that we don't have stale host object here by accessing some random 1009 // Check that we don't have stale host object here by accessing some random
1004 // properties inside. 1010 // properties inside.
1005 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) 1011 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost())
1006 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); 1012 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID();
1007 } 1013 }
1008 #endif 1014 #endif
1009 handlers_frame_host_ = host; 1015 handlers_frame_host_ = host;
1010 if (session()) 1016 for (auto& it : sessions())
1011 session()->SetRenderFrameHost(host); 1017 it.second->SetRenderFrameHost(host);
1012 } 1018 }
1013 1019
1014 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { 1020 void RenderFrameDevToolsAgentHost::DisconnectWebContents() {
1015 if (pending_) 1021 if (pending_)
1016 DiscardPending(); 1022 DiscardPending();
1017 UpdateProtocolHandlers(nullptr); 1023 UpdateProtocolHandlers(nullptr);
1018 disconnected_ = std::move(current_); 1024 disconnected_ = std::move(current_);
1019 disconnected_->Disconnect(); 1025 disconnected_->Disconnect();
1020 frame_tree_node_ = nullptr; 1026 frame_tree_node_ = nullptr;
1021 in_navigation_protocol_message_buffer_.clear(); 1027 in_navigation_protocol_message_buffer_.clear();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 RenderFrameHost* host) { 1210 RenderFrameHost* host) {
1205 return (current_ && current_->host() == host) || 1211 return (current_ && current_->host() == host) ||
1206 (pending_ && pending_->host() == host); 1212 (pending_ && pending_->host() == host);
1207 } 1213 }
1208 1214
1209 bool RenderFrameDevToolsAgentHost::IsChildFrame() { 1215 bool RenderFrameDevToolsAgentHost::IsChildFrame() {
1210 return current_ && current_->host()->GetParent(); 1216 return current_ && current_->host()->GetParent();
1211 } 1217 }
1212 1218
1213 } // namespace content 1219 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/render_frame_devtools_agent_host.h ('k') | content/browser/devtools/worker_devtools_agent_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698