Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/pickle.h" | |
| 11 #include "base/strings/sys_string_conversions.h" | |
| 12 #import "third_party/mozilla/NSPasteboard+Utils.h" | |
| 13 #import "ui/base/dragdrop/cocoa_dnd_util.h" | |
| 14 #include "url/gurl.h" | |
| 8 | 15 |
| 9 namespace ui { | 16 namespace ui { |
| 10 | 17 |
| 11 OSExchangeDataProviderMac::OSExchangeDataProviderMac() { | 18 OSExchangeDataProviderMac::OSExchangeDataProviderMac() |
| 19 : pasteboard_([[NSPasteboard pasteboardWithUniqueName] retain]) { | |
| 20 } | |
| 21 | |
| 22 OSExchangeDataProviderMac::OSExchangeDataProviderMac(NSPasteboard* pasteboard) | |
| 23 : pasteboard_([pasteboard retain]) { | |
| 12 } | 24 } |
| 13 | 25 |
| 14 OSExchangeDataProviderMac::~OSExchangeDataProviderMac() { | 26 OSExchangeDataProviderMac::~OSExchangeDataProviderMac() { |
| 15 } | 27 } |
| 16 | 28 |
| 17 OSExchangeData::Provider* OSExchangeDataProviderMac::Clone() const { | 29 OSExchangeData::Provider* OSExchangeDataProviderMac::Clone() const { |
| 18 NOTIMPLEMENTED(); | 30 return new OSExchangeDataProviderMac(pasteboard_); |
| 19 return new OSExchangeDataProviderMac(); | |
| 20 } | 31 } |
| 21 | 32 |
| 22 void OSExchangeDataProviderMac::MarkOriginatedFromRenderer() { | 33 void OSExchangeDataProviderMac::MarkOriginatedFromRenderer() { |
| 23 NOTIMPLEMENTED(); | 34 NOTIMPLEMENTED(); |
| 24 } | 35 } |
| 25 | 36 |
| 26 bool OSExchangeDataProviderMac::DidOriginateFromRenderer() const { | 37 bool OSExchangeDataProviderMac::DidOriginateFromRenderer() const { |
| 27 NOTIMPLEMENTED(); | 38 NOTIMPLEMENTED(); |
| 28 return false; | 39 return false; |
| 29 } | 40 } |
| 30 | 41 |
| 31 void OSExchangeDataProviderMac::SetString(const base::string16& string) { | 42 void OSExchangeDataProviderMac::SetString(const base::string16& string) { |
| 32 NOTIMPLEMENTED(); | 43 [pasteboard_ writeObjects:@[ base::SysUTF16ToNSString(string) ]]; |
| 33 } | 44 } |
| 34 | 45 |
| 35 void OSExchangeDataProviderMac::SetURL(const GURL& url, | 46 void OSExchangeDataProviderMac::SetURL(const GURL& url, |
| 36 const base::string16& title) { | 47 const base::string16& title) { |
| 37 NOTIMPLEMENTED(); | 48 [pasteboard_ setDataForURL:base::SysUTF8ToNSString(url.spec()) |
| 49 title:base::SysUTF16ToNSString(title)]; | |
| 38 } | 50 } |
| 39 | 51 |
| 40 void OSExchangeDataProviderMac::SetFilename(const base::FilePath& path) { | 52 void OSExchangeDataProviderMac::SetFilename(const base::FilePath& path) { |
| 41 NOTIMPLEMENTED(); | 53 NOTIMPLEMENTED(); |
| 42 } | 54 } |
| 43 | 55 |
| 44 void OSExchangeDataProviderMac::SetFilenames( | 56 void OSExchangeDataProviderMac::SetFilenames( |
| 45 const std::vector<FileInfo>& filenames) { | 57 const std::vector<FileInfo>& filenames) { |
| 46 NOTIMPLEMENTED(); | 58 NOTIMPLEMENTED(); |
| 47 } | 59 } |
| 48 | 60 |
| 49 void OSExchangeDataProviderMac::SetPickledData( | 61 void OSExchangeDataProviderMac::SetPickledData( |
| 50 const OSExchangeData::CustomFormat& format, | 62 const OSExchangeData::CustomFormat& format, |
| 51 const Pickle& data) { | 63 const Pickle& data) { |
| 52 NOTIMPLEMENTED(); | 64 NSData* ns_data = [NSData dataWithBytes:data.data() length:data.size()]; |
| 65 [pasteboard_ setData:ns_data forType:format.ToNSString()]; | |
| 53 } | 66 } |
| 54 | 67 |
| 55 bool OSExchangeDataProviderMac::GetString(base::string16* data) const { | 68 bool OSExchangeDataProviderMac::GetString(base::string16* data) const { |
| 56 NOTIMPLEMENTED(); | 69 DCHECK(data); |
| 57 return false; | 70 NSArray* items = [pasteboard_ readObjectsForClasses:@[ [NSString class] ] |
| 71 options:@{ }]; | |
| 72 if ([items count] == 0) | |
| 73 return false; | |
| 74 | |
| 75 *data = base::SysNSStringToUTF16([items lastObject]); | |
| 76 return true; | |
| 58 } | 77 } |
| 59 | 78 |
| 60 bool OSExchangeDataProviderMac::GetURLAndTitle( | 79 bool OSExchangeDataProviderMac::GetURLAndTitle( |
| 61 OSExchangeData::FilenameToURLPolicy policy, | 80 OSExchangeData::FilenameToURLPolicy policy, |
| 62 GURL* url, | 81 GURL* url, |
| 63 base::string16* title) const { | 82 base::string16* title) const { |
| 64 NOTIMPLEMENTED(); | 83 return PopulateURLAndTitleFromPasteboard( |
| 65 return false; | 84 url, title, pasteboard_, policy == OSExchangeData::CONVERT_FILENAMES); |
| 66 } | 85 } |
| 67 | 86 |
| 68 bool OSExchangeDataProviderMac::GetFilename(base::FilePath* path) const { | 87 bool OSExchangeDataProviderMac::GetFilename(base::FilePath* path) const { |
| 69 NOTIMPLEMENTED(); | 88 NOTIMPLEMENTED(); |
| 70 return false; | 89 return false; |
| 71 } | 90 } |
| 72 | 91 |
| 73 bool OSExchangeDataProviderMac::GetFilenames( | 92 bool OSExchangeDataProviderMac::GetFilenames( |
| 74 std::vector<FileInfo>* filenames) const { | 93 std::vector<FileInfo>* filenames) const { |
| 75 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
| 76 return false; | 95 return false; |
| 77 } | 96 } |
| 78 | 97 |
| 79 bool OSExchangeDataProviderMac::GetPickledData( | 98 bool OSExchangeDataProviderMac::GetPickledData( |
| 80 const OSExchangeData::CustomFormat& format, | 99 const OSExchangeData::CustomFormat& format, |
| 81 Pickle* data) const { | 100 Pickle* data) const { |
| 82 NOTIMPLEMENTED(); | 101 DCHECK(data); |
| 83 return false; | 102 NSData* ns_data = [pasteboard_ dataForType:format.ToNSString()]; |
| 103 if (!ns_data) | |
| 104 return false; | |
|
tapted
2014/07/07 23:39:13
nit: linebreak after conditional ( http://www.chro
tapted
2014/07/07 23:42:11
(actually that link is probably just to say ~"don'
Andre
2014/07/08 00:12:02
Done.
| |
| 105 *data = Pickle(static_cast<const char*>([ns_data bytes]), [ns_data length]); | |
| 106 return true; | |
| 84 } | 107 } |
| 85 | 108 |
| 86 bool OSExchangeDataProviderMac::HasString() const { | 109 bool OSExchangeDataProviderMac::HasString() const { |
| 87 NOTIMPLEMENTED(); | 110 NSArray* classes = @[ [NSString class] ]; |
| 88 return false; | 111 return [pasteboard_ canReadObjectForClasses:classes options:nil]; |
| 89 } | 112 } |
| 90 | 113 |
| 91 bool OSExchangeDataProviderMac::HasURL( | 114 bool OSExchangeDataProviderMac::HasURL( |
| 92 OSExchangeData::FilenameToURLPolicy policy) const { | 115 OSExchangeData::FilenameToURLPolicy policy) const { |
| 93 NOTIMPLEMENTED(); | 116 GURL url; |
| 94 return false; | 117 base::string16 title; |
| 118 return GetURLAndTitle(policy, &url, &title); | |
| 95 } | 119 } |
| 96 | 120 |
| 97 bool OSExchangeDataProviderMac::HasFile() const { | 121 bool OSExchangeDataProviderMac::HasFile() const { |
| 98 NOTIMPLEMENTED(); | 122 NOTIMPLEMENTED(); |
| 99 return false; | 123 return false; |
| 100 } | 124 } |
| 101 | 125 |
| 102 bool OSExchangeDataProviderMac::HasCustomFormat( | 126 bool OSExchangeDataProviderMac::HasCustomFormat( |
| 103 const OSExchangeData::CustomFormat& format) const { | 127 const OSExchangeData::CustomFormat& format) const { |
| 104 NOTIMPLEMENTED(); | 128 return [[pasteboard_ types] containsObject:format.ToNSString()]; |
| 105 return false; | |
| 106 } | 129 } |
| 107 | 130 |
| 108 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 109 // OSExchangeData, public: | 132 // OSExchangeData, public: |
| 110 | 133 |
| 111 // static | 134 // static |
| 112 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 135 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
| 113 return new OSExchangeDataProviderMac; | 136 return new OSExchangeDataProviderMac; |
| 114 } | 137 } |
| 115 | 138 |
| 116 } // namespace ui | 139 } // namespace ui |
| OLD | NEW |