| 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/renderer/devtools/devtools_agent.h" | 5 #include "content/renderer/devtools/devtools_agent.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if (message.type() == FrameMsg_Navigate::ID) | 94 if (message.type() == FrameMsg_Navigate::ID) |
| 95 ContinueProgram(); // Don't want to swallow the message. | 95 ContinueProgram(); // Don't want to swallow the message. |
| 96 | 96 |
| 97 return handled; | 97 return handled; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void DevToolsAgent::WidgetWillClose() { | 100 void DevToolsAgent::WidgetWillClose() { |
| 101 ContinueProgram(); | 101 ContinueProgram(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void DevToolsAgent::sendProtocolMessage( | 104 void DevToolsAgent::sendProtocolMessage(int session_id, |
| 105 int call_id, | 105 int call_id, |
| 106 const blink::WebString& message, | 106 const blink::WebString& message, |
| 107 const blink::WebString& state_cookie) { | 107 const blink::WebString& state_cookie) { |
| 108 SendChunkedProtocolMessage( | 108 SendChunkedProtocolMessage(this, routing_id(), session_id, call_id, |
| 109 this, routing_id(), call_id, message.utf8(), state_cookie.utf8()); | 109 message.utf8(), state_cookie.utf8()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* | 112 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* |
| 113 DevToolsAgent::createClientMessageLoop() { | 113 DevToolsAgent::createClientMessageLoop() { |
| 114 return new WebKitClientMessageLoopImpl(); | 114 return new WebKitClientMessageLoopImpl(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void DevToolsAgent::willEnterDebugLoop() { | 117 void DevToolsAgent::willEnterDebugLoop() { |
| 118 paused_ = true; | 118 paused_ = true; |
| 119 if (RenderWidget* widget = frame_->GetRenderWidget()) | 119 if (RenderWidget* widget = frame_->GetRenderWidget()) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 144 // static | 144 // static |
| 145 DevToolsAgent* DevToolsAgent::FromRoutingId(int routing_id) { | 145 DevToolsAgent* DevToolsAgent::FromRoutingId(int routing_id) { |
| 146 IdToAgentMap::iterator it = g_agent_for_routing_id.Get().find(routing_id); | 146 IdToAgentMap::iterator it = g_agent_for_routing_id.Get().find(routing_id); |
| 147 if (it != g_agent_for_routing_id.Get().end()) { | 147 if (it != g_agent_for_routing_id.Get().end()) { |
| 148 return it->second; | 148 return it->second; |
| 149 } | 149 } |
| 150 return NULL; | 150 return NULL; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // static | 153 // static |
| 154 void DevToolsAgent::SendChunkedProtocolMessage( | 154 void DevToolsAgent::SendChunkedProtocolMessage(IPC::Sender* sender, |
| 155 IPC::Sender* sender, | 155 int routing_id, |
| 156 int routing_id, | 156 int session_id, |
| 157 int call_id, | 157 int call_id, |
| 158 const std::string& message, | 158 const std::string& message, |
| 159 const std::string& post_state) { | 159 const std::string& post_state) { |
| 160 DevToolsMessageChunk chunk; | 160 DevToolsMessageChunk chunk; |
| 161 chunk.message_size = message.size(); | 161 chunk.message_size = message.size(); |
| 162 chunk.is_first = true; | 162 chunk.is_first = true; |
| 163 | 163 |
| 164 if (message.length() < kMaxMessageChunkSize) { | 164 if (message.length() < kMaxMessageChunkSize) { |
| 165 chunk.data = message; | 165 chunk.data = message; |
| 166 chunk.session_id = session_id; |
| 166 chunk.call_id = call_id; | 167 chunk.call_id = call_id; |
| 167 chunk.post_state = post_state; | 168 chunk.post_state = post_state; |
| 168 chunk.is_last = true; | 169 chunk.is_last = true; |
| 169 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( | 170 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( |
| 170 routing_id, chunk)); | 171 routing_id, chunk)); |
| 171 return; | 172 return; |
| 172 } | 173 } |
| 173 | 174 |
| 174 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 175 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
| 175 chunk.is_last = pos + kMaxMessageChunkSize >= message.length(); | 176 chunk.is_last = pos + kMaxMessageChunkSize >= message.length(); |
| 177 chunk.session_id = chunk.is_last ? session_id : 0; |
| 176 chunk.call_id = chunk.is_last ? call_id : 0; | 178 chunk.call_id = chunk.is_last ? call_id : 0; |
| 177 chunk.post_state = chunk.is_last ? post_state : std::string(); | 179 chunk.post_state = chunk.is_last ? post_state : std::string(); |
| 178 chunk.data = message.substr(pos, kMaxMessageChunkSize); | 180 chunk.data = message.substr(pos, kMaxMessageChunkSize); |
| 179 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( | 181 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( |
| 180 routing_id, chunk)); | 182 routing_id, chunk)); |
| 181 chunk.is_first = false; | 183 chunk.is_first = false; |
| 182 chunk.message_size = 0; | 184 chunk.message_size = 0; |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 | 187 |
| 186 void DevToolsAgent::OnAttach(const std::string& host_id) { | 188 void DevToolsAgent::OnAttach(const std::string& host_id, int session_id) { |
| 187 WebDevToolsAgent* web_agent = GetWebAgent(); | 189 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 188 if (web_agent) { | 190 if (web_agent) { |
| 189 web_agent->attach(WebString::fromUTF8(host_id)); | 191 web_agent->attach(WebString::fromUTF8(host_id), session_id); |
| 190 is_attached_ = true; | 192 is_attached_ = true; |
| 191 } | 193 } |
| 192 } | 194 } |
| 193 | 195 |
| 194 void DevToolsAgent::OnReattach(const std::string& host_id, | 196 void DevToolsAgent::OnReattach(const std::string& host_id, |
| 197 int session_id, |
| 195 const std::string& agent_state) { | 198 const std::string& agent_state) { |
| 196 WebDevToolsAgent* web_agent = GetWebAgent(); | 199 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 197 if (web_agent) { | 200 if (web_agent) { |
| 198 web_agent->reattach(WebString::fromUTF8(host_id), | 201 web_agent->reattach(WebString::fromUTF8(host_id), session_id, |
| 199 WebString::fromUTF8(agent_state)); | 202 WebString::fromUTF8(agent_state)); |
| 200 is_attached_ = true; | 203 is_attached_ = true; |
| 201 } | 204 } |
| 202 } | 205 } |
| 203 | 206 |
| 204 void DevToolsAgent::OnDetach() { | 207 void DevToolsAgent::OnDetach() { |
| 205 WebDevToolsAgent* web_agent = GetWebAgent(); | 208 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 206 if (web_agent) { | 209 if (web_agent) { |
| 207 web_agent->detach(); | 210 web_agent->detach(); |
| 208 is_attached_ = false; | 211 is_attached_ = false; |
| 209 } | 212 } |
| 210 } | 213 } |
| 211 | 214 |
| 212 void DevToolsAgent::OnDispatchOnInspectorBackend(const std::string& message) { | 215 void DevToolsAgent::OnDispatchOnInspectorBackend(int session_id, |
| 216 const std::string& message) { |
| 213 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); | 217 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); |
| 214 WebDevToolsAgent* web_agent = GetWebAgent(); | 218 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 215 if (web_agent) | 219 if (web_agent) |
| 216 web_agent->dispatchOnInspectorBackend(WebString::fromUTF8(message)); | 220 web_agent->dispatchOnInspectorBackend(session_id, |
| 221 WebString::fromUTF8(message)); |
| 217 } | 222 } |
| 218 | 223 |
| 219 void DevToolsAgent::OnInspectElement(int x, int y) { | 224 void DevToolsAgent::OnInspectElement(int x, int y) { |
| 220 WebDevToolsAgent* web_agent = GetWebAgent(); | 225 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 221 if (web_agent) { | 226 if (web_agent) { |
| 222 DCHECK(is_attached_); | 227 DCHECK(is_attached_); |
| 223 web_agent->inspectElementAt(WebPoint(x, y)); | 228 web_agent->inspectElementAt(WebPoint(x, y)); |
| 224 } | 229 } |
| 225 } | 230 } |
| 226 | 231 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 273 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
| 269 WebLocalFrame* web_frame = frame_->GetWebFrame(); | 274 WebLocalFrame* web_frame = frame_->GetWebFrame(); |
| 270 return web_frame ? web_frame->devToolsAgent() : nullptr; | 275 return web_frame ? web_frame->devToolsAgent() : nullptr; |
| 271 } | 276 } |
| 272 | 277 |
| 273 bool DevToolsAgent::IsAttached() { | 278 bool DevToolsAgent::IsAttached() { |
| 274 return is_attached_; | 279 return is_attached_; |
| 275 } | 280 } |
| 276 | 281 |
| 277 } // namespace content | 282 } // namespace content |
| OLD | NEW |