Replace access ot HTMLMediaElement from MediaPlayerPrivateBlackBerry with...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2012 16:52:20 +0000 (16:52 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2012 16:52:20 +0000 (16:52 +0000)
        Reviewed by Eric Carlson.

        Code standard compliance - no functional change, so no new tests required.

        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::mediaPlayerExitFullscreen):
        (WebCore):
        (WebCore::HTMLMediaElement::mediaPlayerIsVideo):
        (WebCore::HTMLMediaElement::mediaPlayerContentBoxRect):
        (WebCore::HTMLMediaElement::mediaPlayerSetSize):
        (WebCore::HTMLMediaElement::mediaPlayerPause):
        (WebCore::HTMLMediaElement::mediaPlayerPlay):
        (WebCore::HTMLMediaElement::mediaPlayerIsPaused):
        (WebCore::HTMLMediaElement::mediaPlayerHostWindow):
        (WebCore::HTMLMediaElement::mediaPlayerWindowClipRect):
        * html/HTMLMediaElement.h:
        (HTMLMediaElement):
        * platform/graphics/MediaPlayer.h:
        (WebCore):
        (WebCore::MediaPlayerClient::mediaPlayerExitFullscreen):
        (WebCore::MediaPlayerClient::mediaPlayerIsVideo):
        (WebCore::MediaPlayerClient::mediaPlayerContentBoxRect):
        (WebCore::MediaPlayerClient::mediaPlayerSetSize):
        (WebCore::MediaPlayerClient::mediaPlayerPause):
        (WebCore::MediaPlayerClient::mediaPlayerPlay):
        (WebCore::MediaPlayerClient::mediaPlayerIsPaused):
        (WebCore::MediaPlayerClient::mediaPlayerHostWindow):
        (WebCore::MediaPlayerClient::mediaPlayerWindowClipRect):
        * platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp:
        (WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
        (WebCore::MediaPlayerPrivate::load):
        (WebCore::MediaPlayerPrivate::paint):
        (WebCore::MediaPlayerPrivate::resizeSourceDimensions):
        (WebCore::MediaPlayerPrivate::updateStates):
        (WebCore::MediaPlayerPrivate::onPauseStateChanged):
        (WebCore::MediaPlayerPrivate::onPlayNotified):
        (WebCore::MediaPlayerPrivate::onPauseNotified):
        (WebCore::MediaPlayerPrivate::onAuthenticationNeeded):
        (WebCore::MediaPlayerPrivate::showErrorDialog):
        (WebCore::MediaPlayerPrivate::platformWindow):
        (WebCore::MediaPlayerPrivate::isElementPaused):
        (WebCore::MediaPlayerPrivate::isTabVisible):
        * platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h:
        (MediaPlayerPrivate):

Patch by John Griggs <jgriggs@rim.com> on 2012-08-23

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126441 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp
Source/WebCore/platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h

index b52a704..9ae311c 100644 (file)
@@ -1,3 +1,52 @@
+2012-08-23  John Griggs  <jgriggs@rim.com>
+
+                Replace access ot HTMLMediaElement from MediaPlayerPrivateBlackBerry with methods in MediaPlayerClient - updated with notes from initial reviews.  https://bugs.webkit.org/show_bug.cgi?id=84291
+
+                Reviewed by Eric Carlson.
+
+                Code standard compliance - no functional change, so no new tests required.
+
+                * html/HTMLMediaElement.cpp:
+                (WebCore::HTMLMediaElement::mediaPlayerExitFullscreen):
+                (WebCore):
+                (WebCore::HTMLMediaElement::mediaPlayerIsVideo):
+                (WebCore::HTMLMediaElement::mediaPlayerContentBoxRect):
+                (WebCore::HTMLMediaElement::mediaPlayerSetSize):
+                (WebCore::HTMLMediaElement::mediaPlayerPause):
+                (WebCore::HTMLMediaElement::mediaPlayerPlay):
+                (WebCore::HTMLMediaElement::mediaPlayerIsPaused):
+                (WebCore::HTMLMediaElement::mediaPlayerHostWindow):
+                (WebCore::HTMLMediaElement::mediaPlayerWindowClipRect):
+                * html/HTMLMediaElement.h:
+                (HTMLMediaElement):
+                * platform/graphics/MediaPlayer.h:
+                (WebCore):
+                (WebCore::MediaPlayerClient::mediaPlayerExitFullscreen):
+                (WebCore::MediaPlayerClient::mediaPlayerIsVideo):
+                (WebCore::MediaPlayerClient::mediaPlayerContentBoxRect):
+                (WebCore::MediaPlayerClient::mediaPlayerSetSize):
+                (WebCore::MediaPlayerClient::mediaPlayerPause):
+                (WebCore::MediaPlayerClient::mediaPlayerPlay):
+                (WebCore::MediaPlayerClient::mediaPlayerIsPaused):
+                (WebCore::MediaPlayerClient::mediaPlayerHostWindow):
+                (WebCore::MediaPlayerClient::mediaPlayerWindowClipRect):
+                * platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.cpp:
+                (WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
+                (WebCore::MediaPlayerPrivate::load):
+                (WebCore::MediaPlayerPrivate::paint):
+                (WebCore::MediaPlayerPrivate::resizeSourceDimensions):
+                (WebCore::MediaPlayerPrivate::updateStates):
+                (WebCore::MediaPlayerPrivate::onPauseStateChanged):
+                (WebCore::MediaPlayerPrivate::onPlayNotified):
+                (WebCore::MediaPlayerPrivate::onPauseNotified):
+                (WebCore::MediaPlayerPrivate::onAuthenticationNeeded):
+                (WebCore::MediaPlayerPrivate::showErrorDialog):
+                (WebCore::MediaPlayerPrivate::platformWindow):
+                (WebCore::MediaPlayerPrivate::isElementPaused):
+                (WebCore::MediaPlayerPrivate::isTabVisible):
+                * platform/graphics/blackberry/MediaPlayerPrivateBlackBerry.h:
+                (MediaPlayerPrivate):
+
 2012-08-23  John Mellor  <johnme@chromium.org>
 
         Text Autosizing: Multiply large fonts less, as they are already more legible.
index ffb3089..02a5645 100644 (file)
@@ -4377,6 +4377,54 @@ String HTMLMediaElement::mediaPlayerDocumentHost() const
     return document()->url().host();
 }
 
+void HTMLMediaElement::mediaPlayerExitFullscreen()
+{
+    exitFullscreen();
+}
+
+bool HTMLMediaElement::mediaPlayerIsVideo() const
+{
+    return isVideo();
+}
+
+LayoutRect HTMLMediaElement::mediaPlayerContentBoxRect() const
+{
+    if (renderer())
+        return renderer()->enclosingBox()->contentBoxRect();
+    return LayoutRect();
+}
+
+void HTMLMediaElement::mediaPlayerSetSize(const IntSize& size)
+{
+    setAttribute(widthAttr, String::number(size.width()));
+    setAttribute(heightAttr, String::number(size.height()));
+}
+
+void HTMLMediaElement::mediaPlayerPause()
+{
+    pause();
+}
+
+void HTMLMediaElement::mediaPlayerPlay()
+{
+    play();
+}
+
+bool HTMLMediaElement::mediaPlayerIsPaused() const
+{
+    return paused();
+}
+
+HostWindow* HTMLMediaElement::mediaPlayerHostWindow()
+{
+    return mediaPlayerOwningDocument()->view()->hostWindow();
+}
+
+IntRect HTMLMediaElement::mediaPlayerWindowClipRect()
+{
+    return mediaPlayerOwningDocument()->view()->windowClipRect();
+}
+
 void HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture()
 {
     m_restrictions = NoRestrictions;
index da102a6..32b547d 100644 (file)
@@ -422,6 +422,16 @@ private:
     virtual bool mediaPlayerNeedsSiteSpecificHacks() const OVERRIDE;
     virtual String mediaPlayerDocumentHost() const OVERRIDE;
 
+    virtual void mediaPlayerExitFullscreen() OVERRIDE;
+    virtual bool mediaPlayerIsVideo() const OVERRIDE;
+    virtual LayoutRect mediaPlayerContentBoxRect() const OVERRIDE;
+    virtual void mediaPlayerSetSize(const IntSize&) OVERRIDE;
+    virtual void mediaPlayerPause() OVERRIDE;
+    virtual void mediaPlayerPlay() OVERRIDE;
+    virtual bool mediaPlayerIsPaused() const OVERRIDE;
+    virtual HostWindow* mediaPlayerHostWindow() OVERRIDE;
+    virtual IntRect mediaPlayerWindowClipRect() OVERRIDE;
+
 #if PLATFORM(WIN) && USE(AVFOUNDATION)
     virtual GraphicsDeviceAdapter* mediaPlayerGraphicsDeviceAdapter(const MediaPlayer*) const OVERRIDE;
 #endif
index de69222..eac345c 100644 (file)
@@ -98,6 +98,7 @@ class IntSize;
 class MediaPlayer;
 struct MediaPlayerFactory;
 class TimeRanges;
+class HostWindow;
 
 #if PLATFORM(WIN) && USE(AVFOUNDATION)
 struct GraphicsDeviceAdapter;
@@ -189,6 +190,15 @@ public:
     virtual String mediaPlayerReferrer() const { return String(); }
     virtual String mediaPlayerUserAgent() const { return String(); }
     virtual CORSMode mediaPlayerCORSMode() const { return Unspecified; }
+    virtual void mediaPlayerExitFullscreen() { }
+    virtual bool mediaPlayerIsVideo() const { return false; }
+    virtual LayoutRect mediaPlayerContentBoxRect() const { return LayoutRect(); }
+    virtual void mediaPlayerSetSize(const IntSize&) { }
+    virtual void mediaPlayerPause() { }
+    virtual void mediaPlayerPlay() { }
+    virtual bool mediaPlayerIsPaused() const { return true; }
+    virtual HostWindow* mediaPlayerHostWindow() { return 0; }
+    virtual IntRect mediaPlayerWindowClipRect() { return IntRect(); }
 };
 
 class MediaPlayerSupportsTypeClient {
index 6fad26e..d7f9acb 100644 (file)
@@ -27,7 +27,6 @@
 #include "Frame.h"
 #include "FrameView.h"
 #include "GraphicsContext.h"
-#include "HTMLMediaElement.h"
 #include "HTMLNames.h"
 #include "HostWindow.h"
 #include "MediaStreamDescriptor.h"
@@ -122,8 +121,7 @@ MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)
 MediaPlayerPrivate::~MediaPlayerPrivate()
 {
     if (isFullscreen()) {
-        HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
-        element->exitFullscreen();
+        m_webCorePlayer->mediaPlayerClient()->mediaPlayerExitFullscreen();
     }
 #if USE(ACCELERATED_COMPOSITING)
     // Remove media player from platform layer.
@@ -151,9 +149,7 @@ void MediaPlayerPrivate::load(const String& url)
         modifiedUrl = decodeURLEscapeSequences(modifiedUrl);
     }
 
-    void* tabId = 0;
-    if (frameView() && frameView()->hostWindow())
-        tabId = frameView()->hostWindow()->platformPageClient();
+    void* tabId = m_webCorePlayer->mediaPlayerClient()->mediaPlayerHostWindow()->platformPageClient();
 
     deleteGuardedObject(m_platformPlayer);
 #if USE(ACCELERATED_COMPOSITING)
@@ -370,7 +366,7 @@ void MediaPlayerPrivate::paintCurrentFrameInContext(GraphicsContext* context, co
     ASSERT(graphics);
 
     BlackBerry::Platform::IntRect platformRect(rect.x(), rect.y(), rect.width(), rect.height());
-    IntRect clippedRect = frameView()->windowClipRect();
+    IntRect clippedRect = m_webCorePlayer->mediaPlayerClient()->mediaPlayerWindowClipRect();
     BlackBerry::Platform::IntRect platformWindowClipRect(clippedRect.x(), clippedRect.y(), clippedRect.width(), clippedRect.height());
     m_platformPlayer->paint(graphics->canvas(), platformRect, platformWindowClipRect);
 }
@@ -399,39 +395,27 @@ void MediaPlayerPrivate::resizeSourceDimensions()
     if (!m_webCorePlayer)
         return;
 
-    HTMLMediaElement* client = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
-
-    if (!client || !client->isVideo())
-        return;
-
-    RenderObject* o = client->renderer();
-    if (!o)
+    if (!m_webCorePlayer->mediaPlayerClient()->mediaPlayerIsVideo())
         return;
 
     // If we have an HTMLVideoElement but the source has no video, then we need to resize the media element.
     if (!hasVideo()) {
-        IntRect rect = o->enclosingBox()->contentBoxRect();
+        LayoutRect rect = m_webCorePlayer->mediaPlayerClient()->mediaPlayerContentBoxRect();
 
         static const int playbookMinAudioElementWidth = 300;
         static const int playbookMinAudioElementHeight = 32;
         // If the rect dimensions are less than the allowed minimum, use the minimum instead.
-        int newWidth = max(rect.width(), playbookMinAudioElementWidth);
-        int newHeight = max(rect.height(), playbookMinAudioElementHeight);
-
-        char attrString[12];
+        int newWidth = max(rect.width().toInt(), playbookMinAudioElementWidth);
+        int newHeight = max(rect.height().toInt(), playbookMinAudioElementHeight);
 
-        sprintf(attrString, "%d", newWidth);
-        client->setAttribute(HTMLNames::widthAttr, attrString);
-
-        sprintf(attrString, "%d", newHeight);
-        client->setAttribute(HTMLNames::heightAttr, attrString);
+        m_webCorePlayer->mediaPlayerClient()->mediaPlayerSetSize(IntSize(newWidth, newHeight));
     }
 
     // If we don't know what the width and height of the video source is, then we need to set it to something sane.
     if (m_platformPlayer->sourceWidth() && m_platformPlayer->sourceHeight())
         return;
-    IntRect rect = o->enclosingBox()->contentBoxRect();
-    m_platformPlayer->setSourceDimension(rect.width(), rect.height());
+    LayoutRect rect = m_webCorePlayer->mediaPlayerClient()->mediaPlayerContentBoxRect();
+    m_platformPlayer->setSourceDimension(rect.width().toUnsigned(), rect.height().toUnsigned());
 }
 
 void MediaPlayerPrivate::setFullscreenWebPageClient(BlackBerry::WebKit::WebPageClient* client)
