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 std::vector<std::pair<std::string, int>> pending_messages_; |
|
dgozman
2015/11/06 22:57:27
Let's comment on what all the ints mean here.
kozy
2015/11/07 01:54:44
Done.
| |
| 106 std::map<int, std::string> sent_messages_; | 108 std::map<int, std::pair<std::string, int>> sent_messages_; |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( | 111 RenderFrameDevToolsAgentHost::FrameHostHolder::FrameHostHolder( |
| 110 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) | 112 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host) |
| 111 : agent_(agent), | 113 : agent_(agent), |
| 112 host_(host), | 114 host_(host), |
| 113 attached_(false), | 115 attached_(false), |
| 114 suspended_(false), | 116 suspended_(false), |
| 115 chunk_processor_(base::Bind( | 117 chunk_processor_(base::Bind( |
| 116 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, | 118 &RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient, |
| 117 base::Unretained(this))) { | 119 base::Unretained(this))) { |
| 118 DCHECK(agent_); | 120 DCHECK(agent_); |
| 119 DCHECK(host_); | 121 DCHECK(host_); |
| 120 } | 122 } |
| 121 | 123 |
| 122 RenderFrameDevToolsAgentHost::FrameHostHolder::~FrameHostHolder() { | 124 RenderFrameDevToolsAgentHost::FrameHostHolder::~FrameHostHolder() { |
| 123 if (attached_) | 125 if (attached_) |
| 124 RevokePolicy(); | 126 RevokePolicy(); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach() { | 129 void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach() { |
| 128 host_->Send(new DevToolsAgentMsg_Attach( | 130 host_->Send(new DevToolsAgentMsg_Attach( |
| 129 host_->GetRoutingID(), agent_->GetId())); | 131 host_->GetRoutingID(), agent_->GetId(), agent_->SessionId())); |
| 130 GrantPolicy(); | 132 GrantPolicy(); |
| 131 attached_ = true; | 133 attached_ = true; |
| 132 } | 134 } |
| 133 | 135 |
| 134 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( | 136 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( |
| 135 FrameHostHolder* old) { | 137 FrameHostHolder* old) { |
| 136 if (old) | 138 if (old) |
| 137 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); | 139 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); |
| 138 host_->Send(new DevToolsAgentMsg_Reattach( | 140 host_->Send(new DevToolsAgentMsg_Reattach( |
| 139 host_->GetRoutingID(), agent_->GetId(), chunk_processor_.state_cookie())); | 141 host_->GetRoutingID(), agent_->GetId(), agent_->SessionId(), |
| 142 chunk_processor_.state_cookie())); | |
| 140 if (old) { | 143 if (old) { |
| 141 for (const auto& pair : old->sent_messages_) | 144 for (const auto& pair : old->sent_messages_) |
| 142 DispatchProtocolMessage(pair.first, pair.second); | 145 DispatchProtocolMessage(pair.second.second, pair.first, |
| 146 pair.second.first); | |
| 143 } | 147 } |
| 144 GrantPolicy(); | 148 GrantPolicy(); |
| 145 attached_ = true; | 149 attached_ = true; |
| 146 } | 150 } |
| 147 | 151 |
| 148 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { | 152 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { |
| 149 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); | 153 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); |
| 150 RevokePolicy(); | 154 RevokePolicy(); |
| 151 attached_ = false; | 155 attached_ = false; |
| 152 } | 156 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 172 } | 176 } |
| 173 } | 177 } |
| 174 | 178 |
| 175 // We are the last to disconnect from the renderer -> revoke permissions. | 179 // We are the last to disconnect from the renderer -> revoke permissions. |
| 176 if (!process_has_agents) { | 180 if (!process_has_agents) { |
| 177 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( | 181 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeReadRawCookies( |
| 178 process_host->GetID()); | 182 process_host->GetID()); |
| 179 } | 183 } |
| 180 } | 184 } |
| 181 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( | 185 void RenderFrameDevToolsAgentHost::FrameHostHolder::DispatchProtocolMessage( |
| 182 int call_id, const std::string& message) { | 186 int session_id, |
| 187 int call_id, | |
| 188 const std::string& message) { | |
| 183 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 189 host_->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( |
| 184 host_->GetRoutingID(), message)); | 190 host_->GetRoutingID(), session_id, message)); |
| 185 sent_messages_[call_id] = message; | 191 sent_messages_[call_id] = make_pair(message, session_id); |
|
dgozman
2015/11/06 22:57:27
std::make_pair everywhere
kozy
2015/11/07 01:54:44
Done.
| |
| 186 } | 192 } |
| 187 | 193 |
| 188 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( | 194 void RenderFrameDevToolsAgentHost::FrameHostHolder::InspectElement( |
| 189 int x, int y) { | 195 int x, int y) { |
| 190 host_->Send(new DevToolsAgentMsg_InspectElement( | 196 host_->Send(new DevToolsAgentMsg_InspectElement( |
| 191 host_->GetRoutingID(), agent_->GetId(), x, y)); | 197 host_->GetRoutingID(), agent_->GetId(), agent_->SessionId(), x, y)); |
| 192 } | 198 } |
| 193 | 199 |
| 194 void | 200 void |
| 195 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( | 201 RenderFrameDevToolsAgentHost::FrameHostHolder::ProcessChunkedMessageFromAgent( |
| 196 const DevToolsMessageChunk& chunk) { | 202 const DevToolsMessageChunk& chunk) { |
| 197 chunk_processor_.ProcessChunkedMessageFromAgent(chunk); | 203 chunk_processor_.ProcessChunkedMessageFromAgent(chunk); |
| 198 } | 204 } |
| 199 | 205 |
| 200 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( | 206 void RenderFrameDevToolsAgentHost::FrameHostHolder::SendMessageToClient( |
| 207 int session_id, | |
| 201 const std::string& message) { | 208 const std::string& message) { |
| 202 sent_messages_.erase(chunk_processor_.last_call_id()); | 209 sent_messages_.erase(chunk_processor_.last_call_id()); |
| 203 if (suspended_) | 210 if (suspended_) |
| 204 pending_messages_.push_back(message); | 211 pending_messages_.push_back(make_pair(message, session_id)); |
| 205 else | 212 else |
| 206 agent_->SendMessageToClient(message); | 213 agent_->SendMessageToClient(session_id, message); |
| 207 } | 214 } |
| 208 | 215 |
| 209 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { | 216 void RenderFrameDevToolsAgentHost::FrameHostHolder::Suspend() { |
| 210 suspended_ = true; | 217 suspended_ = true; |
| 211 } | 218 } |
| 212 | 219 |
| 213 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { | 220 void RenderFrameDevToolsAgentHost::FrameHostHolder::Resume() { |
| 214 suspended_ = false; | 221 suspended_ = false; |
| 215 for (const std::string& message : pending_messages_) | 222 for (const std::pair<std::string, int>& message : pending_messages_) |
|
dgozman
2015/11/06 22:57:27
for (const auto& pair : pending_messages_)
kozy
2015/11/07 01:54:44
Done.
| |
| 216 agent_->SendMessageToClient(message); | 223 agent_->SendMessageToClient(message.second, message.first); |
| 217 std::vector<std::string> empty; | 224 std::vector<std::pair<std::string, int>> v; |
|
dgozman
2015/11/06 22:57:27
Please bring back the "empty"
kozy
2015/11/07 01:54:44
Done.
| |
| 218 pending_messages_.swap(empty); | 225 pending_messages_.swap(v); |
| 219 } | 226 } |
| 220 | 227 |
| 221 // RenderFrameDevToolsAgentHost ------------------------------------------------ | 228 // RenderFrameDevToolsAgentHost ------------------------------------------------ |
| 222 | 229 |
| 223 scoped_refptr<DevToolsAgentHost> | 230 scoped_refptr<DevToolsAgentHost> |
| 224 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { | 231 DevToolsAgentHost::GetOrCreateFor(RenderFrameHost* frame_host) { |
| 225 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) | 232 while (frame_host && !ShouldCreateDevToolsFor(frame_host)) |
| 226 frame_host = frame_host->GetParent(); | 233 frame_host = frame_host->GetParent(); |
| 227 DCHECK(frame_host); | 234 DCHECK(frame_host); |
| 228 RenderFrameDevToolsAgentHost* result = FindAgentHost(frame_host); | 235 RenderFrameDevToolsAgentHost* result = FindAgentHost(frame_host); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 if (current_) | 423 if (current_) |
| 417 current_->Detach(); | 424 current_->Detach(); |
| 418 if (pending_) | 425 if (pending_) |
| 419 pending_->Detach(); | 426 pending_->Detach(); |
| 420 OnClientDetached(); | 427 OnClientDetached(); |
| 421 } | 428 } |
| 422 | 429 |
| 423 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 430 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( |
| 424 const std::string& message) { | 431 const std::string& message) { |
| 425 int call_id = 0; | 432 int call_id = 0; |
| 426 if (protocol_handler_->HandleOptionalMessage(message, &call_id)) | 433 if (protocol_handler_->HandleOptionalMessage(SessionId(), message, &call_id)) |
| 427 return true; | 434 return true; |
| 428 | 435 |
| 429 if (current_) | 436 if (current_) |
| 430 current_->DispatchProtocolMessage(call_id, message); | 437 current_->DispatchProtocolMessage(SessionId(), call_id, message); |
| 431 if (pending_) | 438 if (pending_) |
| 432 pending_->DispatchProtocolMessage(call_id, message); | 439 pending_->DispatchProtocolMessage(SessionId(), call_id, message); |
| 433 return true; | 440 return true; |
| 434 } | 441 } |
| 435 | 442 |
| 436 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { | 443 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { |
| 437 if (current_) | 444 if (current_) |
| 438 current_->InspectElement(x, y); | 445 current_->InspectElement(x, y); |
| 439 if (pending_) | 446 if (pending_) |
| 440 pending_->InspectElement(x, y); | 447 pending_->InspectElement(x, y); |
| 441 } | 448 } |
| 442 | 449 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 RenderFrameHost* host) { | 746 RenderFrameHost* host) { |
| 740 return (current_ && current_->host() == host) || | 747 return (current_ && current_->host() == host) || |
| 741 (pending_ && pending_->host() == host); | 748 (pending_ && pending_->host() == host); |
| 742 } | 749 } |
| 743 | 750 |
| 744 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 751 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 745 return current_ && current_->host()->GetParent(); | 752 return current_ && current_->host()->GetParent(); |
| 746 } | 753 } |
| 747 | 754 |
| 748 } // namespace content | 755 } // namespace content |
| OLD | NEW |