Skip to content

Commit

Permalink
Bug 1798493 - Part 1: Use nsIPrincipal instead of ContentPrincipalInf…
Browse files Browse the repository at this point in the history
…o for PLockManager r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D163337
  • Loading branch information
saschanaz committed Jun 28, 2023
1 parent e9f0272 commit b46a392
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 93 deletions.
56 changes: 0 additions & 56 deletions caps/ContentPrincipalInfoHashKey.h

This file was deleted.

4 changes: 2 additions & 2 deletions caps/PrincipalHashKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PrincipalHashKey : public PLDHashEntryHdr {
MOZ_ASSERT(aKey);
MOZ_COUNT_CTOR(PrincipalHashKey);
}
PrincipalHashKey(PrincipalHashKey&& aKey)
PrincipalHashKey(PrincipalHashKey&& aKey) noexcept
: mPrincipal(std::move(aKey.mPrincipal)) {
MOZ_COUNT_CTOR(PrincipalHashKey);
}
Expand All @@ -43,7 +43,7 @@ class PrincipalHashKey : public PLDHashEntryHdr {
return aKey;
}
static PLDHashNumber HashKey(const nsIPrincipal* aKey) {
auto* bp = BasePrincipal::Cast(aKey);
const auto* bp = BasePrincipal::Cast(aKey);
return HashGeneric(bp->GetOriginNoSuffixHash(), bp->GetOriginSuffixHash());
}

