diff options
Diffstat (limited to 'chromium/content/renderer/loader')
20 files changed, 412 insertions, 347 deletions
diff --git a/chromium/content/renderer/loader/child_url_loader_factory_bundle.cc b/chromium/content/renderer/loader/child_url_loader_factory_bundle.cc index 4e66f652480..0847553956c 100644 --- a/chromium/content/renderer/loader/child_url_loader_factory_bundle.cc +++ b/chromium/content/renderer/loader/child_url_loader_factory_bundle.cc @@ -4,7 +4,13 @@ #include "content/renderer/loader/child_url_loader_factory_bundle.h" +#include <memory> +#include <string> +#include <utility> +#include <vector> + #include "base/logging.h" +#include "content/public/common/resource_type.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "url/gurl.h" #include "url/url_constants.h" @@ -89,26 +95,44 @@ class URLLoaderRelay : public network::mojom::URLLoaderClient, network::mojom::URLLoaderClientPtr client_sink_; }; +template <typename TKey> +static std::map<TKey, network::mojom::URLLoaderFactoryPtrInfo> +PassInterfacePtrMapToPtrInfoMap( + std::map<TKey, network::mojom::URLLoaderFactoryPtr> input) { + std::map<TKey, network::mojom::URLLoaderFactoryPtrInfo> output; + for (auto& it : input) { + const TKey& key = it.first; + network::mojom::URLLoaderFactoryPtr& factory = it.second; + output.emplace(key, factory.PassInterface()); + } + return output; +} + } // namespace ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo() = default; ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo( std::unique_ptr<URLLoaderFactoryBundleInfo> base_info) - : URLLoaderFactoryBundleInfo(std::move(base_info->default_factory_info()), - std::move(base_info->factories_info()), - base_info->bypass_redirect_checks()) {} + : URLLoaderFactoryBundleInfo( + std::move(base_info->default_factory_info()), + std::move(base_info->scheme_specific_factory_infos()), + std::move(base_info->initiator_specific_factory_infos()), + base_info->bypass_redirect_checks()) {} ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo( network::mojom::URLLoaderFactoryPtrInfo default_factory_info, - std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> - factories_info, + SchemeMap scheme_specific_factory_infos, + OriginMap initiator_specific_factory_infos, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, + network::mojom::URLLoaderFactoryPtrInfo prefetch_loader_factory_info, bool bypass_redirect_checks) : URLLoaderFactoryBundleInfo(std::move(default_factory_info), - std::move(factories_info), + std::move(scheme_specific_factory_infos), + std::move(initiator_specific_factory_infos), bypass_redirect_checks), - direct_network_factory_info_(std::move(direct_network_factory_info)) {} + direct_network_factory_info_(std::move(direct_network_factory_info)), + prefetch_loader_factory_info_(std::move(prefetch_loader_factory_info)) {} ChildURLLoaderFactoryBundleInfo::~ChildURLLoaderFactoryBundleInfo() = default; @@ -116,8 +140,13 @@ scoped_refptr<network::SharedURLLoaderFactory> ChildURLLoaderFactoryBundleInfo::CreateFactory() { auto other = std::make_unique<ChildURLLoaderFactoryBundleInfo>(); other->default_factory_info_ = std::move(default_factory_info_); - other->factories_info_ = std::move(factories_info_); + other->scheme_specific_factory_infos_ = + std::move(scheme_specific_factory_infos_); + other->initiator_specific_factory_infos_ = + std::move(initiator_specific_factory_infos_); other->direct_network_factory_info_ = std::move(direct_network_factory_info_); + other->prefetch_loader_factory_info_ = + std::move(prefetch_loader_factory_info_); other->bypass_redirect_checks_ = bypass_redirect_checks_; return base::MakeRefCounted<ChildURLLoaderFactoryBundle>(std::move(other)); @@ -139,14 +168,12 @@ ChildURLLoaderFactoryBundle::ChildURLLoaderFactoryBundle( ChildURLLoaderFactoryBundle::~ChildURLLoaderFactoryBundle() = default; -network::mojom::URLLoaderFactory* ChildURLLoaderFactoryBundle::GetFactoryForURL( - const GURL& url) { - auto it = factories_.find(url.scheme()); - if (it != factories_.end()) - return it->second.get(); - - if (default_factory_) - return default_factory_.get(); +network::mojom::URLLoaderFactory* ChildURLLoaderFactoryBundle::GetFactory( + const network::ResourceRequest& request) { + network::mojom::URLLoaderFactory* base_result = + URLLoaderFactoryBundle::GetFactory(request); + if (base_result) + return base_result; InitDirectNetworkFactoryIfNecessary(); DCHECK(direct_network_factory_); @@ -179,11 +206,22 @@ void ChildURLLoaderFactoryBundle::CreateLoaderAndStart( return; } - network::mojom::URLLoaderFactory* factory_ptr = GetFactoryForURL(request.url); + // Use |prefetch_loader_factory_| for prefetch requests to send the requests + // to the PrefetchURLLoaderService in the browser process and triger the + // special prefetch handling. + // TODO(horo): Move this routing logic to network service, when we will have + // the special prefetch handling in network service. + if ((request.resource_type == RESOURCE_TYPE_PREFETCH) && + prefetch_loader_factory_) { + prefetch_loader_factory_->CreateLoaderAndStart( + std::move(loader), routing_id, request_id, options, request, + std::move(client), traffic_annotation); + return; + } - factory_ptr->CreateLoaderAndStart(std::move(loader), routing_id, request_id, - options, request, std::move(client), - traffic_annotation); + URLLoaderFactoryBundle::CreateLoaderAndStart( + std::move(loader), routing_id, request_id, options, request, + std::move(client), traffic_annotation); } std::unique_ptr<network::SharedURLLoaderFactoryInfo> @@ -204,6 +242,10 @@ void ChildURLLoaderFactoryBundle::Update( direct_network_factory_.Bind( std::move(info->direct_network_factory_info())); } + if (info->prefetch_loader_factory_info()) { + prefetch_loader_factory_.Bind( + std::move(info->prefetch_loader_factory_info())); + } URLLoaderFactoryBundle::Update(std::move(info)); if (subresource_overrides) { @@ -213,6 +255,11 @@ void ChildURLLoaderFactoryBundle::Update( } } +void ChildURLLoaderFactoryBundle::SetPrefetchLoaderFactory( + network::mojom::URLLoaderFactoryPtr prefetch_loader_factory) { + prefetch_loader_factory_ = std::move(prefetch_loader_factory); +} + bool ChildURLLoaderFactoryBundle::IsHostChildURLLoaderFactoryBundle() const { return false; } @@ -236,25 +283,27 @@ ChildURLLoaderFactoryBundle::CloneInternal(bool include_default) { if (include_default && default_factory_) default_factory_->Clone(mojo::MakeRequest(&default_factory_info)); - std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> factories_info; - for (auto& factory : factories_) { - network::mojom::URLLoaderFactoryPtrInfo factory_info; - factory.second->Clone(mojo::MakeRequest(&factory_info)); - factories_info.emplace(factory.first, std::move(factory_info)); - } - network::mojom::URLLoaderFactoryPtrInfo direct_network_factory_info; if (direct_network_factory_) { direct_network_factory_->Clone( mojo::MakeRequest(&direct_network_factory_info)); } + network::mojom::URLLoaderFactoryPtrInfo prefetch_loader_factory_info; + if (prefetch_loader_factory_) { + prefetch_loader_factory_->Clone( + mojo::MakeRequest(&prefetch_loader_factory_info)); + } + // Currently there is no need to override subresources from workers, // therefore |subresource_overrides| are not shared with the clones. return std::make_unique<ChildURLLoaderFactoryBundleInfo>( - std::move(default_factory_info), std::move(factories_info), - std::move(direct_network_factory_info), bypass_redirect_checks_); + std::move(default_factory_info), + ClonePtrMapToPtrInfoMap(scheme_specific_factories_), + ClonePtrMapToPtrInfoMap(initiator_specific_factories_), + std::move(direct_network_factory_info), + std::move(prefetch_loader_factory_info), bypass_redirect_checks_); } std::unique_ptr<ChildURLLoaderFactoryBundleInfo> @@ -265,20 +314,23 @@ ChildURLLoaderFactoryBundle::PassInterface() { if (default_factory_) default_factory_info = default_factory_.PassInterface(); - std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> factories_info; - for (auto& factory : factories_) { - factories_info.emplace(factory.first, factory.second.PassInterface()); - } - PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory> direct_network_factory_info; if (direct_network_factory_) { direct_network_factory_info = direct_network_factory_.PassInterface(); } + network::mojom::URLLoaderFactoryPtrInfo prefetch_loader_factory_info; + if (prefetch_loader_factory_) { + prefetch_loader_factory_info = prefetch_loader_factory_.PassInterface(); + } + return std::make_unique<ChildURLLoaderFactoryBundleInfo>( - std::move(default_factory_info), std::move(factories_info), - std::move(direct_network_factory_info), bypass_redirect_checks_); + std::move(default_factory_info), + PassInterfacePtrMapToPtrInfoMap(std::move(scheme_specific_factories_)), + PassInterfacePtrMapToPtrInfoMap(std::move(initiator_specific_factories_)), + std::move(direct_network_factory_info), + std::move(prefetch_loader_factory_info), bypass_redirect_checks_); } } // namespace content diff --git a/chromium/content/renderer/loader/child_url_loader_factory_bundle.h b/chromium/content/renderer/loader/child_url_loader_factory_bundle.h index 0ba0c4950a3..a6b429299c7 100644 --- a/chromium/content/renderer/loader/child_url_loader_factory_bundle.h +++ b/chromium/content/renderer/loader/child_url_loader_factory_bundle.h @@ -5,7 +5,12 @@ #ifndef CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ #define CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ +#include <map> +#include <memory> +#include <vector> + #include "base/callback.h" +#include "base/optional.h" #include "content/common/content_export.h" #include "content/common/possibly_associated_interface_ptr.h" #include "content/common/url_loader_factory_bundle.h" @@ -16,6 +21,12 @@ namespace content { // Holds the internal state of a ChildURLLoaderFactoryBundle in a form that is // safe to pass across sequences. +// |prefetch_loader_factory_info| is used only by the frames who may send +// prefetch requests by <link rel="prefetch"> tags. The loader factory allows +// prefetch loading to be done by the browser process (therefore less memory +// pressure), and also adds special handling for Signed Exchanges (SXG) when the +// flag is enabled. TODO(crbug/803776): deprecate this once SXG specific code is +// moved into Network Service unless we see huge memory benefit for doing this. class CONTENT_EXPORT ChildURLLoaderFactoryBundleInfo : public URLLoaderFactoryBundleInfo { public: @@ -27,21 +38,26 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundleInfo std::unique_ptr<URLLoaderFactoryBundleInfo> base_info); ChildURLLoaderFactoryBundleInfo( network::mojom::URLLoaderFactoryPtrInfo default_factory_info, - std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> - factories_info, + SchemeMap scheme_specific_factory_infos, + OriginMap initiator_specific_factory_infos, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, + network::mojom::URLLoaderFactoryPtrInfo prefetch_loader_factory_info, bool bypass_redirect_checks); ~ChildURLLoaderFactoryBundleInfo() override; PossiblyAssociatedURLLoaderFactoryPtrInfo& direct_network_factory_info() { return direct_network_factory_info_; } + network::mojom::URLLoaderFactoryPtrInfo& prefetch_loader_factory_info() { + return prefetch_loader_factory_info_; + } protected: // URLLoaderFactoryBundleInfo overrides. scoped_refptr<network::SharedURLLoaderFactory> CreateFactory() override; PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info_; + network::mojom::URLLoaderFactoryPtrInfo prefetch_loader_factory_info_; DISALLOW_COPY_AND_ASSIGN(ChildURLLoaderFactoryBundleInfo); }; @@ -70,8 +86,6 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle PossiblyAssociatedFactoryGetterCallback direct_network_factory_getter); // URLLoaderFactoryBundle overrides. - network::mojom::URLLoaderFactory* GetFactoryForURL(const GURL& url) override; - void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader, int32_t routing_id, int32_t request_id, @@ -80,7 +94,6 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle network::mojom::URLLoaderClientPtr client, const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) override; - std::unique_ptr<network::SharedURLLoaderFactoryInfo> Clone() override; // Returns an info that omits this bundle's default factory, if any. This is @@ -93,12 +106,18 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle void Update(std::unique_ptr<ChildURLLoaderFactoryBundleInfo> info, base::Optional<std::vector<mojom::TransferrableURLLoaderPtr>> subresource_overrides); + void SetPrefetchLoaderFactory( + network::mojom::URLLoaderFactoryPtr prefetch_loader_factory); virtual bool IsHostChildURLLoaderFactoryBundle() const; protected: ~ChildURLLoaderFactoryBundle() override; + // URLLoaderFactoryBundle overrides. + network::mojom::URLLoaderFactory* GetFactory( + const network::ResourceRequest& request) override; + private: void InitDirectNetworkFactoryIfNecessary(); std::unique_ptr<network::SharedURLLoaderFactoryInfo> CloneInternal( @@ -106,6 +125,7 @@ class CONTENT_EXPORT ChildURLLoaderFactoryBundle PossiblyAssociatedFactoryGetterCallback direct_network_factory_getter_; PossiblyAssociatedURLLoaderFactoryPtr direct_network_factory_; + network::mojom::URLLoaderFactoryPtr prefetch_loader_factory_; std::map<GURL, mojom::TransferrableURLLoaderPtr> subresource_overrides_; }; diff --git a/chromium/content/renderer/loader/code_cache_loader_impl.cc b/chromium/content/renderer/loader/code_cache_loader_impl.cc index 0fbbeac5e1b..edc4e117dfd 100644 --- a/chromium/content/renderer/loader/code_cache_loader_impl.cc +++ b/chromium/content/renderer/loader/code_cache_loader_impl.cc @@ -45,10 +45,11 @@ void CodeCacheLoaderImpl::FetchFromCodeCacheSynchronously( // It is Ok to pass |fetch_code_cache_event| with base::Unretained. Since // this thread is stalled, the fetch_code_cache_event will be kept alive. task_runner->PostTask( - FROM_HERE, - base::BindOnce(&CodeCacheLoaderImpl::FetchFromCodeCacheImpl, - weak_ptr_factory_.GetWeakPtr(), url, std::move(callback), - base::Unretained(&fetch_code_cache_event))); + FROM_HERE, base::BindOnce(&CodeCacheLoaderImpl::FetchFromCodeCacheImpl, + weak_ptr_factory_.GetWeakPtr(), + blink::mojom::CodeCacheType::kJavascript, url, + std::move(callback), + base::Unretained(&fetch_code_cache_event))); // Wait for the fetch from code cache to finish. fetch_code_cache_event.Wait(); @@ -58,12 +59,15 @@ void CodeCacheLoaderImpl::FetchFromCodeCacheSynchronously( *data_out = data_for_sync_load_; } -void CodeCacheLoaderImpl::FetchFromCodeCache(const GURL& url, - FetchCodeCacheCallback callback) { - FetchFromCodeCacheImpl(url, std::move(callback), nullptr); +void CodeCacheLoaderImpl::FetchFromCodeCache( + blink::mojom::CodeCacheType cache_type, + const GURL& url, + FetchCodeCacheCallback callback) { + FetchFromCodeCacheImpl(cache_type, url, std::move(callback), nullptr); } void CodeCacheLoaderImpl::FetchFromCodeCacheImpl( + blink::mojom::CodeCacheType cache_type, const GURL& gurl, FetchCodeCacheCallback callback, base::WaitableEvent* fetch_event) { @@ -71,9 +75,10 @@ void CodeCacheLoaderImpl::FetchFromCodeCacheImpl( // fetch_event, because the thread is stalled and it will keep the fetch_event // alive. blink::Platform::Current()->FetchCachedCode( - gurl, base::BindOnce(&CodeCacheLoaderImpl::OnReceiveCachedCode, - weak_ptr_factory_.GetWeakPtr(), std::move(callback), - fetch_event)); + cache_type, gurl, + base::BindOnce(&CodeCacheLoaderImpl::OnReceiveCachedCode, + weak_ptr_factory_.GetWeakPtr(), std::move(callback), + fetch_event)); } void CodeCacheLoaderImpl::OnReceiveCachedCode( diff --git a/chromium/content/renderer/loader/code_cache_loader_impl.h b/chromium/content/renderer/loader/code_cache_loader_impl.h index 99c9d156e18..fc4084b616d 100644 --- a/chromium/content/renderer/loader/code_cache_loader_impl.h +++ b/chromium/content/renderer/loader/code_cache_loader_impl.h @@ -22,16 +22,18 @@ class CodeCacheLoaderImpl : public blink::CodeCacheLoader { // Fetches code cache corresponding to |url| and returns response in // |response_time_out| and |data_out|. |response_time_out| and |data_out| - // cannot be nullptrs. + // cannot be nullptrs. This only fetches from the Javascript cache. void FetchFromCodeCacheSynchronously(const GURL& url, base::Time* response_time_out, std::vector<uint8_t>* data_out) override; - void FetchFromCodeCache(const GURL& url, + void FetchFromCodeCache(blink::mojom::CodeCacheType cache_type, + const GURL& url, FetchCodeCacheCallback callback) override; private: - void FetchFromCodeCacheImpl(const GURL& url, + void FetchFromCodeCacheImpl(blink::mojom::CodeCacheType cache_type, + const GURL& url, FetchCodeCacheCallback callback, base::WaitableEvent* event); diff --git a/chromium/content/renderer/loader/request_extra_data.h b/chromium/content/renderer/loader/request_extra_data.h index 2239ee9443d..caafb0083c8 100644 --- a/chromium/content/renderer/loader/request_extra_data.h +++ b/chromium/content/renderer/loader/request_extra_data.h @@ -73,12 +73,6 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData { void set_custom_user_agent(const blink::WebString& custom_user_agent) { custom_user_agent_ = custom_user_agent; } - const blink::WebString& requested_with() const { - return requested_with_; - } - void set_requested_with(const blink::WebString& requested_with) { - requested_with_ = requested_with; - } // PlzNavigate: |navigation_response_override| is used to override certain // parameters of navigation requests. @@ -173,7 +167,6 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData { int service_worker_provider_id_; bool originated_from_service_worker_; blink::WebString custom_user_agent_; - blink::WebString requested_with_; std::unique_ptr<NavigationResponseOverrideParameters> navigation_response_override_; // TODO(arthursonzogni): Move most of the |navigation_response_override_| diff --git a/chromium/content/renderer/loader/resource_dispatcher.cc b/chromium/content/renderer/loader/resource_dispatcher.cc index f07e67896b5..dd7f440dd97 100644 --- a/chromium/content/renderer/loader/resource_dispatcher.cc +++ b/chromium/content/renderer/loader/resource_dispatcher.cc @@ -196,6 +196,26 @@ void NotifyResourceTransferSizeUpdate( render_frame->DidReceiveTransferSizeUpdate(request_id, transfer_size_diff); } +#if defined(OS_ANDROID) +void NotifyUpdateUserGestureCarryoverInfo(int render_frame_id) { + scoped_refptr<base::SingleThreadTaskRunner> task_runner = + RenderThreadImpl::DeprecatedGetMainTaskRunner(); + if (!task_runner->BelongsToCurrentThread()) { + task_runner->PostTask( + FROM_HERE, + base::BindOnce(NotifyUpdateUserGestureCarryoverInfo, render_frame_id)); + return; + } + + RenderFrameImpl* render_frame = + RenderFrameImpl::FromRoutingID(render_frame_id); + if (!render_frame) + return; + + render_frame->GetFrameHost()->UpdateUserGestureCarryoverInfo(); +} +#endif + // Returns true if the headers indicate that this resource should always be // revalidated or not cached. bool AlwaysAccessNetwork( @@ -261,7 +281,7 @@ ResourceDispatcher::~ResourceDispatcher() { ResourceDispatcher::PendingRequestInfo* ResourceDispatcher::GetPendingRequestInfo(int request_id) { - PendingRequestMap::iterator it = pending_requests_.find(request_id); + auto it = pending_requests_.find(request_id); if (it == pending_requests_.end()) return nullptr; return it->second.get(); @@ -495,6 +515,7 @@ void ResourceDispatcher::OnRequestComplete( } network::URLLoaderCompletionStatus renderer_status(status); + // TODO(toyoshim): Consider to convert status.cors_preflight_timing_info here. if (status.completion_time.is_null()) { // No completion timestamp is provided, leave it as is. } else if (request_info->remote_request_start.is_null() || @@ -528,7 +549,7 @@ void ResourceDispatcher::OnRequestComplete( bool ResourceDispatcher::RemovePendingRequest( int request_id, scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - PendingRequestMap::iterator it = pending_requests_.find(request_id); + auto it = pending_requests_.find(request_id); if (it == pending_requests_.end()) return false; @@ -559,7 +580,7 @@ bool ResourceDispatcher::RemovePendingRequest( void ResourceDispatcher::Cancel( int request_id, scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - PendingRequestMap::iterator it = pending_requests_.find(request_id); + auto it = pending_requests_.find(request_id); if (it == pending_requests_.end()) { DLOG(ERROR) << "unknown request"; return; @@ -716,6 +737,13 @@ int ResourceDispatcher::StartAsync( base::OnceClosure* continue_navigation_function) { CheckSchemeForReferrerPolicy(*request); +#if defined(OS_ANDROID) + if (request->resource_type != RESOURCE_TYPE_MAIN_FRAME && + request->has_user_gesture) { + NotifyUpdateUserGestureCarryoverInfo(request->render_frame_id); + } +#endif + bool override_url_loader = !!response_override_params && !!response_override_params->url_loader_client_endpoints; @@ -735,10 +763,23 @@ int ResourceDispatcher::StartAsync( request_id, this, loading_task_runner, true /* bypass_redirect_checks */, request->url); - DCHECK(continue_navigation_function); - *continue_navigation_function = - base::BindOnce(&ResourceDispatcher::ContinueForNavigation, - weak_factory_.GetWeakPtr(), request_id); + if (request->resource_type == RESOURCE_TYPE_SHARED_WORKER) { + // For shared workers, immediately post a task for continuing loading + // because shared workers don't have the concept of the navigation commit + // and |continue_navigation_function| is never called. + // TODO(nhiroki): Unify this case with the navigation case for code + // health. + loading_task_runner->PostTask( + FROM_HERE, base::BindOnce(&ResourceDispatcher::ContinueForNavigation, + weak_factory_.GetWeakPtr(), request_id)); + } else { + // For navigations, |continue_navigation_function| is called after the + // navigation commit. + DCHECK(continue_navigation_function); + *continue_navigation_function = + base::BindOnce(&ResourceDispatcher::ContinueForNavigation, + weak_factory_.GetWeakPtr(), request_id); + } return request_id; } @@ -752,7 +793,8 @@ int ResourceDispatcher::StartAsync( uint32_t options = network::mojom::kURLLoadOptionNone; // TODO(jam): use this flag for ResourceDispatcherHost code path once // MojoLoading is the only IPC code path. - if (request->fetch_request_context_type != REQUEST_CONTEXT_TYPE_FETCH) { + if (request->fetch_request_context_type != + static_cast<int>(blink::mojom::RequestContextType::FETCH)) { // MIME sniffing should be disabled for a request initiated by fetch(). options |= network::mojom::kURLLoadOptionSniffMimeType; if (blink::ServiceWorkerUtils::IsServicificationEnabled()) diff --git a/chromium/content/renderer/loader/resource_dispatcher_unittest.cc b/chromium/content/renderer/loader/resource_dispatcher_unittest.cc index 186292fb0ba..a129c4d568b 100644 --- a/chromium/content/renderer/loader/resource_dispatcher_unittest.cc +++ b/chromium/content/renderer/loader/resource_dispatcher_unittest.cc @@ -15,10 +15,10 @@ #include "base/macros.h" #include "base/memory/shared_memory.h" -#include "base/message_loop/message_loop.h" #include "base/process/process_handle.h" #include "base/run_loop.h" #include "base/test/scoped_feature_list.h" +#include "base/test/scoped_task_environment.h" #include "content/common/appcache_interfaces.h" #include "content/public/common/content_features.h" #include "content/public/renderer/fixed_received_data.h" @@ -130,7 +130,7 @@ class ResourceDispatcherTest : public testing::Test, std::vector<std::pair<network::mojom::URLLoaderRequest, network::mojom::URLLoaderClientPtr>> loader_and_clients_; - base::MessageLoop message_loop_; + base::test::ScopedTaskEnvironment task_environment_; std::unique_ptr<ResourceDispatcher> dispatcher_; }; diff --git a/chromium/content/renderer/loader/shared_memory_data_consumer_handle_unittest.cc b/chromium/content/renderer/loader/shared_memory_data_consumer_handle_unittest.cc index 777deb6c681..77f7542b151 100644 --- a/chromium/content/renderer/loader/shared_memory_data_consumer_handle_unittest.cc +++ b/chromium/content/renderer/loader/shared_memory_data_consumer_handle_unittest.cc @@ -15,11 +15,11 @@ #include "base/callback.h" #include "base/location.h" #include "base/macros.h" -#include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" #include "base/strings/string_split.h" #include "base/task_runner.h" +#include "base/test/scoped_task_environment.h" #include "base/threading/thread.h" #include "base/threading/thread_task_runner_handle.h" #include "content/public/renderer/fixed_received_data.h" @@ -129,11 +129,12 @@ class ThreadedSharedMemoryDataConsumerHandleTest : public ::testing::Test { class ReadDataOperation final { public: typedef WebDataConsumerHandle::Result Result; - ReadDataOperation(std::unique_ptr<SharedMemoryDataConsumerHandle> handle, - base::MessageLoop* main_message_loop, - const base::Closure& on_done) + ReadDataOperation( + std::unique_ptr<SharedMemoryDataConsumerHandle> handle, + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, + const base::Closure& on_done) : handle_(std::move(handle)), - main_message_loop_(main_message_loop), + main_thread_task_runner_(main_thread_task_runner), on_done_(on_done) {} const std::string& result() const { return result_; } @@ -169,14 +170,14 @@ class ThreadedSharedMemoryDataConsumerHandleTest : public ::testing::Test { // The operation is done. reader_.reset(); - main_message_loop_->task_runner()->PostTask(FROM_HERE, on_done_); + main_thread_task_runner_->PostTask(FROM_HERE, on_done_); } private: std::unique_ptr<SharedMemoryDataConsumerHandle> handle_; std::unique_ptr<WebDataConsumerHandle::Reader> reader_; std::unique_ptr<WebDataConsumerHandle::Client> client_; - base::MessageLoop* main_message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; base::Closure on_done_; std::string result_; }; @@ -189,7 +190,7 @@ class ThreadedSharedMemoryDataConsumerHandleTest : public ::testing::Test { StrictMock<MockClient> client_; std::unique_ptr<SharedMemoryDataConsumerHandle> handle_; std::unique_ptr<Writer> writer_; - base::MessageLoop loop_; + base::test::ScopedTaskEnvironment task_environment_; }; class SharedMemoryDataConsumerHandleTest @@ -205,7 +206,7 @@ class SharedMemoryDataConsumerHandleTest StrictMock<MockClient> client_; std::unique_ptr<SharedMemoryDataConsumerHandle> handle_; std::unique_ptr<Writer> writer_; - base::MessageLoop loop_; + base::test::ScopedTaskEnvironment task_environment_; }; void RunPostedTasks() { @@ -923,7 +924,7 @@ TEST_P(SharedMemoryDataConsumerHandleTest, RecursiveErrorNotification) { } TEST(SharedMemoryDataConsumerHandleBackpressureTest, Read) { - base::MessageLoop loop; + base::test::ScopedTaskEnvironment task_environment; char buffer[20]; Result result; size_t size; @@ -969,7 +970,7 @@ TEST(SharedMemoryDataConsumerHandleBackpressureTest, Read) { } TEST(SharedMemoryDataConsumerHandleBackpressureTest, CloseAndReset) { - base::MessageLoop loop; + base::test::ScopedTaskEnvironment task_environment; char buffer[20]; Result result; size_t size; @@ -1017,7 +1018,7 @@ TEST(SharedMemoryDataConsumerHandleBackpressureTest, CloseAndReset) { } TEST(SharedMemoryDataConsumerHandleWithoutBackpressureTest, AddData) { - base::MessageLoop loop; + base::test::ScopedTaskEnvironment task_environment; std::unique_ptr<Writer> writer; auto handle = std::make_unique<SharedMemoryDataConsumerHandle>( kDoNotApplyBackpressure, &writer); @@ -1043,7 +1044,8 @@ TEST(SharedMemoryDataConsumerHandleWithoutBackpressureTest, AddData) { TEST_F(ThreadedSharedMemoryDataConsumerHandleTest, Read) { base::RunLoop run_loop; auto operation = std::make_unique<ReadDataOperation>( - std::move(handle_), &loop_, run_loop.QuitClosure()); + std::move(handle_), base::ThreadTaskRunnerHandle::Get(), + run_loop.QuitClosure()); scoped_refptr<Logger> logger(new Logger); base::Thread t("DataConsumerHandle test thread"); diff --git a/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.cc b/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.cc index 22997f9d413..243eb38d8fa 100644 --- a/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.cc +++ b/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.cc @@ -4,6 +4,8 @@ #include "content/renderer/loader/tracked_child_url_loader_factory_bundle.h" +#include <utility> + #include "content/public/renderer/render_thread.h" namespace content { @@ -13,15 +15,19 @@ TrackedChildURLLoaderFactoryBundleInfo:: TrackedChildURLLoaderFactoryBundleInfo::TrackedChildURLLoaderFactoryBundleInfo( network::mojom::URLLoaderFactoryPtrInfo default_factory_info, - std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> - factories_info, + SchemeMap scheme_specific_factory_infos, + OriginMap initiator_specific_factory_infos, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, + network::mojom::URLLoaderFactoryPtrInfo prefetch_loader_factory_info, std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle, bool bypass_redirect_checks) - : ChildURLLoaderFactoryBundleInfo(std::move(default_factory_info), - std::move(factories_info), - std::move(direct_network_factory_info), - bypass_redirect_checks), + : ChildURLLoaderFactoryBundleInfo( + std::move(default_factory_info), + std::move(scheme_specific_factory_infos), + std::move(initiator_specific_factory_infos), + std::move(direct_network_factory_info), + std::move(prefetch_loader_factory_info), + bypass_redirect_checks), main_thread_host_bundle_(std::move(main_thread_host_bundle)) {} TrackedChildURLLoaderFactoryBundleInfo:: @@ -31,8 +37,13 @@ scoped_refptr<network::SharedURLLoaderFactory> TrackedChildURLLoaderFactoryBundleInfo::CreateFactory() { auto other = std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>(); other->default_factory_info_ = std::move(default_factory_info_); - other->factories_info_ = std::move(factories_info_); + other->scheme_specific_factory_infos_ = + std::move(scheme_specific_factory_infos_); + other->initiator_specific_factory_infos_ = + std::move(initiator_specific_factory_infos_); other->direct_network_factory_info_ = std::move(direct_network_factory_info_); + other->prefetch_loader_factory_info_ = + std::move(prefetch_loader_factory_info_); other->main_thread_host_bundle_ = std::move(main_thread_host_bundle_); other->bypass_redirect_checks_ = bypass_redirect_checks_; @@ -52,7 +63,7 @@ TrackedChildURLLoaderFactoryBundle::TrackedChildURLLoaderFactoryBundle( TrackedChildURLLoaderFactoryBundle::~TrackedChildURLLoaderFactoryBundle() { RemoveObserverOnMainThread(); -}; +} std::unique_ptr<network::SharedURLLoaderFactoryInfo> TrackedChildURLLoaderFactoryBundle::Clone() { @@ -66,16 +77,17 @@ TrackedChildURLLoaderFactoryBundle::Clone() { return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>( std::move(info->default_factory_info()), - std::move(info->factories_info()), + std::move(info->scheme_specific_factory_infos()), + std::move(info->initiator_specific_factory_infos()), std::move(info->direct_network_factory_info()), + std::move(info->prefetch_loader_factory_info()), std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks()); } void TrackedChildURLLoaderFactoryBundle::AddObserverOnMainThread() { DCHECK(main_thread_host_bundle_); - // TODO(chongz): Change this to a DCHECK once all call sites have a - // SequencedTaskRunnerHandle. + // Required by |SequencedTaskRunnerHandle::Get()| below. if (!base::SequencedTaskRunnerHandle::IsSet()) return; @@ -129,8 +141,10 @@ HostChildURLLoaderFactoryBundle::Clone() { return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>( std::move(info->default_factory_info()), - std::move(info->factories_info()), + std::move(info->scheme_specific_factory_infos()), + std::move(info->initiator_specific_factory_infos()), std::move(info->direct_network_factory_info()), + std::move(info->prefetch_loader_factory_info()), std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks()); } @@ -146,8 +160,10 @@ HostChildURLLoaderFactoryBundle::CloneWithoutDefaultFactory() { return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>( std::move(info->default_factory_info()), - std::move(info->factories_info()), + std::move(info->scheme_specific_factory_infos()), + std::move(info->initiator_specific_factory_infos()), std::move(info->direct_network_factory_info()), + std::move(info->prefetch_loader_factory_info()), std::move(main_thread_host_bundle_clone), info->bypass_redirect_checks()); } diff --git a/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.h b/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.h index 0b183ec2180..1322ee93925 100644 --- a/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.h +++ b/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.h @@ -5,6 +5,10 @@ #ifndef CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ #define CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_ +#include <memory> +#include <unordered_map> +#include <utility> + #include "base/sequenced_task_runner.h" #include "content/common/content_export.h" #include "content/renderer/loader/child_url_loader_factory_bundle.h" @@ -25,9 +29,10 @@ class CONTENT_EXPORT TrackedChildURLLoaderFactoryBundleInfo TrackedChildURLLoaderFactoryBundleInfo(); TrackedChildURLLoaderFactoryBundleInfo( network::mojom::URLLoaderFactoryPtrInfo default_factory_info, - std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo> - factories_info, + SchemeMap scheme_specific_factory_infos, + OriginMap initiator_specific_factory_infos, PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info, + network::mojom::URLLoaderFactoryPtrInfo prefetch_loader_factory_info, std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle, bool bypass_redirect_checks); ~TrackedChildURLLoaderFactoryBundleInfo() override; @@ -120,8 +125,8 @@ class CONTENT_EXPORT HostChildURLLoaderFactoryBundle bool IsHostChildURLLoaderFactoryBundle() const override; // Update this bundle with |info|, and post cloned |info| to tracked bundles. - // TODO(chongz): We should also update |direct_network_factory_| together with - // the |URLLoaderFactoryBundleInfo| we got from browser. + // Note: We don't need to worry about |direct_network_factory_| since it's + // only used by |RendererBlinkPlatformImpl| and doesn't rely on this codepath. void UpdateThisAndAllClones(std::unique_ptr<URLLoaderFactoryBundleInfo> info); private: diff --git a/chromium/content/renderer/loader/url_loader_client_impl.cc b/chromium/content/renderer/loader/url_loader_client_impl.cc index bf813ff292a..f9d55782cdc 100644 --- a/chromium/content/renderer/loader/url_loader_client_impl.cc +++ b/chromium/content/renderer/loader/url_loader_client_impl.cc @@ -289,7 +289,7 @@ void URLLoaderClientImpl::OnReceiveCachedMetadata( } void URLLoaderClientImpl::OnTransferSizeUpdated(int32_t transfer_size_diff) { - if (is_deferred_) { + if (NeedsStoringMessage()) { accumulated_transfer_size_diff_during_deferred_ += transfer_size_diff; } else { resource_dispatcher_->OnTransferSizeUpdated(request_id_, @@ -311,7 +311,7 @@ void URLLoaderClientImpl::OnStartLoadingResponseBody( body_consumer_ = new URLResponseBodyConsumer( request_id_, resource_dispatcher_, std::move(body), task_runner_); - if (is_deferred_) { + if (NeedsStoringMessage()) { body_consumer_->SetDefersLoading(); return; } diff --git a/chromium/content/renderer/loader/url_loader_client_impl_unittest.cc b/chromium/content/renderer/loader/url_loader_client_impl_unittest.cc index 2fc2884de80..42a3691bad7 100644 --- a/chromium/content/renderer/loader/url_loader_client_impl_unittest.cc +++ b/chromium/content/renderer/loader/url_loader_client_impl_unittest.cc @@ -5,9 +5,8 @@ #include "content/renderer/loader/url_loader_client_impl.h" #include <vector> -#include "base/message_loop/message_loop.h" #include "base/run_loop.h" -#include "content/public/common/request_context_type.h" +#include "base/test/scoped_task_environment.h" #include "content/renderer/loader/navigation_response_override_parameters.h" #include "content/renderer/loader/resource_dispatcher.h" #include "content/renderer/loader/test_request_peer.h" @@ -18,6 +17,7 @@ #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" #include "services/network/public/mojom/url_loader_factory.mojom.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/public/platform/modules/fetch/fetch_api_request.mojom.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" namespace content { @@ -30,7 +30,8 @@ class URLLoaderClientImplTest : public ::testing::Test, // Set request context type to fetch so that ResourceDispatcher doesn't // install MimeSniffingThrottle, which makes URLLoaderThrottleLoader // defer the request. - request->fetch_request_context_type = REQUEST_CONTEXT_TYPE_FETCH; + request->fetch_request_context_type = + static_cast<int>(blink::mojom::RequestContextType::FETCH); request_id_ = dispatcher_->StartAsync( std::move(request), 0, blink::scheduler::GetSingleThreadTaskRunnerForTesting(), @@ -75,7 +76,7 @@ class URLLoaderClientImplTest : public ::testing::Test, return options; } - base::MessageLoop message_loop_; + base::test::ScopedTaskEnvironment task_environment_; std::unique_ptr<ResourceDispatcher> dispatcher_; TestRequestPeer::Context request_peer_context_; int request_id_ = 0; diff --git a/chromium/content/renderer/loader/url_response_body_consumer_unittest.cc b/chromium/content/renderer/loader/url_response_body_consumer_unittest.cc index fb32f809835..36b002badde 100644 --- a/chromium/content/renderer/loader/url_response_body_consumer_unittest.cc +++ b/chromium/content/renderer/loader/url_response_body_consumer_unittest.cc @@ -7,9 +7,9 @@ #include "base/bind.h" #include "base/callback_forward.h" #include "base/macros.h" -#include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" +#include "base/test/scoped_task_environment.h" #include "content/public/renderer/request_peer.h" #include "content/renderer/loader/navigation_response_override_parameters.h" #include "content/renderer/loader/request_extra_data.h" @@ -154,7 +154,8 @@ class URLResponseBodyConsumerTest : public ::testing::Test { blink::scheduler::GetSingleThreadTaskRunnerForTesting(), TRAFFIC_ANNOTATION_FOR_TESTS, false, false /* pass_response_pipe_to_peer */, - std::make_unique<TestRequestPeer>(context, message_loop_.task_runner()), + std::make_unique<TestRequestPeer>(context, + base::ThreadTaskRunnerHandle::Get()), base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( &factory_), std::vector<std::unique_ptr<URLLoaderThrottle>>(), @@ -168,7 +169,7 @@ class URLResponseBodyConsumerTest : public ::testing::Test { run_loop.Run(); } - base::MessageLoop message_loop_; + base::test::ScopedTaskEnvironment task_environment_; NoopURLLoaderFactory factory_; std::unique_ptr<ResourceDispatcher> dispatcher_; static const MojoWriteDataFlags kNone = MOJO_WRITE_DATA_FLAG_NONE; @@ -182,7 +183,7 @@ TEST_F(URLResponseBodyConsumerTest, ReceiveData) { scoped_refptr<URLResponseBodyConsumer> consumer(new URLResponseBodyConsumer( request_id, dispatcher_.get(), std::move(data_pipe.consumer_handle), - message_loop_.task_runner())); + base::ThreadTaskRunnerHandle::Get())); consumer->ArmOrNotify(); mojo::ScopedDataPipeProducerHandle writer = @@ -207,7 +208,7 @@ TEST_F(URLResponseBodyConsumerTest, OnCompleteThenClose) { scoped_refptr<URLResponseBodyConsumer> consumer(new URLResponseBodyConsumer( request_id, dispatcher_.get(), std::move(data_pipe.consumer_handle), - message_loop_.task_runner())); + base::ThreadTaskRunnerHandle::Get())); consumer->ArmOrNotify(); consumer->OnComplete(network::URLLoaderCompletionStatus()); @@ -242,7 +243,7 @@ TEST_F(URLResponseBodyConsumerTest, OnCompleteThenCloseWithAsyncRelease) { scoped_refptr<URLResponseBodyConsumer> consumer(new URLResponseBodyConsumer( request_id, dispatcher_.get(), std::move(data_pipe.consumer_handle), - message_loop_.task_runner())); + base::ThreadTaskRunnerHandle::Get())); consumer->ArmOrNotify(); consumer->OnComplete(network::URLLoaderCompletionStatus()); @@ -274,7 +275,7 @@ TEST_F(URLResponseBodyConsumerTest, CloseThenOnComplete) { scoped_refptr<URLResponseBodyConsumer> consumer(new URLResponseBodyConsumer( request_id, dispatcher_.get(), std::move(data_pipe.consumer_handle), - message_loop_.task_runner())); + base::ThreadTaskRunnerHandle::Get())); consumer->ArmOrNotify(); network::URLLoaderCompletionStatus status; @@ -317,7 +318,7 @@ TEST_F(URLResponseBodyConsumerTest, TooBigChunkShouldBeSplit) { scoped_refptr<URLResponseBodyConsumer> consumer(new URLResponseBodyConsumer( request_id, dispatcher_.get(), std::move(data_pipe.consumer_handle), - message_loop_.task_runner())); + base::ThreadTaskRunnerHandle::Get())); consumer->ArmOrNotify(); Run(&context); diff --git a/chromium/content/renderer/loader/web_data_consumer_handle_impl_unittest.cc b/chromium/content/renderer/loader/web_data_consumer_handle_impl_unittest.cc index 8e4f0a216a5..da0eb4f749e 100644 --- a/chromium/content/renderer/loader/web_data_consumer_handle_impl_unittest.cc +++ b/chromium/content/renderer/loader/web_data_consumer_handle_impl_unittest.cc @@ -14,10 +14,10 @@ #include "base/bind.h" #include "base/location.h" -#include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" +#include "base/test/scoped_task_environment.h" #include "base/threading/thread.h" #include "base/threading/thread_task_runner_handle.h" #include "mojo/public/cpp/system/data_pipe.h" @@ -62,11 +62,12 @@ class ClientImpl final : public WebDataConsumerHandle::Client { class ReadDataOperation : public ReadDataOperationBase { public: typedef WebDataConsumerHandle::Result Result; - ReadDataOperation(mojo::ScopedDataPipeConsumerHandle handle, - base::MessageLoop* main_message_loop, - const base::Closure& on_done) + ReadDataOperation( + mojo::ScopedDataPipeConsumerHandle handle, + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, + const base::Closure& on_done) : handle_(new WebDataConsumerHandleImpl(std::move(handle))), - main_message_loop_(main_message_loop), + main_thread_task_runner_(main_thread_task_runner), on_done_(on_done) {} const std::string& result() const { return result_; } @@ -107,14 +108,14 @@ class ReadDataOperation : public ReadDataOperationBase { // The operation is done. reader_.reset(); - main_message_loop_->task_runner()->PostTask(FROM_HERE, on_done_); + main_thread_task_runner_->PostTask(FROM_HERE, on_done_); } private: std::unique_ptr<WebDataConsumerHandleImpl> handle_; std::unique_ptr<WebDataConsumerHandle::Reader> reader_; std::unique_ptr<WebDataConsumerHandle::Client> client_; - base::MessageLoop* main_message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; base::Closure on_done_; std::string result_; }; @@ -122,11 +123,12 @@ class ReadDataOperation : public ReadDataOperationBase { class TwoPhaseReadDataOperation : public ReadDataOperationBase { public: typedef WebDataConsumerHandle::Result Result; - TwoPhaseReadDataOperation(mojo::ScopedDataPipeConsumerHandle handle, - base::MessageLoop* main_message_loop, - const base::Closure& on_done) + TwoPhaseReadDataOperation( + mojo::ScopedDataPipeConsumerHandle handle, + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, + const base::Closure& on_done) : handle_(new WebDataConsumerHandleImpl(std::move(handle))), - main_message_loop_(main_message_loop), + main_thread_task_runner_(main_thread_task_runner), on_done_(on_done) {} const std::string& result() const { return result_; } @@ -160,7 +162,7 @@ class TwoPhaseReadDataOperation : public ReadDataOperationBase { if (rv != kOk) { // Something is wrong. result_ = "error"; - main_message_loop_->task_runner()->PostTask(FROM_HERE, on_done_); + main_thread_task_runner_->PostTask(FROM_HERE, on_done_); return; } } @@ -177,14 +179,14 @@ class TwoPhaseReadDataOperation : public ReadDataOperationBase { // The operation is done. reader_.reset(); - main_message_loop_->task_runner()->PostTask(FROM_HERE, on_done_); + main_thread_task_runner_->PostTask(FROM_HERE, on_done_); } private: std::unique_ptr<WebDataConsumerHandleImpl> handle_; std::unique_ptr<WebDataConsumerHandle::Reader> reader_; std::unique_ptr<WebDataConsumerHandle::Client> client_; - base::MessageLoop* main_message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; base::Closure on_done_; std::string result_; }; @@ -236,7 +238,7 @@ class WebDataConsumerHandleImplTest : public ::testing::Test { return expected; } - base::MessageLoop message_loop_; + base::test::ScopedTaskEnvironment task_environment_; mojo::ScopedDataPipeProducerHandle producer_; mojo::ScopedDataPipeConsumerHandle consumer_; @@ -245,7 +247,8 @@ class WebDataConsumerHandleImplTest : public ::testing::Test { TEST_F(WebDataConsumerHandleImplTest, ReadData) { base::RunLoop run_loop; auto operation = std::make_unique<ReadDataOperation>( - std::move(consumer_), &message_loop_, run_loop.QuitClosure()); + std::move(consumer_), base::ThreadTaskRunnerHandle::Get(), + run_loop.QuitClosure()); base::Thread t("DataConsumerHandle test thread"); ASSERT_TRUE(t.Start()); @@ -266,7 +269,8 @@ TEST_F(WebDataConsumerHandleImplTest, ReadData) { TEST_F(WebDataConsumerHandleImplTest, TwoPhaseReadData) { base::RunLoop run_loop; auto operation = std::make_unique<TwoPhaseReadDataOperation>( - std::move(consumer_), &message_loop_, run_loop.QuitClosure()); + std::move(consumer_), base::ThreadTaskRunnerHandle::Get(), + run_loop.QuitClosure()); base::Thread t("DataConsumerHandle test thread"); ASSERT_TRUE(t.Start()); diff --git a/chromium/content/renderer/loader/web_url_loader_impl.cc b/chromium/content/renderer/loader/web_url_loader_impl.cc index 5d63b5a8728..2cc5fe42d5f 100644 --- a/chromium/content/renderer/loader/web_url_loader_impl.cc +++ b/chromium/content/renderer/loader/web_url_loader_impl.cc @@ -24,7 +24,6 @@ #include "base/time/time.h" #include "build/build_config.h" #include "content/child/child_thread_impl.h" -#include "content/child/scoped_child_process_reference.h" #include "content/common/service_worker/service_worker_types.h" #include "content/public/common/browser_side_navigation_policy.h" #include "content/public/common/content_features.h" @@ -102,18 +101,6 @@ constexpr char kImageAcceptHeader[] = "image/webp,image/apng,image/*,*/*;q=0.8"; using HeadersVector = network::HttpRawRequestResponseInfo::HeadersVector; -class KeepAliveHandleWithChildProcessReference { - public: - explicit KeepAliveHandleWithChildProcessReference( - mojom::KeepAliveHandlePtr ptr) - : keep_alive_handle_(std::move(ptr)) {} - ~KeepAliveHandleWithChildProcessReference() {} - - private: - mojom::KeepAliveHandlePtr keep_alive_handle_; - ScopedChildProcessReference reference_; -}; - // TODO(estark): Figure out a way for the embedder to provide the // security style for a resource. Ideally, the logic for assigning // per-resource security styles should live in the same place as the @@ -463,7 +450,7 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context> { scoped_refptr<base::SingleThreadTaskRunner> task_runner_; std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; - std::unique_ptr<KeepAliveHandleWithChildProcessReference> keep_alive_handle_; + mojom::KeepAliveHandlePtr keep_alive_handle_; enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; DeferState defers_loading_; int request_id_; @@ -542,11 +529,7 @@ WebURLLoaderImpl::Context::Context( resource_dispatcher_(resource_dispatcher), task_runner_handle_(std::move(task_runner_handle)), task_runner_(task_runner_handle_->GetTaskRunner()), - keep_alive_handle_( - keep_alive_handle_ptr - ? std::make_unique<KeepAliveHandleWithChildProcessReference>( - std::move(keep_alive_handle_ptr)) - : nullptr), + keep_alive_handle_(std::move(keep_alive_handle_ptr)), defers_loading_(NOT_DEFERRING), request_id_(-1), url_loader_factory_(std::move(url_loader_factory)) { @@ -661,10 +644,18 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, resource_request->url = url_; resource_request->site_for_cookies = request.SiteForCookies(); resource_request->upgrade_if_insecure = request.UpgradeIfInsecure(); - resource_request->request_initiator = - request.RequestorOrigin().IsNull() - ? base::Optional<url::Origin>() - : base::Optional<url::Origin>(request.RequestorOrigin()); + resource_request->is_revalidating = request.IsRevalidating(); + if (!request.RequestorOrigin().IsNull()) { + if (request.RequestorOrigin().ToString() == "null") { + // "file:" origin is treated like an opaque unique origin when + // allow-file-access-from-files is not specified. Such origin is not + // opaque (i.e., IsOpaque() returns false) but still serializes to + // "null". + resource_request->request_initiator = url::Origin(); + } else { + resource_request->request_initiator = request.RequestorOrigin(); + } + } resource_request->referrer = referrer_url; resource_request->referrer_policy = @@ -685,6 +676,8 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, resource_request->headers.SetHeaderIfMissing(network::kAcceptHeader, network::kDefaultAcceptHeader); } + resource_request->requested_with = + WebString(request.GetRequestedWith()).Utf8(); if (resource_request->resource_type == RESOURCE_TYPE_PREFETCH || resource_request->resource_type == RESOURCE_TYPE_FAVICON) { @@ -710,7 +703,7 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, resource_request->fetch_integrity = GetFetchIntegrityForWebURLRequest(request); resource_request->fetch_request_context_type = - GetRequestContextTypeForWebURLRequest(request); + static_cast<int>(GetRequestContextTypeForWebURLRequest(request)); resource_request->fetch_frame_type = request.GetFrameType(); resource_request->request_body = @@ -721,7 +714,7 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, resource_request->enable_upload_progress = request.ReportUploadProgress(); GURL gurl(url_); if (request.GetRequestContext() == - WebURLRequest::kRequestContextXMLHttpRequest && + blink::mojom::RequestContextType::XML_HTTP_REQUEST && (gurl.has_username() || gurl.has_password())) { resource_request->do_not_prompt_for_login = true; } @@ -732,13 +725,14 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, static_cast<int>(request.GetPreviewsState()); resource_request->throttling_profile_id = request.GetDevToolsToken(); + if (base::UnguessableToken window_id = request.GetFetchWindowId()) + resource_request->fetch_window_id = base::make_optional(window_id); + // The network request has already been made by the browser. The renderer // should bind the URLLoaderClientEndpoints stored in |response_override| to // an implementation of a URLLoaderClient to get the response body. if (response_override) { DCHECK(!sync_load_response); - DCHECK_NE(network::mojom::RequestContextFrameType::kNone, - request.GetFrameType()); } RequestExtraData empty_extra_data; @@ -987,7 +981,8 @@ void WebURLLoaderImpl::Context::OnCompletedRequest( } else { client_->DidFinishLoading(status.completion_time, total_transfer_size, encoded_body_size, status.decoded_body_length, - status.should_report_corb_blocking); + status.should_report_corb_blocking, + status.cors_preflight_timing_info); } } } @@ -1032,7 +1027,7 @@ bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally( // Data url requests from object tags may need to be intercepted as streams // and so need to be sent to the browser. - if (request.GetRequestContext() == WebURLRequest::kRequestContextObject) + if (request.GetRequestContext() == blink::mojom::RequestContextType::OBJECT) return false; // Optimize for the case where we can handle a data URL locally. We must @@ -1223,6 +1218,9 @@ void WebURLLoaderImpl::PopulateURLResponse( WebString::FromUTF8(info.alpn_negotiated_protocol)); response->SetConnectionInfo(info.connection_info); response->SetAsyncRevalidationRequested(info.async_revalidation_requested); + response->SetRequestId(request_id); + response->SetIsSignedExchangeInnerResponse( + info.is_signed_exchange_inner_response); SetSecurityStyleAndDetails(url, info, response, report_security_info); @@ -1233,7 +1231,6 @@ void WebURLLoaderImpl::PopulateURLResponse( extra_data->set_was_alternate_protocol_available( info.was_alternate_protocol_available); extra_data->set_effective_connection_type(info.effective_connection_type); - extra_data->set_request_id(request_id); // If there's no received headers end time, don't set load timing. This is // the case for non-HTTP requests, requests that don't go over the wire, and @@ -1260,20 +1257,17 @@ void WebURLLoaderImpl::PopulateURLResponse( info.raw_request_response_info->response_headers_text)); const HeadersVector& request_headers = info.raw_request_response_info->request_headers; - for (HeadersVector::const_iterator it = request_headers.begin(); - it != request_headers.end(); ++it) { + for (auto it = request_headers.begin(); it != request_headers.end(); ++it) { load_info.AddRequestHeader(WebString::FromLatin1(it->first), WebString::FromLatin1(it->second)); } const HeadersVector& response_headers = info.raw_request_response_info->response_headers; - for (HeadersVector::const_iterator it = response_headers.begin(); - it != response_headers.end(); ++it) { + for (auto it = response_headers.begin(); it != response_headers.end(); + ++it) { load_info.AddResponseHeader(WebString::FromLatin1(it->first), WebString::FromLatin1(it->second)); } - load_info.SetNPNNegotiatedProtocol( - WebString::FromLatin1(info.alpn_negotiated_protocol)); response->SetHTTPLoadInfo(load_info); } @@ -1388,36 +1382,36 @@ net::NetworkTrafficAnnotationTag WebURLLoaderImpl::Context::GetTrafficAnnotationTag( const blink::WebURLRequest& request) { switch (request.GetRequestContext()) { - case WebURLRequest::kRequestContextUnspecified: - case WebURLRequest::kRequestContextAudio: - case WebURLRequest::kRequestContextBeacon: - case WebURLRequest::kRequestContextCSPReport: - case WebURLRequest::kRequestContextDownload: - case WebURLRequest::kRequestContextEventSource: - case WebURLRequest::kRequestContextFetch: - case WebURLRequest::kRequestContextFont: - case WebURLRequest::kRequestContextForm: - case WebURLRequest::kRequestContextFrame: - case WebURLRequest::kRequestContextHyperlink: - case WebURLRequest::kRequestContextIframe: - case WebURLRequest::kRequestContextImage: - case WebURLRequest::kRequestContextImageSet: - case WebURLRequest::kRequestContextImport: - case WebURLRequest::kRequestContextInternal: - case WebURLRequest::kRequestContextLocation: - case WebURLRequest::kRequestContextManifest: - case WebURLRequest::kRequestContextPing: - case WebURLRequest::kRequestContextPrefetch: - case WebURLRequest::kRequestContextScript: - case WebURLRequest::kRequestContextServiceWorker: - case WebURLRequest::kRequestContextSharedWorker: - case WebURLRequest::kRequestContextSubresource: - case WebURLRequest::kRequestContextStyle: - case WebURLRequest::kRequestContextTrack: - case WebURLRequest::kRequestContextVideo: - case WebURLRequest::kRequestContextWorker: - case WebURLRequest::kRequestContextXMLHttpRequest: - case WebURLRequest::kRequestContextXSLT: + case blink::mojom::RequestContextType::UNSPECIFIED: + case blink::mojom::RequestContextType::AUDIO: + case blink::mojom::RequestContextType::BEACON: + case blink::mojom::RequestContextType::CSP_REPORT: + case blink::mojom::RequestContextType::DOWNLOAD: + case blink::mojom::RequestContextType::EVENT_SOURCE: + case blink::mojom::RequestContextType::FETCH: + case blink::mojom::RequestContextType::FONT: + case blink::mojom::RequestContextType::FORM: + case blink::mojom::RequestContextType::FRAME: + case blink::mojom::RequestContextType::HYPERLINK: + case blink::mojom::RequestContextType::IFRAME: + case blink::mojom::RequestContextType::IMAGE: + case blink::mojom::RequestContextType::IMAGE_SET: + case blink::mojom::RequestContextType::IMPORT: + case blink::mojom::RequestContextType::INTERNAL: + case blink::mojom::RequestContextType::LOCATION: + case blink::mojom::RequestContextType::MANIFEST: + case blink::mojom::RequestContextType::PING: + case blink::mojom::RequestContextType::PREFETCH: + case blink::mojom::RequestContextType::SCRIPT: + case blink::mojom::RequestContextType::SERVICE_WORKER: + case blink::mojom::RequestContextType::SHARED_WORKER: + case blink::mojom::RequestContextType::SUBRESOURCE: + case blink::mojom::RequestContextType::STYLE: + case blink::mojom::RequestContextType::TRACK: + case blink::mojom::RequestContextType::VIDEO: + case blink::mojom::RequestContextType::WORKER: + case blink::mojom::RequestContextType::XML_HTTP_REQUEST: + case blink::mojom::RequestContextType::XSLT: return net::DefineNetworkTrafficAnnotation("blink_resource_loader", R"( semantics { sender: "Blink Resource Loader" @@ -1439,9 +1433,9 @@ WebURLLoaderImpl::Context::GetTrafficAnnotationTag( "to load any webpage." })"); - case WebURLRequest::kRequestContextEmbed: - case WebURLRequest::kRequestContextObject: - case WebURLRequest::kRequestContextPlugin: + case blink::mojom::RequestContextType::EMBED: + case blink::mojom::RequestContextType::OBJECT: + case blink::mojom::RequestContextType::PLUGIN: return net::DefineNetworkTrafficAnnotation( "blink_extension_resource_loader", R"( semantics { @@ -1470,7 +1464,7 @@ WebURLLoaderImpl::Context::GetTrafficAnnotationTag( } })"); - case WebURLRequest::kRequestContextFavicon: + case blink::mojom::RequestContextType::FAVICON: return net::DefineNetworkTrafficAnnotation("favicon_loader", R"( semantics { sender: "Blink Resource Loader" diff --git a/chromium/content/renderer/loader/web_url_loader_impl_unittest.cc b/chromium/content/renderer/loader/web_url_loader_impl_unittest.cc index 282e275354b..d9a336e1c2d 100644 --- a/chromium/content/renderer/loader/web_url_loader_impl_unittest.cc +++ b/chromium/content/renderer/loader/web_url_loader_impl_unittest.cc @@ -13,9 +13,9 @@ #include "base/command_line.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" +#include "base/test/scoped_task_environment.h" #include "base/time/default_tick_clock.h" #include "base/time/time.h" #include "content/public/common/content_switches.h" @@ -240,11 +240,13 @@ class TestWebURLLoaderClient : public blink::WebURLLoaderClient { loader_.reset(); } - void DidFinishLoading(base::TimeTicks finishTime, - int64_t totalEncodedDataLength, - int64_t totalEncodedBodyLength, - int64_t totalDecodedBodyLength, - bool should_report_corb_blocking) override { + void DidFinishLoading( + base::TimeTicks finishTime, + int64_t totalEncodedDataLength, + int64_t totalEncodedBodyLength, + int64_t totalDecodedBodyLength, + bool should_report_corb_blocking, + const std::vector<network::cors::PreflightTimingInfo>&) override { EXPECT_TRUE(loader_); EXPECT_TRUE(did_receive_response_); EXPECT_FALSE(did_finish_); @@ -314,7 +316,7 @@ class WebURLLoaderImplTest : public testing::Test { void DoStartAsyncRequest() { blink::WebURLRequest request{GURL(kTestURL)}; - request.SetRequestContext(blink::WebURLRequest::kRequestContextInternal); + request.SetRequestContext(blink::mojom::RequestContextType::INTERNAL); client()->loader()->LoadAsynchronously(request, client()); ASSERT_TRUE(peer()); } @@ -322,7 +324,7 @@ class WebURLLoaderImplTest : public testing::Test { void DoStartAsyncRequestWithPriority( blink::WebURLRequest::Priority priority) { blink::WebURLRequest request{GURL(kTestURL)}; - request.SetRequestContext(blink::WebURLRequest::kRequestContextInternal); + request.SetRequestContext(blink::mojom::RequestContextType::INTERNAL); request.SetPriority(priority); client()->loader()->LoadAsynchronously(request, client()); ASSERT_TRUE(peer()); @@ -408,10 +410,9 @@ class WebURLLoaderImplTest : public testing::Test { TestWebURLLoaderClient* client() { return client_.get(); } TestResourceDispatcher* dispatcher() { return &dispatcher_; } RequestPeer* peer() { return dispatcher()->peer(); } - base::MessageLoop* message_loop() { return &message_loop_; } private: - base::MessageLoop message_loop_; + base::test::ScopedTaskEnvironment task_environment_; TestResourceDispatcher dispatcher_; std::unique_ptr<TestWebURLLoaderClient> client_; }; @@ -640,7 +641,7 @@ TEST_F(WebURLLoaderImplTest, BrowserSideNavigationCommit) { const std::string kMimeType = "text/html"; blink::WebURLRequest request(kNavigationURL); request.SetFrameType(network::mojom::RequestContextFrameType::kTopLevel); - request.SetRequestContext(blink::WebURLRequest::kRequestContextFrame); + request.SetRequestContext(blink::mojom::RequestContextType::FRAME); std::unique_ptr<NavigationResponseOverrideParameters> response_override( new NavigationResponseOverrideParameters()); response_override->response.mime_type = kMimeType; @@ -778,7 +779,7 @@ TEST_F(WebURLLoaderImplTest, SyncLengths) { const int kEncodedDataLength = 130; const GURL url(kTestURL); blink::WebURLRequest request(url); - request.SetRequestContext(blink::WebURLRequest::kRequestContextInternal); + request.SetRequestContext(blink::mojom::RequestContextType::INTERNAL); // Prepare a mock response SyncLoadResponse sync_load_response; diff --git a/chromium/content/renderer/loader/web_url_request_util.cc b/chromium/content/renderer/loader/web_url_request_util.cc index a7c47640c90..6197434ad49 100644 --- a/chromium/content/renderer/loader/web_url_request_util.cc +++ b/chromium/content/renderer/loader/web_url_request_util.cc @@ -27,14 +27,13 @@ #include "third_party/blink/public/mojom/blob/blob_registry.mojom.h" #include "third_party/blink/public/platform/file_path_conversion.h" #include "third_party/blink/public/platform/interface_provider.h" -#include "third_party/blink/public/platform/modules/fetch/fetch_api_request.mojom-shared.h" +#include "third_party/blink/public/platform/modules/fetch/fetch_api_request.mojom.h" #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/web_data.h" #include "third_party/blink/public/platform/web_http_body.h" #include "third_party/blink/public/platform/web_http_header_visitor.h" #include "third_party/blink/public/platform/web_mixed_content.h" #include "third_party/blink/public/platform/web_string.h" -#include "third_party/blink/public/platform/web_thread.h" using blink::mojom::FetchCacheMode; using blink::WebData; @@ -109,95 +108,95 @@ class HeaderFlattener : public blink::WebHTTPHeaderVisitor { } // namespace -ResourceType WebURLRequestContextToResourceType( - WebURLRequest::RequestContext request_context) { +ResourceType RequestContextToResourceType( + blink::mojom::RequestContextType request_context) { switch (request_context) { // CSP report - case WebURLRequest::kRequestContextCSPReport: + case blink::mojom::RequestContextType::CSP_REPORT: return RESOURCE_TYPE_CSP_REPORT; // Favicon - case WebURLRequest::kRequestContextFavicon: + case blink::mojom::RequestContextType::FAVICON: return RESOURCE_TYPE_FAVICON; // Font - case WebURLRequest::kRequestContextFont: + case blink::mojom::RequestContextType::FONT: return RESOURCE_TYPE_FONT_RESOURCE; // Image - case WebURLRequest::kRequestContextImage: - case WebURLRequest::kRequestContextImageSet: + case blink::mojom::RequestContextType::IMAGE: + case blink::mojom::RequestContextType::IMAGE_SET: return RESOURCE_TYPE_IMAGE; // Media - case WebURLRequest::kRequestContextAudio: - case WebURLRequest::kRequestContextVideo: + case blink::mojom::RequestContextType::AUDIO: + case blink::mojom::RequestContextType::VIDEO: return RESOURCE_TYPE_MEDIA; // Object - case WebURLRequest::kRequestContextEmbed: - case WebURLRequest::kRequestContextObject: + case blink::mojom::RequestContextType::EMBED: + case blink::mojom::RequestContextType::OBJECT: return RESOURCE_TYPE_OBJECT; // Ping - case WebURLRequest::kRequestContextBeacon: - case WebURLRequest::kRequestContextPing: + case blink::mojom::RequestContextType::BEACON: + case blink::mojom::RequestContextType::PING: return RESOURCE_TYPE_PING; // Subresource of plugins - case WebURLRequest::kRequestContextPlugin: + case blink::mojom::RequestContextType::PLUGIN: return RESOURCE_TYPE_PLUGIN_RESOURCE; // Prefetch - case WebURLRequest::kRequestContextPrefetch: + case blink::mojom::RequestContextType::PREFETCH: return RESOURCE_TYPE_PREFETCH; // Script - case WebURLRequest::kRequestContextImport: - case WebURLRequest::kRequestContextScript: + case blink::mojom::RequestContextType::IMPORT: + case blink::mojom::RequestContextType::SCRIPT: return RESOURCE_TYPE_SCRIPT; // Style - case WebURLRequest::kRequestContextXSLT: - case WebURLRequest::kRequestContextStyle: + case blink::mojom::RequestContextType::XSLT: + case blink::mojom::RequestContextType::STYLE: return RESOURCE_TYPE_STYLESHEET; // Subresource - case WebURLRequest::kRequestContextDownload: - case WebURLRequest::kRequestContextManifest: - case WebURLRequest::kRequestContextSubresource: + case blink::mojom::RequestContextType::DOWNLOAD: + case blink::mojom::RequestContextType::MANIFEST: + case blink::mojom::RequestContextType::SUBRESOURCE: return RESOURCE_TYPE_SUB_RESOURCE; // TextTrack - case WebURLRequest::kRequestContextTrack: + case blink::mojom::RequestContextType::TRACK: return RESOURCE_TYPE_MEDIA; // Workers - case WebURLRequest::kRequestContextServiceWorker: + case blink::mojom::RequestContextType::SERVICE_WORKER: return RESOURCE_TYPE_SERVICE_WORKER; - case WebURLRequest::kRequestContextSharedWorker: + case blink::mojom::RequestContextType::SHARED_WORKER: return RESOURCE_TYPE_SHARED_WORKER; - case WebURLRequest::kRequestContextWorker: + case blink::mojom::RequestContextType::WORKER: return RESOURCE_TYPE_WORKER; // Unspecified - case WebURLRequest::kRequestContextInternal: - case WebURLRequest::kRequestContextUnspecified: + case blink::mojom::RequestContextType::INTERNAL: + case blink::mojom::RequestContextType::UNSPECIFIED: return RESOURCE_TYPE_SUB_RESOURCE; // XHR - case WebURLRequest::kRequestContextEventSource: - case WebURLRequest::kRequestContextFetch: - case WebURLRequest::kRequestContextXMLHttpRequest: + case blink::mojom::RequestContextType::EVENT_SOURCE: + case blink::mojom::RequestContextType::FETCH: + case blink::mojom::RequestContextType::XML_HTTP_REQUEST: return RESOURCE_TYPE_XHR; // These should be handled by the FrameType checks at the top of the // function. - case WebURLRequest::kRequestContextForm: - case WebURLRequest::kRequestContextHyperlink: - case WebURLRequest::kRequestContextLocation: - case WebURLRequest::kRequestContextFrame: - case WebURLRequest::kRequestContextIframe: + case blink::mojom::RequestContextType::FORM: + case blink::mojom::RequestContextType::HYPERLINK: + case blink::mojom::RequestContextType::LOCATION: + case blink::mojom::RequestContextType::FRAME: + case blink::mojom::RequestContextType::IFRAME: NOTREACHED(); return RESOURCE_TYPE_SUB_RESOURCE; @@ -208,15 +207,16 @@ ResourceType WebURLRequestContextToResourceType( } ResourceType WebURLRequestToResourceType(const WebURLRequest& request) { - WebURLRequest::RequestContext request_context = request.GetRequestContext(); + blink::mojom::RequestContextType request_context = + request.GetRequestContext(); if (request.GetFrameType() != network::mojom::RequestContextFrameType::kNone) { - DCHECK(request_context == WebURLRequest::kRequestContextForm || - request_context == WebURLRequest::kRequestContextFrame || - request_context == WebURLRequest::kRequestContextHyperlink || - request_context == WebURLRequest::kRequestContextIframe || - request_context == WebURLRequest::kRequestContextInternal || - request_context == WebURLRequest::kRequestContextLocation); + DCHECK(request_context == blink::mojom::RequestContextType::FORM || + request_context == blink::mojom::RequestContextType::FRAME || + request_context == blink::mojom::RequestContextType::HYPERLINK || + request_context == blink::mojom::RequestContextType::IFRAME || + request_context == blink::mojom::RequestContextType::INTERNAL || + request_context == blink::mojom::RequestContextType::LOCATION); if (request.GetFrameType() == network::mojom::RequestContextFrameType::kTopLevel || request.GetFrameType() == @@ -229,7 +229,7 @@ ResourceType WebURLRequestToResourceType(const WebURLRequest& request) { NOTREACHED(); return RESOURCE_TYPE_SUB_RESOURCE; } - return WebURLRequestContextToResourceType(request_context); + return RequestContextToResourceType(request_context); } net::HttpRequestHeaders GetWebURLRequestHeaders( @@ -283,7 +283,7 @@ int GetLoadFlagsForWebURLRequest(const WebURLRequest& request) { load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; } - if (request.GetRequestContext() == WebURLRequest::kRequestContextPrefetch) + if (request.GetRequestContext() == blink::mojom::RequestContextType::PREFETCH) load_flags |= net::LOAD_PREFETCH; if (request.GetExtraData()) { @@ -456,78 +456,10 @@ std::string GetFetchIntegrityForWebURLRequest(const WebURLRequest& request) { return request.GetFetchIntegrity().Utf8(); } -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_UNSPECIFIED, - WebURLRequest::kRequestContextUnspecified); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_AUDIO, - WebURLRequest::kRequestContextAudio); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_BEACON, - WebURLRequest::kRequestContextBeacon); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_CSP_REPORT, - WebURLRequest::kRequestContextCSPReport); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_DOWNLOAD, - WebURLRequest::kRequestContextDownload); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_EMBED, - WebURLRequest::kRequestContextEmbed); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_EVENT_SOURCE, - WebURLRequest::kRequestContextEventSource); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_FAVICON, - WebURLRequest::kRequestContextFavicon); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_FETCH, - WebURLRequest::kRequestContextFetch); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_FONT, - WebURLRequest::kRequestContextFont); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_FORM, - WebURLRequest::kRequestContextForm); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_FRAME, - WebURLRequest::kRequestContextFrame); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_HYPERLINK, - WebURLRequest::kRequestContextHyperlink); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_IFRAME, - WebURLRequest::kRequestContextIframe); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_IMAGE, - WebURLRequest::kRequestContextImage); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_IMAGE_SET, - WebURLRequest::kRequestContextImageSet); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_IMPORT, - WebURLRequest::kRequestContextImport); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_INTERNAL, - WebURLRequest::kRequestContextInternal); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_LOCATION, - WebURLRequest::kRequestContextLocation); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_MANIFEST, - WebURLRequest::kRequestContextManifest); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_OBJECT, - WebURLRequest::kRequestContextObject); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_PING, - WebURLRequest::kRequestContextPing); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_PLUGIN, - WebURLRequest::kRequestContextPlugin); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_PREFETCH, - WebURLRequest::kRequestContextPrefetch); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_SCRIPT, - WebURLRequest::kRequestContextScript); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_SERVICE_WORKER, - WebURLRequest::kRequestContextServiceWorker); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_SHARED_WORKER, - WebURLRequest::kRequestContextSharedWorker); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_SUBRESOURCE, - WebURLRequest::kRequestContextSubresource); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_STYLE, - WebURLRequest::kRequestContextStyle); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_TRACK, - WebURLRequest::kRequestContextTrack); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_VIDEO, - WebURLRequest::kRequestContextVideo); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_WORKER, - WebURLRequest::kRequestContextWorker); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_XML_HTTP_REQUEST, - WebURLRequest::kRequestContextXMLHttpRequest); -STATIC_ASSERT_ENUM(REQUEST_CONTEXT_TYPE_XSLT, - WebURLRequest::kRequestContextXSLT); - -RequestContextType GetRequestContextTypeForWebURLRequest( +blink::mojom::RequestContextType GetRequestContextTypeForWebURLRequest( const WebURLRequest& request) { - return static_cast<RequestContextType>(request.GetRequestContext()); + return static_cast<blink::mojom::RequestContextType>( + request.GetRequestContext()); } blink::WebMixedContentContextType GetMixedContentContextTypeForWebURLRequest( diff --git a/chromium/content/renderer/loader/web_url_request_util.h b/chromium/content/renderer/loader/web_url_request_util.h index bc85bb64d15..de7df077361 100644 --- a/chromium/content/renderer/loader/web_url_request_util.h +++ b/chromium/content/renderer/loader/web_url_request_util.h @@ -8,12 +8,12 @@ #include <string> #include "content/common/content_export.h" -#include "content/public/common/request_context_type.h" #include "content/public/common/resource_type.h" #include "net/http/http_request_headers.h" #include "services/network/public/cpp/resource_request_body.h" #include "services/network/public/mojom/request_context_frame_type.mojom.h" #include "third_party/blink/public/mojom/blob/blob_registry.mojom.h" +#include "third_party/blink/public/platform/modules/fetch/fetch_api_request.mojom.h" #include "third_party/blink/public/platform/web_mixed_content_context_type.h" #include "third_party/blink/public/platform/web_url_request.h" @@ -23,8 +23,8 @@ class WebHTTPBody; namespace content { -ResourceType WebURLRequestContextToResourceType( - blink::WebURLRequest::RequestContext request_context); +ResourceType RequestContextToResourceType( + blink::mojom::RequestContextType request_context); CONTENT_EXPORT ResourceType WebURLRequestToResourceType( const blink::WebURLRequest& request); @@ -68,7 +68,7 @@ scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebURLRequest( // type. std::string GetFetchIntegrityForWebURLRequest( const blink::WebURLRequest& request); -RequestContextType GetRequestContextTypeForWebURLRequest( +blink::mojom::RequestContextType GetRequestContextTypeForWebURLRequest( const blink::WebURLRequest& request); blink::WebMixedContentContextType GetMixedContentContextTypeForWebURLRequest( const blink::WebURLRequest& request); diff --git a/chromium/content/renderer/loader/web_worker_fetch_context_impl.cc b/chromium/content/renderer/loader/web_worker_fetch_context_impl.cc index 61e6dbb61eb..fc03ca1589f 100644 --- a/chromium/content/renderer/loader/web_worker_fetch_context_impl.cc +++ b/chromium/content/renderer/loader/web_worker_fetch_context_impl.cc @@ -41,8 +41,8 @@ WebWorkerFetchContextImpl::RewriteURLFunction g_rewrite_url = nullptr; namespace { -// Runs on IO thread. -void CreateSubresourceLoaderFactoryForWorker( +// Runs on a background thread created in ResetServiceWorkerURLLoaderFactory(). +void CreateServiceWorkerSubresourceLoaderFactory( mojom::ServiceWorkerContainerHostPtrInfo container_host_info, const std::string& client_id, std::unique_ptr<network::SharedURLLoaderFactoryInfo> fallback_factory, @@ -201,7 +201,7 @@ WebWorkerFetchContextImpl::CloneForNestedWorker() { mojom::ServiceWorkerContainerHostPtrInfo host_ptr_info; if (blink::ServiceWorkerUtils::IsServicificationEnabled()) { - service_worker_container_host_->CloneForWorker( + service_worker_container_host_->CloneContainerHost( mojo::MakeRequest(&host_ptr_info)); } @@ -449,7 +449,7 @@ void WebWorkerFetchContextImpl::ResetServiceWorkerURLLoaderFactory() { network::mojom::URLLoaderFactoryPtr service_worker_url_loader_factory; mojom::ServiceWorkerContainerHostPtrInfo host_ptr_info; - service_worker_container_host_->CloneForWorker( + service_worker_container_host_->CloneContainerHost( mojo::MakeRequest(&host_ptr_info)); // To avoid potential dead-lock while synchronous loading, create the // SubresourceLoaderFactory on a background thread. @@ -458,8 +458,8 @@ void WebWorkerFetchContextImpl::ResetServiceWorkerURLLoaderFactory() { task_runner->PostTask( FROM_HERE, base::BindOnce( - &CreateSubresourceLoaderFactoryForWorker, std::move(host_ptr_info), - client_id_, fallback_factory_->Clone(), + &CreateServiceWorkerSubresourceLoaderFactory, + std::move(host_ptr_info), client_id_, fallback_factory_->Clone(), mojo::MakeRequest(&service_worker_url_loader_factory), task_runner)); web_loader_factory_->SetServiceWorkerURLLoaderFactory( std::move(service_worker_url_loader_factory)); diff --git a/chromium/content/renderer/loader/weburlresponse_extradata_impl.h b/chromium/content/renderer/loader/weburlresponse_extradata_impl.h index 9b26d307ac1..aa5e687481a 100644 --- a/chromium/content/renderer/loader/weburlresponse_extradata_impl.h +++ b/chromium/content/renderer/loader/weburlresponse_extradata_impl.h @@ -62,17 +62,12 @@ class CONTENT_EXPORT WebURLResponseExtraDataImpl effective_connection_type_ = effective_connection_type; } - // Request ID generated by the renderer. - int request_id() const { return request_id_; } - void set_request_id(int request_id) { request_id_ = request_id; } - private: bool is_ftp_directory_listing_; bool was_fetched_via_spdy_; bool was_alpn_negotiated_; bool was_alternate_protocol_available_; net::EffectiveConnectionType effective_connection_type_; - int request_id_; DISALLOW_COPY_AND_ASSIGN(WebURLResponseExtraDataImpl); }; |