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/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/json/json_writer.h" | |
| 11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 15 #include "content/common/devtools_messages.h" | 16 #include "content/common/devtools_messages.h" |
| 16 #include "content/common/frame_messages.h" | 17 #include "content/common/frame_messages.h" |
| 18 #include "content/public/common/manifest.h" | |
| 17 #include "content/renderer/devtools/devtools_client.h" | 19 #include "content/renderer/devtools/devtools_client.h" |
| 18 #include "content/renderer/devtools/devtools_cpu_throttler.h" | 20 #include "content/renderer/devtools/devtools_cpu_throttler.h" |
| 21 #include "content/renderer/manifest/manifest_manager.h" | |
| 19 #include "content/renderer/render_frame_impl.h" | 22 #include "content/renderer/render_frame_impl.h" |
| 20 #include "content/renderer/render_widget.h" | 23 #include "content/renderer/render_widget.h" |
| 21 #include "ipc/ipc_channel.h" | 24 #include "ipc/ipc_channel.h" |
| 22 #include "third_party/WebKit/public/platform/WebPoint.h" | 25 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 23 #include "third_party/WebKit/public/platform/WebString.h" | 26 #include "third_party/WebKit/public/platform/WebString.h" |
| 24 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" | 27 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 28 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 26 | 29 |
| 27 using blink::WebDevToolsAgent; | 30 using blink::WebDevToolsAgent; |
| 28 using blink::WebDevToolsAgentClient; | 31 using blink::WebDevToolsAgentClient; |
| 29 using blink::WebLocalFrame; | 32 using blink::WebLocalFrame; |
| 30 using blink::WebPoint; | 33 using blink::WebPoint; |
| 31 using blink::WebString; | 34 using blink::WebString; |
| 32 | 35 |
| 33 using base::trace_event::TraceLog; | 36 using base::trace_event::TraceLog; |
| 34 | 37 |
| 35 namespace content { | 38 namespace content { |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| 38 | 41 |
| 39 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; | 42 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; |
| 43 const char kPageGetManifest[] = "Page.getManifest"; | |
| 44 | |
| 40 | 45 |
| 41 class WebKitClientMessageLoopImpl | 46 class WebKitClientMessageLoopImpl |
| 42 : public WebDevToolsAgentClient::WebKitClientMessageLoop { | 47 : public WebDevToolsAgentClient::WebKitClientMessageLoop { |
| 43 public: | 48 public: |
| 44 WebKitClientMessageLoopImpl() : message_loop_(base::MessageLoop::current()) {} | 49 WebKitClientMessageLoopImpl() : message_loop_(base::MessageLoop::current()) {} |
| 45 ~WebKitClientMessageLoopImpl() override { message_loop_ = NULL; } | 50 ~WebKitClientMessageLoopImpl() override { message_loop_ = NULL; } |
| 46 void run() override { | 51 void run() override { |
| 47 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop_); | 52 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop_); |
| 48 message_loop_->Run(); | 53 message_loop_->Run(); |
| 49 } | 54 } |
| 50 void quitNow() override { message_loop_->QuitNow(); } | 55 void quitNow() override { message_loop_->QuitNow(); } |
| 51 | 56 |
| 52 private: | 57 private: |
| 53 base::MessageLoop* message_loop_; | 58 base::MessageLoop* message_loop_; |
| 54 }; | 59 }; |
| 55 | 60 |
| 56 typedef std::map<int, DevToolsAgent*> IdToAgentMap; | 61 typedef std::map<int, DevToolsAgent*> IdToAgentMap; |
| 57 base::LazyInstance<IdToAgentMap>::Leaky | 62 base::LazyInstance<IdToAgentMap>::Leaky |
| 58 g_agent_for_routing_id = LAZY_INSTANCE_INITIALIZER; | 63 g_agent_for_routing_id = LAZY_INSTANCE_INITIALIZER; |
| 59 | 64 |
| 60 } // namespace | 65 } // namespace |
| 61 | 66 |
| 62 DevToolsAgent::DevToolsAgent(RenderFrameImpl* frame) | 67 DevToolsAgent::DevToolsAgent(RenderFrameImpl* frame) |
| 63 : RenderFrameObserver(frame), | 68 : RenderFrameObserver(frame), |
| 64 is_attached_(false), | 69 is_attached_(false), |
| 65 is_devtools_client_(false), | 70 is_devtools_client_(false), |
| 66 paused_in_mouse_move_(false), | 71 paused_in_mouse_move_(false), |
| 67 paused_(false), | 72 paused_(false), |
| 68 frame_(frame), | 73 frame_(frame), |
| 69 cpu_throttler_(new DevToolsCPUThrottler()) { | 74 cpu_throttler_(new DevToolsCPUThrottler()), |
| 75 weak_factory_(this) { | |
| 70 g_agent_for_routing_id.Get()[routing_id()] = this; | 76 g_agent_for_routing_id.Get()[routing_id()] = this; |
| 71 frame_->GetWebFrame()->setDevToolsAgentClient(this); | 77 frame_->GetWebFrame()->setDevToolsAgentClient(this); |
| 72 } | 78 } |
| 73 | 79 |
| 74 DevToolsAgent::~DevToolsAgent() { | 80 DevToolsAgent::~DevToolsAgent() { |
| 75 g_agent_for_routing_id.Get().erase(routing_id()); | 81 g_agent_for_routing_id.Get().erase(routing_id()); |
| 76 } | 82 } |
| 77 | 83 |
| 78 // Called on the Renderer thread. | 84 // Called on the Renderer thread. |
| 79 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { | 85 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 | 230 |
| 225 void DevToolsAgent::OnDetach() { | 231 void DevToolsAgent::OnDetach() { |
| 226 GetWebAgent()->detach(); | 232 GetWebAgent()->detach(); |
| 227 is_attached_ = false; | 233 is_attached_ = false; |
| 228 } | 234 } |
| 229 | 235 |
| 230 void DevToolsAgent::OnDispatchOnInspectorBackend(int session_id, | 236 void DevToolsAgent::OnDispatchOnInspectorBackend(int session_id, |
| 231 const std::string& method, | 237 const std::string& method, |
| 232 const std::string& message) { | 238 const std::string& message) { |
| 233 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); | 239 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); |
| 240 if (method == kPageGetManifest) { | |
| 241 ManifestManager* manager = frame_->manifest_manager(); | |
| 242 manager->GetManifest( | |
| 243 base::Bind(&DevToolsAgent::GotManifest, | |
| 244 weak_factory_.GetWeakPtr(), session_id, 0)); | |
| 245 return; | |
| 246 } | |
| 234 GetWebAgent()->dispatchOnInspectorBackend(session_id, | 247 GetWebAgent()->dispatchOnInspectorBackend(session_id, |
| 235 WebString::fromUTF8(method), | 248 WebString::fromUTF8(method), |
| 236 WebString::fromUTF8(message)); | 249 WebString::fromUTF8(message)); |
| 237 } | 250 } |
| 238 | 251 |
| 239 void DevToolsAgent::OnInspectElement(int x, int y) { | 252 void DevToolsAgent::OnInspectElement(int x, int y) { |
| 240 GetWebAgent()->inspectElementAt(WebPoint(x, y)); | 253 GetWebAgent()->inspectElementAt(WebPoint(x, y)); |
| 241 } | 254 } |
| 242 | 255 |
| 243 void DevToolsAgent::OnRequestNewWindowACK(bool success) { | 256 void DevToolsAgent::OnRequestNewWindowACK(bool success) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 260 } | 273 } |
| 261 | 274 |
| 262 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 275 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
| 263 return frame_->GetWebFrame()->devToolsAgent(); | 276 return frame_->GetWebFrame()->devToolsAgent(); |
| 264 } | 277 } |
| 265 | 278 |
| 266 bool DevToolsAgent::IsAttached() { | 279 bool DevToolsAgent::IsAttached() { |
| 267 return is_attached_; | 280 return is_attached_; |
| 268 } | 281 } |
| 269 | 282 |
| 283 void DevToolsAgent::GotManifest(int session_id, | |
| 284 int command_id, | |
| 285 const Manifest& manifest, | |
| 286 const ManifestDebugInfo& debug_info) { | |
| 287 if (!is_attached_) | |
| 288 return; | |
| 289 | |
| 290 std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | |
| 291 response->SetInteger("id", command_id); | |
| 292 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 293 result->SetString("data", debug_info.raw_data); | |
| 294 std::unique_ptr<base::ListValue> errors(new base::ListValue()); | |
| 295 | |
| 296 for (const auto& error :debug_info.errors) { | |
|
dgozman
2016/04/29 02:28:26
style: space after colon
| |
| 297 base::DictionaryValue* error_value = new base::DictionaryValue(); | |
| 298 errors->Append(error_value); | |
| 299 error_value->SetString("message", error.message); | |
| 300 error_value->SetInteger("line", error.line); | |
| 301 error_value->SetInteger("column", error.column); | |
| 302 } | |
| 303 result->Set("errors", errors.release()); | |
| 304 response->Set("result", result.release()); | |
| 305 | |
| 306 std::string json_message; | |
| 307 base::JSONWriter::Write(*response, &json_message); | |
| 308 SendChunkedProtocolMessage(this, routing_id(), session_id, command_id, | |
| 309 json_message, std::string()); | |
| 310 } | |
| 311 | |
| 270 } // namespace content | 312 } // namespace content |
| OLD | NEW |