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) {
}
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) {
......
......@@ -1367,6 +1367,40 @@ function testReload() {
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
// the DOM on exit.
......@@ -1834,6 +1868,7 @@ embedder.test.testList = {
'testNavigateAfterResize': testNavigateAfterResize,
'testNavigationToExternalProtocol': testNavigationToExternalProtocol,
'testReload': testReload,
'testReloadAfterTerminate': testReloadAfterTerminate,
'testRemoveWebviewOnExit': testRemoveWebviewOnExit,
'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation,
'testResizeWebviewResizesContent': testResizeWebviewResizesContent,
......
......@@ -109,13 +109,16 @@ base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, bool focused) {
focused_ = focused;
if (!rwh)
return;
rwh->Send(new InputMsg_SetFocus(rwh->GetRoutingID(), focused));
if (!focused && mouse_locked_)
OnUnlockMouse();
// Restore the last seen state of text input to the view.
RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>(
web_contents()->GetRenderWidgetHostView());
rwh->GetView());
if (rwhv) {
ViewHostMsg_TextInputState_Params params;
params.type = last_text_input_type_;
......@@ -718,9 +721,8 @@ void BrowserPluginGuest::OnResizeGuest(
void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id,
bool focused) {
RenderWidgetHost* rwh = web_contents()->GetRenderWidgetHostView()->
GetRenderWidgetHost();
RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView();
RenderWidgetHost* rwh = rwhv ? rwhv->GetRenderWidgetHost() : NULL;
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