summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--WebCore/Android.mk1
-rw-r--r--WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.cpp164
-rw-r--r--WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h11
-rw-r--r--WebKit/Android.mk1
-rw-r--r--WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp265
5 files changed, 277 insertions, 165 deletions
diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index c6be03c..182c0a7 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -714,7 +714,6 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
platform/graphics/android/ImageAndroid.cpp \
platform/graphics/android/ImageBufferAndroid.cpp \
platform/graphics/android/ImageSourceAndroid.cpp \
- platform/graphics/android/MediaPlayerPrivateAndroid.cpp \
platform/graphics/android/PathAndroid.cpp \
platform/graphics/android/PatternAndroid.cpp \
platform/graphics/android/PlatformGraphicsContext.cpp \
diff --git a/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.cpp b/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.cpp
deleted file mode 100644
index 75bb578..0000000
--- a/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright 2009, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if ENABLE(VIDEO)
-
-#include "MediaPlayerPrivateAndroid.h"
-
-namespace WebCore {
-
-void MediaPlayerPrivate::registerMediaEngine(MediaEngineRegistrar registrar)
-{
- registrar(create, getSupportedTypes, supportsType);
-}
-
-void MediaPlayerPrivate::load(const String& url)
-{
-}
-
-void MediaPlayerPrivate::cancelLoad()
-{
-}
-
-void MediaPlayerPrivate::play()
-{
-}
-
-void MediaPlayerPrivate::pause()
-{
-}
-
-IntSize MediaPlayerPrivate::naturalSize() const
-{
- return IntSize();
-}
-
-bool MediaPlayerPrivate::hasVideo() const
-{
- return false;
-}
-
-void MediaPlayerPrivate::setVisible(bool)
-{
-}
-
-float MediaPlayerPrivate::duration() const
-{
- return 0;
-}
-
-float MediaPlayerPrivate::currentTime() const
-{
- return 0;
-}
-
-void MediaPlayerPrivate::seek(float time)
-{
-}
-
-bool MediaPlayerPrivate::seeking() const
-{
- return false;
-}
-
-void MediaPlayerPrivate::setEndTime(float time)
-{
-}
-
-void MediaPlayerPrivate::setRate(float)
-{
-}
-
-bool MediaPlayerPrivate::paused() const
-{
- return false;
-}
-
-void MediaPlayerPrivate::setVolume(float)
-{
-}
-
-MediaPlayer::NetworkState MediaPlayerPrivate::networkState() const
-{
- return MediaPlayer::Empty;
-}
-
-MediaPlayer::ReadyState MediaPlayerPrivate::readyState() const
-{
- return MediaPlayer::HaveNothing;
-}
-
-float MediaPlayerPrivate::maxTimeSeekable() const
-{
- return 0;
-}
-
-float MediaPlayerPrivate::maxTimeBuffered() const
-{
- return 0;
-}
-
-int MediaPlayerPrivate::dataRate() const
-{
- return 0;
-}
-
-unsigned MediaPlayerPrivate::totalBytes() const
-{
- return 0;
-}
-
-unsigned MediaPlayerPrivate::bytesLoaded() const
-{
- return 0;
-}
-
-void MediaPlayerPrivate::setSize(const IntSize&)
-{
-}
-
-void MediaPlayerPrivate::paint(GraphicsContext*, const IntRect&)
-{
-}
-
-MediaPlayerPrivateInterface* MediaPlayerPrivate::create(MediaPlayer* player)
-{
- return new MediaPlayerPrivate();
-}
-
-void MediaPlayerPrivate::getSupportedTypes(HashSet<String>&)
-{
-}
-
-MediaPlayer::SupportsType MediaPlayerPrivate::supportsType(const String& type, const String& codecs)
-{
- return MediaPlayer::IsNotSupported;
-}
-
-}
-
-#endif // VIDEO
diff --git a/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h b/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h
index 9324699..7dcb60d 100644
--- a/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h
+++ b/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h
@@ -34,6 +34,8 @@ namespace WebCore {
class MediaPlayerPrivate : public MediaPlayerPrivateInterface {
public:
+ ~MediaPlayerPrivate();
+
static void registerMediaEngine(MediaEngineRegistrar);
virtual void load(const String& url);
@@ -77,9 +79,18 @@ public:
virtual void paint(GraphicsContext*, const IntRect&);
private:
+ // Android-specific methods and fields.
static MediaPlayerPrivateInterface* create(MediaPlayer* player);
static void getSupportedTypes(HashSet<String>&);
static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs);
+
+ MediaPlayerPrivate(MediaPlayer *);
+ void createJavaPlayerIfNeeded();
+
+ MediaPlayer* m_player;
+ String m_url;
+ struct JavaGlue;
+ JavaGlue* m_glue;
};
} // namespace WebCore
diff --git a/WebKit/Android.mk b/WebKit/Android.mk
index 87bc2cd..95eb0e1 100644
--- a/WebKit/Android.mk
+++ b/WebKit/Android.mk
@@ -21,6 +21,7 @@ LOCAL_SRC_FILES := \
android/WebCoreSupport/DragClientAndroid.cpp \
android/WebCoreSupport/EditorClientAndroid.cpp \
android/WebCoreSupport/FrameLoaderClientAndroid.cpp \
+ android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp \
\
android/RenderSkinAndroid.cpp \
android/RenderSkinButton.cpp \
diff --git a/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp b/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp
new file mode 100644
index 0000000..b815dd8
--- /dev/null
+++ b/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp
@@ -0,0 +1,265 @@
+/*
+ * Copyright 2009, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(VIDEO)
+
+#include "MediaPlayerPrivateAndroid.h"
+#include "WebCoreJni.h"
+#include "WebViewCore.h"
+#include "jni_utility.h"
+
+#include <JNIHelp.h>
+
+using namespace android;
+
+namespace WebCore {
+
+static const char* g_ProxyJavaClass = "android/webkit/HTML5VideoViewProxy";
+
+struct MediaPlayerPrivate::JavaGlue
+{
+ jobject m_javaProxy;
+ jmethodID m_getInstance;
+ jmethodID m_play;
+};
+
+MediaPlayerPrivate::~MediaPlayerPrivate()
+{
+ if (m_glue->m_javaProxy) {
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ if (env)
+ env->DeleteGlobalRef(m_glue->m_javaProxy);
+ }
+
+ delete m_glue;
+}
+
+void MediaPlayerPrivate::registerMediaEngine(MediaEngineRegistrar registrar)
+{
+ registrar(create, getSupportedTypes, supportsType);
+}
+
+void MediaPlayerPrivate::load(const String& url)
+{
+ // To be able to create our java player, we need a Context object. To get
+ // the Context object, we need a WebViewCore java object. To get a java
+ // WebViewCore object, we need a WebCore::FrameView pointer. To get
+ // the FrameView pointer, the MediaPlayer::setFrameView() must have been
+ // called. However, that method is called only after the MediaPlayerClient
+ // is called back and informed that enough data has been loaded.
+ // We therefore need to fake a readyStateChanged callback before creating
+ // the java player.
+ m_player->readyStateChanged();
+ // We now have a RenderVideo created and the MediaPlayer must have
+ // been updated with a FrameView. Create our JavaPlayer.
+ createJavaPlayerIfNeeded();
+ // Save the URl.
+ m_url = url;
+}
+
+void MediaPlayerPrivate::cancelLoad()
+{
+}
+
+void MediaPlayerPrivate::play()
+{
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ if (!env || !m_glue->m_javaProxy || !m_url.length())
+ return;
+
+ FrameView* frameView = m_player->frameView();
+ if (!frameView)
+ return;
+
+ WebViewCore* webViewCore = WebViewCore::getWebViewCore(frameView);
+ ASSERT(webViewCore);
+ jstring jUrl = env->NewString((unsigned short *)m_url.characters(), m_url.length());
+ env->CallVoidMethod(m_glue->m_javaProxy, m_glue->m_play, jUrl, webViewCore->getJavaObject().get());
+ env->DeleteLocalRef(jUrl);
+ checkException(env);
+}
+
+void MediaPlayerPrivate::pause()
+{
+}
+
+IntSize MediaPlayerPrivate::naturalSize() const
+{
+ return IntSize(20, 20);
+}
+
+bool MediaPlayerPrivate::hasVideo() const
+{
+ return false;
+}
+
+void MediaPlayerPrivate::setVisible(bool)
+{
+}
+
+float MediaPlayerPrivate::duration() const
+{
+ return 100;
+}
+
+float MediaPlayerPrivate::currentTime() const
+{
+ return 0;
+}
+
+void MediaPlayerPrivate::seek(float time)
+{
+}
+
+bool MediaPlayerPrivate::seeking() const
+{
+ return false;
+}
+
+void MediaPlayerPrivate::setEndTime(float time)
+{
+}
+
+void MediaPlayerPrivate::setRate(float)
+{
+}
+
+bool MediaPlayerPrivate::paused() const
+{
+ return true;
+}
+
+void MediaPlayerPrivate::setVolume(float)
+{
+}
+
+MediaPlayer::NetworkState MediaPlayerPrivate::networkState() const
+{
+ return MediaPlayer::Loaded;
+}
+
+MediaPlayer::ReadyState MediaPlayerPrivate::readyState() const
+{
+ return MediaPlayer::HaveEnoughData;
+}
+
+float MediaPlayerPrivate::maxTimeSeekable() const
+{
+ return 0;
+}
+
+float MediaPlayerPrivate::maxTimeBuffered() const
+{
+ return 0;
+}
+
+int MediaPlayerPrivate::dataRate() const
+{
+ return 0;
+}
+
+unsigned MediaPlayerPrivate::totalBytes() const
+{
+ return 0;
+}
+
+unsigned MediaPlayerPrivate::bytesLoaded() const
+{
+ return 0;
+}
+
+void MediaPlayerPrivate::setSize(const IntSize&)
+{
+}
+
+void MediaPlayerPrivate::paint(GraphicsContext*, const IntRect&)
+{
+}
+
+MediaPlayerPrivateInterface* MediaPlayerPrivate::create(MediaPlayer* player)
+{
+ return new MediaPlayerPrivate(player);
+}
+
+void MediaPlayerPrivate::getSupportedTypes(HashSet<String>&)
+{
+}
+
+MediaPlayer::SupportsType MediaPlayerPrivate::supportsType(const String& type, const String& codecs)
+{
+ return MediaPlayer::IsNotSupported;
+}
+
+MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player) : m_player(player), m_glue(NULL)
+{
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ if (!env)
+ return;
+
+ jclass clazz = env->FindClass(g_ProxyJavaClass);
+ if (!clazz)
+ return;
+
+ m_glue = new JavaGlue;
+ m_glue->m_getInstance = env->GetStaticMethodID(clazz, "getInstance", "(Landroid/webkit/WebViewCore;)Landroid/webkit/HTML5VideoViewProxy;");
+ m_glue->m_play = env->GetMethodID(clazz, "play", "(Ljava/lang/String;Landroid/webkit/WebViewCore;)V");
+ m_glue->m_javaProxy = NULL;
+ env->DeleteLocalRef(clazz);
+ // An exception is raised if any of the above fails.
+ checkException(env);
+}
+
+void MediaPlayerPrivate::createJavaPlayerIfNeeded()
+{
+ // Check if we have been already created.
+ if (m_glue->m_javaProxy)
+ return;
+
+ FrameView* frameView = m_player->frameView();
+ if (!frameView)
+ return;
+
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ if (!env)
+ return;
+
+ jclass clazz = env->FindClass(g_ProxyJavaClass);
+ if (!clazz)
+ return;
+
+ WebViewCore* webViewCore = WebViewCore::getWebViewCore(frameView);
+ ASSERT(webViewCore);
+ jobject obj = env->CallStaticObjectMethod(clazz, m_glue->m_getInstance, webViewCore->getJavaObject().get());
+ m_glue->m_javaProxy = env->NewGlobalRef(obj);
+ env->DeleteLocalRef(obj);
+ env->DeleteLocalRef(clazz);
+ checkException(env);
+}
+
+}
+
+#endif // VIDEO