Bug 428876: ondrop gets wrong results when dragging multiple files, patch by Michael Ventnor <ventnor.bugzilla@yahoo.com.au>, r+sr=roc, a=beltzner
authorgavin@gavinsharp.com
Wed, 16 Apr 2008 13:29:06 -0700
changeset 14400 7b8b7b1bfa886d4190cad926f73c05174210add7
parent 14399 d1806f24cfa946798b10b4a1d5e87dab84b869a0
child 14401 6f71381d08e9b7ca3db5e76ac01f552c3314f4fd
push idunknown
push userunknown
push dateunknown
reviewersbeltzner
bugs428876
milestone1.9pre
Bug 428876: ondrop gets wrong results when dragging multiple files, patch by Michael Ventnor <ventnor.bugzilla@yahoo.com.au>, r+sr=roc, a=beltzner
widget/src/gtk2/nsDragService.cpp
--- a/widget/src/gtk2/nsDragService.cpp
+++ b/widget/src/gtk2/nsDragService.cpp
@@ -461,32 +461,39 @@ nsDragService::GetData(nsITransferable *
 
                 // Dragging and dropping from the file manager would cause us to parse the source text as a
                 // nsILocalFile URL.
                 if ( strcmp(flavorStr, kFileMime) == 0 ) {
                     gdkFlavor = gdk_atom_intern(kTextMime, FALSE);
                     GetTargetDragData(gdkFlavor);
                     if (mTargetDragData) {
                         const char* text = static_cast<char*>(mTargetDragData);
-                        NS_ConvertUTF8toUTF16 fileUrl = NS_ConvertUTF8toUTF16(text);
-                        if (StringBeginsWith(fileUrl, NS_LITERAL_STRING("file://")))
-                            fileUrl.Cut(0, strlen("file://"));
+                        PRUnichar* convertedText = nsnull;
+                        PRInt32 convertedTextLen = 0;
 
-                        // Sometimes there are linebreaks in the file URLs. Yes, linebreaks in the file URLs.
-                        fileUrl.StripChars("\r\n");
+                        GetTextUriListItem(text, mTargetDragDataLen, aItemIndex,
+                                           &convertedText, &convertedTextLen);
+
+                        if (convertedText) {
+                            nsDependentString fileUrl = nsDependentString(convertedText);
+                            if (StringBeginsWith(fileUrl, NS_LITERAL_STRING("file://")))
+                                fileUrl.Cut(0, strlen("file://"));
 
-                        nsCOMPtr<nsILocalFile> file;
-                        nsresult rv = NS_NewLocalFile(fileUrl, PR_TRUE, getter_AddRefs(file));
-                        if (NS_SUCCEEDED(rv)) {
-                            // The common wrapping code at the end of this function assumes the data is text
-                            // and calls text-specific operations.
-                            // Make a secret hideout here for nsILocalFile objects and return early.
-                            aTransferable->SetTransferData(flavorStr, file,
-                                                           fileUrl.Length() * sizeof(PRUnichar));
-                            return NS_OK;
+                            nsCOMPtr<nsILocalFile> file;
+                            nsresult rv = NS_NewLocalFile(fileUrl, PR_TRUE, getter_AddRefs(file));
+                            if (NS_SUCCEEDED(rv)) {
+                                // The common wrapping code at the end of this function assumes the data is text
+                                // and calls text-specific operations.
+                                // Make a secret hideout here for nsILocalFile objects and return early.
+                                aTransferable->SetTransferData(flavorStr, file,
+                                                               fileUrl.Length() * sizeof(PRUnichar));
+                                g_free(convertedText);
+                                return NS_OK;
+                            }
+                            g_free(convertedText);
                         }
                         continue;
                     }
                 }
 
                 // if we are looking for text/unicode and we fail to find it
                 // on the clipboard first, try again with text/plain. If that
                 // is present, convert it to unicode.