Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1552176 - Add nsIRequest.set/getTRRMode r=dragana
Browse files Browse the repository at this point in the history
* Makes it possible to selectively enable TRR for pbmode/container/window/etc

Differential Revision: https://phabricator.services.mozilla.com/D48363
  • Loading branch information
valenting committed Nov 8, 2019
1 parent 3078f94 commit 3b4d425
Show file tree
Hide file tree
Showing 40 changed files with 460 additions and 88 deletions.
10 changes: 10 additions & 0 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,16 @@ OnloadBlocker::GetLoadFlags(nsLoadFlags* aLoadFlags) {
return NS_OK;
}

NS_IMETHODIMP
OnloadBlocker::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
OnloadBlocker::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
OnloadBlocker::SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }

Expand Down
2 changes: 2 additions & 0 deletions dom/ipc/BrowserParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,8 @@ class FakeChannel final : public nsIChannel,
NS_IMETHOD SetLoadGroup(nsILoadGroup*) NO_IMPL;
NS_IMETHOD SetLoadFlags(nsLoadFlags) NO_IMPL;
NS_IMETHOD GetLoadFlags(nsLoadFlags*) NO_IMPL;
NS_IMETHOD GetTRRMode(nsIRequest::TRRMode* aTRRMode) NO_IMPL;
NS_IMETHOD SetTRRMode(nsIRequest::TRRMode aMode) NO_IMPL;
NS_IMETHOD GetIsDocument(bool*) NO_IMPL;
NS_IMETHOD GetOriginalURI(nsIURI**) NO_IMPL;
NS_IMETHOD SetOriginalURI(nsIURI*) NO_IMPL;
Expand Down
10 changes: 10 additions & 0 deletions dom/ipc/RemoteWebProgressRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ NS_IMETHODIMP RemoteWebProgressRequest::GetLoadFlags(nsLoadFlags* aLoadFlags) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP RemoteWebProgressRequest::GetTRRMode(
nsIRequest::TRRMode* aTRRMode) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP RemoteWebProgressRequest::SetTRRMode(
nsIRequest::TRRMode aTRRMode) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP RemoteWebProgressRequest::SetLoadFlags(nsLoadFlags aLoadFlags) {
return NS_ERROR_NOT_IMPLEMENTED;
}
Expand Down
10 changes: 10 additions & 0 deletions dom/jsurl/nsJSProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,16 @@ nsJSChannel::SetLoadFlags(nsLoadFlags aLoadFlags) {
return mStreamChannel->SetLoadFlags(aLoadFlags);
}

