Commit cf9039cd authored by dgozman's avatar dgozman Committed by Commit bot

[DevTools] Unpause renderer when paused RenderFrame is closed.

BUG=469421

Review URL: https://codereview.chromium.org/1047653003

Cr-Commit-Position: refs/heads/master@{#323902}
parent 5f549c65
...@@ -45,6 +45,9 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener, ...@@ -45,6 +45,9 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener,
virtual void WasHidden() {} virtual void WasHidden() {}
virtual void WasShown() {} virtual void WasShown() {}
// Called when associated widget is about to close.
virtual void WidgetWillClose() {}
// These match the Blink API notifications // These match the Blink API notifications
virtual void DidCommitProvisionalLoad(bool is_new_navigation, virtual void DidCommitProvisionalLoad(bool is_new_navigation,
bool is_same_page_navigation) {} bool is_same_page_navigation) {}
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "content/common/devtools_messages.h" #include "content/common/devtools_messages.h"
#include "content/common/frame_messages.h" #include "content/common/frame_messages.h"
#include "content/common/view_messages.h"
#include "content/renderer/devtools/devtools_client.h" #include "content/renderer/devtools/devtools_client.h"
#include "content/renderer/render_frame_impl.h" #include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_widget.h" #include "content/renderer/render_widget.h"
...@@ -70,6 +69,7 @@ DevToolsAgent::DevToolsAgent(RenderFrameImpl* frame) ...@@ -70,6 +69,7 @@ DevToolsAgent::DevToolsAgent(RenderFrameImpl* frame)
is_attached_(false), is_attached_(false),
is_devtools_client_(false), is_devtools_client_(false),
paused_in_mouse_move_(false), paused_in_mouse_move_(false),
paused_(false),
frame_(frame) { frame_(frame) {
g_agent_for_routing_id.Get()[routing_id()] = this; g_agent_for_routing_id.Get()[routing_id()] = this;
frame_->GetWebFrame()->setDevToolsAgentClient(this); frame_->GetWebFrame()->setDevToolsAgentClient(this);
...@@ -95,13 +95,16 @@ bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) { ...@@ -95,13 +95,16 @@ bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
if (message.type() == FrameMsg_Navigate::ID || if (message.type() == FrameMsg_Navigate::ID)
message.type() == ViewMsg_Close::ID)
ContinueProgram(); // Don't want to swallow the message. ContinueProgram(); // Don't want to swallow the message.
return handled; return handled;
} }
void DevToolsAgent::WidgetWillClose() {
ContinueProgram();
}
void DevToolsAgent::sendProtocolMessage( void DevToolsAgent::sendProtocolMessage(
int call_id, int call_id,
const blink::WebString& message, const blink::WebString& message,
...@@ -116,11 +119,13 @@ blink::WebDevToolsAgentClient::WebKitClientMessageLoop* ...@@ -116,11 +119,13 @@ blink::WebDevToolsAgentClient::WebKitClientMessageLoop*
} }
void DevToolsAgent::willEnterDebugLoop() { void DevToolsAgent::willEnterDebugLoop() {
paused_ = true;
if (RenderWidget* widget = frame_->GetRenderWidget()) if (RenderWidget* widget = frame_->GetRenderWidget())
paused_in_mouse_move_ = widget->SendAckForMouseMoveFromDebugger(); paused_in_mouse_move_ = widget->SendAckForMouseMoveFromDebugger();
} }
void DevToolsAgent::didExitDebugLoop() { void DevToolsAgent::didExitDebugLoop() {
paused_ = false;
if (!paused_in_mouse_move_) if (!paused_in_mouse_move_)
return; return;
if (RenderWidget* widget = frame_->GetRenderWidget()) { if (RenderWidget* widget = frame_->GetRenderWidget()) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string> #include <string>
#include "content/common/content_export.h"
#include "content/public/common/console_message_level.h" #include "content/public/common/console_message_level.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "third_party/WebKit/public/web/WebDevToolsAgentClient.h" #include "third_party/WebKit/public/web/WebDevToolsAgentClient.h"
...@@ -22,8 +23,9 @@ class RenderFrameImpl; ...@@ -22,8 +23,9 @@ class RenderFrameImpl;
// DevToolsAgent belongs to the inspectable RenderFrameImpl and communicates // DevToolsAgent belongs to the inspectable RenderFrameImpl and communicates
// with WebDevToolsAgent. There is a corresponding DevToolsAgentHost // with WebDevToolsAgent. There is a corresponding DevToolsAgentHost
// on the browser side. // on the browser side.
class DevToolsAgent : public RenderFrameObserver, class CONTENT_EXPORT DevToolsAgent
public blink::WebDevToolsAgentClient { : public RenderFrameObserver,
NON_EXPORTED_BASE(public blink::WebDevToolsAgentClient) {
public: public:
explicit DevToolsAgent(RenderFrameImpl* frame); explicit DevToolsAgent(RenderFrameImpl* frame);
~DevToolsAgent() override; ~DevToolsAgent() override;
...@@ -43,8 +45,11 @@ class DevToolsAgent : public RenderFrameObserver, ...@@ -43,8 +45,11 @@ class DevToolsAgent : public RenderFrameObserver,
bool IsAttached(); bool IsAttached();
private: private:
friend class DevToolsAgentTest;
// RenderFrameObserver implementation. // RenderFrameObserver implementation.
bool OnMessageReceived(const IPC::Message& message) override; bool OnMessageReceived(const IPC::Message& message) override;
void WidgetWillClose() override;
// WebDevToolsAgentClient implementation. // WebDevToolsAgentClient implementation.
void sendProtocolMessage(int call_id, void sendProtocolMessage(int call_id,
...@@ -72,6 +77,7 @@ class DevToolsAgent : public RenderFrameObserver, ...@@ -72,6 +77,7 @@ class DevToolsAgent : public RenderFrameObserver,
bool is_attached_; bool is_attached_;
bool is_devtools_client_; bool is_devtools_client_;
bool paused_in_mouse_move_; bool paused_in_mouse_move_;
bool paused_;
RenderFrameImpl* frame_; RenderFrameImpl* frame_;
DISALLOW_COPY_AND_ASSIGN(DevToolsAgent); DISALLOW_COPY_AND_ASSIGN(DevToolsAgent);
......
...@@ -3789,6 +3789,10 @@ void RenderFrameImpl::WasShown() { ...@@ -3789,6 +3789,10 @@ void RenderFrameImpl::WasShown() {
FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasShown()); FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasShown());
} }
void RenderFrameImpl::WidgetWillClose() {
FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WidgetWillClose());
}
bool RenderFrameImpl::IsHidden() { bool RenderFrameImpl::IsHidden() {
return GetRenderWidget()->is_hidden(); return GetRenderWidget()->is_hidden();
} }
......
...@@ -185,6 +185,8 @@ class CONTENT_EXPORT RenderFrameImpl ...@@ -185,6 +185,8 @@ class CONTENT_EXPORT RenderFrameImpl
// Returns the RenderWidget associated with this frame. // Returns the RenderWidget associated with this frame.
RenderWidget* GetRenderWidget(); RenderWidget* GetRenderWidget();
DevToolsAgent* devtools_agent() { return devtools_agent_; }
// This is called right after creation with the WebLocalFrame for this // This is called right after creation with the WebLocalFrame for this
// RenderFrame. It must be called before Initialize. // RenderFrame. It must be called before Initialize.
void SetWebFrame(blink::WebLocalFrame* web_frame); void SetWebFrame(blink::WebLocalFrame* web_frame);
...@@ -197,6 +199,7 @@ class CONTENT_EXPORT RenderFrameImpl ...@@ -197,6 +199,7 @@ class CONTENT_EXPORT RenderFrameImpl
// Notifications from RenderWidget. // Notifications from RenderWidget.
void WasHidden(); void WasHidden();
void WasShown(); void WasShown();
void WidgetWillClose();
// Start/Stop loading notifications. // Start/Stop loading notifications.
// TODO(nasko): Those are page-level methods at this time and come from // TODO(nasko): Those are page-level methods at this time and come from
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "content/public/test/render_view_test.h" #include "content/public/test/render_view_test.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "content/renderer/accessibility/renderer_accessibility.h" #include "content/renderer/accessibility/renderer_accessibility.h"
#include "content/renderer/devtools/devtools_agent.h"
#include "content/renderer/history_controller.h" #include "content/renderer/history_controller.h"
#include "content/renderer/history_serialization.h" #include "content/renderer/history_serialization.h"
#include "content/renderer/navigation_state_impl.h" #include "content/renderer/navigation_state_impl.h"
...@@ -288,6 +289,36 @@ class RenderViewImplTest : public RenderViewTest { ...@@ -288,6 +289,36 @@ class RenderViewImplTest : public RenderViewTest {
scoped_ptr<MockKeyboard> mock_keyboard_; scoped_ptr<MockKeyboard> mock_keyboard_;
}; };
class DevToolsAgentTest : public RenderViewImplTest {
public:
void Attach() {
std::string host_id = "host_id";
agent()->OnAttach(host_id);
}
void Detach() {
agent()->OnDetach();
}
bool IsPaused() {
return agent()->paused_;
}
void DispatchDevToolsMessage(const std::string& message) {
agent()->OnDispatchOnInspectorBackend(message);
}
void CloseWhilePaused() {
EXPECT_TRUE(IsPaused());
view()->NotifyOnClose();
}
private:
DevToolsAgent* agent() {
return frame()->devtools_agent();
}
};
// Test for https://crbug.com/461191. // Test for https://crbug.com/461191.
TEST_F(RenderViewImplTest, RenderFrameMessageAfterDetach) { TEST_F(RenderViewImplTest, RenderFrameMessageAfterDetach) {
// Create a new main frame RenderFrame so that we don't interfere with the // Create a new main frame RenderFrame so that we don't interfere with the
...@@ -2340,4 +2371,20 @@ TEST_F(RenderViewImplTest, HistoryIsProperlyUpdatedOnNavigation) { ...@@ -2340,4 +2371,20 @@ TEST_F(RenderViewImplTest, HistoryIsProperlyUpdatedOnNavigation) {
view()->historyForwardListCount() + 1); view()->historyForwardListCount() + 1);
} }
TEST_F(DevToolsAgentTest, DevToolsResumeOnClose) {
Attach();
EXPECT_FALSE(IsPaused());
DispatchDevToolsMessage("{\"id\":1,\"method\":\"Debugger.enable\"}");
// Executing javascript will pause the thread and create nested message loop.
// Posting task simulates message coming from browser.
base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
ExecuteJavaScript("debugger;");
// CloseWhilePaused should resume execution and continue here.
EXPECT_FALSE(IsPaused());
Detach();
}
} // namespace content } // namespace content
...@@ -511,6 +511,7 @@ class CONTENT_EXPORT RenderViewImpl ...@@ -511,6 +511,7 @@ class CONTENT_EXPORT RenderViewImpl
private: private:
// For unit tests. // For unit tests.
friend class DevToolsAgentTest;
friend class PepperDeviceTest; friend class PepperDeviceTest;
friend class RenderViewImplTest; friend class RenderViewImplTest;
friend class RenderViewTest; friend class RenderViewTest;
......
...@@ -854,6 +854,7 @@ void RenderWidget::SetWindowRectSynchronously( ...@@ -854,6 +854,7 @@ void RenderWidget::SetWindowRectSynchronously(
void RenderWidget::OnClose() { void RenderWidget::OnClose() {
if (closing_) if (closing_)
return; return;
NotifyOnClose();
closing_ = true; closing_ = true;
// Browser correspondence is no longer needed at this point. // Browser correspondence is no longer needed at this point.
...@@ -1537,6 +1538,10 @@ void RenderWidget::DoDeferredClose() { ...@@ -1537,6 +1538,10 @@ void RenderWidget::DoDeferredClose() {
Send(new ViewHostMsg_Close(routing_id_)); Send(new ViewHostMsg_Close(routing_id_));
} }
void RenderWidget::NotifyOnClose() {
FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
}
void RenderWidget::closeWidgetSoon() { void RenderWidget::closeWidgetSoon() {
if (is_swapped_out_) { if (is_swapped_out_) {
// This widget is currently swapped out, and the active widget is in a // This widget is currently swapped out, and the active widget is in a
......
...@@ -380,6 +380,7 @@ class CONTENT_EXPORT RenderWidget ...@@ -380,6 +380,7 @@ class CONTENT_EXPORT RenderWidget
void FlushPendingInputEventAck(); void FlushPendingInputEventAck();
void DoDeferredClose(); void DoDeferredClose();
void DoDeferredSetWindowRect(const blink::WebRect& pos); void DoDeferredSetWindowRect(const blink::WebRect& pos);
void NotifyOnClose();
// Resizes the render widget. // Resizes the render widget.
void Resize(const gfx::Size& new_size, void Resize(const gfx::Size& new_size,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment