From: Andrei Popescu Date: Tue, 15 Sep 2009 12:09:27 +0000 (+0100) Subject: Add poster support and other fixes X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=2471bb64;p=android-x86%2Fexternal-webkit.git Add poster support and other fixes --- diff --git a/WebCore/html/HTMLMediaElement.cpp b/WebCore/html/HTMLMediaElement.cpp index b2e642882..17a3110a5 100644 --- a/WebCore/html/HTMLMediaElement.cpp +++ b/WebCore/html/HTMLMediaElement.cpp @@ -554,7 +554,15 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType) updateVolume(); m_player->load(m_currentSrc, contentType); - + +#if PLATFORM(ANDROID) + if (isVideo() && m_player->canLoadPoster()) { + KURL posterUrl = static_cast(this)->poster(); + if (!posterUrl.isEmpty()) + m_player->setPoster(posterUrl); + } +#endif + if (renderer()) renderer()->updateFromElement(); } diff --git a/WebCore/platform/graphics/MediaPlayer.cpp b/WebCore/platform/graphics/MediaPlayer.cpp index 6205a7b67..15815dce6 100644 --- a/WebCore/platform/graphics/MediaPlayer.cpp +++ b/WebCore/platform/graphics/MediaPlayer.cpp @@ -104,6 +104,11 @@ public: virtual void paint(GraphicsContext*, const IntRect&) { } +#if PLATFORM(ANDROID) + virtual bool canLoadPoster() const { return false; } + virtual void setPoster(const String&) { } +#endif + #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) virtual void setPoster(const String& /*url*/) { } virtual void deliverNotification(MediaPlayerProxyNotificationType) { } @@ -253,11 +258,18 @@ void MediaPlayer::load(const String& url, const ContentType& contentType) m_private.set(createNullMediaPlayer(this)); } -#if ENABLE(PLUGIN_PROXY_FOR_VIDEO) +#if PLATFORM(ANDROID) +bool MediaPlayer::canLoadPoster() const +{ + return m_private->canLoadPoster(); +} +#endif + +#if ENABLE(PLUGIN_PROXY_FOR_VIDEO) || PLATFORM(ANDROID) void MediaPlayer::setPoster(const String& url) { m_private->setPoster(url); -} +} #endif void MediaPlayer::cancelLoad() diff --git a/WebCore/platform/graphics/MediaPlayer.h b/WebCore/platform/graphics/MediaPlayer.h index 7f5f2a04b..1cb7625ec 100644 --- a/WebCore/platform/graphics/MediaPlayer.h +++ b/WebCore/platform/graphics/MediaPlayer.h @@ -184,6 +184,11 @@ public: MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; } +#if PLATFORM(ANDROID) + bool canLoadPoster() const; + void setPoster(const String&); +#endif + #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) void setPoster(const String& url); void deliverNotification(MediaPlayerProxyNotificationType notification); diff --git a/WebCore/platform/graphics/MediaPlayerPrivate.h b/WebCore/platform/graphics/MediaPlayerPrivate.h index 6d1359b35..ba0f4b063 100644 --- a/WebCore/platform/graphics/MediaPlayerPrivate.h +++ b/WebCore/platform/graphics/MediaPlayerPrivate.h @@ -92,6 +92,11 @@ public: virtual void setAutobuffer(bool) { }; +#if PLATFORM(ANDROID) + virtual bool canLoadPoster() const { return false; } + virtual void setPoster(const String&) { } +#endif + #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) virtual void setPoster(const String& url) = 0; virtual void deliverNotification(MediaPlayerProxyNotificationType) = 0; diff --git a/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h b/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h index 7dcb60d6d..1dbd20bf9 100644 --- a/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h +++ b/WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h @@ -77,6 +77,9 @@ public: virtual void setSize(const IntSize&); + virtual bool canLoadPoster() const { return true; } + virtual void setPoster(const String&); + virtual void paint(GraphicsContext*, const IntRect&); private: // Android-specific methods and fields. diff --git a/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp b/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp index 2465e29e4..d6362d0ae 100644 --- a/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp +++ b/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp @@ -47,6 +47,7 @@ struct MediaPlayerPrivate::JavaGlue jmethodID m_createView; jmethodID m_attachView; jmethodID m_removeView; + jmethodID m_setPoster; }; MediaPlayerPrivate::~MediaPlayerPrivate() @@ -99,8 +100,6 @@ void MediaPlayerPrivate::play() 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); env->DeleteLocalRef(jUrl); @@ -200,6 +199,17 @@ void MediaPlayerPrivate::setSize(const IntSize&) { } +void MediaPlayerPrivate::setPoster(const String& url) +{ + JNIEnv* env = JSC::Bindings::getJNIEnv(); + if (!env) + return; + jstring jUrl = env->NewString((unsigned short *)url.characters(), url.length()); + env->CallVoidMethod(m_glue->m_javaProxy, m_glue->m_setPoster, jUrl); + env->DeleteLocalRef(jUrl); + checkException(env); +} + void MediaPlayerPrivate::paint(GraphicsContext*, const IntRect& r) { createJavaPlayerIfNeeded(); @@ -242,6 +252,7 @@ MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player) : m_player(player), m_glue->m_createView = env->GetMethodID(clazz, "createView", "()V"); m_glue->m_attachView = env->GetMethodID(clazz, "attachView", "(IIII)V"); m_glue->m_removeView = env->GetMethodID(clazz, "removeView", "()V"); + m_glue->m_setPoster = env->GetMethodID(clazz, "loadPoster", "(Ljava/lang/String;)V"); m_glue->m_javaProxy = NULL; env->DeleteLocalRef(clazz); // An exception is raised if any of the above fails.