Bug 812412 - replace full path with leaf name only, r=dougt
authorEric Chou <echou@mozilla.com>
Wed, 21 Nov 2012 15:53:19 +0800
changeset 113870 2a35b6fb48d7bfc3310f2457e6f56340ec61c194
parent 113869 d03453c186e9ffa6cefc61230d601f0f817bb57c
child 113871 0dc53785ef12e59f2a5fdcb4f2087edfacf9e60e
push id23893
push userryanvm@gmail.com
push dateThu, 22 Nov 2012 00:50:15 +0000
treeherdermozilla-central@20ec9014f220 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs812412
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 812412 - replace full path with leaf name only, r=dougt
dom/bluetooth/BluetoothOppManager.cpp
--- a/dom/bluetooth/BluetoothOppManager.cpp
+++ b/dom/bluetooth/BluetoothOppManager.cpp
@@ -18,16 +18,17 @@
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsIDOMFile.h"
 #include "nsIFile.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
+#include "nsLocalFile.h"
 #include "nsNetUtil.h"
 
 #define TARGET_FOLDER "/sdcard/downloads/bluetooth/"
 
 USING_BLUETOOTH_NAMESPACE
 using namespace mozilla;
 using namespace mozilla::ipc;
 
@@ -271,24 +272,32 @@ BluetoothOppManager::SendFile(BlobParent
   if (mBlob) {
     // Means there's a sending process. Reply error.
     return false;
   }
 
   /*
    * Process of sending a file:
    *  - Keep blob because OPP connection has not been established yet.
+   *  - Try to retrieve file name from the blob or assign one if failed to get.
    *  - Create an OPP connection by SendConnectRequest()
    *  - After receiving the response, start to read file and send.
    */
   mBlob = aActor->GetBlob();
 
-  nsCOMPtr<nsIDOMFile> file = do_QueryInterface(mBlob);
-  if (file) {
-    file->GetName(sFileName);
+  nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(mBlob);
+  nsString fullPath;
+
+  if (domFile && NS_SUCCEEDED(domFile->GetMozFullPathInternal(fullPath))) {
+    nsCOMPtr<nsIFile> localFile = new nsLocalFile();
+    NS_NewLocalFile(fullPath, false, getter_AddRefs(localFile));
+
+    if (localFile) {
+      localFile->GetLeafName(sFileName);
+    }
   }
 
   if (sFileName.IsEmpty()) {
     sFileName.AssignLiteral("Unknown");
   }
 
   SendConnectRequest();