summaryrefslogtreecommitdiff
path: root/chromium/content/renderer/loader
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/renderer/loader')
-rw-r--r--chromium/content/renderer/loader/child_url_loader_factory_bundle.cc175
-rw-r--r--chromium/content/renderer/loader/child_url_loader_factory_bundle.h104
-rw-r--r--chromium/content/renderer/loader/child_url_loader_factory_getter_impl.cc95
-rw-r--r--chromium/content/renderer/loader/child_url_loader_factory_getter_impl.h56
-rw-r--r--chromium/content/renderer/loader/cors_url_loader.cc237
-rw-r--r--chromium/content/renderer/loader/cors_url_loader.h103
-rw-r--r--chromium/content/renderer/loader/cors_url_loader_factory.cc67
-rw-r--r--chromium/content/renderer/loader/cors_url_loader_factory.h61
-rw-r--r--chromium/content/renderer/loader/cors_url_loader_unittest.cc254
-rw-r--r--chromium/content/renderer/loader/request_extra_data.cc10
-rw-r--r--chromium/content/renderer/loader/request_extra_data.h28
-rw-r--r--chromium/content/renderer/loader/resource_dispatcher.cc34
-rw-r--r--chromium/content/renderer/loader/resource_dispatcher.h15
-rw-r--r--chromium/content/renderer/loader/resource_dispatcher_unittest.cc9
-rw-r--r--chromium/content/renderer/loader/shared_memory_data_consumer_handle.cc4
-rw-r--r--chromium/content/renderer/loader/shared_memory_data_consumer_handle.h4
-rw-r--r--chromium/content/renderer/loader/shared_memory_data_consumer_handle_unittest.cc88
-rw-r--r--chromium/content/renderer/loader/site_isolation_stats_gatherer.cc6
-rw-r--r--chromium/content/renderer/loader/site_isolation_stats_gatherer_browsertest.cc3
-rw-r--r--chromium/content/renderer/loader/sync_load_context.cc6
-rw-r--r--chromium/content/renderer/loader/sync_load_response.h2
-rw-r--r--chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.cc177
-rw-r--r--chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.h153
-rw-r--r--chromium/content/renderer/loader/url_loader_client_impl.h2
-rw-r--r--chromium/content/renderer/loader/url_loader_client_impl_unittest.cc8
-rw-r--r--chromium/content/renderer/loader/url_response_body_consumer.h2
-rw-r--r--chromium/content/renderer/loader/url_response_body_consumer_unittest.cc9
-rw-r--r--chromium/content/renderer/loader/web_data_consumer_handle_impl.cc15
-rw-r--r--chromium/content/renderer/loader/web_data_consumer_handle_impl.h8
-rw-r--r--chromium/content/renderer/loader/web_data_consumer_handle_impl_unittest.cc16
-rw-r--r--chromium/content/renderer/loader/web_url_loader_impl.cc59
-rw-r--r--chromium/content/renderer/loader/web_url_loader_impl.h12
-rw-r--r--chromium/content/renderer/loader/web_url_loader_impl_unittest.cc13
-rw-r--r--chromium/content/renderer/loader/web_url_request_util.cc41
-rw-r--r--chromium/content/renderer/loader/web_url_request_util.h5
35 files changed, 821 insertions, 1060 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
new file mode 100644
index 00000000000..08d0a9dc06b
--- /dev/null
+++ b/chromium/content/renderer/loader/child_url_loader_factory_bundle.cc
@@ -0,0 +1,175 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/loader/child_url_loader_factory_bundle.h"
+
+#include "base/logging.h"
+#include "url/gurl.h"
+#include "url/url_constants.h"
+
+namespace content {
+
+ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo() = default;
+
+ChildURLLoaderFactoryBundleInfo::ChildURLLoaderFactoryBundleInfo(
+ network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
+ std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>
+ factories_info,
+ PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info)
+ : URLLoaderFactoryBundleInfo(std::move(default_factory_info),
+ std::move(factories_info)),
+ direct_network_factory_info_(std::move(direct_network_factory_info)) {}
+
+ChildURLLoaderFactoryBundleInfo::~ChildURLLoaderFactoryBundleInfo() = default;
+
+scoped_refptr<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->direct_network_factory_info_ = std::move(direct_network_factory_info_);
+
+ return base::MakeRefCounted<ChildURLLoaderFactoryBundle>(std::move(other));
+}
+
+// -----------------------------------------------------------------------------
+
+ChildURLLoaderFactoryBundle::ChildURLLoaderFactoryBundle() = default;
+
+ChildURLLoaderFactoryBundle::ChildURLLoaderFactoryBundle(
+ std::unique_ptr<ChildURLLoaderFactoryBundleInfo> info) {
+ Update(std::move(info));
+}
+
+ChildURLLoaderFactoryBundle::ChildURLLoaderFactoryBundle(
+ PossiblyAssociatedFactoryGetterCallback direct_network_factory_getter,
+ FactoryGetterCallback default_blob_factory_getter)
+ : direct_network_factory_getter_(std::move(direct_network_factory_getter)),
+ default_blob_factory_getter_(std::move(default_blob_factory_getter)) {}
+
+ChildURLLoaderFactoryBundle::~ChildURLLoaderFactoryBundle() = default;
+
+network::mojom::URLLoaderFactory* ChildURLLoaderFactoryBundle::GetFactoryForURL(
+ const GURL& url) {
+ if (url.SchemeIsBlob())
+ InitDefaultBlobFactoryIfNecessary();
+
+ auto it = factories_.find(url.scheme());
+ if (it != factories_.end())
+ return it->second.get();
+
+ if (default_factory_)
+ return default_factory_.get();
+
+ InitDirectNetworkFactoryIfNecessary();
+ DCHECK(direct_network_factory_);
+ return direct_network_factory_.get();
+}
+
+void ChildURLLoaderFactoryBundle::CreateLoaderAndStart(
+ network::mojom::URLLoaderRequest loader,
+ int32_t routing_id,
+ int32_t request_id,
+ uint32_t options,
+ const network::ResourceRequest& request,
+ network::mojom::URLLoaderClientPtr client,
+ const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
+ network::mojom::URLLoaderFactory* factory_ptr = GetFactoryForURL(request.url);
+
+ factory_ptr->CreateLoaderAndStart(std::move(loader), routing_id, request_id,
+ options, request, std::move(client),
+ traffic_annotation);
+}
+
+std::unique_ptr<SharedURLLoaderFactoryInfo>
+ChildURLLoaderFactoryBundle::Clone() {
+ InitDefaultBlobFactoryIfNecessary();
+ InitDirectNetworkFactoryIfNecessary();
+
+ network::mojom::URLLoaderFactoryPtrInfo default_factory_info;
+ if (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));
+ }
+
+ return std::make_unique<ChildURLLoaderFactoryBundleInfo>(
+ std::move(default_factory_info), std::move(factories_info),
+ std::move(direct_network_factory_info));
+}
+
+void ChildURLLoaderFactoryBundle::Update(
+ std::unique_ptr<ChildURLLoaderFactoryBundleInfo> info) {
+ if (info->direct_network_factory_info()) {
+ direct_network_factory_.Bind(
+ std::move(info->direct_network_factory_info()));
+ }
+ URLLoaderFactoryBundle::Update(std::move(info));
+}
+
+bool ChildURLLoaderFactoryBundle::IsHostChildURLLoaderFactoryBundle() const {
+ return false;
+}
+
+void ChildURLLoaderFactoryBundle::InitDefaultBlobFactoryIfNecessary() {
+ if (default_blob_factory_getter_.is_null())
+ return;
+
+ if (factories_.find(url::kBlobScheme) == factories_.end()) {
+ network::mojom::URLLoaderFactoryPtr blob_factory =
+ std::move(default_blob_factory_getter_).Run();
+ if (blob_factory)
+ factories_.emplace(url::kBlobScheme, std::move(blob_factory));
+ } else {
+ default_blob_factory_getter_.Reset();
+ }
+}
+
+void ChildURLLoaderFactoryBundle::InitDirectNetworkFactoryIfNecessary() {
+ if (direct_network_factory_getter_.is_null())
+ return;
+
+ if (!direct_network_factory_) {
+ direct_network_factory_ = std::move(direct_network_factory_getter_).Run();
+ } else {
+ direct_network_factory_getter_.Reset();
+ }
+}
+
+std::unique_ptr<ChildURLLoaderFactoryBundleInfo>
+ChildURLLoaderFactoryBundle::PassInterface() {
+ InitDefaultBlobFactoryIfNecessary();
+ InitDirectNetworkFactoryIfNecessary();
+
+ network::mojom::URLLoaderFactoryPtrInfo default_factory_info;
+ 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();
+ }
+
+ return std::make_unique<ChildURLLoaderFactoryBundleInfo>(
+ std::move(default_factory_info), std::move(factories_info),
+ std::move(direct_network_factory_info));
+}
+
+} // 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
new file mode 100644
index 00000000000..2e884253e60
--- /dev/null
+++ b/chromium/content/renderer/loader/child_url_loader_factory_bundle.h
@@ -0,0 +1,104 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
+#define CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
+
+#include "base/callback.h"
+#include "content/common/content_export.h"
+#include "content/common/possibly_associated_interface_ptr.h"
+#include "content/common/url_loader_factory_bundle.h"
+#include "services/network/public/mojom/url_loader_factory.mojom.h"
+
+namespace content {
+
+// Holds the internal state of a ChildURLLoaderFactoryBundle in a form that is
+// safe to pass across sequences.
+class CONTENT_EXPORT ChildURLLoaderFactoryBundleInfo
+ : public URLLoaderFactoryBundleInfo {
+ public:
+ using PossiblyAssociatedURLLoaderFactoryPtrInfo =
+ PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory>;
+
+ ChildURLLoaderFactoryBundleInfo();
+ ChildURLLoaderFactoryBundleInfo(
+ network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
+ std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>
+ factories_info,
+ PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info);
+ ~ChildURLLoaderFactoryBundleInfo() override;
+
+ PossiblyAssociatedURLLoaderFactoryPtrInfo& direct_network_factory_info() {
+ return direct_network_factory_info_;
+ }
+
+ protected:
+ // URLLoaderFactoryBundleInfo overrides.
+ scoped_refptr<SharedURLLoaderFactory> CreateFactory() override;
+
+ PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChildURLLoaderFactoryBundleInfo);
+};
+
+// This class extends URLLoaderFactoryBundle to support a direct network loader
+// factory, which bypasses custom overrides such as appcache or service worker.
+// Besides, it also supports using callbacks to lazily initialize the blob and
+// the direct network loader factories.
+class CONTENT_EXPORT ChildURLLoaderFactoryBundle
+ : public URLLoaderFactoryBundle {
+ public:
+ using PossiblyAssociatedURLLoaderFactoryPtr =
+ PossiblyAssociatedInterfacePtr<network::mojom::URLLoaderFactory>;
+
+ using FactoryGetterCallback =
+ base::OnceCallback<network::mojom::URLLoaderFactoryPtr()>;
+ using PossiblyAssociatedFactoryGetterCallback =
+ base::OnceCallback<PossiblyAssociatedURLLoaderFactoryPtr()>;
+
+ ChildURLLoaderFactoryBundle();
+
+ explicit ChildURLLoaderFactoryBundle(
+ std::unique_ptr<ChildURLLoaderFactoryBundleInfo> info);
+
+ ChildURLLoaderFactoryBundle(
+ PossiblyAssociatedFactoryGetterCallback direct_network_factory_getter,
+ FactoryGetterCallback default_blob_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,
+ uint32_t options,
+ const network::ResourceRequest& request,
+ network::mojom::URLLoaderClientPtr client,
+ const net::MutableNetworkTrafficAnnotationTag&
+ traffic_annotation) override;
+
+ std::unique_ptr<SharedURLLoaderFactoryInfo> Clone() override;
+
+ std::unique_ptr<ChildURLLoaderFactoryBundleInfo> PassInterface();
+
+ void Update(std::unique_ptr<ChildURLLoaderFactoryBundleInfo> info);
+
+ virtual bool IsHostChildURLLoaderFactoryBundle() const;
+
+ protected:
+ ~ChildURLLoaderFactoryBundle() override;
+
+ private:
+ void InitDefaultBlobFactoryIfNecessary();
+ void InitDirectNetworkFactoryIfNecessary();
+
+ PossiblyAssociatedFactoryGetterCallback direct_network_factory_getter_;
+ PossiblyAssociatedURLLoaderFactoryPtr direct_network_factory_;
+
+ FactoryGetterCallback default_blob_factory_getter_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
diff --git a/chromium/content/renderer/loader/child_url_loader_factory_getter_impl.cc b/chromium/content/renderer/loader/child_url_loader_factory_getter_impl.cc
deleted file mode 100644
index 9b636b03866..00000000000
--- a/chromium/content/renderer/loader/child_url_loader_factory_getter_impl.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/renderer/loader/child_url_loader_factory_getter_impl.h"
-
-#include "base/feature_list.h"
-#include "content/public/common/content_features.h"
-#include "third_party/WebKit/public/platform/WebURLRequest.h"
-
-namespace content {
-
-ChildURLLoaderFactoryGetter::Info::Info(
- network::mojom::URLLoaderFactoryPtrInfo network_loader_factory_info,
- network::mojom::URLLoaderFactoryPtrInfo blob_loader_factory_info)
- : network_loader_factory_info_(std::move(network_loader_factory_info)),
- blob_loader_factory_info_(std::move(blob_loader_factory_info)) {}
-
-ChildURLLoaderFactoryGetter::Info::Info(Info&& other)
- : network_loader_factory_info_(
- std::move(other.network_loader_factory_info_)),
- blob_loader_factory_info_(std::move(other.blob_loader_factory_info_)) {}
-
-ChildURLLoaderFactoryGetter::Info::~Info() = default;
-
-scoped_refptr<ChildURLLoaderFactoryGetter>
-ChildURLLoaderFactoryGetter::Info::Bind() {
- DCHECK(network_loader_factory_info_.is_valid());
- network::mojom::URLLoaderFactoryPtr network_loader_factory;
- network::mojom::URLLoaderFactoryPtr blob_loader_factory;
- network_loader_factory.Bind(std::move(network_loader_factory_info_));
- blob_loader_factory.Bind(std::move(blob_loader_factory_info_));
- return base::MakeRefCounted<ChildURLLoaderFactoryGetterImpl>(
- std::move(network_loader_factory), std::move(blob_loader_factory));
-}
-
-ChildURLLoaderFactoryGetterImpl::ChildURLLoaderFactoryGetterImpl() = default;
-
-ChildURLLoaderFactoryGetterImpl::ChildURLLoaderFactoryGetterImpl(
- PossiblyAssociatedURLLoaderFactory network_loader_factory,
- URLLoaderFactoryGetterCallback blob_loader_factory_getter)
- : network_loader_factory_(std::move(network_loader_factory)),
- blob_loader_factory_getter_(std::move(blob_loader_factory_getter)) {}
-
-ChildURLLoaderFactoryGetterImpl::ChildURLLoaderFactoryGetterImpl(
- PossiblyAssociatedURLLoaderFactory network_loader_factory,
- PossiblyAssociatedURLLoaderFactory blob_loader_factory)
- : network_loader_factory_(std::move(network_loader_factory)),
- blob_loader_factory_(std::move(blob_loader_factory)) {}
-
-ChildURLLoaderFactoryGetterImpl::Info
-ChildURLLoaderFactoryGetterImpl::GetClonedInfo() {
- network::mojom::URLLoaderFactoryPtrInfo network_loader_factory_info;
- GetNetworkLoaderFactory()->Clone(
- mojo::MakeRequest(&network_loader_factory_info));
-
- network::mojom::URLLoaderFactoryPtrInfo blob_loader_factory_info;
- GetBlobLoaderFactory()->Clone(mojo::MakeRequest(&blob_loader_factory_info));
-
- return Info(std::move(network_loader_factory_info),
- std::move(blob_loader_factory_info));
-}
-
-network::mojom::URLLoaderFactory*
-ChildURLLoaderFactoryGetterImpl::GetFactoryForURL(
- const GURL& url,
- network::mojom::URLLoaderFactory* default_factory) {
- if (base::FeatureList::IsEnabled(features::kNetworkService) &&
- url.SchemeIsBlob()) {
- return GetBlobLoaderFactory();
- }
- if (default_factory)
- return default_factory;
- return GetNetworkLoaderFactory();
-}
-
-network::mojom::URLLoaderFactory*
-ChildURLLoaderFactoryGetterImpl::GetNetworkLoaderFactory() {
- return network_loader_factory_.get();
-}
-
-network::mojom::URLLoaderFactory*
-ChildURLLoaderFactoryGetterImpl::GetBlobLoaderFactory() {
- if (!blob_loader_factory_) {
- if (blob_loader_factory_getter_.is_null()) {
- return GetNetworkLoaderFactory();
- }
- blob_loader_factory_ = std::move(blob_loader_factory_getter_).Run();
- }
- return blob_loader_factory_.get();
-}
-
-ChildURLLoaderFactoryGetterImpl::~ChildURLLoaderFactoryGetterImpl() = default;
-
-} // namespace content
diff --git a/chromium/content/renderer/loader/child_url_loader_factory_getter_impl.h b/chromium/content/renderer/loader/child_url_loader_factory_getter_impl.h
deleted file mode 100644
index 5d2e73abcd0..00000000000
--- a/chromium/content/renderer/loader/child_url_loader_factory_getter_impl.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_GETTER_IMPL_H_
-#define CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_GETTER_IMPL_H_
-
-#include "base/callback.h"
-#include "content/common/content_export.h"
-#include "content/common/possibly_associated_interface_ptr.h"
-#include "content/public/renderer/child_url_loader_factory_getter.h"
-#include "services/network/public/interfaces/url_loader_factory.mojom.h"
-
-namespace content {
-
-class CONTENT_EXPORT ChildURLLoaderFactoryGetterImpl
- : public ChildURLLoaderFactoryGetter {
- public:
- using PossiblyAssociatedURLLoaderFactory =
- PossiblyAssociatedInterfacePtr<network::mojom::URLLoaderFactory>;
- using URLLoaderFactoryGetterCallback =
- base::OnceCallback<network::mojom::URLLoaderFactoryPtr()>;
-
- ChildURLLoaderFactoryGetterImpl();
-
- ChildURLLoaderFactoryGetterImpl(
- PossiblyAssociatedURLLoaderFactory network_loader_factory,
- URLLoaderFactoryGetterCallback blob_loader_factory_getter);
-
- ChildURLLoaderFactoryGetterImpl(
- PossiblyAssociatedURLLoaderFactory network_loader_factory,
- PossiblyAssociatedURLLoaderFactory blob_loader_factory_getter);
-
- Info GetClonedInfo() override;
-
- network::mojom::URLLoaderFactory* GetFactoryForURL(
- const GURL& url,
- network::mojom::URLLoaderFactory* default_factory) override;
- network::mojom::URLLoaderFactory* GetNetworkLoaderFactory() override;
- network::mojom::URLLoaderFactory* GetBlobLoaderFactory() override;
-
- private:
- ~ChildURLLoaderFactoryGetterImpl() override;
-
- PossiblyAssociatedURLLoaderFactory network_loader_factory_;
-
- // Either factory_getter or factory is non-null (to support
- // lazy instantiation), or both could be null (if the default
- // ctor is used).
- URLLoaderFactoryGetterCallback blob_loader_factory_getter_;
- PossiblyAssociatedURLLoaderFactory blob_loader_factory_;
-};
-
-} // namespace content
-
-#endif // CONTENT_RENDERER_LOADER_CHILD_URL_LOADER_FACTORY_GETTER_IMPL_H_
diff --git a/chromium/content/renderer/loader/cors_url_loader.cc b/chromium/content/renderer/loader/cors_url_loader.cc
deleted file mode 100644
index 10dcfedf817..00000000000
--- a/chromium/content/renderer/loader/cors_url_loader.cc
+++ /dev/null
@@ -1,237 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/renderer/loader/cors_url_loader.h"
-
-#include "content/public/common/origin_util.h"
-#include "content/public/common/resource_type.h"
-#include "content/public/common/service_worker_modes.h"
-#include "services/network/public/cpp/cors/cors.h"
-
-using network::mojom::CORSError;
-using network::mojom::FetchRequestMode;
-
-namespace content {
-
-namespace {
-
-bool CalculateCORSFlag(const network::ResourceRequest& request) {
- if (request.fetch_request_mode == FetchRequestMode::kNavigate &&
- (request.resource_type == RESOURCE_TYPE_MAIN_FRAME ||
- request.resource_type == RESOURCE_TYPE_SUB_FRAME)) {
- return false;
- }
- url::Origin url_origin = url::Origin::Create(request.url);
- if (IsOriginWhiteListedTrustworthy(url_origin))
- return false;
- if (!request.request_initiator.has_value())
- return true;
- url::Origin security_origin(request.request_initiator.value());
- return !security_origin.IsSameOriginWith(url_origin);
-}
-
-base::Optional<std::string> GetHeaderString(
- const scoped_refptr<net::HttpResponseHeaders>& headers,
- const std::string& header_name) {
- std::string header_value;
- if (!headers->GetNormalizedHeader(header_name, &header_value))
- return base::nullopt;
- return header_value;
-}
-
-} // namespace
-
-// TODO(toyoshim): At the moment this class simply forwards all calls to the
-// underlying network loader. Part of the effort to move CORS handling out of
-// Blink: http://crbug/736308.
-CORSURLLoader::CORSURLLoader(
- int32_t routing_id,
- int32_t request_id,
- uint32_t options,
- const network::ResourceRequest& resource_request,
- network::mojom::URLLoaderClientPtr client,
- const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
- network::mojom::URLLoaderFactory* network_loader_factory)
- : network_loader_factory_(network_loader_factory),
- network_client_binding_(this),
- forwarding_client_(std::move(client)),
- security_origin_(
- resource_request.request_initiator.value_or(url::Origin())),
- last_response_url_(resource_request.url),
- fetch_request_mode_(resource_request.fetch_request_mode),
- fetch_credentials_mode_(resource_request.fetch_credentials_mode),
- fetch_cors_flag_(CalculateCORSFlag(resource_request)) {
- DCHECK(network_loader_factory_);
-
- if (fetch_cors_flag_ &&
- fetch_request_mode_ == FetchRequestMode::kSameOrigin) {
- forwarding_client_->OnComplete(network::URLLoaderCompletionStatus(
- network::CORSErrorStatus(CORSError::kDisallowedByMode)));
- return;
- }
-
- // TODO(toyoshim): Needs some checks if the calculated fetch_cors_flag_
- // is allowed in this request or not.
-
- network::mojom::URLLoaderClientPtr network_client;
- network_client_binding_.Bind(mojo::MakeRequest(&network_client));
- // Binding |this| as an unretained pointer is safe because
- // |network_client_binding_| shares this object's lifetime.
- network_client_binding_.set_connection_error_handler(base::BindOnce(
- &CORSURLLoader::OnUpstreamConnectionError, base::Unretained(this)));
- network_loader_factory_->CreateLoaderAndStart(
- mojo::MakeRequest(&network_loader_), routing_id, request_id, options,
- resource_request, std::move(network_client), traffic_annotation);
-}
-
-CORSURLLoader::~CORSURLLoader() {}
-
-void CORSURLLoader::FollowRedirect() {
- DCHECK(network_loader_);
- DCHECK(is_waiting_follow_redirect_call_);
- is_waiting_follow_redirect_call_ = false;
- network_loader_->FollowRedirect();
-}
-
-void CORSURLLoader::ProceedWithResponse() {
- NOTREACHED();
-}
-
-void CORSURLLoader::SetPriority(net::RequestPriority priority,
- int32_t intra_priority_value) {
- // TODO(toyoshim): Should not be called during the redirect decisions, but
- // Blink calls actually.
- // DCHECK(!is_waiting_follow_redirect_call_);
- if (network_loader_)
- network_loader_->SetPriority(priority, intra_priority_value);
-}
-
-void CORSURLLoader::PauseReadingBodyFromNet() {
- DCHECK(!is_waiting_follow_redirect_call_);
- if (network_loader_)
- network_loader_->PauseReadingBodyFromNet();
-}
-
-void CORSURLLoader::ResumeReadingBodyFromNet() {
- DCHECK(!is_waiting_follow_redirect_call_);
- if (network_loader_)
- network_loader_->ResumeReadingBodyFromNet();
-}
-
-void CORSURLLoader::OnReceiveResponse(
- const network::ResourceResponseHead& response_head,
- const base::Optional<net::SSLInfo>& ssl_info,
- network::mojom::DownloadedTempFilePtr downloaded_file) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
- if (fetch_cors_flag_ &&
- network::cors::IsCORSEnabledRequestMode(fetch_request_mode_)) {
- base::Optional<CORSError> cors_error = network::cors::CheckAccess(
- last_response_url_, response_head.headers->response_code(),
- GetHeaderString(response_head.headers,
- network::cors::header_names::kAccessControlAllowOrigin),
- GetHeaderString(
- response_head.headers,
- network::cors::header_names::kAccessControlAllowSuborigin),
- GetHeaderString(
- response_head.headers,
- network::cors::header_names::kAccessControlAllowCredentials),
- fetch_credentials_mode_, security_origin_);
- if (cors_error) {
- // TODO(toyoshim): Generate related_response_headers here.
- network::CORSErrorStatus cors_error_status(*cors_error);
- HandleComplete(network::URLLoaderCompletionStatus(cors_error_status));
- return;
- }
- }
- forwarding_client_->OnReceiveResponse(response_head, ssl_info,
- std::move(downloaded_file));
-}
-
-void CORSURLLoader::OnReceiveRedirect(
- const net::RedirectInfo& redirect_info,
- const network::ResourceResponseHead& response_head) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
-
- // TODO(toyoshim): Following code expects OnReceivedRedirect is invoked
- // asynchronously, and |last_response_url_| and other methods should not be
- // accessed until FollowRedirect() is called.
- // We need to ensure callback behaviors once redirect implementation in this
- // class is ready for testing.
- is_waiting_follow_redirect_call_ = true;
- last_response_url_ = redirect_info.new_url;
- forwarding_client_->OnReceiveRedirect(redirect_info, response_head);
-}
-
-void CORSURLLoader::OnDataDownloaded(int64_t data_len,
- int64_t encoded_data_len) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
- forwarding_client_->OnDataDownloaded(data_len, encoded_data_len);
-}
-
-void CORSURLLoader::OnUploadProgress(int64_t current_position,
- int64_t total_size,
- OnUploadProgressCallback ack_callback) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
- forwarding_client_->OnUploadProgress(current_position, total_size,
- std::move(ack_callback));
-}
-
-void CORSURLLoader::OnReceiveCachedMetadata(const std::vector<uint8_t>& data) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
- forwarding_client_->OnReceiveCachedMetadata(data);
-}
-
-void CORSURLLoader::OnTransferSizeUpdated(int32_t transfer_size_diff) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
- forwarding_client_->OnTransferSizeUpdated(transfer_size_diff);
-}
-
-void CORSURLLoader::OnStartLoadingResponseBody(
- mojo::ScopedDataPipeConsumerHandle body) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
- forwarding_client_->OnStartLoadingResponseBody(std::move(body));
-}
-
-void CORSURLLoader::OnComplete(
- const network::URLLoaderCompletionStatus& status) {
- DCHECK(network_loader_);
- DCHECK(forwarding_client_);
- DCHECK(!is_waiting_follow_redirect_call_);
- HandleComplete(status);
-}
-
-void CORSURLLoader::OnUpstreamConnectionError() {
- // |network_client_binding_| has experienced a connection error and will no
- // longer call any of the network::mojom::URLLoaderClient methods above. The
- // client pipe to the downstream client is closed to inform it of this
- // failure. The client should respond by closing its network::mojom::URLLoader
- // pipe which will cause this object to be destroyed.
- forwarding_client_.reset();
-}
-
-void CORSURLLoader::HandleComplete(
- const network::URLLoaderCompletionStatus& status) {
- forwarding_client_->OnComplete(status);
- forwarding_client_.reset();
-
- // Close pipes to ignore possible subsequent callback invocations.
- network_client_binding_.Close();
- network_loader_.reset();
-}
-
-} // namespace content
diff --git a/chromium/content/renderer/loader/cors_url_loader.h b/chromium/content/renderer/loader/cors_url_loader.h
deleted file mode 100644
index 7eb94d4f0b8..00000000000
--- a/chromium/content/renderer/loader/cors_url_loader.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_RENDERER_LOADER_CORS_URL_LOADER_H_
-#define CONTENT_RENDERER_LOADER_CORS_URL_LOADER_H_
-
-#include "content/common/content_export.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "net/traffic_annotation/network_traffic_annotation.h"
-#include "services/network/public/interfaces/fetch_api.mojom.h"
-#include "services/network/public/interfaces/url_loader_factory.mojom.h"
-#include "url/gurl.h"
-#include "url/origin.h"
-
-namespace content {
-
-// Wrapper class that adds cross-origin resource sharing capabilities
-// (https://fetch.spec.whatwg.org/#http-cors-protocol), delegating requests as
-// well as potential preflight requests to the supplied
-// |network_loader_factory|. It is owned by the CORSURLLoaderFactory that
-// created it.
-class CONTENT_EXPORT CORSURLLoader : public network::mojom::URLLoader,
- public network::mojom::URLLoaderClient {
- public:
- // Assumes network_loader_factory outlives this loader.
- CORSURLLoader(
- int32_t routing_id,
- int32_t request_id,
- uint32_t options,
- const network::ResourceRequest& resource_request,
- network::mojom::URLLoaderClientPtr client,
- const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
- network::mojom::URLLoaderFactory* network_loader_factory);
-
- ~CORSURLLoader() override;
-
- // network::mojom::URLLoader overrides:
- void FollowRedirect() override;
- void ProceedWithResponse() override;
- void SetPriority(net::RequestPriority priority,
- int intra_priority_value) override;
- void PauseReadingBodyFromNet() override;
- void ResumeReadingBodyFromNet() override;
-
- // network::mojom::URLLoaderClient overrides:
- void OnReceiveResponse(
- const network::ResourceResponseHead& head,
- const base::Optional<net::SSLInfo>& ssl_info,
- network::mojom::DownloadedTempFilePtr downloaded_file) override;
- void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
- const network::ResourceResponseHead& head) override;
- void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override;
- void OnUploadProgress(int64_t current_position,
- int64_t total_size,
- base::OnceCallback<void()> callback) override;
- void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
- void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
- void OnStartLoadingResponseBody(
- mojo::ScopedDataPipeConsumerHandle body) override;
- void OnComplete(const network::URLLoaderCompletionStatus& status) override;
-
- private:
- // Called when there is a connection error on the upstream pipe used for the
- // actual request.
- void OnUpstreamConnectionError();
-
- // Handles OnComplete() callback.
- void HandleComplete(const network::URLLoaderCompletionStatus& status);
-
- // This raw URLLoaderFactory pointer is shared with the CORSURLLoaderFactory
- // that created and owns this object.
- network::mojom::URLLoaderFactory* network_loader_factory_;
-
- // For the actual request.
- network::mojom::URLLoaderPtr network_loader_;
- mojo::Binding<network::mojom::URLLoaderClient> network_client_binding_;
-
- // To be a URLLoader for the client.
- network::mojom::URLLoaderClientPtr forwarding_client_;
-
- // Request initiator's origin.
- url::Origin security_origin_;
-
- // The last response URL, that is usually the requested URL, but can be
- // different if redirects happen.
- GURL last_response_url_;
-
- // A flag to indicate that the instance is waiting for that forwarding_client_
- // calls FollowRedirect.
- bool is_waiting_follow_redirect_call_ = false;
-
- // Corresponds to the Fetch spec, https://fetch.spec.whatwg.org/.
- network::mojom::FetchRequestMode fetch_request_mode_;
- network::mojom::FetchCredentialsMode fetch_credentials_mode_;
- bool fetch_cors_flag_;
-
- DISALLOW_COPY_AND_ASSIGN(CORSURLLoader);
-};
-
-} // namespace content
-
-#endif // CONTENT_RENDERER_LOADER_CORS_URL_LOADER_H_
diff --git a/chromium/content/renderer/loader/cors_url_loader_factory.cc b/chromium/content/renderer/loader/cors_url_loader_factory.cc
deleted file mode 100644
index 53815d3da3d..00000000000
--- a/chromium/content/renderer/loader/cors_url_loader_factory.cc
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/renderer/loader/cors_url_loader_factory.h"
-
-#include "content/renderer/loader/cors_url_loader.h"
-#include "net/traffic_annotation/network_traffic_annotation.h"
-#include "services/network/public/interfaces/url_loader_factory.mojom.h"
-
-namespace content {
-
-void CORSURLLoaderFactory::CreateAndBind(
- PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory>
- network_loader_factory,
- network::mojom::URLLoaderFactoryRequest request) {
- DCHECK(network_loader_factory);
-
- // This object will be destroyed when all pipes bound to it are closed.
- // See OnConnectionError().
- auto* impl = new CORSURLLoaderFactory(std::move(network_loader_factory));
- impl->Clone(std::move(request));
-}
-
-CORSURLLoaderFactory::CORSURLLoaderFactory(
- PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory>
- network_loader_factory) {
- // Binding |this| as an unretained pointer is safe because |bindings_| shares
- // this object's lifetime.
- bindings_.set_connection_error_handler(base::Bind(
- &CORSURLLoaderFactory::OnConnectionError, base::Unretained(this)));
- loader_bindings_.set_connection_error_handler(base::Bind(
- &CORSURLLoaderFactory::OnConnectionError, base::Unretained(this)));
-
- network_loader_factory_.Bind(std::move(network_loader_factory));
-}
-
-CORSURLLoaderFactory::~CORSURLLoaderFactory() {}
-
-void CORSURLLoaderFactory::CreateLoaderAndStart(
- network::mojom::URLLoaderRequest request,
- int32_t routing_id,
- int32_t request_id,
- uint32_t options,
- const network::ResourceRequest& resource_request,
- network::mojom::URLLoaderClientPtr client,
- const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
- // Instances of CORSURLLoader are owned by this class and their pipe so that
- // they can share |network_loader_factory_|.
- loader_bindings_.AddBinding(
- std::make_unique<CORSURLLoader>(
- routing_id, request_id, options, resource_request, std::move(client),
- traffic_annotation, network_loader_factory_.get()),
- std::move(request));
-}
-
-void CORSURLLoaderFactory::Clone(
- network::mojom::URLLoaderFactoryRequest request) {
- bindings_.AddBinding(this, std::move(request));
-}
-
-void CORSURLLoaderFactory::OnConnectionError() {
- if (bindings_.empty() && loader_bindings_.empty())
- delete this;
-}
-
-} // namespace content
diff --git a/chromium/content/renderer/loader/cors_url_loader_factory.h b/chromium/content/renderer/loader/cors_url_loader_factory.h
deleted file mode 100644
index 2816a38611c..00000000000
--- a/chromium/content/renderer/loader/cors_url_loader_factory.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_RENDERER_LOADER_CORS_URL_LOADER_FACTORY_H_
-#define CONTENT_RENDERER_LOADER_CORS_URL_LOADER_FACTORY_H_
-
-#include "content/common/content_export.h"
-#include "content/common/possibly_associated_interface_ptr.h"
-#include "content/common/possibly_associated_interface_ptr_info.h"
-#include "mojo/public/cpp/bindings/binding_set.h"
-#include "mojo/public/cpp/bindings/strong_binding_set.h"
-#include "services/network/public/interfaces/url_loader_factory.mojom.h"
-
-namespace content {
-
-// URLLoaderFactory that adds cross-origin resource sharing capabilities
-// (https://www.w3.org/TR/cors/), delegating requests as well as potential
-// preflight requests to the supplied |network_loader_factory|. Its lifetime is
-// bound to that of the pipes connected to it and the CORSURLLoader instances it
-// creates.
-class CONTENT_EXPORT CORSURLLoaderFactory
- : public network::mojom::URLLoaderFactory {
- public:
- static void CreateAndBind(
- PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory>
- network_loader_factory,
- network::mojom::URLLoaderFactoryRequest request);
-
- explicit CORSURLLoaderFactory(
- PossiblyAssociatedInterfacePtrInfo<network::mojom::URLLoaderFactory>
- network_loader_factory);
- ~CORSURLLoaderFactory() override;
-
- // network::mojom::URLLoaderFactory
- void CreateLoaderAndStart(network::mojom::URLLoaderRequest request,
- int32_t routing_id,
- int32_t request_id,
- uint32_t options,
- const network::ResourceRequest& resource_request,
- network::mojom::URLLoaderClientPtr client,
- const net::MutableNetworkTrafficAnnotationTag&
- traffic_annotation) override;
- void Clone(network::mojom::URLLoaderFactoryRequest request) override;
-
- void OnConnectionError();
-
- private:
- PossiblyAssociatedInterfacePtr<network::mojom::URLLoaderFactory>
- network_loader_factory_;
-
- // The factory owns the CORSURLLoaders it creates so that they can share
- // |network_loader_factory_|.
- mojo::StrongBindingSet<network::mojom::URLLoader> loader_bindings_;
-
- mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_;
-};
-
-} // namespace content
-
-#endif // CONTENT_RENDERER_LOADER_CORS_URL_LOADER_FACTORY_H_
diff --git a/chromium/content/renderer/loader/cors_url_loader_unittest.cc b/chromium/content/renderer/loader/cors_url_loader_unittest.cc
deleted file mode 100644
index 8b54ee81bea..00000000000
--- a/chromium/content/renderer/loader/cors_url_loader_unittest.cc
+++ /dev/null
@@ -1,254 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/renderer/loader/cors_url_loader.h"
-
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "content/public/common/request_context_type.h"
-#include "content/public/common/resource_type.h"
-#include "content/public/test/test_url_loader_client.h"
-#include "content/renderer/loader/cors_url_loader_factory.h"
-#include "net/http/http_request_headers.h"
-#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
-#include "services/network/public/interfaces/url_loader.mojom.h"
-#include "services/network/public/interfaces/url_loader_factory.mojom.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using network::mojom::FetchRequestMode;
-
-namespace content {
-namespace {
-
-class TestURLLoaderFactory : public network::mojom::URLLoaderFactory {
- public:
- TestURLLoaderFactory() = default;
- ~TestURLLoaderFactory() override = default;
-
- void NotifyClientOnReceiveResponse(const std::string& extra_header) {
- DCHECK(client_ptr_);
- network::ResourceResponseHead response;
- response.headers = new net::HttpResponseHeaders(
- "HTTP/1.1 200 OK\n"
- "Content-Type: image/png\n");
- if (!extra_header.empty())
- response.headers->AddHeader(extra_header);
-
- client_ptr_->OnReceiveResponse(response, base::nullopt /* ssl_info */,
- nullptr /* downloaded_file */);
- }
-
- void NotifyClientOnComplete(int error_code) {
- DCHECK(client_ptr_);
- client_ptr_->OnComplete(network::URLLoaderCompletionStatus(error_code));
- }
-
- bool IsCreateLoaderAndStartCalled() { return !!client_ptr_; }
-
- private:
- // network::mojom::URLLoaderFactory implementation.
- void CreateLoaderAndStart(network::mojom::URLLoaderRequest request,
- int32_t routing_id,
- int32_t request_id,
- uint32_t options,
- const network::ResourceRequest& url_request,
- network::mojom::URLLoaderClientPtr client,
- const net::MutableNetworkTrafficAnnotationTag&
- traffic_annotation) override {
- DCHECK(client);
- client_ptr_ = std::move(client);
- }
-
- void Clone(network::mojom::URLLoaderFactoryRequest request) override {
- NOTREACHED();
- }
-
- network::mojom::URLLoaderClientPtr client_ptr_;
-
- DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory);
-};
-
-class CORSURLLoaderTest : public testing::Test {
- public:
- CORSURLLoaderTest()
- : test_network_factory_binding_(&test_network_loader_factory_) {}
-
- protected:
- void CreateLoaderAndStart(const GURL& origin,
- const GURL& url,
- FetchRequestMode fetch_request_mode) {
- network::mojom::URLLoaderFactoryPtr network_factory_ptr;
- test_network_factory_binding_.Bind(mojo::MakeRequest(&network_factory_ptr));
-
- network::mojom::URLLoaderFactoryPtr loader_factory_ptr;
- CORSURLLoaderFactory::CreateAndBind(network_factory_ptr.PassInterface(),
- mojo::MakeRequest(&loader_factory_ptr));
-
- network::ResourceRequest request;
- request.resource_type = RESOURCE_TYPE_IMAGE;
- request.fetch_request_context_type = REQUEST_CONTEXT_TYPE_IMAGE;
- request.fetch_request_mode = fetch_request_mode;
- request.method = net::HttpRequestHeaders::kGetMethod;
- request.url = url;
- request.request_initiator = url::Origin::Create(origin);
-
- loader_factory_ptr->CreateLoaderAndStart(
- mojo::MakeRequest(&url_loader_), 0 /* routing_id */, 0 /* request_id */,
- network::mojom::kURLLoadOptionNone, request,
- test_cors_loader_client_.CreateInterfacePtr(),
- net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS));
-
- // Flushes to ensure that the request is handled and
- // TestURLLoaderFactory::CreateLoaderAndStart() runs internally.
- loader_factory_ptr.FlushForTesting();
- }
-
- bool IsNetworkLoaderStarted() {
- return test_network_loader_factory_.IsCreateLoaderAndStartCalled();
- }
-
- void NotifyLoaderClientOnReceiveResponse(
- const std::string& extra_header = std::string()) {
- test_network_loader_factory_.NotifyClientOnReceiveResponse(extra_header);
- }
-
- void NotifyLoaderClientOnComplete(int error_code) {
- test_network_loader_factory_.NotifyClientOnComplete(error_code);
- }
-
- const TestURLLoaderClient& client() const { return test_cors_loader_client_; }
-
- void RunUntilComplete() { test_cors_loader_client_.RunUntilComplete(); }
-
- private:
- // Be the first member so it is destroyed last.
- base::MessageLoop message_loop_;
-
- // TestURLLoaderFactory instance and mojo binding.
- TestURLLoaderFactory test_network_loader_factory_;
- mojo::Binding<network::mojom::URLLoaderFactory> test_network_factory_binding_;
-
- // Holds URLLoaderPtr that CreateLoaderAndStart() creates.
- network::mojom::URLLoaderPtr url_loader_;
-
- // TestURLLoaderClient that records callback activities.
- TestURLLoaderClient test_cors_loader_client_;
-
- DISALLOW_COPY_AND_ASSIGN(CORSURLLoaderTest);
-};
-
-TEST_F(CORSURLLoaderTest, SameOriginRequest) {
- const GURL url("http://example.com/foo.png");
- CreateLoaderAndStart(url.GetOrigin(), url, FetchRequestMode::kSameOrigin);
-
- NotifyLoaderClientOnReceiveResponse();
- NotifyLoaderClientOnComplete(net::OK);
-
- RunUntilComplete();
-
- EXPECT_TRUE(IsNetworkLoaderStarted());
- EXPECT_FALSE(client().has_received_redirect());
- EXPECT_TRUE(client().has_received_response());
- EXPECT_TRUE(client().has_received_completion());
- EXPECT_EQ(net::OK, client().completion_status().error_code);
-}
-
-TEST_F(CORSURLLoaderTest, CrossOriginRequestWithNoCORSMode) {
- const GURL origin("http://example.com");
- const GURL url("http://other.com/foo.png");
- CreateLoaderAndStart(origin, url, FetchRequestMode::kNoCORS);
-
- NotifyLoaderClientOnReceiveResponse();
- NotifyLoaderClientOnComplete(net::OK);
-
- RunUntilComplete();
-
- EXPECT_TRUE(IsNetworkLoaderStarted());
- EXPECT_FALSE(client().has_received_redirect());
- EXPECT_TRUE(client().has_received_response());
- EXPECT_TRUE(client().has_received_completion());
- EXPECT_EQ(net::OK, client().completion_status().error_code);
-}
-
-TEST_F(CORSURLLoaderTest, CrossOriginRequestFetchRequestModeSameOrigin) {
- const GURL origin("http://example.com");
- const GURL url("http://other.com/foo.png");
- CreateLoaderAndStart(origin, url,
- network::mojom::FetchRequestMode::kSameOrigin);
-
- RunUntilComplete();
-
- // This call never hits the network URLLoader (i.e. the TestURLLoaderFactory)
- // because it is fails right away.
- EXPECT_FALSE(IsNetworkLoaderStarted());
- EXPECT_FALSE(client().has_received_redirect());
- EXPECT_FALSE(client().has_received_response());
- EXPECT_EQ(net::ERR_FAILED, client().completion_status().error_code);
- ASSERT_TRUE(client().completion_status().cors_error_status);
- EXPECT_EQ(network::mojom::CORSError::kDisallowedByMode,
- client().completion_status().cors_error_status->cors_error);
-}
-
-TEST_F(CORSURLLoaderTest, CrossOriginRequestWithCORSModeButMissingCORSHeader) {
- const GURL origin("http://example.com");
- const GURL url("http://other.com/foo.png");
- CreateLoaderAndStart(origin, url, FetchRequestMode::kCORS);
-
- NotifyLoaderClientOnReceiveResponse();
- NotifyLoaderClientOnComplete(net::OK);
-
- RunUntilComplete();
-
- EXPECT_TRUE(IsNetworkLoaderStarted());
- EXPECT_FALSE(client().has_received_redirect());
- EXPECT_FALSE(client().has_received_response());
- EXPECT_EQ(net::ERR_FAILED, client().completion_status().error_code);
- ASSERT_TRUE(client().completion_status().cors_error_status);
- EXPECT_EQ(network::mojom::CORSError::kMissingAllowOriginHeader,
- client().completion_status().cors_error_status->cors_error);
-}
-
-TEST_F(CORSURLLoaderTest, CrossOriginRequestWithCORSMode) {
- const GURL origin("http://example.com");
- const GURL url("http://other.com/foo.png");
- CreateLoaderAndStart(origin, url, FetchRequestMode::kCORS);
-
- NotifyLoaderClientOnReceiveResponse(
- "Access-Control-Allow-Origin: http://example.com");
- NotifyLoaderClientOnComplete(net::OK);
-
- RunUntilComplete();
-
- EXPECT_TRUE(IsNetworkLoaderStarted());
- EXPECT_FALSE(client().has_received_redirect());
- EXPECT_TRUE(client().has_received_response());
- EXPECT_TRUE(client().has_received_completion());
- EXPECT_EQ(net::OK, client().completion_status().error_code);
-}
-
-TEST_F(CORSURLLoaderTest,
- CrossOriginRequestFetchRequestWithCORSModeButMismatchedCORSHeader) {
- const GURL origin("http://example.com");
- const GURL url("http://other.com/foo.png");
- CreateLoaderAndStart(origin, url, FetchRequestMode::kCORS);
-
- NotifyLoaderClientOnReceiveResponse(
- "Access-Control-Allow-Origin: http://some-other-domain.com");
- NotifyLoaderClientOnComplete(net::OK);
-
- RunUntilComplete();
-
- EXPECT_TRUE(IsNetworkLoaderStarted());
- EXPECT_FALSE(client().has_received_redirect());
- EXPECT_FALSE(client().has_received_response());
- EXPECT_EQ(net::ERR_FAILED, client().completion_status().error_code);
- ASSERT_TRUE(client().completion_status().cors_error_status);
- EXPECT_EQ(network::mojom::CORSError::kAllowOriginMismatch,
- client().completion_status().cors_error_status->cors_error);
-}
-
-} // namespace
-} // namespace content
diff --git a/chromium/content/renderer/loader/request_extra_data.cc b/chromium/content/renderer/loader/request_extra_data.cc
index a1657c751e7..b9fce63a076 100644
--- a/chromium/content/renderer/loader/request_extra_data.cc
+++ b/chromium/content/renderer/loader/request_extra_data.cc
@@ -5,7 +5,6 @@
#include "content/renderer/loader/request_extra_data.h"
#include "content/common/service_worker/service_worker_types.h"
-#include "content/public/common/service_worker_modes.h"
#include "services/network/public/cpp/resource_request.h"
using blink::WebString;
@@ -22,7 +21,7 @@ RequestExtraData::RequestExtraData()
service_worker_provider_id_(kInvalidServiceWorkerProviderId),
originated_from_service_worker_(false),
initiated_in_secure_context_(false),
- is_prefetch_(false),
+ is_for_no_state_prefetch_(false),
download_to_network_cache_only_(false),
block_mixed_plugin_content_(false),
navigation_initiated_by_renderer_(false) {}
@@ -44,13 +43,6 @@ void RequestExtraData::CopyToResourceRequest(
request->originated_from_service_worker = originated_from_service_worker_;
request->initiated_in_secure_context = initiated_in_secure_context_;
-
- /*
- TODO(jam): if have agreement that alternate solution of having a dummy sink
- in the renderer so that notifications are still received, then undo
- the cl https://codereview.chromium.org/2262183002.
- request->download_to_network_cache_only = download_to_network_cache_only_;
- */
}
} // namespace content
diff --git a/chromium/content/renderer/loader/request_extra_data.h b/chromium/content/renderer/loader/request_extra_data.h
index a852e149423..d32c610e93a 100644
--- a/chromium/content/renderer/loader/request_extra_data.h
+++ b/chromium/content/renderer/loader/request_extra_data.h
@@ -13,7 +13,7 @@
#include "content/common/navigation_params.h"
#include "content/public/common/url_loader_throttle.h"
#include "content/renderer/loader/web_url_loader_impl.h"
-#include "third_party/WebKit/common/page/page_visibility_state.mojom.h"
+#include "third_party/WebKit/public/mojom/page/page_visibility_state.mojom.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "ui/base/page_transition_types.h"
@@ -98,16 +98,29 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData {
stream_override_ = std::move(stream_override);
}
+ // NavigationMojoResponse: |continue_navigation| is used to continue a
+ // navigation on the renderer process that has already been started on the
+ // browser process.
+ base::OnceClosure TakeContinueNavigationFunctionOwnerShip() {
+ return std::move(continue_navigation_function_);
+ }
+ void set_continue_navigation_function(base::OnceClosure continue_navigation) {
+ continue_navigation_function_ = std::move(continue_navigation);
+ }
+
void set_initiated_in_secure_context(bool secure) {
initiated_in_secure_context_ = secure;
}
- // The request is a prefetch and should use LOAD_PREFETCH network flags.
- bool is_prefetch() const { return is_prefetch_; }
- void set_is_prefetch(bool prefetch) { is_prefetch_ = prefetch; }
+ // The request is for a prefetch-only client (i.e. running NoStatePrefetch)
+ // and should use LOAD_PREFETCH network flags.
+ bool is_for_no_state_prefetch() const { return is_for_no_state_prefetch_; }
+ void set_is_for_no_state_prefetch(bool prefetch) {
+ is_for_no_state_prefetch_ = prefetch;
+ }
// The request is downloaded to the network cache, but not rendered or
- // executed. The renderer will see this as an aborted request.
+ // executed.
bool download_to_network_cache_only() const {
return download_to_network_cache_only_;
}
@@ -155,8 +168,11 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData {
blink::WebString custom_user_agent_;
blink::WebString requested_with_;
std::unique_ptr<StreamOverrideParameters> stream_override_;
+ // TODO(arthursonzogni): Once NavigationMojoResponse is launched, move most of
+ // the |stream_override_| content as parameters of this function.
+ base::OnceClosure continue_navigation_function_;
bool initiated_in_secure_context_;
- bool is_prefetch_;
+ bool is_for_no_state_prefetch_;
bool download_to_network_cache_only_;
bool block_mixed_plugin_content_;
bool navigation_initiated_by_renderer_;
diff --git a/chromium/content/renderer/loader/resource_dispatcher.cc b/chromium/content/renderer/loader/resource_dispatcher.cc
index 16f8c1da184..c29ac8509c0 100644
--- a/chromium/content/renderer/loader/resource_dispatcher.cc
+++ b/chromium/content/renderer/loader/resource_dispatcher.cc
@@ -24,7 +24,6 @@
#include "content/common/inter_process_time_ticks_converter.h"
#include "content/common/navigation_params.h"
#include "content/common/throttling_url_loader.h"
-#include "content/public/common/content_features.h"
#include "content/public/common/resource_type.h"
#include "content/public/renderer/fixed_received_data.h"
#include "content/public/renderer/request_peer.h"
@@ -39,6 +38,7 @@
#include "net/base/net_errors.h"
#include "net/base/request_priority.h"
#include "net/http/http_response_headers.h"
+#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
@@ -110,11 +110,8 @@ int ResourceDispatcher::MakeRequestID() {
return sequence.GetNext(); // We start at zero.
}
-ResourceDispatcher::ResourceDispatcher(
- scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner)
- : delegate_(nullptr),
- thread_task_runner_(thread_task_runner),
- weak_factory_(this) {}
+ResourceDispatcher::ResourceDispatcher()
+ : delegate_(nullptr), weak_factory_(this) {}
ResourceDispatcher::~ResourceDispatcher() {
}
@@ -122,10 +119,8 @@ ResourceDispatcher::~ResourceDispatcher() {
ResourceDispatcher::PendingRequestInfo*
ResourceDispatcher::GetPendingRequestInfo(int request_id) {
PendingRequestMap::iterator it = pending_requests_.find(request_id);
- if (it == pending_requests_.end()) {
- // This might happen for kill()ed requests on the webkit end.
+ if (it == pending_requests_.end())
return nullptr;
- }
return it->second.get();
}
@@ -300,7 +295,7 @@ void ResourceDispatcher::Cancel(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
PendingRequestMap::iterator it = pending_requests_.find(request_id);
if (it == pending_requests_.end()) {
- DVLOG(1) << "unknown request";
+ DLOG(ERROR) << "unknown request";
return;
}
@@ -330,7 +325,11 @@ void ResourceDispatcher::DidChangePriority(int request_id,
net::RequestPriority new_priority,
int intra_priority_value) {
PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
- DCHECK(request_info);
+ if (!request_info) {
+ DLOG(ERROR) << "unknown request";
+ return;
+ }
+
request_info->url_loader->SetPriority(new_priority, intra_priority_value);
}
@@ -415,7 +414,8 @@ int ResourceDispatcher::StartAsync(
std::unique_ptr<RequestPeer> peer,
scoped_refptr<SharedURLLoaderFactory> url_loader_factory,
std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
- network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints) {
+ network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
+ base::OnceClosure* continue_navigation_function) {
CheckSchemeForReferrerPolicy(*request);
// Compute a unique request_id for this renderer process.
@@ -430,10 +430,10 @@ int ResourceDispatcher::StartAsync(
std::make_unique<URLLoaderClientImpl>(request_id, this,
loading_task_runner);
- loading_task_runner->PostTask(
- FROM_HERE, base::BindOnce(&ResourceDispatcher::ContinueForNavigation,
- weak_factory_.GetWeakPtr(), request_id,
- std::move(url_loader_client_endpoints)));
+ DCHECK(continue_navigation_function);
+ *continue_navigation_function = base::BindOnce(
+ &ResourceDispatcher::ContinueForNavigation, weak_factory_.GetWeakPtr(),
+ request_id, std::move(url_loader_client_endpoints));
return request_id;
}
@@ -444,7 +444,7 @@ 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 (base::FeatureList::IsEnabled(features::kNetworkService) &&
+ if (base::FeatureList::IsEnabled(network::features::kNetworkService) &&
request->fetch_request_context_type != REQUEST_CONTEXT_TYPE_FETCH) {
// MIME sniffing should be disabled for a request initiated by fetch().
options |= network::mojom::kURLLoadOptionSniffMimeType;
diff --git a/chromium/content/renderer/loader/resource_dispatcher.h b/chromium/content/renderer/loader/resource_dispatcher.h
index d287525ef31..44de7552def 100644
--- a/chromium/content/renderer/loader/resource_dispatcher.h
+++ b/chromium/content/renderer/loader/resource_dispatcher.h
@@ -28,7 +28,7 @@
#include "mojo/public/cpp/system/data_pipe.h"
#include "net/base/request_priority.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
-#include "services/network/public/interfaces/url_loader.mojom.h"
+#include "services/network/public/mojom/url_loader.mojom.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "url/gurl.h"
#include "url/origin.h"
@@ -69,8 +69,7 @@ class CONTENT_EXPORT ResourceDispatcher {
// CORS preflight requests.
static int MakeRequestID();
- explicit ResourceDispatcher(
- scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner);
+ ResourceDispatcher();
virtual ~ResourceDispatcher();
// Call this method to load the resource synchronously (i.e., in one shot).
@@ -111,7 +110,8 @@ class CONTENT_EXPORT ResourceDispatcher {
std::unique_ptr<RequestPeer> peer,
scoped_refptr<SharedURLLoaderFactory> url_loader_factory,
std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
- network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints);
+ network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
+ base::OnceClosure* continue_navigation_function);
// Removes a request from the |pending_requests_| list, returning true if the
// request was found and removed.
@@ -138,11 +138,6 @@ class CONTENT_EXPORT ResourceDispatcher {
delegate_ = delegate;
}
- void SetThreadTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner) {
- thread_task_runner_ = thread_task_runner;
- }
-
base::WeakPtr<ResourceDispatcher> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
@@ -233,8 +228,6 @@ class CONTENT_EXPORT ResourceDispatcher {
ResourceDispatcherDelegate* delegate_;
- scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner_;
-
base::WeakPtrFactory<ResourceDispatcher> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher);
diff --git a/chromium/content/renderer/loader/resource_dispatcher_unittest.cc b/chromium/content/renderer/loader/resource_dispatcher_unittest.cc
index a90fa94495f..5f1a87e6b6b 100644
--- a/chromium/content/renderer/loader/resource_dispatcher_unittest.cc
+++ b/chromium/content/renderer/loader/resource_dispatcher_unittest.cc
@@ -23,7 +23,6 @@
#include "content/common/appcache_interfaces.h"
#include "content/common/weak_wrapper_shared_url_loader_factory.h"
#include "content/public/common/content_features.h"
-#include "content/public/common/service_worker_modes.h"
#include "content/public/renderer/fixed_received_data.h"
#include "content/public/renderer/request_peer.h"
#include "content/public/renderer/resource_dispatcher_delegate.h"
@@ -36,7 +35,7 @@
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
-#include "services/network/public/interfaces/request_context_frame_type.mojom.h"
+#include "services/network/public/mojom/request_context_frame_type.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
#include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_test_support.h"
@@ -57,8 +56,7 @@ static constexpr char kTestPageContents[] =
class ResourceDispatcherTest : public testing::Test,
public network::mojom::URLLoaderFactory {
public:
- ResourceDispatcherTest()
- : dispatcher_(new ResourceDispatcher(message_loop_.task_runner())) {}
+ ResourceDispatcherTest() : dispatcher_(new ResourceDispatcher()) {}
~ResourceDispatcherTest() override {
dispatcher_.reset();
@@ -122,7 +120,8 @@ class ResourceDispatcherTest : public testing::Test,
TRAFFIC_ANNOTATION_FOR_TESTS, false, std::move(peer),
base::MakeRefCounted<WeakWrapperSharedURLLoaderFactory>(this),
std::vector<std::unique_ptr<URLLoaderThrottle>>(),
- network::mojom::URLLoaderClientEndpointsPtr());
+ network::mojom::URLLoaderClientEndpointsPtr(),
+ nullptr /* continue_navigation_function */);
peer_context->request_id = request_id;
return request_id;
}
diff --git a/chromium/content/renderer/loader/shared_memory_data_consumer_handle.cc b/chromium/content/renderer/loader/shared_memory_data_consumer_handle.cc
index f216a6e0072..2551ead92fa 100644
--- a/chromium/content/renderer/loader/shared_memory_data_consumer_handle.cc
+++ b/chromium/content/renderer/loader/shared_memory_data_consumer_handle.cc
@@ -455,7 +455,9 @@ SharedMemoryDataConsumerHandle::~SharedMemoryDataConsumerHandle() {
}
std::unique_ptr<blink::WebDataConsumerHandle::Reader>
-SharedMemoryDataConsumerHandle::ObtainReader(Client* client) {
+SharedMemoryDataConsumerHandle::ObtainReader(
+ Client* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
return base::WrapUnique(new ReaderImpl(context_, client));
}
diff --git a/chromium/content/renderer/loader/shared_memory_data_consumer_handle.h b/chromium/content/renderer/loader/shared_memory_data_consumer_handle.h
index c5afb3842ed..7f68865c69a 100644
--- a/chromium/content/renderer/loader/shared_memory_data_consumer_handle.h
+++ b/chromium/content/renderer/loader/shared_memory_data_consumer_handle.h
@@ -81,7 +81,9 @@ class CONTENT_EXPORT SharedMemoryDataConsumerHandle final
std::unique_ptr<Writer>* writer);
~SharedMemoryDataConsumerHandle() override;
- std::unique_ptr<Reader> ObtainReader(Client* client) override;
+ std::unique_ptr<Reader> ObtainReader(
+ Client* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
private:
const char* DebugName() const override;
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 9a8f620a74e..0cc0ac3174f 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
@@ -142,7 +142,9 @@ class ThreadedSharedMemoryDataConsumerHandleTest : public ::testing::Test {
void ReadData() {
if (!client_) {
client_.reset(new ClientImpl(this));
- reader_ = handle_->ObtainReader(client_.get());
+ reader_ = handle_->ObtainReader(
+ client_.get(),
+ blink::scheduler::GetSingleThreadTaskRunnerForTesting());
}
Result rv = kOk;
@@ -217,7 +219,8 @@ void RunPostedTasks() {
TEST_P(SharedMemoryDataConsumerHandleTest, ReadFromEmpty) {
char buffer[4];
size_t read = 88;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
Result result = reader->Read(buffer, 4, kNone, &read);
EXPECT_EQ(kShouldWait, result);
@@ -229,7 +232,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, AutoClose) {
size_t read = 88;
writer_.reset();
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
Result result = reader->Read(buffer, 4, kNone, &read);
EXPECT_EQ(kDone, result);
@@ -241,7 +245,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, ReadSimple) {
char buffer[4] = {};
size_t read = 88;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
Result result = reader->Read(buffer, 3, kNone, &read);
EXPECT_EQ(kOk, result);
@@ -269,7 +274,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, ReadAfterHandleIsGone) {
char buffer[8] = {};
size_t read = 88;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
handle_.reset();
@@ -295,7 +301,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, ReObtainReader) {
char buffer[4] = {};
size_t read = 88;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
Result result = reader->Read(buffer, 3, kNone, &read);
EXPECT_EQ(kOk, result);
@@ -303,7 +310,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, ReObtainReader) {
EXPECT_STREQ("hel", buffer);
reader.reset();
- reader = handle_->ObtainReader(nullptr);
+ reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
result = reader->Read(buffer, 3, kNone, &read);
EXPECT_EQ(kOk, result);
@@ -327,7 +335,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, CloseBeforeReading) {
char buffer[20] = {};
size_t read = 88;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
Result result = reader->Read(buffer, sizeof(buffer), kNone, &read);
EXPECT_EQ(kOk, result);
@@ -344,7 +353,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, CloseWithDataBeforeZeroRead) {
writer_->Close();
size_t read = 88;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
Result result = reader->Read(nullptr, 0, kNone, &read);
EXPECT_EQ(kOk, result);
@@ -355,7 +365,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, CloseWithoutDataBeforeZeroRead) {
writer_->Close();
size_t read = 88;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
Result result = reader->Read(nullptr, 0, kNone, &read);
EXPECT_EQ(kDone, result);
@@ -375,7 +386,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, AddMultipleData) {
size_t read;
Result result;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
std::fill(&buffer[0], &buffer[arraysize(buffer)], 0);
result = reader->Read(buffer, 6, kNone, &read);
EXPECT_EQ(kOk, result);
@@ -419,7 +431,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, AddMultipleDataInteractively) {
size_t read;
Result result;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
std::fill(&buffer[0], &buffer[arraysize(buffer)], 0);
result = reader->Read(buffer, 6, kNone, &read);
EXPECT_EQ(kOk, result);
@@ -481,7 +494,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, RegisterClient) {
EXPECT_CALL(checkpoint, Call(4));
checkpoint.Call(0);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(1);
RunPostedTasks();
checkpoint.Call(2);
@@ -504,7 +518,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, RegisterClientWhenDataExists) {
checkpoint.Call(0);
writer_->AddData(NewFixedData("Once "));
checkpoint.Call(1);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(2);
RunPostedTasks();
checkpoint.Call(3);
@@ -527,7 +542,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, AddDataWhenClientIsRegistered) {
EXPECT_CALL(checkpoint, Call(5));
checkpoint.Call(0);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(1);
writer_->AddData(NewFixedData("Once "));
checkpoint.Call(2);
@@ -552,7 +568,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, CloseWithClientAndData) {
EXPECT_CALL(checkpoint, Call(3));
checkpoint.Call(0);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(1);
writer_->AddData(NewFixedData("Once "));
checkpoint.Call(2);
@@ -569,7 +586,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, ReleaseReader) {
EXPECT_CALL(checkpoint, Call(2));
checkpoint.Call(0);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(1);
reader.reset();
writer_->AddData(NewFixedData("Once "));
@@ -581,7 +599,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, TwoPhaseReadShouldWait) {
const void* buffer = &result;
size_t size = 99;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
result = reader->BeginRead(&buffer, kNone, &size);
EXPECT_EQ(kShouldWait, result);
EXPECT_EQ(nullptr, buffer);
@@ -595,7 +614,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, TwoPhaseReadSimple) {
const void* buffer = &result;
size_t size = 99;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
result = reader->BeginRead(&buffer, kNone, &size);
EXPECT_EQ(kOk, result);
EXPECT_EQ(5u, size);
@@ -666,7 +686,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, CallOnClearWhenDestructed2) {
handle_.reset(new SharedMemoryDataConsumerHandle(
kApplyBackpressure,
base::Bind(&DestructionTrackingFunction::Call, on_clear), &writer_));
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
handle_.reset();
on_clear = nullptr;
checkpoint.Call(1);
@@ -740,7 +761,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, TwoPhaseReadWithMultipleData) {
const void* buffer = &result;
size_t size = 99;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
result = reader->BeginRead(&buffer, kNone, &size);
EXPECT_EQ(kOk, result);
EXPECT_EQ(5u, size);
@@ -780,7 +802,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, ErrorRead) {
Result result;
char buffer[20] = {};
size_t read = 99;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
writer_->Fail();
result = reader->Read(buffer, sizeof(buffer), kNone, &read);
@@ -793,7 +816,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, ErrorTwoPhaseRead) {
Result result;
const void* pointer = &result;
size_t size = 99;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
writer_->Fail();
result = reader->BeginRead(&pointer, kNone, &size);
@@ -807,7 +831,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, FailWhileTwoPhaseReadIsInProgress) {
Result result;
const void* pointer = nullptr;
size_t size = 0;
- auto reader = handle_->ObtainReader(nullptr);
+ auto reader = handle_->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
writer_->AddData(NewFixedData("Once "));
result = reader->BeginRead(&pointer, kNone, &size);
@@ -843,7 +868,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, FailWithClient) {
EXPECT_CALL(checkpoint, Call(3));
checkpoint.Call(0);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(1);
writer_->Fail();
checkpoint.Call(2);
@@ -864,7 +890,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, FailWithClientAndData) {
EXPECT_CALL(checkpoint, Call(4));
checkpoint.Call(0);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(1);
writer_->AddData(NewFixedData("Once "));
checkpoint.Call(2);
@@ -887,7 +914,8 @@ TEST_P(SharedMemoryDataConsumerHandleTest, RecursiveErrorNotification) {
EXPECT_CALL(checkpoint, Call(3));
checkpoint.Call(0);
- auto reader = handle_->ObtainReader(&client_);
+ auto reader = handle_->ObtainReader(
+ &client_, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
checkpoint.Call(1);
writer_->AddData(NewFixedData("Once "));
checkpoint.Call(2);
@@ -914,7 +942,8 @@ TEST(SharedMemoryDataConsumerHandleBackpressureTest, Read) {
writer->AddData(
std::make_unique<LoggingFixedReceivedData>("data4", "time ", logger));
- auto reader = handle->ObtainReader(nullptr);
+ auto reader = handle->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
logger->Add("1");
result = reader->Read(buffer, 2, kNone, &size);
EXPECT_EQ(kOk, result);
@@ -957,7 +986,8 @@ TEST(SharedMemoryDataConsumerHandleBackpressureTest, CloseAndReset) {
writer->AddData(
std::make_unique<LoggingFixedReceivedData>("data3", "a ", logger));
- auto reader = handle->ObtainReader(nullptr);
+ auto reader = handle->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting());
logger->Add("1");
result = reader->Read(buffer, 2, kNone, &size);
EXPECT_EQ(kOk, result);
diff --git a/chromium/content/renderer/loader/site_isolation_stats_gatherer.cc b/chromium/content/renderer/loader/site_isolation_stats_gatherer.cc
index 60d5045a90d..d713b83cbd5 100644
--- a/chromium/content/renderer/loader/site_isolation_stats_gatherer.cc
+++ b/chromium/content/renderer/loader/site_isolation_stats_gatherer.cc
@@ -119,9 +119,7 @@ SiteIsolationStatsGatherer::OnReceivedResponse(
if (!CrossSiteDocumentClassifier::IsBlockableScheme(response_url))
return nullptr;
- // TODO(csharrison): Add a path for IsSameSite/IsValidCorsHeaderSet to take an
- // Origin.
- if (CrossSiteDocumentClassifier::IsSameSite(frame_origin, response_url))
+ if (frame_origin.IsSameOriginWith(url::Origin::Create(response_url)))
return nullptr;
CrossSiteDocumentMimeType canonical_mime_type =
@@ -140,7 +138,7 @@ SiteIsolationStatsGatherer::OnReceivedResponse(
info.headers->EnumerateHeader(nullptr, "access-control-allow-origin",
&access_control_origin);
if (CrossSiteDocumentClassifier::IsValidCorsHeaderSet(
- frame_origin, response_url, access_control_origin)) {
+ frame_origin, access_control_origin)) {
return nullptr;
}
diff --git a/chromium/content/renderer/loader/site_isolation_stats_gatherer_browsertest.cc b/chromium/content/renderer/loader/site_isolation_stats_gatherer_browsertest.cc
index 9d1fed14ad2..124eea57bce 100644
--- a/chromium/content/renderer/loader/site_isolation_stats_gatherer_browsertest.cc
+++ b/chromium/content/renderer/loader/site_isolation_stats_gatherer_browsertest.cc
@@ -16,6 +16,7 @@
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "services/network/public/cpp/network_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace content {
@@ -40,7 +41,7 @@ class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest {
// This allows us to use "real" hostnames in URLs, which we can use to
// create arbitrary SiteInstances.
command_line->AppendSwitchASCII(
- switches::kHostResolverRules,
+ network::switches::kHostResolverRules,
"MAP * " + embedded_test_server()->host_port_pair().ToString() +
",EXCLUDE localhost");
diff --git a/chromium/content/renderer/loader/sync_load_context.cc b/chromium/content/renderer/loader/sync_load_context.cc
index 5df463ce689..70c9ead0abf 100644
--- a/chromium/content/renderer/loader/sync_load_context.cc
+++ b/chromium/content/renderer/loader/sync_load_context.cc
@@ -35,7 +35,8 @@ void SyncLoadContext::StartAsyncWithWaitableEvent(
std::move(request), routing_id, std::move(loading_task_runner),
frame_origin, traffic_annotation, true /* is_sync */,
base::WrapUnique(context), context->url_loader_factory_,
- std::move(throttles), network::mojom::URLLoaderClientEndpointsPtr());
+ std::move(throttles), network::mojom::URLLoaderClientEndpointsPtr(),
+ nullptr /* continue_for_navigation */);
}
SyncLoadContext::SyncLoadContext(
@@ -49,8 +50,7 @@ SyncLoadContext::SyncLoadContext(
SharedURLLoaderFactory::Create(std::move(url_loader_factory));
// Constructs a new ResourceDispatcher specifically for this request.
- resource_dispatcher_ =
- std::make_unique<ResourceDispatcher>(base::ThreadTaskRunnerHandle::Get());
+ resource_dispatcher_ = std::make_unique<ResourceDispatcher>();
// Initialize the final URL with the original request URL. It will be
// overwritten on redirects.
diff --git a/chromium/content/renderer/loader/sync_load_response.h b/chromium/content/renderer/loader/sync_load_response.h
index 8682be6a384..049f2a287d0 100644
--- a/chromium/content/renderer/loader/sync_load_response.h
+++ b/chromium/content/renderer/loader/sync_load_response.h
@@ -10,7 +10,7 @@
#include "base/optional.h"
#include "content/common/content_export.h"
#include "services/network/public/cpp/resource_response_info.h"
-#include "services/network/public/interfaces/cors.mojom.h"
+#include "services/network/public/mojom/cors.mojom.h"
#include "url/gurl.h"
namespace content {
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
new file mode 100644
index 00000000000..c970d9aec49
--- /dev/null
+++ b/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.cc
@@ -0,0 +1,177 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/loader/tracked_child_url_loader_factory_bundle.h"
+
+#include "content/public/renderer/render_thread.h"
+
+namespace content {
+
+TrackedChildURLLoaderFactoryBundleInfo::
+ TrackedChildURLLoaderFactoryBundleInfo() = default;
+
+TrackedChildURLLoaderFactoryBundleInfo::TrackedChildURLLoaderFactoryBundleInfo(
+ network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
+ std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>
+ factories_info,
+ PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info,
+ std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle)
+ : ChildURLLoaderFactoryBundleInfo(std::move(default_factory_info),
+ std::move(factories_info),
+ std::move(direct_network_factory_info)),
+ main_thread_host_bundle_(std::move(main_thread_host_bundle)) {}
+
+TrackedChildURLLoaderFactoryBundleInfo::
+ ~TrackedChildURLLoaderFactoryBundleInfo() = default;
+
+scoped_refptr<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->direct_network_factory_info_ = std::move(direct_network_factory_info_);
+ other->main_thread_host_bundle_ = std::move(main_thread_host_bundle_);
+
+ return base::MakeRefCounted<TrackedChildURLLoaderFactoryBundle>(
+ std::move(other));
+}
+
+// -----------------------------------------------------------------------------
+
+TrackedChildURLLoaderFactoryBundle::TrackedChildURLLoaderFactoryBundle(
+ std::unique_ptr<TrackedChildURLLoaderFactoryBundleInfo> info) {
+ DCHECK(info->main_thread_host_bundle());
+ main_thread_host_bundle_ = std::move(info->main_thread_host_bundle());
+ Update(std::move(info));
+ AddObserverOnMainThread();
+}
+
+TrackedChildURLLoaderFactoryBundle::~TrackedChildURLLoaderFactoryBundle() {
+ RemoveObserverOnMainThread();
+};
+
+std::unique_ptr<SharedURLLoaderFactoryInfo>
+TrackedChildURLLoaderFactoryBundle::Clone() {
+ auto info = base::WrapUnique(static_cast<ChildURLLoaderFactoryBundleInfo*>(
+ ChildURLLoaderFactoryBundle::Clone().release()));
+
+ DCHECK(main_thread_host_bundle_);
+
+ auto main_thread_host_bundle_clone = std::make_unique<HostPtrAndTaskRunner>(
+ main_thread_host_bundle_->first, main_thread_host_bundle_->second);
+
+ return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>(
+ std::move(info->default_factory_info()),
+ std::move(info->factories_info()),
+ std::move(info->direct_network_factory_info()),
+ std::move(main_thread_host_bundle_clone));
+}
+
+void TrackedChildURLLoaderFactoryBundle::AddObserverOnMainThread() {
+ DCHECK(main_thread_host_bundle_);
+
+ // TODO(chongz): Change this to a DCHECK once all call sites have a
+ // SequencedTaskRunnerHandle.
+ if (!base::SequencedTaskRunnerHandle::IsSet())
+ return;
+
+ main_thread_host_bundle_->second->PostTask(
+ FROM_HERE,
+ base::BindOnce(
+ &HostChildURLLoaderFactoryBundle::AddObserver,
+ main_thread_host_bundle_->first, base::Unretained(this),
+ std::make_unique<
+ HostChildURLLoaderFactoryBundle::ObserverPtrAndTaskRunner>(
+ AsWeakPtr(), base::SequencedTaskRunnerHandle::Get())));
+}
+
+void TrackedChildURLLoaderFactoryBundle::RemoveObserverOnMainThread() {
+ DCHECK(main_thread_host_bundle_);
+
+ main_thread_host_bundle_->second->PostTask(
+ FROM_HERE,
+ base::BindOnce(&HostChildURLLoaderFactoryBundle::RemoveObserver,
+ main_thread_host_bundle_->first, base::Unretained(this)));
+}
+
+void TrackedChildURLLoaderFactoryBundle::OnUpdate(
+ std::unique_ptr<SharedURLLoaderFactoryInfo> info) {
+ Update(base::WrapUnique(
+ static_cast<ChildURLLoaderFactoryBundleInfo*>(info.release())));
+}
+
+// -----------------------------------------------------------------------------
+
+HostChildURLLoaderFactoryBundle::HostChildURLLoaderFactoryBundle()
+ : observer_list_(std::make_unique<ObserverList>()) {
+ DCHECK(RenderThread::Get()) << "HostChildURLLoaderFactoryBundle should live "
+ "on the main renderer thread";
+}
+
+HostChildURLLoaderFactoryBundle::~HostChildURLLoaderFactoryBundle() = default;
+
+std::unique_ptr<SharedURLLoaderFactoryInfo>
+HostChildURLLoaderFactoryBundle::Clone() {
+ auto info = base::WrapUnique(static_cast<ChildURLLoaderFactoryBundleInfo*>(
+ ChildURLLoaderFactoryBundle::Clone().release()));
+
+ DCHECK(base::SequencedTaskRunnerHandle::IsSet());
+ auto main_thread_host_bundle_clone = std::make_unique<
+ TrackedChildURLLoaderFactoryBundle::HostPtrAndTaskRunner>(
+ AsWeakPtr(), base::SequencedTaskRunnerHandle::Get());
+
+ return std::make_unique<TrackedChildURLLoaderFactoryBundleInfo>(
+ std::move(info->default_factory_info()),
+ std::move(info->factories_info()),
+ std::move(info->direct_network_factory_info()),
+ std::move(main_thread_host_bundle_clone));
+}
+
+void HostChildURLLoaderFactoryBundle::UpdateThisAndAllClones(
+ std::unique_ptr<URLLoaderFactoryBundleInfo> info) {
+ DCHECK(RenderThread::Get()) << "Should run on the main renderer thread";
+ DCHECK(observer_list_);
+
+ auto partial_bundle = base::MakeRefCounted<ChildURLLoaderFactoryBundle>();
+ static_cast<URLLoaderFactoryBundle*>(partial_bundle.get())
+ ->Update(std::move(info));
+
+ for (const auto& iter : *observer_list_) {
+ NotifyUpdateOnMainOrWorkerThread(iter.second.get(),
+ partial_bundle->Clone());
+ }
+
+ Update(partial_bundle->PassInterface());
+}
+
+bool HostChildURLLoaderFactoryBundle::IsHostChildURLLoaderFactoryBundle()
+ const {
+ return true;
+}
+
+void HostChildURLLoaderFactoryBundle::AddObserver(
+ TrackedChildURLLoaderFactoryBundle* observer,
+ std::unique_ptr<ObserverPtrAndTaskRunner> observer_info) {
+ DCHECK(RenderThread::Get()) << "Should run in the main renderer thread";
+ DCHECK(observer_list_);
+ (*observer_list_)[observer] = std::move(observer_info);
+}
+
+void HostChildURLLoaderFactoryBundle::RemoveObserver(
+ TrackedChildURLLoaderFactoryBundle* observer) {
+ DCHECK(RenderThread::Get()) << "Should run in the main renderer thread";
+ DCHECK(observer_list_);
+ observer_list_->erase(observer);
+}
+
+void HostChildURLLoaderFactoryBundle::NotifyUpdateOnMainOrWorkerThread(
+ ObserverPtrAndTaskRunner* observer_bundle,
+ std::unique_ptr<SharedURLLoaderFactoryInfo> update_info) {
+ observer_bundle->second->PostTask(
+ FROM_HERE,
+ base::BindOnce(&TrackedChildURLLoaderFactoryBundle::OnUpdate,
+ observer_bundle->first, std::move(update_info)));
+}
+
+} // namespace content
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
new file mode 100644
index 00000000000..8d2a49380cd
--- /dev/null
+++ b/chromium/content/renderer/loader/tracked_child_url_loader_factory_bundle.h
@@ -0,0 +1,153 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
+#define CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
+
+#include "content/common/content_export.h"
+#include "content/renderer/loader/child_url_loader_factory_bundle.h"
+
+namespace content {
+
+class HostChildURLLoaderFactoryBundle;
+
+// Holds the internal state of a |TrackedChildURLLoaderFactoryBundle| in a form
+// that is safe to pass across sequences.
+class CONTENT_EXPORT TrackedChildURLLoaderFactoryBundleInfo
+ : public ChildURLLoaderFactoryBundleInfo {
+ public:
+ using HostPtrAndTaskRunner =
+ std::pair<base::WeakPtr<HostChildURLLoaderFactoryBundle>,
+ scoped_refptr<base::SequencedTaskRunner>>;
+
+ TrackedChildURLLoaderFactoryBundleInfo();
+ TrackedChildURLLoaderFactoryBundleInfo(
+ network::mojom::URLLoaderFactoryPtrInfo default_factory_info,
+ std::map<std::string, network::mojom::URLLoaderFactoryPtrInfo>
+ factories_info,
+ PossiblyAssociatedURLLoaderFactoryPtrInfo direct_network_factory_info,
+ std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle);
+ ~TrackedChildURLLoaderFactoryBundleInfo() override;
+
+ std::unique_ptr<HostPtrAndTaskRunner>& main_thread_host_bundle() {
+ return main_thread_host_bundle_;
+ }
+
+ protected:
+ // ChildURLLoaderFactoryBundleInfo overrides.
+ scoped_refptr<SharedURLLoaderFactory> CreateFactory() override;
+
+ std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle_;
+
+ DISALLOW_COPY_AND_ASSIGN(TrackedChildURLLoaderFactoryBundleInfo);
+};
+
+// This class extends |ChildURLLoaderFactoryBundle| to support a host/observer
+// tracking logic. There will be a single |HostChildURLLoaderFactoryBundle|
+// owned by |RenderFrameImpl| which lives on the main thread, and multiple
+// |TrackedChildURLLoaderFactoryBundle| on the worker thread (for Workers) or
+// the main thread (for frames from 'window.open()').
+// Both |Host/TrackedChildURLLoaderFactoryBundle::Clone()| can be used to create
+// a tracked bundle to the original host bundle.
+// These two classes are required to bring bundles back online in the event of
+// Network Service crash.
+class CONTENT_EXPORT TrackedChildURLLoaderFactoryBundle
+ : public ChildURLLoaderFactoryBundle,
+ public base::SupportsWeakPtr<TrackedChildURLLoaderFactoryBundle> {
+ public:
+ using HostPtrAndTaskRunner =
+ std::pair<base::WeakPtr<HostChildURLLoaderFactoryBundle>,
+ scoped_refptr<base::SequencedTaskRunner>>;
+
+ // Posts a task to the host bundle on main thread to start tracking |this|.
+ explicit TrackedChildURLLoaderFactoryBundle(
+ std::unique_ptr<TrackedChildURLLoaderFactoryBundleInfo> info);
+
+ // ChildURLLoaderFactoryBundle overrides.
+ // Returns |std::unique_ptr<TrackedChildURLLoaderFactoryBundleInfo>|.
+ std::unique_ptr<SharedURLLoaderFactoryInfo> Clone() override;
+
+ private:
+ friend class HostChildURLLoaderFactoryBundle;
+
+ // Posts a task to the host bundle on main thread to stop tracking |this|.
+ ~TrackedChildURLLoaderFactoryBundle() override;
+
+ // Helper method to post a task to the host bundle on main thread to start
+ // tracking |this|.
+ void AddObserverOnMainThread();
+
+ // Helper method to post a task to the host bundle on main thread to start
+ // tracking |this|.
+ void RemoveObserverOnMainThread();
+
+ // Callback method to receive updates from the host bundle.
+ void OnUpdate(std::unique_ptr<SharedURLLoaderFactoryInfo> info);
+
+ // |WeakPtr| and |TaskRunner| of the host bundle. Can be copied and passed
+ // across sequences.
+ std::unique_ptr<HostPtrAndTaskRunner> main_thread_host_bundle_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(TrackedChildURLLoaderFactoryBundle);
+};
+
+// |HostChildURLLoaderFactoryBundle| lives entirely on the main thread, and all
+// methods should be invoked on the main thread or through PostTask. See
+// comments in |TrackedChildURLLoaderFactoryBundle| for details about the
+// tracking logic.
+class CONTENT_EXPORT HostChildURLLoaderFactoryBundle
+ : public ChildURLLoaderFactoryBundle,
+ public base::SupportsWeakPtr<HostChildURLLoaderFactoryBundle> {
+ public:
+ using ObserverPtrAndTaskRunner =
+ std::pair<base::WeakPtr<TrackedChildURLLoaderFactoryBundle>,
+ scoped_refptr<base::SequencedTaskRunner>>;
+ using ObserverList =
+ std::unordered_map<TrackedChildURLLoaderFactoryBundle*,
+ std::unique_ptr<ObserverPtrAndTaskRunner>>;
+
+ HostChildURLLoaderFactoryBundle();
+
+ // ChildURLLoaderFactoryBundle overrides.
+ // Returns |std::unique_ptr<TrackedChildURLLoaderFactoryBundleInfo>|.
+ std::unique_ptr<SharedURLLoaderFactoryInfo> Clone() override;
+ 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.
+ void UpdateThisAndAllClones(std::unique_ptr<URLLoaderFactoryBundleInfo> info);
+
+ private:
+ friend class TrackedChildURLLoaderFactoryBundle;
+
+ ~HostChildURLLoaderFactoryBundle() override;
+
+ // Must be called by the newly created |TrackedChildURLLoaderFactoryBundle|.
+ // |TrackedChildURLLoaderFactoryBundle*| serves as the key and doesn't have to
+ // remain valid.
+ void AddObserver(TrackedChildURLLoaderFactoryBundle* observer,
+ std::unique_ptr<ObserverPtrAndTaskRunner> observer_info);
+
+ // Must be called by the observer before it was destroyed.
+ // |TrackedChildURLLoaderFactoryBundle*| serves as the key and doesn't have to
+ // remain valid.
+ void RemoveObserver(TrackedChildURLLoaderFactoryBundle* observer);
+
+ // Post an update to the tracked bundle on the worker thread (for Workers) or
+ // the main thread (for frames from 'window.open()'). Safe to use after the
+ // tracked bundle has been destroyed.
+ void NotifyUpdateOnMainOrWorkerThread(
+ ObserverPtrAndTaskRunner* observer_bundle,
+ std::unique_ptr<SharedURLLoaderFactoryInfo> update_info);
+
+ // Contains |WeakPtr| and |TaskRunner| to tracked bundles.
+ std::unique_ptr<ObserverList> observer_list_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(HostChildURLLoaderFactoryBundle);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_LOADER_TRACKED_CHILD_URL_LOADER_FACTORY_BUNDLE_H_
diff --git a/chromium/content/renderer/loader/url_loader_client_impl.h b/chromium/content/renderer/loader/url_loader_client_impl.h
index 676c6d3f941..d42044af045 100644
--- a/chromium/content/renderer/loader/url_loader_client_impl.h
+++ b/chromium/content/renderer/loader/url_loader_client_impl.h
@@ -13,7 +13,7 @@
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/system/data_pipe.h"
-#include "services/network/public/interfaces/url_loader.mojom.h"
+#include "services/network/public/mojom/url_loader.mojom.h"
namespace base {
class SingleThreadTaskRunner;
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 8b952c3802b..b71a08ed8b7 100644
--- a/chromium/content/renderer/loader/url_loader_client_impl_unittest.cc
+++ b/chromium/content/renderer/loader/url_loader_client_impl_unittest.cc
@@ -15,7 +15,7 @@
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/redirect_info.h"
-#include "services/network/public/interfaces/url_loader_factory.mojom.h"
+#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_test_support.h"
@@ -24,8 +24,7 @@ namespace content {
class URLLoaderClientImplTest : public ::testing::Test,
public network::mojom::URLLoaderFactory {
protected:
- URLLoaderClientImplTest()
- : dispatcher_(new ResourceDispatcher(message_loop_.task_runner())) {
+ URLLoaderClientImplTest() : dispatcher_(new ResourceDispatcher()) {
request_id_ = dispatcher_->StartAsync(
std::make_unique<network::ResourceRequest>(), 0,
blink::scheduler::GetSingleThreadTaskRunnerForTesting(), url::Origin(),
@@ -34,7 +33,8 @@ class URLLoaderClientImplTest : public ::testing::Test,
&request_peer_context_),
base::MakeRefCounted<WeakWrapperSharedURLLoaderFactory>(this),
std::vector<std::unique_ptr<URLLoaderThrottle>>(),
- network::mojom::URLLoaderClientEndpointsPtr());
+ network::mojom::URLLoaderClientEndpointsPtr(),
+ nullptr /* continue_navigation_function */);
request_peer_context_.request_id = request_id_;
base::RunLoop().RunUntilIdle();
diff --git a/chromium/content/renderer/loader/url_response_body_consumer.h b/chromium/content/renderer/loader/url_response_body_consumer.h
index 6f27081b98f..3b6061b346c 100644
--- a/chromium/content/renderer/loader/url_response_body_consumer.h
+++ b/chromium/content/renderer/loader/url_response_body_consumer.h
@@ -18,7 +18,7 @@
#include "content/common/content_export.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/simple_watcher.h"
-#include "services/network/public/interfaces/url_loader.mojom.h"
+#include "services/network/public/mojom/url_loader.mojom.h"
namespace network {
struct URLLoaderCompletionStatus;
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 7fb870ea45c..c7a6630f14f 100644
--- a/chromium/content/renderer/loader/url_response_body_consumer_unittest.cc
+++ b/chromium/content/renderer/loader/url_response_body_consumer_unittest.cc
@@ -12,7 +12,6 @@
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "content/common/weak_wrapper_shared_url_loader_factory.h"
-#include "content/public/common/service_worker_modes.h"
#include "content/public/renderer/request_peer.h"
#include "content/renderer/loader/request_extra_data.h"
#include "content/renderer/loader/resource_dispatcher.h"
@@ -20,7 +19,7 @@
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
-#include "services/network/public/interfaces/request_context_frame_type.mojom.h"
+#include "services/network/public/mojom/request_context_frame_type.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "url/gurl.h"
@@ -113,8 +112,7 @@ class URLResponseBodyConsumerTest : public ::testing::Test {
std::vector<network::mojom::URLLoaderClientPtr> clients_;
};
- URLResponseBodyConsumerTest()
- : dispatcher_(new ResourceDispatcher(message_loop_.task_runner())) {}
+ URLResponseBodyConsumerTest() : dispatcher_(new ResourceDispatcher()) {}
~URLResponseBodyConsumerTest() override {
dispatcher_.reset();
@@ -157,7 +155,8 @@ class URLResponseBodyConsumerTest : public ::testing::Test {
std::make_unique<TestRequestPeer>(context, message_loop_.task_runner()),
base::MakeRefCounted<WeakWrapperSharedURLLoaderFactory>(&factory_),
std::vector<std::unique_ptr<URLLoaderThrottle>>(),
- network::mojom::URLLoaderClientEndpointsPtr());
+ network::mojom::URLLoaderClientEndpointsPtr(),
+ nullptr /* continue_navigation_function */);
}
void Run(TestRequestPeer::Context* context) {
diff --git a/chromium/content/renderer/loader/web_data_consumer_handle_impl.cc b/chromium/content/renderer/loader/web_data_consumer_handle_impl.cc
index bc8386ed388..b97d43b62cc 100644
--- a/chromium/content/renderer/loader/web_data_consumer_handle_impl.cc
+++ b/chromium/content/renderer/loader/web_data_consumer_handle_impl.cc
@@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
+#include "base/single_thread_task_runner.h"
#include "mojo/public/c/system/types.h"
namespace content {
@@ -36,9 +37,12 @@ class WebDataConsumerHandleImpl::Context
WebDataConsumerHandleImpl::ReaderImpl::ReaderImpl(
scoped_refptr<Context> context,
- Client* client)
+ Client* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: context_(context),
- handle_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL),
+ handle_watcher_(FROM_HERE,
+ mojo::SimpleWatcher::ArmingPolicy::MANUAL,
+ std::move(task_runner)),
client_(client) {
if (client_)
StartWatching();
@@ -147,8 +151,11 @@ WebDataConsumerHandleImpl::~WebDataConsumerHandleImpl() {
}
std::unique_ptr<blink::WebDataConsumerHandle::Reader>
-WebDataConsumerHandleImpl::ObtainReader(Client* client) {
- return base::WrapUnique(new ReaderImpl(context_, client));
+WebDataConsumerHandleImpl::ObtainReader(
+ Client* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
+ return base::WrapUnique(
+ new ReaderImpl(context_, client, std::move(task_runner)));
}
const char* WebDataConsumerHandleImpl::DebugName() const {
diff --git a/chromium/content/renderer/loader/web_data_consumer_handle_impl.h b/chromium/content/renderer/loader/web_data_consumer_handle_impl.h
index 5a9a018dad4..740e80c7553 100644
--- a/chromium/content/renderer/loader/web_data_consumer_handle_impl.h
+++ b/chromium/content/renderer/loader/web_data_consumer_handle_impl.h
@@ -24,7 +24,9 @@ class CONTENT_EXPORT WebDataConsumerHandleImpl final
public:
class CONTENT_EXPORT ReaderImpl final : public Reader {
public:
- ReaderImpl(scoped_refptr<Context> context, Client* client);
+ ReaderImpl(scoped_refptr<Context> context,
+ Client* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~ReaderImpl() override;
Result Read(void* data,
size_t size,
@@ -46,7 +48,9 @@ class CONTENT_EXPORT WebDataConsumerHandleImpl final
DISALLOW_COPY_AND_ASSIGN(ReaderImpl);
};
- std::unique_ptr<Reader> ObtainReader(Client* client) override;
+ std::unique_ptr<Reader> ObtainReader(
+ Client* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
explicit WebDataConsumerHandleImpl(Handle handle);
~WebDataConsumerHandleImpl() override;
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 4d774e4f9c9..91e49c1a2bc 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
@@ -81,7 +81,9 @@ class ReadDataOperation : public ReadDataOperationBase {
void ReadData() {
if (!client_) {
client_.reset(new ClientImpl(this));
- reader_ = handle_->ObtainReader(client_.get());
+ reader_ = handle_->ObtainReader(
+ client_.get(),
+ blink::scheduler::GetSingleThreadTaskRunnerForTesting());
}
Result rv = kOk;
@@ -139,7 +141,9 @@ class TwoPhaseReadDataOperation : public ReadDataOperationBase {
void ReadData() {
if (!client_) {
client_.reset(new ClientImpl(this));
- reader_ = handle_->ObtainReader(client_.get());
+ reader_ = handle_->ObtainReader(
+ client_.get(),
+ blink::scheduler::GetSingleThreadTaskRunnerForTesting());
}
Result rv;
@@ -286,8 +290,8 @@ TEST_F(WebDataConsumerHandleImplTest, ZeroSizeRead) {
constexpr size_t data_size = kDataPipeCapacity - 1;
std::unique_ptr<WebDataConsumerHandleImpl> handle(
new WebDataConsumerHandleImpl(std::move(consumer_)));
- std::unique_ptr<WebDataConsumerHandle::Reader> reader(
- handle->ObtainReader(nullptr));
+ std::unique_ptr<WebDataConsumerHandle::Reader> reader(handle->ObtainReader(
+ nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting()));
size_t read_size;
WebDataConsumerHandle::Result rv =
@@ -329,8 +333,8 @@ TEST_F(WebDataConsumerHandleImplTest, DidGetReadable) {
std::make_unique<CountDidGetReadableClient>();
std::unique_ptr<WebDataConsumerHandleImpl> handle(
new WebDataConsumerHandleImpl(std::move(consumer_)));
- std::unique_ptr<WebDataConsumerHandle::Reader> reader(
- handle->ObtainReader(client.get()));
+ std::unique_ptr<WebDataConsumerHandle::Reader> reader(handle->ObtainReader(
+ client.get(), blink::scheduler::GetSingleThreadTaskRunnerForTesting()));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, client->num_did_get_readable_called());
diff --git a/chromium/content/renderer/loader/web_url_loader_impl.cc b/chromium/content/renderer/loader/web_url_loader_impl.cc
index 02eb4997464..718af1ef082 100644
--- a/chromium/content/renderer/loader/web_url_loader_impl.cc
+++ b/chromium/content/renderer/loader/web_url_loader_impl.cc
@@ -27,13 +27,10 @@
#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/common/weak_wrapper_shared_url_loader_factory.h"
#include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/common/content_features.h"
#include "content/public/common/previews_state.h"
#include "content/public/common/referrer.h"
-#include "content/public/common/service_worker_modes.h"
-#include "content/public/renderer/child_url_loader_factory_getter.h"
#include "content/public/renderer/fixed_received_data.h"
#include "content/public/renderer/request_peer.h"
#include "content/renderer/loader/ftp_directory_listing_response_delegate.h"
@@ -55,11 +52,11 @@
#include "net/ssl/ssl_cipher_suite_names.h"
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/url_request/url_request_data_job.h"
-#include "services/network/public/cpp/loader_util.h"
+#include "services/network/loader_util.h"
#include "services/network/public/cpp/resource_request.h"
-#include "services/network/public/interfaces/request_context_frame_type.mojom.h"
-#include "services/network/public/interfaces/url_loader.mojom.h"
-#include "third_party/WebKit/common/mime_util/mime_util.h"
+#include "services/network/public/mojom/request_context_frame_type.mojom.h"
+#include "services/network/public/mojom/url_loader.mojom.h"
+#include "third_party/WebKit/public/common/mime_util/mime_util.h"
#include "third_party/WebKit/public/platform/FilePathConversion.h"
#include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h"
#include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
@@ -362,9 +359,9 @@ StreamOverrideParameters::~StreamOverrideParameters() {
WebURLLoaderFactoryImpl::WebURLLoaderFactoryImpl(
base::WeakPtr<ResourceDispatcher> resource_dispatcher,
- scoped_refptr<ChildURLLoaderFactoryGetter> loader_factory_getter)
+ scoped_refptr<SharedURLLoaderFactory> loader_factory)
: resource_dispatcher_(std::move(resource_dispatcher)),
- loader_factory_getter_(std::move(loader_factory_getter)) {}
+ loader_factory_(std::move(loader_factory)) {}
WebURLLoaderFactoryImpl::~WebURLLoaderFactoryImpl() = default;
@@ -376,10 +373,9 @@ WebURLLoaderFactoryImpl::CreateTestOnlyFactory() {
std::unique_ptr<blink::WebURLLoader> WebURLLoaderFactoryImpl::CreateURLLoader(
const blink::WebURLRequest& request,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
- if (!loader_factory_getter_) {
- // In some tests like RenderViewTests loader_factory_getter_ is not
- // available. These tests can still use data URLs to bypass the
- // ResourceDispatcher.
+ if (!loader_factory_) {
+ // In some tests like RenderViewTests loader_factory_ is not available.
+ // These tests can still use data URLs to bypass the ResourceDispatcher.
if (!task_runner)
task_runner = base::ThreadTaskRunnerHandle::Get();
return std::make_unique<WebURLLoaderImpl>(resource_dispatcher_.get(),
@@ -389,12 +385,8 @@ std::unique_ptr<blink::WebURLLoader> WebURLLoaderFactoryImpl::CreateURLLoader(
DCHECK(task_runner);
DCHECK(resource_dispatcher_);
- // TODO(crbug.com/796425): Temporarily wrap the raw mojom::URLLoaderFactory
- // pointer into SharedURLLoaderFactory.
return std::make_unique<WebURLLoaderImpl>(
- resource_dispatcher_.get(), std::move(task_runner),
- base::MakeRefCounted<WeakWrapperSharedURLLoaderFactory>(
- loader_factory_getter_->GetFactoryForURL(request.Url())));
+ resource_dispatcher_.get(), std::move(task_runner), loader_factory_);
}
// This inner class exists since the WebURLLoader may be deleted while inside a
@@ -479,7 +471,9 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context> {
// Context and held by ResourceDispatcher.
class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer {
public:
- explicit RequestPeerImpl(Context* context);
+ // If |discard_body| is false this doesn't propagate the received data
+ // to the context.
+ explicit RequestPeerImpl(Context* context, bool discard_body = false);
// RequestPeer methods:
void OnUploadProgress(uint64_t position, uint64_t size) override;
@@ -495,6 +489,7 @@ class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer {
private:
scoped_refptr<Context> context_;
+ const bool discard_body_;
DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl);
};
@@ -675,8 +670,6 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
}
resource_request->load_flags = GetLoadFlagsForWebURLRequest(request);
- if (resource_request->resource_type == RESOURCE_TYPE_PREFETCH)
- resource_request->load_flags |= net::LOAD_PREFETCH;
// |plugin_child_id| only needs to be non-zero if the request originates
// outside the render process, so we can use requestorProcessID even
@@ -688,8 +681,7 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
resource_request->should_reset_appcache = request.ShouldResetAppCache();
resource_request->is_external_request = request.IsExternalRequest();
resource_request->cors_preflight_policy = request.GetCORSPreflightPolicy();
- resource_request->service_worker_mode =
- static_cast<int>(GetServiceWorkerModeForWebURLRequest(request));
+ resource_request->skip_service_worker = request.GetSkipServiceWorker();
resource_request->fetch_request_mode = request.GetFetchRequestMode();
resource_request->fetch_credentials_mode = request.GetFetchCredentialsMode();
resource_request->fetch_redirect_mode = request.GetFetchRedirectMode();
@@ -757,17 +749,23 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
if (extra_data->download_to_network_cache_only()) {
peer = std::make_unique<SinkPeer>(this);
} else {
- peer = std::make_unique<WebURLLoaderImpl::RequestPeerImpl>(this);
+ const bool discard_body =
+ (resource_request->resource_type == RESOURCE_TYPE_PREFETCH);
+ peer =
+ std::make_unique<WebURLLoaderImpl::RequestPeerImpl>(this, discard_body);
}
TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this,
TRACE_EVENT_FLAG_FLOW_OUT);
+ base::OnceClosure continue_navigation_function;
request_id_ = resource_dispatcher_->StartAsync(
std::move(resource_request), request.RequestorID(), task_runner_,
extra_data->frame_origin(), GetTrafficAnnotationTag(request),
false /* is_sync */, std::move(peer), url_loader_factory_,
extra_data->TakeURLLoaderThrottles(),
- std::move(url_loader_client_endpoints));
+ std::move(url_loader_client_endpoints), &continue_navigation_function);
+ extra_data->set_continue_navigation_function(
+ std::move(continue_navigation_function));
if (defers_loading_ != NOT_DEFERRING)
resource_dispatcher_->SetDefersLoading(request_id_, true);
@@ -1087,8 +1085,9 @@ void WebURLLoaderImpl::Context::HandleDataURL() {
// WebURLLoaderImpl::RequestPeerImpl ------------------------------------------
-WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context)
- : context_(context) {}
+WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context,
+ bool discard_body)
+ : context_(context), discard_body_(discard_body) {}
void WebURLLoaderImpl::RequestPeerImpl::OnUploadProgress(uint64_t position,
uint64_t size) {
@@ -1114,6 +1113,8 @@ void WebURLLoaderImpl::RequestPeerImpl::OnDownloadedData(
void WebURLLoaderImpl::RequestPeerImpl::OnReceivedData(
std::unique_ptr<ReceivedData> data) {
+ if (discard_body_)
+ return;
context_->OnReceivedData(std::move(data));
}
@@ -1125,6 +1126,8 @@ void WebURLLoaderImpl::RequestPeerImpl::OnTransferSizeUpdated(
void WebURLLoaderImpl::RequestPeerImpl::OnReceivedCachedMetadata(
const char* data,
int len) {
+ if (discard_body_)
+ return;
context_->OnReceivedCachedMetadata(data, len);
}
@@ -1172,8 +1175,8 @@ void WebURLLoaderImpl::PopulateURLResponse(
response->SetHasMajorCertificateErrors(
net::IsCertStatusError(info.cert_status) &&
!net::IsCertStatusMinorError(info.cert_status));
+ response->SetCTPolicyCompliance(info.ct_policy_compliance);
response->SetIsLegacySymantecCert(info.is_legacy_symantec_cert);
- response->SetCertValidityStart(info.cert_validity_start);
response->SetAppCacheID(info.appcache_id);
response->SetAppCacheManifestURL(info.appcache_manifest_url);
response->SetWasCached(!info.load_timing.request_start_time.is_null() &&
diff --git a/chromium/content/renderer/loader/web_url_loader_impl.h b/chromium/content/renderer/loader/web_url_loader_impl.h
index a408937c026..1986f56a4ac 100644
--- a/chromium/content/renderer/loader/web_url_loader_impl.h
+++ b/chromium/content/renderer/loader/web_url_loader_impl.h
@@ -16,8 +16,8 @@
#include "mojo/public/cpp/system/data_pipe.h"
#include "net/url_request/redirect_info.h"
#include "services/network/public/cpp/resource_response.h"
-#include "services/network/public/interfaces/url_loader.mojom.h"
-#include "services/network/public/interfaces/url_loader_factory.mojom.h"
+#include "services/network/public/mojom/url_loader.mojom.h"
+#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "third_party/WebKit/public/platform/WebURLLoader.h"
#include "third_party/WebKit/public/platform/WebURLLoaderFactory.h"
#include "url/gurl.h"
@@ -32,7 +32,6 @@ struct ResourceResponseInfo;
namespace content {
-class ChildURLLoaderFactoryGetter;
class ResourceDispatcher;
// PlzNavigate: Used to override parameters of the navigation request.
@@ -57,9 +56,8 @@ struct CONTENT_EXPORT StreamOverrideParameters {
class CONTENT_EXPORT WebURLLoaderFactoryImpl
: public blink::WebURLLoaderFactory {
public:
- WebURLLoaderFactoryImpl(
- base::WeakPtr<ResourceDispatcher> resource_dispatcher,
- scoped_refptr<ChildURLLoaderFactoryGetter> loader_factory_getter);
+ WebURLLoaderFactoryImpl(base::WeakPtr<ResourceDispatcher> resource_dispatcher,
+ scoped_refptr<SharedURLLoaderFactory> loader_factory);
~WebURLLoaderFactoryImpl() override;
// Creates a test-only factory which can be used only for data URLs.
@@ -71,7 +69,7 @@ class CONTENT_EXPORT WebURLLoaderFactoryImpl
private:
base::WeakPtr<ResourceDispatcher> resource_dispatcher_;
- scoped_refptr<ChildURLLoaderFactoryGetter> loader_factory_getter_;
+ scoped_refptr<SharedURLLoaderFactory> loader_factory_;
DISALLOW_COPY_AND_ASSIGN(WebURLLoaderFactoryImpl);
};
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 2e2ff1d741d..350aea17522 100644
--- a/chromium/content/renderer/loader/web_url_loader_impl_unittest.cc
+++ b/chromium/content/renderer/loader/web_url_loader_impl_unittest.cc
@@ -36,7 +36,7 @@
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/redirect_info.h"
#include "services/network/public/cpp/resource_response_info.h"
-#include "services/network/public/interfaces/request_context_frame_type.mojom.h"
+#include "services/network/public/mojom/request_context_frame_type.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
@@ -64,8 +64,7 @@ const char kFtpDirListing[] =
class TestResourceDispatcher : public ResourceDispatcher {
public:
- TestResourceDispatcher()
- : ResourceDispatcher(nullptr), canceled_(false), defers_loading_(false) {}
+ TestResourceDispatcher() : canceled_(false), defers_loading_(false) {}
~TestResourceDispatcher() override {}
@@ -92,8 +91,8 @@ class TestResourceDispatcher : public ResourceDispatcher {
std::unique_ptr<RequestPeer> peer,
scoped_refptr<SharedURLLoaderFactory> url_loader_factory,
std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
- network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints)
- override {
+ network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
+ base::OnceClosure* continue_navigation_function) override {
EXPECT_FALSE(peer_);
if (sync_load_response_.encoded_body_length != -1)
EXPECT_TRUE(is_sync);
@@ -637,9 +636,9 @@ TEST_F(WebURLLoaderImplTest, BrowserSideNavigationCommit) {
new StreamOverrideParameters());
stream_override->stream_url = kStreamURL;
stream_override->response.mime_type = kMimeType;
- RequestExtraData* extra_data = new RequestExtraData();
+ auto extra_data = std::make_unique<RequestExtraData>();
extra_data->set_stream_override(std::move(stream_override));
- request.SetExtraData(extra_data);
+ request.SetExtraData(std::move(extra_data));
client()->loader()->LoadAsynchronously(request, client());
diff --git a/chromium/content/renderer/loader/web_url_request_util.cc b/chromium/content/renderer/loader/web_url_request_util.cc
index 2245bdb22c2..f41221cdc69 100644
--- a/chromium/content/renderer/loader/web_url_request_util.cc
+++ b/chromium/content/renderer/loader/web_url_request_util.cc
@@ -13,19 +13,19 @@
#include "base/strings/string_util.h"
#include "base/task_scheduler/post_task.h"
#include "content/child/child_thread_impl.h"
-#include "content/public/common/content_features.h"
#include "content/public/common/service_names.mojom.h"
#include "content/renderer/loader/request_extra_data.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/http/http_util.h"
-#include "services/network/public/interfaces/data_pipe_getter.mojom.h"
-#include "services/network/public/interfaces/request_context_frame_type.mojom.h"
+#include "services/network/public/cpp/features.h"
+#include "services/network/public/mojom/data_pipe_getter.mojom.h"
+#include "services/network/public/mojom/request_context_frame_type.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h"
-#include "third_party/WebKit/common/blob/blob.mojom.h"
-#include "third_party/WebKit/common/blob/blob_registry.mojom.h"
+#include "third_party/WebKit/public/mojom/blob/blob.mojom.h"
+#include "third_party/WebKit/public/mojom/blob/blob_registry.mojom.h"
#include "third_party/WebKit/public/platform/FilePathConversion.h"
#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebData.h"
@@ -376,10 +376,13 @@ int GetLoadFlagsForWebURLRequest(const WebURLRequest& request) {
load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA;
}
+ if (request.GetRequestContext() == WebURLRequest::kRequestContextPrefetch)
+ load_flags |= net::LOAD_PREFETCH;
+
if (request.GetExtraData()) {
RequestExtraData* extra_data =
static_cast<RequestExtraData*>(request.GetExtraData());
- if (extra_data->is_prefetch())
+ if (extra_data->is_for_no_state_prefetch())
load_flags |= net::LOAD_PREFETCH;
}
@@ -420,9 +423,6 @@ WebHTTPBody GetWebHTTPBodyForRequestBody(
break;
}
case network::DataElement::TYPE_UNKNOWN:
- case network::DataElement::TYPE_BYTES_DESCRIPTION:
- case network::DataElement::TYPE_DISK_CACHE_ENTRY:
- case network::DataElement::TYPE_FILE_FILESYSTEM:
case network::DataElement::TYPE_RAW_FILE:
NOTREACHED();
break;
@@ -482,17 +482,8 @@ scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebHTTPBody(
base::Time::FromDoubleT(element.modification_time));
}
break;
- case WebHTTPBody::Element::kTypeFileSystemURL: {
- GURL file_system_url = element.file_system_url;
- DCHECK(file_system_url.SchemeIsFileSystem());
- request_body->AppendFileSystemFileRange(
- file_system_url, static_cast<uint64_t>(element.file_start),
- static_cast<uint64_t>(element.file_length),
- base::Time::FromDoubleT(element.modification_time));
- break;
- }
case WebHTTPBody::Element::kTypeBlob: {
- if (base::FeatureList::IsEnabled(features::kNetworkService)) {
+ if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
if (!blob_registry.is_bound()) {
if (ChildThreadImpl::current()) {
ChildThreadImpl::current()->GetConnector()->BindInterface(
@@ -502,7 +493,7 @@ scoped_refptr<network::ResourceRequestBody> GetRequestBodyForWebHTTPBody(
// InterfaceProvider instead (crbug.com/734210).
blink::Platform::Current()
->MainThread()
- ->GetSingleThreadTaskRunner()
+ ->GetTaskRunner()
->PostTask(FROM_HERE,
base::BindOnce(&GetBlobRegistry,
MakeRequest(&blob_registry)));
@@ -642,16 +633,6 @@ blink::WebMixedContentContextType GetMixedContentContextTypeForWebURLRequest(
request.GetRequestContext(), block_mixed_plugin_content);
}
-STATIC_ASSERT_ENUM(ServiceWorkerMode::NONE,
- WebURLRequest::ServiceWorkerMode::kNone);
-STATIC_ASSERT_ENUM(ServiceWorkerMode::ALL,
- WebURLRequest::ServiceWorkerMode::kAll);
-
-ServiceWorkerMode GetServiceWorkerModeForWebURLRequest(
- const WebURLRequest& request) {
- return static_cast<ServiceWorkerMode>(request.GetServiceWorkerMode());
-}
-
#undef STATIC_ASSERT_ENUM
} // namespace content
diff --git a/chromium/content/renderer/loader/web_url_request_util.h b/chromium/content/renderer/loader/web_url_request_util.h
index fcea92fa8e8..ac622e47eef 100644
--- a/chromium/content/renderer/loader/web_url_request_util.h
+++ b/chromium/content/renderer/loader/web_url_request_util.h
@@ -10,10 +10,9 @@
#include "content/common/content_export.h"
#include "content/public/common/request_context_type.h"
#include "content/public/common/resource_type.h"
-#include "content/public/common/service_worker_modes.h"
#include "net/http/http_request_headers.h"
#include "services/network/public/cpp/resource_request_body.h"
-#include "services/network/public/interfaces/request_context_frame_type.mojom.h"
+#include "services/network/public/mojom/request_context_frame_type.mojom.h"
#include "third_party/WebKit/public/platform/WebMixedContentContextType.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
@@ -59,8 +58,6 @@ RequestContextType GetRequestContextTypeForWebURLRequest(
const blink::WebURLRequest& request);
blink::WebMixedContentContextType GetMixedContentContextTypeForWebURLRequest(
const blink::WebURLRequest& request);
-ServiceWorkerMode GetServiceWorkerModeForWebURLRequest(
- const blink::WebURLRequest& request);
} // namespace content