| 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(int session_id, | 104 void DevToolsAgent::sendProtocolMessage( |
| 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(this, routing_id(), session_id, call_id, | 108 SendChunkedProtocolMessage( |
| 109 message.utf8(), state_cookie.utf8()); | 109 this, routing_id(), call_id, 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(IPC::Sender* sender, | 154 void DevToolsAgent::SendChunkedProtocolMessage( |
| 155 int routing_id, | 155 IPC::Sender* sender, |
| 156 int session_id, | 156 int routing_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; | |
| 167 chunk.call_id = call_id; | 166 chunk.call_id = call_id; |
| 168 chunk.post_state = post_state; | 167 chunk.post_state = post_state; |
| 169 chunk.is_last = true; | 168 chunk.is_last = true; |
| 170 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( | 169 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( |
| 171 routing_id, chunk)); | 170 routing_id, chunk)); |
| 172 return; | 171 return; |
| 173 } | 172 } |
| 174 | 173 |
| 175 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 174 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
| 176 chunk.is_last = pos + kMaxMessageChunkSize >= message.length(); | 175 chunk.is_last = pos + kMaxMessageChunkSize >= message.length(); |
| 177 chunk.session_id = chunk.is_last ? session_id : 0; | |
| 178 chunk.call_id = chunk.is_last ? call_id : 0; | 176 chunk.call_id = chunk.is_last ? call_id : 0; |
| 179 chunk.post_state = chunk.is_last ? post_state : std::string(); | 177 chunk.post_state = chunk.is_last ? post_state : std::string(); |
| 180 chunk.data = message.substr(pos, kMaxMessageChunkSize); | 178 chunk.data = message.substr(pos, kMaxMessageChunkSize); |
| 181 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( | 179 sender->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( |
| 182 routing_id, chunk)); | 180 routing_id, chunk)); |
| 183 chunk.is_first = false; | 181 chunk.is_first = false; |
| 184 chunk.message_size = 0; | 182 chunk.message_size = 0; |
| 185 } | 183 } |
| 186 } | 184 } |
| 187 | 185 |
| 188 void DevToolsAgent::OnAttach(const std::string& host_id, int session_id) { | 186 void DevToolsAgent::OnAttach(const std::string& host_id) { |
| 189 WebDevToolsAgent* web_agent = GetWebAgent(); | 187 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 190 if (web_agent) { | 188 if (web_agent) { |
| 191 web_agent->attach(WebString::fromUTF8(host_id), session_id); | 189 web_agent->attach(WebString::fromUTF8(host_id)); |
| 192 is_attached_ = true; | 190 is_attached_ = true; |
| 193 } | 191 } |
| 194 } | 192 } |
| 195 | 193 |
| 196 void DevToolsAgent::OnReattach(const std::string& host_id, | 194 void DevToolsAgent::OnReattach(const std::string& host_id, |
| 197 int session_id, | |
| 198 const std::string& agent_state) { | 195 const std::string& agent_state) { |
| 199 WebDevToolsAgent* web_agent = GetWebAgent(); | 196 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 200 if (web_agent) { | 197 if (web_agent) { |
| 201 web_agent->reattach(WebString::fromUTF8(host_id), session_id, | 198 web_agent->reattach(WebString::fromUTF8(host_id), |
| 202 WebString::fromUTF8(agent_state)); | 199 WebString::fromUTF8(agent_state)); |
| 203 is_attached_ = true; | 200 is_attached_ = true; |
| 204 } | 201 } |
| 205 } | 202 } |
| 206 | 203 |
| 207 void DevToolsAgent::OnDetach() { | 204 void DevToolsAgent::OnDetach() { |
| 208 WebDevToolsAgent* web_agent = GetWebAgent(); | 205 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 209 if (web_agent) { | 206 if (web_agent) { |
| 210 web_agent->detach(); | 207 web_agent->detach(); |
| 211 is_attached_ = false; | 208 is_attached_ = false; |
| 212 } | 209 } |
| 213 } | 210 } |
| 214 | 211 |
| 215 void DevToolsAgent::OnDispatchOnInspectorBackend(int session_id, | 212 void DevToolsAgent::OnDispatchOnInspectorBackend(const std::string& message) { |
| 216 const std::string& message) { | |
| 217 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); | 213 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); |
| 218 WebDevToolsAgent* web_agent = GetWebAgent(); | 214 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 219 if (web_agent) | 215 if (web_agent) |
| 220 web_agent->dispatchOnInspectorBackend(session_id, | 216 web_agent->dispatchOnInspectorBackend(WebString::fromUTF8(message)); |
| 221 WebString::fromUTF8(message)); | |
| 222 } | 217 } |
| 223 | 218 |
| 224 void DevToolsAgent::OnInspectElement(const std::string& host_id, | 219 void DevToolsAgent::OnInspectElement( |
| 225 int session_id, | 220 const std::string& host_id, int x, int y) { |
| 226 int x, | |
| 227 int y) { | |
| 228 WebDevToolsAgent* web_agent = GetWebAgent(); | 221 WebDevToolsAgent* web_agent = GetWebAgent(); |
| 229 if (web_agent) { | 222 if (web_agent) { |
| 230 web_agent->attach(WebString::fromUTF8(host_id), session_id); | 223 web_agent->attach(WebString::fromUTF8(host_id)); |
| 231 web_agent->inspectElementAt(WebPoint(x, y)); | 224 web_agent->inspectElementAt(WebPoint(x, y)); |
| 232 is_attached_ = true; | 225 is_attached_ = true; |
| 233 } | 226 } |
| 234 } | 227 } |
| 235 | 228 |
| 236 void DevToolsAgent::AddMessageToConsole(ConsoleMessageLevel level, | 229 void DevToolsAgent::AddMessageToConsole(ConsoleMessageLevel level, |
| 237 const std::string& message) { | 230 const std::string& message) { |
| 238 WebLocalFrame* web_frame = frame_->GetWebFrame(); | 231 WebLocalFrame* web_frame = frame_->GetWebFrame(); |
| 239 if (!web_frame) | 232 if (!web_frame) |
| 240 return; | 233 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 270 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
| 278 WebLocalFrame* web_frame = frame_->GetWebFrame(); | 271 WebLocalFrame* web_frame = frame_->GetWebFrame(); |
| 279 return web_frame ? web_frame->devToolsAgent() : nullptr; | 272 return web_frame ? web_frame->devToolsAgent() : nullptr; |
| 280 } | 273 } |
| 281 | 274 |
| 282 bool DevToolsAgent::IsAttached() { | 275 bool DevToolsAgent::IsAttached() { |
| 283 return is_attached_; | 276 return is_attached_; |
| 284 } | 277 } |
| 285 | 278 |
| 286 } // namespace content | 279 } // namespace content |
| OLD | NEW |