Expand Down
1 change: 0 additions & 1 deletion caps/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ EXPORTS += [
EXPORTS.mozilla = [
"BasePrincipal.h",
"ContentPrincipal.h",
"ContentPrincipalInfoHashKey.h",
"ExpandedPrincipal.h",
"NullPrincipal.h",
"OriginAttributes.h",
Expand Down
10 changes: 5 additions & 5 deletions dom/clients/manager/ClientInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ ClientInfo& ClientInfo::operator=(const ClientInfo& aRight) {
return *this;
}

ClientInfo::ClientInfo(ClientInfo&& aRight) : mData(std::move(aRight.mData)) {}
ClientInfo::ClientInfo(ClientInfo&& aRight) noexcept
: mData(std::move(aRight.mData)) {}

ClientInfo& ClientInfo::operator=(ClientInfo&& aRight) {
ClientInfo& ClientInfo::operator=(ClientInfo&& aRight) noexcept {
mData.reset();
mData = std::move(aRight.mData);
return *this;
Expand Down Expand Up @@ -89,14 +90,14 @@ const IPCClientInfo& ClientInfo::ToIPC() const { return *mData; }
bool ClientInfo::IsPrivateBrowsing() const {
switch (PrincipalInfo().type()) {
case PrincipalInfo::TContentPrincipalInfo: {
auto& p = PrincipalInfo().get_ContentPrincipalInfo();
const auto& p = PrincipalInfo().get_ContentPrincipalInfo();
return p.attrs().mPrivateBrowsingId != 0;
}
case PrincipalInfo::TSystemPrincipalInfo: {
return false;
}
case PrincipalInfo::TNullPrincipalInfo: {
auto& p = PrincipalInfo().get_NullPrincipalInfo();
const auto& p = PrincipalInfo().get_NullPrincipalInfo();
return p.attrs().mPrivateBrowsingId != 0;
}
default: {
Expand All @@ -107,7 +108,6 @@ bool ClientInfo::IsPrivateBrowsing() const {
}

Result<nsCOMPtr<nsIPrincipal>, nsresult> ClientInfo::GetPrincipal() const {
MOZ_ASSERT(NS_IsMainThread());
return PrincipalInfoToPrincipal(PrincipalInfo());
}

Expand Down
4 changes: 2 additions & 2 deletions dom/clients/manager/ClientInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class ClientInfo final {

ClientInfo& operator=(const ClientInfo& aRight);

ClientInfo(ClientInfo&& aRight);
ClientInfo(ClientInfo&& aRight) noexcept;

ClientInfo& operator=(ClientInfo&& aRight);
ClientInfo& operator=(ClientInfo&& aRight) noexcept;

explicit ClientInfo(const IPCClientInfo& aData);

Expand Down
10 changes: 4 additions & 6 deletions dom/locks/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ LockManager::LockManager(nsIGlobalObject* aGlobal) : mOwner(aGlobal) {
return;
}

const mozilla::ipc::PrincipalInfo& principalInfo =
clientInfo->PrincipalInfo();

if (principalInfo.type() !=
mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) {
nsCOMPtr<nsIPrincipal> principal =
clientInfo->GetPrincipal().unwrapOr(nullptr);
if (!principal || !principal->GetIsContentPrincipal()) {
return;
}

mozilla::ipc::PBackgroundChild* backgroundActor =
mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread();
mActor = new locks::LockManagerChild(aGlobal);
backgroundActor->SendPLockManagerConstructor(mActor, principalInfo,
backgroundActor->SendPLockManagerConstructor(mActor, WrapNotNull(principal),
clientInfo->Id());

if (!NS_IsMainThread()) {
Expand Down
22 changes: 9 additions & 13 deletions dom/locks/LockManagerParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "LockManagerParent.h"
#include "LockRequestParent.h"

#include "mozilla/ContentPrincipalInfoHashKey.h"
#include "mozilla/PrincipalHashKey.h"
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
Expand All @@ -18,27 +17,24 @@

namespace mozilla::dom::locks {

static StaticAutoPtr<
nsTHashMap<ContentPrincipalInfoHashKey, WeakPtr<ManagedLocks>>>
static StaticAutoPtr<nsTHashMap<PrincipalHashKey, WeakPtr<ManagedLocks>>>
sManagedLocksMap;

using IPCResult = mozilla::ipc::IPCResult;

LockManagerParent::LockManagerParent(
const mozilla::ipc::ContentPrincipalInfo& aPrincipalInfo,
const nsID& aClientId)
: mClientId(NSID_TrimBracketsUTF16(aClientId)),
mPrincipalInfo(aPrincipalInfo) {
LockManagerParent::LockManagerParent(NotNull<nsIPrincipal*> aPrincipal,
const nsID& aClientId)
: mClientId(NSID_TrimBracketsUTF16(aClientId)), mPrincipal(aPrincipal) {
if (!sManagedLocksMap) {
sManagedLocksMap =
new nsTHashMap<ContentPrincipalInfoHashKey, WeakPtr<ManagedLocks>>();
new nsTHashMap<PrincipalHashKey, WeakPtr<ManagedLocks>>();
} else {
mManagedLocks = sManagedLocksMap->Get(aPrincipalInfo);
mManagedLocks = sManagedLocksMap->Get(aPrincipal);
}

if (!mManagedLocks) {
mManagedLocks = new ManagedLocks();
sManagedLocksMap->LookupOrInsert(aPrincipalInfo, mManagedLocks);
sManagedLocksMap->LookupOrInsert(aPrincipal, mManagedLocks);
}
}

Expand Down Expand Up @@ -79,8 +75,8 @@ void LockManagerParent::ActorDestroy(ActorDestroyReason aWhy) {
mManagedLocks = nullptr;
// We just decreased the refcount and potentially deleted it, so check whether
// the weak pointer still points to anything and remove the entry if not.
if (!sManagedLocksMap->Get(mPrincipalInfo)) {
sManagedLocksMap->Remove(mPrincipalInfo);
if (!sManagedLocksMap->Get(mPrincipal)) {
sManagedLocksMap->Remove(mPrincipal);
}
}

Expand Down
5 changes: 2 additions & 3 deletions dom/locks/LockManagerParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class LockManagerParent final : public PLockManagerParent {
public:
NS_INLINE_DECL_REFCOUNTING(LockManagerParent)

LockManagerParent(const mozilla::ipc::ContentPrincipalInfo& aPrincipalInfo,
const nsID& aClientId);
LockManagerParent(NotNull<nsIPrincipal*> aPrincipal, const nsID& aClientId);

void ProcessRequestQueue(nsTArray<RefPtr<LockRequestParent>>& aQueue);
bool IsGrantableRequest(const IPCLockRequest& aRequest);
Expand All @@ -54,7 +53,7 @@ class LockManagerParent final : public PLockManagerParent {

RefPtr<ManagedLocks> mManagedLocks;
nsString mClientId;
mozilla::ipc::ContentPrincipalInfo mPrincipalInfo;
NotNull<nsCOMPtr<nsIPrincipal>> mPrincipal;
};

} // namespace mozilla::dom::locks
Expand Down
6 changes: 3 additions & 3 deletions ipc/glue/BackgroundParentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,9 @@ bool BackgroundParentImpl::DeallocPMediaTransportParent(
}

already_AddRefed<dom::locks::PLockManagerParent>
BackgroundParentImpl::AllocPLockManagerParent(
const ContentPrincipalInfo& aPrincipalInfo, const nsID& aClientId) {
return MakeAndAddRef<mozilla::dom::locks::LockManagerParent>(aPrincipalInfo,
BackgroundParentImpl::AllocPLockManagerParent(NotNull<nsIPrincipal*> aPrincipal,
const nsID& aClientId) {
return MakeAndAddRef<mozilla::dom::locks::LockManagerParent>(aPrincipal,
aClientId);
}

Expand Down
2 changes: 1 addition & 1 deletion ipc/glue/BackgroundParentImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class BackgroundParentImpl : public PBackgroundParent {
PWebSocketConnectionParent* actor, const uint32_t& aListenerId) override;

already_AddRefed<PLockManagerParent> AllocPLockManagerParent(
const ContentPrincipalInfo& aPrincipalInfo, const nsID& aClientId) final;
NotNull<nsIPrincipal*> aPrincipal, const nsID& aClientId) final;

already_AddRefed<PFetchParent> AllocPFetchParent() override;
};
Expand Down
2 changes: 1 addition & 1 deletion ipc/glue/PBackground.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ parent:

async PWebSocketConnection(uint32_t aListenerId);

async PLockManager(ContentPrincipalInfo aPrincipalInfo, nsID aClientId);
async PLockManager(nsIPrincipal aPrincipalInfo, nsID aClientId);

async PIPCClientCerts();

Expand Down

0 comments on commit b46a392

Please sign in to comment.