2009-03-04 Eric Carlson <eric.carlson@apple.com>
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Mar 2009 22:21:16 +0000 (22:21 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Mar 2009 22:21:16 +0000 (22:21 +0000)
        Reviewed by Antti Koivisto.

        https://bugs.webkit.org/show_bug.cgi?id=24364
        Add support for HTMLMediaElement canPlayType method. Make
        MediaPlayer::supportsType take a ContentType instead of a
        separate mime type and codecs parameter.

        Test: media/video-can-play-type.html

        * dom/DOMImplementation.cpp:
        (WebCore::DOMImplementation::createDocument):
        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::canPlayType): Add canPlayType method.
        (WebCore::HTMLMediaElement::loadInternal): selectMediaURL returns a ContentType.
        (WebCore::HTMLMediaElement::selectMediaURL): Return a ContentType instead of raw MIME type.
        (WebCore::HTMLMediaElement::initialURL): selectMediaURL returns a ContentType.
        * html/HTMLMediaElement.h: Add prototype.
        * html/HTMLMediaElement.idl: Ditto.
        * platform/graphics/MediaPlayer.cpp:
        (WebCore::MediaPlayer::load): Take a ContentType instead of raw MIME type.
        (WebCore::MediaPlayer::supportsType): Ditto.
        * platform/graphics/MediaPlayer.h:

2009-03-04  Eric Carlson  <eric.carlson@apple.com>

        Reviewed by Antti Koivisto.

        https://bugs.webkit.org/show_bug.cgi?id=24364
        Test HTMLMediaElement canPlayType method.

        * media/video-can-play-type-expected.txt: Added.
        * media/video-can-play-type.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/media/video-can-play-type-expected.txt [new file with mode: 0644]
LayoutTests/media/video-can-play-type.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/DOMImplementation.cpp
WebCore/html/HTMLMediaElement.cpp
WebCore/html/HTMLMediaElement.h
WebCore/html/HTMLMediaElement.idl
WebCore/platform/graphics/MediaPlayer.cpp
WebCore/platform/graphics/MediaPlayer.h

index 8ed3b16b51c1dc5d5745c592d637b1f5d8169efb..321670fdb4f084005ed1d06ebb1b7f87c92ee229 100644 (file)
@@ -1,3 +1,13 @@
+2009-03-04  Eric Carlson  <eric.carlson@apple.com>
+
+        Reviewed by Antti Koivisto.
+
+        https://bugs.webkit.org/show_bug.cgi?id=24364
+        Test HTMLMediaElement canPlayType method.
+
+        * media/video-can-play-type-expected.txt: Added.
+        * media/video-can-play-type.html: Added.
+
 2009-03-04  Kevin McCullough  <kmccullough@apple.com>
 
         - Build bot fix.
