| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 public: | 79 public: |
| 80 FrameHostHolder( | 80 FrameHostHolder( |
| 81 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host); | 81 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host); |
| 82 ~FrameHostHolder(); | 82 ~FrameHostHolder(); |
| 83 | 83 |
| 84 RenderFrameHostImpl* host() const { return host_; } | 84 RenderFrameHostImpl* host() const { return host_; } |
| 85 | 85 |
| 86 void Attach(); | 86 void Attach(); |
| 87 void Reattach(FrameHostHolder* old); | 87 void Reattach(FrameHostHolder* old); |
| 88 void Detach(); | 88 void Detach(); |
| 89 void DispatchProtocolMessage(int call_id, const std::string& message); | 89 void DispatchProtocolMessage(int session_id, |
| 90 int call_id, |
| 91 const std::string& message); |
| 90 void InspectElement(int x, int y); | 92 void InspectElement(int x, int y); |
| 91 void ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); | 93 void ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); |
| 92 void Suspend(); | 94 void Suspend(); |
| 93 void Resume(); | 95 void Resume(); |
| 94 | 96 |
| 95 private: | 97 private: |
| 96 void GrantPolicy(); | 98 void GrantPolicy(); |
| 97 void RevokePolicy(); | 99 void RevokePolicy(); |
| 98 void SendMessageToClient(const std::string& message); | 100 void SendMessageToClient(int session_id, const std::string& message); |
| 99 | 101 |
| 100 RenderFrameDevToolsAgentHost* agent_; | 102 RenderFrameDevToolsAgentHost* agent_; |
| 101 RenderFrameHostImpl* host_; | 103 RenderFrameHostImpl* host_; |
| 102 bool attached_; | 104 bool attached_; |
| 103 bool suspended_; | 105 bool suspended_; |
| 104 DevToolsMessageChunkProcessor chunk_processor_; | 106 DevToolsMessageChunkProcessor chunk_processor_; |
| 105 std::vector<std::string> pending_messages_; | 107 // <session_id, message> |
| 106 std::map<int, std::string> sent_messages_; | 108 std::vector<std::pair<int, std::string>> pending_messages_; |
| 109 // <call_id> -> <session_id, message> |
| 110 std::map<int, std::pair<int, std::string>> sent_messages_; |
| 107 }; | 111 }; |
| 108 | 112 |
| 109 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( | 113 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( |
| 110 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) | 114 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) |
| 111 : agent_(agent), | 115 : agent_(agent), |
| 112 host_(host), | 116 host_(host), |
| 113 attached_(false), | 117 attached_(false), |
| 114 suspended_(false), | 118 suspended_(false), |
| 115 chunk_processor_(base::Bind( | 119 chunk_processor_(base::Bind( |
| 116 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, | 120 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, |
| 117 base::Unretained(this))) { | 121 base::Unretained(this))) { |
| 118 DCHECK(agent_); | 122 DCHECK(agent_); |
| 119 DCHECK(host_); | 123 DCHECK(host_); |
| 120 } | 124 } |
| 121 | 125 |
| 122 RenderFrameDevToolsAgentHost::FrameHostHolder::~FrameHostHolder() { | 126 RenderFrameDevToolsAgentHost::FrameHostHolder::~FrameHostHolder() { |
| 123 if (attached_) | 127 if (attached_) |
| 124 RevokePolicy(); | 128 RevokePolicy(); |
| 125 } | 129 } |
| 126 | 130 |
| 127 void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach() { | 131 void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach() { |
| 128 host_->Send(new DevToolsAgentMsg_Attach( | 132 host_->Send(new DevToolsAgentMsg_Attach( |
| 129 host_->GetRoutingID(), agent_->GetId())); | 133 host_->GetRoutingID(), agent_->GetId(), agent_->session_id())); |
| 130 GrantPolicy(); | 134 GrantPolicy(); |
| 131 attached_ = true; | 135 attached_ = true; |
| 132 } | 136 } |
| 133 | 137 |
| 134 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( | 138 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( |
| 135 FrameHostHolder* old) { | 139 FrameHostHolder* old) { |
| 136 if (old) | 140 if (old) |
| 137 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); | 141 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); |
| 138 host_->Send(new DevToolsAgentMsg_Reattach( | 142 host_->Send(new DevToolsAgentMsg_Reattach( |
| 139 host_->GetRoutingID(), agent_->GetId(), chunk_processor_.state_cookie())); | 143 host_->GetRoutingID(), agent_->GetId(), agent_->session_id(), |
| 144 chunk_processor_.state_cookie())); |
| 140 if (old) { | 145 if (old) { |
| 141 for (const auto& pair : old->sent_messages_) | 146 for (const auto& pair : old->sent_messages_) { |
| 142 DispatchProtocolMessage(pair.first, pair.second); | 147 DispatchProtocolMessage(pair.second.first, pair.first, |
| 148 pair.second.second); |
| 149 } |
| 143 } | 150 } |
| 144 GrantPolicy(); | 151 GrantPolicy(); |
| 145 attached_ = true; | 152 attached_ = true; |
| 146 } | 153 } |
| 147 | 154 |
| 148 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { | 155 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { |
| 149 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); | 156 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); |
| 150 RevokePolicy(); | 157 RevokePolicy(); |
| 151 attached_ = false; | 158 attached_ = false; |
| 152 } | 159 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 172 } | 179 } |
| 173 } | 180 } |
| 174 | 181 |
| 175 // We are the last to disconnect from the renderer -> revoke permissions. | 182 // We are the last to disconnect from the renderer -> revoke permissions. |
| 176 if (!process_has_agents) { | 183 if (!process_has_agents) { |
| 177 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( | 184 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( |
| 178 process_host->GetID()); | 185 process_host->GetID()); |
| 179 } | 186 } |
| 180 } | 187 } |
| 181 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( | 188 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( |
| 182 int call_id, const std::string& message) { | 189 int session_id, |
| 190 int call_id, |
| 191 const std::string& message) { |
| 183 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 192 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( |
| 184 host_->GetRoutingID(), message)); | 193 host_->GetRoutingID(), session_id, message)); |
| 185 sent_messages_[call_id] = message; | 194 sent_messages_[call_id] = std::make_pair(session_id, message); |
| 186 } | 195 } |
| 187 | 196 |
| 188 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( | 197 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( |
| 189 int x, int y) { | 198 int x, int y) { |
| 190 DCHECK(attached_); | 199 DCHECK(attached_); |
| 191 host_->Send(new DevToolsAgentMsg_InspectElement( | 200 host_->Send(new DevToolsAgentMsg_InspectElement( |
| 192 host_->GetRoutingID(), x, y)); | 201 host_->GetRoutingID(), x, y)); |
| 193 } | 202 } |
| 194 | 203 |
| 195 void | 204 void |
| 196 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( | 205 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( |
| 197 const DevToolsMessageChunk& chunk) { | 206 const DevToolsMessageChunk& chunk) { |
| 198 chunk_processor_.ProcessChunkedMessageFromAgent(chunk); | 207 chunk_processor_.ProcessChunkedMessageFromAgent(chunk); |
| 199 } | 208 } |
| 200 | 209 |
| 201 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( | 210 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( |
| 211 int session_id, |
| 202 const std::string& message) { | 212 const std::string& message) { |
| 203 sent_messages_.erase(chunk_processor_.last_call_id()); | 213 sent_messages_.erase(chunk_processor_.last_call_id()); |
| 204 if (suspended_) | 214 if (suspended_) |
| 205 pending_messages_.push_back(message); | 215 pending_messages_.push_back(std::make_pair(session_id, message)); |
| 206 else | 216 else |
| 207 agent_->SendMessageToClient(message); | 217 agent_->SendMessageToClient(session_id, message); |
| 208 } | 218 } |
| 209 | 219 |
| 210 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { | 220 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { |
| 211 suspended_ = true; | 221 suspended_ = true; |
| 212 } | 222 } |
| 213 | 223 |
| 214 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { | 224 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { |
| 215 suspended_ = false; | 225 suspended_ = false; |
| 216 for (const std::string& message : pending_messages_) | 226 for (const auto& pair : pending_messages_) |
| 217 agent_->SendMessageToClient(message); | 227 agent_->SendMessageToClient(pair.first, pair.second); |
| 218 std::vector<std::string> empty; | 228 std::vector<std::pair<int, std::string>> empty; |
| 219 pending_messages_.swap(empty); | 229 pending_messages_.swap(empty); |
| 220 } | 230 } |
| 221 | 231 |
| 222 // RenderFrameDevToolsAgentHost ------------------------------------------------ | 232 // RenderFrameDevToolsAgentHost ------------------------------------------------ |
| 223 | 233 |
| 224 scoped_refptr<DevToolsAgentHost> | 234 scoped_refptr<DevToolsAgentHost> |
| 225 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { | 235 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { |
| 226 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) | 236 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) |
| 227 frame_host = frame_host->GetParent(); | 237 frame_host = frame_host->GetParent(); |
| 228 DCHECK(frame_host); | 238 DCHECK(frame_host); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 network_handler_(new devtools::network::NetworkHandler()), | 329 network_handler_(new devtools::network::NetworkHandler()), |
| 320 page_handler_(nullptr), | 330 page_handler_(nullptr), |
| 321 security_handler_(nullptr), | 331 security_handler_(nullptr), |
| 322 service_worker_handler_( | 332 service_worker_handler_( |
| 323 new devtools::service_worker::ServiceWorkerHandler()), | 333 new devtools::service_worker::ServiceWorkerHandler()), |
| 324 tracing_handler_(new devtools::tracing::TracingHandler( | 334 tracing_handler_(new devtools::tracing::TracingHandler( |
| 325 devtools::tracing::TracingHandler::Renderer, | 335 devtools::tracing::TracingHandler::Renderer, |
| 326 GetIOContext())), | 336 GetIOContext())), |
| 327 emulation_handler_(nullptr), | 337 emulation_handler_(nullptr), |
| 328 frame_trace_recorder_(nullptr), | 338 frame_trace_recorder_(nullptr), |
| 329 protocol_handler_(new DevToolsProtocolHandler( | 339 protocol_handler_(new DevToolsProtocolHandler(this)), |
| 330 this, | |
| 331 base::Bind(&RenderFrameDevToolsAgentHost::SendMessageToClient, | |
| 332 base::Unretained(this)))), | |
| 333 current_frame_crashed_(false) { | 340 current_frame_crashed_(false) { |
| 334 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 341 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
| 335 dispatcher->SetDOMHandler(dom_handler_.get()); | 342 dispatcher->SetDOMHandler(dom_handler_.get()); |
| 336 dispatcher->SetInputHandler(input_handler_.get()); | 343 dispatcher->SetInputHandler(input_handler_.get()); |
| 337 dispatcher->SetInspectorHandler(inspector_handler_.get()); | 344 dispatcher->SetInspectorHandler(inspector_handler_.get()); |
| 338 dispatcher->SetIOHandler(io_handler_.get()); | 345 dispatcher->SetIOHandler(io_handler_.get()); |
| 339 dispatcher->SetNetworkHandler(network_handler_.get()); | 346 dispatcher->SetNetworkHandler(network_handler_.get()); |
| 340 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); | 347 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); |
| 341 dispatcher->SetTracingHandler(tracing_handler_.get()); | 348 dispatcher->SetTracingHandler(tracing_handler_.get()); |
| 342 | 349 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (current_) | 424 if (current_) |
| 418 current_->Detach(); | 425 current_->Detach(); |
| 419 if (pending_) | 426 if (pending_) |
| 420 pending_->Detach(); | 427 pending_->Detach(); |
| 421 OnClientDetached(); | 428 OnClientDetached(); |
| 422 } | 429 } |
| 423 | 430 |
| 424 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 431 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( |
| 425 const std::string& message) { | 432 const std::string& message) { |
| 426 int call_id = 0; | 433 int call_id = 0; |
| 427 if (protocol_handler_->HandleOptionalMessage(message, &call_id)) | 434 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id)) |
| 428 return true; | 435 return true; |
| 429 | 436 |
| 430 if (current_) | 437 if (current_) |
| 431 current_->DispatchProtocolMessage(call_id, message); | 438 current_->DispatchProtocolMessage(session_id(), call_id, message); |
| 432 if (pending_) | 439 if (pending_) |
| 433 pending_->DispatchProtocolMessage(call_id, message); | 440 pending_->DispatchProtocolMessage(session_id(), call_id, message); |
| 434 return true; | 441 return true; |
| 435 } | 442 } |
| 436 | 443 |
| 437 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { | 444 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { |
| 438 if (current_) | 445 if (current_) |
| 439 current_->InspectElement(x, y); | 446 current_->InspectElement(x, y); |
| 440 if (pending_) | 447 if (pending_) |
| 441 pending_->InspectElement(x, y); | 448 pending_->InspectElement(x, y); |
| 442 } | 449 } |
| 443 | 450 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 RenderFrameHost* host) { | 748 RenderFrameHost* host) { |
| 742 return (current_ && current_->host() == host) || | 749 return (current_ && current_->host() == host) || |
| 743 (pending_ && pending_->host() == host); | 750 (pending_ && pending_->host() == host); |
| 744 } | 751 } |
| 745 | 752 |
| 746 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 753 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 747 return current_ && current_->host()->GetParent(); | 754 return current_ && current_->host()->GetParent(); |
| 748 } | 755 } |
| 749 | 756 |
| 750 } // namespace content | 757 } // namespace content |
| OLD | NEW |