Commit 66602da3 authored by fsamuel's avatar fsamuel Committed by Commit bot

Browser Plugin: Don't crash browser when reloading crashed webview

We were accessing a NULL RWHV on BrowserPluginGuest::SetFocus. This CL
adds a guard to ensure we only attempt to set focus if we have a View.

BUG=413874

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

Cr-Commit-Position: refs/heads/master@{#294674}
parent 8aec45ee
...@@ -1193,7 +1193,11 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortNonWebSafeScheme) { ...@@ -1193,7 +1193,11 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortNonWebSafeScheme) {
} }
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReload) { IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReload) {
TestHelper("testReload", "web_view/shim", NEEDS_TEST_SERVER); TestHelper("testReload", "web_view/shim", NO_TEST_SERVER);
}
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReloadAfterTerminate) {
TestHelper("testReloadAfterTerminate", "web_view/shim", NO_TEST_SERVER);
} }
IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) { IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) {
......
...@@ -1367,6 +1367,40 @@ function testReload() { ...@@ -1367,6 +1367,40 @@ function testReload() {
document.body.appendChild(webview); document.body.appendChild(webview);
} }
// This test verifies that the reload method on webview functions as expected.
function testReloadAfterTerminate() {
var triggerNavUrl = 'data:text/html,trigger navigation';
var webview = document.createElement('webview');
var step = 1;
webview.addEventListener('loadstop', function(e) {
switch (step) {
case 1:
webview.terminate();
break;
case 2:
setTimeout(function() { embedder.test.succeed(); }, 0);
break;
default:
window.console.log('Unexpected loadstop event, step = ' + step);
embedder.test.fail();
break;
}
++step;
});
webview.addEventListener('exit', function(e) {
// Trigger a focus state change of the guest to test for
// http://crbug.com/413874.
webview.blur();
webview.focus();
setTimeout(function() { webview.reload(); }, 0);
});
webview.src = triggerNavUrl;
document.body.appendChild(webview);
}
// This test verifies that a <webview> is torn down gracefully when removed from // This test verifies that a <webview> is torn down gracefully when removed from
// the DOM on exit. // the DOM on exit.
...@@ -1834,6 +1868,7 @@ embedder.test.testList = { ...@@ -1834,6 +1868,7 @@ embedder.test.testList = {
'testNavigateAfterResize': testNavigateAfterResize, 'testNavigateAfterResize': testNavigateAfterResize,
'testNavigationToExternalProtocol': testNavigationToExternalProtocol, 'testNavigationToExternalProtocol': testNavigationToExternalProtocol,
'testReload': testReload, 'testReload': testReload,
'testReloadAfterTerminate': testReloadAfterTerminate,
'testRemoveWebviewOnExit': testRemoveWebviewOnExit, 'testRemoveWebviewOnExit': testRemoveWebviewOnExit,
'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation,
'testResizeWebviewResizesContent': testResizeWebviewResizesContent, 'testResizeWebviewResizesContent': testResizeWebviewResizesContent,
......
...@@ -109,13 +109,16 @@ base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { ...@@ -109,13 +109,16 @@ base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, bool focused) { void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, bool focused) {
focused_ = focused; focused_ = focused;
if (!rwh)
return;
rwh->Send(new InputMsg_SetFocus(rwh->GetRoutingID(), focused)); rwh->Send(new InputMsg_SetFocus(rwh->GetRoutingID(), focused));
if (!focused && mouse_locked_) if (!focused && mouse_locked_)
OnUnlockMouse(); OnUnlockMouse();
// Restore the last seen state of text input to the view. // Restore the last seen state of text input to the view.
RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>( RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>(
web_contents()->GetRenderWidgetHostView()); rwh->GetView());
if (rwhv) { if (rwhv) {
ViewHostMsg_TextInputState_Params params; ViewHostMsg_TextInputState_Params params;
params.type = last_text_input_type_; params.type = last_text_input_type_;
...@@ -718,9 +721,8 @@ void BrowserPluginGuest::OnResizeGuest( ...@@ -718,9 +721,8 @@ void BrowserPluginGuest::OnResizeGuest(
void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id, void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id,
bool focused) { bool focused) {
RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView();
RenderWidgetHost* rwh = web_contents()->GetRenderWidgetHostView()-> RenderWidgetHost* rwh = rwhv ? rwhv->GetRenderWidgetHost() : NULL;
GetRenderWidgetHost();
SetFocus(rwh, focused); SetFocus(rwh, focused);
} }
......
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