Chromium Code Reviews| Index: ui/base/dragdrop/os_exchange_data_provider_mac.mm |
| diff --git a/ui/base/dragdrop/os_exchange_data_provider_mac.mm b/ui/base/dragdrop/os_exchange_data_provider_mac.mm |
| index e8e60c3942cffd1546e946adb97e493d73a49765..8afb9c07fcb03a0c02271589dd5532531f047045 100644 |
| --- a/ui/base/dragdrop/os_exchange_data_provider_mac.mm |
| +++ b/ui/base/dragdrop/os_exchange_data_provider_mac.mm |
| @@ -4,19 +4,30 @@ |
| #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
| +#import <Cocoa/Cocoa.h> |
| + |
| #include "base/logging.h" |
| +#include "base/pickle.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#import "third_party/mozilla/NSPasteboard+Utils.h" |
| +#import "ui/base/dragdrop/cocoa_dnd_util.h" |
| +#include "url/gurl.h" |
| namespace ui { |
| -OSExchangeDataProviderMac::OSExchangeDataProviderMac() { |
| +OSExchangeDataProviderMac::OSExchangeDataProviderMac() |
| + : pasteboard_([[NSPasteboard pasteboardWithUniqueName] retain]) { |
| +} |
| + |
| +OSExchangeDataProviderMac::OSExchangeDataProviderMac(NSPasteboard* pasteboard) |
| + : pasteboard_([pasteboard retain]) { |
| } |
| OSExchangeDataProviderMac::~OSExchangeDataProviderMac() { |
| } |
| OSExchangeData::Provider* OSExchangeDataProviderMac::Clone() const { |
| - NOTIMPLEMENTED(); |
| - return new OSExchangeDataProviderMac(); |
| + return new OSExchangeDataProviderMac(pasteboard_); |
| } |
| void OSExchangeDataProviderMac::MarkOriginatedFromRenderer() { |
| @@ -29,12 +40,13 @@ bool OSExchangeDataProviderMac::DidOriginateFromRenderer() const { |
| } |
| void OSExchangeDataProviderMac::SetString(const base::string16& string) { |
| - NOTIMPLEMENTED(); |
| + [pasteboard_ writeObjects:@[ base::SysUTF16ToNSString(string) ]]; |
| } |
| void OSExchangeDataProviderMac::SetURL(const GURL& url, |
| const base::string16& title) { |
| - NOTIMPLEMENTED(); |
| + [pasteboard_ setDataForURL:base::SysUTF8ToNSString(url.spec()) |
| + title:base::SysUTF16ToNSString(title)]; |
| } |
| void OSExchangeDataProviderMac::SetFilename(const base::FilePath& path) { |
| @@ -49,20 +61,27 @@ void OSExchangeDataProviderMac::SetFilenames( |
| void OSExchangeDataProviderMac::SetPickledData( |
| const OSExchangeData::CustomFormat& format, |
| const Pickle& data) { |
| - NOTIMPLEMENTED(); |
| + NSData* ns_data = [NSData dataWithBytes:data.data() length:data.size()]; |
| + [pasteboard_ setData:ns_data forType:format.ToNSString()]; |
| } |
| bool OSExchangeDataProviderMac::GetString(base::string16* data) const { |
| - NOTIMPLEMENTED(); |
| - return false; |
| + DCHECK(data); |
| + NSArray* items = [pasteboard_ readObjectsForClasses:@[ [NSString class] ] |
| + options:nil]; |
|
tapted
2014/07/03 07:01:50
should options be @[ ]? -- i.e. an empty array ra
Andre
2014/07/07 18:29:05
Done.
Passing nil as options is pretty common in C
|
| + if (!items || [items count] < 1) |
|
tapted
2014/07/03 07:01:50
optional nit: I'd probably go with `if ([items cou
Andre
2014/07/07 18:29:05
Done.
|
| + return false; |
| + |
| + *data = base::SysNSStringToUTF16([items lastObject]); |
|
dcheng
2014/07/03 05:44:16
Why lastObject?
Andre
2014/07/07 18:29:05
items is a 1 element array at this point, so lastO
dcheng
2014/07/07 18:42:18
I guess as a reader, I would usually expect to see
Andre
2014/07/07 20:10:51
I agree, however firstObject is a relatively late
dcheng
2014/07/09 00:26:35
I have a very very slight preference for objectAtI
Andre
2014/07/10 03:54:28
Done.
|
| + return true; |
| } |
|
tapted
2014/07/03 07:01:50
clipboard_util_win.cc seems to fallback to URL as
Andre
2014/07/07 18:29:05
I'm not sure, OSExchangeDataProviderAura does not
tapted
2014/07/07 23:39:13
sg
|
| bool OSExchangeDataProviderMac::GetURLAndTitle( |
| OSExchangeData::FilenameToURLPolicy policy, |
| GURL* url, |
| base::string16* title) const { |
| - NOTIMPLEMENTED(); |
| - return false; |
| + return PopulateURLAndTitleFromPasteboard( |
| + url, title, pasteboard_, policy == OSExchangeData::CONVERT_FILENAMES); |
| } |
| bool OSExchangeDataProviderMac::GetFilename(base::FilePath* path) const { |
| @@ -79,19 +98,19 @@ bool OSExchangeDataProviderMac::GetFilenames( |
| bool OSExchangeDataProviderMac::GetPickledData( |
| const OSExchangeData::CustomFormat& format, |
| Pickle* data) const { |
| - NOTIMPLEMENTED(); |
| - return false; |
| + NSData* ns_data = [pasteboard_ dataForType:format.ToNSString()]; |
|
tapted
2014/07/03 07:01:50
dataForType can return nil in some cases (e.g. tim
Andre
2014/07/07 18:29:05
Done.
|
| + *data = Pickle(static_cast<const char*>([ns_data bytes]), [ns_data length]); |
| + return true; |
| } |
| bool OSExchangeDataProviderMac::HasString() const { |
| - NOTIMPLEMENTED(); |
| - return false; |
| + NSArray* classes = @[ [NSString class] ]; |
| + return [pasteboard_ canReadObjectForClasses:classes options:nil]; |
| } |
| bool OSExchangeDataProviderMac::HasURL( |
| OSExchangeData::FilenameToURLPolicy policy) const { |
| - NOTIMPLEMENTED(); |
| - return false; |
| + return [pasteboard_ containsURLData]; |
|
dcheng
2014/07/03 05:44:16
As currently written, won't there be situations wh
Andre
2014/07/07 18:29:05
Possibly, are you referring to the CONVERT_FILENAM
dcheng
2014/07/07 18:42:18
Yes. The simplest solution is to forward the argum
Andre
2014/07/07 20:10:51
Done.
|
| } |
| bool OSExchangeDataProviderMac::HasFile() const { |
| @@ -101,8 +120,7 @@ bool OSExchangeDataProviderMac::HasFile() const { |
| bool OSExchangeDataProviderMac::HasCustomFormat( |
| const OSExchangeData::CustomFormat& format) const { |
| - NOTIMPLEMENTED(); |
| - return false; |
| + return [[pasteboard_ types] containsObject:format.ToNSString()]; |
| } |
| /////////////////////////////////////////////////////////////////////////////// |