Commit 2c23b14c authored by Ting Shao's avatar Ting Shao Committed by Commit Bot

ServiceWorker: Add URLLoaderFactoryType::kServiceWorkerScript

Service workers load scripts and sub resources. Currently There is only
one URLLoaderFactory type (kServiceWorkerSubResources) for all cases.
However, When ServiceWorkerImportedScriptUpdateCheck is enabled, only
scripts are loaded in browser process during the check. It's necessary
to separate the loader factory into two types.

So add ContentBrowserClient::URLLoaderFactoryType::kServiceWorkerScript.

Change-Id: I41564fba6b4702257324d77c3d9125be747b2ee4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774051Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Ting Shao <ting.shao@intel.com>
Cr-Commit-Position: refs/heads/master@{#691528}
parent 63030b69
...@@ -206,9 +206,11 @@ void ServiceWorkerDevToolsAgentHost::UpdateLoaderFactories( ...@@ -206,9 +206,11 @@ void ServiceWorkerDevToolsAgentHost::UpdateLoaderFactories(
} }
const url::Origin origin = url::Origin::Create(url_); const url::Origin origin = url::Origin::Create(url_);
auto script_bundle = EmbeddedWorkerInstance::CreateFactoryBundleOnUI( auto script_bundle = EmbeddedWorkerInstance::CreateFactoryBundleOnUI(
rph, worker_route_id_, origin); rph, worker_route_id_, origin,
ContentBrowserClient::URLLoaderFactoryType::kServiceWorkerScript);
auto subresource_bundle = EmbeddedWorkerInstance::CreateFactoryBundleOnUI( auto subresource_bundle = EmbeddedWorkerInstance::CreateFactoryBundleOnUI(
rph, worker_route_id_, origin); rph, worker_route_id_, origin,
ContentBrowserClient::URLLoaderFactoryType::kServiceWorkerSubResource);
base::PostTaskAndReply( base::PostTaskAndReply(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&UpdateLoaderFactoriesOnIO, context_weak_, version_id_, base::BindOnce(&UpdateLoaderFactoriesOnIO, context_weak_, version_id_,
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "content/common/url_schemes.h" #include "content/common/url_schemes.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/child_process_host.h" #include "content/public/common/child_process_host.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
...@@ -237,8 +236,9 @@ void SetupOnUIThread( ...@@ -237,8 +236,9 @@ void SetupOnUIThread(
// the 'installed' state. // the 'installed' state.
if (!params->is_installed) { if (!params->is_installed) {
factory_bundle_for_new_scripts = factory_bundle_for_new_scripts =
EmbeddedWorkerInstance::CreateFactoryBundleOnUI(rph, routing_id, EmbeddedWorkerInstance::CreateFactoryBundleOnUI(
origin); rph, routing_id, origin,
ContentBrowserClient::URLLoaderFactoryType::kServiceWorkerScript);
} }
// The bundle for the renderer is passed to the service worker, and // The bundle for the renderer is passed to the service worker, and
...@@ -246,8 +246,9 @@ void SetupOnUIThread( ...@@ -246,8 +246,9 @@ void SetupOnUIThread(
// It's OK to not support reconnection to the network service because the // It's OK to not support reconnection to the network service because the
// service worker terminates itself when the connection breaks, so a new // service worker terminates itself when the connection breaks, so a new
// instance can be started. // instance can be started.
factory_bundle_for_renderer = factory_bundle_for_renderer = EmbeddedWorkerInstance::CreateFactoryBundleOnUI(
EmbeddedWorkerInstance::CreateFactoryBundleOnUI(rph, routing_id, origin); rph, routing_id, origin,
ContentBrowserClient::URLLoaderFactoryType::kServiceWorkerSubResource);
// TODO(crbug.com/862854): Support changes to // TODO(crbug.com/862854): Support changes to
// blink::mojom::RendererPreferences while the worker is running. // blink::mojom::RendererPreferences while the worker is running.
...@@ -1036,9 +1037,11 @@ base::WeakPtr<EmbeddedWorkerInstance> EmbeddedWorkerInstance::AsWeakPtr() { ...@@ -1036,9 +1037,11 @@ base::WeakPtr<EmbeddedWorkerInstance> EmbeddedWorkerInstance::AsWeakPtr() {
// //
// The network factory does not support reconnection to the network service. // The network factory does not support reconnection to the network service.
std::unique_ptr<blink::URLLoaderFactoryBundleInfo> std::unique_ptr<blink::URLLoaderFactoryBundleInfo>
EmbeddedWorkerInstance::CreateFactoryBundleOnUI(RenderProcessHost* rph, EmbeddedWorkerInstance::CreateFactoryBundleOnUI(
int routing_id, RenderProcessHost* rph,
const url::Origin& origin) { int routing_id,
const url::Origin& origin,
ContentBrowserClient::URLLoaderFactoryType factory_type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto factory_bundle = std::make_unique<blink::URLLoaderFactoryBundleInfo>(); auto factory_bundle = std::make_unique<blink::URLLoaderFactoryBundleInfo>();
mojo::PendingReceiver<network::mojom::URLLoaderFactory> mojo::PendingReceiver<network::mojom::URLLoaderFactory>
...@@ -1051,8 +1054,7 @@ EmbeddedWorkerInstance::CreateFactoryBundleOnUI(RenderProcessHost* rph, ...@@ -1051,8 +1054,7 @@ EmbeddedWorkerInstance::CreateFactoryBundleOnUI(RenderProcessHost* rph,
// See if the default factory needs to be tweaked by the embedder. // See if the default factory needs to be tweaked by the embedder.
GetContentClient()->browser()->WillCreateURLLoaderFactory( GetContentClient()->browser()->WillCreateURLLoaderFactory(
rph->GetBrowserContext(), nullptr /* frame_host */, rph->GetID(), rph->GetBrowserContext(), nullptr /* frame_host */, rph->GetID(),
ContentBrowserClient::URLLoaderFactoryType::kServiceWorkerSubResource, factory_type, origin, &default_factory_receiver, &default_header_client,
origin, &default_factory_receiver, &default_header_client,
&bypass_redirect_checks); &bypass_redirect_checks);
devtools_instrumentation::WillCreateURLLoaderFactoryForServiceWorker( devtools_instrumentation::WillCreateURLLoaderFactoryForServiceWorker(
rph, routing_id, &default_factory_receiver); rph, routing_id, &default_factory_receiver);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "content/browser/service_worker/embedded_worker_status.h" #include "content/browser/service_worker/embedded_worker_status.h"
#include "content/browser/service_worker/service_worker_metrics.h" #include "content/browser/service_worker/service_worker_metrics.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/content_browser_client.h"
#include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
...@@ -237,9 +238,11 @@ class CONTENT_EXPORT EmbeddedWorkerInstance ...@@ -237,9 +238,11 @@ class CONTENT_EXPORT EmbeddedWorkerInstance
// The below can only be called on the UI thread. The returned factory may be // The below can only be called on the UI thread. The returned factory may be
// later supplied to UpdateLoaderFactories(). // later supplied to UpdateLoaderFactories().
static std::unique_ptr<blink::URLLoaderFactoryBundleInfo> static std::unique_ptr<blink::URLLoaderFactoryBundleInfo>
CreateFactoryBundleOnUI(RenderProcessHost* rph, CreateFactoryBundleOnUI(
int routing_id, RenderProcessHost* rph,
const url::Origin& origin); int routing_id,
const url::Origin& origin,
ContentBrowserClient::URLLoaderFactoryType factory_type);
private: private:
typedef base::ObserverList<Listener>::Unchecked ListenerList; typedef base::ObserverList<Listener>::Unchecked ListenerList;
......
...@@ -1189,7 +1189,8 @@ class CONTENT_EXPORT ContentBrowserClient { ...@@ -1189,7 +1189,8 @@ class CONTENT_EXPORT ContentBrowserClient {
// Allows the embedder to intercept URLLoaderFactory interfaces used for // Allows the embedder to intercept URLLoaderFactory interfaces used for
// navigation or being brokered on behalf of a renderer fetching subresources. // navigation or being brokered on behalf of a renderer fetching subresources.
// //
// |frame| is nullptr for kWorkerSubResource and kServiceWorkerSubResource. // |frame| is nullptr for kWorkerSubResource, kServiceWorkerSubResource and
// kServiceWorkerScript.
// For kNavigation type, it's the RenderFrameHost the navigation might commit // For kNavigation type, it's the RenderFrameHost the navigation might commit
// in. Else it's the initiating frame. // in. Else it's the initiating frame.
// //
...@@ -1200,8 +1201,9 @@ class CONTENT_EXPORT ContentBrowserClient { ...@@ -1200,8 +1201,9 @@ class CONTENT_EXPORT ContentBrowserClient {
// requests that will use the URLLoaderFactory. It's set when this factory is // requests that will use the URLLoaderFactory. It's set when this factory is
// created a) for a renderer to use to fetch subresources // created a) for a renderer to use to fetch subresources
// (kDocumentSubResource, kWorkerSubResource, kServiceWorkerSubResource), or // (kDocumentSubResource, kWorkerSubResource, kServiceWorkerSubResource), or
// b) for the browser to use to fetch a worker (kWorkerMainResource). An // b) for the browser to use to fetch a worker (kWorkerMainResource) or
// opaque origin is passed currently for navigation (kNavigation) and // service worker scripts (kServiceWorkerScript).
// An opaque origin is passed currently for navigation (kNavigation) and
// download (kDownload) factories even though requests from these factories // download (kDownload) factories even though requests from these factories
// can have a valid |network::ResourceRequest::request_initiator|. // can have a valid |network::ResourceRequest::request_initiator|.
// Note: For the kDocumentSubResource case, the |request_initiator| may be // Note: For the kDocumentSubResource case, the |request_initiator| may be
...@@ -1235,7 +1237,12 @@ class CONTENT_EXPORT ContentBrowserClient { ...@@ -1235,7 +1237,12 @@ class CONTENT_EXPORT ContentBrowserClient {
kWorkerMainResource, kWorkerMainResource,
kWorkerSubResource, kWorkerSubResource,
// For regular fetches from a service worker (e.g., fetch(), XHR).
kServiceWorkerSubResource, kServiceWorkerSubResource,
// For fetching a service worker main script or subresource scripts
// (e.g., importScripts()).
kServiceWorkerScript,
}; };
virtual bool WillCreateURLLoaderFactory( virtual bool WillCreateURLLoaderFactory(
BrowserContext* browser_context, BrowserContext* browser_context,
......
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