Commit c6370718 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

[DevTools] Fix crash in WebContentsImpl::ClearDeviceEmulationSize

We are accessing null RenderWidgetHostView. Also added a test which
exposed an issue with emulation commands not being processed when
crashed.

Bug: 818573
Change-Id: Ife852d5323b56d2d08382ef865ac9bf51c5476ff
Reviewed-on: https://chromium-review.googlesource.com/949725Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540998}
parent ddf2a4e4
...@@ -2250,6 +2250,24 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolDeviceEmulationTest, MAYBE_DeviceSize) { ...@@ -2250,6 +2250,24 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolDeviceEmulationTest, MAYBE_DeviceSize) {
EXPECT_EQ(original_size, GetViewSize()); EXPECT_EQ(original_size, GetViewSize());
} }
// Setting frame size (through RWHV) is not supported on Android.
#if defined(OS_ANDROID)
#define MAYBE_RenderKillDoesNotCrashBrowser \
DISABLED_RenderKillDoesNotCrashBrowser
#else
#define MAYBE_RenderKillDoesNotCrashBrowser RenderKillDoesNotCrashBrowser
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProtocolDeviceEmulationTest,
MAYBE_RenderKillDoesNotCrashBrowser) {
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach();
EmulateDeviceSize(gfx::Size(200, 200));
NavigateToURLBlockUntilNavigationsComplete(
shell(), GURL(content::kChromeUICrashURL), 1);
SendCommand("Emulation.clearDeviceMetricsOverride", nullptr);
// Should not crash at this point.
}
class DevToolsProtocolTouchTest : public DevToolsProtocolTest { class DevToolsProtocolTouchTest : public DevToolsProtocolTest {
public: public:
~DevToolsProtocolTouchTest() override {} ~DevToolsProtocolTouchTest() override {}
......
...@@ -265,8 +265,12 @@ Response EmulationHandler::SetDeviceMetricsOverride( ...@@ -265,8 +265,12 @@ Response EmulationHandler::SetDeviceMetricsOverride(
device_emulation_enabled_ = true; device_emulation_enabled_ = true;
device_emulation_params_ = params; device_emulation_params_ = params;
UpdateDeviceEmulationState(); UpdateDeviceEmulationState();
// Renderer should answer after emulation params were updated, so that the // Renderer should answer after emulation params were updated, so that the
// response is only sent to the client once updates were applied. // response is only sent to the client once updates were applied.
// Unless the renderer has crashed.
if (GetWebContents() && GetWebContents()->IsCrashed())
return Response::OK();
return Response::FallThrough(); return Response::FallThrough();
} }
...@@ -282,6 +286,9 @@ Response EmulationHandler::ClearDeviceMetricsOverride() { ...@@ -282,6 +286,9 @@ Response EmulationHandler::ClearDeviceMetricsOverride() {
UpdateDeviceEmulationState(); UpdateDeviceEmulationState();
// Renderer should answer after emulation was disabled, so that the response // Renderer should answer after emulation was disabled, so that the response
// is only sent to the client once updates were applied. // is only sent to the client once updates were applied.
// Unless the renderer has crashed.
if (GetWebContents() && GetWebContents()->IsCrashed())
return Response::OK();
return Response::FallThrough(); return Response::FallThrough();
} }
......
...@@ -5983,9 +5983,10 @@ void WebContentsImpl::ClearDeviceEmulationSize() { ...@@ -5983,9 +5983,10 @@ void WebContentsImpl::ClearDeviceEmulationSize() {
// emulation. // emulation.
// TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when
// WebContentsView size changes). // WebContentsView size changes).
if (!view_size_before_emulation_.IsEmpty() && if (!view_size_before_emulation_.IsEmpty() && rwhv &&
rwhv->GetViewBounds().size() == device_emulation_size_) rwhv->GetViewBounds().size() == device_emulation_size_) {
rwhv->SetSize(view_size_before_emulation_); rwhv->SetSize(view_size_before_emulation_);
}
device_emulation_size_ = gfx::Size(); device_emulation_size_ = gfx::Size();
view_size_before_emulation_ = gfx::Size(); view_size_before_emulation_ = gfx::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