From a320d71605005f8642fa96a660541a4e1b297b38 Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Fri, 27 Mar 2009 15:31:12 +0100 Subject: [PATCH] Bug 237944 - The name of Bookmark dragged from IE is the same as URL, r=enn sr=roc --- widget/src/windows/nsClipboard.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/widget/src/windows/nsClipboard.cpp b/widget/src/windows/nsClipboard.cpp index 5c3f1765db0..db7f8910163 100644 --- a/widget/src/windows/nsClipboard.cpp +++ b/widget/src/windows/nsClipboard.cpp @@ -758,16 +758,27 @@ nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, v const nsDependentString filepath(static_cast(*outData)); nsCOMPtr file; nsresult rv = NS_NewLocalFile(filepath, PR_TRUE, getter_AddRefs(file)); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { + nsMemory::Free(*outData); return dataFound; + } if ( IsInternetShortcut(filepath) ) { + nsMemory::Free(*outData); nsCAutoString url; ResolveShortcut( file, url ); if ( !url.IsEmpty() ) { // convert it to unicode and pass it out - nsMemory::Free(*outData); - *outData = UTF8ToNewUnicode(url); + nsDependentString urlString(UTF8ToNewUnicode(url)); + // the internal mozilla URL format, text/x-moz-url, contains + // URL\ntitle. We can guess the title from the file's name. + nsAutoString title; + file->GetLeafName(title); + // We rely on IsInternetShortcut check that file has a .url extension. + title.SetLength(title.Length() - 4); + if (title.IsEmpty()) + title = urlString; + *outData = ToNewUnicode(urlString + NS_LITERAL_STRING("\n") + title); *outDataLen = nsCRT::strlen(static_cast(*outData)) * sizeof(PRUnichar); dataFound = PR_TRUE;