Reviewed by Adele.
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jan 2008 01:58:09 +0000 (01:58 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jan 2008 01:58:09 +0000 (01:58 +0000)
        Windows fix for <rdar://problem/5605682>
        Disallow streaming protocols for media elements
        and <rdar://problem/5668711>
        Limit the container and codec types that the <video> tag supports

        - Disable unsupported QuickTime tracks types.
        - Disallow streaming protocols (for now).

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

LayoutTests/ChangeLog
LayoutTests/platform/win/Skipped
WebCore/ChangeLog
WebCore/platform/graphics/win/MediaPlayerPrivateQuickTimeWin.cpp
WebCore/platform/graphics/win/QTMovieWin.cpp
WebCore/platform/graphics/win/QTMovieWin.h

index 97e82b3..790076c 100644 (file)
@@ -1,3 +1,11 @@
+2008-01-17  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Adele.
+        
+        Enable tests for unsupported types on Windows.
+
+        * platform/win/Skipped:
+
 2008-01-17  Stephanie  <slewis@apple.com>
 
         RS=Adam
index 247fc1b..c9200e8 100644 (file)
@@ -45,12 +45,6 @@ http/tests/security/cross-frame-access-protocol.html
 # Crashes on Windows <rdar://problem/5674277>
 media/video-display-toggle.html
 
-# Disallow streaming protocols for media elements <rdar://problem/5605682>
-media/unsupported-rtsp.html
-
-# Limit the container and codec types that the <video> tag supports <rdar://problem/5605682>
-media/unsupported-tracks.html
-
 # Fails, could be problem with the test setup <rdar://problem/5674282>
 http/tests/media/video-play-stall.html
 http/tests/media/video-seekable-stall.html
index 0e9eb98..7107dee 100644 (file)
@@ -1,3 +1,23 @@
+2008-01-17  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Adele.
+
+        Windows fix for <rdar://problem/5605682>
+        Disallow streaming protocols for media elements
+        and <rdar://problem/5668711>
+        Limit the container and codec types that the <video> tag supports
+        
+        - Disable unsupported QuickTime tracks types. 
+        - Disallow streaming protocols (for now).
+
+        * WebCore.vcproj/WebCore.vcproj:
+        * platform/graphics/win/MediaPlayerPrivateQuickTimeWin.cpp:
+        (WebCore::MediaPlayerPrivate::updateStates):
+        * platform/graphics/win/QTMovieWin.cpp:
+        (QTMovieWin::load):
+        (QTMovieWin::disableUnsupportedTracks):
+        * platform/graphics/win/QTMovieWin.h:
+
 2008-01-17  Oliver Hunt  <oliver@apple.com>
 
         Support smart copy and paste during drag and drop
index 71eec0f..0480689 100644 (file)
@@ -310,7 +310,16 @@ void MediaPlayerPrivate::updateStates()
     MediaPlayer::NetworkState oldNetworkState = m_networkState;\r
     MediaPlayer::ReadyState oldReadyState = m_readyState;\r
   \r
-    long loadState = m_qtMovie ? m_qtMovie->loadState() : -1;\r
+    long loadState = m_qtMovie ? m_qtMovie->loadState() : QTMovieLoadStateError;\r
+\r
+    if (loadState >= QTMovieLoadStateLoaded && m_networkState < MediaPlayer::LoadedMetaData) {\r
+        unsigned enabledTrackCount;\r
+        m_qtMovie->disableUnsupportedTracks(enabledTrackCount);\r
+        // FIXME: We should differentiate between load errors and decode errors <rdar://problem/5605692>\r
+        if (!enabledTrackCount)\r
+            loadState = QTMovieLoadStateError;\r
+    }\r
+\r
     // "Loaded" is reserved for fully buffered movies, never the case when streaming\r
     if (loadState >= QTMovieLoadStateComplete && !m_isStreaming) {\r
         if (m_networkState < MediaPlayer::Loaded)\r
@@ -328,7 +337,7 @@ void MediaPlayerPrivate::updateStates()
         if (m_networkState < MediaPlayer::LoadedMetaData)\r
             m_networkState = MediaPlayer::LoadedMetaData;\r
         m_readyState = MediaPlayer::DataUnavailable;\r
-    } else if (loadState >= 0) {\r
+    } else if (loadState > QTMovieLoadStateError) {\r
         if (m_networkState < MediaPlayer::Loading)\r
             m_networkState = MediaPlayer::Loading;\r
         m_readyState = MediaPlayer::DataUnavailable;        \r
index 2bb8d4b..0b48ec1 100644 (file)
 
 #include "QTMovieWin.h"
 
-#include <GXMath.h>
+// Put Movies.h first so build failures here point clearly to QuickTime
 #include <Movies.h>
+#include <GXMath.h>
 #include <QTML.h>
+
 #include "QTMovieWinTimer.h"
 
 #include <wtf/Assertions.h>
@@ -438,7 +440,14 @@ void QTMovieWin::load(const UChar* url, int len)
     bool boolTrue = true;
 
     // Create a URL data reference of type CFURL 
-    CFStringRef urlStringRef = CFStringCreateWithCharacters (kCFAllocatorDefault, reinterpret_cast<const UniChar*>(url), len);
+    CFStringRef urlStringRef = CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(url), len);
+    
+    // Disable streaming support for now. 
+    if (CFStringHasPrefix(urlStringRef, CFSTR("rtsp:"))) {
+        m_private->m_loadError = noMovieFound;
+        goto end;
+    }
+
     CFURLRef urlRef = CFURLCreateWithString(kCFAllocatorDefault, urlStringRef, 0); 
 
     // Add the movie data location to the property array 
@@ -477,9 +486,25 @@ void QTMovieWin::load(const UChar* url, int len)
     movieProps[moviePropCount].propStatus = 0; 
     moviePropCount++; 
 
+    movieProps[moviePropCount].propClass = kQTPropertyClass_MovieInstantiation;
+    movieProps[moviePropCount].propID = '!url'; // kQTInteractivePropertyID_BlockExternalURLLinks
+    movieProps[moviePropCount].propValueSize = sizeof(boolTrue); 
+    movieProps[moviePropCount].propValueAddress = &boolTrue; 
+    movieProps[moviePropCount].propStatus = 0; 
+    moviePropCount++; 
+
+    movieProps[moviePropCount].propClass = kQTPropertyClass_MovieInstantiation; 
+    movieProps[moviePropCount].propID = 'site'; // kQTSecurityPolicyPropertyID_NoCrossSite; 
+    movieProps[moviePropCount].propValueSize = sizeof(boolTrue); 
+    movieProps[moviePropCount].propValueAddress = &boolTrue; 
+    movieProps[moviePropCount].propStatus = 0; 
+    moviePropCount++; 
+
     m_private->m_loadError = NewMovieFromProperties(moviePropCount, movieProps, 0, NULL, &m_private->m_movie);
-    m_private->startTask();
 
+    CFRelease(urlRef);
+end:
+    m_private->startTask();
     // get the load fail callback quickly 
     if (m_private->m_loadError)
         updateTaskTimer(0);
@@ -487,7 +512,109 @@ void QTMovieWin::load(const UChar* url, int len)
         m_private->registerDrawingCallback();
 
     CFRelease(urlStringRef);
-    CFRelease(urlRef);
+}
+
+void QTMovieWin::disableUnsupportedTracks(unsigned& enabledTrackCount)
+{
+    if (!m_private->m_movie) {
+        enabledTrackCount = 0;
+        return;
+    }
+
+    static HashSet<OSType>* allowedTrackTypes = 0;
+    if (!allowedTrackTypes) {
+        allowedTrackTypes = new HashSet<OSType>;
+        allowedTrackTypes->add(VideoMediaType);
+        allowedTrackTypes->add(SoundMediaType);
+        allowedTrackTypes->add(TextMediaType);
+        allowedTrackTypes->add(BaseMediaType);
+        allowedTrackTypes->add('clcp'); // Closed caption
+        allowedTrackTypes->add('sbtl'); // Subtitle
+    }
+
+    long trackCount = GetMovieTrackCount(m_private->m_movie);
+    enabledTrackCount = trackCount;
+    
+    // Track indexes are 1-based. yuck. These things must descend from old-
+    // school mac resources or something.
+    for (long trackIndex = 1; trackIndex <= trackCount; trackIndex++) {
+        // Grab the track at the current index. If there isn't one there, then
+        // we can move onto the next one.
+        Track currentTrack = GetMovieIndTrack(m_private->m_movie, trackIndex);
+        if (!currentTrack)
+            continue;
+        
+        // Check to see if the track is disabled already, we should move along.
+        // We don't need to re-disable it.
+        if (!GetTrackEnabled(currentTrack))
+            continue;
+
+        // Grab the track's media. We're going to check to see if we need to
+        // disable the tracks. They could be unsupported. <rdar://problem/4983892>
+        Media trackMedia = GetTrackMedia(currentTrack);
+        if (!trackMedia)
+            continue;
+        
+        // Grab the media type for this track. Make sure that we don't
+        // get an error in doing so. If we do, then something really funky is
+        // wrong.
+        OSType mediaType;
+        GetMediaHandlerDescription(trackMedia, &mediaType, nil, nil);
+        OSErr mediaErr = GetMoviesError();    
+        if (mediaErr != noErr)
+            continue;
+        
+        if (!allowedTrackTypes->contains(mediaType)) {
+            SetTrackEnabled(currentTrack, false);
+            --enabledTrackCount;
+        }
+        
+        // Grab the track reference count for chapters. This will tell us if it
+        // has chapter tracks in it. If there aren't any references, then we
+        // can move on the next track.
+        long referenceCount = GetTrackReferenceCount(currentTrack, kTrackReferenceChapterList);
+        if (referenceCount <= 0)
+            continue;
+        
+        long referenceIndex = 0;        
+        while (1) {
+            // If we get nothing here, we've overstepped our bounds and can stop
+            // looking. Chapter indices here are 1-based as well - hence, the
+            // pre-increment.
+            referenceIndex++;
+            Track chapterTrack = GetTrackReference(currentTrack, kTrackReferenceChapterList, referenceIndex);
+            if (!chapterTrack)
+                break;
+            
+            // Try to grab the media for the track.
+            Media chapterMedia = GetTrackMedia(chapterTrack);
+            if (!chapterMedia)
+                continue;
+        
+            // Grab the media type for this track. Make sure that we don't
+            // get an error in doing so. If we do, then something really
+            // funky is wrong.
+            OSType mediaType;
+            GetMediaHandlerDescription(chapterMedia, &mediaType, nil, nil);
+            OSErr mediaErr = GetMoviesError();
+            if (mediaErr != noErr)
+                continue;
+            
+            // Check to see if the track is a video track. We don't care about
+            // other non-video tracks.
+            if (mediaType != VideoMediaType)
+                continue;
+            
+            // Check to see if the track is already disabled. If it is, we
+            // should move along.
+            if (!GetTrackEnabled(chapterTrack))
+                continue;
+            
+            // Disabled the evil, evil track.
+            SetTrackEnabled(chapterTrack, false);
+            --enabledTrackCount;
+        }
+    }
 }
 
 pascal OSErr movieDrawingCompleteProc(Movie movie, long data)
index 3baec36..e537294 100644 (file)
@@ -46,6 +46,7 @@ public:
 };
 
 enum {
+    QTMovieLoadStateError = -1L,
     QTMovieLoadStateLoaded  = 2000L,
     QTMovieLoadStatePlayable = 10000L,
     QTMovieLoadStatePlaythroughOK = 20000L,
@@ -84,6 +85,8 @@ public:
     void setVisible(bool);
     void paint(HDC, int x, int y);
 
+    void disableUnsupportedTracks(unsigned& enabledTrackCount);
+
     static unsigned countSupportedTypes();
     static void getSupportedType(unsigned index, const UChar*& str, unsigned& len);