Skip to content

Commit

Permalink
Bug 1765313, part 2 - Move the ShouldAllowAccessFor functions to Stor…
Browse files Browse the repository at this point in the history
…ageAccess.h, r=anti-tracking-reviewers,timhuang

These functions are used to check if an object or context should have storage access.
Therefore they belong in StorageAccess.h with other functions that serve this purpose.

Differential Revision: https://phabricator.services.mozilla.com/D148285
  • Loading branch information
bvandersloot-mozilla committed Jun 8, 2022
1 parent 1290825 commit 5157d54
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 518 deletions.
5 changes: 2 additions & 3 deletions caps/BasePrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "prnetdb.h"
#include "nsIURIFixup.h"
#include "mozilla/dom/StorageUtils.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/StorageAccess.h"
#include "nsPIDOMWindow.h"
#include "nsIURIMutator.h"
#include "mozilla/PermissionManager.h"
Expand Down Expand Up @@ -785,8 +785,7 @@ BasePrincipal::HasFirstpartyStorageAccess(mozIDOMWindow* aCheckWindow,
if (NS_FAILED(rv)) {
return rv;
}
*aOutAllowed =
ContentBlocking::ShouldAllowAccessFor(win, uri, aRejectedReason);
*aOutAllowed = ShouldAllowAccessFor(win, uri, aRejectedReason);
return NS_OK;
}

