Bug 1001851 - Fall back to saving temp files if other file pickers fail. r=rnewman, a=lsblakk
authorWes Johnston <wjohnston@mozilla.com>
Mon, 19 May 2014 15:49:09 -0700
changeset 199341 67145b77ac8476e3d65d3a87d893ee8c5030c5d7
parent 199340 2c7882800cdd322de35efc4d06b324ce635f9f9e
child 199342 d74b6d5766d426d054b3d9f20000dc2fb7643b45
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lsblakk
bugs1001851
milestone31.0a2
Bug 1001851 - Fall back to saving temp files if other file pickers fail. r=rnewman, a=lsblakk
mobile/android/base/FilePickerResultHandler.java
--- a/mobile/android/base/FilePickerResultHandler.java
+++ b/mobile/android/base/FilePickerResultHandler.java
@@ -27,17 +27,16 @@ import android.text.TextUtils;
 import android.text.format.Time;
 import android.util.Log;
 import android.os.Process;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.IOException;
-import java.util.Queue;
 
 class FilePickerResultHandler implements ActivityResultHandler {
     private static final String LOGTAG = "GeckoFilePickerResultHandler";
     private static final String UPLOADS_DIR = "uploads";
 
     protected final FilePicker.ResultHandler handler;
     private final int tabId;
     private final File cacheDir;
@@ -139,20 +138,36 @@ class FilePickerResultHandler implements
                                     null,  // selectionArgs
                                     null); // sortOrder
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
             if (cursor.moveToFirst()) {
                 String res = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
+
+                // Some pickers (the KitKat Documents one for instance) won't return a temporary file here.
+                // Fall back to the normal FileLoader if we didn't find anything.
+                if (TextUtils.isEmpty(res)) {
+                    tryFileLoaderCallback();
+                    return;
+                }
+
                 sendResult(res);
+            } else {
+                tryFileLoaderCallback();
             }
         }
 
+        private void tryFileLoaderCallback() {
+            final FragmentActivity fa = (FragmentActivity) GeckoAppShell.getGeckoInterface().getActivity();
+            final LoaderManager lm = fa.getSupportLoaderManager();
+            lm.initLoader(uri.hashCode(), null, new FileLoaderCallbacks(uri));
+        }
+
         @Override
         public void onLoaderReset(Loader<Cursor> loader) { }
     }
 
     private class FileLoaderCallbacks implements LoaderCallbacks<Cursor>,
                                                  Tabs.OnTabsChangedListener {
         final private Uri uri;
         private String tempFile;