diff --git a/LayoutTests/media/video-can-play-type-expected.txt b/LayoutTests/media/video-can-play-type-expected.txt
new file mode 100644 (file)
index 0000000..7deb421
--- /dev/null
@@ -0,0 +1,11 @@
+Test HTMLMediaElement canPlayType() method.
+
+EXPECTED (video.canPlayType() == 'no') OK
+EXPECTED (video.canPlayType('video/') == 'no') OK
+EXPECTED (video.canPlayType('video/blahblah') == 'no') OK
+EXPECTED (video.canPlayType('video/mpeg; codecs="avc1.4D400C"') == 'maybe') OK
+EXPECTED (video.canPlayType('   video/mp4 ; video/mp4; codecs="mp4v.20.8, mp4a.40.2"') == 'maybe') OK
+EXPECTED (video.canPlayType('audio/mpeg') == 'probably') OK
+EXPECTED (video.canPlayType('audio/wav') == 'probably') OK
+END OF TEST
+
diff --git a/LayoutTests/media/video-can-play-type.html b/LayoutTests/media/video-can-play-type.html
new file mode 100644 (file)
index 0000000..3f608c2
--- /dev/null
@@ -0,0 +1,29 @@
+<html>
+    <head>
+        <style>
+            video { background-color: yellow; width: 320px; height: 240px;} 
+        </style>
+    </head>
+    <body>
+
+        <video controls ></video>
+
+        <p>Test HTMLMediaElement <em>canPlayType()</em> method.</p>
+
+        <script src=video-test.js></script>
+        <script>
+        
+            video = media = document.getElementsByTagName('video')[0];
+
+            testExpected("video.canPlayType()", "no");
+            testExpected("video.canPlayType('video/')", "no");
+            testExpected("video.canPlayType('video/blahblah')", "no");
+            testExpected("video.canPlayType('video/mpeg; codecs=&quot;avc1.4D400C&quot;')", "maybe");
+            testExpected("video.canPlayType('        video/mp4  ; video/mp4; codecs=&quot;mp4v.20.8, mp4a.40.2&quot;')", "maybe");
+            testExpected("video.canPlayType('audio/mpeg')", "probably");
+            testExpected("video.canPlayType('audio/wav')", "probably");
+
+            endTest();
+        </script>
+    </body>
+</html>
index 5fa5f60a9f7fcbf6082f0af3365e310dedde56d7..9c5b8ce825fb8a623dece7a5cec992ed5eb8dffc 100644 (file)
@@ -1,3 +1,28 @@
+2009-03-04  Eric Carlson  <eric.carlson@apple.com>
+
+        Reviewed by Antti Koivisto.
+
+        https://bugs.webkit.org/show_bug.cgi?id=24364
+        Add support for HTMLMediaElement canPlayType method. Make
+        MediaPlayer::supportsType take a ContentType instead of a
+        separate mime type and codecs parameter.
+
+        Test: media/video-can-play-type.html
+
+        * dom/DOMImplementation.cpp:
+        (WebCore::DOMImplementation::createDocument):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::canPlayType): Add canPlayType method.
+        (WebCore::HTMLMediaElement::loadInternal): selectMediaURL returns a ContentType.
+        (WebCore::HTMLMediaElement::selectMediaURL): Return a ContentType instead of raw MIME type.
+        (WebCore::HTMLMediaElement::initialURL): selectMediaURL returns a ContentType.
+        * html/HTMLMediaElement.h: Add prototype.
+        * html/HTMLMediaElement.idl: Ditto.
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::load): Take a ContentType instead of raw MIME type.
+        (WebCore::MediaPlayer::supportsType): Ditto.
+        * platform/graphics/MediaPlayer.h:
+
 2009-03-04  Antti Koivisto  <antti@apple.com>
 
         Reviewed by Dave Hyatt.
         (WebCore::JSXMLHttpRequestConstructor::scriptExecutionContext):
         * dom/EventException.idl:
         * dom/EventListener.idl:
-        Chnage to have the NoStaticTables attribute since they are used from XHR.
+        Change to have the NoStaticTables attribute since they are used from XHR.
 
         * loader/WorkerThreadableLoader.cpp:
         (WebCore::workerContextDidFinishLoading):
         * xml/XMLHttpRequestException.idl:
         * xml/XMLHttpRequestProgressEvent.idl:
         * xml/XMLHttpRequestUpload.idl:
-        Chnage to have the NoStaticTables attribute since they are used from XHR.
+        Change to have the NoStaticTables attribute since they are used from XHR.
 
 2009-03-01  Horia Olaru  <olaru@adobe.com>
 
 
         Rubber-stamped by Ada Chan.
 
-        * dom/Document.h: Chnaged HitTestRequest to a class from a struct.
+        * dom/Document.h: Changed HitTestRequest to a class from a struct.
         * page/EventHandler.h: Ditto.
         * rendering/EllipsisBox.h: Ditto.
         * rendering/InlineBox.h: Ditto.
index 738575fe3aa14af2ae844d6cf7521dc37e813a72..4f29f969113f457820df439dc62b0caf365d4f75 100644 (file)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "DOMImplementation.h"
 
+#include "ContentType.h"
 #include "CSSStyleSheet.h"
 #include "DocumentType.h"
 #include "Element.h"
