<video> won't load when URL ends with .php
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 May 2012 17:17:40 +0000 (17:17 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 May 2012 17:17:40 +0000 (17:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86308

Source/WebCore:

Reviewed by NOBODY (OOPS!).

Test: http/tests/media/video-query-url.html

* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::MediaPlayer): Initialize m_typeInferredFromExtension.
(WebCore::MediaPlayer::load): Set m_typeInferredFromExtension appropriately.
(WebCore::MediaPlayer::loadWithNextMediaEngine): If we don't find a media engine registered
    for a MIME type, and the type was inferred from the extension, give the first registered
    media engine a chance anwyay just as we do when there is no MIME type at all.
* platform/graphics/MediaPlayer.h: Add m_typeInferredFromExtension.

LayoutTests:

Reviewed by Darin Adler.

* http/tests/media/resources/load-video.php: Added.
* http/tests/media/video-query-url-expected.txt: Added.
* http/tests/media/video-query-url.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/media/resources/load-video.php [new file with mode: 0644]
LayoutTests/http/tests/media/video-query-url-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/media/video-query-url.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h

index 8002b02..9fc9115 100644 (file)
@@ -1,3 +1,14 @@
+2012-05-14  Eric Carlson  <eric.carlson@apple.com>
+
+        <video> won't load when URL ends with .php
+        https://bugs.webkit.org/show_bug.cgi?id=86308
+
+        Reviewed by Darin Adler.
+
+        * http/tests/media/resources/load-video.php: Added.
+        * http/tests/media/video-query-url-expected.txt: Added.
+        * http/tests/media/video-query-url.html: Added.
+
 2012-05-14  Andrey Kosyakov  <caseq@chromium.org>
 
         Web Inspector: [Extensions API] allow extensions to evaluate in the context of their content scripts
diff --git a/LayoutTests/http/tests/media/resources/load-video.php b/LayoutTests/http/tests/media/resources/load-video.php
new file mode 100644 (file)
index 0000000..00a39f5
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+    $fileName = $_GET["name"];
+    $type = $_GET["type"];
+
+    $_GET = array();
+    $_GET['name'] = $fileName;
+    $_GET['type'] = $type;
+    @include("./serve-video.php"); 
+
+?>
diff --git a/LayoutTests/http/tests/media/video-query-url-expected.txt b/LayoutTests/http/tests/media/video-query-url-expected.txt
new file mode 100644 (file)
index 0000000..2c00f86
--- /dev/null
@@ -0,0 +1,5 @@
+Tests that WebKit is able to open a media file specified with a query url.  
+EVENT(canplay)
+END OF TEST
+
diff --git a/LayoutTests/http/tests/media/video-query-url.html b/LayoutTests/http/tests/media/video-query-url.html
new file mode 100644 (file)
index 0000000..e1b4582
--- /dev/null
@@ -0,0 +1,34 @@
+<html>
+    <head>
+        <script src=../../media-resources/video-test.js></script>
+        <script src=../../media-resources/media-file.js></script>
+        <script>
+            function loadMediaFrame() 
+            {
+                findMediaElement();
+
+                var movie = findMediaFile('video', 'test');
+                var type = mimeTypeForExtension(movie.split('.').pop());
+                var frame = document.createElement('iframe');
+
+                frame.width = 0;
+                frame.height = 0;
+                frame.addEventListener('load', function () {
+                    video.src = 'http://127.0.0.1:8000/media/resources/load-video.php?name=' + movie + '&type=' + type;
+    
+                    waitForEventAndFail('error');
+                    waitForEventAndEnd('canplay');
+                });
+        
+                frame.src = "data:text/html,<b>test</b>";
+                document.body.appendChild(frame);
+            }
+        </script>
+    </head>
+
+    <body onload="loadMediaFrame()">
+        <video controls></video>
+        <br>
+        Tests that WebKit is able to open a media file specified with a query url.
+    </body>
+</html>
index eac988b..4bed189 100644 (file)
@@ -1,3 +1,20 @@
+2012-05-14  Eric Carlson  <eric.carlson@apple.com>
+
+        <video> won't load when URL ends with .php
+        https://bugs.webkit.org/show_bug.cgi?id=86308
+
+        Reviewed by Darin Adler.
+
+        Test: http/tests/media/video-query-url.html
+
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::MediaPlayer): Initialize m_typeInferredFromExtension.
+        (WebCore::MediaPlayer::load): Set m_typeInferredFromExtension appropriately.
+        (WebCore::MediaPlayer::loadWithNextMediaEngine): If we don't find a media engine registered
+            for a MIME type, and the type was inferred from the extension, give the first registered
+            media engine a chance anwyay just as we do when there is no MIME type at all.
+        * platform/graphics/MediaPlayer.h: Add m_typeInferredFromExtension.
+
 2012-05-14  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Web Inspector: do not update $0-$4 console variables for the objects from loaded from file heap snapshot.
