| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "content/common/devtools_messages.h" | 15 #include "content/common/devtools_messages.h" |
| 16 #include "content/common/frame_messages.h" | 16 #include "content/common/frame_messages.h" |
| 17 #include "content/renderer/devtools/devtools_client.h" | 17 #include "content/renderer/devtools/devtools_client.h" |
| 18 #include "content/renderer/devtools/devtools_cpu_throttler.h" | 18 #include "content/renderer/devtools/devtools_cpu_throttler.h" |
| 19 #include "content/renderer/render_frame_impl.h" | 19 #include "content/renderer/render_frame_impl.h" |
| 20 #include "content/renderer/render_widget.h" | 20 #include "content/renderer/render_widget.h" |
| 21 #include "ipc/ipc_channel.h" | 21 #include "ipc/ipc_channel.h" |
| 22 #include "third_party/WebKit/public/platform/WebPoint.h" | 22 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 23 #include "third_party/WebKit/public/platform/WebString.h" | 23 #include "third_party/WebKit/public/platform/WebString.h" |
| 24 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | |
| 25 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" | 24 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 27 | 26 |
| 28 using blink::WebConsoleMessage; | |
| 29 using blink::WebDevToolsAgent; | 27 using blink::WebDevToolsAgent; |
| 30 using blink::WebDevToolsAgentClient; | 28 using blink::WebDevToolsAgentClient; |
| 31 using blink::WebLocalFrame; | 29 using blink::WebLocalFrame; |
| 32 using blink::WebPoint; | 30 using blink::WebPoint; |
| 33 using blink::WebString; | 31 using blink::WebString; |
| 34 | 32 |
| 35 using base::trace_event::TraceLog; | 33 using base::trace_event::TraceLog; |
| 36 | 34 |
| 37 namespace content { | 35 namespace content { |
| 38 | 36 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 236 |
| 239 void DevToolsAgent::OnInspectElement(int x, int y) { | 237 void DevToolsAgent::OnInspectElement(int x, int y) { |
| 240 GetWebAgent()->inspectElementAt(WebPoint(x, y)); | 238 GetWebAgent()->inspectElementAt(WebPoint(x, y)); |
| 241 } | 239 } |
| 242 | 240 |
| 243 void DevToolsAgent::OnRequestNewWindowACK(bool success) { | 241 void DevToolsAgent::OnRequestNewWindowACK(bool success) { |
| 244 if (!success) | 242 if (!success) |
| 245 GetWebAgent()->failedToRequestDevTools(); | 243 GetWebAgent()->failedToRequestDevTools(); |
| 246 } | 244 } |
| 247 | 245 |
| 248 void DevToolsAgent::AddMessageToConsole(ConsoleMessageLevel level, | |
| 249 const std::string& message) { | |
| 250 WebLocalFrame* web_frame = frame_->GetWebFrame(); | |
| 251 | |
| 252 WebConsoleMessage::Level target_level = WebConsoleMessage::LevelLog; | |
| 253 switch (level) { | |
| 254 case CONSOLE_MESSAGE_LEVEL_DEBUG: | |
| 255 target_level = WebConsoleMessage::LevelDebug; | |
| 256 break; | |
| 257 case CONSOLE_MESSAGE_LEVEL_LOG: | |
| 258 target_level = WebConsoleMessage::LevelLog; | |
| 259 break; | |
| 260 case CONSOLE_MESSAGE_LEVEL_WARNING: | |
| 261 target_level = WebConsoleMessage::LevelWarning; | |
| 262 break; | |
| 263 case CONSOLE_MESSAGE_LEVEL_ERROR: | |
| 264 target_level = WebConsoleMessage::LevelError; | |
| 265 break; | |
| 266 } | |
| 267 web_frame->addMessageToConsole( | |
| 268 WebConsoleMessage(target_level, WebString::fromUTF8(message))); | |
| 269 } | |
| 270 | |
| 271 void DevToolsAgent::ContinueProgram() { | 246 void DevToolsAgent::ContinueProgram() { |
| 272 GetWebAgent()->continueProgram(); | 247 GetWebAgent()->continueProgram(); |
| 273 } | 248 } |
| 274 | 249 |
| 275 void DevToolsAgent::OnSetupDevToolsClient( | 250 void DevToolsAgent::OnSetupDevToolsClient( |
| 276 const std::string& compatibility_script) { | 251 const std::string& compatibility_script) { |
| 277 // We only want to register once; and only in main frame. | 252 // We only want to register once; and only in main frame. |
| 278 DCHECK(!frame_->GetWebFrame()->parent()); | 253 DCHECK(!frame_->GetWebFrame()->parent()); |
| 279 if (is_devtools_client_) | 254 if (is_devtools_client_) |
| 280 return; | 255 return; |
| 281 is_devtools_client_ = true; | 256 is_devtools_client_ = true; |
| 282 new DevToolsClient(frame_, compatibility_script); | 257 new DevToolsClient(frame_, compatibility_script); |
| 283 } | 258 } |
| 284 | 259 |
| 285 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 260 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
| 286 return frame_->GetWebFrame()->devToolsAgent(); | 261 return frame_->GetWebFrame()->devToolsAgent(); |
| 287 } | 262 } |
| 288 | 263 |
| 289 bool DevToolsAgent::IsAttached() { | 264 bool DevToolsAgent::IsAttached() { |
| 290 return is_attached_; | 265 return is_attached_; |
| 291 } | 266 } |
| 292 | 267 |
| 293 } // namespace content | 268 } // namespace content |
| OLD | NEW |