@@ -347,7 +348,7 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame
 
 #if ENABLE(VIDEO)
      // Check to see if the type can be played by our MediaPlayer, if so create a MediaDocument
-     if (MediaPlayer::supportsType(type))
+     if (MediaPlayer::supportsType(ContentType(type)))
          return MediaDocument::create(frame);
 #endif
 
index 861fc0626163be53c7ece2c89e8008325d75669e..3325423d3fee3f91e0abd4a8beba46d81b70e37a 100644 (file)
@@ -307,6 +307,28 @@ float HTMLMediaElement::bufferingRate()
     //return m_player->dataRate();
 }
 
+String HTMLMediaElement::canPlayType(const String& mimeType) const
+{
+    MediaPlayer::SupportsType support = MediaPlayer::supportsType(ContentType(mimeType));
+    String canPlay;
+
+    // 4.8.10.3
+    switch (support)
+    {
+        case MediaPlayer::IsNotSupported:
+            canPlay = "no";
+            break;
+        case MediaPlayer::MayBeSupported:
+            canPlay = "maybe";
+            break;
+        case MediaPlayer::IsSupported:
+            canPlay = "probably";
+            break;
+    }
+    
+    return canPlay;
+}
+
 void HTMLMediaElement::load(ExceptionCode& ec)
 {
     if (m_restrictions & RequireUserGestureForLoadRestriction && !processingUserGesture()) {
@@ -320,7 +342,7 @@ void HTMLMediaElement::load(ExceptionCode& ec)
 void HTMLMediaElement::loadInternal(ExceptionCode& ec)
 {
     String mediaSrc;
-    String mediaMIMEType;
+    ContentType contentType("");
 
     // 3.14.9.4. Loading the media resource
     // 1
@@ -369,7 +391,7 @@ void HTMLMediaElement::loadInternal(ExceptionCode& ec)
     }
     
     // 6
-    mediaSrc = selectMediaURL(mediaMIMEType);
+    mediaSrc = selectMediaURL(contentType);
     if (mediaSrc.isEmpty()) {
         ec = INVALID_STATE_ERR;
         goto end;
@@ -398,7 +420,7 @@ void HTMLMediaElement::loadInternal(ExceptionCode& ec)
 #endif
 
     updateVolume();
-    m_player->load(m_currentSrc, mediaMIMEType);
+    m_player->load(m_currentSrc, contentType);
     if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
         goto end;
     
@@ -952,7 +974,7 @@ bool HTMLMediaElement::canPlay() const
     return paused() || ended() || networkState() < LOADED_METADATA;
 }
 
-String HTMLMediaElement::selectMediaURL(String& mediaMIMEType)
+String HTMLMediaElement::selectMediaURL(ContentType& contentType)
 {
     // 3.14.9.2. Location of the media resource
     String mediaSrc = getAttribute(srcAttr);
@@ -969,12 +991,12 @@ String HTMLMediaElement::selectMediaURL(String& mediaMIMEType)
                         continue;
                 }
                 if (source->hasAttribute(typeAttr)) {
-                    ContentType contentType(source->type());
-                    if (!MediaPlayer::supportsType(contentType.type(), contentType.parameter("codecs")))
+                    ContentType type(source->type());
+                    if (!MediaPlayer::supportsType(type))
                         continue;
 
                     // return type with all parameters in place so the media engine can use them
-                    mediaMIMEType = contentType.raw();
+                    contentType = type;
                 }
                 mediaSrc = source->src().string();
                 break;
@@ -1262,7 +1284,7 @@ void HTMLMediaElement::setMediaPlayerProxy(WebMediaPlayerProxy* proxy)
 
 String HTMLMediaElement::initialURL()
 {
-    String ignoredType;
+    ContentType ignoredType;
     String initialSrc = selectMediaURL(ignoredType);
     m_currentSrc = initialSrc;
     return initialSrc;
index df5db8a460d43d60f9a85b7a69be51794620d64b..2909f8332d07ac173ffce835e99361ea6be56e3e 100644 (file)
@@ -86,6 +86,8 @@ public:
     float bufferingRate();
     PassRefPtr<TimeRanges> buffered() const;
     void load(ExceptionCode&);
+    
+    String canPlayType(const String& mimeType) const;
 
 // ready state
     enum ReadyState { DATA_UNAVAILABLE, CAN_SHOW_CURRENT_FRAME, CAN_PLAY, CAN_PLAY_THROUGH };
@@ -183,7 +185,7 @@ private:
     void beginProcessingMediaPlayerCallback() { ++m_processingMediaPlayerCallback; }
     void endProcessingMediaPlayerCallback() { ASSERT(m_processingMediaPlayerCallback); --m_processingMediaPlayerCallback; }
 
-    String selectMediaURL(String& mediaMIMEType);
+    String selectMediaURL(ContentType& contentType);
     void updateVolume();
     void updatePlayState();
     float effectiveStart() const;
index 1e3eb90a59fc00cf6067ab10c07adc8ea0e0b79f..0bc27ea311cbc020a81ef4a1e5845af55b21e2bd 100644 (file)
@@ -43,6 +43,9 @@ interface [GenerateConstructor, Conditional=VIDEO] HTMLMediaElement : HTMLElemen
     readonly attribute TimeRanges buffered;
     void load() 
         raises (DOMException);
+    
+    DOMString canPlayType(in DOMString type);
+
 
     // ready state
     const unsigned short DATA_UNAVAILABLE = 0;
index 92ed15ce0cfddd01c0fbab6e56d57adeefbd00d1..e0c379013980452c72d4ba294640e57321b2801d 100644 (file)
@@ -193,11 +193,14 @@ MediaPlayer::~MediaPlayer()
 {
 }
 
-void MediaPlayer::load(const String& url, const String& mimeType)
+void MediaPlayer::load(const String& url, const ContentType& contentType)
 {
+    String type = contentType.type();
+    String codecs = contentType.parameter("codecs");
+
     // if we don't know the MIME type, see if the path can help
-    String type = mimeType.isEmpty() ? MIMETypeRegistry::getMIMETypeForPath(url) : mimeType;
-    String codecs = ContentType(type).parameter("codecs");
+    if (type.isEmpty()) 
+        type = MIMETypeRegistry::getMIMETypeForPath(url);
 
     MediaPlayerFactory* engine = chooseBestEngineForTypeAndCodecs(type, codecs);
 
@@ -376,8 +379,10 @@ void MediaPlayer::paint(GraphicsContext* p, const IntRect& r)
     m_private->paint(p, r);
 }
 
-MediaPlayer::SupportsType MediaPlayer::supportsType(const String& type, const String& codecs)
+MediaPlayer::SupportsType MediaPlayer::supportsType(ContentType contentType)
 {
+    String type = contentType.type();
+    String codecs = contentType.parameter("codecs");
     MediaPlayerFactory* engine = chooseBestEngineForTypeAndCodecs(type, codecs);
 
     if (!engine)
index 7748656855ec06fb831df4d8cdddb587b73289b2..1b8f3676a52a53eb73cae57713d7ba3d7d51c175 100644 (file)
@@ -40,6 +40,7 @@
 
 namespace WebCore {
 
+class ContentType;
 class FrameView;
 class GraphicsContext;
 class IntRect;
@@ -65,7 +66,7 @@ public:
 
     // media engine support
     enum SupportsType { IsNotSupported, IsSupported, MayBeSupported };
-    static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs = "");
+    static MediaPlayer::SupportsType supportsType(ContentType contentType);
     static void getSupportedTypes(HashSet<String>&);
     static bool isAvailable();
     
@@ -82,7 +83,7 @@ public:
     IntRect rect() const { return m_rect; }
     void setRect(const IntRect& r);
     
-    void load(const String& url, const String& mimeType);
+    void load(const String& url, const ContentType& contentType);
     void cancelLoad();
     
     bool visible() const;