mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1663192 - Part 2: Set the IsThirdPartyToTopWindow in the nsBaseChannel. r=dimi,kershaw,necko-reviewers
We should also set IsThirdPartyToTopWindow flag and HasStoragePermission in loadInfo for channels loading `file:` uri. So, we set this flag in the nsBaseChannel::AsyncOpen(). This change would affect about: and data: channels. Differential Revision: https://phabricator.services.mozilla.com/D91002
This commit is contained in:
parent
85ee48719b
commit
a5c949a08a
@ -22,6 +22,7 @@
|
||||
#include "LoadInfo.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsRedirectHistoryEntry.h"
|
||||
#include "mozilla/AntiTrackingUtils.h"
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
|
||||
using namespace mozilla;
|
||||
@ -701,6 +702,8 @@ nsBaseChannel::AsyncOpen(nsIStreamListener* aListener) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
AntiTrackingUtils::UpdateAntiTrackingInfoForChannel(this);
|
||||
|
||||
// Store the listener and context early so that OpenContentStream and the
|
||||
// stream's AsyncWait method (called by AsyncRead) can have access to them
|
||||
// via PushStreamConverter and the StreamListener methods. However, since
|
||||
|
@ -1885,31 +1885,6 @@ void nsHttpChannel::SetCachedContentType() {
|
||||
mCacheEntry->SetContentType(contentType);
|
||||
}
|
||||
|
||||
void nsHttpChannel::UpdateAntiTrackingInfo() {
|
||||
Unused << mLoadInfo->SetHasStoragePermission(
|
||||
AntiTrackingUtils::HasStoragePermissionInParent(this));
|
||||
|
||||
AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(this);
|
||||
|
||||
if (mLoadInfo->GetExternalContentPolicyType() ==
|
||||
nsIContentPolicy::TYPE_DOCUMENT) {
|
||||
nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
|
||||
Unused << mLoadInfo->GetCookieJarSettings(
|
||||
getter_AddRefs(cookieJarSettings));
|
||||
|
||||
// Update the IsOnContentBlockingAllowList flag in the CookieJarSettings
|
||||
// if this is a top level loading. For sub-document loading, this flag
|
||||
// would inherit from the parent.
|
||||
mozilla::net::CookieJarSettings::Cast(cookieJarSettings)
|
||||
->UpdateIsOnContentBlockingAllowList(this);
|
||||
|
||||
// We only need to set FPD for top-level loads. FPD will automatically be
|
||||
// propagated to non-top level loads via CookieJarSetting.
|
||||
mozilla::net::CookieJarSettings::Cast(cookieJarSettings)
|
||||
->SetPartitionKey(mURI);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsHttpChannel::CallOnStartRequest() {
|
||||
LOG(("nsHttpChannel::CallOnStartRequest [this=%p]", this));
|
||||
|
||||
@ -6767,7 +6742,7 @@ nsHttpChannel::AsyncOpen(nsIStreamListener* aListener) {
|
||||
UpdatePrivateBrowsing();
|
||||
}
|
||||
|
||||
UpdateAntiTrackingInfo();
|
||||
AntiTrackingUtils::UpdateAntiTrackingInfoForChannel(this);
|
||||
|
||||
if (WaitingForTailUnblock()) {
|
||||
// This channel is marked as Tail and is part of a request context
|
||||
|
@ -557,11 +557,6 @@ class nsHttpChannel final : public HttpBaseChannel,
|
||||
// writing a new entry. The content type is used in cache internally only.
|
||||
void SetCachedContentType();
|
||||
|
||||
// This function updates all the fields used by anti-tracking when a channel
|
||||
// is opened. We have to do this in the parent to access cross-origin info
|
||||
// that is not exposed to child processes.
|
||||
void UpdateAntiTrackingInfo();
|
||||
|
||||
private:
|
||||
// this section is for main-thread-only object
|
||||
// all the references need to be proxy released on main thread.
|
||||
|
@ -674,3 +674,51 @@ nsCString AntiTrackingUtils::GrantedReasonToString(
|
||||
return "stroage access API"_ns;
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
void AntiTrackingUtils::UpdateAntiTrackingInfoForChannel(nsIChannel* aChannel) {
|
||||
MOZ_ASSERT(aChannel);
|
||||
|
||||
if (!XRE_IsParentProcess()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
||||
|
||||
Unused << loadInfo->SetHasStoragePermission(
|
||||
AntiTrackingUtils::HasStoragePermissionInParent(aChannel));
|
||||
|
||||
AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(aChannel);
|
||||
|
||||
// We only update the IsOnContentBlockingAllowList flag and the partition key
|
||||
// for the top-level http channel.
|
||||
//
|
||||
// The IsOnContentBlockingAllowList is only for http. For other types of
|
||||
// channels, such as 'file:', there will be no interface to modify this. So,
|
||||
// we only update it in http channels.
|
||||
//
|
||||
// The partition key is computed based on the site, so it's no point to set it
|
||||
// for channels other than http channels.
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
|
||||
if (!httpChannel || loadInfo->GetExternalContentPolicyType() !=
|
||||
nsIContentPolicy::TYPE_DOCUMENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
|
||||
Unused << loadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings));
|
||||
|
||||
// Update the IsOnContentBlockingAllowList flag in the CookieJarSettings
|
||||
// if this is a top level loading. For sub-document loading, this flag
|
||||
// would inherit from the parent.
|
||||
net::CookieJarSettings::Cast(cookieJarSettings)
|
||||
->UpdateIsOnContentBlockingAllowList(aChannel);
|
||||
|
||||
// We only need to set FPD for top-level loads. FPD will automatically be
|
||||
// propagated to non-top level loads via CookieJarSetting.
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
Unused << aChannel->GetURI(getter_AddRefs(uri));
|
||||
net::CookieJarSettings::Cast(cookieJarSettings)->SetPartitionKey(uri);
|
||||
}
|
||||
|
@ -123,6 +123,13 @@ class AntiTrackingUtils final {
|
||||
|
||||
static nsCString GrantedReasonToString(
|
||||
ContentBlockingNotifier::StorageAccessPermissionGrantedReason aReason);
|
||||
|
||||
/**
|
||||
* This function updates all the fields used by anti-tracking when a channel
|
||||
* is opened. We have to do this in the parent to access cross-origin info
|
||||
* that is not exposed to child processes.
|
||||
*/
|
||||
static void UpdateAntiTrackingInfoForChannel(nsIChannel* aChannel);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
Loading…
Reference in New Issue
Block a user