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 192409 46b4808e08dea6ace1458edb4a4059169abfb5e0
parent 192408 aef210a74b6914c1e09b0e0eb35b4ad6efdc4986
child 192410 73da1997e6da948b7f32bb7b9060a025b23bff27
push id3606
push userryanvm@gmail.com
push dateThu, 29 May 2014 13:29:41 +0000
treeherdermozilla-beta@46b4808e08de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lsblakk
bugs1001851
milestone30.0
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;