diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 11:33:05 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 11:33:05 +0000 |
commit | b4b967edacf8e291f78df2c8238e3446922a179f (patch) | |
tree | 621b8c0eedf48e7cb346f31277ce3b34a30cb99a /chrome/renderer | |
parent | 57b4ef12d0f726a79a3fa023cd6bb32b51925be8 (diff) | |
download | chromium_src-b4b967edacf8e291f78df2c8238e3446922a179f.zip chromium_src-b4b967edacf8e291f78df2c8238e3446922a179f.tar.gz chromium_src-b4b967edacf8e291f78df2c8238e3446922a179f.tar.bz2 |
DevTools: Run nested message loop instead of whitelisting the messages.
Review URL: http://codereview.chromium.org/90007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14183 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/devtools_agent.cc | 12 | ||||
-rw-r--r-- | chrome/renderer/devtools_agent.h | 2 | ||||
-rw-r--r-- | chrome/renderer/devtools_agent_filter.cc | 112 | ||||
-rw-r--r-- | chrome/renderer/devtools_agent_filter.h | 10 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/render_widget.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/render_widget.h | 3 |
7 files changed, 42 insertions, 103 deletions
diff --git a/chrome/renderer/devtools_agent.cc b/chrome/renderer/devtools_agent.cc index 918bb73..88528b2 100644 --- a/chrome/renderer/devtools_agent.cc +++ b/chrome/renderer/devtools_agent.cc @@ -26,6 +26,7 @@ DevToolsAgent::~DevToolsAgent() { bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(DevToolsAgent, message) + IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach) IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach) IPC_MESSAGE_HANDLER(DevToolsAgentMsg_RpcMessage, OnRpcMessage) IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement) @@ -45,6 +46,10 @@ int DevToolsAgent::GetHostId() { return routing_id_; } +void DevToolsAgent::ForceRepaint() { + view_->GenerateFullRepaint(); +} + // static DevToolsAgent* DevToolsAgent::FromHostId(int host_id) { std::map<int, DevToolsAgent*>::iterator it = @@ -55,6 +60,13 @@ DevToolsAgent* DevToolsAgent::FromHostId(int host_id) { return NULL; } +void DevToolsAgent::OnAttach() { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) { + web_agent->Attach(); + } +} + void DevToolsAgent::OnDetach() { WebDevToolsAgent* web_agent = GetWebAgent(); if (web_agent) { diff --git a/chrome/renderer/devtools_agent.h b/chrome/renderer/devtools_agent.h index 9f813a3..2c2702c 100644 --- a/chrome/renderer/devtools_agent.h +++ b/chrome/renderer/devtools_agent.h @@ -32,6 +32,7 @@ class DevToolsAgent : public WebDevToolsAgentDelegate { // WebDevToolsAgentDelegate implementation virtual void SendMessageToClient(const std::string& raw_msg); virtual int GetHostId(); + virtual void ForceRepaint(); // Returns agent instance for its host id. static DevToolsAgent* FromHostId(int host_id); @@ -43,6 +44,7 @@ class DevToolsAgent : public WebDevToolsAgentDelegate { private: friend class DevToolsAgentFilter; + void OnAttach(); void OnDetach(); void OnRpcMessage(const std::string& raw_msg); void OnInspectElement(int x, int y); diff --git a/chrome/renderer/devtools_agent_filter.cc b/chrome/renderer/devtools_agent_filter.cc index ec7dd1c7..13b76f4 100644 --- a/chrome/renderer/devtools_agent_filter.cc +++ b/chrome/renderer/devtools_agent_filter.cc @@ -5,6 +5,7 @@ #include "chrome/renderer/devtools_agent_filter.h" #include "base/command_line.h" +#include "base/message_loop.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/devtools_messages.h" #include "chrome/renderer/devtools_agent.h" @@ -12,37 +13,24 @@ #include "chrome/renderer/render_view.h" #include "webkit/glue/webdevtoolsagent.h" -namespace { - -class DebuggerMessage : public WebDevToolsAgent::Message { - public: - DebuggerMessage(int routing_id, const IPC::Message& message) - : routing_id_(routing_id), - message_(message) { - } - - virtual void Dispatch() { - DevToolsAgent* agent = DevToolsAgent::FromHostId(routing_id_); - if (agent) { - agent->OnMessageReceived(message_); - } - } - - private: - int routing_id_; - IPC::Message message_; - DISALLOW_COPY_AND_ASSIGN(DebuggerMessage); -}; - -} // namespace - -std::set<int> DevToolsAgentFilter::attached_routing_ids_; +// static +void DevToolsAgentFilter::DispatchMessageLoop() { + MessageLoop* current = MessageLoop::current(); + bool old_state = current->NestableTasksAllowed(); + current->SetNestableTasksAllowed(true); + current->RunAllPending(); + current->SetNestableTasksAllowed(old_state); +} DevToolsAgentFilter::DevToolsAgentFilter() : current_routing_id_(0) { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); devtools_enabled_ = command_line.HasSwitch( switches::kEnableOutOfProcessDevTools); + if (devtools_enabled_) { + WebDevToolsAgent::SetMessageLoopDispatchHandler( + &DevToolsAgentFilter::DispatchMessageLoop); + } } DevToolsAgentFilter::~DevToolsAgentFilter() { @@ -52,84 +40,18 @@ bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { if (!devtools_enabled_) { return false; } - if (message.type() < DevToolsAgentStart || - message.type() >= DevToolsAgentEnd) { - return false; - } - - int routing_id = message.routing_id(); - - MessageLoop* view_loop = RenderThread::current()->message_loop(); - if (attached_routing_ids_.find(routing_id) == attached_routing_ids_.end()) { - // Agent has not been scheduled for attachment yet. - // Schedule attach command, no matter which one is actually being - // dispatched. - view_loop->PostTask(FROM_HERE, NewRunnableMethod( - this, - &DevToolsAgentFilter::Attach, - message.routing_id())); - attached_routing_ids_.insert(routing_id); - -#if defined(OS_WIN) - // Disable plugin message routing. - PluginChannelHost::SetListening(false); -#endif - } - - // If this is attach request - we are done. - if (message.type() == DevToolsAgentMsg_Attach::ID) { - return true; - } - if (message.type() == DevToolsAgentMsg_Detach::ID) { - // We are about to schedule detach. - attached_routing_ids_.erase(routing_id); - if (attached_routing_ids_.size() == 0) { -#if defined(OS_WIN) - // All the agents are scheduled for detach -> resume dispatching - // of plugin messages. - PluginChannelHost::SetListening(true); -#endif - } - } - - if (message.type() != DevToolsAgentMsg_DebuggerCommand::ID) { - // Dispatch everything except for command through the debugger interrupt. - DebuggerMessage* m = new DebuggerMessage(routing_id, message); - WebDevToolsAgent::ScheduleMessageDispatch(m); - view_loop->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &DevToolsAgentFilter::EvalNoop, - routing_id)); - return true; - } else { + if (message.type() == DevToolsAgentMsg_DebuggerCommand::ID) { // Dispatch command directly from IO. bool handled = true; - current_routing_id_ = routing_id; + current_routing_id_ = message.routing_id(); IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message) IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DebuggerCommand, OnDebuggerCommand) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; - } -} - -void DevToolsAgentFilter::EvalNoop(int routing_id) { - DevToolsAgent* agent = DevToolsAgent::FromHostId(routing_id); - if (agent) { - agent->render_view()->EvaluateScript(L"", L"javascript:void(0)"); - } -} - -void DevToolsAgentFilter::Attach(int routing_id) { - DevToolsAgent* agent = DevToolsAgent::FromHostId(routing_id); - if (agent) { - WebDevToolsAgent* web_agent = agent->GetWebAgent(); - if (web_agent) { - web_agent->Attach(); - } + } else { + return false; } } diff --git a/chrome/renderer/devtools_agent_filter.h b/chrome/renderer/devtools_agent_filter.h index f97e4a3..662b863 100644 --- a/chrome/renderer/devtools_agent_filter.h +++ b/chrome/renderer/devtools_agent_filter.h @@ -28,18 +28,12 @@ class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { // IPC::ChannelProxy::MessageFilter override. Called on IO thread. virtual bool OnMessageReceived(const IPC::Message& message); + static void DispatchMessageLoop(); + // OnDebuggerCommand will be executed in the IO thread so that we can // handle debug messages even when v8 is stopped. void OnDebuggerCommand(const std::string& command); - // Evaluates noop to kick the debugger. - void EvalNoop(int routing_id); - - // Attaches agent. - void Attach(int routing_id); - - static std::set<int> attached_routing_ids_; - int current_routing_id_; bool devtools_enabled_; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 771fa8a..56528e4 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -360,6 +360,8 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { // If this is developer tools renderer intercept tools messages first. if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) return; + if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) + return; IPC_BEGIN_MESSAGE_MAP(RenderView, message) IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index 7f698cf..4cd54c1 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -595,6 +595,10 @@ void RenderWidget::CloseWidgetSoon(WebWidget* webwidget) { Send(new ViewHostMsg_Close(routing_id_)); } +void RenderWidget::GenerateFullRepaint() { + DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height())); +} + void RenderWidget::Close() { if (webwidget_) { webwidget_->Close(); diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h index 9dbfcbb..668b4fd 100644 --- a/chrome/renderer/render_widget.h +++ b/chrome/renderer/render_widget.h @@ -90,6 +90,9 @@ class RenderWidget : public IPC::Channel::Listener, virtual bool IsHidden(WebWidget* webwidget) { return is_hidden_; } virtual WebKit::WebScreenInfo GetScreenInfo(WebWidget* webwidget); + // Invalidates entire widget rect to generate a full repaint. + void GenerateFullRepaint(); + // Close the underlying WebWidget. void Close(); |