Expand Down
4 changes: 1 addition & 3 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include "mozilla/Base64.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/CSSEnabledState.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ContentBlockingAllowList.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/ContentBlockingUserInteraction.h"
Expand Down Expand Up @@ -17701,8 +17700,7 @@ nsIPrincipal* Document::EffectiveStoragePrincipal() const {
// We use the lower-level ContentBlocking API here to ensure this
// check doesn't send notifications.
uint32_t rejectedReason = 0;
if (ContentBlocking::ShouldAllowAccessFor(inner, GetDocumentURI(),
&rejectedReason)) {
if (ShouldAllowAccessFor(inner, GetDocumentURI(), &rejectedReason)) {
return mActiveStoragePrincipal = NodePrincipal();
}

Expand Down
6 changes: 3 additions & 3 deletions dom/base/ThirdPartyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include "mozilla/Assertions.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/Logging.h"
#include "mozilla/MacroForEach.h"
#include "mozilla/Components.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/BrowsingContext.h"
Expand Down Expand Up @@ -512,8 +512,8 @@ ThirdPartyUtil::AnalyzeChannel(nsIChannel* aChannel, bool aNotify, nsIURI* aURI,
aRequireThirdPartyCheck ? result.contains(ThirdPartyAnalysis::IsForeign)
: true;
if (performStorageChecks &&
ContentBlocking::ShouldAllowAccessFor(aChannel, aURI ? aURI : uri.get(),
aRejectedReason)) {
ShouldAllowAccessFor(aChannel, aURI ? aURI : uri.get(),
aRejectedReason)) {
result += ThirdPartyAnalysis::IsStorageAccessPermissionGranted;
}

Expand Down
5 changes: 2 additions & 3 deletions dom/security/ReferrerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#include "ReferrerInfo.h"

#include "mozilla/BasePrincipal.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ContentBlockingAllowList.h"
#include "mozilla/net/CookieJarSettings.h"
#include "mozilla/net/HttpBaseChannel.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/Telemetry.h"
#include "nsIWebProgressListener.h"
Expand Down Expand Up @@ -210,8 +210,7 @@ ReferrerPolicy ReferrerInfo::GetDefaultReferrerPolicy(nsIHttpChannel* aChannel,
if (XRE_IsParentProcess() && cjs->GetRejectThirdPartyContexts()) {
uint32_t rejectedReason = 0;
thirdPartyTrackerIsolated =
!ContentBlocking::ShouldAllowAccessFor(aChannel, aURI,
&rejectedReason) &&
!ShouldAllowAccessFor(aChannel, aURI, &rejectedReason) &&
rejectedReason !=
static_cast<uint32_t>(
nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN);
Expand Down
6 changes: 3 additions & 3 deletions image/ImageCacheKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <utility>

#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/StoragePrincipalHelper.h"
Expand All @@ -17,6 +16,7 @@
#include "mozilla/dom/File.h"
#include "mozilla/dom/ServiceWorkerManager.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StorageAccess.h"
#include "nsContentUtils.h"
#include "nsHashKeys.h"
#include "nsLayoutUtils.h"
Expand Down Expand Up @@ -153,8 +153,8 @@ nsCString ImageCacheKey::GetIsolationKey(Document* aDocument, nsIURI* aURI) {
// this point. The best approach here is to be conservative: if we are sure
// that the permission is granted, let's return 0. Otherwise, let's make a
// unique image cache per the top-level document eTLD+1.
if (!ContentBlocking::ApproximateAllowAccessForWithoutChannel(
aDocument->GetInnerWindow(), aURI)) {
if (!ApproximateAllowAccessForWithoutChannel(aDocument->GetInnerWindow(),
aURI)) {
// If we are here, the image is a 3rd-party resource loaded by a first-party
// context. We can just use the document's base domain as the key because it
// should be the same as the top-level document's base domain.
Expand Down
5 changes: 2 additions & 3 deletions netwerk/cookie/CookieCommons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "CookieCommons.h"
#include "CookieLogging.h"
#include "CookieService.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ConsoleReportCollector.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/nsMixedContentBlocker.h"
#include "mozilla/net/CookieJarSettings.h"
Expand Down Expand Up @@ -386,8 +386,7 @@ already_AddRefed<Cookie> CookieCommons::CreateCookieFromDocument(
if (aDocument->CookieJarSettings()->GetLimitForeignContexts() &&
!aHasExistingCookiesLambda(baseDomain,
storagePrincipal->OriginAttributesRef()) &&
!ContentBlocking::ShouldAllowAccessFor(innerWindow, principalURI,
&dummyRejectedReason)) {
!ShouldAllowAccessFor(innerWindow, principalURI, &dummyRejectedReason)) {
return nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions netwerk/protocol/http/ClassifierDummyChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

#include "ClassifierDummyChannel.h"

#include "mozilla/ContentBlocking.h"
#include "mozilla/net/ClassifierDummyChannelChild.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StorageAccess.h"
#include "nsContentSecurityManager.h"
#include "nsIChannel.h"
#include "nsIURI.h"
Expand Down Expand Up @@ -64,7 +64,7 @@ ClassifierDummyChannel::StorageAllowed(
return eAsyncNeeded;
}

if (ContentBlocking::ShouldAllowAccessFor(httpChannel, uri, nullptr)) {
if (ShouldAllowAccessFor(httpChannel, uri, nullptr)) {
return eStorageGranted;
}

Expand Down
5 changes: 2 additions & 3 deletions netwerk/protocol/http/ClassifierDummyChannelChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ClassifierDummyChannelChild.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/URIUtils.h"
#include "nsIURI.h"
#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/StorageAccess.h"
#include "nsIHttpChannelInternal.h"
#include "nsIHttpChannel.h"
#include "mozilla/net/NeckoChannelParams.h"
Expand Down Expand Up @@ -82,8 +82,7 @@ mozilla::ipc::IPCResult ClassifierDummyChannelChild::Recv__delete__(
RefPtr<HttpBaseChannel> httpChannel = do_QueryObject(channel);
httpChannel->AddClassificationFlags(aClassificationFlags, mIsThirdParty);

bool storageGranted =
ContentBlocking::ShouldAllowAccessFor(httpChannel, mURI, nullptr);
bool storageGranted = ShouldAllowAccessFor(httpChannel, mURI, nullptr);
mCallback(storageGranted);
return IPC_OK();
}
Expand Down
Loading

0 comments on commit 5157d54

Please sign in to comment.