| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "ui/base/dragdrop/cocoa_dnd_util.h" | 5 #import "ui/base/dragdrop/cocoa_dnd_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #import "third_party/mozilla/NSPasteboard+Utils.h" | 9 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 | 13 |
| 14 NSString* const kChromeDragDummyPboardType = @"org.chromium.drag-dummy-type"; | 14 NSString* const kChromeDragDummyPboardType = @"org.chromium.drag-dummy-type"; |
| 15 | 15 |
| 16 NSString* const kChromeDragImageHTMLPboardType = @"org.chromium.image-html"; | 16 NSString* const kChromeDragImageHTMLPboardType = @"org.chromium.image-html"; |
| 17 | 17 |
| 18 BOOL PopulateURLAndTitleFromPasteboard(GURL* url, | 18 BOOL PopulateURLAndTitleFromPasteboard(GURL* url, |
| 19 base::string16* title, | 19 base::string16* title, |
| 20 NSPasteboard* pboard, | 20 NSPasteboard* pboard, |
| 21 BOOL convert_filenames) { | 21 BOOL convert_filenames) { |
| 22 CHECK(url); | 22 CHECK(url); |
| 23 | 23 |
| 24 // Bail out early if there's no URL data. | 24 // Bail out early if there's no URL data. |
| 25 if (![pboard containsURLData]) | 25 if (![pboard containsURLDataConvertingTextToURL:YES]) |
| 26 return NO; | 26 return NO; |
| 27 | 27 |
| 28 // -getURLs:andTitles:convertingFilenames: will already validate URIs so we | 28 // -getURLs:andTitles:convertingFilenames: will already validate URIs so we |
| 29 // don't need to again. The arrays returned are both of NSStrings. | 29 // don't need to again. The arrays returned are both of NSStrings. |
| 30 NSArray* url_array = nil; | 30 NSArray* url_array = nil; |
| 31 NSArray* title_array = nil; | 31 NSArray* title_array = nil; |
| 32 [pboard getURLs:&url_array andTitles:&title_array | 32 [pboard getURLs:&url_array |
| 33 convertingFilenames:convert_filenames]; | 33 andTitles:&title_array |
| 34 convertingFilenames:convert_filenames |
| 35 convertingTextToURL:YES]; |
| 34 DCHECK_EQ([url_array count], [title_array count]); | 36 DCHECK_EQ([url_array count], [title_array count]); |
| 35 // It's possible that no URLs were actually provided! | 37 // It's possible that no URLs were actually provided! |
| 36 if (![url_array count]) | 38 if (![url_array count]) |
| 37 return NO; | 39 return NO; |
| 38 NSString* url_string = [url_array objectAtIndex:0]; | 40 NSString* url_string = [url_array objectAtIndex:0]; |
| 39 if ([url_string length]) { | 41 if ([url_string length]) { |
| 40 // Check again just to make sure to not assign NULL into a std::string, | 42 // Check again just to make sure to not assign NULL into a std::string, |
| 41 // which throws an exception. | 43 // which throws an exception. |
| 42 const char* utf8_url = [url_string UTF8String]; | 44 const char* utf8_url = [url_string UTF8String]; |
| 43 if (utf8_url) { | 45 if (utf8_url) { |
| 44 *url = GURL(utf8_url); | 46 *url = GURL(utf8_url); |
| 45 // Extra paranoia check. | 47 // Extra paranoia check. |
| 46 if (title && [title_array count]) | 48 if (title && [title_array count]) |
| 47 *title = base::SysNSStringToUTF16([title_array objectAtIndex:0]); | 49 *title = base::SysNSStringToUTF16([title_array objectAtIndex:0]); |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 return YES; | 52 return YES; |
| 51 } | 53 } |
| 52 | 54 |
| 53 } // namespace ui | 55 } // namespace ui |
| OLD | NEW |