2019-08-29 06:50:14 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jeremy Apthorp <nornagon@nornagon.net>
|
|
|
|
Date: Wed, 28 Aug 2019 12:21:25 -0700
|
|
|
|
Subject: expose SetUserAgent on NetworkContext
|
|
|
|
|
|
|
|
Applying
|
|
|
|
https://chromium-review.googlesource.com/c/chromium/src/+/1585083 before
|
|
|
|
it's merged. There may end up being a better way of doing this, or the
|
|
|
|
patch may be merged upstream, at which point this patch should be
|
|
|
|
removed.
|
|
|
|
|
|
|
|
diff --git a/net/url_request/static_http_user_agent_settings.h b/net/url_request/static_http_user_agent_settings.h
|
2022-10-03 20:21:00 +00:00
|
|
|
index 0ab8187b0db8ae6db46d81738f653a2bc4c566f6..de3d55e85c22317f7f9375eb94d0d5d41b0dbd3b 100644
|
2019-08-29 06:50:14 +00:00
|
|
|
--- a/net/url_request/static_http_user_agent_settings.h
|
|
|
|
+++ b/net/url_request/static_http_user_agent_settings.h
|
2021-11-24 08:45:59 +00:00
|
|
|
@@ -30,13 +30,17 @@ class NET_EXPORT StaticHttpUserAgentSettings : public HttpUserAgentSettings {
|
2019-08-29 06:50:14 +00:00
|
|
|
accept_language_ = new_accept_language;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ void set_user_agent(const std::string& new_user_agent) {
|
|
|
|
+ user_agent_ = new_user_agent;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
// HttpUserAgentSettings implementation
|
|
|
|
std::string GetAcceptLanguage() const override;
|
|
|
|
std::string GetUserAgent() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string accept_language_;
|
|
|
|
- const std::string user_agent_;
|
|
|
|
+ std::string user_agent_;
|
|
|
|
};
|
2021-10-21 18:51:36 +00:00
|
|
|
|
|
|
|
} // namespace net
|
2019-08-29 06:50:14 +00:00
|
|
|
diff --git a/services/network/network_context.cc b/services/network/network_context.cc
|
2023-04-17 21:40:26 +00:00
|
|
|
index 3c8c72eca43b5842a17f502d3b705c27f9c78ec3..8516117fb0da14f128e3fd9cf64e2dba65a0417a 100644
|
2019-08-29 06:50:14 +00:00
|
|
|
--- a/services/network/network_context.cc
|
|
|
|
+++ b/services/network/network_context.cc
|
2023-04-17 21:40:26 +00:00
|
|
|
@@ -1461,6 +1461,13 @@ void NetworkContext::SetNetworkConditions(
|
2019-08-29 06:50:14 +00:00
|
|
|
std::move(network_conditions));
|
|
|
|
}
|
|
|
|
|
|
|
|
+void NetworkContext::SetUserAgent(const std::string& new_user_agent) {
|
|
|
|
+ // This may only be called on NetworkContexts created with a constructor that
|
|
|
|
+ // calls ApplyContextParamsToBuilder.
|
|
|
|
+ DCHECK(user_agent_settings_);
|
|
|
|
+ user_agent_settings_->set_user_agent(new_user_agent);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void NetworkContext::SetAcceptLanguage(const std::string& new_accept_language) {
|
|
|
|
// This may only be called on NetworkContexts created with the constructor
|
|
|
|
// that calls MakeURLRequestContext().
|
|
|
|
diff --git a/services/network/network_context.h b/services/network/network_context.h
|
2023-04-17 21:40:26 +00:00
|
|
|
index 574434c94e0ee145c9a86566baa04d1c054b0dff..5a15c65967b73e54ea742c4f44ee40dd8c2add1e 100644
|
2019-08-29 06:50:14 +00:00
|
|
|
--- a/services/network/network_context.h
|
|
|
|
+++ b/services/network/network_context.h
|
2023-04-17 21:40:26 +00:00
|
|
|
@@ -312,6 +312,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext
|
2019-08-29 06:50:14 +00:00
|
|
|
void CloseIdleConnections(CloseIdleConnectionsCallback callback) override;
|
|
|
|
void SetNetworkConditions(const base::UnguessableToken& throttling_profile_id,
|
|
|
|
mojom::NetworkConditionsPtr conditions) override;
|
|
|
|
+ void SetUserAgent(const std::string& new_user_agent) override;
|
|
|
|
void SetAcceptLanguage(const std::string& new_accept_language) override;
|
|
|
|
void SetEnableReferrers(bool enable_referrers) override;
|
2023-03-23 00:09:13 +00:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS)
|
2019-08-29 06:50:14 +00:00
|
|
|
diff --git a/services/network/public/mojom/network_context.mojom b/services/network/public/mojom/network_context.mojom
|
2023-04-18 21:23:22 +00:00
|
|
|
index 8d8899d941050868c80642d6589e4e3bc48462c7..411282b43eaee28d4091510777c83897e0e844fc 100644
|
2019-08-29 06:50:14 +00:00
|
|
|
--- a/services/network/public/mojom/network_context.mojom
|
|
|
|
+++ b/services/network/public/mojom/network_context.mojom
|
2023-04-17 21:40:26 +00:00
|
|
|
@@ -1119,6 +1119,9 @@ interface NetworkContext {
|
2019-08-29 06:50:14 +00:00
|
|
|
SetNetworkConditions(mojo_base.mojom.UnguessableToken throttling_profile_id,
|
|
|
|
NetworkConditions? conditions);
|
|
|
|
|
|
|
|
+ // Updates the user agent to be used for requests.
|
|
|
|
+ SetUserAgent(string new_user_agent);
|
|
|
|
+
|
|
|
|
// Updates the Accept-Language header to be used for requests.
|
|
|
|
SetAcceptLanguage(string new_accept_language);
|
|
|
|
|
|
|
|
diff --git a/services/network/test/test_network_context.h b/services/network/test/test_network_context.h
|
2023-03-31 02:03:58 +00:00
|
|
|
index 7309c276e12f2dcb4edd867affc7b66a6b7dc8dc..4c0744167f2c43b43857aa0e0f51340e0f580d04 100644
|
2019-08-29 06:50:14 +00:00
|
|
|
--- a/services/network/test/test_network_context.h
|
|
|
|
+++ b/services/network/test/test_network_context.h
|
2023-03-31 02:03:58 +00:00
|
|
|
@@ -141,6 +141,7 @@ class TestNetworkContext : public mojom::NetworkContext {
|
2019-08-29 06:50:14 +00:00
|
|
|
void CloseIdleConnections(CloseIdleConnectionsCallback callback) override {}
|
|
|
|
void SetNetworkConditions(const base::UnguessableToken& throttling_profile_id,
|
|
|
|
mojom::NetworkConditionsPtr conditions) override {}
|
|
|
|
+ void SetUserAgent(const std::string& new_user_agent) override {}
|
|
|
|
void SetAcceptLanguage(const std::string& new_accept_language) override {}
|
|
|
|
void SetEnableReferrers(bool enable_referrers) override {}
|
2023-03-23 00:09:13 +00:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS)
|