index 9fc614d..c2a6d5f 100644 (file)
@@ -325,6 +325,7 @@ MediaPlayer::MediaPlayer(MediaPlayerClient* client)
     , m_preservesPitch(true)
     , m_privateBrowsing(false)
     , m_shouldPrepareToRender(false)
+    , m_contentMIMETypeWasInferredFromExtension(false)
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     , m_playerProxy(0)
 #endif
@@ -347,44 +348,45 @@ MediaPlayer::~MediaPlayer()
 
 bool MediaPlayer::load(const KURL& url, const ContentType& contentType, const String& keySystem)
 {
-    String type = contentType.type().lower();
-    String typeCodecs = contentType.parameter(codecs());
-    String urlString = url.string();
+    m_contentMIMEType = contentType.type().lower();
+    m_contentTypeCodecs = contentType.parameter(codecs());
+    m_url = url.string();
+    m_keySystem = keySystem.lower();
+    m_contentMIMETypeWasInferredFromExtension = false;
 
     // If the MIME type is missing or is not meaningful, try to figure it out from the URL.
-    if (type.isEmpty() || type == applicationOctetStream() || type == textPlain()) {
-        if (protocolIs(urlString, "data"))
-            type = mimeTypeFromDataURL(urlString);
+    if (m_contentMIMEType.isEmpty() || m_contentMIMEType == applicationOctetStream() || m_contentMIMEType == textPlain()) {
+        if (protocolIs(m_url, "data"))
+            m_contentMIMEType = mimeTypeFromDataURL(m_url);
         else {
             String lastPathComponent = url.lastPathComponent();
             size_t pos = lastPathComponent.reverseFind('.');
             if (pos != notFound) {
                 String extension = lastPathComponent.substring(pos + 1);
                 String mediaType = MIMETypeRegistry::getMediaMIMETypeForExtension(extension);
-                if (!mediaType.isEmpty())
-                    type = mediaType;
+                if (!mediaType.isEmpty()) {
+                    m_contentMIMEType = mediaType;
+                    m_contentMIMETypeWasInferredFromExtension = true;
+                }
             }
         }
     }
 
-    m_url = urlString;
-    m_contentMIMEType = type;
-    m_contentTypeCodecs = typeCodecs;
-    m_keySystem = keySystem.lower();
     loadWithNextMediaEngine(0);
     return m_currentMediaEngine;
 }
 
 void MediaPlayer::loadWithNextMediaEngine(MediaPlayerFactory* current)
 {
-    MediaPlayerFactory* engine;
+    MediaPlayerFactory* engine = 0;
 
-    // If no MIME type is specified, just use the next engine.
-    if (m_contentMIMEType.isEmpty())
-        engine = nextMediaEngine(current);
-    else
+    if (!m_contentMIMEType.isEmpty())
         engine = bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_keySystem, current);
 
+    // If no MIME type is specified or the type was inferred from the file extension, just use the next engine.
+    if (!engine && (m_contentMIMEType.isEmpty() || m_contentMIMETypeWasInferredFromExtension))
+        engine = nextMediaEngine(current);
+
     // Don't delete and recreate the player unless it comes from a different engine.
     if (!engine) {
         LOG(Media, "MediaPlayer::loadWithNextMediaEngine - no media engine found for type \"%s\"", m_contentMIMEType.utf8().data());
index fd62305..340cd4c 100644 (file)
@@ -399,6 +399,7 @@ private:
     bool m_preservesPitch;
     bool m_privateBrowsing;
     bool m_shouldPrepareToRender;
+    bool m_contentMIMETypeWasInferredFromExtension;
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     WebMediaPlayerProxy* m_playerProxy;    // not owned or used, passed to m_private
 #endif