Bug 1765313, part 3 - Rename ContentBlocking to StorageAccessAPIHelper, r=anti-tracking-reviewers,necko-reviewers,dragana,timhuang

The only functions that remain are used as helper functions in the various variants of the Storage Access API.
To make this clearer, I have renamed this class and file that contains it.

Differential Revision: https://phabricator.services.mozilla.com/D148286
This commit is contained in:
Benjamin VanderSloot 2022-06-08 12:18:23 +00:00
Родитель b99dc899f7
Коммит b49966ba21
17 изменённых файлов: 170 добавлений и 168 удалений

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

@ -16425,7 +16425,7 @@ void Document::MaybeAllowStorageForOpenerAfterUserInteraction() {
}
// We don't care when the asynchronous work finishes here.
Unused << ContentBlocking::AllowAccessFor(
Unused << StorageAccessAPIHelper::AllowAccessFor(
NodePrincipal(), openerBC,
ContentBlockingNotifier::eOpenerAfterUserInteraction);
}
@ -16834,7 +16834,7 @@ nsresult Document::HasStorageAccessSync(bool& aHasStorageAccess) {
return NS_OK;
}
Maybe<bool> resultBecauseCookiesApproved =
ContentBlocking::CheckCookiesPermittedDecidesStorageAccessAPI(
StorageAccessAPIHelper::CheckCookiesPermittedDecidesStorageAccessAPI(
CookieJarSettings(), NodePrincipal());
if (resultBecauseCookiesApproved.isSome()) {
if (resultBecauseCookiesApproved.value()) {
@ -16859,7 +16859,7 @@ nsresult Document::HasStorageAccessSync(bool& aHasStorageAccess) {
bool isThirdPartyTracker =
nsContentUtils::IsThirdPartyTrackingResourceWindow(inner);
Maybe<bool> resultBecauseBrowserSettings =
ContentBlocking::CheckBrowserSettingsDecidesStorageAccessAPI(
StorageAccessAPIHelper::CheckBrowserSettingsDecidesStorageAccessAPI(
CookieJarSettings(), isThirdPartyDocument, isOnRejectForeignAllowList,
isOnThirdPartySkipList, isThirdPartyTracker);
if (resultBecauseBrowserSettings.isSome()) {
@ -16875,7 +16875,8 @@ nsresult Document::HasStorageAccessSync(bool& aHasStorageAccess) {
// Step 3: Check if the location of this call (embedded, top level, same-site)
// determines if cookies are permitted or not.
Maybe<bool> resultBecauseCallContext =
ContentBlocking::CheckCallingContextDecidesStorageAccessAPI(this, false);
StorageAccessAPIHelper::CheckCallingContextDecidesStorageAccessAPI(this,
false);
if (resultBecauseCallContext.isSome()) {
if (resultBecauseCallContext.value()) {
aHasStorageAccess = true;
@ -16889,7 +16890,8 @@ nsresult Document::HasStorageAccessSync(bool& aHasStorageAccess) {
// Step 4: Check if the permissions for this document determine if if has
// access or is denied cookies.
Maybe<bool> resultBecausePreviousPermission =
ContentBlocking::CheckExistingPermissionDecidesStorageAccessAPI(this);
StorageAccessAPIHelper::CheckExistingPermissionDecidesStorageAccessAPI(
this);
if (resultBecausePreviousPermission.isSome()) {
if (resultBecausePreviousPermission.value()) {
aHasStorageAccess = true;
@ -16967,8 +16969,9 @@ RefPtr<MozPromise<int, bool, true>> Document::RequestStorageAccessAsyncHelper(
// called later in CompleteAllowAccessFor inside of AllowAccessFor.
auto performFinalChecks = [inner, self, principal, aHasUserInteraction]() {
// Create the user prompt
RefPtr<ContentBlocking::StorageAccessFinalCheckPromise::Private> p =
new ContentBlocking::StorageAccessFinalCheckPromise::Private(__func__);
RefPtr<StorageAccessAPIHelper::StorageAccessFinalCheckPromise::Private> p =
new StorageAccessAPIHelper::StorageAccessFinalCheckPromise::Private(
__func__);
RefPtr<StorageAccessPermissionRequest> sapr =
StorageAccessPermissionRequest::Create(
inner, principal,
@ -16976,7 +16979,7 @@ RefPtr<MozPromise<int, bool, true>> Document::RequestStorageAccessAsyncHelper(
[p] {
Telemetry::AccumulateCategorical(
Telemetry::LABELS_STORAGE_ACCESS_API_UI::Allow);
p->Resolve(ContentBlocking::eAllow, __func__);
p->Resolve(StorageAccessAPIHelper::eAllow, __func__);
},
// Block
[p] {
@ -17026,10 +17029,10 @@ RefPtr<MozPromise<int, bool, true>> Document::RequestStorageAccessAsyncHelper(
MOZ_ASSERT_IF(pr2 != PromptResult::Granted,
pr2 == PromptResult::Denied);
if (pr2 == PromptResult::Granted) {
ContentBlocking::StorageAccessPromptChoices choice =
ContentBlocking::eAllow;
StorageAccessAPIHelper::StorageAccessPromptChoices choice =
StorageAccessAPIHelper::eAllow;
if (autoGrant) {
choice = ContentBlocking::eAllowAutoGrant;
choice = StorageAccessAPIHelper::eAllowAutoGrant;
}
if (!autoGrant) {
p->Resolve(choice, __func__);
@ -17056,8 +17059,8 @@ RefPtr<MozPromise<int, bool, true>> Document::RequestStorageAccessAsyncHelper(
};
// Try to allow access for the given principal.
return ContentBlocking::AllowAccessFor(principal, aBrowsingContext, aNotifier,
performFinalChecks);
return StorageAccessAPIHelper::AllowAccessFor(principal, aBrowsingContext,
aNotifier, performFinalChecks);
}
already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
@ -17086,7 +17089,7 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
// This is outside of the spec of the StorageAccess API, but makes the return
// values to have proper semantics.
Maybe<bool> resultBecauseCookiesApproved =
ContentBlocking::CheckCookiesPermittedDecidesStorageAccessAPI(
StorageAccessAPIHelper::CheckCookiesPermittedDecidesStorageAccessAPI(
CookieJarSettings(), NodePrincipal());
if (resultBecauseCookiesApproved.isSome()) {
if (resultBecauseCookiesApproved.value()) {
@ -17114,7 +17117,7 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
bool isThirdPartyTracker =
nsContentUtils::IsThirdPartyTrackingResourceWindow(inner);
Maybe<bool> resultBecauseBrowserSettings =
ContentBlocking::CheckBrowserSettingsDecidesStorageAccessAPI(
StorageAccessAPIHelper::CheckBrowserSettingsDecidesStorageAccessAPI(
CookieJarSettings(), isThirdPartyDocument, isOnRejectForeignAllowList,
isOnThirdPartySkipList, isThirdPartyTracker);
if (resultBecauseBrowserSettings.isSome()) {
@ -17131,7 +17134,8 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
// Step 3: Check if the Document calling requestStorageAccess has anything to
// gain from storage access. It should be embedded, non-null, etc.
Maybe<bool> resultBecauseCallContext =
ContentBlocking::CheckCallingContextDecidesStorageAccessAPI(this, true);
StorageAccessAPIHelper::CheckCallingContextDecidesStorageAccessAPI(this,
true);
if (resultBecauseCallContext.isSome()) {
if (resultBecauseCallContext.value()) {
promise->MaybeResolveWithUndefined();
@ -17146,7 +17150,8 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
// Step 4: Check if we already allowed or denied storage access for this
// document's storage key.
Maybe<bool> resultBecausePreviousPermission =
ContentBlocking::CheckExistingPermissionDecidesStorageAccessAPI(this);
StorageAccessAPIHelper::CheckExistingPermissionDecidesStorageAccessAPI(
this);
if (resultBecausePreviousPermission.isSome()) {
if (resultBecausePreviousPermission.value()) {
promise->MaybeResolveWithUndefined();
@ -17220,7 +17225,7 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
bool isOnRejectForeignAllowList =
RejectForeignAllowList::Check(thirdPartyURI);
Maybe<bool> resultBecauseBrowserSettings =
ContentBlocking::CheckBrowserSettingsDecidesStorageAccessAPI(
StorageAccessAPIHelper::CheckBrowserSettingsDecidesStorageAccessAPI(
CookieJarSettings(), isThirdPartyDocument, isOnRejectForeignAllowList,
false, true);
if (resultBecauseBrowserSettings.isSome()) {
@ -17235,8 +17240,8 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
// Step 2: Check that this Document is same-site to the top, and check that
// we have user activation if we require it.
Maybe<bool> resultBecauseCallContext =
ContentBlocking::CheckSameSiteCallingContextDecidesStorageAccessAPI(
Maybe<bool> resultBecauseCallContext = StorageAccessAPIHelper::
CheckSameSiteCallingContextDecidesStorageAccessAPI(
this, aRequireUserActivation);
if (resultBecauseCallContext.isSome()) {
if (resultBecauseCallContext.value()) {
@ -17283,7 +17288,7 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccessForOrigin(
// permission, but this can't be done in this process. We needs the cookie
// permission of the URL as if it were embedded on this page, so we need to
// make this check in the ContentParent.
ContentBlocking::AsyncCheckCookiesPermittedDecidesStorageAccessAPI(
StorageAccessAPIHelper::AsyncCheckCookiesPermittedDecidesStorageAccessAPI(
GetBrowsingContext(), principal)
->Then(
GetCurrentSerialEventTarget(), __func__,

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

@ -12,7 +12,6 @@
#include "nsPluginArray.h"
#include "nsMimeTypeArray.h"
#include "mozilla/Components.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/BodyExtractor.h"

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

@ -24,7 +24,6 @@
#include "nsISecureBrowserUI.h"
#include "nsIWebProgressListener.h"
#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/dom/AutoPrintEventDispatcher.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/BrowserChild.h"
@ -52,6 +51,7 @@
#include "mozilla/dom/WindowFeatures.h" // WindowFeatures
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "nsBaseCommandController.h"
#include "nsError.h"
#include "nsICookieService.h"
@ -7134,8 +7134,8 @@ void nsGlobalWindowOuter::MaybeAllowStorageForOpenedWindow(nsIURI* aURI) {
aURI, doc->NodePrincipal()->OriginAttributesRef());
// We don't care when the asynchronous work finishes here.
Unused << ContentBlocking::AllowAccessFor(principal, GetBrowsingContext(),
ContentBlockingNotifier::eOpener);
Unused << StorageAccessAPIHelper::AllowAccessFor(
principal, GetBrowsingContext(), ContentBlockingNotifier::eOpener);
}
//*****************************************************************************

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

@ -18,7 +18,6 @@
#include "mozilla/Attributes.h"
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/BenchmarkStorageChild.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/FOGIPC.h"
#include "GMPServiceChild.h"
#include "Geolocation.h"
@ -49,6 +48,7 @@
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "mozilla/TelemetryIPC.h"
#include "mozilla/Unused.h"
#include "mozilla/WebBrowserPersistDocumentChild.h"
@ -3621,8 +3621,8 @@ mozilla::ipc::IPCResult ContentChild::RecvOnAllowAccessFor(
aReason) {
MOZ_ASSERT(!aContext.IsNull(), "Browsing context cannot be null");
ContentBlocking::OnAllowAccessFor(aContext.GetMaybeDiscarded(),
aTrackingOrigin, aCookieBehavior, aReason);
StorageAccessAPIHelper::OnAllowAccessFor(
aContext.GetMaybeDiscarded(), aTrackingOrigin, aCookieBehavior, aReason);
return IPC_OK();
}

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

@ -55,7 +55,6 @@
#include "gfxPlatformFontList.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/BenchmarkStorageParent.h"
#include "mozilla/ContentBlockingUserInteraction.h"
@ -83,6 +82,7 @@
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/Telemetry.h"
@ -6406,18 +6406,17 @@ ContentParent::RecvStorageAccessPermissionGrantedForOrigin(
aReason.value());
}
ContentBlocking::SaveAccessForOriginOnParentProcess(
StorageAccessAPIHelper::SaveAccessForOriginOnParentProcess(
aTopLevelWindowId, aParentContext.get_canonical(), aTrackingPrincipal,
aAllowMode)
->Then(
GetCurrentSerialEventTarget(), __func__,
[aResolver = std::move(aResolver)](
ContentBlocking::ParentAccessGrantPromise::ResolveOrRejectValue&&
aValue) {
bool success =
aValue.IsResolve() && NS_SUCCEEDED(aValue.ResolveValue());
aResolver(success);
});
->Then(GetCurrentSerialEventTarget(), __func__,
[aResolver = std::move(aResolver)](
StorageAccessAPIHelper::ParentAccessGrantPromise::
ResolveOrRejectValue&& aValue) {
bool success =
aValue.IsResolve() && NS_SUCCEEDED(aValue.ResolveValue());
aResolver(success);
});
return IPC_OK();
}
@ -6432,12 +6431,12 @@ mozilla::ipc::IPCResult ContentParent::RecvCompleteAllowAccessFor(
return IPC_OK();
}
ContentBlocking::CompleteAllowAccessFor(
StorageAccessAPIHelper::CompleteAllowAccessFor(
aParentContext.get_canonical(), aTopLevelWindowId, aTrackingPrincipal,
aTrackingOrigin, aCookieBehavior, aReason, nullptr)
->Then(GetCurrentSerialEventTarget(), __func__,
[aResolver = std::move(aResolver)](
ContentBlocking::StorageAccessPermissionGrantPromise::
StorageAccessAPIHelper::StorageAccessPermissionGrantPromise::
ResolveOrRejectValue&& aValue) {
Maybe<StorageAccessPromptChoices> choice;
if (aValue.IsResolve()) {
@ -6471,8 +6470,8 @@ mozilla::ipc::IPCResult ContentParent::RecvTestCookiePermissionDecided(
nsCOMPtr<nsICookieJarSettings> cjs = wgp->CookieJarSettings();
Maybe<bool> result =
ContentBlocking::CheckCookiesPermittedDecidesStorageAccessAPI(cjs,
aPrincipal);
StorageAccessAPIHelper::CheckCookiesPermittedDecidesStorageAccessAPI(
cjs, aPrincipal);
aResolver(result);
return IPC_OK();
}

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

@ -140,7 +140,7 @@ using mozilla::dom::PositionState from "mozilla/dom/MediaSession.h";
using mozilla::dom::ServiceWorkerShutdownState::Progress from "mozilla/dom/ServiceWorkerShutdownState.h";
using mozilla::ContentBlockingNotifier::StorageAccessPermissionGrantedReason from "mozilla/ContentBlockingNotifier.h";
using mozilla::ContentBlockingNotifier::BlockingDecision from "mozilla/ContentBlockingNotifier.h";
using mozilla::ContentBlocking::StorageAccessPromptChoices from "mozilla/ContentBlocking.h";
using mozilla::StorageAccessAPIHelper::StorageAccessPromptChoices from "mozilla/StorageAccessAPIHelper.h";
using JSActorMessageKind from "mozilla/dom/JSActor.h";
using JSActorMessageMeta from "mozilla/dom/PWindowGlobal.h";
using mozilla::PermissionDelegateHandler::DelegatedPermissionList from "mozilla/PermissionDelegateHandler.h";

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

@ -19,7 +19,6 @@
#include "nsProxyRelease.h"
#include "nsQueryObject.h"
#include "NeckoChild.h"
#include "mozilla/ContentBlocking.h"
#include "nsIHttpChannel.h"
#include "nsIStreamListener.h"

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

@ -59,7 +59,6 @@
#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Preferences.h"
#include "mozilla/ProfilerLabels.h"

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

@ -10,7 +10,7 @@
#include "ipc/EnumSerializer.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "nsILoadInfo.h"
@ -38,13 +38,13 @@ struct ParamTraits<mozilla::ContentBlockingNotifier::BlockingDecision>
mozilla::ContentBlockingNotifier::BlockingDecision::eBlock,
mozilla::ContentBlockingNotifier::BlockingDecision::eAllow> {};
// ContentBlocking::StorageAccessPromptChoices over IPC.
// StorageAccessAPIHelper::StorageAccessPromptChoices over IPC.
template <>
struct ParamTraits<mozilla::ContentBlocking::StorageAccessPromptChoices>
struct ParamTraits<mozilla::StorageAccessAPIHelper::StorageAccessPromptChoices>
: public ContiguousEnumSerializerInclusive<
mozilla::ContentBlocking::StorageAccessPromptChoices,
mozilla::ContentBlocking::StorageAccessPromptChoices::eAllow,
mozilla::ContentBlocking::StorageAccessPromptChoices::
mozilla::StorageAccessAPIHelper::StorageAccessPromptChoices,
mozilla::StorageAccessAPIHelper::StorageAccessPromptChoices::eAllow,
mozilla::StorageAccessAPIHelper::StorageAccessPromptChoices::
eAllowAutoGrant> {};
// nsILoadInfo::StoragePermissionState over IPC.

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

@ -6,9 +6,9 @@
#include "AntiTrackingLog.h"
#include "AntiTrackingRedirectHeuristic.h"
#include "ContentBlocking.h"
#include "ContentBlockingAllowList.h"
#include "ContentBlockingUserInteraction.h"
#include "StorageAccessAPIHelper.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/Document.h"
@ -422,10 +422,10 @@ void FinishAntiTrackingRedirectHeuristic(nsIChannel* aNewChannel,
Telemetry::LABELS_STORAGE_ACCESS_GRANTED_COUNT::Redirect);
// We don't care about this promise because the operation is actually sync.
RefPtr<ContentBlocking::ParentAccessGrantPromise> promise =
ContentBlocking::SaveAccessForOriginOnParentProcess(
RefPtr<StorageAccessAPIHelper::ParentAccessGrantPromise> promise =
StorageAccessAPIHelper::SaveAccessForOriginOnParentProcess(
newPrincipal, oldPrincipal,
ContentBlocking::StorageAccessPromptChoices::eAllow,
StorageAccessAPIHelper::StorageAccessPromptChoices::eAllow,
StaticPrefs::privacy_restrict3rdpartystorage_expiration_redirect());
Unused << promise;
}

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

@ -30,7 +30,10 @@ class ContentBlockingAllowList final {
bool aIsPrivateBrowsing, bool& aIsAllowListed);
static bool Check(nsIHttpChannel* aChannel);
// Utility APIs for ContentBlocking.
static bool Check(nsPIDOMWindowInner* aWindow);
static bool Check(nsIPrincipal* aTopWinPrincipal, bool aIsPrivateBrowsing);
static bool Check(nsICookieJarSettings* aCookieJarSettings);
// Computes the principal used to check the content blocking allow list for a
// top-level document based on the document principal. This function is used
@ -41,13 +44,6 @@ class ContentBlockingAllowList final {
static void RecomputePrincipal(nsIURI* aURIBeingLoaded,
const OriginAttributes& aAttrs,
nsIPrincipal** aPrincipal);
private:
// Utility APIs for ContentBlocking.
static bool Check(nsIPrincipal* aTopWinPrincipal, bool aIsPrivateBrowsing);
static bool Check(nsICookieJarSettings* aCookieJarSettings);
friend class ContentBlocking;
};
} // namespace mozilla

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

@ -12,6 +12,7 @@
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/WindowGlobalParent.h"
#include "nsIClassifiedChannel.h"
#include "nsIRunnable.h"

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

@ -6,9 +6,9 @@
#include "AntiTrackingLog.h"
#include "DynamicFpiRedirectHeuristic.h"
#include "ContentBlocking.h"
#include "ContentBlockingAllowList.h"
#include "ContentBlockingUserInteraction.h"
#include "StorageAccessAPIHelper.h"
#include "mozilla/net/HttpBaseChannel.h"
#include "mozilla/Telemetry.h"
@ -329,10 +329,10 @@ void DynamicFpiRedirectHeuristic(nsIChannel* aOldChannel, nsIURI* aOldURI,
Telemetry::LABELS_STORAGE_ACCESS_GRANTED_COUNT::Redirect);
// We don't care about this promise because the operation is actually sync.
RefPtr<ContentBlocking::ParentAccessGrantPromise> promise =
ContentBlocking::SaveAccessForOriginOnParentProcess(
RefPtr<StorageAccessAPIHelper::ParentAccessGrantPromise> promise =
StorageAccessAPIHelper::SaveAccessForOriginOnParentProcess(
newPrincipal, oldPrincipal,
ContentBlocking::StorageAccessPromptChoices::eAllow,
StorageAccessAPIHelper::StorageAccessPromptChoices::eAllow,
StaticPrefs::privacy_restrict3rdpartystorage_expiration_visited());
Unused << promise;
}

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

@ -22,6 +22,7 @@
using namespace mozilla;
using namespace mozilla::dom;
using mozilla::net::CookieJarSettings;
/**
* Gets the cookie lifetime policy for a given cookieJarSettings and a given
@ -56,6 +57,28 @@ static void GetCookieLifetimePolicyFromCookieJarSettings(
}
}
// This internal method returns ACCESS_DENY if the access is denied,
// ACCESS_DEFAULT if unknown, some other access code if granted.
uint32_t CheckCookiePermissionForPrincipal(
nsICookieJarSettings* aCookieJarSettings, nsIPrincipal* aPrincipal) {
MOZ_ASSERT(aCookieJarSettings);
MOZ_ASSERT(aPrincipal);
uint32_t cookiePermission = nsICookiePermission::ACCESS_DEFAULT;
if (!aPrincipal->GetIsContentPrincipal()) {
return cookiePermission;
}
nsresult rv =
aCookieJarSettings->CookiePermission(aPrincipal, &cookiePermission);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nsICookiePermission::ACCESS_DEFAULT;
}
// If we have a custom cookie permission, let's use it.
return cookiePermission;
}
/*
* Checks if storage for a given principal is permitted by the user's
* preferences. If aWindow is non-null, its principal must be passed as
@ -415,6 +438,52 @@ bool StoragePartitioningEnabled(uint32_t aRejectedReason,
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
}
int32_t CookiesBehavior(Document* a3rdPartyDocument) {
MOZ_ASSERT(a3rdPartyDocument);
// WebExtensions principals always get BEHAVIOR_ACCEPT as cookieBehavior
// (See Bug 1406675 and Bug 1525917 for rationale).
if (BasePrincipal::Cast(a3rdPartyDocument->NodePrincipal())->AddonPolicy()) {
return nsICookieService::BEHAVIOR_ACCEPT;
}
return a3rdPartyDocument->CookieJarSettings()->GetCookieBehavior();
}
int32_t CookiesBehavior(nsILoadInfo* aLoadInfo, nsIURI* a3rdPartyURI) {
MOZ_ASSERT(aLoadInfo);
MOZ_ASSERT(a3rdPartyURI);
// WebExtensions 3rd party URI always get BEHAVIOR_ACCEPT as cookieBehavior,
// this is semantically equivalent to the principal having a AddonPolicy().
if (a3rdPartyURI->SchemeIs("moz-extension")) {
return nsICookieService::BEHAVIOR_ACCEPT;
}
nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
nsresult rv =
aLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nsICookieService::BEHAVIOR_REJECT;
}
return cookieJarSettings->GetCookieBehavior();
}
int32_t CookiesBehavior(nsIPrincipal* aPrincipal,
nsICookieJarSettings* aCookieJarSettings) {
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(aCookieJarSettings);
// WebExtensions principals always get BEHAVIOR_ACCEPT as cookieBehavior
// (See Bug 1406675 for rationale).
if (BasePrincipal::Cast(aPrincipal)->AddonPolicy()) {
return nsICookieService::BEHAVIOR_ACCEPT;
}
return aCookieJarSettings->GetCookieBehavior();
}
bool ShouldAllowAccessFor(nsPIDOMWindowInner* aWindow, nsIURI* aURI,
uint32_t* aRejectedReason) {
MOZ_ASSERT(aWindow);
@ -863,5 +932,4 @@ bool ApproximateAllowAccessForWithoutChannel(
parentPrincipal, type,
nsContentUtils::IsInPrivateBrowsing(parentDocument), nullptr, 0);
}
} // namespace mozilla

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

@ -5,7 +5,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AntiTrackingLog.h"
#include "ContentBlocking.h"
#include "StorageAccessAPIHelper.h"
#include "AntiTrackingUtils.h"
#include "TemporaryAccessGrantObserver.h"
@ -64,80 +64,13 @@ bool GetTopLevelWindowId(BrowsingContext* aParentContext, uint32_t aBehavior,
return aTopLevelInnerWindowId != 0;
}
// This internal method returns ACCESS_DENY if the access is denied,
// ACCESS_DEFAULT if unknown, some other access code if granted.
uint32_t CheckCookiePermissionForPrincipal(
nsICookieJarSettings* aCookieJarSettings, nsIPrincipal* aPrincipal) {
MOZ_ASSERT(aCookieJarSettings);
MOZ_ASSERT(aPrincipal);
uint32_t cookiePermission = nsICookiePermission::ACCESS_DEFAULT;
if (!aPrincipal->GetIsContentPrincipal()) {
return cookiePermission;
}
nsresult rv =
aCookieJarSettings->CookiePermission(aPrincipal, &cookiePermission);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nsICookiePermission::ACCESS_DEFAULT;
}
// If we have a custom cookie permission, let's use it.
return cookiePermission;
}
int32_t CookiesBehavior(Document* a3rdPartyDocument) {
MOZ_ASSERT(a3rdPartyDocument);
// WebExtensions principals always get BEHAVIOR_ACCEPT as cookieBehavior
// (See Bug 1406675 and Bug 1525917 for rationale).
if (BasePrincipal::Cast(a3rdPartyDocument->NodePrincipal())->AddonPolicy()) {
return nsICookieService::BEHAVIOR_ACCEPT;
}
return a3rdPartyDocument->CookieJarSettings()->GetCookieBehavior();
}
int32_t CookiesBehavior(nsILoadInfo* aLoadInfo, nsIURI* a3rdPartyURI) {
MOZ_ASSERT(aLoadInfo);
MOZ_ASSERT(a3rdPartyURI);
// WebExtensions 3rd party URI always get BEHAVIOR_ACCEPT as cookieBehavior,
// this is semantically equivalent to the principal having a AddonPolicy().
if (a3rdPartyURI->SchemeIs("moz-extension")) {
return nsICookieService::BEHAVIOR_ACCEPT;
}
nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
nsresult rv =
aLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nsICookieService::BEHAVIOR_REJECT;
}
return cookieJarSettings->GetCookieBehavior();
}
int32_t CookiesBehavior(nsIPrincipal* aPrincipal,
nsICookieJarSettings* aCookieJarSettings) {
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(aCookieJarSettings);
// WebExtensions principals always get BEHAVIOR_ACCEPT as cookieBehavior
// (See Bug 1406675 for rationale).
if (BasePrincipal::Cast(aPrincipal)->AddonPolicy()) {
return nsICookieService::BEHAVIOR_ACCEPT;
}
return aCookieJarSettings->GetCookieBehavior();
}
} // namespace
/* static */ RefPtr<ContentBlocking::StorageAccessPermissionGrantPromise>
ContentBlocking::AllowAccessFor(
/* static */ RefPtr<StorageAccessAPIHelper::StorageAccessPermissionGrantPromise>
StorageAccessAPIHelper::AllowAccessFor(
nsIPrincipal* aPrincipal, dom::BrowsingContext* aParentContext,
ContentBlockingNotifier::StorageAccessPermissionGrantedReason aReason,
const ContentBlocking::PerformFinalChecks& aPerformFinalChecks) {
const StorageAccessAPIHelper::PerformFinalChecks& aPerformFinalChecks) {
MOZ_ASSERT(aParentContext);
switch (aReason) {
@ -350,7 +283,7 @@ ContentBlocking::AllowAccessFor(
}
if (runInSameProcess) {
return ContentBlocking::CompleteAllowAccessFor(
return StorageAccessAPIHelper::CompleteAllowAccessFor(
aParentContext, topLevelWindowId, trackingPrincipal, trackingOrigin,
behavior, aReason, aPerformFinalChecks);
}
@ -380,8 +313,8 @@ ContentBlocking::AllowAccessFor(
if (aReason == ContentBlockingNotifier::eOpener &&
!bc->IsDiscarded()) {
MOZ_ASSERT(bc->IsInProcess());
ContentBlocking::OnAllowAccessFor(bc, trackingOrigin,
behavior, aReason);
StorageAccessAPIHelper::OnAllowAccessFor(bc, trackingOrigin,
behavior, aReason);
}
return StorageAccessPermissionGrantPromise::CreateAndResolve(
aValue.ResolveValue().value(), __func__);
@ -422,8 +355,8 @@ ContentBlocking::AllowAccessFor(
// privilege API. So, it is always in-process. And we don't need to check the
// user interaction permission for the tracking origin in this case. We can
// run in the same process.
/* static */ RefPtr<ContentBlocking::StorageAccessPermissionGrantPromise>
ContentBlocking::CompleteAllowAccessFor(
/* static */ RefPtr<StorageAccessAPIHelper::StorageAccessPermissionGrantPromise>
StorageAccessAPIHelper::CompleteAllowAccessFor(
dom::BrowsingContext* aParentContext, uint64_t aTopLevelWindowId,
nsIPrincipal* aTrackingPrincipal, const nsCString& aTrackingOrigin,
uint32_t aCookieBehavior,
@ -507,8 +440,8 @@ ContentBlocking::CompleteAllowAccessFor(
// Inform the window we granted permission for. This has to be done in the
// window's process.
if (aParentContext->IsInProcess()) {
ContentBlocking::OnAllowAccessFor(aParentContext, trackingOrigin,
aCookieBehavior, aReason);
StorageAccessAPIHelper::OnAllowAccessFor(aParentContext, trackingOrigin,
aCookieBehavior, aReason);
} else {
MOZ_ASSERT(XRE_IsParentProcess());
@ -560,7 +493,7 @@ ContentBlocking::CompleteAllowAccessFor(
ContentBlockingUserInteraction::Observe(trackingPrincipal);
}
return StorageAccessPermissionGrantPromise::CreateAndResolve(
ContentBlocking::eAllow, __func__);
StorageAccessAPIHelper::eAllow, __func__);
});
}
@ -614,7 +547,7 @@ ContentBlocking::CompleteAllowAccessFor(
return storePermission(false);
}
/* static */ void ContentBlocking::OnAllowAccessFor(
/* static */ void StorageAccessAPIHelper::OnAllowAccessFor(
dom::BrowsingContext* aParentContext, const nsCString& aTrackingOrigin,
uint32_t aCookieBehavior,
ContentBlockingNotifier::StorageAccessPermissionGrantedReason aReason) {
@ -622,8 +555,8 @@ ContentBlocking::CompleteAllowAccessFor(
// Let's inform the parent window and the other windows having the
// same tracking origin about the storage permission is granted.
ContentBlocking::UpdateAllowAccessOnCurrentProcess(aParentContext,
aTrackingOrigin);
StorageAccessAPIHelper::UpdateAllowAccessOnCurrentProcess(aParentContext,
aTrackingOrigin);
// Let's inform the parent window.
nsCOMPtr<nsPIDOMWindowInner> parentInner =
@ -676,8 +609,8 @@ ContentBlocking::CompleteAllowAccessFor(
}
/* static */
RefPtr<mozilla::ContentBlocking::ParentAccessGrantPromise>
ContentBlocking::SaveAccessForOriginOnParentProcess(
RefPtr<mozilla::StorageAccessAPIHelper::ParentAccessGrantPromise>
StorageAccessAPIHelper::SaveAccessForOriginOnParentProcess(
uint64_t aTopLevelWindowId, BrowsingContext* aParentContext,
nsIPrincipal* aTrackingPrincipal, int aAllowMode,
uint64_t aExpirationTime) {
@ -707,17 +640,17 @@ ContentBlocking::SaveAccessForOriginOnParentProcess(
// If the permission is granted on a first-party window, also have to update
// the permission to all the other windows with the same tracking origin (in
// the same tab), if any.
ContentBlocking::UpdateAllowAccessOnParentProcess(aParentContext,
trackingOrigin);
StorageAccessAPIHelper::UpdateAllowAccessOnParentProcess(aParentContext,
trackingOrigin);
return ContentBlocking::SaveAccessForOriginOnParentProcess(
return StorageAccessAPIHelper::SaveAccessForOriginOnParentProcess(
wgp->DocumentPrincipal(), aTrackingPrincipal, aAllowMode,
aExpirationTime);
}
/* static */
RefPtr<mozilla::ContentBlocking::ParentAccessGrantPromise>
ContentBlocking::SaveAccessForOriginOnParentProcess(
RefPtr<mozilla::StorageAccessAPIHelper::ParentAccessGrantPromise>
StorageAccessAPIHelper::SaveAccessForOriginOnParentProcess(
nsIPrincipal* aParentPrincipal, nsIPrincipal* aTrackingPrincipal,
int aAllowMode, uint64_t aExpirationTime) {
MOZ_ASSERT(XRE_IsParentProcess());
@ -803,7 +736,8 @@ ContentBlocking::SaveAccessForOriginOnParentProcess(
}
// static
Maybe<bool> ContentBlocking::CheckCookiesPermittedDecidesStorageAccessAPI(
Maybe<bool>
StorageAccessAPIHelper::CheckCookiesPermittedDecidesStorageAccessAPI(
nsICookieJarSettings* aCookieJarSettings,
nsIPrincipal* aRequestingPrincipal) {
MOZ_ASSERT(aCookieJarSettings);
@ -825,7 +759,7 @@ Maybe<bool> ContentBlocking::CheckCookiesPermittedDecidesStorageAccessAPI(
// static
RefPtr<MozPromise<Maybe<bool>, nsresult, true>>
ContentBlocking::AsyncCheckCookiesPermittedDecidesStorageAccessAPI(
StorageAccessAPIHelper::AsyncCheckCookiesPermittedDecidesStorageAccessAPI(
dom::BrowsingContext* aBrowsingContext,
nsIPrincipal* aRequestingPrincipal) {
MOZ_ASSERT(XRE_IsContentProcess());
@ -850,7 +784,7 @@ ContentBlocking::AsyncCheckCookiesPermittedDecidesStorageAccessAPI(
}
// static
Maybe<bool> ContentBlocking::CheckBrowserSettingsDecidesStorageAccessAPI(
Maybe<bool> StorageAccessAPIHelper::CheckBrowserSettingsDecidesStorageAccessAPI(
nsICookieJarSettings* aCookieJarSettings, bool aThirdParty,
bool aOnRejectForeignAllowlist, bool aIsOnThirdPartySkipList,
bool aIsThirdPartyTracker) {
@ -898,7 +832,7 @@ Maybe<bool> ContentBlocking::CheckBrowserSettingsDecidesStorageAccessAPI(
}
// static
Maybe<bool> ContentBlocking::CheckCallingContextDecidesStorageAccessAPI(
Maybe<bool> StorageAccessAPIHelper::CheckCallingContextDecidesStorageAccessAPI(
Document* aDocument, bool aRequestingStorageAccess) {
MOZ_ASSERT(aDocument);
// Window doesn't have user activation and we are asking for access -> reject.
@ -970,7 +904,8 @@ Maybe<bool> ContentBlocking::CheckCallingContextDecidesStorageAccessAPI(
}
// static
Maybe<bool> ContentBlocking::CheckSameSiteCallingContextDecidesStorageAccessAPI(
Maybe<bool>
StorageAccessAPIHelper::CheckSameSiteCallingContextDecidesStorageAccessAPI(
dom::Document* aDocument, bool aRequireUserActivation) {
MOZ_ASSERT(aDocument);
if (aRequireUserActivation) {
@ -1006,7 +941,8 @@ Maybe<bool> ContentBlocking::CheckSameSiteCallingContextDecidesStorageAccessAPI(
}
// static
Maybe<bool> ContentBlocking::CheckExistingPermissionDecidesStorageAccessAPI(
Maybe<bool>
StorageAccessAPIHelper::CheckExistingPermissionDecidesStorageAccessAPI(
dom::Document* aDocument) {
MOZ_ASSERT(aDocument);
if (aDocument->StorageAccessSandboxed()) {
@ -1041,7 +977,7 @@ Maybe<bool> ContentBlocking::CheckExistingPermissionDecidesStorageAccessAPI(
// This function is used to update permission to all in-process windows, so it
// can be called either from the parent or the child.
/* static */
void ContentBlocking::UpdateAllowAccessOnCurrentProcess(
void StorageAccessAPIHelper::UpdateAllowAccessOnCurrentProcess(
BrowsingContext* aParentContext, const nsACString& aTrackingOrigin) {
MOZ_ASSERT(aParentContext && aParentContext->IsInProcess());
@ -1076,7 +1012,7 @@ void ContentBlocking::UpdateAllowAccessOnCurrentProcess(
}
/* static */
void ContentBlocking::UpdateAllowAccessOnParentProcess(
void StorageAccessAPIHelper::UpdateAllowAccessOnParentProcess(
BrowsingContext* aParentContext, const nsACString& aTrackingOrigin) {
MOZ_ASSERT(XRE_IsParentProcess());

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

@ -33,7 +33,7 @@ class ContentParent;
class Document;
} // namespace dom
class ContentBlocking final {
class StorageAccessAPIHelper final {
public:
enum StorageAccessPromptChoices { eAllow, eAllowAutoGrant };

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

@ -38,7 +38,6 @@ EXPORTS.mozilla = [
"AntiTrackingIPCUtils.h",
"AntiTrackingRedirectHeuristic.h",
"AntiTrackingUtils.h",
"ContentBlocking.h",
"ContentBlockingAllowList.h",
"ContentBlockingLog.h",
"ContentBlockingNotifier.h",
@ -48,6 +47,7 @@ EXPORTS.mozilla = [
"PartitioningExceptionList.h",
"RejectForeignAllowList.h",
"StorageAccess.h",
"StorageAccessAPIHelper.h",
"StoragePrincipalHelper.h",
"URLDecorationStripper.h",
"URLQueryStringStripper.h",
@ -56,7 +56,6 @@ EXPORTS.mozilla = [
UNIFIED_SOURCES += [
"AntiTrackingRedirectHeuristic.cpp",
"AntiTrackingUtils.cpp",
"ContentBlocking.cpp",
"ContentBlockingAllowList.cpp",
"ContentBlockingLog.cpp",
"ContentBlockingNotifier.cpp",
@ -67,6 +66,7 @@ UNIFIED_SOURCES += [
"RejectForeignAllowList.cpp",
"SettingsChangeObserver.cpp",
"StorageAccess.cpp",
"StorageAccessAPIHelper.cpp",
"StoragePrincipalHelper.cpp",
"TemporaryAccessGrantObserver.cpp",
"URLDecorationStripper.cpp",