OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/renderer/dev_tools_agent.h" | 5 #include "chrome/renderer/dev_tools_agent.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
9 #include "chrome/renderer/dev_tools_messages.h" | 9 #include "chrome/renderer/dev_tools_messages.h" |
10 // TODO(yurys): remove this macros once plugins available on other platforms | 10 // TODO(yurys): remove this macros once plugins available on other platforms |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #include "chrome/renderer/plugin_channel_host.h" | 12 #include "chrome/renderer/plugin_channel_host.h" |
13 #endif // OS_WIN | 13 #endif // OS_WIN |
14 #include "chrome/renderer/render_process.h" | 14 #include "chrome/renderer/render_process.h" |
15 #include "chrome/renderer/render_view.h" | 15 #include "chrome/renderer/render_view.h" |
16 | 16 |
17 DevToolsAgent::DevToolsAgent(RenderView* view, MessageLoop* view_loop) | 17 DevToolsAgent::DevToolsAgent(RenderView* view, MessageLoop* view_loop) |
18 : debugger_(NULL), | 18 : debugger_(NULL), |
19 routing_id_(view->routing_id()), | |
19 view_(view), | 20 view_(view), |
20 view_loop_(view_loop), | 21 view_loop_(view_loop), |
21 channel_(NULL), | 22 channel_(NULL), |
22 io_loop_(NULL) { | 23 io_loop_(NULL) { |
23 } | 24 } |
24 | 25 |
25 DevToolsAgent::~DevToolsAgent() { | 26 DevToolsAgent::~DevToolsAgent() { |
26 } | 27 } |
27 | 28 |
29 // Called on render thread. | |
Dean McNamee
2009/03/05 11:43:29
on the render thread
| |
30 void DevToolsAgent::RenderViewDestroyed() { | |
31 DCHECK(MessageLoop::current() == view_loop_); | |
32 view_ = NULL; | |
33 } | |
34 | |
28 void DevToolsAgent::Send(const IPC::Message& tools_client_message) { | 35 void DevToolsAgent::Send(const IPC::Message& tools_client_message) { |
29 // It's possible that this will get cleared out from under us. | 36 // It's possible that this will get cleared out from under us. |
30 MessageLoop* io_loop = io_loop_; | 37 MessageLoop* io_loop = io_loop_; |
31 if (!io_loop) | 38 if (!io_loop) |
32 return; | 39 return; |
33 | 40 |
34 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( | 41 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( |
35 view_->routing_id(), | 42 routing_id_, |
36 tools_client_message); | 43 tools_client_message); |
37 io_loop->PostTask(FROM_HERE, NewRunnableMethod( | 44 io_loop->PostTask(FROM_HERE, NewRunnableMethod( |
38 this, &DevToolsAgent::SendFromIOThread, m)); | 45 this, &DevToolsAgent::SendFromIOThread, m)); |
39 } | 46 } |
40 | 47 |
41 void DevToolsAgent::SendFromIOThread(IPC::Message* message) { | 48 void DevToolsAgent::SendFromIOThread(IPC::Message* message) { |
42 if (channel_) { | 49 if (channel_) { |
43 channel_->Send(message); | 50 channel_->Send(message); |
44 } else { | 51 } else { |
45 delete message; | 52 delete message; |
46 } | 53 } |
47 } | 54 } |
48 | 55 |
49 // Called on IO thread. | 56 // Called on IO thread. |
50 void DevToolsAgent::OnFilterAdded(IPC::Channel* channel) { | 57 void DevToolsAgent::OnFilterAdded(IPC::Channel* channel) { |
51 io_loop_ = MessageLoop::current(); | 58 io_loop_ = MessageLoop::current(); |
52 channel_ = channel; | 59 channel_ = channel; |
53 } | 60 } |
54 | 61 |
55 // Called on IO thread. | 62 // Called on IO thread. |
56 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { | 63 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
57 DCHECK(MessageLoop::current() == io_loop_); | 64 DCHECK(MessageLoop::current() == io_loop_); |
58 | 65 |
59 if (message.routing_id() != view_->routing_id()) | 66 if (message.routing_id() != routing_id_) |
60 return false; | 67 return false; |
61 | 68 |
62 bool handled = true; | 69 bool handled = true; |
63 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) | 70 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) |
64 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugAttach, OnDebugAttach) | 71 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugAttach, OnDebugAttach) |
65 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugDetach, OnDebugDetach) | 72 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugDetach, OnDebugDetach) |
66 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugBreak, OnDebugBreak) | 73 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugBreak, OnDebugBreak) |
67 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugCommand, OnDebugCommand) | 74 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebugCommand, OnDebugCommand) |
68 IPC_MESSAGE_UNHANDLED(handled = false) | 75 IPC_MESSAGE_UNHANDLED(handled = false) |
69 IPC_END_MESSAGE_MAP() | 76 IPC_END_MESSAGE_MAP() |
70 return handled; | 77 return handled; |
71 } | 78 } |
72 | 79 |
80 // Called on IO thread. | |
Dean McNamee
2009/03/05 11:43:29
on the IO thread.
| |
73 void DevToolsAgent::OnFilterRemoved() { | 81 void DevToolsAgent::OnFilterRemoved() { |
74 io_loop_ = NULL; | 82 io_loop_ = NULL; |
75 channel_ = NULL; | 83 channel_ = NULL; |
76 } | 84 } |
77 | 85 |
78 void DevToolsAgent::DebuggerOutput(const std::wstring& out) { | 86 void DevToolsAgent::DebuggerOutput(const std::wstring& out) { |
79 Send(DevToolsClientMsg_DebuggerOutput(out)); | 87 Send(DevToolsClientMsg_DebuggerOutput(out)); |
80 } | 88 } |
81 | 89 |
82 void DevToolsAgent::EvaluateScript(const std::wstring& script) { | 90 void DevToolsAgent::EvaluateScript(const std::wstring& script) { |
83 DCHECK(MessageLoop::current() == view_loop_); | 91 DCHECK(MessageLoop::current() == view_loop_); |
84 view_->EvaluateScript(L"", script); | 92 // view_ may have been cleared after this method execution was scheduled. |
Dean McNamee
2009/03/05 11:43:29
|view_|
| |
93 if (view_) | |
94 view_->EvaluateScript(L"", script); | |
85 } | 95 } |
86 | 96 |
87 void DevToolsAgent::OnDebugAttach() { | 97 void DevToolsAgent::OnDebugAttach() { |
88 DCHECK(MessageLoop::current() == io_loop_); | 98 DCHECK(MessageLoop::current() == io_loop_); |
89 if (!debugger_) { | 99 if (!debugger_) { |
90 debugger_ = new DebuggerBridge(this); | 100 debugger_ = new DebuggerBridge(this); |
91 } | 101 } |
92 | 102 |
93 debugger_->Attach(); | 103 debugger_->Attach(); |
94 | 104 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 if (!debugger_) { | 144 if (!debugger_) { |
135 NOTREACHED(); | 145 NOTREACHED(); |
136 std::wstring msg = | 146 std::wstring msg = |
137 StringPrintf(L"before attach, ignored command (%S)", cmd.c_str()); | 147 StringPrintf(L"before attach, ignored command (%S)", cmd.c_str()); |
138 DebuggerOutput(msg); | 148 DebuggerOutput(msg); |
139 } else { | 149 } else { |
140 debugger_->Command(cmd); | 150 debugger_->Command(cmd); |
141 } | 151 } |
142 } | 152 } |
143 | 153 |
OLD | NEW |