Commit 18b17847 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Issue KeepAliveHandler for service worker intercepted requests

We forgot to attach a KeepAliveHandler to a request with keepalive set
is intercepted to a service worker. Fix that.

Bug: 1008494
Change-Id: Ia3c2056b65aaedf2b9f865a324ea3f99d0f55506
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1830249Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701424}
parent 3a865fe5
......@@ -59,9 +59,13 @@ std::unique_ptr<net::test_server::HttpResponse> HandleBeacon(
}
std::unique_ptr<net::test_server::HttpResponse> HandleHungBeacon(
const base::RepeatingClosure& on_called,
const net::test_server::HttpRequest& request) {
if (request.relative_url != "/beacon")
return nullptr;
if (on_called) {
on_called.Run();
}
return std::make_unique<net::test_server::HungResponse>();
}
......@@ -987,6 +991,35 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KeepAliveRendererProcess) {
rph->RemoveObserver(this);
}
IN_PROC_BROWSER_TEST_F(RenderProcessHostTest,
KeepAliveRendererProcessWithServiceWorker) {
base::RunLoop run_loop;
embedded_test_server()->RegisterRequestHandler(
base::BindRepeating(HandleHungBeacon, run_loop.QuitClosure()));
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_TRUE(NavigateToURL(
shell(),
embedded_test_server()->GetURL("/workers/service_worker_setup.html")));
EXPECT_EQ("ok", EvalJs(shell(), "setup();"));
RenderProcessHostImpl* rph = static_cast<RenderProcessHostImpl*>(
shell()->web_contents()->GetMainFrame()->GetProcess());
// 1 for the service worker.
EXPECT_EQ(rph->keep_alive_ref_count(), 1u);
// We use /workers/send-beacon.html, not send-beacon.html, due to the
// service worker scope rule.
EXPECT_TRUE(NavigateToURL(
shell(), embedded_test_server()->GetURL("/workers/send-beacon.html")));
run_loop.Run();
// We are still using the same process.
ASSERT_EQ(shell()->web_contents()->GetMainFrame()->GetProcess(), rph);
// 1 for the service worker, 1 for the keepalive fetch.
EXPECT_EQ(rph->keep_alive_ref_count(), 2u);
}
// Test is flaky on Android builders: https://crbug.com/875179
#if defined(OS_ANDROID)
#define MAYBE_KeepAliveRendererProcess_Hung \
......@@ -997,7 +1030,7 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KeepAliveRendererProcess) {
IN_PROC_BROWSER_TEST_F(RenderProcessHostTest,
MAYBE_KeepAliveRendererProcess_Hung) {
embedded_test_server()->RegisterRequestHandler(
base::BindRepeating(HandleHungBeacon));
base::BindRepeating(HandleHungBeacon, base::RepeatingClosure()));
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_TRUE(NavigateToURL(
......@@ -1034,7 +1067,7 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest,
IN_PROC_BROWSER_TEST_F(RenderProcessHostTest,
MAYBE_FetchKeepAliveRendererProcess_Hung) {
embedded_test_server()->RegisterRequestHandler(
base::BindRepeating(HandleHungBeacon));
base::BindRepeating(HandleHungBeacon, base::RepeatingClosure()));
ASSERT_TRUE(embedded_test_server()->Start());
EXPECT_TRUE(NavigateToURL(
......
......@@ -546,6 +546,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
ipc_send_watcher_for_testing_ = std::move(watcher);
}
size_t keep_alive_ref_count() const { return keep_alive_ref_count_; }
protected:
// A proxy for our IPC::Channel that lives on the IO thread.
std::unique_ptr<IPC::ChannelProxy> channel_;
......
......@@ -137,11 +137,22 @@ ServiceWorkerNetworkProviderForFrame::CreateURLLoader(
kServiceWorkerInterceptedRequestFromOriginDirtyStyleSheet);
}
mojo::PendingRemote<mojom::KeepAliveHandle> keep_alive_handle;
if (request.GetKeepalive()) {
// This cast is safe because NewDocumentObserver is always created with a
// RenderFrameImpl.
auto* render_frame_impl =
static_cast<RenderFrameImpl*>(observer_->render_frame());
render_frame_impl->GetFrameHost()->IssueKeepAliveHandle(
keep_alive_handle.InitWithNewPipeAndPassReceiver());
}
// Create our own SubresourceLoader to route the request to the controller
// ServiceWorker.
return std::make_unique<WebURLLoaderImpl>(
RenderThreadImpl::current()->resource_dispatcher(),
std::move(task_runner_handle), context()->GetSubresourceLoaderFactory());
std::move(task_runner_handle), context()->GetSubresourceLoaderFactory(),
std::move(keep_alive_handle));
}
blink::mojom::ControllerServiceWorkerMode
......
<!doctype html>
<script>
navigator.sendBeacon('/beacon', 'hello');
</script>
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