@@ -511,8 +495,6 @@ void MediaPlayerPrivate::updateStates()
 
     PlatformPlayer::Error currentError = m_platformPlayer->error();
 
-    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
-
     if (currentError != PlatformPlayer::MediaOK) {
         m_readyState = MediaPlayer::HaveNothing;
         if (currentError == PlatformPlayer::MediaDecodeError)
@@ -549,7 +531,7 @@ void MediaPlayerPrivate::updateStates()
             }
 #endif
             if (isFullscreen())
-                element->exitFullscreen();
+                m_webCorePlayer->mediaPlayerClient()->mediaPlayerExitFullscreen();
             break;
         case PlatformPlayer::MP_STATE_ACTIVE:
 #if USE(ACCELERATED_COMPOSITING)
@@ -608,15 +590,14 @@ void MediaPlayerPrivate::onPauseStateChanged()
     if (!isFullscreen())
         return;
 
-    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
     // Paused state change not due to local controller.
     if (m_platformPlayer->isPaused())
-        element->pause();
+        m_webCorePlayer->mediaPlayerClient()->mediaPlayerPause();
     else {
         // The HMI fullscreen widget has resumed play. Check if the
         // pause timeout occurred.
         m_platformPlayer->processPauseTimeoutIfNecessary();
-        element->play();
+        m_webCorePlayer->mediaPlayerClient()->mediaPlayerPlay();
     }
 }
 
