/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Get a list of flavors this transferable can import
nsTArray<nsCString> flavors;
nsresult rv = aTransferable->FlavorsTransferableCanImport(flavors); if (NS_FAILED(rv)) { return rv;
}
MOZ_ASSERT(mActor); // If the requested flavor is not in the list, throw an error. for (constauto& flavor : flavors) { if (!mActor->FlavorList().Contains(flavor)) { return NS_ERROR_FAILURE;
}
}
if (!mActor->CanSend()) { return aCallback->OnComplete(NS_ERROR_NOT_AVAILABLE);
}
// Get a list of flavors this transferable can import
nsTArray<nsCString> flavors;
nsresult rv = aTransferable->FlavorsTransferableCanImport(flavors); if (NS_FAILED(rv)) { return rv;
}
MOZ_ASSERT(mActor); // If the requested flavor is not in the list, throw an error. for (constauto& flavor : flavors) { if (!mActor->FlavorList().Contains(flavor)) { return NS_ERROR_FAILURE;
}
}
if (!mActor->CanSend()) { return NS_ERROR_NOT_AVAILABLE;
}
if (!nsIClipboard::IsClipboardTypeSupported(aWhichClipboard)) {
MOZ_CLIPBOARD_LOG("%s: clipboard %d is not supported.", __FUNCTION__,
aWhichClipboard); return NS_ERROR_FAILURE;
}
ContentChild::GetSingleton()
->SendGetClipboardDataSnapshot(aFlavorList, aWhichClipboard,
aRequestingWindowContext,
WrapNotNull(aRequestingPrincipal))
->Then(
GetMainThreadSerialEventTarget(), __func__, /* resolve */
[callback = nsCOMPtr{aCallback}](
ClipboardReadRequestOrError&& aClipboardReadRequestOrError) { auto result = CreateClipboardDataSnapshotProxy(
std::move(aClipboardReadRequestOrError)); if (result.isErr()) {
callback->OnError(result.unwrapErr()); return;
}
if (aFlavorList.IsEmpty()) { return NS_ERROR_INVALID_ARG;
}
if (!nsIClipboard::IsClipboardTypeSupported(aWhichClipboard)) {
MOZ_CLIPBOARD_LOG("%s: clipboard %d is not supported.", __FUNCTION__,
aWhichClipboard); return NS_ERROR_FAILURE;
} if (MOZ_UNLIKELY(nsIContentAnalysis::MightBeActive())) { // If Content Analysis is active we want to fetch all the clipboard data // up front since we need to analyze it anyway.
RefPtr<ClipboardContentAnalysisChild> contentAnalysis =
ClipboardContentAnalysisChild::GetOrCreate();
IPCTransferableDataOrError ipcTransferableDataOrError; bool result = contentAnalysis->SendGetAllClipboardDataSync(
aFlavorList, aWhichClipboard, aRequestingWindowContext->InnerWindowId(),
&ipcTransferableDataOrError); if (!result) { return NS_ERROR_FAILURE;
} if (ipcTransferableDataOrError.type() ==
IPCTransferableDataOrError::Tnsresult) { return ipcTransferableDataOrError.get_nsresult();
}
nsresult rv;
nsCOMPtr<nsITransferable> trans =
do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
trans->Init(nullptr);
rv = nsContentUtils::IPCTransferableDataToTransferable(
ipcTransferableDataOrError.get_IPCTransferableData(), true/* aAddDataFlavor */, trans, false /* aFilterUnknownFlavors */);
NS_ENSURE_SUCCESS(rv, rv); auto snapshot =
mozilla::MakeRefPtr<nsBaseClipboard::ClipboardPopulatedDataSnapshot>(
trans);
snapshot.forget(_retval); return NS_OK;
}
ClipboardReadRequestOrError requestOrError;
ContentChild* contentChild = ContentChild::GetSingleton();
contentChild->SendGetClipboardDataSnapshotSync(
aFlavorList, aWhichClipboard, aRequestingWindowContext, &requestOrError); auto result = CreateClipboardDataSnapshotProxy(std::move(requestOrError)); if (result.isErr()) { return result.unwrapErr();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.