Bug 1867636 - Rename nsITransferable::requestingPrincipal; r=nika

Differential Revision: https://phabricator.services.mozilla.com/D207272
This commit is contained in:
Edgar Chen 2024-04-18 10:06:07 +00:00
Родитель d54c4bb1fd
Коммит 77d9d637a6
14 изменённых файлов: 26 добавлений и 29 удалений

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

@ -295,7 +295,7 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable* aTransferable,
bool isPrivate = aTransferable->GetIsPrivateData();
nsCOMPtr<nsIPrincipal> principal = aTransferable->GetRequestingPrincipal();
nsCOMPtr<nsIPrincipal> principal = aTransferable->GetDataPrincipal();
nsContentPolicyType contentPolicyType =
aTransferable->GetContentPolicyType();
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =

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

@ -8228,7 +8228,7 @@ nsresult nsContentUtils::IPCTransferableToTransferable(
aTransferable->SetCookieJarSettings(cookieJarSettings);
}
aTransferable->SetReferrerInfo(aIPCTransferable.referrerInfo());
aTransferable->SetRequestingPrincipal(aIPCTransferable.requestingPrincipal());
aTransferable->SetDataPrincipal(aIPCTransferable.dataPrincipal());
aTransferable->SetContentPolicyType(aIPCTransferable.contentPolicyType());
return NS_OK;
@ -8586,8 +8586,7 @@ void nsContentUtils::TransferableToIPCTransferable(
aIPCTransferable->data() = std::move(ipcTransferableData);
aIPCTransferable->isPrivateData() = aTransferable->GetIsPrivateData();
aIPCTransferable->requestingPrincipal() =
aTransferable->GetRequestingPrincipal();
aIPCTransferable->dataPrincipal() = aTransferable->GetDataPrincipal();
aIPCTransferable->cookieJarSettings() = std::move(cookieJarSettingsArgs);
aIPCTransferable->contentPolicyType() = aTransferable->GetContentPolicyType();
aIPCTransferable->referrerInfo() = aTransferable->GetReferrerInfo();

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

@ -245,7 +245,7 @@ static nsresult CreateTransferable(
NS_ENSURE_TRUE(aTransferable, NS_ERROR_NULL_POINTER);
aTransferable->Init(aDocument.GetLoadContext());
aTransferable->SetRequestingPrincipal(aDocument.NodePrincipal());
aTransferable->SetDataPrincipal(aDocument.NodePrincipal());
if (aEncodedDocumentWithContext.mUnicodeEncodingIsTextHTML) {
// Set up a format converter so that clipboard flavor queries work.
// This converter isn't really used for conversions.
@ -468,7 +468,7 @@ nsresult nsCopySupport::ImageCopy(
nsCOMPtr<nsITransferable> trans(do_CreateInstance(kCTransferableCID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
trans->Init(aLoadContext);
trans->SetRequestingPrincipal(imageNode->NodePrincipal());
trans->SetDataPrincipal(imageNode->NodePrincipal());
if (aCopyFlags & nsIDocumentViewerEdit::COPY_IMAGE_TEXT) {
// get the location from the element

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

@ -909,7 +909,7 @@ already_AddRefed<nsITransferable> DataTransfer::GetTransferable(
// from another origin or from the OS.
if (mMode == Mode::ReadWrite) {
if (nsCOMPtr<nsIGlobalObject> global = GetGlobal()) {
transferable->SetRequestingPrincipal(global->PrincipalOrNull());
transferable->SetDataPrincipal(global->PrincipalOrNull());
}
}

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

@ -3413,12 +3413,12 @@ mozilla::ipc::IPCResult ContentParent::RecvSetClipboard(
const MaybeDiscarded<WindowContext>& aRequestingWindowContext) {
// aRequestingPrincipal is allowed to be nullptr here.
if (!ValidatePrincipal(aTransferable.requestingPrincipal(),
if (!ValidatePrincipal(aTransferable.dataPrincipal(),
{ValidatePrincipalOptions::AllowNullPtr,
ValidatePrincipalOptions::AllowExpanded,
ValidatePrincipalOptions::AllowSystem})) {
LogAndAssertFailedPrincipalValidationInfo(
aTransferable.requestingPrincipal(), __func__);
LogAndAssertFailedPrincipalValidationInfo(aTransferable.dataPrincipal(),
__func__);
}
nsresult rv;

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

@ -83,7 +83,7 @@ struct IPCTransferable
{
IPCTransferableData data;
bool isPrivateData;
nullable nsIPrincipal requestingPrincipal;
nullable nsIPrincipal dataPrincipal;
CookieJarSettingsArgs? cookieJarSettings;
nsContentPolicyType contentPolicyType;
nullable nsIReferrerInfo referrerInfo;

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

@ -60,12 +60,12 @@ NS_IMETHODIMP ClipboardWriteRequestParent::OnComplete(nsresult aResult) {
IPCResult ClipboardWriteRequestParent::RecvSetData(
const IPCTransferable& aTransferable) {
if (!mManager->ValidatePrincipal(
aTransferable.requestingPrincipal(),
aTransferable.dataPrincipal(),
{ContentParent::ValidatePrincipalOptions::AllowNullPtr,
ContentParent::ValidatePrincipalOptions::AllowExpanded,
ContentParent::ValidatePrincipalOptions::AllowSystem})) {
ContentParent::LogAndAssertFailedPrincipalValidationInfo(
aTransferable.requestingPrincipal(), __func__);
aTransferable.dataPrincipal(), __func__);
}
if (!mAsyncSetClipboardData) {

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

@ -1758,7 +1758,7 @@ nsresult nsDragService::CreateTempFile(nsITransferable* aItem,
}
// create and open channel for source uri
nsCOMPtr<nsIPrincipal> principal = aItem->GetRequestingPrincipal();
nsCOMPtr<nsIPrincipal> principal = aItem->GetDataPrincipal();
nsContentPolicyType contentPolicyType = aItem->GetContentPolicyType();
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
aItem->GetCookieJarSettings();

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

@ -769,7 +769,7 @@ NS_IMETHODIMP nsBaseClipboard::AsyncGetData(
nsCOMPtr<nsITransferable> trans = clipboardCache->GetTransferable();
MOZ_ASSERT(trans);
if (nsCOMPtr<nsIPrincipal> principal = trans->GetRequestingPrincipal()) {
if (nsCOMPtr<nsIPrincipal> principal = trans->GetDataPrincipal()) {
if (aRequestingPrincipal->Subsumes(principal)) {
MOZ_CLIPBOARD_LOG("%s: native clipboard data is from same-origin page.",
__FUNCTION__);

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

@ -368,7 +368,7 @@ nsBaseDragService::InvokeDragSession(
nsCOMPtr<nsITransferable> trans =
do_CreateInstance("@mozilla.org/widget/transferable;1");
trans->Init(nullptr);
trans->SetRequestingPrincipal(mSourceNode->NodePrincipal());
trans->SetDataPrincipal(mSourceNode->NodePrincipal());
trans->SetContentPolicyType(mContentPolicyType);
trans->SetCookieJarSettings(aCookieJarSettings);
mutableArray->AppendElement(trans);
@ -378,8 +378,8 @@ nsBaseDragService::InvokeDragSession(
nsCOMPtr<nsITransferable> trans =
do_QueryElementAt(aTransferableArray, i);
if (trans) {
// Set the requestingPrincipal on the transferable.
trans->SetRequestingPrincipal(mSourceNode->NodePrincipal());
// Set the dataPrincipal on the transferable.
trans->SetDataPrincipal(mSourceNode->NodePrincipal());
trans->SetContentPolicyType(mContentPolicyType);
trans->SetCookieJarSettings(aCookieJarSettings);
}

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

@ -203,9 +203,8 @@ interface nsITransferable : nsISupports
* node principal of the source DOM node from which this transferable was
* created, or the principal of the global from which this transferable was
* created.
* XXXedgar: Rename it to something more generic, bug 1867636.
*/
[notxpcom, nostdcall] attribute nsIPrincipal requestingPrincipal;
[notxpcom, nostdcall] attribute nsIPrincipal dataPrincipal;
/**
* the contentPolicyType for this transferable.

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

@ -511,17 +511,16 @@ void nsTransferable::SetIsPrivateData(bool aIsPrivateData) {
mPrivateData = aIsPrivateData;
}
nsIPrincipal* nsTransferable::GetRequestingPrincipal() {
nsIPrincipal* nsTransferable::GetDataPrincipal() {
MOZ_ASSERT(mInitialized);
return mRequestingPrincipal;
return mDataPrincipal;
}
void nsTransferable::SetRequestingPrincipal(
nsIPrincipal* aRequestingPrincipal) {
void nsTransferable::SetDataPrincipal(nsIPrincipal* aDataPrincipal) {
MOZ_ASSERT(mInitialized);
mRequestingPrincipal = aRequestingPrincipal;
mDataPrincipal = aDataPrincipal;
}
nsContentPolicyType nsTransferable::GetContentPolicyType() {

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

@ -80,7 +80,7 @@ class nsTransferable : public nsITransferable {
nsTArray<DataStruct> mDataArray;
nsCOMPtr<nsIFormatConverter> mFormatConv;
bool mPrivateData;
nsCOMPtr<nsIPrincipal> mRequestingPrincipal;
nsCOMPtr<nsIPrincipal> mDataPrincipal;
nsContentPolicyType mContentPolicyType;
nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;

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

@ -346,10 +346,10 @@ HRESULT nsDataObj::CreateStream(IStream** outStream) {
pStream->AddRef();
// query the requestingPrincipal from the transferable and add it to the new
// channel
// query the dataPrincipal from the transferable and add it to the new
// channel.
nsCOMPtr<nsIPrincipal> requestingPrincipal =
mTransferable->GetRequestingPrincipal();
mTransferable->GetDataPrincipal();
MOZ_ASSERT(requestingPrincipal, "can not create channel without a principal");
// Note that the cookieJarSettings could be null if the data object is for the