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

Unified 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, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/dragdrop/cocoa_dnd_util.h ('k') | ui/ui.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/dragdrop/cocoa_dnd_util.mm
diff --git a/ui/base/dragdrop/cocoa_dnd_util.mm b/ui/base/dragdrop/cocoa_dnd_util.mm
new file mode 100644
index 0000000000000000000000000000000000000000..4ad0ad5be7870271b2f4b20664811c599da92db3
--- /dev/null
+++ b/ui/base/dragdrop/cocoa_dnd_util.mm
@@ -0,0 +1,49 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/base/dragdrop/cocoa_dnd_util.h"
+
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+#include "googleurl/src/gurl.h"
+#import "third_party/mozilla/NSPasteboard+Utils.h"
+
+namespace ui {
+
+BOOL PopulateURLAndTitleFromPasteboard(GURL* url,
+ string16* title,
+ NSPasteboard* pboard,
+ BOOL convert_filenames) {
+ CHECK(url);
+
+ // Bail out early if there's no URL data.
+ if (![pboard containsURLData])
+ return NO;
+
+ // -getURLs:andTitles:convertingFilenames: will already validate URIs so we
+ // don't need to again. The arrays returned are both of NSStrings.
+ NSArray* url_array = nil;
+ NSArray* title_array = nil;
+ [pboard getURLs:&url_array andTitles:&title_array
+ convertingFilenames:convert_filenames];
+ DCHECK_EQ([url_array count], [title_array count]);
+ // It's possible that no URLs were actually provided!
+ if (![url_array count])
+ return NO;
+ NSString* url_string = [url_array objectAtIndex:0];
+ if ([url_string length]) {
+ // Check again just to make sure to not assign NULL into a std::string,
+ // which throws an exception.
+ const char* utf8_url = [url_string UTF8String];
+ if (utf8_url) {
+ *url = GURL(utf8_url);
+ // Extra paranoia check.
+ if (title && [title_array count])
+ *title = base::SysNSStringToUTF16([title_array objectAtIndex:0]);
+ }
+ }
+ return YES;
+}
+
+} // namespace ui
« 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