NS_IMETHODIMP
nsJSChannel::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsJSChannel::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsJSChannel::GetLoadGroup(nsILoadGroup** aLoadGroup) {
return mStreamChannel->GetLoadGroup(aLoadGroup);
Expand Down
10 changes: 10 additions & 0 deletions dom/presentation/PresentationConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,16 @@ PresentationConnection::GetLoadFlags(nsLoadFlags* aLoadFlags) {
NS_IMETHODIMP
PresentationConnection::SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }

NS_IMETHODIMP
PresentationConnection::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
PresentationConnection::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

nsresult PresentationConnection::AddIntoLoadGroup() {
// Avoid adding to loadgroup multiple times
if (mWeakLoadGroup) {
Expand Down
10 changes: 10 additions & 0 deletions dom/websocket/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,16 @@ WebSocketImpl::SetLoadFlags(nsLoadFlags aLoadFlags) {
return NS_OK;
}

NS_IMETHODIMP
WebSocketImpl::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
WebSocketImpl::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

namespace {

class WorkerRunnableDispatcher final : public WorkerRunnable {
Expand Down
6 changes: 6 additions & 0 deletions image/decoders/icon/mac/nsIconChannelCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@
return mPump->SetLoadFlags(aLoadAttributes);
}

NS_IMETHODIMP
nsIconChannel::GetTRRMode(nsIRequest::TRRMode* aTRRMode) { return GetTRRModeImpl(aTRRMode); }

NS_IMETHODIMP
nsIconChannel::SetTRRMode(nsIRequest::TRRMode aTRRMode) { return SetTRRModeImpl(aTRRMode); }

NS_IMETHODIMP
nsIconChannel::GetIsDocument(bool* aIsDocument) {
return NS_GetIsDocumentChannel(this, aIsDocument);
Expand Down
10 changes: 10 additions & 0 deletions image/decoders/icon/win/nsIconChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes) {
return mPump->SetLoadFlags(aLoadAttributes);
}

NS_IMETHODIMP
nsIconChannel::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsIconChannel::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsIconChannel::GetIsDocument(bool* aIsDocument) {
return NS_GetIsDocumentChannel(this, aIsDocument);
Expand Down
10 changes: 10 additions & 0 deletions image/imgRequestProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ imgRequestProxy::SetLoadFlags(nsLoadFlags flags) {
return NS_OK;
}

NS_IMETHODIMP
imgRequestProxy::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
imgRequestProxy::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

/** imgIRequest methods **/

NS_IMETHODIMP
Expand Down
10 changes: 10 additions & 0 deletions modules/libjar/nsJARChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,16 @@ nsJARChannel::SetLoadFlags(nsLoadFlags aLoadFlags) {
return NS_OK;
}

NS_IMETHODIMP
nsJARChannel::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsJARChannel::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsJARChannel::GetIsDocument(bool* aIsDocument) {
return NS_GetIsDocumentChannel(this, aIsDocument);
Expand Down
9 changes: 5 additions & 4 deletions netwerk/base/NetworkConnectivityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ static inline already_AddRefed<nsIChannel> SetupIPCheckChannel(bool ipv4) {
nullptr, // aPerformanceStorage
nullptr, // aLoadGroup
nullptr,
nsIRequest::LOAD_BYPASS_CACHE | // don't read from the cache
nsIRequest::INHIBIT_CACHING | // don't write the response to cache
nsIRequest::LOAD_DISABLE_TRR | // check network capabilities not TRR
nsIRequest::LOAD_ANONYMOUS); // prevent privacy leaks
nsIRequest::LOAD_BYPASS_CACHE | // don't read from the cache
nsIRequest::INHIBIT_CACHING | // don't write the response to cache
nsIRequest::LOAD_ANONYMOUS); // prevent privacy leaks

channel->SetTRRMode(nsIRequest::TRR_DISABLED_MODE);

NS_ENSURE_SUCCESS(rv, nullptr);

Expand Down
10 changes: 10 additions & 0 deletions netwerk/base/nsAsyncStreamCopier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ nsAsyncStreamCopier::GetLoadFlags(nsLoadFlags* aLoadFlags) {
NS_IMETHODIMP
nsAsyncStreamCopier::SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_OK; }

NS_IMETHODIMP
nsAsyncStreamCopier::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return nsIAsyncStreamCopier::GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsAsyncStreamCopier::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return nsIAsyncStreamCopier::SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsAsyncStreamCopier::GetLoadGroup(nsILoadGroup** aLoadGroup) {
*aLoadGroup = nullptr;
Expand Down
10 changes: 10 additions & 0 deletions netwerk/base/nsBaseChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ nsBaseChannel::SetLoadFlags(nsLoadFlags aLoadFlags) {
return NS_OK;
}

NS_IMETHODIMP
nsBaseChannel::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsBaseChannel::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsBaseChannel::GetLoadGroup(nsILoadGroup** aLoadGroup) {
NS_IF_ADDREF(*aLoadGroup = mLoadGroup);
Expand Down
61 changes: 59 additions & 2 deletions netwerk/base/nsIRequest.idl
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,68 @@ interface nsIRequest : nsISupports
*/
const unsigned long LOAD_DOCUMENT_NEEDS_COOKIE = 1 << 2;

cenum TRRMode : 8 {
TRR_DEFAULT_MODE = 0,
TRR_DISABLED_MODE = 1,
TRR_FIRST_MODE = 2,
TRR_ONLY_MODE = 3
};

/**
* Set this flag to disable TRR for this request.
* These methods encode/decode the TRR mode to/from the loadFlags.
* Helper methods Get/SetTRRModeImpl are provided so implementations don't
* need to duplicate code.
*
* Requests with TRR_DEFAULT_MODE will use the mode indicated by the pref
* - see network.trr.mode in all.js
* Requests with TRR_DISABLED_MODE will always use native DNS, even if the
* pref is set to mode3 (TRR-only).
* Requests with TRR_DISABLED_MODE will first use TRR then fallback to
* regular DNS, unless TRR is disabled by setting the pref to mode5,
* parental control being enabled, or the domain being in the exclusion
* list.
* Requests with TRR_ONLY_MODE will only use TRR, unless not allowed by
* the same conditions mentioned above.
*/
nsIRequest_TRRMode getTRRMode();
void setTRRMode(in nsIRequest_TRRMode mode);

%{C++
TRRMode GetTRRMode() {
TRRMode mode = TRR_DEFAULT_MODE;
GetTRRMode(&mode);
return mode;
}

nsresult GetTRRModeImpl(nsIRequest::TRRMode* aTRRMode) {
NS_ENSURE_ARG_POINTER(aTRRMode);
nsLoadFlags flags = nsIRequest::LOAD_NORMAL;
nsresult rv = GetLoadFlags(&flags);
if (NS_FAILED(rv)) {
return rv;
}
*aTRRMode = static_cast<nsIRequest::TRRMode>(
(flags & nsIRequest::LOAD_TRR_MASK) >> 3);
return NS_OK;
}

nsresult SetTRRModeImpl(nsIRequest::TRRMode aTRRMode) {
MOZ_ASSERT(aTRRMode <= 3, "invalid value");
nsLoadFlags flags = nsIRequest::LOAD_NORMAL;
nsresult rv = GetLoadFlags(&flags);
if (NS_FAILED(rv)) {
return rv;
}
flags = (flags & ~nsIRequest::LOAD_TRR_MASK) | (aTRRMode << 3);
return SetLoadFlags(flags);
}
%}

/**
* These two bits encode the TRR mode.
* Do not get/set manually, rather use the getTRRMode/setTRRMode methods.
*/
const unsigned long LOAD_DISABLE_TRR = 1 << 3;
const unsigned long LOAD_TRR_MASK = (1 << 3) | (1 << 4);

/**************************************************************************
* The following flags control the flow of data into the cache.
Expand Down
18 changes: 18 additions & 0 deletions netwerk/base/nsISocketTransport.idl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsITransport.idl"
#include "nsIRequest.idl"

interface nsIInterfaceRequestor;
interface nsINetAddr;
Expand Down Expand Up @@ -258,6 +259,23 @@ interface nsISocketTransport : nsITransport
*/
const unsigned long DONT_TRY_ESNI = (1 << 10);

/**
* These two bits encode the TRR mode of the request.
* Use the static helper methods convert between the TRR mode and flags.
*/
const unsigned long TRR_MODE_FLAGS = (1 << 11) | (1 << 12);

%{C++

static uint32_t GetFlagsFromTRRMode(nsIRequest::TRRMode aMode) {
return static_cast<uint32_t>(aMode) << 11;
}

static nsIRequest::TRRMode GetTRRModeFromFlags(uint32_t aFlags) {
return static_cast<nsIRequest::TRRMode>((aFlags & TRR_MODE_FLAGS) >> 11);
}
%}

/**
* An opaque flags for non-standard behavior of the TLS system.
* It is unlikely this will need to be set outside of telemetry studies
Expand Down
10 changes: 10 additions & 0 deletions netwerk/base/nsIncrementalDownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ nsIncrementalDownload::SetLoadFlags(nsLoadFlags loadFlags) {
return NS_OK;
}

NS_IMETHODIMP
nsIncrementalDownload::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsIncrementalDownload::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsIncrementalDownload::GetLoadGroup(nsILoadGroup** loadGroup) {
return NS_ERROR_NOT_IMPLEMENTED;
Expand Down
10 changes: 10 additions & 0 deletions netwerk/base/nsInputStreamPump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ nsInputStreamPump::SetLoadFlags(nsLoadFlags aLoadFlags) {
return NS_OK;
}

NS_IMETHODIMP
nsInputStreamPump::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsInputStreamPump::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsInputStreamPump::GetLoadGroup(nsILoadGroup** aLoadGroup) {
RecursiveMutexAutoLock lock(mMutex);
Expand Down
10 changes: 10 additions & 0 deletions netwerk/base/nsLoadGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ nsLoadGroup::SetLoadFlags(uint32_t aLoadFlags) {
return NS_OK;
}

NS_IMETHODIMP
nsLoadGroup::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
return GetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsLoadGroup::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
return SetTRRModeImpl(aTRRMode);
}

NS_IMETHODIMP
nsLoadGroup::GetLoadGroup(nsILoadGroup** loadGroup) {
nsCOMPtr<nsILoadGroup> result = mLoadGroup;
Expand Down
3 changes: 3 additions & 0 deletions netwerk/base/nsSocketTransport2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ nsresult nsSocketTransport::ResolveHost() {
if (mConnectionFlags & nsSocketTransport::DISABLE_TRR)
dnsFlags |= nsIDNSService::RESOLVE_DISABLE_TRR;

dnsFlags |= nsIDNSService::GetFlagsFromTRRMode(
nsISocketTransport::GetTRRModeFromFlags(mConnectionFlags));

NS_ASSERTION(!(dnsFlags & nsIDNSService::RESOLVE_DISABLE_IPV6) ||
!(dnsFlags & nsIDNSService::RESOLVE_DISABLE_IPV4),
"Setting both RESOLVE_DISABLE_IPV6 and RESOLVE_DISABLE_IPV4");
Expand Down
8 changes: 7 additions & 1 deletion netwerk/dns/TRR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ nsresult TRR::SendHTTPRequest() {
return NS_ERROR_FAILURE;
}

if ((mType == TRRTYPE_A) || (mType == TRRTYPE_AAAA)) {
if (((mType == TRRTYPE_A) || (mType == TRRTYPE_AAAA)) &&
mRec->EffectiveTRRMode() != nsIRequest::TRR_ONLY_MODE) {
// let NS resolves skip the blacklist check
// we also don't check the blacklist for TRR only requests
MOZ_ASSERT(mRec);

if (gTRRService->IsTRRBlacklisted(mHost, mOriginSuffix, mPB, true)) {
Expand Down Expand Up @@ -254,6 +256,10 @@ nsresult TRR::SendHTTPRequest() {
return NS_ERROR_UNEXPECTED;
}

// This connection should not use TRR
rv = httpChannel->SetTRRMode(nsIRequest::TRR_DISABLED_MODE);
NS_ENSURE_SUCCESS(rv, rv);

rv = httpChannel->SetRequestHeader(
NS_LITERAL_CSTRING("Accept"),
NS_LITERAL_CSTRING("application/dns-message"), false);
Expand Down
Loading

0 comments on commit 3b4d425

Please sign in to comment.