Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: ui/base/dragdrop/os_exchange_data_provider_mac.mm

Issue 1235713004: mac: Fix os_exchange_data_provider_mac.mm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/dragdrop/os_exchange_data.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
12 #import "third_party/mozilla/NSPasteboard+Utils.h" 13 #import "third_party/mozilla/NSPasteboard+Utils.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 OSExchangeDataProviderMac::OSExchangeDataProviderMac() 18 OSExchangeDataProviderMac::OSExchangeDataProviderMac()
18 : pasteboard_([[NSPasteboard pasteboardWithUniqueName] retain]) { 19 : pasteboard_([[NSPasteboard pasteboardWithUniqueName] retain]) {
19 } 20 }
20 21
21 OSExchangeDataProviderMac::OSExchangeDataProviderMac(NSPasteboard* pasteboard) 22 OSExchangeDataProviderMac::OSExchangeDataProviderMac(NSPasteboard* pasteboard)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const OSExchangeData::CustomFormat& format, 66 const OSExchangeData::CustomFormat& format,
66 const base::Pickle& data) { 67 const base::Pickle& data) {
67 NSData* ns_data = [NSData dataWithBytes:data.data() length:data.size()]; 68 NSData* ns_data = [NSData dataWithBytes:data.data() length:data.size()];
68 [pasteboard_ setData:ns_data forType:format.ToNSString()]; 69 [pasteboard_ setData:ns_data forType:format.ToNSString()];
69 } 70 }
70 71
71 bool OSExchangeDataProviderMac::GetString(base::string16* data) const { 72 bool OSExchangeDataProviderMac::GetString(base::string16* data) const {
72 DCHECK(data); 73 DCHECK(data);
73 NSArray* items = [pasteboard_ readObjectsForClasses:@[ [NSString class] ] 74 NSArray* items = [pasteboard_ readObjectsForClasses:@[ [NSString class] ]
74 options:@{ }]; 75 options:@{ }];
75 if ([items count] == 0) 76
76 return false; 77 // There was no NSString, check for an NSURL.
78 if ([items count] == 0) {
79 GURL url;
80 base::string16 title;
81 bool result =
82 GetURLAndTitle(OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &title);
83 if (result)
84 *data = base::UTF8ToUTF16(url.spec());
85 return result;
86 }
77 87
78 *data = base::SysNSStringToUTF16([items objectAtIndex:0]); 88 *data = base::SysNSStringToUTF16([items objectAtIndex:0]);
79 return true; 89 return true;
80 } 90 }
81 91
82 bool OSExchangeDataProviderMac::GetURLAndTitle( 92 bool OSExchangeDataProviderMac::GetURLAndTitle(
83 OSExchangeData::FilenameToURLPolicy policy, 93 OSExchangeData::FilenameToURLPolicy policy,
84 GURL* url, 94 GURL* url,
85 base::string16* title) const { 95 base::string16* title) const {
86 DCHECK(url); 96 DCHECK(url);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 170
161 /////////////////////////////////////////////////////////////////////////////// 171 ///////////////////////////////////////////////////////////////////////////////
162 // OSExchangeData, public: 172 // OSExchangeData, public:
163 173
164 // static 174 // static
165 OSExchangeData::Provider* OSExchangeData::CreateProvider() { 175 OSExchangeData::Provider* OSExchangeData::CreateProvider() {
166 return new OSExchangeDataProviderMac; 176 return new OSExchangeDataProviderMac;
167 } 177 }
168 178
169 } // namespace ui 179 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/dragdrop/os_exchange_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698