|
|
|
@ -88,7 +88,8 @@ static void SetTransferableData(nsITransferable* aTransferable,
|
|
|
|
|
const nsACString& aFlavor,
|
|
|
|
|
const char* aClipboardData,
|
|
|
|
|
uint32_t aClipboardDataLength) {
|
|
|
|
|
LOGCLIP("SetTransferableData MIME %s\n", PromiseFlatCString(aFlavor).get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG("SetTransferableData MIME %s\n",
|
|
|
|
|
PromiseFlatCString(aFlavor).get());
|
|
|
|
|
nsCOMPtr<nsISupports> wrapper;
|
|
|
|
|
nsPrimitiveHelpers::CreatePrimitiveForData(
|
|
|
|
|
aFlavor, aClipboardData, aClipboardDataLength, getter_AddRefs(wrapper));
|
|
|
|
@ -161,29 +162,30 @@ int GetGeckoClipboardType(GtkClipboard* aGtkClipboard) {
|
|
|
|
|
void nsRetrievalContext::ClearCachedTargetsClipboard(GtkClipboard* aClipboard,
|
|
|
|
|
GdkEvent* aEvent,
|
|
|
|
|
gpointer data) {
|
|
|
|
|
LOGCLIP("nsRetrievalContext::ClearCachedTargetsClipboard()");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("nsRetrievalContext::ClearCachedTargetsClipboard()");
|
|
|
|
|
sClipboardTargets.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nsRetrievalContext::ClearCachedTargetsPrimary(GtkClipboard* aClipboard,
|
|
|
|
|
GdkEvent* aEvent,
|
|
|
|
|
gpointer data) {
|
|
|
|
|
LOGCLIP("nsRetrievalContext::ClearCachedTargetsPrimary()");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("nsRetrievalContext::ClearCachedTargetsPrimary()");
|
|
|
|
|
sPrimaryTargets.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClipboardTargets nsRetrievalContext::GetTargets(int32_t aWhichClipboard) {
|
|
|
|
|
LOGCLIP("nsRetrievalContext::GetTargets(%s)\n",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("nsRetrievalContext::GetTargets(%s)\n",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard
|
|
|
|
|
? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
ClipboardTargets& storedTargets =
|
|
|
|
|
(aWhichClipboard == nsClipboard::kSelectionClipboard) ? sPrimaryTargets
|
|
|
|
|
: sClipboardTargets;
|
|
|
|
|
if (!storedTargets) {
|
|
|
|
|
LOGCLIP(" getting targets from system");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" getting targets from system");
|
|
|
|
|
storedTargets.Set(GetTargetsImpl(aWhichClipboard));
|
|
|
|
|
} else {
|
|
|
|
|
LOGCLIP(" using cached targets");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" using cached targets");
|
|
|
|
|
}
|
|
|
|
|
return storedTargets.Clone();
|
|
|
|
|
}
|
|
|
|
@ -249,7 +251,7 @@ nsClipboard::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
|
// runnable.
|
|
|
|
|
return SchedulerGroup::Dispatch(
|
|
|
|
|
NS_NewRunnableFunction("gtk_clipboard_store()", []() {
|
|
|
|
|
LOGCLIP("nsClipboard storing clipboard content\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("nsClipboard storing clipboard content\n");
|
|
|
|
|
gtk_clipboard_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
@ -269,8 +271,9 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP("nsClipboard::SetNativeClipboardData (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::SetNativeClipboardData (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
|
|
|
|
|
// List of suported targets
|
|
|
|
|
GtkTargetList* list = gtk_target_list_new(nullptr, 0);
|
|
|
|
@ -279,7 +282,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
|
nsresult rv = aTransferable->FlavorsTransferableCanExport(flavors);
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
|
LOGCLIP(" FlavorsTransferableCanExport failed!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" FlavorsTransferableCanExport failed!\n");
|
|
|
|
|
// Fall through. |gtkTargets| will be null below.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -287,11 +290,11 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
bool imagesAdded = false;
|
|
|
|
|
for (uint32_t i = 0; i < flavors.Length(); i++) {
|
|
|
|
|
nsCString& flavorStr = flavors[i];
|
|
|
|
|
LOGCLIP(" processing target %s\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" processing target %s\n", flavorStr.get());
|
|
|
|
|
|
|
|
|
|
// Special case text/plain since we can handle all of the string types.
|
|
|
|
|
if (flavorStr.EqualsLiteral(kTextMime)) {
|
|
|
|
|
LOGCLIP(" adding TEXT targets\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" adding TEXT targets\n");
|
|
|
|
|
gtk_target_list_add_text_targets(list, 0);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -300,7 +303,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
// Don't bother adding image targets twice
|
|
|
|
|
if (!imagesAdded) {
|
|
|
|
|
// accept any writable image type
|
|
|
|
|
LOGCLIP(" adding IMAGE targets\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" adding IMAGE targets\n");
|
|
|
|
|
gtk_target_list_add_image_targets(list, 0, TRUE);
|
|
|
|
|
imagesAdded = true;
|
|
|
|
|
}
|
|
|
|
@ -308,14 +311,14 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flavorStr.EqualsLiteral(kFileMime)) {
|
|
|
|
|
LOGCLIP(" adding text/uri-list target\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" adding text/uri-list target\n");
|
|
|
|
|
GdkAtom atom = gdk_atom_intern(kURIListMime, FALSE);
|
|
|
|
|
gtk_target_list_add(list, atom, 0, 0);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add this to our list of valid targets
|
|
|
|
|
LOGCLIP(" adding OTHER target %s\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" adding OTHER target %s\n", flavorStr.get());
|
|
|
|
|
GdkAtom atom = gdk_atom_intern(flavorStr.get(), FALSE);
|
|
|
|
|
gtk_target_list_add(list, atom, 0, 0);
|
|
|
|
|
}
|
|
|
|
@ -328,7 +331,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
GtkTargetEntry* gtkTargets =
|
|
|
|
|
gtk_target_table_new_from_list(list, &numTargets);
|
|
|
|
|
if (!gtkTargets || numTargets == 0) {
|
|
|
|
|
LOGCLIP(
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
" gtk_target_table_new_from_list() failed or empty list of "
|
|
|
|
|
"targets!\n");
|
|
|
|
|
// Clear references to the any old data and let GTK know that it is no
|
|
|
|
@ -356,7 +359,7 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
|
} else {
|
|
|
|
|
LOGCLIP(" gtk_clipboard_set_with_data() failed!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" gtk_clipboard_set_with_data() failed!\n");
|
|
|
|
|
EmptyNativeClipboardData(aWhichClipboard);
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
}
|
|
|
|
@ -390,11 +393,11 @@ static bool IsMIMEAtFlavourList(const nsTArray<nsCString>& aFlavourList,
|
|
|
|
|
// So if clipboard contains images only remove text MIME offer.
|
|
|
|
|
bool nsClipboard::FilterImportedFlavors(int32_t aWhichClipboard,
|
|
|
|
|
nsTArray<nsCString>& aFlavors) {
|
|
|
|
|
LOGCLIP("nsClipboard::FilterImportedFlavors");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("nsClipboard::FilterImportedFlavors");
|
|
|
|
|
|
|
|
|
|
auto targets = mContext->GetTargets(aWhichClipboard);
|
|
|
|
|
if (!targets) {
|
|
|
|
|
LOGCLIP(" X11: no targes at clipboard (null), quit.\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" X11: no targes at clipboard (null), quit.\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -419,7 +422,8 @@ bool nsClipboard::FilterImportedFlavors(int32_t aWhichClipboard,
|
|
|
|
|
}
|
|
|
|
|
// We have some other MIME type on clipboard which can be hopefully
|
|
|
|
|
// converted to text without any problem.
|
|
|
|
|
LOGCLIP(" X11: text types in clipboard, no need to filter them.\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
" X11: text types in clipboard, no need to filter them.\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -436,9 +440,9 @@ bool nsClipboard::FilterImportedFlavors(int32_t aWhichClipboard,
|
|
|
|
|
}
|
|
|
|
|
aFlavors.SwapElements(clipboardFlavors);
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
|
LOGCLIP(" X11: Flavors which match clipboard content:\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" X11: Flavors which match clipboard content:\n");
|
|
|
|
|
for (uint32_t i = 0; i < aFlavors.Length(); i++) {
|
|
|
|
|
LOGCLIP(" %s\n", aFlavors[i].get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" %s\n", aFlavors[i].get());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
@ -452,13 +456,13 @@ static nsresult GetTransferableFlavors(nsITransferable* aTransferable,
|
|
|
|
|
// Get a list of flavors this transferable can import
|
|
|
|
|
nsresult rv = aTransferable->FlavorsTransferableCanImport(aFlavors);
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
|
LOGCLIP(" FlavorsTransferableCanImport falied!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" FlavorsTransferableCanImport falied!\n");
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
|
LOGCLIP(" Flavors which can be imported:");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Flavors which can be imported:");
|
|
|
|
|
for (const auto& flavor : aFlavors) {
|
|
|
|
|
LOGCLIP(" %s", flavor.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" %s", flavor.get());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return NS_OK;
|
|
|
|
@ -476,7 +480,7 @@ static bool TransferableSetFile(nsITransferable* aTransferable,
|
|
|
|
|
rv = fileURL->GetFile(getter_AddRefs(file));
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
aTransferable->SetTransferData(kFileMime, file);
|
|
|
|
|
LOGCLIP(" successfully set file to clipboard\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" successfully set file to clipboard\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -492,17 +496,20 @@ static bool TransferableSetHTML(nsITransferable* aTransferable,
|
|
|
|
|
nsAutoCString charset;
|
|
|
|
|
if (!GetHTMLCharset(aData, charset)) {
|
|
|
|
|
// Fall back to utf-8 in case html/data is missing kHTMLMarkupPrefix.
|
|
|
|
|
LOGCLIP("Failed to get html/text encoding, fall back to utf-8.\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"Failed to get html/text encoding, fall back to utf-8.\n");
|
|
|
|
|
charset.AssignLiteral("utf-8");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP("TransferableSetHTML: HTML detected charset %s", charset.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG("TransferableSetHTML: HTML detected charset %s",
|
|
|
|
|
charset.get());
|
|
|
|
|
// app which use "text/html" to copy&paste
|
|
|
|
|
// get the decoder
|
|
|
|
|
auto encoding = Encoding::ForLabelNoReplacement(charset);
|
|
|
|
|
if (!encoding) {
|
|
|
|
|
LOGCLIP("TransferableSetHTML: get unicode decoder error (charset: %s)",
|
|
|
|
|
charset.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"TransferableSetHTML: get unicode decoder error (charset: %s)",
|
|
|
|
|
charset.get());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -523,16 +530,15 @@ static bool TransferableSetHTML(nsITransferable* aTransferable,
|
|
|
|
|
nsAutoString unicodeData;
|
|
|
|
|
auto [rv, enc] = encoding->Decode(AsBytes(aData), unicodeData);
|
|
|
|
|
#if MOZ_LOGGING
|
|
|
|
|
if (enc != UTF_8_ENCODING &&
|
|
|
|
|
MOZ_LOG_TEST(gClipboardLog, mozilla::LogLevel::Debug)) {
|
|
|
|
|
if (enc != UTF_8_ENCODING && MOZ_CLIPBOARD_LOG_ENABLED()) {
|
|
|
|
|
nsCString decoderName;
|
|
|
|
|
enc->Name(decoderName);
|
|
|
|
|
LOGCLIP("TransferableSetHTML: expected UTF-8 decoder but got %s",
|
|
|
|
|
decoderName.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG("TransferableSetHTML: expected UTF-8 decoder but got %s",
|
|
|
|
|
decoderName.get());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
|
LOGCLIP("TransferableSetHTML: failed to decode HTML");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("TransferableSetHTML: failed to decode HTML");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
SetTransferableData(aTransferable, mimeType,
|
|
|
|
@ -548,8 +554,9 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
|
nsIClipboard::IsClipboardTypeSupported(aWhichClipboard));
|
|
|
|
|
|
|
|
|
|
LOGCLIP("nsClipboard::GetNativeClipboardData (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::GetNativeClipboardData (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
|
|
|
|
|
// TODO: Ensure we don't re-enter here.
|
|
|
|
|
if (!mContext) {
|
|
|
|
@ -564,7 +571,7 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
// see Bug 1611407
|
|
|
|
|
if (widget::GdkIsX11Display() &&
|
|
|
|
|
!FilterImportedFlavors(aWhichClipboard, flavors)) {
|
|
|
|
|
LOGCLIP(" Missing suitable clipboard data, quit.");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Missing suitable clipboard data, quit.");
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -580,12 +587,13 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
flavorStr.Assign(kJPEGImageMime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" Getting image %s MIME clipboard data\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting image %s MIME clipboard data\n",
|
|
|
|
|
flavorStr.get());
|
|
|
|
|
|
|
|
|
|
auto clipboardData =
|
|
|
|
|
mContext->GetClipboardData(flavorStr.get(), aWhichClipboard);
|
|
|
|
|
if (!clipboardData) {
|
|
|
|
|
LOGCLIP(" %s type is missing\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" %s type is missing\n", flavorStr.get());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -593,18 +601,19 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
NS_NewByteInputStream(getter_AddRefs(byteStream), clipboardData.AsSpan(),
|
|
|
|
|
NS_ASSIGNMENT_COPY);
|
|
|
|
|
aTransferable->SetTransferData(flavorStr.get(), byteStream);
|
|
|
|
|
LOGCLIP(" got %s MIME data\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" got %s MIME data\n", flavorStr.get());
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special case text/plain since we can convert any
|
|
|
|
|
// string into text/plain
|
|
|
|
|
if (flavorStr.EqualsLiteral(kTextMime)) {
|
|
|
|
|
LOGCLIP(" Getting text %s MIME clipboard data\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting text %s MIME clipboard data\n",
|
|
|
|
|
flavorStr.get());
|
|
|
|
|
|
|
|
|
|
auto clipboardData = mContext->GetClipboardText(aWhichClipboard);
|
|
|
|
|
if (!clipboardData) {
|
|
|
|
|
LOGCLIP(" failed to get text data\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get text data\n");
|
|
|
|
|
// If the type was text/plain and we couldn't get
|
|
|
|
|
// text off the clipboard, run the next loop
|
|
|
|
|
// iteration.
|
|
|
|
@ -617,17 +626,18 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
(const char*)ucs2string.BeginReading(),
|
|
|
|
|
ucs2string.Length() * 2);
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" got text data, length %zd\n", ucs2string.Length());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" got text data, length %zd\n", ucs2string.Length());
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flavorStr.EqualsLiteral(kFileMime)) {
|
|
|
|
|
LOGCLIP(" Getting %s file clipboard data\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting %s file clipboard data\n",
|
|
|
|
|
flavorStr.get());
|
|
|
|
|
|
|
|
|
|
auto clipboardData =
|
|
|
|
|
mContext->GetClipboardData(kURIListMime, aWhichClipboard);
|
|
|
|
|
if (!clipboardData) {
|
|
|
|
|
LOGCLIP(" text/uri-list type is missing\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" text/uri-list type is missing\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -638,19 +648,19 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" Getting %s MIME clipboard data\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting %s MIME clipboard data\n", flavorStr.get());
|
|
|
|
|
|
|
|
|
|
auto clipboardData =
|
|
|
|
|
mContext->GetClipboardData(flavorStr.get(), aWhichClipboard);
|
|
|
|
|
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
|
if (!clipboardData) {
|
|
|
|
|
LOGCLIP(" %s type is missing\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" %s type is missing\n", flavorStr.get());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (clipboardData) {
|
|
|
|
|
LOGCLIP(" got %s mime type data.\n", flavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" got %s mime type data.\n", flavorStr.get());
|
|
|
|
|
|
|
|
|
|
// Special case text/html since we can convert into UCS2
|
|
|
|
|
if (flavorStr.EqualsLiteral(kHTMLMime)) {
|
|
|
|
@ -666,7 +676,7 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" failed to get clipboard content.\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get clipboard content.\n");
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -692,11 +702,11 @@ struct DataCallbackHandler {
|
|
|
|
|
mMimeType(aMimeType),
|
|
|
|
|
mDataType(aDataType) {
|
|
|
|
|
MOZ_COUNT_CTOR(DataCallbackHandler);
|
|
|
|
|
LOGCLIP("DataCallbackHandler created [%p] MIME %s type %d", this,
|
|
|
|
|
mMimeType.get(), mDataType);
|
|
|
|
|
MOZ_CLIPBOARD_LOG("DataCallbackHandler created [%p] MIME %s type %d", this,
|
|
|
|
|
mMimeType.get(), mDataType);
|
|
|
|
|
}
|
|
|
|
|
~DataCallbackHandler() {
|
|
|
|
|
LOGCLIP("DataCallbackHandler deleted [%p]", this);
|
|
|
|
|
MOZ_CLIPBOARD_LOG("DataCallbackHandler deleted [%p]", this);
|
|
|
|
|
MOZ_COUNT_DTOR(DataCallbackHandler);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -704,20 +714,21 @@ struct DataCallbackHandler {
|
|
|
|
|
static void AsyncGetTextImpl(nsITransferable* aTransferable,
|
|
|
|
|
int32_t aWhichClipboard,
|
|
|
|
|
nsBaseClipboard::GetDataCallback&& aCallback) {
|
|
|
|
|
LOGCLIP("AsyncGetText() type '%s'",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("AsyncGetText() type '%s'",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard
|
|
|
|
|
? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
|
|
|
|
|
gtk_clipboard_request_text(
|
|
|
|
|
gtk_clipboard_get(GetSelectionAtom(aWhichClipboard)),
|
|
|
|
|
[](GtkClipboard* aClipboard, const gchar* aText, gpointer aData) -> void {
|
|
|
|
|
UniquePtr<DataCallbackHandler> ref(
|
|
|
|
|
static_cast<DataCallbackHandler*>(aData));
|
|
|
|
|
LOGCLIP("AsyncGetText async handler of [%p]", aData);
|
|
|
|
|
MOZ_CLIPBOARD_LOG("AsyncGetText async handler of [%p]", aData);
|
|
|
|
|
|
|
|
|
|
size_t dataLength = aText ? strlen(aText) : 0;
|
|
|
|
|
if (dataLength <= 0) {
|
|
|
|
|
LOGCLIP(" quit, text is not available");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" quit, text is not available");
|
|
|
|
|
ref->mDataCallback(NS_OK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -728,7 +739,7 @@ static void AsyncGetTextImpl(nsITransferable* aTransferable,
|
|
|
|
|
SetTransferableData(ref->mTransferable, flavor,
|
|
|
|
|
(const char*)utf16string.BeginReading(),
|
|
|
|
|
utf16string.Length() * 2);
|
|
|
|
|
LOGCLIP(" text is set, length = %d", (int)dataLength);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" text is set, length = %d", (int)dataLength);
|
|
|
|
|
ref->mDataCallback(NS_OK);
|
|
|
|
|
},
|
|
|
|
|
new DataCallbackHandler(aTransferable, std::move(aCallback), kTextMime));
|
|
|
|
@ -738,9 +749,10 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable,
|
|
|
|
|
int32_t aWhichClipboard, const char* aMimeType,
|
|
|
|
|
DataType aDataType,
|
|
|
|
|
nsBaseClipboard::GetDataCallback&& aCallback) {
|
|
|
|
|
LOGCLIP("AsyncGetData() type '%s'",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("AsyncGetData() type '%s'",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard
|
|
|
|
|
? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
|
|
|
|
|
const char* gtkMIMEType = nullptr;
|
|
|
|
|
switch (aDataType) {
|
|
|
|
@ -762,8 +774,8 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable,
|
|
|
|
|
gpointer aData) -> void {
|
|
|
|
|
UniquePtr<DataCallbackHandler> ref(
|
|
|
|
|
static_cast<DataCallbackHandler*>(aData));
|
|
|
|
|
LOGCLIP("AsyncGetData async handler [%p] MIME %s type %d", aData,
|
|
|
|
|
ref->mMimeType.get(), ref->mDataType);
|
|
|
|
|
MOZ_CLIPBOARD_LOG("AsyncGetData async handler [%p] MIME %s type %d",
|
|
|
|
|
aData, ref->mMimeType.get(), ref->mDataType);
|
|
|
|
|
|
|
|
|
|
int dataLength = gtk_selection_data_get_length(aSelection);
|
|
|
|
|
if (dataLength <= 0) {
|
|
|
|
@ -777,7 +789,7 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable,
|
|
|
|
|
}
|
|
|
|
|
switch (ref->mDataType) {
|
|
|
|
|
case DATATYPE_IMAGE: {
|
|
|
|
|
LOGCLIP(" set image clipboard data");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" set image clipboard data");
|
|
|
|
|
nsCOMPtr<nsIInputStream> byteStream;
|
|
|
|
|
NS_NewByteInputStream(getter_AddRefs(byteStream),
|
|
|
|
|
Span(data, dataLength), NS_ASSIGNMENT_COPY);
|
|
|
|
@ -786,19 +798,19 @@ static void AsyncGetDataImpl(nsITransferable* aTransferable,
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DATATYPE_FILE: {
|
|
|
|
|
LOGCLIP(" set file clipboard data");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" set file clipboard data");
|
|
|
|
|
nsDependentCSubstring file(data, dataLength);
|
|
|
|
|
TransferableSetFile(ref->mTransferable, file);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DATATYPE_HTML: {
|
|
|
|
|
LOGCLIP(" html clipboard data");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" html clipboard data");
|
|
|
|
|
Span dataSpan(data, dataLength);
|
|
|
|
|
TransferableSetHTML(ref->mTransferable, dataSpan);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DATATYPE_RAW: {
|
|
|
|
|
LOGCLIP(" raw clipboard data %s", ref->mMimeType.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" raw clipboard data %s", ref->mMimeType.get());
|
|
|
|
|
SetTransferableData(ref->mTransferable, ref->mMimeType, data,
|
|
|
|
|
dataLength);
|
|
|
|
|
break;
|
|
|
|
@ -821,7 +833,8 @@ static void AsyncGetDataFlavor(nsITransferable* aTransferable,
|
|
|
|
|
if (aFlavorStr.EqualsLiteral(kJPGImageMime)) {
|
|
|
|
|
aFlavorStr.Assign(kJPEGImageMime);
|
|
|
|
|
}
|
|
|
|
|
LOGCLIP(" Getting image %s MIME clipboard data", aFlavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting image %s MIME clipboard data",
|
|
|
|
|
aFlavorStr.get());
|
|
|
|
|
AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(),
|
|
|
|
|
DATATYPE_IMAGE, std::move(aCallback));
|
|
|
|
|
return;
|
|
|
|
@ -829,23 +842,23 @@ static void AsyncGetDataFlavor(nsITransferable* aTransferable,
|
|
|
|
|
// Special case text/plain since we can convert any
|
|
|
|
|
// string into text/plain
|
|
|
|
|
if (aFlavorStr.EqualsLiteral(kTextMime)) {
|
|
|
|
|
LOGCLIP(" Getting unicode clipboard data");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting unicode clipboard data");
|
|
|
|
|
AsyncGetTextImpl(aTransferable, aWhichClipboard, std::move(aCallback));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (aFlavorStr.EqualsLiteral(kFileMime)) {
|
|
|
|
|
LOGCLIP(" Getting file clipboard data\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting file clipboard data\n");
|
|
|
|
|
AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(),
|
|
|
|
|
DATATYPE_FILE, std::move(aCallback));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (aFlavorStr.EqualsLiteral(kHTMLMime)) {
|
|
|
|
|
LOGCLIP(" Getting HTML clipboard data");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting HTML clipboard data");
|
|
|
|
|
AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(),
|
|
|
|
|
DATATYPE_HTML, std::move(aCallback));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LOGCLIP(" Getting raw %s MIME clipboard data\n", aFlavorStr.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Getting raw %s MIME clipboard data\n", aFlavorStr.get());
|
|
|
|
|
AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(),
|
|
|
|
|
DATATYPE_RAW, std::move(aCallback));
|
|
|
|
|
}
|
|
|
|
@ -857,9 +870,10 @@ void nsClipboard::AsyncGetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
|
nsIClipboard::IsClipboardTypeSupported(aWhichClipboard));
|
|
|
|
|
|
|
|
|
|
LOGCLIP("nsClipboard::AsyncGetNativeClipboardData (%s)",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard ? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("nsClipboard::AsyncGetNativeClipboardData (%s)",
|
|
|
|
|
aWhichClipboard == nsClipboard::kSelectionClipboard
|
|
|
|
|
? "primary"
|
|
|
|
|
: "clipboard");
|
|
|
|
|
nsTArray<nsCString> importedFlavors;
|
|
|
|
|
nsresult rv = GetTransferableFlavors(aTransferable, importedFlavors);
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
@ -874,8 +888,9 @@ void nsClipboard::AsyncGetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
}
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
|
if (flavorsNum > 1) {
|
|
|
|
|
LOGCLIP(" Only first MIME type (%s) will be imported from clipboard!",
|
|
|
|
|
importedFlavors[0].get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
" Only first MIME type (%s) will be imported from clipboard!",
|
|
|
|
|
importedFlavors[0].get());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -894,7 +909,7 @@ void nsClipboard::AsyncGetNativeClipboardData(nsITransferable* aTransferable,
|
|
|
|
|
nsTArray<nsCString> clipboardFlavors =
|
|
|
|
|
std::move(aResultOrError.unwrap());
|
|
|
|
|
if (!clipboardFlavors.Length()) {
|
|
|
|
|
LOGCLIP(" no flavors in clipboard, quit.");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" no flavors in clipboard, quit.");
|
|
|
|
|
callback(NS_OK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -914,8 +929,9 @@ nsresult nsClipboard::EmptyNativeClipboardData(int32_t aWhichClipboard) {
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
|
nsIClipboard::IsClipboardTypeSupported(aWhichClipboard));
|
|
|
|
|
|
|
|
|
|
LOGCLIP("nsClipboard::EmptyNativeClipboardData (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::EmptyNativeClipboardData (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
if (aWhichClipboard == kSelectionClipboard) {
|
|
|
|
|
if (mSelectionTransferable) {
|
|
|
|
|
gtk_clipboard_clear(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
|
|
|
|
@ -947,20 +963,21 @@ static bool FlavorMatchesTarget(const nsACString& aFlavor, GdkAtom aTarget) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (aFlavor.Equals(atom_name.get())) {
|
|
|
|
|
LOGCLIP(" has %s\n", atom_name.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" has %s\n", atom_name.get());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// X clipboard supports image/jpeg, but we want to emulate support
|
|
|
|
|
// for image/jpg as well
|
|
|
|
|
if (aFlavor.EqualsLiteral(kJPGImageMime) &&
|
|
|
|
|
!strcmp(atom_name.get(), kJPEGImageMime)) {
|
|
|
|
|
LOGCLIP(" has image/jpg\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" has image/jpg\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// application/x-moz-file should be treated like text/uri-list
|
|
|
|
|
if (aFlavor.EqualsLiteral(kFileMime) &&
|
|
|
|
|
!strcmp(atom_name.get(), kURIListMime)) {
|
|
|
|
|
LOGCLIP(" has text/uri-list treating as application/x-moz-file");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
" has text/uri-list treating as application/x-moz-file");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
@ -972,8 +989,9 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors(
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
|
nsIClipboard::IsClipboardTypeSupported(aWhichClipboard));
|
|
|
|
|
|
|
|
|
|
LOGCLIP("nsClipboard::HasNativeClipboardDataMatchingFlavors (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::HasNativeClipboardDataMatchingFlavors (%s)\n",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
|
|
|
|
|
if (!mContext) {
|
|
|
|
|
return Err(NS_ERROR_FAILURE);
|
|
|
|
@ -981,25 +999,25 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors(
|
|
|
|
|
|
|
|
|
|
auto targets = mContext->GetTargets(aWhichClipboard);
|
|
|
|
|
if (!targets) {
|
|
|
|
|
LOGCLIP(" no targes at clipboard (null)\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" no targes at clipboard (null)\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
|
if (LOGCLIP_ENABLED()) {
|
|
|
|
|
LOGCLIP(" Asking for content:\n");
|
|
|
|
|
if (MOZ_CLIPBOARD_LOG_ENABLED()) {
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Asking for content:\n");
|
|
|
|
|
for (auto& flavor : aFlavorList) {
|
|
|
|
|
LOGCLIP(" MIME %s\n", flavor.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" MIME %s\n", flavor.get());
|
|
|
|
|
}
|
|
|
|
|
LOGCLIP(" Clipboard content (target nums %zu):\n",
|
|
|
|
|
targets.AsSpan().Length());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Clipboard content (target nums %zu):\n",
|
|
|
|
|
targets.AsSpan().Length());
|
|
|
|
|
for (const auto& target : targets.AsSpan()) {
|
|
|
|
|
GUniquePtr<gchar> atom_name(gdk_atom_name(target));
|
|
|
|
|
if (!atom_name) {
|
|
|
|
|
LOGCLIP(" failed to get MIME\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get MIME\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
LOGCLIP(" MIME %s\n", atom_name.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" MIME %s\n", atom_name.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -1011,7 +1029,7 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors(
|
|
|
|
|
if (flavor.EqualsLiteral(kTextMime) &&
|
|
|
|
|
gtk_targets_include_text(targets.AsSpan().data(),
|
|
|
|
|
targets.AsSpan().Length())) {
|
|
|
|
|
LOGCLIP(" has kTextMime\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" has kTextMime\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
for (const auto& target : targets.AsSpan()) {
|
|
|
|
@ -1021,7 +1039,7 @@ nsClipboard::HasNativeClipboardDataMatchingFlavors(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" no targes at clipboard (bad match)\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" no targes at clipboard (bad match)\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1030,10 +1048,10 @@ struct TragetCallbackHandler {
|
|
|
|
|
nsBaseClipboard::HasMatchingFlavorsCallback&& aCallback)
|
|
|
|
|
: mAcceptedFlavorList(aAcceptedFlavorList.Clone()),
|
|
|
|
|
mCallback(std::move(aCallback)) {
|
|
|
|
|
LOGCLIP("TragetCallbackHandler(%p) created", this);
|
|
|
|
|
MOZ_CLIPBOARD_LOG("TragetCallbackHandler(%p) created", this);
|
|
|
|
|
}
|
|
|
|
|
~TragetCallbackHandler() {
|
|
|
|
|
LOGCLIP("TragetCallbackHandler(%p) deleted", this);
|
|
|
|
|
MOZ_CLIPBOARD_LOG("TragetCallbackHandler(%p) deleted", this);
|
|
|
|
|
}
|
|
|
|
|
nsTArray<nsCString> mAcceptedFlavorList;
|
|
|
|
|
nsBaseClipboard::HasMatchingFlavorsCallback mCallback;
|
|
|
|
@ -1045,15 +1063,17 @@ void nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors(
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
|
nsIClipboard::IsClipboardTypeSupported(aWhichClipboard));
|
|
|
|
|
|
|
|
|
|
LOGCLIP("nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors (%s)",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors (%s)",
|
|
|
|
|
aWhichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
|
|
|
|
|
gtk_clipboard_request_contents(
|
|
|
|
|
gtk_clipboard_get(GetSelectionAtom(aWhichClipboard)),
|
|
|
|
|
gdk_atom_intern("TARGETS", FALSE),
|
|
|
|
|
[](GtkClipboard* aClipboard, GtkSelectionData* aSelection,
|
|
|
|
|
gpointer aData) -> void {
|
|
|
|
|
LOGCLIP("gtk_clipboard_request_contents async handler (%p)", aData);
|
|
|
|
|
MOZ_CLIPBOARD_LOG("gtk_clipboard_request_contents async handler (%p)",
|
|
|
|
|
aData);
|
|
|
|
|
UniquePtr<TragetCallbackHandler> handler(
|
|
|
|
|
static_cast<TragetCallbackHandler*>(aData));
|
|
|
|
|
|
|
|
|
@ -1065,11 +1085,11 @@ void nsClipboard::AsyncHasNativeClipboardDataMatchingFlavors(
|
|
|
|
|
nsTArray<nsCString> results;
|
|
|
|
|
if (targetsNum) {
|
|
|
|
|
for (auto& flavor : handler->mAcceptedFlavorList) {
|
|
|
|
|
LOGCLIP(" looking for %s", flavor.get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" looking for %s", flavor.get());
|
|
|
|
|
if (flavor.EqualsLiteral(kTextMime) &&
|
|
|
|
|
gtk_targets_include_text(targets, targetsNum)) {
|
|
|
|
|
results.AppendElement(flavor);
|
|
|
|
|
LOGCLIP(" has kTextMime\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" has kTextMime\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < targetsNum; i++) {
|
|
|
|
@ -1113,14 +1133,16 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
else
|
|
|
|
|
return; // THAT AIN'T NO CLIPBOARD I EVER HEARD OF
|
|
|
|
|
|
|
|
|
|
LOGCLIP("nsClipboard::SelectionGetEvent (%s)\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::SelectionGetEvent (%s)\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans = GetTransferable(whichClipboard);
|
|
|
|
|
if (!trans) {
|
|
|
|
|
// We have nothing to serve
|
|
|
|
|
LOGCLIP("nsClipboard::SelectionGetEvent() - %s clipboard is empty!\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "Primary" : "Clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::SelectionGetEvent() - %s clipboard is empty!\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "Primary" : "Clipboard");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1128,18 +1150,18 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
nsCOMPtr<nsISupports> item;
|
|
|
|
|
|
|
|
|
|
GdkAtom selectionTarget = gtk_selection_data_get_target(aSelectionData);
|
|
|
|
|
LOGCLIP(" selection target %s\n",
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" selection target %s\n",
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
|
|
|
|
|
// Check to see if the selection data is some text type.
|
|
|
|
|
if (gtk_targets_include_text(&selectionTarget, 1)) {
|
|
|
|
|
LOGCLIP(" providing text/plain data\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" providing text/plain data\n");
|
|
|
|
|
// Try to convert our internal type into a text string. Get
|
|
|
|
|
// the transferable for this clipboard and try to get the
|
|
|
|
|
// text/plain type for it.
|
|
|
|
|
rv = trans->GetTransferData("text/plain", getter_AddRefs(item));
|
|
|
|
|
if (NS_FAILED(rv) || !item) {
|
|
|
|
|
LOGCLIP(" GetTransferData() failed to get text/plain!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" GetTransferData() failed to get text/plain!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1151,9 +1173,9 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
wideString->GetData(ucs2string);
|
|
|
|
|
NS_ConvertUTF16toUTF8 utf8string(ucs2string);
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" sent %zd bytes of utf-8 data\n", utf8string.Length());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" sent %zd bytes of utf-8 data\n", utf8string.Length());
|
|
|
|
|
if (selectionTarget == gdk_atom_intern("text/plain;charset=utf-8", FALSE)) {
|
|
|
|
|
LOGCLIP(
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
" using gtk_selection_data_set for 'text/plain;charset=utf-8'\n");
|
|
|
|
|
// Bypass gtk_selection_data_set_text, which will convert \n to \r\n
|
|
|
|
|
// in some versions of GTK.
|
|
|
|
@ -1169,7 +1191,7 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
|
|
|
|
|
// Check to see if the selection data is an image type
|
|
|
|
|
if (gtk_targets_include_image(&selectionTarget, 1, TRUE)) {
|
|
|
|
|
LOGCLIP(" providing image data\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" providing image data\n");
|
|
|
|
|
// Look through our transfer data for the image
|
|
|
|
|
static const char* const imageMimeTypes[] = {kNativeImageMime,
|
|
|
|
|
kPNGImageMime, kJPEGImageMime,
|
|
|
|
@ -1179,47 +1201,50 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(imageMimeTypes); i++) {
|
|
|
|
|
rv = trans->GetTransferData(imageMimeTypes[i], getter_AddRefs(imageItem));
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
|
LOGCLIP(" %s is missing at GetTransferData()\n", imageMimeTypes[i]);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" %s is missing at GetTransferData()\n",
|
|
|
|
|
imageMimeTypes[i]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image = do_QueryInterface(imageItem);
|
|
|
|
|
if (image) {
|
|
|
|
|
LOGCLIP(" %s is available at GetTransferData()\n",
|
|
|
|
|
imageMimeTypes[i]);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" %s is available at GetTransferData()\n",
|
|
|
|
|
imageMimeTypes[i]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!image) { // Not getting an image for an image mime type!?
|
|
|
|
|
LOGCLIP(" Failed to get any image mime from GetTransferData()!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
" Failed to get any image mime from GetTransferData()!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefPtr<GdkPixbuf> pixbuf = nsImageToPixbuf::ImageToPixbuf(image);
|
|
|
|
|
if (!pixbuf) {
|
|
|
|
|
LOGCLIP(" nsImageToPixbuf::ImageToPixbuf() failed!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" nsImageToPixbuf::ImageToPixbuf() failed!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" Setting pixbuf image data as %s\n",
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Setting pixbuf image data as %s\n",
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
gtk_selection_data_set_pixbuf(aSelectionData, pixbuf);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (selectionTarget == gdk_atom_intern(kHTMLMime, FALSE)) {
|
|
|
|
|
LOGCLIP(" providing %s data\n", kHTMLMime);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" providing %s data\n", kHTMLMime);
|
|
|
|
|
rv = trans->GetTransferData(kHTMLMime, getter_AddRefs(item));
|
|
|
|
|
if (NS_FAILED(rv) || !item) {
|
|
|
|
|
LOGCLIP(" failed to get %s data by GetTransferData()!\n", kHTMLMime);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get %s data by GetTransferData()!\n",
|
|
|
|
|
kHTMLMime);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsString> wideString;
|
|
|
|
|
wideString = do_QueryInterface(item);
|
|
|
|
|
if (!wideString) {
|
|
|
|
|
LOGCLIP(" failed to get wideString interface!");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get wideString interface!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1231,8 +1256,8 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
html.AppendLiteral(kHTMLMarkupPrefix);
|
|
|
|
|
AppendUTF16toUTF8(ucs2string, html);
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" Setting %zd bytes of %s data\n", html.Length(),
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Setting %zd bytes of %s data\n", html.Length(),
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
gtk_selection_data_set(aSelectionData, selectionTarget, 8,
|
|
|
|
|
(const guchar*)html.get(), html.Length());
|
|
|
|
|
return;
|
|
|
|
@ -1240,53 +1265,54 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
|
|
|
|
|
// We put kFileMime onto the clipboard as kURIListMime.
|
|
|
|
|
if (selectionTarget == gdk_atom_intern(kURIListMime, FALSE)) {
|
|
|
|
|
LOGCLIP(" providing %s data\n", kURIListMime);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" providing %s data\n", kURIListMime);
|
|
|
|
|
rv = trans->GetTransferData(kFileMime, getter_AddRefs(item));
|
|
|
|
|
if (NS_FAILED(rv) || !item) {
|
|
|
|
|
LOGCLIP(" failed to get %s data by GetTransferData()!\n", kFileMime);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get %s data by GetTransferData()!\n",
|
|
|
|
|
kFileMime);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(item);
|
|
|
|
|
if (!file) {
|
|
|
|
|
LOGCLIP(" failed to get nsIFile interface!");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get nsIFile interface!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> fileURI;
|
|
|
|
|
rv = NS_NewFileURI(getter_AddRefs(fileURI), file);
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
|
LOGCLIP(" failed to get fileURI\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get fileURI\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsAutoCString uri;
|
|
|
|
|
if (NS_FAILED(fileURI->GetSpec(uri))) {
|
|
|
|
|
LOGCLIP(" failed to get fileURI spec\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" failed to get fileURI spec\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" Setting %zd bytes of data\n", uri.Length());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Setting %zd bytes of data\n", uri.Length());
|
|
|
|
|
gtk_selection_data_set(aSelectionData, selectionTarget, 8,
|
|
|
|
|
(const guchar*)uri.get(), uri.Length());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" Try if we have anything at GetTransferData() for %s\n",
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Try if we have anything at GetTransferData() for %s\n",
|
|
|
|
|
GUniquePtr<gchar>(gdk_atom_name(selectionTarget)).get());
|
|
|
|
|
|
|
|
|
|
// Try to match up the selection data target to something our
|
|
|
|
|
// transferable provides.
|
|
|
|
|
GUniquePtr<gchar> target_name(gdk_atom_name(selectionTarget));
|
|
|
|
|
if (!target_name) {
|
|
|
|
|
LOGCLIP(" Failed to get target name!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Failed to get target name!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rv = trans->GetTransferData(target_name.get(), getter_AddRefs(item));
|
|
|
|
|
// nothing found?
|
|
|
|
|
if (NS_FAILED(rv) || !item) {
|
|
|
|
|
LOGCLIP(" Failed to get anything from GetTransferData()!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Failed to get anything from GetTransferData()!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1295,12 +1321,12 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
|
|
|
|
|
nsPrimitiveHelpers::CreateDataFromPrimitive(
|
|
|
|
|
nsDependentCString(target_name.get()), item, &primitive_data, &dataLen);
|
|
|
|
|
if (!primitive_data) {
|
|
|
|
|
LOGCLIP(" Failed to get primitive data!\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Failed to get primitive data!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGCLIP(" Setting %s as a primitive data type, %d bytes\n",
|
|
|
|
|
target_name.get(), dataLen);
|
|
|
|
|
MOZ_CLIPBOARD_LOG(" Setting %s as a primitive data type, %d bytes\n",
|
|
|
|
|
target_name.get(), dataLen);
|
|
|
|
|
gtk_selection_data_set(aSelectionData, selectionTarget,
|
|
|
|
|
8, /* 8 bits in a unit */
|
|
|
|
|
(const guchar*)primitive_data, dataLen);
|
|
|
|
@ -1320,8 +1346,9 @@ void nsClipboard::SelectionClearEvent(GtkClipboard* aGtkClipboard) {
|
|
|
|
|
if (whichClipboard < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LOGCLIP("nsClipboard::SelectionClearEvent (%s)\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::SelectionClearEvent (%s)\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
ClearCachedTargets(whichClipboard);
|
|
|
|
|
ClearTransferable(whichClipboard);
|
|
|
|
|
ClearClipboardCache(whichClipboard);
|
|
|
|
@ -1333,8 +1360,9 @@ void nsClipboard::OwnerChangedEvent(GtkClipboard* aGtkClipboard,
|
|
|
|
|
if (whichClipboard < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LOGCLIP("nsClipboard::OwnerChangedEvent (%s)\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
MOZ_CLIPBOARD_LOG(
|
|
|
|
|
"nsClipboard::OwnerChangedEvent (%s)\n",
|
|
|
|
|
whichClipboard == kSelectionClipboard ? "primary" : "clipboard");
|
|
|
|
|
GtkWidget* gtkWidget = [aEvent]() -> GtkWidget* {
|
|
|
|
|
if (!aEvent->owner) {
|
|
|
|
|
return nullptr;
|
|
|
|
@ -1360,13 +1388,13 @@ void nsClipboard::OwnerChangedEvent(GtkClipboard* aGtkClipboard,
|
|
|
|
|
void clipboard_get_cb(GtkClipboard* aGtkClipboard,
|
|
|
|
|
GtkSelectionData* aSelectionData, guint info,
|
|
|
|
|
gpointer user_data) {
|
|
|
|
|
LOGCLIP("clipboard_get_cb() callback\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("clipboard_get_cb() callback\n");
|
|
|
|
|
nsClipboard* clipboard = static_cast<nsClipboard*>(user_data);
|
|
|
|
|
clipboard->SelectionGetEvent(aGtkClipboard, aSelectionData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clipboard_clear_cb(GtkClipboard* aGtkClipboard, gpointer user_data) {
|
|
|
|
|
LOGCLIP("clipboard_clear_cb() callback\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("clipboard_clear_cb() callback\n");
|
|
|
|
|
nsClipboard* clipboard = static_cast<nsClipboard*>(user_data);
|
|
|
|
|
clipboard->SelectionClearEvent(aGtkClipboard);
|
|
|
|
|
}
|
|
|
|
@ -1374,7 +1402,7 @@ void clipboard_clear_cb(GtkClipboard* aGtkClipboard, gpointer user_data) {
|
|
|
|
|
void clipboard_owner_change_cb(GtkClipboard* aGtkClipboard,
|
|
|
|
|
GdkEventOwnerChange* aEvent,
|
|
|
|
|
gpointer aUserData) {
|
|
|
|
|
LOGCLIP("clipboard_owner_change_cb() callback\n");
|
|
|
|
|
MOZ_CLIPBOARD_LOG("clipboard_owner_change_cb() callback\n");
|
|
|
|
|
nsClipboard* clipboard = static_cast<nsClipboard*>(aUserData);
|
|
|
|
|
clipboard->OwnerChangedEvent(aGtkClipboard, aEvent);
|
|
|
|
|
}
|
|
|
|
|