| 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_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/guid.h" | 10 #include "base/guid.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 RenderFrameDevToolsAgentHost* agent_; | 124 RenderFrameDevToolsAgentHost* agent_; |
| 125 RenderFrameHostImpl* host_; | 125 RenderFrameHostImpl* host_; |
| 126 bool attached_; | 126 bool attached_; |
| 127 bool suspended_; | 127 bool suspended_; |
| 128 DevToolsMessageChunkProcessor chunk_processor_; | 128 DevToolsMessageChunkProcessor chunk_processor_; |
| 129 // <session_id, message> | 129 // <session_id, message> |
| 130 std::vector<std::pair<int, std::string>> pending_messages_; | 130 std::vector<std::pair<int, std::string>> pending_messages_; |
| 131 // <call_id> -> PendingMessage | 131 // <call_id> -> PendingMessage |
| 132 std::map<int, PendingMessage> sent_messages_; | 132 std::map<int, PendingMessage> sent_messages_; |
| 133 // These are sent messages for which we got a reply while suspended. |
| 134 std::map<int, PendingMessage> sent_messages_whose_reply_came_while_suspended_; |
| 133 }; | 135 }; |
| 134 | 136 |
| 135 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( | 137 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( |
| 136 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) | 138 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) |
| 137 : agent_(agent), | 139 : agent_(agent), |
| 138 host_(host), | 140 host_(host), |
| 139 attached_(false), | 141 attached_(false), |
| 140 suspended_(false), | 142 suspended_(false), |
| 141 chunk_processor_(base::Bind( | 143 chunk_processor_(base::Bind( |
| 142 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, | 144 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 } | 160 } |
| 159 | 161 |
| 160 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( | 162 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( |
| 161 FrameHostHolder* old) { | 163 FrameHostHolder* old) { |
| 162 if (old) | 164 if (old) |
| 163 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); | 165 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); |
| 164 host_->Send(new DevToolsAgentMsg_Reattach( | 166 host_->Send(new DevToolsAgentMsg_Reattach( |
| 165 host_->GetRoutingID(), agent_->GetId(), agent_->session()->session_id(), | 167 host_->GetRoutingID(), agent_->GetId(), agent_->session()->session_id(), |
| 166 chunk_processor_.state_cookie())); | 168 chunk_processor_.state_cookie())); |
| 167 if (old) { | 169 if (old) { |
| 170 if (IsBrowserSideNavigationEnabled()) { |
| 171 for (const auto& pair : |
| 172 old->sent_messages_whose_reply_came_while_suspended_) { |
| 173 DispatchProtocolMessage(pair.second.session_id, pair.first, |
| 174 pair.second.method, pair.second.message); |
| 175 } |
| 176 } |
| 168 for (const auto& pair : old->sent_messages_) { | 177 for (const auto& pair : old->sent_messages_) { |
| 169 DispatchProtocolMessage(pair.second.session_id, pair.first, | 178 DispatchProtocolMessage(pair.second.session_id, pair.first, |
| 170 pair.second.method, pair.second.message); | 179 pair.second.method, pair.second.message); |
| 171 } | 180 } |
| 172 } | 181 } |
| 173 GrantPolicy(); | 182 GrantPolicy(); |
| 174 attached_ = true; | 183 attached_ = true; |
| 175 } | 184 } |
| 176 | 185 |
| 177 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { | 186 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 235 |
| 227 bool | 236 bool |
| 228 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( | 237 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( |
| 229 const DevToolsMessageChunk& chunk) { | 238 const DevToolsMessageChunk& chunk) { |
| 230 return chunk_processor_.ProcessChunkedMessageFromAgent(chunk); | 239 return chunk_processor_.ProcessChunkedMessageFromAgent(chunk); |
| 231 } | 240 } |
| 232 | 241 |
| 233 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( | 242 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( |
| 234 int session_id, | 243 int session_id, |
| 235 const std::string& message) { | 244 const std::string& message) { |
| 236 sent_messages_.erase(chunk_processor_.last_call_id()); | 245 int id = chunk_processor_.last_call_id(); |
| 237 if (suspended_) | 246 if (suspended_) { |
| 247 sent_messages_whose_reply_came_while_suspended_[id] = sent_messages_[id]; |
| 238 pending_messages_.push_back(std::make_pair(session_id, message)); | 248 pending_messages_.push_back(std::make_pair(session_id, message)); |
| 239 else | 249 } else { |
| 240 agent_->SendMessageToClient(session_id, message); | 250 agent_->SendMessageToClient(session_id, message); |
| 251 } |
| 252 sent_messages_.erase(id); |
| 241 } | 253 } |
| 242 | 254 |
| 243 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { | 255 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { |
| 244 suspended_ = true; | 256 suspended_ = true; |
| 245 } | 257 } |
| 246 | 258 |
| 247 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { | 259 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { |
| 248 suspended_ = false; | 260 suspended_ = false; |
| 249 for (const auto& pair : pending_messages_) | 261 for (const auto& pair : pending_messages_) |
| 250 agent_->SendMessageToClient(pair.first, pair.second); | 262 agent_->SendMessageToClient(pair.first, pair.second); |
| 251 std::vector<std::pair<int, std::string>> empty; | 263 std::vector<std::pair<int, std::string>> empty; |
| 252 pending_messages_.swap(empty); | 264 pending_messages_.swap(empty); |
| 265 sent_messages_whose_reply_came_while_suspended_.clear(); |
| 253 } | 266 } |
| 254 | 267 |
| 255 // RenderFrameDevToolsAgentHost ------------------------------------------------ | 268 // RenderFrameDevToolsAgentHost ------------------------------------------------ |
| 256 | 269 |
| 257 // static | 270 // static |
| 258 scoped_refptr<DevToolsAgentHost> | 271 scoped_refptr<DevToolsAgentHost> |
| 259 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { | 272 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { |
| 260 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) | 273 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) |
| 261 frame_host = frame_host->GetParent(); | 274 frame_host = frame_host->GetParent(); |
| 262 DCHECK(frame_host); | 275 DCHECK(frame_host); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 if (pending_handle_ == navigation_handle) { | 697 if (pending_handle_ == navigation_handle) { |
| 685 // This navigation handle did set the pending FrameHostHolder. | 698 // This navigation handle did set the pending FrameHostHolder. |
| 686 DCHECK(pending_); | 699 DCHECK(pending_); |
| 687 if (navigation_handle->HasCommitted()) { | 700 if (navigation_handle->HasCommitted()) { |
| 688 DCHECK(pending_->host() == navigation_handle->GetRenderFrameHost()); | 701 DCHECK(pending_->host() == navigation_handle->GetRenderFrameHost()); |
| 689 CommitPending(); | 702 CommitPending(); |
| 690 } else { | 703 } else { |
| 691 DiscardPending(); | 704 DiscardPending(); |
| 692 } | 705 } |
| 693 pending_handle_ = nullptr; | 706 pending_handle_ = nullptr; |
| 707 } else if (navigating_handles_.empty()) { |
| 708 current_->Resume(); |
| 694 } | 709 } |
| 695 DispatchBufferedProtocolMessagesIfNecessary(); | 710 DispatchBufferedProtocolMessagesIfNecessary(); |
| 696 | 711 |
| 697 DCHECK(CheckConsistency()); | 712 DCHECK(CheckConsistency()); |
| 698 if (target_handler_ && navigation_handle->HasCommitted()) | 713 if (target_handler_ && navigation_handle->HasCommitted()) |
| 699 target_handler_->UpdateServiceWorkers(); | 714 target_handler_->UpdateServiceWorkers(); |
| 700 } | 715 } |
| 701 | 716 |
| 702 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 717 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( |
| 703 RenderFrameHost* old_host, | 718 RenderFrameHost* old_host, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 725 CommitPending(); | 740 CommitPending(); |
| 726 DCHECK(CheckConsistency()); | 741 DCHECK(CheckConsistency()); |
| 727 } | 742 } |
| 728 | 743 |
| 729 void RenderFrameDevToolsAgentHost::AboutToNavigate( | 744 void RenderFrameDevToolsAgentHost::AboutToNavigate( |
| 730 NavigationHandle* navigation_handle) { | 745 NavigationHandle* navigation_handle) { |
| 731 if (!IsBrowserSideNavigationEnabled()) | 746 if (!IsBrowserSideNavigationEnabled()) |
| 732 return; | 747 return; |
| 733 DCHECK(current_); | 748 DCHECK(current_); |
| 734 navigating_handles_.insert(navigation_handle); | 749 navigating_handles_.insert(navigation_handle); |
| 750 current_->Suspend(); |
| 735 DCHECK(CheckConsistency()); | 751 DCHECK(CheckConsistency()); |
| 736 } | 752 } |
| 737 | 753 |
| 738 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 754 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( |
| 739 RenderFrameHost* old_host, | 755 RenderFrameHost* old_host, |
| 740 RenderFrameHost* new_host) { | 756 RenderFrameHost* new_host) { |
| 741 // CommitPending may destruct |this|. | 757 // CommitPending may destruct |this|. |
| 742 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 758 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 743 | 759 |
| 744 if (target_handler_) | 760 if (target_handler_) |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 RenderFrameHost* host) { | 1208 RenderFrameHost* host) { |
| 1193 return (current_ && current_->host() == host) || | 1209 return (current_ && current_->host() == host) || |
| 1194 (pending_ && pending_->host() == host); | 1210 (pending_ && pending_->host() == host); |
| 1195 } | 1211 } |
| 1196 | 1212 |
| 1197 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1213 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1198 return current_ && current_->host()->GetParent(); | 1214 return current_ && current_->host()->GetParent(); |
| 1199 } | 1215 } |
| 1200 | 1216 |
| 1201 } // namespace content | 1217 } // namespace content |
| OLD | NEW |