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 // DevToolsAgent belongs to the inspectable renderer and provides Glue's | 5 // DevToolsAgent belongs to the inspectable renderer and provides Glue's |
6 // agents with the communication capabilities. All messages from/to Glue's | 6 // agents with the communication capabilities. All messages from/to Glue's |
7 // agents infrastructure are flowing through this comminucation agent. | 7 // agents infrastructure are flowing through this comminucation agent. |
8 // | 8 // |
9 // DevToolsAgent is registered as an IPC filter in order to be able to | 9 // DevToolsAgent is registered as an IPC filter in order to be able to |
10 // dispatch messages while on the IO thread. The reason for that is that while | 10 // dispatch messages while on the IO thread. The reason for that is that while |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/renderer/render_process.h" | 25 #include "chrome/renderer/render_process.h" |
26 #include "chrome/renderer/render_view.h" | 26 #include "chrome/renderer/render_view.h" |
27 #include "webkit/glue/webdevtoolsagent.h" | 27 #include "webkit/glue/webdevtoolsagent.h" |
28 | 28 |
29 DevToolsAgent::DevToolsAgent(int routing_id, | 29 DevToolsAgent::DevToolsAgent(int routing_id, |
30 RenderView* view, | 30 RenderView* view, |
31 MessageLoop* view_loop) | 31 MessageLoop* view_loop) |
32 : routing_id_(routing_id), | 32 : routing_id_(routing_id), |
33 view_(view), | 33 view_(view), |
34 view_loop_(view_loop), | 34 view_loop_(view_loop), |
35 channel_(NULL), | |
36 io_loop_(NULL) { | 35 io_loop_(NULL) { |
37 } | 36 } |
38 | 37 |
39 DevToolsAgent::~DevToolsAgent() { | 38 DevToolsAgent::~DevToolsAgent() { |
40 } | 39 } |
41 | 40 |
42 // Called on render thread. | 41 // Called on render thread. |
43 void DevToolsAgent::RenderViewDestroyed() { | 42 void DevToolsAgent::RenderViewDestroyed() { |
44 DCHECK(MessageLoop::current() == view_loop_); | 43 DCHECK(MessageLoop::current() == view_loop_); |
45 view_ = NULL; | 44 view_ = NULL; |
46 } | 45 } |
47 | 46 |
48 void DevToolsAgent::Send(const IPC::Message& tools_client_message) { | 47 void DevToolsAgent::Send(const IPC::Message& tools_client_message) { |
49 // It's possible that this will get cleared out from under us. | 48 DCHECK(MessageLoop::current() == view_loop_); |
50 MessageLoop* io_loop = io_loop_; | 49 if (!view_) { |
51 if (!io_loop) | |
52 return; | 50 return; |
| 51 } |
53 | 52 |
54 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( | 53 IPC::Message* m = new ViewHostMsg_ForwardToDevToolsClient( |
55 routing_id_, | 54 routing_id_, |
56 tools_client_message); | 55 tools_client_message); |
57 io_loop->PostTask(FROM_HERE, NewRunnableMethod( | 56 view_->Send(m); |
58 this, &DevToolsAgent::SendFromIOThread, m)); | |
59 } | |
60 | |
61 void DevToolsAgent::SendFromIOThread(IPC::Message* message) { | |
62 if (channel_) { | |
63 channel_->Send(message); | |
64 } else { | |
65 delete message; | |
66 } | |
67 } | 57 } |
68 | 58 |
69 // Called on the IO thread. | 59 // Called on the IO thread. |
70 void DevToolsAgent::OnFilterAdded(IPC::Channel* channel) { | 60 void DevToolsAgent::OnFilterAdded(IPC::Channel* channel) { |
71 io_loop_ = MessageLoop::current(); | 61 io_loop_ = MessageLoop::current(); |
72 channel_ = channel; | |
73 } | 62 } |
74 | 63 |
75 // Called on the IO thread. | 64 // Called on the IO thread. |
76 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { | 65 bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { |
77 DCHECK(MessageLoop::current() == io_loop_); | 66 DCHECK(MessageLoop::current() == io_loop_); |
78 | 67 |
79 if (message.routing_id() != routing_id_) | 68 if (message.routing_id() != routing_id_) |
80 return false; | 69 return false; |
81 | 70 |
| 71 // TODO(yurys): only DebuggerCommand message is handled on the IO thread |
| 72 // all other messages could be handled in RenderView::OnMessageReceived. With |
| 73 // that approach we wouldn't have to call view_loop_->PostTask for each of the |
| 74 // messages. |
82 bool handled = true; | 75 bool handled = true; |
83 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) | 76 IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) |
84 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) | 77 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) |
85 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) | 78 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) |
86 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_RpcMessage, OnRpcMessage) | 79 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_RpcMessage, OnRpcMessage) |
87 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerCommand, | 80 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerCommand, |
88 OnDebuggerCommand) | 81 OnDebuggerCommand) |
89 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) | 82 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) |
90 IPC_MESSAGE_UNHANDLED(handled = false) | 83 IPC_MESSAGE_UNHANDLED(handled = false) |
91 IPC_END_MESSAGE_MAP() | 84 IPC_END_MESSAGE_MAP() |
92 return handled; | 85 return handled; |
93 } | 86 } |
94 | 87 |
95 // Called on the IO thread. | 88 // Called on the IO thread. |
96 void DevToolsAgent::OnFilterRemoved() { | 89 void DevToolsAgent::OnFilterRemoved() { |
97 io_loop_ = NULL; | 90 io_loop_ = NULL; |
98 channel_ = NULL; | |
99 } | 91 } |
100 | 92 |
101 void DevToolsAgent::EvaluateScript(const std::wstring& script) { | 93 void DevToolsAgent::EvaluateScript(const std::wstring& script) { |
102 DCHECK(MessageLoop::current() == view_loop_); | 94 DCHECK(MessageLoop::current() == view_loop_); |
103 // view_ may have been cleared after this method execution was scheduled. | 95 // view_ may have been cleared after this method execution was scheduled. |
104 if (view_) | 96 if (view_) |
105 view_->EvaluateScript(L"", script); | 97 view_->EvaluateScript(L"", script); |
106 } | 98 } |
107 | 99 |
108 void DevToolsAgent::OnAttach() { | 100 void DevToolsAgent::OnAttach() { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 155 } |
164 | 156 |
165 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { | 157 WebDevToolsAgent* DevToolsAgent::GetWebAgent() { |
166 if (!view_) | 158 if (!view_) |
167 return NULL; | 159 return NULL; |
168 WebView* web_view = view_->webview(); | 160 WebView* web_view = view_->webview(); |
169 if (!web_view) | 161 if (!web_view) |
170 return NULL; | 162 return NULL; |
171 return web_view->GetWebDevToolsAgent(); | 163 return web_view->GetWebDevToolsAgent(); |
172 } | 164 } |
OLD | NEW |