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

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

Issue 8418033: Push one function from the Mac drag/drop util code to ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/dragdrop/cocoa_dnd_util.h ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « ui/base/dragdrop/cocoa_dnd_util.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698