Commit bfd828d9 authored by Sreeja Kamishetty's avatar Sreeja Kamishetty Committed by Commit Bot

[chooser] Blocklist FileChooser for BackForwardCache

Currently, the FileChooser window is not explicitly closed when
navigating away.

This CL disables BackForwardCache when RunFileChooser is invoked
to avoid any renderer interactions when the page is in
BackForwardCache and user seeing any unexpected behaviour.

To make FileChooser bfcache compatible is is the next step.

BUG=1071232

Change-Id: I219143190425107a7604f2f23dd25c5e462d7106
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2193932
Commit-Queue: Sreeja Kamishetty <sreejakshetty@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776908}
parent 2524138f
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "content/browser/frame_host/render_frame_host_impl.h" #include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/generic_sensor/sensor_provider_proxy_impl.h" #include "content/browser/generic_sensor/sensor_provider_proxy_impl.h"
#include "content/browser/presentation/presentation_test_utils.h" #include "content/browser/presentation/presentation_test_utils.h"
#include "content/browser/web_contents/file_chooser_impl.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/content_navigation_policy.h" #include "content/common/content_navigation_policy.h"
#include "content/public/browser/back_forward_cache.h" #include "content/public/browser/back_forward_cache.h"
...@@ -6063,4 +6064,51 @@ IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, ...@@ -6063,4 +6064,51 @@ IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
FROM_HERE); FROM_HERE);
} }
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
DoesNotCacheIfRunFileChooserIsInvoked) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url_a(embedded_test_server()->GetURL("a.com", "/title1.html"));
GURL url_b(embedded_test_server()->GetURL("b.com", "/title1.html"));
// 1) Navigate to url_a and open file chooser.
EXPECT_TRUE(NavigateToURL(shell(), url_a));
RenderFrameHostImpl* rfh_a = current_frame_host();
RenderFrameDeletedObserver deleted_rfh_a(rfh_a);
content::BackForwardCacheDisabledTester tester;
// 2) Bind FileChooser to RenderFrameHost.
mojo::Remote<blink::mojom::FileChooser> chooser =
FileChooserImpl::CreateBoundForTesting(rfh_a);
auto quit_run_loop = [](base::OnceClosure callback,
blink::mojom::FileChooserResultPtr result) {
std::move(callback).Run();
};
// 3) Run OpenFileChooser and wait till its run.
base::RunLoop run_loop;
chooser->OpenFileChooser(
blink::mojom::FileChooserParams::New(),
base::BindOnce(quit_run_loop, run_loop.QuitClosure()));
run_loop.Run();
// 4) rfh_a should be disabled for BackForwardCache after opening file
// chooser.
EXPECT_TRUE(rfh_a->IsBackForwardCacheDisabled());
EXPECT_TRUE(tester.IsDisabledForFrameWithReason(
rfh_a->GetProcess()->GetID(), rfh_a->GetRoutingID(), "FileChooser"));
// 5) Navigate to B having the file chooser open.
EXPECT_TRUE(NavigateToURL(shell(), url_b));
// The page uses FileChooser so it should be deleted.
deleted_rfh_a.WaitUntilDeleted();
// 6) Go back to the page with FileChooser.
web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
ExpectOutcome(BackForwardCacheMetrics::HistoryNavigationOutcome::kNotRestored,
FROM_HERE);
}
} // namespace content } // namespace content
...@@ -117,6 +117,12 @@ void FileChooserImpl::OpenFileChooser(blink::mojom::FileChooserParamsPtr params, ...@@ -117,6 +117,12 @@ void FileChooserImpl::OpenFileChooser(blink::mojom::FileChooserParamsPtr params,
listener->FileSelectionCanceled(); listener->FileSelectionCanceled();
return; return;
} }
// Don't allow page with open FileChooser to enter BackForwardCache to avoid
// any unexpected behaviour from BackForwardCache.
BackForwardCache::DisableForRenderFrameHost(render_frame_host_,
"FileChooser");
static_cast<WebContentsImpl*>(web_contents()) static_cast<WebContentsImpl*>(web_contents())
->RunFileChooser(render_frame_host_, std::move(listener), *params); ->RunFileChooser(render_frame_host_, std::move(listener), *params);
} }
......
...@@ -17,6 +17,9 @@ class RenderFrameHostImpl; ...@@ -17,6 +17,9 @@ class RenderFrameHostImpl;
// An implementation of blink::mojom::FileChooser and FileSelectListener // An implementation of blink::mojom::FileChooser and FileSelectListener
// associated to RenderFrameHost. // associated to RenderFrameHost.
// TODO(sreejakshetty): Make FileChooserImpl per-frame and associate with
// RenderDocumentHostUserData to ensure that the state is correctly tracked and
// deleted.
class CONTENT_EXPORT FileChooserImpl : public blink::mojom::FileChooser, class CONTENT_EXPORT FileChooserImpl : public blink::mojom::FileChooser,
public WebContentsObserver { public WebContentsObserver {
using FileChooserResult = blink::mojom::FileChooserResult; using FileChooserResult = blink::mojom::FileChooserResult;
......
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