void DataTransfer::ClearData(const Optional<nsAString>& aFormat, ErrorResult& aRv) { if (mReadOnly) { aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return; } if (mItems.Length() == 0) { return; } if (aFormat.WasPassed()) { MozClearDataAtHelper(aFormat.Value(), 0, aRv); } else { MozClearDataAtHelper(EmptyString(), 0, aRv); } }
void DataTransfer::ClearData(const Optional<nsAString>& aFormat, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) { if (IsReadOnly()) { aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return; } if (MozItemCount() == 0) { return; } if (aFormat.WasPassed()) { MozClearDataAtHelper(aFormat.Value(), 0, aSubjectPrincipal, aRv); } else { MozClearDataAtHelper(EmptyString(), 0, aSubjectPrincipal, aRv); } }
void DataTransfer::MozClearDataAt(const nsAString& aFormat, uint32_t aIndex, const Maybe<nsIPrincipal*>& aSubjectPrincipal, ErrorResult& aRv) { MOZ_ASSERT(aSubjectPrincipal.isSome()); if (mReadOnly) { aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return; } if (aIndex >= MozItemCount()) { aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return; } // Only the first item is valid for clipboard events if (aIndex > 0 && (mEventMessage == eCut || mEventMessage == eCopy || mEventMessage == ePaste)) { aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return; } MozClearDataAtHelper(aFormat, aIndex, aSubjectPrincipal, aRv); // If we just cleared the 0-th index, and there are still more than 1 indexes // remaining, MozClearDataAt should cause the 1st index to become the 0th // index. This should _only_ happen when the MozClearDataAt function is // explicitly called by script, as this behavior is inconsistent with spec. // (however, so is the MozClearDataAt API) if (aIndex == 0 && mItems->MozItemCount() > 1 && mItems->MozItemsAt(0)->Length() == 0) { mItems->PopIndexZero(); } }
void DataTransfer::MozClearDataAt(const nsAString& aFormat, uint32_t aIndex, ErrorResult& aRv) { if (mReadOnly) { aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return; } if (aIndex >= mItems.Length()) { aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return; } // Only the first item is valid for clipboard events if (aIndex > 0 && (mEventType == NS_CUT || mEventType == NS_COPY || mEventType == NS_PASTE)) { aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return; } MozClearDataAtHelper(aFormat, aIndex, aRv); }