Introduce CreateContentBrowserURLLoaderThrottles
This provides a central location to add content internal throttles.
Bug: 1025612
Change-Id: I6e3323f0cfa605b520a5079255e6001ab445093e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2046138
Reviewed-by: John Abd-El-Malek <[email protected]>
Commit-Queue: Alex Clarke <[email protected]>
Cr-Commit-Position: refs/heads/master@{#740211}
diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
index dcbdd2e..945a8b4 100644
--- a/content/browser/BUILD.gn
+++ b/content/browser/BUILD.gn
@@ -1101,6 +1101,8 @@
"loader/shared_cors_origin_access_list_impl.h",
"loader/single_request_url_loader_factory.cc",
"loader/single_request_url_loader_factory.h",
+ "loader/url_loader_throttles.cc",
+ "loader/url_loader_throttles.h",
"loader/webrtc_connections_observer.cc",
"loader/webrtc_connections_observer.h",
"locks/lock_manager.cc",
diff --git a/content/browser/loader/navigation_url_loader_impl.cc b/content/browser/loader/navigation_url_loader_impl.cc
index 536d410..63850d6 100644
--- a/content/browser/loader/navigation_url_loader_impl.cc
+++ b/content/browser/loader/navigation_url_loader_impl.cc
@@ -35,6 +35,7 @@
#include "content/browser/loader/navigation_url_loader_delegate.h"
#include "content/browser/loader/prefetch_url_loader_service.h"
#include "content/browser/loader/single_request_url_loader_factory.h"
+#include "content/browser/loader/url_loader_throttles.h"
#include "content/browser/navigation_subresource_loader_params.h"
#include "content/browser/service_worker/service_worker_container_host.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h"
@@ -1122,7 +1123,7 @@
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
CreateURLLoaderThrottles() {
- return GetContentClient()->browser()->CreateURLLoaderThrottles(
+ return CreateContentBrowserURLLoaderThrottles(
*resource_request_, browser_context_, web_contents_getter_,
navigation_ui_data_.get(), frame_tree_node_id_);
}
diff --git a/content/browser/loader/prefetch_url_loader_service.cc b/content/browser/loader/prefetch_url_loader_service.cc
index 8faf8f8..46314386 100644
--- a/content/browser/loader/prefetch_url_loader_service.cc
+++ b/content/browser/loader/prefetch_url_loader_service.cc
@@ -10,6 +10,7 @@
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/loader/prefetch_url_loader.h"
+#include "content/browser/loader/url_loader_throttles.h"
#include "content/browser/url_loader_factory_getter.h"
#include "content/browser/web_package/prefetched_signed_exchange_cache.h"
#include "content/public/browser/content_browser_client.h"
@@ -316,7 +317,7 @@
PrefetchURLLoaderService::CreateURLLoaderThrottles(
const network::ResourceRequest& request,
int frame_tree_node_id) {
- return GetContentClient()->browser()->CreateURLLoaderThrottles(
+ return CreateContentBrowserURLLoaderThrottles(
request, browser_context_,
base::BindRepeating(&WebContents::FromFrameTreeNodeId,
frame_tree_node_id),
diff --git a/content/browser/loader/url_loader_throttles.cc b/content/browser/loader/url_loader_throttles.cc
new file mode 100644
index 0000000..8caf401be
--- /dev/null
+++ b/content/browser/loader/url_loader_throttles.cc
@@ -0,0 +1,28 @@
+// Copyright 2020 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/browser/loader/url_loader_throttles.h"
+
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/common/content_client.h"
+#include "third_party/blink/public/common/loader/url_loader_throttle.h"
+
+namespace content {
+
+std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
+CreateContentBrowserURLLoaderThrottles(
+ const network::ResourceRequest& request,
+ BrowserContext* browser_context,
+ const base::RepeatingCallback<WebContents*()>& wc_getter,
+ NavigationUIData* navigation_ui_data,
+ int frame_tree_node_id) {
+ std::vector<std::unique_ptr<blink::URLLoaderThrottle>> throttles =
+ GetContentClient()->browser()->CreateURLLoaderThrottles(
+ request, browser_context, wc_getter, navigation_ui_data,
+ frame_tree_node_id);
+ // TODO(alexclarke): Add VariationsURLLoaderThrottle here.
+ return throttles;
+}
+
+} // namespace content
diff --git a/content/browser/loader/url_loader_throttles.h b/content/browser/loader/url_loader_throttles.h
new file mode 100644
index 0000000..dadf954
--- /dev/null
+++ b/content/browser/loader/url_loader_throttles.h
@@ -0,0 +1,36 @@
+// Copyright 2020 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_BROWSER_LOADER_URL_LOADER_THROTTLES_H_
+#define CONTENT_BROWSER_LOADER_URL_LOADER_THROTTLES_H_
+
+#include "base/callback.h"
+
+namespace blink {
+class URLLoaderThrottle;
+} // namespace blink
+
+namespace network {
+struct ResourceRequest;
+} // namespace network
+
+namespace content {
+
+class BrowserContext;
+class NavigationUIData;
+class WebContents;
+
+// Wrapper around ContentBrowserClient::CreateURLLoaderThrottles which inserts
+// additional content specific throttles.
+std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
+CreateContentBrowserURLLoaderThrottles(
+ const network::ResourceRequest& request,
+ BrowserContext* browser_context,
+ const base::RepeatingCallback<WebContents*()>& wc_getter,
+ NavigationUIData* navigation_ui_data,
+ int frame_tree_node_id);
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_LOADER_URL_LOADER_THROTTLES_H_
diff --git a/content/browser/service_worker/service_worker_updated_script_loader.cc b/content/browser/service_worker/service_worker_updated_script_loader.cc
index 56d925e..6dee752 100644
--- a/content/browser/service_worker/service_worker_updated_script_loader.cc
+++ b/content/browser/service_worker/service_worker_updated_script_loader.cc
@@ -11,6 +11,7 @@
#include "base/numerics/safe_conversions.h"
#include "base/task/post_task.h"
#include "content/browser/appcache/appcache_response.h"
+#include "content/browser/loader/url_loader_throttles.h"
#include "content/browser/service_worker/service_worker_cache_writer.h"
#include "content/browser/service_worker/service_worker_consts.h"
#include "content/browser/service_worker/service_worker_context_core.h"
@@ -99,7 +100,7 @@
base::RepeatingCallback<WebContents*()> wc_getter =
base::BindRepeating([]() -> WebContents* { return nullptr; });
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> throttles =
- GetContentClient()->browser()->CreateURLLoaderThrottles(
+ CreateContentBrowserURLLoaderThrottles(
resource_request, browser_context, std::move(wc_getter),
/*navigation_ui_data=*/nullptr, RenderFrameHost::kNoFrameTreeNodeId);
diff --git a/content/browser/worker_host/worker_script_fetch_initiator.cc b/content/browser/worker_host/worker_script_fetch_initiator.cc
index cb463ca..5959ca00 100644
--- a/content/browser/worker_host/worker_script_fetch_initiator.cc
+++ b/content/browser/worker_host/worker_script_fetch_initiator.cc
@@ -19,6 +19,7 @@
#include "content/browser/file_system/file_system_url_loader_factory.h"
#include "content/browser/loader/browser_initiated_resource_request.h"
#include "content/browser/loader/file_url_loader_factory.h"
+#include "content/browser/loader/url_loader_throttles.h"
#include "content/browser/navigation_subresource_loader_params.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h"
@@ -349,7 +350,7 @@
base::RepeatingCallback<WebContents*()> wc_getter =
base::BindRepeating([]() -> WebContents* { return nullptr; });
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> throttles =
- GetContentClient()->browser()->CreateURLLoaderThrottles(
+ CreateContentBrowserURLLoaderThrottles(
*resource_request, browser_context, wc_getter,
nullptr /* navigation_ui_data */,
RenderFrameHost::kNoFrameTreeNodeId);