Bug 646550 - Tell Android to scan media items downloaded by Fennec r=blassey

This commit is contained in:
Wes Johnston 2011-04-08 10:52:13 -07:00
parent 85a845c09c
commit 738d5a3dc0
4 changed files with 64 additions and 1 deletions

View File

@ -59,6 +59,8 @@ import android.widget.*;
import android.hardware.*;
import android.location.*;
import android.webkit.MimeTypeMap;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.util.*;
import android.net.Uri;
@ -119,6 +121,31 @@ public class GeckoAppShell
}
}
private static class GeckoMediaScannerClient implements MediaScannerConnectionClient {
private String mFile = "";
private String mMimeType = "";
private MediaScannerConnection mScanner = null;
public GeckoMediaScannerClient(Context aContext, String aFile, String aMimeType) {
mFile = aFile;
mMimeType = aMimeType;
mScanner = new MediaScannerConnection(aContext, this);
if (mScanner != null)
mScanner.connect();
}
public void onMediaScannerConnected() {
mScanner.scanFile(mFile, mMimeType);
}
public void onScanCompleted(String path, Uri uri) {
if(path.equals(mFile)) {
mScanner.disconnect();
mScanner = null;
}
}
}
// Get a Handler for the main java thread
public static Handler getMainHandler() {
return GeckoApp.mAppContext.mMainHandler;
@ -1065,4 +1092,9 @@ public class GeckoAppShell
} catch (InterruptedException ie) {}
}
}
public static void scanMedia(String aFile, String aMimeType) {
Context context = GeckoApp.surfaceView.getContext();
GeckoMediaScannerClient client = new GeckoMediaScannerClient(context, aFile, aMimeType);
}
}

View File

@ -80,6 +80,10 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
#ifdef ANDROID
#include "AndroidBridge.h"
#endif
#define DOWNLOAD_MANAGER_BUNDLE "chrome://mozapps/locale/downloads/downloads.properties"
#define DOWNLOAD_MANAGER_ALERT_ICON "chrome://mozapps/skin/downloads/downloadIcon.png"
#define PREF_BDM_SHOWALERTONCOMPLETE "browser.download.manager.showAlertOnComplete"
@ -2239,7 +2243,7 @@ nsDownload::SetState(DownloadState aState)
}
}
#if (defined(XP_WIN) && !defined(WINCE)) || defined(XP_MACOSX)
#if (defined(XP_WIN) && !defined(WINCE)) || defined(XP_MACOSX) || defined(ANDROID)
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mTarget);
nsCOMPtr<nsIFile> file;
nsAutoString path;
@ -2272,6 +2276,16 @@ nsDownload::SetState(DownloadState aState)
::CFNotificationCenterPostNotification(center, CFSTR("com.apple.DownloadFileFinished"),
observedObject, NULL, TRUE);
::CFRelease(observedObject);
#endif
#ifdef ANDROID
nsCOMPtr<nsIMIMEInfo> mimeInfo;
nsCAutoString contentType;
GetMIMEInfo(getter_AddRefs(mimeInfo));
if (mimeInfo)
mimeInfo->GetMIMEType(contentType);
mozilla::AndroidBridge::Bridge()->ScanMedia(path, contentType);
#endif
}

View File

@ -134,6 +134,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
jIsNetworkLinkUp = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isNetworkLinkUp", "()Z");
jIsNetworkLinkKnown = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isNetworkLinkKnown", "()Z");
jSetSelectedLocale = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setSelectedLocale", "(Ljava/lang/String;)V");
jScanMedia = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scanMedia", "(Ljava/lang/String;Ljava/lang/String;)V");
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
@ -784,3 +785,16 @@ jclass GetGeckoAppShellClass()
{
return mozilla::AndroidBridge::GetGeckoAppShellClass();
}
void
AndroidBridge::ScanMedia(const nsAString& aFile, const nsACString& aMimeType)
{
jstring jstrFile = mJNIEnv->NewString(nsPromiseFlatString(aFile).get(), aFile.Length());
nsString mimeType2;
CopyUTF8toUTF16(aMimeType, mimeType2);
jstring jstrMimeTypes = mJNIEnv->NewString(nsPromiseFlatString(mimeType2).get(), mimeType2.Length());
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jScanMedia, jstrFile, jstrMimeTypes);
}

View File

@ -224,6 +224,8 @@ public:
void SetKeepScreenOn(bool on);
void ScanMedia(const nsAString& aFile, const nsACString& aMimeType);
protected:
static AndroidBridge *sBridge;
@ -278,6 +280,7 @@ protected:
jmethodID jIsNetworkLinkUp;
jmethodID jIsNetworkLinkKnown;
jmethodID jSetSelectedLocale;
jmethodID jScanMedia;
// stuff we need for CallEglCreateWindowSurface
jclass jEGLSurfaceImplClass;