diff --git a/browser/net/BUILD.gn b/browser/net/BUILD.gn index 87b9bfb6712e..08013412277a 100644 --- a/browser/net/BUILD.gn +++ b/browser/net/BUILD.gn @@ -1,11 +1,18 @@ import("//build/config/features.gni") source_set("net") { + configs += [ "//brave/build/geolocation" ] sources = [ - "brave_network_delegate.cc", - "brave_network_delegate.h", - "brave_httpse_network_delegate.cc", - "brave_httpse_network_delegate.h", + "brave_network_delegate_base.cc", + "brave_network_delegate_base.h", + "brave_httpse_network_delegate_helper.cc", + "brave_httpse_network_delegate_helper.h", + "brave_profile_network_delegate.cc", + "brave_profile_network_delegate.h", + "brave_static_redirect_network_delegate_helper.cc", + "brave_static_redirect_network_delegate_helper.h", + "brave_system_network_delegate.cc", + "brave_system_network_delegate.h", "url_context.cc", "url_context.h" ] diff --git a/browser/net/brave_httpse_network_delegate.cc b/browser/net/brave_httpse_network_delegate_helper.cc similarity index 96% rename from browser/net/brave_httpse_network_delegate.cc rename to browser/net/brave_httpse_network_delegate_helper.cc index f6c5b87a7344..2d7291272580 100644 --- a/browser/net/brave_httpse_network_delegate.cc +++ b/browser/net/brave_httpse_network_delegate_helper.cc @@ -2,10 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "brave/browser/net/brave_network_delegate.h" +#include "brave/browser/net/brave_httpse_network_delegate_helper.h" #include "brave/browser/brave_browser_process_impl.h" -#include "brave/browser/net/brave_httpse_network_delegate.h" #include "brave/browser/net/url_context.h" #include "brave/components/brave_shields/browser/brave_shields_util.h" #include "brave/components/brave_shields/browser/https_everywhere_service.h" diff --git a/browser/net/brave_httpse_network_delegate.h b/browser/net/brave_httpse_network_delegate_helper.h similarity index 100% rename from browser/net/brave_httpse_network_delegate.h rename to browser/net/brave_httpse_network_delegate_helper.h diff --git a/browser/net/brave_network_delegate.cc b/browser/net/brave_network_delegate_base.cc similarity index 71% rename from browser/net/brave_network_delegate.cc rename to browser/net/brave_network_delegate_base.cc index 390d6af3a77b..4c48d63fb92e 100644 --- a/browser/net/brave_network_delegate.cc +++ b/browser/net/brave_network_delegate_base.cc @@ -2,41 +2,33 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "brave/browser/net/brave_network_delegate.h" +#include "brave/browser/net/brave_network_delegate_base.h" #include -#include "brave/browser/net/brave_httpse_network_delegate.h" #include "brave/browser/net/url_context.h" - -//#include "chrome/browser/profiles/profile_io_data.h" #include "content/public/browser/browser_thread.h" -//#include "content/public/browser/resource_request_info.h" #include "net/url_request/url_request.h" using content::BrowserThread; -BraveNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo() { +BraveNetworkDelegateBase::ResponseListenerInfo::ResponseListenerInfo() { } -BraveNetworkDelegate::ResponseListenerInfo::~ResponseListenerInfo() { +BraveNetworkDelegateBase::ResponseListenerInfo::~ResponseListenerInfo() { } -BraveNetworkDelegate::BraveNetworkDelegate( +BraveNetworkDelegateBase::BraveNetworkDelegateBase( extensions::EventRouterForwarder* event_router, BooleanPrefMember* enable_referrers) : ChromeNetworkDelegate(event_router, enable_referrers) { - brave::OnBeforeURLRequestCallback callback = - base::Bind( - brave::OnBeforeURLRequest_HttpsePreFileWork); - before_url_request_callbacks_.push_back(callback); } -BraveNetworkDelegate::~BraveNetworkDelegate() { +BraveNetworkDelegateBase::~BraveNetworkDelegateBase() { } -int BraveNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request, +int BraveNetworkDelegateBase::OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) { if (before_url_request_callbacks_.empty() || !request) { @@ -52,7 +44,7 @@ int BraveNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request, return net::ERR_IO_PENDING; } -void BraveNetworkDelegate::RunNextCallback( +void BraveNetworkDelegateBase::RunNextCallback( net::URLRequest* request, GURL *new_url, std::shared_ptr ctx) { @@ -67,7 +59,7 @@ void BraveNetworkDelegate::RunNextCallback( brave::OnBeforeURLRequestCallback callback = before_url_request_callbacks_[ctx->next_url_request_index++]; brave::ResponseCallback next_callback = - base::Bind(&BraveNetworkDelegate::RunNextCallback, + base::Bind(&BraveNetworkDelegateBase::RunNextCallback, base::Unretained(this), request, new_url, ctx); int rv = callback.Run(request, new_url, next_callback, ctx); if (rv == net::ERR_IO_PENDING) { @@ -85,7 +77,7 @@ void BraveNetworkDelegate::RunNextCallback( } } -void BraveNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { +void BraveNetworkDelegateBase::OnURLRequestDestroyed(net::URLRequest* request) { if (!ContainsKey(callbacks_, request->identifier())) { return; } diff --git a/browser/net/brave_network_delegate.h b/browser/net/brave_network_delegate_base.h similarity index 79% rename from browser/net/brave_network_delegate.h rename to browser/net/brave_network_delegate_base.h index e1ad199ee34f..750bc067963f 100644 --- a/browser/net/brave_network_delegate.h +++ b/browser/net/brave_network_delegate_base.h @@ -2,8 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_BROWSER_NET_BRAVE_NETWORK_DELEGATE_H_ -#define BRAVE_BROWSER_NET_BRAVE_NETWORK_DELEGATE_H_ +#ifndef BRAVE_BROWSER_NET_BRAVE_NETWORK_DELEGATE_BASE_H_ +#define BRAVE_BROWSER_NET_BRAVE_NETWORK_DELEGATE_BASE_H_ #include "chrome/browser/net/chrome_network_delegate.h" #include "brave/browser/net/url_context.h" @@ -20,9 +20,9 @@ namespace net { class URLRequest; } -// BraveNetworkDelegate is the central point from within the Brave code to +// BraveNetworkDelegateBase is the central point from within the Brave code to // add hooks into the network stack. -class BraveNetworkDelegate : public ChromeNetworkDelegate { +class BraveNetworkDelegateBase : public ChromeNetworkDelegate { public: using ResponseCallback = base::Callback; @@ -45,9 +45,9 @@ class BraveNetworkDelegate : public ChromeNetworkDelegate { // |enable_referrers| (and all of the other optional PrefMembers) should be // initialized on the UI thread (see below) beforehand. This object's owner is // responsible for cleaning them up at shutdown. - BraveNetworkDelegate(extensions::EventRouterForwarder* event_router, + BraveNetworkDelegateBase(extensions::EventRouterForwarder* event_router, BooleanPrefMember* enable_referrers); - ~BraveNetworkDelegate() override; + ~BraveNetworkDelegateBase() override; // NetworkDelegate implementation. int OnBeforeURLRequest(net::URLRequest* request, @@ -60,14 +60,14 @@ class BraveNetworkDelegate : public ChromeNetworkDelegate { net::URLRequest* request, GURL *new_url, std::shared_ptr ctx); - - private: std::vector before_url_request_callbacks_; + + private: std::map response_listeners_; std::map callbacks_; - DISALLOW_COPY_AND_ASSIGN(BraveNetworkDelegate); + DISALLOW_COPY_AND_ASSIGN(BraveNetworkDelegateBase); }; -#endif // BRAVE_BROWSER_NET_BRAVE_NETWORK_DELEGATE_H_ +#endif // BRAVE_BROWSER_NET_BRAVE_NETWORK_DELEGATE_BASE_H_ diff --git a/browser/net/brave_profile_network_delegate.cc b/browser/net/brave_profile_network_delegate.cc new file mode 100644 index 000000000000..90e4574e5261 --- /dev/null +++ b/browser/net/brave_profile_network_delegate.cc @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/net/brave_profile_network_delegate.h" + +#include "brave/browser/net/brave_httpse_network_delegate_helper.h" + +BraveProfileNetworkDelegate::BraveProfileNetworkDelegate( + extensions::EventRouterForwarder* event_router, + BooleanPrefMember* enable_referrers) : + BraveNetworkDelegateBase(event_router, enable_referrers) { + brave::OnBeforeURLRequestCallback callback = + base::Bind( + brave::OnBeforeURLRequest_HttpsePreFileWork); + before_url_request_callbacks_.push_back(callback); +} + +BraveProfileNetworkDelegate::~BraveProfileNetworkDelegate() { +} diff --git a/browser/net/brave_profile_network_delegate.h b/browser/net/brave_profile_network_delegate.h new file mode 100644 index 000000000000..777145d4387c --- /dev/null +++ b/browser/net/brave_profile_network_delegate.h @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_NET_BRAVE_PROFILE_NETWORK_DELEGATE_H_ +#define BRAVE_BROWSER_NET_BRAVE_PROFILE_NETWORK_DELEGATE_H_ + +#include "brave/browser/net/brave_network_delegate_base.h" + +class BraveProfileNetworkDelegate : public BraveNetworkDelegateBase { + public: + BraveProfileNetworkDelegate(extensions::EventRouterForwarder* event_router, + BooleanPrefMember* enable_referrers); + ~BraveProfileNetworkDelegate() override; + + DISALLOW_COPY_AND_ASSIGN(BraveProfileNetworkDelegate); +}; + +#endif // BRAVE_BROWSER_NET_BRAVE_PROFILE_NETWORK_DELEGATE_H_ diff --git a/browser/net/brave_static_redirect_network_delegate_helper.cc b/browser/net/brave_static_redirect_network_delegate_helper.cc new file mode 100644 index 000000000000..b6494d2fc175 --- /dev/null +++ b/browser/net/brave_static_redirect_network_delegate_helper.cc @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/net/brave_static_redirect_network_delegate_helper.h" + +#include "extensions/common/url_pattern.h" +#include "net/url_request/url_request.h" + + +namespace brave { + +int OnBeforeURLRequest_StaticRedirectWork( + net::URLRequest* request, + GURL* new_url, + const ResponseCallback& next_callback, + std::shared_ptr ctx) { + URLPattern geoPattern(URLPattern::SCHEME_HTTPS, + "https://www.googleapis.com/geolocation/v1/geolocate?key=*"); + if (geoPattern.MatchesURL(request->url())) { + *new_url = GURL(GOOGLEAPIS_ENDPOINT GOOGLEAPIS_API_KEY); + } + return net::OK; +} + +} // namespace brave diff --git a/browser/net/brave_static_redirect_network_delegate_helper.h b/browser/net/brave_static_redirect_network_delegate_helper.h new file mode 100644 index 000000000000..6482b21efa97 --- /dev/null +++ b/browser/net/brave_static_redirect_network_delegate_helper.h @@ -0,0 +1,27 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_NET_BRAVE_STATIC_REDIRECT_NETWORK_DELEGATE_H_ +#define BRAVE_BROWSER_NET_BRAVE_STATIC_REDIRECT_NETWORK_DELEGATE_H_ + +#include "chrome/browser/net/chrome_network_delegate.h" +#include "brave/browser/net/url_context.h" + +struct OnBeforeURLRequestContext; + +namespace net { +class URLRequest; +} + +namespace brave { + +int OnBeforeURLRequest_StaticRedirectWork( + net::URLRequest* request, + GURL* new_url, + const ResponseCallback& next_callback, + std::shared_ptr ctx); + +} // namespace brave + +#endif // BRAVE_BROWSER_NET_BRAVE_STATIC_REDIRECT_NETWORK_DELEGATE_H_ diff --git a/browser/net/brave_system_network_delegate.cc b/browser/net/brave_system_network_delegate.cc new file mode 100644 index 000000000000..a71756aace32 --- /dev/null +++ b/browser/net/brave_system_network_delegate.cc @@ -0,0 +1,21 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/net/brave_system_network_delegate.h" + +#include "brave/browser/net/brave_static_redirect_network_delegate_helper.h" + + +BraveSystemNetworkDelegate::BraveSystemNetworkDelegate( + extensions::EventRouterForwarder* event_router, + BooleanPrefMember* enable_referrers) : + BraveNetworkDelegateBase(event_router, enable_referrers) { + brave::OnBeforeURLRequestCallback callback = + base::Bind( + brave::OnBeforeURLRequest_StaticRedirectWork); + before_url_request_callbacks_.push_back(callback); +} + +BraveSystemNetworkDelegate::~BraveSystemNetworkDelegate() { +} diff --git a/browser/net/brave_system_network_delegate.h b/browser/net/brave_system_network_delegate.h new file mode 100644 index 000000000000..1ec32364576b --- /dev/null +++ b/browser/net/brave_system_network_delegate.h @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_NET_BRAVE_SYSTEM_NETWORK_DELEGATE_H_ +#define BRAVE_BROWSER_NET_BRAVE_SYSTEM_NETWORK_DELEGATE_H_ + +#include "brave/browser/net/brave_network_delegate_base.h" + + +class BraveSystemNetworkDelegate : public BraveNetworkDelegateBase { + public: + BraveSystemNetworkDelegate(extensions::EventRouterForwarder* event_router, + BooleanPrefMember* enable_referrers); + ~BraveSystemNetworkDelegate() override; + + DISALLOW_COPY_AND_ASSIGN(BraveSystemNetworkDelegate); +}; + +#endif // BRAVE_BROWSER_NET_BRAVE_SYSTEM_NETWORK_DELEGATE_H_ diff --git a/build/geolocation/BUILD.gn b/build/geolocation/BUILD.gn new file mode 100644 index 000000000000..a51d823112b9 --- /dev/null +++ b/build/geolocation/BUILD.gn @@ -0,0 +1,11 @@ +declare_args() { + antimuon_google_api_key = "" + antimuon_google_api_endpoint = "" +} + +config("geolocation") { + defines = [ + "GOOGLEAPIS_API_KEY=\"$antimuon_google_api_key\"", + "GOOGLEAPIS_ENDPOINT=\"$antimuon_google_api_endpoint\"" + ] +} diff --git a/patches/chrome-browser-io_thread.cc.patch b/patches/chrome-browser-io_thread.cc.patch new file mode 100644 index 000000000000..419a8f0b67b8 --- /dev/null +++ b/patches/chrome-browser-io_thread.cc.patch @@ -0,0 +1,21 @@ +diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc +index 7e840669571cb041bd20aa33b2801dc255a9f19f..d5c6e35efcb062ac14b849452548f873d68798ee 100644 +--- a/chrome/browser/io_thread.cc ++++ b/chrome/browser/io_thread.cc +@@ -30,6 +30,7 @@ + #include "base/threading/thread.h" + #include "base/time/time.h" + #include "base/trace_event/trace_event.h" ++#include "brave/browser/net/brave_system_network_delegate.h" + #include "build/build_config.h" + #include "chrome/browser/browser_process.h" + #include "chrome/browser/data_usage/tab_id_annotator.h" +@@ -755,7 +756,7 @@ void IOThread::ConstructSystemRequestContext() { + + builder->set_user_agent(GetUserAgent()); + std::unique_ptr chrome_network_delegate( +- new ChromeNetworkDelegate(extension_event_router_forwarder(), ++ new BraveSystemNetworkDelegate(extension_event_router_forwarder(), + &system_enable_referrers_)); + // By default, data usage is considered off the record. + chrome_network_delegate->set_data_use_aggregator( diff --git a/patches/chrome-browser-net-chrome_network_delegate.h.patch b/patches/chrome-browser-net-chrome_network_delegate.h.patch index f5f7f66d4456..3a0d9d9d4e3c 100644 --- a/patches/chrome-browser-net-chrome_network_delegate.h.patch +++ b/patches/chrome-browser-net-chrome_network_delegate.h.patch @@ -1,12 +1,12 @@ diff --git a/chrome/browser/net/chrome_network_delegate.h b/chrome/browser/net/chrome_network_delegate.h -index e055ef156da9ea78b1dee96ee04f9c061267c775..5ffcecf64f39f3ff593cd30d9c1ef551be5f1a27 100644 +index e055ef156da9ea78b1dee96ee04f9c061267c775..1177d422a0f0d8a6f51ff4b8f429997de9cc3272 100644 --- a/chrome/browser/net/chrome_network_delegate.h +++ b/chrome/browser/net/chrome_network_delegate.h @@ -144,6 +144,8 @@ class ChromeNetworkDelegate : public net::NetworkDelegateImpl { static void EnableAccessToAllFilesForTesting(bool enabled); private: -+ friend class BraveNetworkDelegate; ++ friend class BraveNetworkDelegateBase; + // NetworkDelegate implementation. int OnBeforeURLRequest(net::URLRequest* request, diff --git a/patches/chrome-browser-profiles-profile_io_data.cc.patch b/patches/chrome-browser-profiles-profile_io_data.cc.patch index 8f89d1025c0b..a846310f8c1f 100644 --- a/patches/chrome-browser-profiles-profile_io_data.cc.patch +++ b/patches/chrome-browser-profiles-profile_io_data.cc.patch @@ -1,12 +1,12 @@ diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc -index 7bcc72f67676bf1bd388109e94bd0739cd588957..cd1cfd7930ace33eb1c6e72b39133c815a656be2 100644 +index 7bcc72f67676bf1bd388109e94bd0739cd588957..279794b6c6b52fd792f21b227ffdeb5850e3e700 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -25,6 +25,7 @@ #include "base/strings/string_util.h" #include "base/task_scheduler/post_task.h" #include "base/threading/thread_task_runner_handle.h" -+#include "brave/browser/net/brave_network_delegate.h" ++#include "brave/browser/net/brave_profile_network_delegate.h" #include "build/build_config.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" @@ -15,7 +15,7 @@ index 7bcc72f67676bf1bd388109e94bd0739cd588957..cd1cfd7930ace33eb1c6e72b39133c81 std::unique_ptr chrome_network_delegate( - new ChromeNetworkDelegate( -+ new BraveNetworkDelegate( ++ new BraveProfileNetworkDelegate( #if BUILDFLAG(ENABLE_EXTENSIONS) io_thread_globals->extension_event_router_forwarder.get(), #else