void DataTransferItemList::ClearDataHelper(DataTransferItem* aItem, uint32_t aIndexHint, uint32_t aMozOffsetHint, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) { MOZ_ASSERT(aItem); if (NS_WARN_IF(mDataTransfer->IsReadOnly())) { return; } if (aItem->Principal() && !aSubjectPrincipal.Subsumes(aItem->Principal())) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return; } // Check if the aIndexHint is actually the index, and then remove the item // from aItems bool found; if (IndexedGetter(aIndexHint, found) == aItem) { mItems.RemoveElementAt(aIndexHint); } else { mItems.RemoveElement(aItem); } // Check if the aMozIndexHint and aMozOffsetHint are actually the index and // offset, and then remove them from mIndexedItems MOZ_ASSERT(aItem->Index() < mIndexedItems.Length()); nsTArray<RefPtr<DataTransferItem>>& items = mIndexedItems[aItem->Index()]; if (aMozOffsetHint < items.Length() && aItem == items[aMozOffsetHint]) { items.RemoveElementAt(aMozOffsetHint); } else { items.RemoveElement(aItem); } mDataTransfer->TypesListMayHaveChanged(); // Check if we should remove the index. We never remove index 0. if (items.Length() == 0 && aItem->Index() != 0) { mIndexedItems.RemoveElementAt(aItem->Index()); // Update the index of every element which has now been shifted for (uint32_t i = aItem->Index(); i < mIndexedItems.Length(); i++) { nsTArray<RefPtr<DataTransferItem>>& items = mIndexedItems[i]; for (uint32_t j = 0; j < items.Length(); j++) { items[j]->SetIndex(i); } } } // Give the removed item the invalid index aItem->SetIndex(-1); if (aItem->Kind() == DataTransferItem::KIND_FILE) { RegenerateFiles(); } }
void StyleSheet::SubjectSubsumesInnerPrincipal(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) { StyleSheetInfo& info = SheetInfo(); if (aSubjectPrincipal.Subsumes(info.mPrincipal)) { return; } // Allow access only if CORS mode is not NONE if (GetCORSMode() == CORS_NONE) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return; } // Now make sure we set the principal of our inner to the subjectPrincipal. // We do this because we're in a situation where the caller would not normally // be able to access the sheet, but the sheet has opted in to being read. // Unfortunately, that means it's also opted in to being _edited_, and if the // caller now makes edits to the sheet we want the resulting resource loads, // if any, to look as if they are coming from the caller's principal, not the // original sheet principal. // // That means we need a unique inner, of course. But we don't want to do that // if we're not complete yet. Luckily, all the callers of this method throw // anyway if not complete, so we can just do that here too. if (!info.mComplete) { aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR); return; } WillDirty(); info.mPrincipal = &aSubjectPrincipal; DidDirty(); }