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
|
|
|
|
index 0ccfe130f00ec3b6c75cd8ee04d5a2777e1fd00c..653829457d58bf92057cc36aa8a289703d8b0577 100644
|
|
|
|
--- a/net/url_request/static_http_user_agent_settings.h
|
|
|
|
+++ b/net/url_request/static_http_user_agent_settings.h
|
|
|
|
@@ -26,13 +26,17 @@ class NET_EXPORT StaticHttpUserAgentSettings : public HttpUserAgentSettings {
|
|
|
|
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_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(StaticHttpUserAgentSettings);
|
|
|
|
};
|
|
|
|
diff --git a/services/network/network_context.cc b/services/network/network_context.cc
|
2021-07-26 16:02:16 +00:00
|
|
|
index f6ffe4fd17beda171df181a28b8a7b6e4b39b982..cc6960e647205e3a8d7ac96e6b116458aef79207 100644
|
2019-08-29 06:50:14 +00:00
|
|
|
--- a/services/network/network_context.cc
|
|
|
|
+++ b/services/network/network_context.cc
|
2021-07-26 16:02:16 +00:00
|
|
|
@@ -1195,6 +1195,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
|
2021-07-26 16:02:16 +00:00
|
|
|
index c701d79bbe05f52c03eb0c0c13ad00cdfc3263fb..01e65839c7cb180f9e94f51eda71193fec1f4f30 100644
|
2019-08-29 06:50:14 +00:00
|
|
|
--- a/services/network/network_context.h
|
|
|
|
+++ b/services/network/network_context.h
|
2021-07-26 16:02:16 +00:00
|
|
|
@@ -256,6 +256,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;
|
2020-12-22 22:14:44 +00:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
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
|
2021-07-26 16:02:16 +00:00
|
|
|
index 2606002021db94fe208c9f8e4d8dea6a5478b697..b60b0102e865e656c2df309c5e5ec4db1975e06f 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
|
2021-07-26 16:02:16 +00:00
|
|
|
@@ -958,6 +958,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
|
2021-07-06 12:17:13 +00:00
|
|
|
index 0d928e7db97bcc2ac99eea0e46a2f0b8405ddfb9..b325c08a447abb2424f08fb11abe2b1375e4b920 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
|
2021-06-22 19:17:16 +00:00
|
|
|
@@ -123,6 +123,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 {}
|
2020-12-22 22:14:44 +00:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS_ASH)
|