+ useragent override per domain
parent
07cb6455d9
commit
8993b5c7f0
|
@ -0,0 +1,286 @@
|
|||
diff -ur firefox-93.0/netwerk/base/RequestContextService.cpp firefox-93.0_patched/netwerk/base/RequestContextService.cpp
|
||||
--- firefox-93.0/netwerk/base/RequestContextService.cpp 2021-09-28 01:17:27.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/base/RequestContextService.cpp 2021-10-20 21:16:24.413520944 +0200
|
||||
@@ -60,6 +60,7 @@
|
||||
uint64_t mID;
|
||||
Atomic<uint32_t> mBlockingTransactionCount;
|
||||
UniquePtr<SpdyPushCache> mSpdyCache;
|
||||
+ nsCString mUserAgentOverride;
|
||||
|
||||
using PendingTailRequest = nsCOMPtr<nsIRequestTailUnblockCallback>;
|
||||
// Number of known opened non-tailed requets
|
||||
@@ -186,6 +187,15 @@
|
||||
|
||||
uint64_t RequestContext::GetID() { return mID; }
|
||||
|
||||
+const nsACString& RequestContext::GetUserAgentOverride() {
|
||||
+ return mUserAgentOverride;
|
||||
+}
|
||||
+
|
||||
+void RequestContext::SetUserAgentOverride(
|
||||
+ const nsACString& aUserAgentOverride) {
|
||||
+ mUserAgentOverride = aUserAgentOverride;
|
||||
+}
|
||||
+
|
||||
NS_IMETHODIMP
|
||||
RequestContext::AddNonTailRequest() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
diff -ur firefox-93.0/netwerk/base/nsILoadGroup.idl firefox-93.0_patched/netwerk/base/nsILoadGroup.idl
|
||||
--- firefox-93.0/netwerk/base/nsILoadGroup.idl 2021-09-28 00:46:56.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/base/nsILoadGroup.idl 2021-10-20 21:17:31.740524540 +0200
|
||||
@@ -96,6 +96,8 @@
|
||||
*/
|
||||
attribute nsLoadFlags defaultLoadFlags;
|
||||
|
||||
+ attribute ACString userAgentOverrideCache;
|
||||
+
|
||||
/**
|
||||
* Returns true if the loadGroup belongs to a discarded context, such as, a
|
||||
* terminated private browsing session.
|
||||
diff -ur firefox-93.0/netwerk/base/nsIRequestContext.idl firefox-93.0_patched/netwerk/base/nsIRequestContext.idl
|
||||
--- firefox-93.0/netwerk/base/nsIRequestContext.idl 2021-09-28 00:47:20.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/base/nsIRequestContext.idl 2021-10-20 21:18:11.556526666 +0200
|
||||
@@ -93,6 +93,8 @@
|
||||
*/
|
||||
[notxpcom,nostdcall] attribute SpdyPushCachePtr spdyPushCache;
|
||||
|
||||
+ [notxpcom,nostdcall] attribute ACString userAgentOverride;
|
||||
+
|
||||
/**
|
||||
* Increases/decrease the number of non-tailed requests in this context.
|
||||
* If the count drops to zero, all tail-blocked callbacks are notified
|
||||
diff -ur firefox-93.0/netwerk/base/nsLoadGroup.cpp firefox-93.0_patched/netwerk/base/nsLoadGroup.cpp
|
||||
--- firefox-93.0/netwerk/base/nsLoadGroup.cpp 2021-09-28 00:47:46.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/base/nsLoadGroup.cpp 2021-10-20 21:20:24.781533781 +0200
|
||||
@@ -767,6 +767,19 @@
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
+NS_IMETHODIMP
|
||||
+nsLoadGroup::GetUserAgentOverrideCache(nsACString& aUserAgentOverrideCache) {
|
||||
+ aUserAgentOverrideCache = mUserAgentOverrideCache;
|
||||
+ return NS_OK;
|
||||
+}
|
||||
+
|
||||
+NS_IMETHODIMP
|
||||
+nsLoadGroup::SetUserAgentOverrideCache(
|
||||
+ const nsACString& aUserAgentOverrideCache) {
|
||||
+ mUserAgentOverrideCache = aUserAgentOverrideCache;
|
||||
+ return NS_OK;
|
||||
+}
|
||||
+
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void nsLoadGroup::TelemetryReport() {
|
||||
diff -ur firefox-93.0/netwerk/base/nsLoadGroup.h firefox-93.0_patched/netwerk/base/nsLoadGroup.h
|
||||
--- firefox-93.0/netwerk/base/nsLoadGroup.h 2021-09-28 00:47:20.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/base/nsLoadGroup.h 2021-10-20 21:19:17.732530200 +0200
|
||||
@@ -103,6 +103,8 @@
|
||||
mozilla::TimeStamp mDefaultRequestCreationTime;
|
||||
uint32_t mTimedRequests{0};
|
||||
uint32_t mCachedRequests{0};
|
||||
+
|
||||
+ nsCString mUserAgentOverrideCache;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
Only in firefox-93.0_patched/netwerk/protocol/http: UAOverridesBootstrapper.jsm
|
||||
Only in firefox-93.0_patched/netwerk/protocol/http: UserAgentOverrides.jsm
|
||||
Only in firefox-93.0_patched/netwerk/protocol/http: UserAgentUpdates.jsm
|
||||
diff -ur firefox-93.0/netwerk/protocol/http/components.conf firefox-93.0_patched/netwerk/protocol/http/components.conf
|
||||
--- firefox-93.0/netwerk/protocol/http/components.conf 2021-09-28 00:47:17.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/protocol/http/components.conf 2021-10-20 21:46:26.687617196 +0200
|
||||
@@ -6,6 +6,13 @@
|
||||
|
||||
Classes = [
|
||||
{
|
||||
+ 'cid': '{965b0ca8-155b-11e7-93ae-92361f002671}',
|
||||
+ 'contract_ids': ['@mozilla.org/network/ua-overrides-bootstrapper;1'],
|
||||
+ 'jsm': 'resource://gre/modules/UAOverridesBootstrapper.jsm',
|
||||
+ 'constructor': 'UAOverridesBootstrapper',
|
||||
+ 'processes': ProcessSelector.MAIN_PROCESS_ONLY,
|
||||
+ },
|
||||
+ {
|
||||
'cid': '{b4f96c89-5238-450c-8bda-e12c26f1d150}',
|
||||
'contract_ids': ['@mozilla.org/network/well-known-opportunistic-utils;1'],
|
||||
'jsm': 'resource://gre/modules/WellKnownOpportunisticUtils.jsm',
|
||||
diff -ur firefox-93.0/netwerk/protocol/http/moz.build firefox-93.0_patched/netwerk/protocol/http/moz.build
|
||||
--- firefox-93.0/netwerk/protocol/http/moz.build 2021-09-28 01:17:27.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/protocol/http/moz.build 2021-10-20 21:48:41.781624411 +0200
|
||||
@@ -174,6 +174,7 @@
|
||||
"PHttpTransaction.ipdl",
|
||||
]
|
||||
|
||||
+
|
||||
include("/ipc/chromium/chromium-config.mozbuild")
|
||||
|
||||
FINAL_LIBRARY = "xul"
|
||||
@@ -190,7 +191,10 @@
|
||||
]
|
||||
|
||||
EXTRA_JS_MODULES += [
|
||||
+ "UAOverridesBootstrapper.jsm",
|
||||
"WellKnownOpportunisticUtils.jsm",
|
||||
+ "UserAgentOverrides.jsm",
|
||||
+ "UserAgentUpdates.jsm",
|
||||
]
|
||||
|
||||
XPCOM_MANIFESTS += [
|
||||
diff -ur firefox-93.0/netwerk/protocol/http/nsHttpChannel.cpp firefox-93.0_patched/netwerk/protocol/http/nsHttpChannel.cpp
|
||||
--- firefox-93.0/netwerk/protocol/http/nsHttpChannel.cpp 2021-09-28 01:17:27.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/protocol/http/nsHttpChannel.cpp 2021-10-20 21:29:52.377564094 +0200
|
||||
@@ -436,6 +436,8 @@
|
||||
nsresult nsHttpChannel::OnBeforeConnect() {
|
||||
nsresult rv;
|
||||
|
||||
+ SetLoadGroupUserAgentOverride();
|
||||
+
|
||||
// Check if request was cancelled during suspend AFTER on-modify-request
|
||||
if (mCanceled) {
|
||||
return mStatus;
|
||||
@@ -5428,6 +5430,8 @@
|
||||
// notify "http-on-modify-request" observers
|
||||
CallOnModifyRequestObservers();
|
||||
|
||||
+ SetLoadGroupUserAgentOverride();
|
||||
+
|
||||
// Check if request was cancelled during on-modify-request
|
||||
if (mCanceled) {
|
||||
return mStatus;
|
||||
@@ -8640,6 +8644,48 @@
|
||||
return aFunc(this);
|
||||
}
|
||||
|
||||
+void nsHttpChannel::SetLoadGroupUserAgentOverride() {
|
||||
+ nsCOMPtr<nsIURI> uri;
|
||||
+ GetURI(getter_AddRefs(uri));
|
||||
+ nsAutoCString uriScheme;
|
||||
+ if (uri) {
|
||||
+ uri->GetScheme(uriScheme);
|
||||
+ }
|
||||
+
|
||||
+ // We don't need a UA for file: protocols.
|
||||
+ if (uriScheme.EqualsLiteral("file")) {
|
||||
+ gHttpHandler->OnUserAgentRequest(this);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ nsIRequestContextService* rcsvc = gHttpHandler->GetRequestContextService();
|
||||
+ nsCOMPtr<nsIRequestContext> rc;
|
||||
+ if (rcsvc) {
|
||||
+ rcsvc->GetRequestContext(mRequestContextID, getter_AddRefs(rc));
|
||||
+ }
|
||||
+
|
||||
+ nsAutoCString ua;
|
||||
+ if (nsContentUtils::IsNonSubresourceRequest(this)) {
|
||||
+ gHttpHandler->OnUserAgentRequest(this);
|
||||
+ if (rc) {
|
||||
+ GetRequestHeader(NS_LITERAL_CSTRING("User-Agent"), ua);
|
||||
+ rc->SetUserAgentOverride(ua);
|
||||
+ }
|
||||
+ } else {
|
||||
+ GetRequestHeader(NS_LITERAL_CSTRING("User-Agent"), ua);
|
||||
+ // Don't overwrite the UA if it is already set (eg by an XHR with explicit
|
||||
+ // UA).
|
||||
+ if (ua.IsEmpty()) {
|
||||
+ if (rc) {
|
||||
+ SetRequestHeader(NS_LITERAL_CSTRING("User-Agent"),
|
||||
+ rc->GetUserAgentOverride(), false);
|
||||
+ } else {
|
||||
+ gHttpHandler->OnUserAgentRequest(this);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
// Step 10 of HTTP-network-or-cache fetch
|
||||
void nsHttpChannel::SetOriginHeader() {
|
||||
if (mRequestHead.IsGet() || mRequestHead.IsHead()) {
|
||||
diff -ur firefox-93.0/netwerk/protocol/http/nsHttpChannel.h firefox-93.0_patched/netwerk/protocol/http/nsHttpChannel.h
|
||||
--- firefox-93.0/netwerk/protocol/http/nsHttpChannel.h 2021-09-28 01:17:27.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/protocol/http/nsHttpChannel.h 2021-10-20 21:25:28.422549997 +0200
|
||||
@@ -502,6 +502,8 @@
|
||||
void SetPushedStreamTransactionAndId(
|
||||
HttpTransactionShell* aTransWithPushedStream, uint32_t aPushedStreamId);
|
||||
|
||||
+ void SetLoadGroupUserAgentOverride();
|
||||
+
|
||||
void SetOriginHeader();
|
||||
void SetDoNotTrack();
|
||||
|
||||
diff -ur firefox-93.0/netwerk/protocol/http/nsHttpHandler.cpp firefox-93.0_patched/netwerk/protocol/http/nsHttpHandler.cpp
|
||||
--- firefox-93.0/netwerk/protocol/http/nsHttpHandler.cpp 2021-09-28 01:17:27.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/protocol/http/nsHttpHandler.cpp 2021-10-20 21:35:59.579583705 +0200
|
||||
@@ -291,6 +291,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
+void nsHttpHandler::EnsureUAOverridesInit() {
|
||||
+ MOZ_ASSERT(XRE_IsParentProcess());
|
||||
+ MOZ_ASSERT(NS_IsMainThread());
|
||||
+
|
||||
+ static bool initDone = false;
|
||||
+
|
||||
+ if (initDone) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ nsresult rv;
|
||||
+ nsCOMPtr<nsISupports> bootstrapper =
|
||||
+ do_GetService("@mozilla.org/network/ua-overrides-bootstrapper;1", &rv);
|
||||
+ MOZ_ASSERT(bootstrapper);
|
||||
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
+ initDone = true;
|
||||
+}
|
||||
+
|
||||
nsHttpHandler::~nsHttpHandler() {
|
||||
LOG(("Deleting nsHttpHandler [this=%p]\n", this));
|
||||
|
||||
@@ -2031,6 +2049,11 @@
|
||||
|
||||
uint32_t caps = mCapabilities;
|
||||
|
||||
+ if (XRE_IsParentProcess()) {
|
||||
+ // Load UserAgentOverrides.jsm before any HTTP request is issued.
|
||||
+ EnsureUAOverridesInit();
|
||||
+ }
|
||||
+
|
||||
uint64_t channelId;
|
||||
nsresult rv = NewChannelId(channelId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
diff -ur firefox-93.0/netwerk/protocol/http/nsHttpHandler.h firefox-93.0_patched/netwerk/protocol/http/nsHttpHandler.h
|
||||
--- firefox-93.0/netwerk/protocol/http/nsHttpHandler.h 2021-09-28 01:17:27.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/protocol/http/nsHttpHandler.h 2021-10-20 21:31:35.602569607 +0200
|
||||
@@ -383,6 +383,11 @@
|
||||
NotifyObservers(chan, NS_HTTP_ON_STOP_REQUEST_TOPIC);
|
||||
}
|
||||
|
||||
+ // Called by the channel and cached in the loadGroup
|
||||
+ void OnUserAgentRequest(nsIHttpChannel* chan) {
|
||||
+ NotifyObservers(chan, NS_HTTP_ON_USERAGENT_REQUEST_TOPIC);
|
||||
+ }
|
||||
+
|
||||
// Called by the channel before setting up the transaction
|
||||
void OnBeforeConnect(nsIHttpChannel* chan) {
|
||||
NotifyObservers(chan, NS_HTTP_ON_BEFORE_CONNECT_TOPIC);
|
||||
@@ -528,6 +533,8 @@
|
||||
void SetHttpHandlerInitArgs(const HttpHandlerInitArgs& aArgs);
|
||||
void SetDeviceModelId(const nsCString& aModelId);
|
||||
|
||||
+ void EnsureUAOverridesInit();
|
||||
+
|
||||
// Checks if there are any user certs or active smart cards on a different
|
||||
// thread. Updates mSpeculativeConnectEnabled when done.
|
||||
void MaybeEnableSpeculativeConnect();
|
||||
diff -ur firefox-93.0/netwerk/protocol/http/nsIHttpProtocolHandler.idl firefox-93.0_patched/netwerk/protocol/http/nsIHttpProtocolHandler.idl
|
||||
--- firefox-93.0/netwerk/protocol/http/nsIHttpProtocolHandler.idl 2021-09-28 00:47:46.000000000 +0200
|
||||
+++ firefox-93.0_patched/netwerk/protocol/http/nsIHttpProtocolHandler.idl 2021-10-20 21:38:21.926591307 +0200
|
||||
@@ -190,6 +190,8 @@
|
||||
*/
|
||||
#define NS_HTTP_ON_EXAMINE_CACHED_RESPONSE_TOPIC "http-on-examine-cached-response"
|
||||
|
||||
+#define NS_HTTP_ON_USERAGENT_REQUEST_TOPIC "http-on-useragent-request"
|
||||
+
|
||||
/**
|
||||
* This topic is notified for every http channel right after it called
|
||||
* OnStopRequest on its listener, regardless whether it was finished
|
Loading…
Reference in New Issue