Commit 2101161e authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

Reland: Ensure page visibility is consistent after load

Broken case is WebContents::WasHidden is called before the first load
then page visibility remains visible because nothing handles
PageMsg_WasHidden, and nothing rechecks the state after first load.
Note RenderView is invisible due to
EnsureRenderFrameHostVisibilityConsistent.

A related bug is that in this case RenderView is created to be visible
and then marked visible after. Turns out fixing this will also
correctly set page visibility, so this CL fixes this bug instead.

Previously reverted due to test flake due to test environment changing
visibility of WebContents under test. New version uses a WebContents
that's detached from the window, so should not be subject to such
external signals.

Bug: 929860
Change-Id: Id163bc57c79dbaf628eac50014d571aa76ad4ef6
Reviewed-on: https://chromium-review.googlesource.com/c/1476812Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633739}
parent d6c4ab8b
......@@ -364,8 +364,7 @@ bool RenderViewHostImpl::CreateRenderView(
params->opener_frame_route_id = opener_frame_route_id;
params->replicated_frame_state = replicated_frame_state;
params->proxy_routing_id = proxy_route_id;
params->hidden = is_active() ? GetWidget()->is_hidden()
: GetWidget()->delegate()->IsHidden();
params->hidden = GetWidget()->delegate()->IsHidden();
params->never_visible = delegate_->IsNeverVisible();
params->window_was_created_with_opener = window_was_created_with_opener;
if (main_rfh) {
......
......@@ -249,6 +249,7 @@ class CONTENT_EXPORT RenderWidgetHostDelegate {
// the RenderWidgetHost to ask the delegate if it can be shown in the event of
// something other than the WebContents attempting to enable visibility of
// this RenderWidgetHost.
// TODO(nasko): Move this to RenderViewHostDelegate.
virtual bool IsHidden();
// Returns the associated RenderViewHostDelegateView*, if possible.
......
......@@ -3242,4 +3242,26 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, CtrlClickSubframeLink) {
EXPECT_EQ(new_web_contents1, new_web_contents2);
}
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, SetVisibilityBeforeLoad) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/hello.html"));
WebContents* attached_web_contents = shell()->web_contents();
// Create a WebContents detached from native windows so that visibility of
// the WebContents is fully controlled by the app.
WebContents::CreateParams create_params(
attached_web_contents->GetBrowserContext(), nullptr /* site_instance */);
create_params.initial_size = gfx::Size(100, 100);
std::unique_ptr<WebContents> web_contents =
WebContents::Create(create_params);
EXPECT_EQ(Visibility::VISIBLE, web_contents->GetVisibility());
web_contents->WasHidden();
EXPECT_EQ(Visibility::HIDDEN, web_contents->GetVisibility());
EXPECT_TRUE(NavigateToURL(web_contents.get(), url));
EXPECT_TRUE(EvalJs(web_contents.get(), "document.hidden").ExtractBool());
}
} // namespace content
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