Commit 06343cc3 authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

bfcache: Disable BFCache when WebSerial is used.

Similar to WebUSB, pages that uses the Web Serial APIs shouldn't be
frozen and enter the BFCache (at least for now).

This CL marks the RenderFrameHost that uses the SerialService as
disabled for BFCache.

See CL for WebUSB:
https://chromium-review.googlesource.com/c/chromium/src/+/1837933/

Some background on why we sometimes need to disable bfcache:
https://docs.google.com/document/d/1NjZeusdS1kyEkZyfLggndU1A6qVt0Y1sa-LRUxnMoK8

Bug: 992851
Change-Id: I26f48bb309c2c2c6f2737e52c1ce533f8e03f437
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1851785
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704928}
parent eb5ef393
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h" #include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "components/network_session_configurator/common/network_switches.h" #include "components/network_session_configurator/common/network_switches.h"
#include "content/browser/frame_host/back_forward_cache_impl.h" #include "content/browser/frame_host/back_forward_cache_impl.h"
#include "content/browser/frame_host/frame_tree_node.h" #include "content/browser/frame_host/frame_tree_node.h"
...@@ -56,6 +57,8 @@ class BackForwardCacheBrowserTest : public ContentBrowserTest { ...@@ -56,6 +57,8 @@ class BackForwardCacheBrowserTest : public ContentBrowserTest {
switches::kUseFakeUIForMediaStream); switches::kUseFakeUIForMediaStream);
base::CommandLine::ForCurrentProcess()->AppendSwitch( base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kIgnoreCertificateErrors); switches::kIgnoreCertificateErrors);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
feature_list_.InitAndEnableFeatureWithParameters( feature_list_.InitAndEnableFeatureWithParameters(
features::kBackForwardCache, GetFeatureParams()); features::kBackForwardCache, GetFeatureParams());
...@@ -2774,6 +2777,99 @@ IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, WebUSB) { ...@@ -2774,6 +2777,99 @@ IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, WebUSB) {
} }
} }
#if !defined(OS_ANDROID)
// Check that the back-forward cache is disabled when the Serial API is used.
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, Serial) {
// Serial API requires HTTPS.
net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
https_server.AddDefaultHandlers(GetTestDataFilePath());
https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK);
ASSERT_TRUE(https_server.Start());
// Main document.
{
content::BackForwardCacheDisabledTester tester;
GURL url(https_server.GetURL("a.com", "/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_FALSE(current_frame_host()->is_back_forward_cache_disallowed());
EXPECT_EQ("Found 0 ports", content::EvalJs(current_frame_host(), R"(
new Promise(async resolve => {
let ports = await navigator.serial.getPorts();
resolve("Found " + ports.length + " ports");
});
)"));
EXPECT_TRUE(current_frame_host()->is_back_forward_cache_disallowed());
EXPECT_TRUE(tester.IsDisabledForFrameWithReason(
current_frame_host()->GetProcess()->GetID(),
current_frame_host()->GetRoutingID(), "Serial"));
}
// Nested document.
{
content::BackForwardCacheDisabledTester tester;
GURL url(
https_server.GetURL("c.com", "/cross_site_iframe_factory.html?c(d)"));
EXPECT_TRUE(NavigateToURL(shell(), url));
RenderFrameHostImpl* rfh_c = current_frame_host();
RenderFrameHostImpl* rfh_d = rfh_c->child_at(0)->current_frame_host();
EXPECT_FALSE(rfh_c->is_back_forward_cache_disallowed());
EXPECT_FALSE(rfh_d->is_back_forward_cache_disallowed());
EXPECT_EQ("Found 0 ports", content::EvalJs(rfh_c, R"(
new Promise(async resolve => {
let ports = await navigator.serial.getPorts();
resolve("Found " + ports.length + " ports");
});
)"));
EXPECT_TRUE(rfh_c->is_back_forward_cache_disallowed());
EXPECT_FALSE(rfh_d->is_back_forward_cache_disallowed());
EXPECT_TRUE(tester.IsDisabledForFrameWithReason(
rfh_c->GetProcess()->GetID(), rfh_c->GetRoutingID(), "Serial"));
}
// Worker.
{
content::BackForwardCacheDisabledTester tester;
GURL url(https_server.GetURL("e.com", "/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_FALSE(current_frame_host()->is_back_forward_cache_disallowed());
EXPECT_EQ("Found 0 ports", content::EvalJs(current_frame_host(), R"(
new Promise(async resolve => {
const worker = new Worker("/back_forward_cache/serial/worker.js");
worker.onmessage = message => resolve(message.data);
worker.postMessage("Run");
});
)"));
EXPECT_TRUE(current_frame_host()->is_back_forward_cache_disallowed());
EXPECT_TRUE(tester.IsDisabledForFrameWithReason(
current_frame_host()->GetProcess()->GetID(),
current_frame_host()->GetRoutingID(), "Serial"));
}
// Nested worker.
{
content::BackForwardCacheDisabledTester tester;
GURL url(https_server.GetURL("f.com", "/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
EXPECT_FALSE(current_frame_host()->is_back_forward_cache_disallowed());
EXPECT_EQ("Found 0 ports", content::EvalJs(current_frame_host(), R"(
new Promise(async resolve => {
const worker = new Worker(
"/back_forward_cache/serial/nested-worker.js");
worker.onmessage = message => resolve(message.data);
worker.postMessage("Run");
});
)"));
EXPECT_TRUE(current_frame_host()->is_back_forward_cache_disallowed());
EXPECT_TRUE(tester.IsDisabledForFrameWithReason(
current_frame_host()->GetProcess()->GetID(),
current_frame_host()->GetRoutingID(), "Serial"));
}
}
#endif
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, Encoding) { IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, Encoding) {
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
const GURL url_a(embedded_test_server()->GetURL( const GURL url_a(embedded_test_server()->GetURL(
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/serial_chooser.h" #include "content/public/browser/serial_chooser.h"
...@@ -41,6 +42,12 @@ SerialService::SerialService(RenderFrameHost* render_frame_host) ...@@ -41,6 +42,12 @@ SerialService::SerialService(RenderFrameHost* render_frame_host)
: render_frame_host_(render_frame_host) { : render_frame_host_(render_frame_host) {
DCHECK(render_frame_host_->IsFeatureEnabled( DCHECK(render_frame_host_->IsFeatureEnabled(
blink::mojom::FeaturePolicyFeature::kSerial)); blink::mojom::FeaturePolicyFeature::kSerial));
// Serial API is not supported for back-forward cache for now because we
// don't have support for closing/freezing ports when the frame is added to
// the back-forward cache, so we mark frames that use this API as disabled
// for back-forward cache.
BackForwardCache::DisableForRenderFrameHost(render_frame_host, "Serial");
watchers_.set_disconnect_handler(base::BindRepeating( watchers_.set_disconnect_handler(base::BindRepeating(
&SerialService::OnWatcherConnectionError, base::Unretained(this))); &SerialService::OnWatcherConnectionError, base::Unretained(this)));
} }
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const worker = new Worker("./worker.js");
// This worker is a simple bidirectional proxy.
onmessage = message => worker.postMessage(message.data);
worker.onmessage = message => postMessage(message.data);
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
onmessage = async () => {
let ports = await navigator.serial.getPorts();
postMessage("Found " + ports.length + " ports");
}
...@@ -12,15 +12,6 @@ ...@@ -12,15 +12,6 @@
-RenderFrameHostManagerTest.CommitNewNavigationBeforeSendingSwapOut -RenderFrameHostManagerTest.CommitNewNavigationBeforeSendingSwapOut
-RenderFrameHostManagerTest.SwapOutFrameAfterSwapOutACK -RenderFrameHostManagerTest.SwapOutFrameAfterSwapOutACK
# WebSerial:
#
# WebContentsImpl::IsConnectedToSerialPort() returns true, because the previous
# document uses the WebSerial and continue to do so after entering the
# BackForwardCache.
#
# See https://crbug.com/992851
-SerialTest.OpenAndNavigateCrossOrigin
# Test: # Test:
# 1) Normal navigation to a non-webui URL. # 1) Normal navigation to a non-webui URL.
# 2) Add the webui capability to the RenderFrameHost. # 2) Add the webui capability to the RenderFrameHost.
......
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