Bug 1839916 - Add navigation callbacks for BounceTrackingState in DocumentLoadListener. r=bvandersloot,smaug

Differential Revision: https://phabricator.services.mozilla.com/D182343
This commit is contained in:
Paul Zuehlcke 2023-07-17 17:54:51 +00:00
Родитель d26a3d493b
Коммит b1a6751277
1 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -12,6 +12,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/RefPtr.h"
#include "mozilla/ResultVariant.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_extensions.h"
@ -929,6 +930,27 @@ auto DocumentLoadListener::OpenDocument(
nsLoadFlags loadFlags = aLoadState->CalculateChannelLoadFlags(
browsingContext, std::move(aUriModified), std::move(aIsXFOError));
// Keep track of navigation for the Bounce Tracking Protection.
if (browsingContext->IsTopContent()) {
RefPtr<BounceTrackingState> bounceTrackingState =
browsingContext->GetBounceTrackingState();
// Not every browsing context has a BounceTrackingState. It's also null when
// the feature is disabled.
if (bounceTrackingState) {
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
nsresult rv =
loadInfo->GetTriggeringPrincipal(getter_AddRefs(triggeringPrincipal));
if (!NS_WARN_IF(NS_FAILED(rv))) {
DebugOnly<nsresult> rv = bounceTrackingState->OnStartNavigation(
triggeringPrincipal, loadInfo->GetHasValidUserGestureActivation());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"BounceTrackingState::OnStartNavigation failed");
}
}
}
return Open(aLoadState, loadInfo, loadFlags, aCacheKey, aChannelId,
aAsyncOpenTime, aTiming, std::move(aInfo), false, aContentParent,
aRv);
@ -2517,6 +2539,24 @@ DocumentLoadListener::OnStartRequest(nsIRequest* aRequest) {
return NS_OK;
}
// Keep track of server responses resulting in a document for the Bounce
// Tracking Protection.
if (mIsDocumentLoad && GetParentWindowContext() == nullptr &&
loadingContext->IsTopContent()) {
RefPtr<BounceTrackingState> bounceTrackingState =
loadingContext->GetBounceTrackingState();
// Not every browsing context has a BounceTrackingState. It's also null when
// the feature is disabled.
if (bounceTrackingState) {
DebugOnly<nsresult> rv =
bounceTrackingState->OnDocumentStartRequest(mChannel);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"BounceTrackingState::OnDocumentStartRequest failed.");
}
}
mChannel->Suspend();
mInitiatedRedirectToRealChannel = true;