OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ui/base/dragdrop/cocoa_dnd_util.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/sys_string_conversions.h" |
| 9 #include "googleurl/src/gurl.h" |
| 10 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 BOOL PopulateURLAndTitleFromPasteboard(GURL* url, |
| 15 string16* title, |
| 16 NSPasteboard* pboard, |
| 17 BOOL convert_filenames) { |
| 18 CHECK(url); |
| 19 |
| 20 // Bail out early if there's no URL data. |
| 21 if (![pboard containsURLData]) |
| 22 return NO; |
| 23 |
| 24 // -getURLs:andTitles:convertingFilenames: will already validate URIs so we |
| 25 // don't need to again. The arrays returned are both of NSStrings. |
| 26 NSArray* url_array = nil; |
| 27 NSArray* title_array = nil; |
| 28 [pboard getURLs:&url_array andTitles:&title_array |
| 29 convertingFilenames:convert_filenames]; |
| 30 DCHECK_EQ([url_array count], [title_array count]); |
| 31 // It's possible that no URLs were actually provided! |
| 32 if (![url_array count]) |
| 33 return NO; |
| 34 NSString* url_string = [url_array objectAtIndex:0]; |
| 35 if ([url_string length]) { |
| 36 // Check again just to make sure to not assign NULL into a std::string, |
| 37 // which throws an exception. |
| 38 const char* utf8_url = [url_string UTF8String]; |
| 39 if (utf8_url) { |
| 40 *url = GURL(utf8_url); |
| 41 // Extra paranoia check. |
| 42 if (title && [title_array count]) |
| 43 *title = base::SysNSStringToUTF16([title_array objectAtIndex:0]); |
| 44 } |
| 45 } |
| 46 return YES; |
| 47 } |
| 48 |
| 49 } // namespace ui |
OLD | NEW |