Skip to content

Commit

Permalink
Bug 1783844 - Remove IPC::Principal type remains from codebase. r=nika
Browse files Browse the repository at this point in the history
  • Loading branch information
choller committed Aug 10, 2022
1 parent 11081ee commit f2f142f
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 98 deletions.
4 changes: 1 addition & 3 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17338,9 +17338,7 @@ Document::AutomaticStorageAccessPermissionCanBeGranted(bool hasUserActivation) {
ContentChild* cc = ContentChild::GetSingleton();
MOZ_ASSERT(cc);

return cc
->SendAutomaticStorageAccessPermissionCanBeGranted(
IPC::Principal(NodePrincipal()))
return cc->SendAutomaticStorageAccessPermissionCanBeGranted(NodePrincipal())
->Then(GetCurrentSerialEventTarget(), __func__,
[](const ContentChild::
AutomaticStorageAccessPermissionCanBeGrantedPromise::
Expand Down
3 changes: 1 addition & 2 deletions dom/base/nsContentPermissionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ nsresult nsContentPermissionUtils::AskPermission(

req->IPDLAddRef();
ContentChild::GetSingleton()->SendPContentPermissionRequestConstructor(
req, permArray, IPC::Principal(principal),
IPC::Principal(topLevelPrincipal),
req, permArray, principal, topLevelPrincipal,
hasValidTransientUserGestureActivation,
isRequestDelegatedToUnsafeThirdParty, child->GetTabId());
ContentPermissionRequestChildMap()[req.get()] = child->GetTabId();
Expand Down
10 changes: 0 additions & 10 deletions dom/base/nsContentPermissionHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@
class nsPIDOMWindowInner;
class nsContentPermissionRequestProxy;

// Forward declare IPC::Principal here which is defined in
// PermissionMessageUtils.h. Include this file will transitively includes
// "windows.h" and it defines
// #define CreateEvent CreateEventW
// #define LoadImage LoadImageW
// That will mess up windows build.
namespace IPC {
class Principal;
} // namespace IPC

namespace mozilla::dom {

class Element;
Expand Down
6 changes: 3 additions & 3 deletions dom/file/uri/BlobURLProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void BroadcastBlobURLRegistration(const nsACString& aURI,

dom::ContentChild* cc = dom::ContentChild::GetSingleton();
Unused << NS_WARN_IF(!cc->SendStoreAndBroadcastBlobURLRegistration(
nsCString(aURI), ipcBlob, IPC::Principal(aPrincipal), aAgentClusterId));
nsCString(aURI), ipcBlob, aPrincipal, aAgentClusterId));
}

void BroadcastBlobURLUnregistration(const nsCString& aURI,
Expand All @@ -170,8 +170,8 @@ void BroadcastBlobURLUnregistration(const nsCString& aURI,

dom::ContentChild* cc = dom::ContentChild::GetSingleton();
if (cc) {
Unused << NS_WARN_IF(!cc->SendUnstoreAndBroadcastBlobURLUnregistration(
aURI, IPC::Principal(aPrincipal)));
Unused << NS_WARN_IF(
!cc->SendUnstoreAndBroadcastBlobURLUnregistration(aURI, aPrincipal));
}
}

Expand Down
5 changes: 2 additions & 3 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5930,15 +5930,14 @@ void ContentParent::BroadcastBlobURLRegistration(
BlobURLProtocolHandler::IsBlobURLBroadcastPrincipal(aPrincipal);

nsCString uri(aURI);
IPC::Principal principal(aPrincipal);

for (auto* cp : AllProcesses(eLive)) {
if (cp != aIgnoreThisCP) {
if (!toBeSent && !cp->mLoadedOriginHashes.Contains(originHash)) {
continue;
}

nsresult rv = cp->TransmitPermissionsForPrincipal(principal);
nsresult rv = cp->TransmitPermissionsForPrincipal(aPrincipal);
if (NS_WARN_IF(NS_FAILED(rv))) {
break;
}
Expand All @@ -5949,7 +5948,7 @@ void ContentParent::BroadcastBlobURLRegistration(
break;
}

Unused << cp->SendBlobURLRegistration(uri, ipcBlob, principal,
Unused << cp->SendBlobURLRegistration(uri, ipcBlob, aPrincipal,
aAgentClusterId);
}
}
Expand Down
38 changes: 0 additions & 38 deletions dom/ipc/PermissionMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@
#include "nsCOMPtr.h"
#include "nsIPrincipal.h"

namespace IPC {

/**
* Legacy IPC::Principal type. Use nsIPrincipal directly in new IPDL code.
*/
class Principal {
friend struct mozilla::ipc::IPDLParamTraits<Principal>;

public:
Principal() = default;

explicit Principal(nsIPrincipal* aPrincipal) : mPrincipal(aPrincipal) {}
Principal(Principal&&) = default;

Principal& operator=(Principal&& aOther) = default;
Principal& operator=(const Principal& aOther) = delete;

operator nsIPrincipal*() const { return mPrincipal.get(); }

private:
RefPtr<nsIPrincipal> mPrincipal;
};

} // namespace IPC

namespace mozilla::ipc {

template <>
Expand All @@ -58,19 +33,6 @@ struct IPDLParamTraits<nsIPrincipal*> {
}
};

template <>
struct IPDLParamTraits<IPC::Principal> {
typedef IPC::Principal paramType;
static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
const paramType& aParam) {
WriteIPDLParam(aWriter, aActor, aParam.mPrincipal);
}
static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
paramType* aResult) {
return ReadIPDLParam(aReader, aActor, &aResult->mPrincipal);
}
};

} // namespace mozilla::ipc

#endif // mozilla_dom_permission_message_utils_h__
6 changes: 2 additions & 4 deletions dom/notification/Notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,17 +1091,15 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
// Permissions can't be removed from the content process. Send a message
// to the parent; `ContentParent::RecvDisableNotifications` will call
// `RemovePermission`.
ContentChild::GetSingleton()->SendDisableNotifications(
IPC::Principal(mPrincipal));
ContentChild::GetSingleton()->SendDisableNotifications(mPrincipal);
return NS_OK;
} else if (!strcmp("alertsettingscallback", aTopic)) {
if (XRE_IsParentProcess()) {
return Notification::OpenSettings(mPrincipal);
}
// `ContentParent::RecvOpenNotificationSettings` notifies observers in the
// parent process.
ContentChild::GetSingleton()->SendOpenNotificationSettings(
IPC::Principal(mPrincipal));
ContentChild::GetSingleton()->SendOpenNotificationSettings(mPrincipal);
return NS_OK;
} else if (!strcmp("alertshow", aTopic) || !strcmp("alertfinished", aTopic)) {
Unused << NS_WARN_IF(NS_FAILED(AdjustPushQuota(aTopic)));
Expand Down
2 changes: 1 addition & 1 deletion dom/permission/Permissions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ already_AddRefed<Promise> Permissions::Revoke(JSContext* aCx,
// to the parent; `ContentParent::RecvRemovePermission` will call
// `RemovePermission`.
ContentChild::GetSingleton()->SendRemovePermission(
IPC::Principal(document->NodePrincipal()), permissionType, &rv);
document->NodePrincipal(), permissionType, &rv);
}

if (NS_WARN_IF(NS_FAILED(rv))) {
Expand Down
33 changes: 14 additions & 19 deletions dom/push/PushNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,17 @@ nsresult PushMessageDispatcher::NotifyWorkers() {
bool PushMessageDispatcher::SendToParent(ContentChild* aParentActor) {
if (mData) {
return aParentActor->SendNotifyPushObserversWithData(
mScope, IPC::Principal(mPrincipal), mMessageId, mData.ref());
mScope, mPrincipal, mMessageId, mData.ref());
}
return aParentActor->SendNotifyPushObservers(
mScope, IPC::Principal(mPrincipal), mMessageId);
return aParentActor->SendNotifyPushObservers(mScope, mPrincipal, mMessageId);
}

bool PushMessageDispatcher::SendToChild(ContentParent* aContentActor) {
if (mData) {
return aContentActor->SendPushWithData(mScope, IPC::Principal(mPrincipal),
mMessageId, mData.ref());
return aContentActor->SendPushWithData(mScope, mPrincipal, mMessageId,
mData.ref());
}
return aContentActor->SendPush(mScope, IPC::Principal(mPrincipal),
mMessageId);
return aContentActor->SendPush(mScope, mPrincipal, mMessageId);
}

PushSubscriptionChangeDispatcher::PushSubscriptionChangeDispatcher(
Expand Down Expand Up @@ -341,14 +339,13 @@ nsresult PushSubscriptionChangeDispatcher::NotifyWorkers() {

bool PushSubscriptionChangeDispatcher::SendToParent(
ContentChild* aParentActor) {
return aParentActor->SendNotifyPushSubscriptionChangeObservers(
mScope, IPC::Principal(mPrincipal));
return aParentActor->SendNotifyPushSubscriptionChangeObservers(mScope,
mPrincipal);
}

bool PushSubscriptionChangeDispatcher::SendToChild(
ContentParent* aContentActor) {
return aContentActor->SendPushSubscriptionChange(mScope,
IPC::Principal(mPrincipal));
return aContentActor->SendPushSubscriptionChange(mScope, mPrincipal);
}

PushSubscriptionModifiedDispatcher::PushSubscriptionModifiedDispatcher(
Expand All @@ -367,14 +364,14 @@ nsresult PushSubscriptionModifiedDispatcher::NotifyWorkers() { return NS_OK; }

bool PushSubscriptionModifiedDispatcher::SendToParent(
ContentChild* aParentActor) {
return aParentActor->SendNotifyPushSubscriptionModifiedObservers(
mScope, IPC::Principal(mPrincipal));
return aParentActor->SendNotifyPushSubscriptionModifiedObservers(mScope,
mPrincipal);
}

bool PushSubscriptionModifiedDispatcher::SendToChild(
ContentParent* aContentActor) {
return aContentActor->SendNotifyPushSubscriptionModifiedObservers(
mScope, IPC::Principal(mPrincipal));
return aContentActor->SendNotifyPushSubscriptionModifiedObservers(mScope,
mPrincipal);
}

PushErrorDispatcher::PushErrorDispatcher(const nsACString& aScope,
Expand Down Expand Up @@ -414,13 +411,11 @@ nsresult PushErrorDispatcher::NotifyWorkers() {
}

bool PushErrorDispatcher::SendToParent(ContentChild* aContentActor) {
return aContentActor->SendPushError(mScope, IPC::Principal(mPrincipal),
mMessage, mFlags);
return aContentActor->SendPushError(mScope, mPrincipal, mMessage, mFlags);
}

bool PushErrorDispatcher::SendToChild(ContentParent* aContentActor) {
return aContentActor->SendPushError(mScope, IPC::Principal(mPrincipal),
mMessage, mFlags);
return aContentActor->SendPushError(mScope, mPrincipal, mMessage, mFlags);
}

nsresult PushErrorDispatcher::HandleNoChildProcesses() {
Expand Down
4 changes: 2 additions & 2 deletions toolkit/components/alerts/AlertNotificationIPCSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct IPDLParamTraits<nsIAlertNotification*> {
WriteIPDLParam(aWriter, aActor, dir);
WriteIPDLParam(aWriter, aActor, lang);
WriteIPDLParam(aWriter, aActor, data);
WriteIPDLParam(aWriter, aActor, IPC::Principal(principal));
WriteIPDLParam(aWriter, aActor, principal);
WriteIPDLParam(aWriter, aActor, inPrivateBrowsing);
WriteIPDLParam(aWriter, aActor, requireInteraction);
WriteIPDLParam(aWriter, aActor, silent);
Expand All @@ -84,7 +84,7 @@ struct IPDLParamTraits<nsIAlertNotification*> {

nsString name, imageURL, title, text, cookie, dir, lang, data;
bool textClickable, inPrivateBrowsing, requireInteraction, silent;
IPC::Principal principal;
nsCOMPtr<nsIPrincipal> principal;
nsTArray<uint32_t> vibrate;

if (!ReadIPDLParam(aReader, aActor, &name) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ContentBlockingUserInteraction::Observe(nsIPrincipal* aPrincipal) {
LOG_PRIN(("Asking the parent process to save the user-interaction for us: %s",
_spec),
aPrincipal);
cc->SendStoreUserInteractionAsPermission(IPC::Principal(aPrincipal));
cc->SendStoreUserInteractionAsPermission(aPrincipal);
}

/* static */
Expand Down
12 changes: 5 additions & 7 deletions toolkit/components/antitracking/StorageAccessAPIHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ StorageAccessAPIHelper::AllowAccessFor(
RefPtr<BrowsingContext> bc = aParentContext;
return cc
->SendCompleteAllowAccessFor(aParentContext, topLevelWindowId,
IPC::Principal(trackingPrincipal),
trackingOrigin, behavior, aReason)
trackingPrincipal, trackingOrigin, behavior,
aReason)
->Then(GetCurrentSerialEventTarget(), __func__,
[bc, trackingOrigin, behavior,
aReason](const ContentChild::CompleteAllowAccessForPromise::
Expand Down Expand Up @@ -509,9 +509,8 @@ StorageAccessAPIHelper::CompleteAllowAccessFor(
// sending the request of storing a permission.
return cc
->SendStorageAccessPermissionGrantedForOrigin(
aTopLevelWindowId, aParentContext,
IPC::Principal(trackingPrincipal), trackingOrigin, aAllowMode,
reportReason)
aTopLevelWindowId, aParentContext, trackingPrincipal,
trackingOrigin, aAllowMode, reportReason)
->Then(
GetCurrentSerialEventTarget(), __func__,
[aReason, trackingPrincipal](
Expand Down Expand Up @@ -768,8 +767,7 @@ StorageAccessAPIHelper::AsyncCheckCookiesPermittedDecidesStorageAccessAPI(
MOZ_ASSERT(cc);

return cc
->SendTestCookiePermissionDecided(aBrowsingContext,
IPC::Principal(aRequestingPrincipal))
->SendTestCookiePermissionDecided(aBrowsingContext, aRequestingPrincipal)
->Then(
GetCurrentSerialEventTarget(), __func__,
[](const ContentChild::TestCookiePermissionDecidedPromise::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1707,11 +1707,10 @@ nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
MOZ_ASSERT(content);

auto actor = static_cast<URLClassifierChild*>(
content->AllocPURLClassifierChild(IPC::Principal(aPrincipal), aResult));
content->AllocPURLClassifierChild(aPrincipal, aResult));
MOZ_ASSERT(actor);

if (!content->SendPURLClassifierConstructor(
actor, IPC::Principal(aPrincipal), aResult)) {
if (!content->SendPURLClassifierConstructor(actor, aPrincipal, aResult)) {
*aResult = false;
return NS_ERROR_FAILURE;
}
Expand Down
3 changes: 1 addition & 2 deletions widget/nsClipboardProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ nsClipboardProxy::SetData(nsITransferable* aTransferable,
nsCOMPtr<nsIPrincipal> requestingPrincipal =
aTransferable->GetRequestingPrincipal();
nsContentPolicyType contentPolicyType = aTransferable->GetContentPolicyType();
child->SendSetClipboard(ipcDataTransfer, isPrivateData,
IPC::Principal(requestingPrincipal),
child->SendSetClipboard(ipcDataTransfer, isPrivateData, requestingPrincipal,
contentPolicyType, aWhichClipboard);

return NS_OK;
Expand Down

0 comments on commit f2f142f

Please sign in to comment.