mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1137681 - Make user agent docshell overrides affect network requests. r=jduell
This commit is contained in:
parent
f6642acc87
commit
23d4194266
@ -37,6 +37,7 @@
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsPerformance.h"
|
||||
#include "nsINetworkInterceptController.h"
|
||||
#include "mozIThirdPartyUtil.h"
|
||||
@ -254,7 +255,7 @@ NS_IMETHODIMP
|
||||
HttpBaseChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
||||
|
||||
|
||||
if (!CanSetLoadGroup(aLoadGroup)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -296,6 +297,47 @@ HttpBaseChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HttpBaseChannel::SetDocshellUserAgentOverride()
|
||||
{
|
||||
// This sets the docshell specific user agent override, it will be overwritten
|
||||
// by UserAgentOverrides.jsm if site-specific user agent overrides are set.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILoadContext> loadContext;
|
||||
NS_QueryNotificationCallbacks(this, loadContext);
|
||||
if (!loadContext) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
loadContext->GetAssociatedWindow(getter_AddRefs(domWindow));
|
||||
if (!domWindow) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> pDomWindow = do_QueryInterface(domWindow);
|
||||
if (!pDomWindow) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIDocShell* docshell = pDomWindow->GetDocShell();
|
||||
if (!docshell) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsString customUserAgent;
|
||||
docshell->GetCustomUserAgent(customUserAgent);
|
||||
if (customUserAgent.IsEmpty()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8 utf8CustomUserAgent(customUserAgent);
|
||||
rv = SetRequestHeader(NS_LITERAL_CSTRING("User-Agent"), utf8CustomUserAgent, false);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HttpBaseChannel::nsIChannel
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -370,7 +412,7 @@ NS_IMETHODIMP
|
||||
HttpBaseChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
||||
|
||||
|
||||
if (!CanSetCallbacks(aCallbacks)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -1380,7 +1422,7 @@ HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer,
|
||||
if (eTLDService) {
|
||||
rv = eTLDService->GetBaseDomain(mURI, extraDomains, currentDomain);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = eTLDService->GetBaseDomain(clone, extraDomains, referrerDomain);
|
||||
rv = eTLDService->GetBaseDomain(clone, extraDomains, referrerDomain);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
@ -2445,7 +2487,7 @@ void
|
||||
HttpBaseChannel::ReleaseListeners()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
||||
|
||||
|
||||
mListener = nullptr;
|
||||
mListenerContext = nullptr;
|
||||
mCallbacks = nullptr;
|
||||
@ -3121,4 +3163,3 @@ HttpBaseChannel::SetCorsPreflightParameters(const nsTArray<nsCString>& aUnsafeHe
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -100,6 +100,7 @@ public:
|
||||
NS_IMETHOD SetLoadGroup(nsILoadGroup *aLoadGroup) override;
|
||||
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags) override;
|
||||
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) override;
|
||||
NS_IMETHOD SetDocshellUserAgentOverride();
|
||||
|
||||
// nsIChannel
|
||||
NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI) override;
|
||||
|
@ -1740,6 +1740,9 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Set user agent override
|
||||
HttpBaseChannel::SetDocshellUserAgentOverride();
|
||||
|
||||
if (ShouldIntercept()) {
|
||||
mResponseCouldBeSynthesized = true;
|
||||
|
||||
|
@ -5040,6 +5040,9 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
|
||||
gHttpHandler->OnOpeningRequest(this);
|
||||
}
|
||||
|
||||
// Set user agent override
|
||||
HttpBaseChannel::SetDocshellUserAgentOverride();
|
||||
|
||||
mIsPending = true;
|
||||
mWasOpened = true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user