Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/renderer/devtools/devtools_agent.cc

Issue 1932623003: DevTools: Introduce Page.getManifest remote debugging protocol method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 int call_id, 237 int call_id,
232 const std::string& method, 238 const std::string& method,
233 const std::string& message) { 239 const std::string& message) {
234 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend"); 240 TRACE_EVENT0("devtools", "DevToolsAgent::OnDispatchOnInspectorBackend");
241 if (method == kPageGetManifest) {
242 ManifestManager* manager = frame_->manifest_manager();
243 manager->GetManifest(
244 base::Bind(&DevToolsAgent::GotManifest,
245 weak_factory_.GetWeakPtr(), session_id, call_id));
246 return;
247 }
235 GetWebAgent()->dispatchOnInspectorBackend(session_id, 248 GetWebAgent()->dispatchOnInspectorBackend(session_id,
236 call_id, 249 call_id,
237 WebString::fromUTF8(method), 250 WebString::fromUTF8(method),
238 WebString::fromUTF8(message)); 251 WebString::fromUTF8(message));
239 } 252 }
240 253
241 void DevToolsAgent::OnInspectElement(int x, int y) { 254 void DevToolsAgent::OnInspectElement(int x, int y) {
242 GetWebAgent()->inspectElementAt(WebPoint(x, y)); 255 GetWebAgent()->inspectElementAt(WebPoint(x, y));
243 } 256 }
244 257
(...skipping 17 matching lines...) Expand all
262 } 275 }
263 276
264 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { 277 WebDevToolsAgent* DevToolsAgent::GetWebAgent() {
265 return frame_->GetWebFrame()->devToolsAgent(); 278 return frame_->GetWebFrame()->devToolsAgent();
266 } 279 }
267 280
268 bool DevToolsAgent::IsAttached() { 281 bool DevToolsAgent::IsAttached() {
269 return is_attached_; 282 return is_attached_;
270 } 283 }
271 284
285 void DevToolsAgent::GotManifest(int session_id,
286 int call_id,
287 const Manifest& manifest,
288 const ManifestDebugInfo& debug_info) {
289 if (!is_attached_)
290 return;
291
292 std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue());
293 response->SetInteger("id", call_id);
294 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
295 result->SetString("data", debug_info.raw_data);
296 std::unique_ptr<base::ListValue> errors(new base::ListValue());
297
298 for (const auto& error : debug_info.errors) {
299 base::DictionaryValue* error_value = new base::DictionaryValue();
300 errors->Append(error_value);
301 error_value->SetString("message", error.message);
302 error_value->SetInteger("line", error.line);
303 error_value->SetInteger("column", error.column);
304 }
305 result->Set("errors", errors.release());
306 response->Set("result", result.release());
307
308 std::string json_message;
309 base::JSONWriter::Write(*response, &json_message);
310 SendChunkedProtocolMessage(this, routing_id(), session_id, call_id,
311 json_message, std::string());
312 }
313
272 } // namespace content 314 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698