Chromium Code Reviews| 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 // <message, session_id> |
| 106 std::map<int, std::string> sent_messages_; | 108 std::vector<std::pair<std::string, int>> pending_messages_; |
| 109 // <call_id> -> <message, session_id> | |
| 110 std::map<int, std::pair<std::string, int>> 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_) |
|
dgozman
2015/11/07 02:28:40
{}
kozy
2015/11/07 03:02:35
Done.
| |
| 142 DispatchProtocolMessage(pair.first, pair.second); | 147 DispatchProtocolMessage(pair.second.second, pair.first, |
| 148 pair.second.first); | |
| 143 } | 149 } |
| 144 GrantPolicy(); | 150 GrantPolicy(); |
| 145 attached_ = true; | 151 attached_ = true; |
| 146 } | 152 } |
| 147 | 153 |
| 148 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { | 154 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { |
| 149 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); | 155 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); |
| 150 RevokePolicy(); | 156 RevokePolicy(); |
| 151 attached_ = false; | 157 attached_ = false; |
| 152 } | 158 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 172 } | 178 } |
| 173 } | 179 } |
| 174 | 180 |
| 175 // We are the last to disconnect from the renderer -> revoke permissions. | 181 // We are the last to disconnect from the renderer -> revoke permissions. |
| 176 if (!process_has_agents) { | 182 if (!process_has_agents) { |
| 177 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( | 183 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( |
| 178 process_host->GetID()); | 184 process_host->GetID()); |
| 179 } | 185 } |
| 180 } | 186 } |
| 181 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( | 187 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( |
| 182 int call_id, const std::string& message) { | 188 int session_id, |
| 189 int call_id, | |
| 190 const std::string& message) { | |
| 183 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 191 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( |
| 184 host_->GetRoutingID(), message)); | 192 host_->GetRoutingID(), session_id, message)); |
| 185 sent_messages_[call_id] = message; | 193 sent_messages_[call_id] = std::make_pair(message, session_id); |
| 186 } | 194 } |
| 187 | 195 |
| 188 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( | 196 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( |
| 189 int x, int y) { | 197 int x, int y) { |
| 190 host_->Send(new DevToolsAgentMsg_InspectElement( | 198 host_->Send(new DevToolsAgentMsg_InspectElement( |
| 191 host_->GetRoutingID(), agent_->GetId(), x, y)); | 199 host_->GetRoutingID(), agent_->GetId(), agent_->session_id(), x, y)); |
| 192 } | 200 } |
| 193 | 201 |
| 194 void | 202 void |
| 195 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( | 203 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( |
| 196 const DevToolsMessageChunk& chunk) { | 204 const DevToolsMessageChunk& chunk) { |
| 197 chunk_processor_.ProcessChunkedMessageFromAgent(chunk); | 205 chunk_processor_.ProcessChunkedMessageFromAgent(chunk); |
| 198 } | 206 } |
| 199 | 207 |
| 200 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( | 208 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( |
| 209 int session_id, | |
| 201 const std::string& message) { | 210 const std::string& message) { |
| 202 sent_messages_.erase(chunk_processor_.last_call_id()); | 211 sent_messages_.erase(chunk_processor_.last_call_id()); |
| 203 if (suspended_) | 212 if (suspended_) |
| 204 pending_messages_.push_back(message); | 213 pending_messages_.push_back(make_pair(message, session_id)); |
| 205 else | 214 else |
| 206 agent_->SendMessageToClient(message); | 215 agent_->SendMessageToClient(session_id, message); |
| 207 } | 216 } |
| 208 | 217 |
| 209 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { | 218 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { |
| 210 suspended_ = true; | 219 suspended_ = true; |
| 211 } | 220 } |
| 212 | 221 |
| 213 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { | 222 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { |
| 214 suspended_ = false; | 223 suspended_ = false; |
| 215 for (const std::string& message : pending_messages_) | 224 for (const auto& pair : pending_messages_) |
| 216 agent_->SendMessageToClient(message); | 225 agent_->SendMessageToClient(pair.second, pair.first); |
|
dgozman
2015/11/07 02:28:40
Let's reverse the pair order.
kozy
2015/11/07 03:02:35
Done.
| |
| 217 std::vector<std::string> empty; | 226 std::vector<std::pair<std::string, int>> empty; |
| 218 pending_messages_.swap(empty); | 227 pending_messages_.swap(empty); |
| 219 } | 228 } |
| 220 | 229 |
| 221 // RenderFrameDevToolsAgentHost ------------------------------------------------ | 230 // RenderFrameDevToolsAgentHost ------------------------------------------------ |
| 222 | 231 |
| 223 scoped_refptr<DevToolsAgentHost> | 232 scoped_refptr<DevToolsAgentHost> |
| 224 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { | 233 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { |
| 225 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) | 234 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) |
| 226 frame_host = frame_host->GetParent(); | 235 frame_host = frame_host->GetParent(); |
| 227 DCHECK(frame_host); | 236 DCHECK(frame_host); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 network_handler_(new devtools::network::NetworkHandler()), | 327 network_handler_(new devtools::network::NetworkHandler()), |
| 319 page_handler_(nullptr), | 328 page_handler_(nullptr), |
| 320 security_handler_(nullptr), | 329 security_handler_(nullptr), |
| 321 service_worker_handler_( | 330 service_worker_handler_( |
| 322 new devtools::service_worker::ServiceWorkerHandler()), | 331 new devtools::service_worker::ServiceWorkerHandler()), |
| 323 tracing_handler_(new devtools::tracing::TracingHandler( | 332 tracing_handler_(new devtools::tracing::TracingHandler( |
| 324 devtools::tracing::TracingHandler::Renderer, | 333 devtools::tracing::TracingHandler::Renderer, |
| 325 GetIOContext())), | 334 GetIOContext())), |
| 326 emulation_handler_(nullptr), | 335 emulation_handler_(nullptr), |
| 327 frame_trace_recorder_(nullptr), | 336 frame_trace_recorder_(nullptr), |
| 328 protocol_handler_(new DevToolsProtocolHandler( | 337 protocol_handler_(new DevToolsProtocolHandler(this, this)), |
| 329 this, | |
| 330 base::Bind(&RenderFrameDevToolsAgentHost::SendMessageToClient, | |
| 331 base::Unretained(this)))), | |
| 332 current_frame_crashed_(false) { | 338 current_frame_crashed_(false) { |
| 333 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 339 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
| 334 dispatcher->SetDOMHandler(dom_handler_.get()); | 340 dispatcher->SetDOMHandler(dom_handler_.get()); |
| 335 dispatcher->SetInputHandler(input_handler_.get()); | 341 dispatcher->SetInputHandler(input_handler_.get()); |
| 336 dispatcher->SetInspectorHandler(inspector_handler_.get()); | 342 dispatcher->SetInspectorHandler(inspector_handler_.get()); |
| 337 dispatcher->SetIOHandler(io_handler_.get()); | 343 dispatcher->SetIOHandler(io_handler_.get()); |
| 338 dispatcher->SetNetworkHandler(network_handler_.get()); | 344 dispatcher->SetNetworkHandler(network_handler_.get()); |
| 339 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); | 345 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); |
| 340 dispatcher->SetTracingHandler(tracing_handler_.get()); | 346 dispatcher->SetTracingHandler(tracing_handler_.get()); |
| 341 | 347 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 if (current_) | 422 if (current_) |
| 417 current_->Detach(); | 423 current_->Detach(); |
| 418 if (pending_) | 424 if (pending_) |
| 419 pending_->Detach(); | 425 pending_->Detach(); |
| 420 OnClientDetached(); | 426 OnClientDetached(); |
| 421 } | 427 } |
| 422 | 428 |
| 423 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 429 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( |
| 424 const std::string& message) { | 430 const std::string& message) { |
| 425 int call_id = 0; | 431 int call_id = 0; |
| 426 if (protocol_handler_->HandleOptionalMessage(message, &call_id)) | 432 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id)) |
| 427 return true; | 433 return true; |
| 428 | 434 |
| 429 if (current_) | 435 if (current_) |
| 430 current_->DispatchProtocolMessage(call_id, message); | 436 current_->DispatchProtocolMessage(session_id(), call_id, message); |
| 431 if (pending_) | 437 if (pending_) |
| 432 pending_->DispatchProtocolMessage(call_id, message); | 438 pending_->DispatchProtocolMessage(session_id(), call_id, message); |
| 433 return true; | 439 return true; |
| 434 } | 440 } |
| 435 | 441 |
| 436 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { | 442 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { |
| 437 if (current_) | 443 if (current_) |
| 438 current_->InspectElement(x, y); | 444 current_->InspectElement(x, y); |
| 439 if (pending_) | 445 if (pending_) |
| 440 pending_->InspectElement(x, y); | 446 pending_->InspectElement(x, y); |
| 441 } | 447 } |
| 442 | 448 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 RenderFrameHost* host) { | 745 RenderFrameHost* host) { |
| 740 return (current_ && current_->host() == host) || | 746 return (current_ && current_->host() == host) || |
| 741 (pending_ && pending_->host() == host); | 747 (pending_ && pending_->host() == host); |
| 742 } | 748 } |
| 743 | 749 |
| 744 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 750 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 745 return current_ && current_->host()->GetParent(); | 751 return current_ && current_->host()->GetParent(); |
| 746 } | 752 } |
| 747 | 753 |
| 748 } // namespace content | 754 } // namespace content |
| OLD | NEW |