@@ -644,14 +625,12 @@ void MediaPlayerPrivate::onSizeChanged()
 
 void MediaPlayerPrivate::onPlayNotified()
 {
-    if (HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient()))
-        element->play();
+    m_webCorePlayer->mediaPlayerClient()->mediaPlayerPlay();
 }
 
 void MediaPlayerPrivate::onPauseNotified()
 {
-    if (HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient()))
-        element->pause();
+    m_webCorePlayer->mediaPlayerClient()->mediaPlayerPause();
 }
 
 static const int popupDialogInterval = 10;
@@ -726,8 +705,8 @@ bool MediaPlayerPrivate::onAuthenticationNeeded(MMRAuthChallenge& authChallenge)
     Credential credential = CredentialStorage::get(protectionSpace);
     bool isConfirmed = false;
     if (credential.isEmpty()) {
-        if (frameView() && frameView()->hostWindow())
-            isConfirmed = frameView()->hostWindow()->platformPageClient()->authenticationChallenge(url, protectionSpace, credential);
+        isConfirmed = m_webCorePlayer->mediaPlayerClient()->mediaPlayerHostWindow()->platformPageClient()->authenticationChallenge(url, protectionSpace, credential);
+
     } else
         isConfirmed = true;
 
@@ -783,11 +762,7 @@ int MediaPlayerPrivate::showErrorDialog(PlatformPlayer::Error type)
         LOG(Media, "Alert type does not exist.");
         return -1;
     }
