2006-10-03 00:28:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2006-10-03 00:28:40 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2010-06-28 04:25:04 +04:00
|
|
|
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-04-19 07:30:11 +03:00
|
|
|
|
2014-03-08 05:21:24 +04:00
|
|
|
#include "gfxPlatform.h"
|
2016-10-16 22:43:56 +03:00
|
|
|
#include "nsArrayUtils.h"
|
2006-10-03 00:28:40 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsClipboard.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsPrimitiveHelpers.h"
|
|
|
|
#include "nsMemory.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2007-09-17 22:02:50 +04:00
|
|
|
#include "nsStringStream.h"
|
2007-09-25 00:43:01 +04:00
|
|
|
#include "nsDragService.h"
|
|
|
|
#include "nsEscape.h"
|
2007-10-23 09:44:25 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2008-02-18 20:30:59 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
#include "imgIContainer.h"
|
2010-03-13 17:39:55 +03:00
|
|
|
#include "nsCocoaUtils.h"
|
2007-09-17 22:02:50 +04:00
|
|
|
|
2014-03-08 05:21:24 +04:00
|
|
|
using mozilla::gfx::DataSourceSurface;
|
|
|
|
using mozilla::gfx::SourceSurface;
|
2015-06-04 01:25:57 +03:00
|
|
|
using mozilla::LogLevel;
|
2014-03-08 05:21:24 +04:00
|
|
|
|
2016-05-18 22:55:42 +03:00
|
|
|
extern mozilla::LazyLogModule sCocoaLog;
|
2007-09-05 10:58:16 +04:00
|
|
|
|
2016-07-08 18:21:43 +03:00
|
|
|
mozilla::StaticRefPtr<nsITransferable> nsClipboard::sSelectionCache;
|
|
|
|
|
2017-05-23 07:23:38 +03:00
|
|
|
@implementation UTIHelper
|
|
|
|
|
|
|
|
+ (NSString*)stringFromPboardType:(NSString*)aType {
|
2017-05-23 07:23:47 +03:00
|
|
|
if ([aType isEqualToString:kMozWildcardPboardType] ||
|
|
|
|
[aType isEqualToString:kMozCustomTypesPboardType] ||
|
2017-05-23 07:23:38 +03:00
|
|
|
[aType isEqualToString:kPublicUrlPboardType] ||
|
|
|
|
[aType isEqualToString:kPublicUrlNamePboardType] ||
|
2017-05-23 07:23:47 +03:00
|
|
|
[aType isEqualToString:kMozFileUrlsPboardType] ||
|
2017-05-23 07:23:38 +03:00
|
|
|
[aType isEqualToString:(NSString*)kPasteboardTypeFileURLPromise] ||
|
|
|
|
[aType isEqualToString:(NSString*)kPasteboardTypeFilePromiseContent] ||
|
2017-05-23 07:23:47 +03:00
|
|
|
[aType isEqualToString:(NSString*)kUTTypeFileURL] ||
|
2017-05-23 07:23:54 +03:00
|
|
|
[aType isEqualToString:NSStringPboardType] ||
|
2017-05-23 07:23:38 +03:00
|
|
|
[aType isEqualToString:NSPasteboardTypeString] ||
|
|
|
|
[aType isEqualToString:NSPasteboardTypeHTML] || [aType isEqualToString:NSPasteboardTypeRTF] ||
|
|
|
|
[aType isEqualToString:NSPasteboardTypeTIFF] || [aType isEqualToString:NSPasteboardTypePNG]) {
|
|
|
|
return [NSString stringWithString:aType];
|
|
|
|
}
|
|
|
|
NSString* dynamicType = (NSString*)UTTypeCreatePreferredIdentifierForTag(
|
|
|
|
kUTTagClassNSPboardType, (CFStringRef)aType, kUTTypeData);
|
|
|
|
NSString* result = [NSString stringWithString:dynamicType];
|
|
|
|
[dynamicType release];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end // UTIHelper
|
|
|
|
|
2016-08-11 23:43:32 +03:00
|
|
|
nsClipboard::nsClipboard()
|
|
|
|
: mCachedClipboard(-1), mChangeCount(0), mIgnoreEmptyNotification(false) {}
|
2006-10-03 00:28:40 +04:00
|
|
|
|
|
|
|
nsClipboard::~nsClipboard() {
|
2016-08-11 23:43:32 +03:00
|
|
|
EmptyClipboard(kGlobalClipboard);
|
|
|
|
EmptyClipboard(kFindClipboard);
|
|
|
|
ClearSelectionCache();
|
2006-10-03 00:28:40 +04:00
|
|
|
}
|
|
|
|
|
2016-08-11 23:43:32 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
|
|
|
|
|
2007-10-23 09:44:25 +04:00
|
|
|
// We separate this into its own function because after an @try, all local
|
2015-04-19 07:30:11 +03:00
|
|
|
// variables within that function get marked as volatile, and our C++ type
|
2007-10-23 09:44:25 +04:00
|
|
|
// system doesn't like volatile things.
|
|
|
|
static NSData* GetDataFromPasteboard(NSPasteboard* aPasteboard, NSString* aType) {
|
|
|
|
NSData* data = nil;
|
|
|
|
@try {
|
|
|
|
data = [aPasteboard dataForType:aType];
|
|
|
|
} @catch (NSException* e) {
|
2015-04-19 07:30:11 +03:00
|
|
|
NS_WARNING(
|
|
|
|
nsPrintfCString("Exception raised while getting data from the pasteboard: \"%s - %s\"",
|
2007-10-23 09:44:25 +04:00
|
|
|
[[e name] UTF8String], [[e reason] UTF8String])
|
|
|
|
.get());
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << e;
|
2007-10-23 09:44:25 +04:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2016-07-08 18:21:43 +03:00
|
|
|
void nsClipboard::SetSelectionCache(nsITransferable* aTransferable) {
|
|
|
|
sSelectionCache = aTransferable;
|
|
|
|
}
|
|
|
|
|
2016-06-08 21:11:39 +03:00
|
|
|
void nsClipboard::ClearSelectionCache() { sSelectionCache = nullptr; }
|
|
|
|
|
2006-10-03 00:28:40 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsClipboard::SetNativeClipboardData(int32_t aWhichClipboard) {
|
2008-02-18 20:30:59 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2014-02-28 19:07:30 +04:00
|
|
|
if ((aWhichClipboard != kGlobalClipboard && aWhichClipboard != kFindClipboard) || !mTransferable)
|
2006-10-03 00:28:40 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
mIgnoreEmptyNotification = true;
|
2006-10-03 00:28:40 +04:00
|
|
|
|
2007-06-27 09:26:18 +04:00
|
|
|
NSDictionary* pasteboardOutputDict = PasteboardDictFromTransferable(mTransferable);
|
|
|
|
if (!pasteboardOutputDict) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
unsigned int outputCount = [pasteboardOutputDict count];
|
|
|
|
NSArray* outputKeys = [pasteboardOutputDict allKeys];
|
2014-02-28 19:07:30 +04:00
|
|
|
NSPasteboard* cocoaPasteboard;
|
|
|
|
if (aWhichClipboard == kFindClipboard) {
|
|
|
|
cocoaPasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* stringType = [UTIHelper stringFromPboardType:NSPasteboardTypeString];
|
|
|
|
[cocoaPasteboard declareTypes:[NSArray arrayWithObject:stringType] owner:nil];
|
2014-02-28 19:07:30 +04:00
|
|
|
} else {
|
|
|
|
// Write everything else out to the general pasteboard.
|
|
|
|
cocoaPasteboard = [NSPasteboard generalPasteboard];
|
|
|
|
[cocoaPasteboard declareTypes:outputKeys owner:nil];
|
|
|
|
}
|
|
|
|
|
2007-06-27 09:26:18 +04:00
|
|
|
for (unsigned int i = 0; i < outputCount; i++) {
|
|
|
|
NSString* currentKey = [outputKeys objectAtIndex:i];
|
|
|
|
id currentValue = [pasteboardOutputDict valueForKey:currentKey];
|
2014-02-28 19:07:30 +04:00
|
|
|
if (aWhichClipboard == kFindClipboard) {
|
2017-05-23 07:23:38 +03:00
|
|
|
if ([currentKey isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeString]]) {
|
2014-02-28 19:07:30 +04:00
|
|
|
[cocoaPasteboard setString:currentValue forType:currentKey];
|
2017-05-23 07:23:38 +03:00
|
|
|
}
|
2009-01-01 17:26:16 +03:00
|
|
|
} else {
|
2017-05-23 07:23:38 +03:00
|
|
|
if ([currentKey isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeString]] ||
|
|
|
|
[currentKey isEqualToString:[UTIHelper stringFromPboardType:kPublicUrlPboardType]] ||
|
|
|
|
[currentKey isEqualToString:[UTIHelper stringFromPboardType:kPublicUrlNamePboardType]]) {
|
2014-02-28 19:07:30 +04:00
|
|
|
[cocoaPasteboard setString:currentValue forType:currentKey];
|
2017-05-23 07:23:38 +03:00
|
|
|
} else if ([currentKey
|
|
|
|
isEqualToString:[UTIHelper stringFromPboardType:kUrlsWithTitlesPboardType]]) {
|
2017-05-23 07:23:33 +03:00
|
|
|
[cocoaPasteboard setPropertyList:[pasteboardOutputDict valueForKey:currentKey]
|
|
|
|
forType:currentKey];
|
2017-05-23 07:23:38 +03:00
|
|
|
} else if ([currentKey
|
|
|
|
isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeHTML]]) {
|
2014-02-28 19:07:30 +04:00
|
|
|
[cocoaPasteboard setString:(nsClipboard::WrapHtmlForSystemPasteboard(currentValue))
|
|
|
|
forType:currentKey];
|
2017-05-23 07:23:47 +03:00
|
|
|
} else if ([currentKey
|
|
|
|
isEqualToString:[UTIHelper stringFromPboardType:kMozFileUrlsPboardType]]) {
|
|
|
|
[cocoaPasteboard writeObjects:currentValue];
|
2014-02-28 19:07:30 +04:00
|
|
|
} else {
|
|
|
|
[cocoaPasteboard setData:currentValue forType:currentKey];
|
|
|
|
}
|
2009-01-01 17:26:16 +03:00
|
|
|
}
|
2007-06-27 09:26:18 +04:00
|
|
|
}
|
|
|
|
|
2014-06-26 05:29:50 +04:00
|
|
|
mCachedClipboard = aWhichClipboard;
|
|
|
|
mChangeCount = [cocoaPasteboard changeCount];
|
2007-07-03 11:16:19 +04:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
mIgnoreEmptyNotification = false;
|
2007-06-27 09:26:18 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-18 20:30:59 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-06-27 09:26:18 +04:00
|
|
|
}
|
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
nsresult nsClipboard::TransferableFromPasteboard(nsITransferable* aTransferable,
|
|
|
|
NSPasteboard* cocoaPasteboard) {
|
2008-02-18 20:30:59 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-07-03 11:16:19 +04:00
|
|
|
// get flavor list that includes all acceptable flavors (including ones obtained through
|
|
|
|
// conversion)
|
2018-10-10 23:25:54 +03:00
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
nsresult rv = aTransferable->FlavorsTransferableCanImport(flavors);
|
2007-07-03 11:16:19 +04:00
|
|
|
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
for (uint32_t i = 0; i < flavors.Length(); i++) {
|
|
|
|
nsCString& flavorStr = flavors[i];
|
2007-07-03 11:16:19 +04:00
|
|
|
|
|
|
|
// printf("looking for clipboard data of type %s\n", flavorStr.get());
|
|
|
|
|
2010-11-18 00:42:05 +03:00
|
|
|
NSString* pboardType = nil;
|
2008-11-07 04:08:35 +03:00
|
|
|
if (nsClipboard::IsStringType(flavorStr, &pboardType)) {
|
|
|
|
NSString* pString = [cocoaPasteboard stringForType:pboardType];
|
2007-07-03 11:16:19 +04:00
|
|
|
if (!pString) continue;
|
|
|
|
|
2015-11-23 22:04:26 +03:00
|
|
|
NSData* stringData;
|
2017-05-23 07:23:38 +03:00
|
|
|
if ([pboardType isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeRTF]]) {
|
2015-11-23 22:04:26 +03:00
|
|
|
stringData = [pString dataUsingEncoding:NSASCIIStringEncoding];
|
|
|
|
} else {
|
|
|
|
stringData = [pString dataUsingEncoding:NSUnicodeStringEncoding];
|
|
|
|
}
|
2007-07-03 11:16:19 +04:00
|
|
|
unsigned int dataLength = [stringData length];
|
|
|
|
void* clipboardDataPtr = malloc(dataLength);
|
2017-05-23 07:23:38 +03:00
|
|
|
if (!clipboardDataPtr) {
|
|
|
|
[pboardType release];
|
2007-07-03 11:16:19 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2017-05-23 07:23:38 +03:00
|
|
|
}
|
2007-07-03 11:16:19 +04:00
|
|
|
[stringData getBytes:clipboardDataPtr];
|
|
|
|
|
|
|
|
// The DOM only wants LF, so convert from MacOS line endings to DOM line endings.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t signedDataLength = dataLength;
|
2007-07-03 11:16:19 +04:00
|
|
|
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(flavorStr, &clipboardDataPtr,
|
|
|
|
&signedDataLength);
|
|
|
|
dataLength = signedDataLength;
|
|
|
|
|
|
|
|
// skip BOM (Byte Order Mark to distinguish little or big endian)
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* clipboardDataPtrNoBOM = (char16_t*)clipboardDataPtr;
|
2007-07-03 11:16:19 +04:00
|
|
|
if ((dataLength > 2) &&
|
|
|
|
((clipboardDataPtrNoBOM[0] == 0xFEFF) || (clipboardDataPtrNoBOM[0] == 0xFFFE))) {
|
2014-01-04 19:02:17 +04:00
|
|
|
dataLength -= sizeof(char16_t);
|
2007-07-03 11:16:19 +04:00
|
|
|
clipboardDataPtrNoBOM += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
|
|
|
nsPrimitiveHelpers::CreatePrimitiveForData(flavorStr, clipboardDataPtrNoBOM, dataLength,
|
|
|
|
getter_AddRefs(genericDataWrapper));
|
2018-11-20 20:00:09 +03:00
|
|
|
aTransferable->SetTransferData(flavorStr.get(), genericDataWrapper);
|
2007-07-03 11:16:19 +04:00
|
|
|
free(clipboardDataPtr);
|
|
|
|
break;
|
2016-04-21 21:11:14 +03:00
|
|
|
} else if (flavorStr.EqualsLiteral(kCustomTypesMime)) {
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* type = [cocoaPasteboard
|
|
|
|
availableTypeFromArray:
|
2017-05-23 07:23:47 +03:00
|
|
|
[NSArray arrayWithObject:[UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]];
|
2016-04-21 21:11:14 +03:00
|
|
|
if (!type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSData* pasteboardData = GetDataFromPasteboard(cocoaPasteboard, type);
|
|
|
|
if (!pasteboardData) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int dataLength = [pasteboardData length];
|
|
|
|
void* clipboardDataPtr = malloc(dataLength);
|
|
|
|
if (!clipboardDataPtr) {
|
2017-05-23 07:23:38 +03:00
|
|
|
[pboardType release];
|
2016-04-21 21:11:14 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
[pasteboardData getBytes:clipboardDataPtr];
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
|
|
|
nsPrimitiveHelpers::CreatePrimitiveForData(flavorStr, clipboardDataPtr, dataLength,
|
|
|
|
getter_AddRefs(genericDataWrapper));
|
|
|
|
|
2018-11-20 20:00:09 +03:00
|
|
|
aTransferable->SetTransferData(flavorStr.get(), genericDataWrapper);
|
2016-04-21 21:11:14 +03:00
|
|
|
free(clipboardDataPtr);
|
2007-09-17 22:02:50 +04:00
|
|
|
} else if (flavorStr.EqualsLiteral(kJPEGImageMime) || flavorStr.EqualsLiteral(kJPGImageMime) ||
|
|
|
|
flavorStr.EqualsLiteral(kPNGImageMime) || flavorStr.EqualsLiteral(kGIFImageMime)) {
|
|
|
|
// Figure out if there's data on the pasteboard we can grab (sanity check)
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* type = [cocoaPasteboard
|
|
|
|
availableTypeFromArray:
|
2018-05-17 16:12:46 +03:00
|
|
|
[NSArray arrayWithObjects:[UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL],
|
2017-05-23 07:23:38 +03:00
|
|
|
[UTIHelper stringFromPboardType:NSPasteboardTypeTIFF],
|
|
|
|
[UTIHelper stringFromPboardType:NSPasteboardTypePNG], nil]];
|
2007-09-17 22:02:50 +04:00
|
|
|
if (!type) continue;
|
2007-07-03 11:16:19 +04:00
|
|
|
|
2007-10-23 09:44:25 +04:00
|
|
|
// Read data off the clipboard
|
|
|
|
NSData* pasteboardData = GetDataFromPasteboard(cocoaPasteboard, type);
|
2007-10-12 23:36:19 +04:00
|
|
|
if (!pasteboardData) continue;
|
|
|
|
|
2007-09-17 22:02:50 +04:00
|
|
|
// Figure out what type we're converting to
|
|
|
|
CFStringRef outputType = NULL;
|
2012-06-11 03:44:50 +04:00
|
|
|
if (flavorStr.EqualsLiteral(kJPEGImageMime) || flavorStr.EqualsLiteral(kJPGImageMime))
|
2007-09-17 22:02:50 +04:00
|
|
|
outputType = CFSTR("public.jpeg");
|
|
|
|
else if (flavorStr.EqualsLiteral(kPNGImageMime))
|
|
|
|
outputType = CFSTR("public.png");
|
|
|
|
else if (flavorStr.EqualsLiteral(kGIFImageMime))
|
|
|
|
outputType = CFSTR("com.compuserve.gif");
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Use ImageIO to interpret the data on the clipboard and transcode.
|
|
|
|
// Note that ImageIO, like all CF APIs, allows NULLs to propagate freely
|
|
|
|
// and safely in most cases (like ObjC). A notable exception is CFRelease.
|
2018-05-17 16:12:46 +03:00
|
|
|
NSDictionary* options = [NSDictionary
|
|
|
|
dictionaryWithObjectsAndKeys:(NSNumber*)kCFBooleanTrue, kCGImageSourceShouldAllowFloat,
|
|
|
|
type, kCGImageSourceTypeIdentifierHint, nil];
|
|
|
|
CGImageSourceRef source = nullptr;
|
|
|
|
if (type == [UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL]) {
|
|
|
|
NSString* urlStr = [cocoaPasteboard stringForType:type];
|
|
|
|
NSURL* url = [NSURL URLWithString:urlStr];
|
|
|
|
source = CGImageSourceCreateWithURL((CFURLRef)url, (CFDictionaryRef)options);
|
|
|
|
} else {
|
|
|
|
source = CGImageSourceCreateWithData((CFDataRef)pasteboardData, (CFDictionaryRef)options);
|
|
|
|
}
|
|
|
|
|
2007-09-17 22:02:50 +04:00
|
|
|
NSMutableData* encodedData = [NSMutableData data];
|
|
|
|
CGImageDestinationRef dest =
|
|
|
|
CGImageDestinationCreateWithData((CFMutableDataRef)encodedData, outputType, 1, NULL);
|
|
|
|
CGImageDestinationAddImageFromSource(dest, source, 0, NULL);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool successfullyConverted = CGImageDestinationFinalize(dest);
|
2007-09-17 22:02:50 +04:00
|
|
|
|
|
|
|
if (successfullyConverted) {
|
|
|
|
// Put the converted data in a form Gecko can understand
|
|
|
|
nsCOMPtr<nsIInputStream> byteStream;
|
2020-08-07 10:49:47 +03:00
|
|
|
NS_NewByteInputStream(getter_AddRefs(byteStream),
|
|
|
|
mozilla::Span((const char*)[encodedData bytes], [encodedData length]),
|
|
|
|
NS_ASSIGNMENT_COPY);
|
2019-01-21 20:18:16 +03:00
|
|
|
|
2018-11-20 20:00:09 +03:00
|
|
|
aTransferable->SetTransferData(flavorStr.get(), byteStream);
|
2007-09-17 22:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dest) CFRelease(dest);
|
|
|
|
if (source) CFRelease(source);
|
2019-01-21 20:18:16 +03:00
|
|
|
|
2007-09-17 22:02:50 +04:00
|
|
|
if (successfullyConverted)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
continue;
|
2007-07-03 11:16:19 +04:00
|
|
|
}
|
2017-05-23 07:23:38 +03:00
|
|
|
[pboardType release];
|
2007-07-03 11:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-18 20:30:59 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-06-27 09:26:18 +04:00
|
|
|
}
|
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, int32_t aWhichClipboard) {
|
2010-01-11 04:45:45 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2014-02-28 19:07:30 +04:00
|
|
|
if ((aWhichClipboard != kGlobalClipboard && aWhichClipboard != kFindClipboard) || !aTransferable)
|
2010-01-11 04:45:45 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2014-02-28 19:07:30 +04:00
|
|
|
NSPasteboard* cocoaPasteboard;
|
|
|
|
if (aWhichClipboard == kFindClipboard) {
|
|
|
|
cocoaPasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
|
|
|
|
} else {
|
|
|
|
cocoaPasteboard = [NSPasteboard generalPasteboard];
|
|
|
|
}
|
2010-01-11 04:45:45 +03:00
|
|
|
if (!cocoaPasteboard) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// get flavor list that includes all acceptable flavors (including ones obtained through
|
|
|
|
// conversion)
|
2018-10-10 23:25:54 +03:00
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
nsresult rv = aTransferable->FlavorsTransferableCanImport(flavors);
|
2010-01-11 04:45:45 +03:00
|
|
|
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// If we were the last ones to put something on the pasteboard, then just use the cached
|
|
|
|
// transferable. Otherwise clear it because it isn't relevant any more.
|
2014-06-26 05:29:50 +04:00
|
|
|
if (mCachedClipboard == aWhichClipboard && mChangeCount == [cocoaPasteboard changeCount]) {
|
2010-01-11 04:45:45 +03:00
|
|
|
if (mTransferable) {
|
2018-10-10 23:25:54 +03:00
|
|
|
for (uint32_t i = 0; i < flavors.Length(); i++) {
|
|
|
|
nsCString& flavorStr = flavors[i];
|
2010-01-11 04:45:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> dataSupports;
|
2018-11-20 19:59:56 +03:00
|
|
|
rv = mTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(dataSupports));
|
2010-01-11 04:45:45 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-11-20 20:00:09 +03:00
|
|
|
aTransferable->SetTransferData(flavorStr.get(), dataSupports);
|
2010-01-11 04:45:45 +03:00
|
|
|
return NS_OK; // maybe try to fill in more types? Is there a point?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 19:07:30 +04:00
|
|
|
} else {
|
2016-08-11 23:43:32 +03:00
|
|
|
EmptyClipboard(aWhichClipboard);
|
2010-01-11 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// at this point we can't satisfy the request from cache data so let's look
|
|
|
|
// for things other people put on the system clipboard
|
|
|
|
|
|
|
|
return nsClipboard::TransferableFromPasteboard(aTransferable, cocoaPasteboard);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2007-07-04 03:13:28 +04:00
|
|
|
// returns true if we have *any* of the passed in flavors available for pasting
|
2007-06-27 09:26:18 +04:00
|
|
|
NS_IMETHODIMP
|
2019-06-09 04:06:39 +03:00
|
|
|
nsClipboard::HasDataMatchingFlavors(const nsTArray<nsCString>& aFlavorList, int32_t aWhichClipboard,
|
|
|
|
bool* outResult) {
|
2008-02-18 20:30:59 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
*outResult = false;
|
2007-06-27 09:26:18 +04:00
|
|
|
|
2019-06-09 04:06:39 +03:00
|
|
|
if (aWhichClipboard != kGlobalClipboard) return NS_OK;
|
2007-06-27 09:26:18 +04:00
|
|
|
|
2007-07-04 03:13:28 +04:00
|
|
|
// first see if we have data for this in our cached transferable
|
2016-04-21 21:11:14 +03:00
|
|
|
if (mTransferable) {
|
2018-10-10 23:25:54 +03:00
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
nsresult rv = mTransferable->FlavorsTransferableCanImport(flavors);
|
2007-07-04 03:13:28 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-10-10 23:25:54 +03:00
|
|
|
for (uint32_t j = 0; j < flavors.Length(); j++) {
|
2018-10-17 19:21:55 +03:00
|
|
|
const nsCString& transferableFlavorStr = flavors[j];
|
2007-11-20 22:06:30 +03:00
|
|
|
|
2019-06-09 04:06:39 +03:00
|
|
|
for (uint32_t k = 0; k < aFlavorList.Length(); k++) {
|
2007-11-20 22:06:30 +03:00
|
|
|
if (transferableFlavorStr.Equals(aFlavorList[k])) {
|
2011-10-01 04:20:33 +04:00
|
|
|
*outResult = true;
|
2007-07-04 03:13:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 23:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
2007-07-04 03:13:28 +04:00
|
|
|
}
|
|
|
|
|
2007-06-27 09:26:18 +04:00
|
|
|
NSPasteboard* generalPBoard = [NSPasteboard generalPasteboard];
|
|
|
|
|
2019-06-09 04:06:39 +03:00
|
|
|
for (auto& mimeType : aFlavorList) {
|
2010-11-18 00:42:05 +03:00
|
|
|
NSString* pboardType = nil;
|
2008-11-07 04:08:35 +03:00
|
|
|
|
|
|
|
if (nsClipboard::IsStringType(mimeType, &pboardType)) {
|
|
|
|
NSString* availableType =
|
|
|
|
[generalPBoard availableTypeFromArray:[NSArray arrayWithObject:pboardType]];
|
|
|
|
if (availableType && [availableType isEqualToString:pboardType]) {
|
2011-10-01 04:20:33 +04:00
|
|
|
*outResult = true;
|
2007-11-20 22:06:30 +03:00
|
|
|
break;
|
2007-06-27 09:26:18 +04:00
|
|
|
}
|
2019-06-09 04:06:39 +03:00
|
|
|
} else if (mimeType.EqualsLiteral(kCustomTypesMime)) {
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* availableType = [generalPBoard
|
|
|
|
availableTypeFromArray:
|
2017-05-23 07:23:47 +03:00
|
|
|
[NSArray arrayWithObject:[UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]];
|
2016-04-21 21:11:14 +03:00
|
|
|
if (availableType) {
|
|
|
|
*outResult = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-06-09 04:06:39 +03:00
|
|
|
} else if (mimeType.EqualsLiteral(kJPEGImageMime) || mimeType.EqualsLiteral(kJPGImageMime) ||
|
|
|
|
mimeType.EqualsLiteral(kPNGImageMime) || mimeType.EqualsLiteral(kGIFImageMime)) {
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* availableType = [generalPBoard
|
|
|
|
availableTypeFromArray:
|
|
|
|
[NSArray arrayWithObjects:[UTIHelper stringFromPboardType:NSPasteboardTypeTIFF],
|
|
|
|
[UTIHelper stringFromPboardType:NSPasteboardTypePNG], nil]];
|
2007-11-20 22:06:30 +03:00
|
|
|
if (availableType) {
|
2011-10-01 04:20:33 +04:00
|
|
|
*outResult = true;
|
2007-11-20 22:06:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-05-23 07:23:38 +03:00
|
|
|
[pboardType release];
|
2007-06-27 09:26:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-18 20:30:59 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-06-27 09:26:18 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 19:07:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::SupportsFindClipboard(bool* _retval) {
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-03 11:16:19 +04:00
|
|
|
// This function converts anything that other applications might understand into the system format
|
|
|
|
// and puts it into a dictionary which it returns.
|
2007-06-27 09:26:18 +04:00
|
|
|
// static
|
|
|
|
NSDictionary* nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable) {
|
2008-02-18 20:30:59 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-06-27 09:26:18 +04:00
|
|
|
if (!aTransferable) return nil;
|
|
|
|
|
|
|
|
NSMutableDictionary* pasteboardOutputDict = [NSMutableDictionary dictionary];
|
2006-10-03 00:28:40 +04:00
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
nsTArray<nsCString> flavors;
|
|
|
|
nsresult rv = aTransferable->FlavorsTransferableCanExport(flavors);
|
2006-10-03 00:28:40 +04:00
|
|
|
if (NS_FAILED(rv)) return nil;
|
|
|
|
|
2018-10-10 23:25:54 +03:00
|
|
|
for (uint32_t i = 0; i < flavors.Length(); i++) {
|
|
|
|
nsCString& flavorStr = flavors[i];
|
2006-10-03 00:28:40 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sCocoaLog, LogLevel::Info,
|
|
|
|
("writing out clipboard data of type %s (%d)\n", flavorStr.get(), i));
|
2006-10-03 00:28:40 +04:00
|
|
|
|
2010-11-18 00:42:05 +03:00
|
|
|
NSString* pboardType = nil;
|
2008-11-07 04:08:35 +03:00
|
|
|
|
|
|
|
if (nsClipboard::IsStringType(flavorStr, &pboardType)) {
|
2007-07-03 11:16:19 +04:00
|
|
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
2018-11-20 19:59:56 +03:00
|
|
|
rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(genericDataWrapper));
|
2018-11-09 16:24:28 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
[pboardType release];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString data;
|
|
|
|
if (nsCOMPtr<nsISupportsString> text = do_QueryInterface(genericDataWrapper)) {
|
|
|
|
text->GetData(data);
|
|
|
|
}
|
2011-08-18 17:22:52 +04:00
|
|
|
|
|
|
|
NSString* nativeString;
|
2018-11-09 16:24:28 +03:00
|
|
|
if (!data.IsEmpty())
|
|
|
|
nativeString = [NSString stringWithCharacters:(const unichar*)data.get()
|
|
|
|
length:data.Length()];
|
2011-08-18 17:22:52 +04:00
|
|
|
else
|
|
|
|
nativeString = [NSString string];
|
2018-11-09 16:24:28 +03:00
|
|
|
|
2007-07-03 11:16:19 +04:00
|
|
|
// be nice to Carbon apps, normalize the receiver's contents using Form C.
|
|
|
|
nativeString = [nativeString precomposedStringWithCanonicalMapping];
|
2008-11-07 04:08:35 +03:00
|
|
|
|
|
|
|
[pasteboardOutputDict setObject:nativeString forKey:pboardType];
|
2016-04-21 21:11:14 +03:00
|
|
|
} else if (flavorStr.EqualsLiteral(kCustomTypesMime)) {
|
|
|
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
2018-11-20 19:59:56 +03:00
|
|
|
rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(genericDataWrapper));
|
2018-11-09 16:24:28 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString data;
|
|
|
|
if (nsCOMPtr<nsISupportsCString> text = do_QueryInterface(genericDataWrapper)) {
|
|
|
|
text->GetData(data);
|
|
|
|
}
|
2016-04-21 21:11:14 +03:00
|
|
|
|
2018-11-09 16:24:28 +03:00
|
|
|
if (!data.IsEmpty()) {
|
|
|
|
NSData* nativeData = [NSData dataWithBytes:data.get() length:data.Length()];
|
2017-05-23 07:23:47 +03:00
|
|
|
NSString* customType = [UTIHelper stringFromPboardType:kMozCustomTypesPboardType];
|
2017-05-23 07:23:38 +03:00
|
|
|
[pasteboardOutputDict setObject:nativeData forKey:customType];
|
2016-04-21 21:11:14 +03:00
|
|
|
}
|
2007-07-03 11:16:19 +04:00
|
|
|
} else if (flavorStr.EqualsLiteral(kPNGImageMime) || flavorStr.EqualsLiteral(kJPEGImageMime) ||
|
2012-06-11 03:44:50 +04:00
|
|
|
flavorStr.EqualsLiteral(kJPGImageMime) || flavorStr.EqualsLiteral(kGIFImageMime) ||
|
|
|
|
flavorStr.EqualsLiteral(kNativeImageMime)) {
|
2006-10-03 00:28:40 +04:00
|
|
|
nsCOMPtr<nsISupports> transferSupports;
|
2019-01-04 19:16:59 +03:00
|
|
|
rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(transferSupports));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-19 23:47:53 +03:00
|
|
|
|
2018-10-07 17:33:07 +03:00
|
|
|
nsCOMPtr<imgIContainer> image(do_QueryInterface(transferSupports));
|
2006-10-03 00:28:40 +04:00
|
|
|
if (!image) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
NS_WARNING("Image isn't an imgIContainer in transferable");
|
2006-10-03 00:28:40 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surface =
|
2019-09-03 18:36:23 +03:00
|
|
|
image->GetFrame(imgIContainer::FRAME_CURRENT,
|
|
|
|
imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY);
|
2014-03-08 05:21:24 +04:00
|
|
|
if (!surface) {
|
2013-03-06 03:39:48 +04:00
|
|
|
continue;
|
|
|
|
}
|
2010-03-13 17:39:55 +03:00
|
|
|
CGImageRef imageRef = NULL;
|
2015-09-12 06:32:37 +03:00
|
|
|
rv = nsCocoaUtils::CreateCGImageFromSurface(surface, &imageRef);
|
2010-03-13 17:39:55 +03:00
|
|
|
if (NS_FAILED(rv) || !imageRef) {
|
2006-10-03 00:28:40 +04:00
|
|
|
continue;
|
2010-03-13 17:39:55 +03:00
|
|
|
}
|
2015-09-12 06:32:37 +03:00
|
|
|
|
2008-02-06 09:22:51 +03:00
|
|
|
// Convert the CGImageRef to TIFF data.
|
|
|
|
CFMutableDataRef tiffData = CFDataCreateMutable(kCFAllocatorDefault, 0);
|
|
|
|
CGImageDestinationRef destRef =
|
|
|
|
CGImageDestinationCreateWithData(tiffData, CFSTR("public.tiff"), 1, NULL);
|
|
|
|
CGImageDestinationAddImage(destRef, imageRef, NULL);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool successfullyConverted = CGImageDestinationFinalize(destRef);
|
2008-02-06 09:22:51 +03:00
|
|
|
|
2007-08-30 06:10:32 +04:00
|
|
|
CGImageRelease(imageRef);
|
2008-02-06 09:22:51 +03:00
|
|
|
if (destRef) CFRelease(destRef);
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
if (!successfullyConverted) {
|
2008-02-06 09:22:51 +03:00
|
|
|
if (tiffData) CFRelease(tiffData);
|
|
|
|
continue;
|
|
|
|
}
|
2006-10-03 00:28:40 +04:00
|
|
|
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* tiffType = [UTIHelper stringFromPboardType:NSPasteboardTypeTIFF];
|
2016-12-20 22:33:08 +03:00
|
|
|
[pasteboardOutputDict setObject:(NSMutableData*)tiffData forKey:tiffType];
|
2008-02-06 09:22:51 +03:00
|
|
|
if (tiffData) CFRelease(tiffData);
|
2013-08-02 05:21:31 +04:00
|
|
|
} else if (flavorStr.EqualsLiteral(kFileMime)) {
|
|
|
|
nsCOMPtr<nsISupports> genericFile;
|
2018-11-20 19:59:56 +03:00
|
|
|
rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(genericFile));
|
2013-08-02 05:21:31 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file(do_QueryInterface(genericFile));
|
|
|
|
if (!file) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString fileURI;
|
|
|
|
rv = file->GetPath(fileURI);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString* str = nsCocoaUtils::ToNSString(fileURI);
|
2017-05-23 07:23:47 +03:00
|
|
|
NSURL* url = [NSURL fileURLWithPath:str isDirectory:NO];
|
|
|
|
NSString* fileUTType = [UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL];
|
|
|
|
[pasteboardOutputDict setObject:[url absoluteString] forKey:fileUTType];
|
2007-07-19 22:09:43 +04:00
|
|
|
} else if (flavorStr.EqualsLiteral(kFilePromiseMime)) {
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* urlPromise =
|
|
|
|
[UTIHelper stringFromPboardType:(NSString*)kPasteboardTypeFileURLPromise];
|
|
|
|
NSString* urlPromiseContent =
|
|
|
|
[UTIHelper stringFromPboardType:(NSString*)kPasteboardTypeFilePromiseContent];
|
2016-12-20 22:33:08 +03:00
|
|
|
[pasteboardOutputDict setObject:[NSArray arrayWithObject:@""] forKey:urlPromise];
|
2017-05-23 07:23:23 +03:00
|
|
|
[pasteboardOutputDict setObject:[NSArray arrayWithObject:@""] forKey:urlPromiseContent];
|
2007-09-25 00:43:01 +04:00
|
|
|
} else if (flavorStr.EqualsLiteral(kURLMime)) {
|
|
|
|
nsCOMPtr<nsISupports> genericURL;
|
2018-11-20 19:59:56 +03:00
|
|
|
rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(genericURL));
|
2007-09-25 00:43:01 +04:00
|
|
|
nsCOMPtr<nsISupportsString> urlObject(do_QueryInterface(genericURL));
|
|
|
|
|
|
|
|
nsAutoString url;
|
|
|
|
urlObject->GetData(url);
|
|
|
|
|
2017-05-26 18:45:28 +03:00
|
|
|
NSString* nativeTitle = nil;
|
|
|
|
|
|
|
|
// A newline embedded in the URL means that the form is actually URL +
|
|
|
|
// title. This embedding occurs in nsDragService::GetData.
|
|
|
|
int32_t newlinePos = url.FindChar(char16_t('\n'));
|
|
|
|
if (newlinePos >= 0) {
|
|
|
|
url.Truncate(newlinePos);
|
|
|
|
|
|
|
|
nsAutoString urlTitle;
|
|
|
|
urlObject->GetData(urlTitle);
|
2018-11-20 19:59:56 +03:00
|
|
|
urlTitle.Mid(urlTitle, newlinePos + 1, urlTitle.Length() - (newlinePos + 1));
|
2017-05-26 18:45:28 +03:00
|
|
|
|
|
|
|
nativeTitle =
|
|
|
|
[NSString stringWithCharacters:reinterpret_cast<const unichar*>(urlTitle.get())
|
|
|
|
length:urlTitle.Length()];
|
|
|
|
}
|
2017-05-23 07:23:33 +03:00
|
|
|
// The Finder doesn't like getting random binary data aka
|
|
|
|
// Unicode, so change it into an escaped URL containing only
|
|
|
|
// ASCII.
|
|
|
|
nsAutoCString utf8Data = NS_ConvertUTF16toUTF8(url.get(), url.Length());
|
|
|
|
nsAutoCString escData;
|
|
|
|
NS_EscapeURL(utf8Data.get(), utf8Data.Length(), esc_OnlyNonASCII | esc_AlwaysCopy, escData);
|
|
|
|
|
|
|
|
NSString* nativeURL = [NSString stringWithUTF8String:escData.get()];
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* publicUrl = [UTIHelper stringFromPboardType:kPublicUrlPboardType];
|
|
|
|
[pasteboardOutputDict setObject:nativeURL forKey:publicUrl];
|
2017-05-26 18:45:28 +03:00
|
|
|
if (nativeTitle) {
|
2017-05-23 07:23:33 +03:00
|
|
|
NSArray* urlsAndTitles = @[ @[ nativeURL ], @[ nativeTitle ] ];
|
2017-05-23 07:23:38 +03:00
|
|
|
NSString* urlName = [UTIHelper stringFromPboardType:kPublicUrlNamePboardType];
|
|
|
|
NSString* urlsWithTitles = [UTIHelper stringFromPboardType:kUrlsWithTitlesPboardType];
|
2017-05-23 07:23:33 +03:00
|
|
|
[pasteboardOutputDict setObject:nativeTitle forKey:urlName];
|
|
|
|
[pasteboardOutputDict setObject:urlsAndTitles forKey:urlsWithTitles];
|
2007-09-25 00:43:01 +04:00
|
|
|
}
|
|
|
|
}
|
2017-05-23 07:23:38 +03:00
|
|
|
[pboardType release];
|
2007-07-03 11:16:19 +04:00
|
|
|
// If it wasn't a type that we recognize as exportable we don't put it on the system
|
|
|
|
// clipboard. We'll just access it from our cached transferable when we need it.
|
2006-10-03 00:28:40 +04:00
|
|
|
}
|
|
|
|
|
2007-07-03 11:16:19 +04:00
|
|
|
return pasteboardOutputDict;
|
2008-02-18 20:30:59 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-10-03 00:28:40 +04:00
|
|
|
}
|
2008-11-07 04:08:35 +03:00
|
|
|
|
2017-05-23 07:23:38 +03:00
|
|
|
// aPasteboardType is being retained and needs to be released by the caller.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsClipboard::IsStringType(const nsCString& aMIMEType, NSString** aPasteboardType) {
|
2015-11-23 22:04:26 +03:00
|
|
|
if (aMIMEType.EqualsLiteral(kUnicodeMime)) {
|
2017-05-23 07:23:38 +03:00
|
|
|
*aPasteboardType = [[UTIHelper stringFromPboardType:NSPasteboardTypeString] retain];
|
2015-11-23 22:04:26 +03:00
|
|
|
return true;
|
|
|
|
} else if (aMIMEType.EqualsLiteral(kRTFMime)) {
|
2017-05-23 07:23:38 +03:00
|
|
|
*aPasteboardType = [[UTIHelper stringFromPboardType:NSPasteboardTypeRTF] retain];
|
2015-11-23 22:04:26 +03:00
|
|
|
return true;
|
|
|
|
} else if (aMIMEType.EqualsLiteral(kHTMLMime)) {
|
2017-05-23 07:23:38 +03:00
|
|
|
*aPasteboardType = [[UTIHelper stringFromPboardType:NSPasteboardTypeHTML] retain];
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2008-11-07 04:08:35 +03:00
|
|
|
} else {
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2008-11-07 04:08:35 +03:00
|
|
|
}
|
|
|
|
}
|
2009-01-01 17:26:16 +03:00
|
|
|
|
|
|
|
NSString* nsClipboard::WrapHtmlForSystemPasteboard(NSString* aString) {
|
|
|
|
NSString* wrapped = [NSString
|
|
|
|
stringWithFormat:@"<html>"
|
|
|
|
"<head>"
|
|
|
|
"<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"
|
|
|
|
"</head>"
|
|
|
|
"<body>"
|
|
|
|
"%@"
|
|
|
|
"</body>"
|
|
|
|
"</html>",
|
|
|
|
aString];
|
|
|
|
return wrapped;
|
|
|
|
}
|
2016-08-11 23:43:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the transferable object
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner,
|
|
|
|
int32_t aWhichClipboard) {
|
|
|
|
NS_ASSERTION(aTransferable, "clipboard given a null transferable");
|
|
|
|
|
|
|
|
if (aWhichClipboard == kSelectionCache) {
|
|
|
|
if (aTransferable) {
|
|
|
|
SetSelectionCache(aTransferable);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTransferable == mTransferable && anOwner == mClipboardOwner) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
bool selectClipPresent;
|
|
|
|
SupportsSelectionClipboard(&selectClipPresent);
|
|
|
|
bool findClipPresent;
|
|
|
|
SupportsFindClipboard(&findClipPresent);
|
|
|
|
if (!selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmptyClipboard(aWhichClipboard);
|
|
|
|
|
|
|
|
mClipboardOwner = anOwner;
|
|
|
|
mTransferable = aTransferable;
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (mTransferable) {
|
|
|
|
rv = SetNativeClipboardData(aWhichClipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the transferable object
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::GetData(nsITransferable* aTransferable, int32_t aWhichClipboard) {
|
|
|
|
NS_ASSERTION(aTransferable, "clipboard given a null transferable");
|
|
|
|
|
|
|
|
bool selectClipPresent;
|
|
|
|
SupportsSelectionClipboard(&selectClipPresent);
|
|
|
|
bool findClipPresent;
|
|
|
|
SupportsFindClipboard(&findClipPresent);
|
|
|
|
if (!selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (aTransferable) {
|
|
|
|
return GetNativeClipboardData(aTransferable, aWhichClipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::EmptyClipboard(int32_t aWhichClipboard) {
|
|
|
|
if (aWhichClipboard == kSelectionCache) {
|
|
|
|
ClearSelectionCache();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool selectClipPresent;
|
|
|
|
SupportsSelectionClipboard(&selectClipPresent);
|
|
|
|
bool findClipPresent;
|
|
|
|
SupportsFindClipboard(&findClipPresent);
|
|
|
|
if (!selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIgnoreEmptyNotification) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mClipboardOwner) {
|
|
|
|
mClipboardOwner->LosingOwnership(mTransferable);
|
|
|
|
mClipboardOwner = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTransferable = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::SupportsSelectionClipboard(bool* _retval) {
|
|
|
|
*_retval = false; // we don't support the selection clipboard by default.
|
|
|
|
return NS_OK;
|
2016-10-16 22:43:56 +03:00
|
|
|
}
|