diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-26 06:00:23 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-06-26 06:00:23 -0700 |
commit | 2402143eddeb5773bdf7e9c74fe7f4412692775b (patch) | |
tree | f05c8f661083229ce248c2cd7009d0bf1d52510d /WebKit | |
parent | 6829e61782ddf72e8dae812e0e5a0b91614d257b (diff) | |
parent | 3c5348b2ac92d2472149fad08c81c09fa6f43824 (diff) | |
download | external_webkit-2402143eddeb5773bdf7e9c74fe7f4412692775b.zip external_webkit-2402143eddeb5773bdf7e9c74fe7f4412692775b.tar.gz external_webkit-2402143eddeb5773bdf7e9c74fe7f4412692775b.tar.bz2 |
Merge change 5139
* changes:
Implement fullscreen video. Currently only load() and play() are supported. The rest of the MediaPlayerPrivate functionality will be added in a later CL.
Diffstat (limited to 'WebKit')
-rw-r--r-- | WebKit/Android.mk | 1 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp | 265 |
2 files changed, 266 insertions, 0 deletions
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 |