/** * Sets the transferable object * */ NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable * aTransferable, nsIClipboardOwner * anOwner, PRInt32 aWhichClipboard) { NS_ASSERTION ( aTransferable, "clipboard given a null transferable" ); if (aTransferable == mTransferable && anOwner == mClipboardOwner) return NS_OK; bool selectClipPresent; SupportsSelectionClipboard(&selectClipPresent); if ( !selectClipPresent && aWhichClipboard != kGlobalClipboard ) return NS_ERROR_FAILURE; EmptyClipboard(aWhichClipboard); mClipboardOwner = anOwner; if ( anOwner ) NS_ADDREF(mClipboardOwner); mTransferable = aTransferable; nsresult rv = NS_ERROR_FAILURE; if ( mTransferable ) { NS_ADDREF(mTransferable); if (!mPrivacyHandler) { rv = NS_NewClipboardPrivacyHandler(getter_AddRefs(mPrivacyHandler)); NS_ENSURE_SUCCESS(rv, rv); } rv = mPrivacyHandler->PrepareDataForClipboard(mTransferable); NS_ENSURE_SUCCESS(rv, rv); rv = SetNativeClipboardData(aWhichClipboard); } return rv; }
/** * Sets the transferable object */ NS_IMETHODIMP nsClipboard::SetData(nsITransferable *aTransferable, nsIClipboardOwner *aOwner, PRInt32 aWhichClipboard) { // See if we can short cut if ( (aWhichClipboard == kGlobalClipboard && aTransferable == mGlobalTransferable.get() && aOwner == mGlobalOwner.get() ) || (aWhichClipboard == kSelectionClipboard && aTransferable == mSelectionTransferable.get() && aOwner == mSelectionOwner.get() ) ) { return NS_OK; } nsresult rv; if (!mPrivacyHandler) { rv = NS_NewClipboardPrivacyHandler(getter_AddRefs(mPrivacyHandler)); NS_ENSURE_SUCCESS(rv, rv); } rv = mPrivacyHandler->PrepareDataForClipboard(aTransferable); NS_ENSURE_SUCCESS(rv, rv); EmptyClipboard(aWhichClipboard); QClipboard::Mode mode; if (kGlobalClipboard == aWhichClipboard) { mGlobalOwner = aOwner; mGlobalTransferable = aTransferable; mode = QClipboard::Clipboard; } else { mSelectionOwner = aOwner; mSelectionTransferable = aTransferable; mode = QClipboard::Selection; } return SetNativeClipboardData( aTransferable, mode ); }