-
-    int rc = 0;
-    if (frameView() && frameView()->hostWindow())
-        rc = frameView()->hostWindow()->platformPageClient()->showAlertDialog(atype);
-    return rc;
+    return m_webCorePlayer->mediaPlayerClient()->mediaPlayerHostWindow()->platformPageClient()->showAlertDialog(atype);
 }
 
 static WebMediaStreamSource toWebMediaStreamSource(MediaStreamSource* src)
@@ -817,23 +792,9 @@ WebMediaStreamDescriptor MediaPlayerPrivate::lookupMediaStream(const string& url
     return toWebMediaStreamDescriptor(descriptor);
 }
 
-FrameView* MediaPlayerPrivate::frameView() const
-{
-    // We previously used m_webCorePlayer->frameView(), but this method returns
-    // a null frameView until quite late in the media player initialization,
-    // and starting quite early in the media player destruction (because
-    // it may be set to zero by the destructor in RenderVideo.cpp before
-    // our destructor is called, leaving us unable to clean up child windows
-    // in mmrDisconnect).
-    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
-    return element->document()->view();
-}
-
 BlackBerry::Platform::Graphics::Window* MediaPlayerPrivate::platformWindow()
 {
-    if (frameView() && frameView()->hostWindow())
-        return frameView()->hostWindow()->platformPageClient()->platformWindow();
-    return 0;
+    return m_webCorePlayer->mediaPlayerClient()->mediaPlayerHostWindow()->platformPageClient()->platformWindow();
 }
 
 bool MediaPlayerPrivate::isFullscreen() const
@@ -843,17 +804,12 @@ bool MediaPlayerPrivate::isFullscreen() const
 
 bool MediaPlayerPrivate::isElementPaused() const
 {
-    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
-    if (!element || element->paused())
-        return true;
-    return false;
+    return m_webCorePlayer->mediaPlayerClient()->mediaPlayerIsPaused();
 }
 
 bool MediaPlayerPrivate::isTabVisible() const
 {
-    if (frameView() && frameView()->hostWindow())
-        return frameView()->hostWindow()->platformPageClient()->isVisible();
-    return true;
+    return m_webCorePlayer->mediaPlayerClient()->mediaPlayerHostWindow()->platformPageClient()->isVisible();
 }
 
 #if USE(ACCELERATED_COMPOSITING)
index 40156fb..570741c 100644 (file)
@@ -145,7 +145,6 @@ public:
 private:
     MediaPlayerPrivate(MediaPlayer*);
 
-    FrameView* frameView() const;
     void updateStates();
     String userAgent(const String&) const;