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

Side by Side Diff: chrome/renderer/dev_tools_agent.cc

Issue 21543: Add developer tools message handling to renderer (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/dev_tools_agent.h ('k') | chrome/renderer/dev_tools_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/dev_tools_agent.h"
6
7 #include "base/message_loop.h"
8 #include "chrome/common/render_messages.h"
9 #include "chrome/renderer/dev_tools_messages.h"
10 // TODO(yurys): remove this macros once plugins available on other platforms
11 #if defined(OS_WIN)
12 #include "chrome/renderer/plugin_channel_host.h"
13 #endif // OS_WIN
14 #include "chrome/renderer/render_process.h"
15 #include "chrome/renderer/render_view.h"
16
17 DevToolsAgent::DevToolsAgent(RenderView* view, MessageLoop* view_loop)
18 : debugger_(NULL),
19 view_(view),
20 view_loop_(view_loop),
21 channel_(NULL),
22 io_loop_(NULL) {
23 }
24
25 DevToolsAgent::~DevToolsAgent() {
26 }
27
28 void DevToolsAgent::Send(const IPC::Message& tools_client_message) {
29 // It's possible that this will get cleared out from under us.
30 MessageLoop* io_loop = io_loop_;
31 if (!io_loop)
32 return;
33
34 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient(
35 view_->routing_id(),
36 tools_client_message);
37 io_loop->PostTask(FROM_HERE, NewRunnableMethod(
38 this, &DevToolsAgent::SendFromIOThread, m));
39 }
40
41 void DevToolsAgent::SendFromIOThread(IPC::Message* message) {
42 if (channel_) {
43 channel_->Send(message);
44 } else {
45 delete message;
46 }
47 }
48
49 // Called on IO thread.
50 void DevToolsAgent::OnFilterAdded(IPC::Channel* channel) {
51 io_loop_ = MessageLoop::current();
52 channel_ = channel;
53 }
54
55 // Called on IO thread.
56 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) {
57 DCHECK(MessageLoop::current() == io_loop_);
58
59 if (message.routing_id() != view_->routing_id())
60 return false;
61
62 bool handled = true;
63 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message)
64 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugAttach, OnDebugAttach)
65 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugDetach, OnDebugDetach)
66 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugBreak, OnDebugBreak)
67 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugCommand, OnDebugCommand)
68 IPC_MESSAGE_UNHANDLED(handled = false)
69 IPC_END_MESSAGE_MAP()
70 return handled;
71 }
72
73 void DevToolsAgent::OnFilterRemoved() {
74 io_loop_ = NULL;
75 channel_ = NULL;
76 }
77
78 void DevToolsAgent::DebuggerOutput(const std::wstring& out) {
79 Send(DevToolsClientMsg_DebuggerOutput(out));
80 }
81
82 void DevToolsAgent::EvaluateScript(const std::wstring& script) {
83 DCHECK(MessageLoop::current() == view_loop_);
84 view_->EvaluateScript(L"", script);
85 }
86
87 void DevToolsAgent::OnDebugAttach() {
88 DCHECK(MessageLoop::current() == io_loop_);
89 if (!debugger_) {
90 debugger_ = new DebuggerBridge(this);
91 }
92
93 debugger_->Attach();
94
95 Send(DevToolsClientMsg_DidDebugAttach());
96
97 // TODO(yurys): remove this macros once plugins available on other platforms
98 #if defined(OS_WIN)
99 // Tell the plugin host to stop accepting messages in order to avoid
100 // hangs while the renderer is paused.
101 // TODO(yurys): It might be an improvement to add more plumbing to do this
102 // when the renderer is actually paused vs. just the debugger being attached.
103 // http://code.google.com/p/chromium/issues/detail?id=7556
104 PluginChannelHost::SetListening(false);
105 #endif // OS_WIN
106 }
107
108 void DevToolsAgent::OnDebugDetach() {
109 DCHECK(MessageLoop::current() == io_loop_);
110 if (debugger_)
111 debugger_->Detach();
112 // TODO(yurys): remove this macros once plugins available on other platforms
113 #if defined(OS_WIN)
114 PluginChannelHost::SetListening(true);
115 #endif // OS_WIN
116 }
117
118 void DevToolsAgent::OnDebugBreak(bool force) {
119 DCHECK(MessageLoop::current() == io_loop_);
120 // Set the debug break flag in the V8 engine.
121 debugger_->Break(force);
122
123 // If a forced break has been requested make sure that it will occour by
124 // running some JavaScript in the renderer.
125 if (force && view_loop_) {
126 view_loop_->PostTask(FROM_HERE, NewRunnableMethod(
127 this, &DevToolsAgent::EvaluateScript,
128 std::wstring(L"javascript:void(0)")));
129 }
130 }
131
132 void DevToolsAgent::OnDebugCommand(const std::wstring& cmd) {
133 DCHECK(MessageLoop::current() == io_loop_);
134 if (!debugger_) {
135 NOTREACHED();
136 std::wstring msg =
137 StringPrintf(L"before attach, ignored command (%S)", cmd.c_str());
138 DebuggerOutput(msg);
139 } else {
140 debugger_->Command(cmd);
141 }
142 }
143
OLDNEW
« no previous file with comments | « chrome/renderer/dev_tools_agent.h ('k') | chrome/renderer/dev_tools_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698