Title: [119694] trunk
Revision
119694
Author
[email protected]
Date
2012-06-07 01:48:25 -0700 (Thu, 07 Jun 2012)

Log Message

Plumb CORS attribute information from HTMLMediaElement to media players so it can be used
https://bugs.webkit.org/show_bug.cgi?id=88349

Reviewed by Adam Barth.

Source/WebCore:

Test: http/tests/security/video-cross-origin-readback.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerCORSMode):
(WebCore):
* html/HTMLMediaElement.h:
(HTMLMediaElement):
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaPlayerCORSMode):

Source/WebKit/chromium:

* public/WebMediaPlayer.h:
(WebMediaPlayer):
* src/WebMediaPlayerClientImpl.cpp:
(WebKit::WebMediaPlayerClientImpl::loadInternal):

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/http/tests/security/resources/video-cross-origin-allow.php (0 => 119694)


--- trunk/LayoutTests/http/tests/security/resources/video-cross-origin-allow.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/resources/video-cross-origin-allow.php	2012-06-07 08:48:25 UTC (rev 119694)
@@ -0,0 +1,13 @@
+<?php
+
+header("Access-Control-Allow-Origin: *");
+
+if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
+    header("Access-Control-Allow-Methods: GET");
+    header("Access-Control-Allow-Headers: origin, accept-encoding, referer, range");
+    exit;
+}
+
+@include("../../media/resources/serve-video.php");
+
+?>
\ No newline at end of file

Added: trunk/LayoutTests/http/tests/security/video-cross-origin-readback-expected.txt (0 => 119694)


--- trunk/LayoutTests/http/tests/security/video-cross-origin-readback-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/video-cross-origin-readback-expected.txt	2012-06-07 08:48:25 UTC (rev 119694)
@@ -0,0 +1,3 @@
+EVENT(playing)
+END OF TEST
+ 

Added: trunk/LayoutTests/http/tests/security/video-cross-origin-readback.html (0 => 119694)


--- trunk/LayoutTests/http/tests/security/video-cross-origin-readback.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/video-cross-origin-readback.html	2012-06-07 08:48:25 UTC (rev 119694)
@@ -0,0 +1,33 @@
+<html>
+  <body _onload_="start()">
+    <script src=""
+    <script src=""
+    <script>
+        waitForEvent('error', function() {
+            failTest("error: " + JSON.stringify(video.error));
+        });
+
+        waitForEvent('playing', function() {
+          try {
+              var ctx = document.getElementsByTagName('canvas')[0].getContext("2d");
+              ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
+              ctx.getImageData(0, 0, video.videoWidth, video.videoHeight);
+          } catch (e) {
+              failTest("Caught error: " + e);
+          }
+          endTest();
+        });
+
+        function start() {
+            findMediaElement();
+            var mediaFile = findMediaFile("video", "../../media/resources/test");
+            var type = mimeTypeForExtension(mediaFile.split('.').pop());
+            video.src = "" + mediaFile + "&type=" + type;
+            video.play();
+        }
+    </script>
+
+    <video crossorigin></video>
+    <canvas></canvas>
+  </body>
+</head>

Modified: trunk/Source/WebCore/ChangeLog (119693 => 119694)


--- trunk/Source/WebCore/ChangeLog	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebCore/ChangeLog	2012-06-07 08:48:25 UTC (rev 119694)
@@ -1,3 +1,20 @@
+2012-06-07  Ami Fischman  <[email protected]>
+
+        Plumb CORS attribute information from HTMLMediaElement to media players so it can be used
+        https://bugs.webkit.org/show_bug.cgi?id=88349
+
+        Reviewed by Adam Barth.
+
+        Test: http/tests/security/video-cross-origin-readback.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerCORSMode):
+        (WebCore):
+        * html/HTMLMediaElement.h:
+        (HTMLMediaElement):
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayerClient::mediaPlayerCORSMode):
+
 2012-06-07  Hironori Bono  <[email protected]>
 
         Use light gray for grammar markers on Windows and Linux

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (119693 => 119694)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-06-07 08:48:25 UTC (rev 119694)
@@ -4456,6 +4456,15 @@
 
 }
 
+MediaPlayerClient::CORSMode HTMLMediaElement::mediaPlayerCORSMode() const
+{
+    if (!fastHasAttribute(HTMLNames::crossoriginAttr))
+        return Unspecified;
+    if (equalIgnoringCase(fastGetAttribute(HTMLNames::crossoriginAttr), "use-credentials"))
+        return UseCredentials;
+    return Anonymous;
+}
+
 bool HTMLMediaElement::mediaPlayerNeedsSiteSpecificHacks() const
 {
     Settings* settings = document()->settings();

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (119693 => 119694)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2012-06-07 08:48:25 UTC (rev 119694)
@@ -427,6 +427,7 @@
 
     virtual String mediaPlayerReferrer() const OVERRIDE;
     virtual String mediaPlayerUserAgent() const OVERRIDE;
+    virtual CORSMode mediaPlayerCORSMode() const OVERRIDE;
 
     virtual bool mediaPlayerNeedsSiteSpecificHacks() const OVERRIDE;
     virtual String mediaPlayerDocumentHost() const OVERRIDE;

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp (119693 => 119694)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp	2012-06-07 08:48:25 UTC (rev 119694)
@@ -77,11 +77,12 @@
     if (!video || !canvas()->originClean())
         return false;
 
-    if (wouldTaintOrigin(video->currentSrc()))
+    if (!video->hasSingleSecurityOrigin())
         return true;
 
-    if (!video->hasSingleSecurityOrigin())
+    if (!(video->player() && video->player()->didPassCORSAccessCheck()) && wouldTaintOrigin(video->currentSrc()))
         return true;
+
 #else
     UNUSED_PARAM(video);
 #endif

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (119693 => 119694)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2012-06-07 08:48:25 UTC (rev 119694)
@@ -834,6 +834,11 @@
     return m_private->hasSingleSecurityOrigin();
 }
 
+bool MediaPlayer::didPassCORSAccessCheck() const
+{
+    return m_private->didPassCORSAccessCheck();
+}
+
 MediaPlayer::MovieLoadType MediaPlayer::movieLoadType() const
 {
     return m_private->movieLoadType();

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (119693 => 119694)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2012-06-07 08:48:25 UTC (rev 119694)
@@ -101,6 +101,8 @@
 
 class MediaPlayerClient {
 public:
+    enum CORSMode { Unspecified, Anonymous, UseCredentials };
+
     virtual ~MediaPlayerClient() { }
 
     // Get the document which the media player is owned by
@@ -178,6 +180,7 @@
 
     virtual String mediaPlayerReferrer() const { return String(); }
     virtual String mediaPlayerUserAgent() const { return String(); }
+    virtual CORSMode mediaPlayerCORSMode() const { return Unspecified; }
 };
 
 class MediaPlayerSupportsTypeClient {
@@ -354,6 +357,8 @@
 
     bool hasSingleSecurityOrigin() const;
 
+    bool didPassCORSAccessCheck() const;
+
     float mediaTimeForTimeValue(float) const;
 
     double maximumDurationToCacheMediaTime() const;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (119693 => 119694)


--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2012-06-07 08:48:25 UTC (rev 119694)
@@ -135,6 +135,8 @@
 
     virtual bool hasSingleSecurityOrigin() const { return false; }
 
+    virtual bool didPassCORSAccessCheck() const { return false; }
+
     virtual MediaPlayer::MovieLoadType movieLoadType() const { return MediaPlayer::Unknown; }
 
     virtual void prepareForRendering() { }

Modified: trunk/Source/WebKit/chromium/ChangeLog (119693 => 119694)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-06-07 08:48:25 UTC (rev 119694)
@@ -1,3 +1,15 @@
+2012-06-07  Ami Fischman  <[email protected]>
+
+        Plumb CORS attribute information from HTMLMediaElement to media players so it can be used
+        https://bugs.webkit.org/show_bug.cgi?id=88349
+
+        Reviewed by Adam Barth.
+
+        * public/WebMediaPlayer.h:
+        (WebMediaPlayer):
+        * src/WebMediaPlayerClientImpl.cpp:
+        (WebKit::WebMediaPlayerClientImpl::loadInternal):
+
 2012-06-07  Yoshifumi Inoue  <[email protected]>
 
         [Platform] Introduce conversion from/to Deciaml to/from double and helper functions

Modified: trunk/Source/WebKit/chromium/public/WebMediaPlayer.h (119693 => 119694)


--- trunk/Source/WebKit/chromium/public/WebMediaPlayer.h	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebKit/chromium/public/WebMediaPlayer.h	2012-06-07 08:48:25 UTC (rev 119694)
@@ -108,7 +108,7 @@
 
     virtual ~WebMediaPlayer() {}
 
-    virtual void load(const WebURL&) = 0;
+    virtual void load(const WebURL&, CORSMode) = 0;
     virtual void cancelLoad() = 0;
 
     // Playback controls.
@@ -154,6 +154,7 @@
     virtual unsigned long long totalBytes() const = 0;
 
     virtual bool hasSingleSecurityOrigin() const = 0;
+    virtual bool didPassCORSAccessCheck() const = 0;
     virtual MovieLoadType movieLoadType() const = 0;
 
     virtual float mediaTimeForTimeValue(float timeValue) const = 0;

Modified: trunk/Source/WebKit/chromium/src/AssertMatchingEnums.cpp (119693 => 119694)


--- trunk/Source/WebKit/chromium/src/AssertMatchingEnums.cpp	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebKit/chromium/src/AssertMatchingEnums.cpp	2012-06-07 08:48:25 UTC (rev 119694)
@@ -581,3 +581,7 @@
 COMPILE_ASSERT_MATCHING_ENUM(WebURLResponse::HTTP_0_9, ResourceResponse::HTTP_0_9);
 COMPILE_ASSERT_MATCHING_ENUM(WebURLResponse::HTTP_1_0, ResourceResponse::HTTP_1_0);
 COMPILE_ASSERT_MATCHING_ENUM(WebURLResponse::HTTP_1_1, ResourceResponse::HTTP_1_1);
+
+COMPILE_ASSERT_MATCHING_ENUM(WebMediaPlayer::CORSModeUnspecified, MediaPlayerClient::Unspecified);
+COMPILE_ASSERT_MATCHING_ENUM(WebMediaPlayer::CORSModeAnonymous, MediaPlayerClient::Anonymous);
+COMPILE_ASSERT_MATCHING_ENUM(WebMediaPlayer::CORSModeUseCredentials, MediaPlayerClient::UseCredentials);

Modified: trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp (119693 => 119694)


--- trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp	2012-06-07 08:48:25 UTC (rev 119694)
@@ -318,7 +318,9 @@
         // Make sure if we create/re-create the WebMediaPlayer that we update our wrapper.
         m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider());
 #endif
-        m_webMediaPlayer->load(KURL(ParsedURLString, m_url));
+        m_webMediaPlayer->load(
+            KURL(ParsedURLString, m_url),
+            static_cast<WebMediaPlayer::CORSMode>(m_mediaPlayer->mediaPlayerClient()->mediaPlayerCORSMode()));
     }
 }
 
@@ -662,6 +664,13 @@
     return false;
 }
 
+bool WebMediaPlayerClientImpl::didPassCORSAccessCheck() const
+{
+    if (m_webMediaPlayer)
+        return m_webMediaPlayer->didPassCORSAccessCheck();
+    return false;
+}
+
 MediaPlayer::MovieLoadType WebMediaPlayerClientImpl::movieLoadType() const
 {
     if (m_webMediaPlayer)

Modified: trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h (119693 => 119694)


--- trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h	2012-06-07 08:28:10 UTC (rev 119693)
+++ trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h	2012-06-07 08:48:25 UTC (rev 119694)
@@ -131,6 +131,7 @@
     virtual void paintCurrentFrameInContext(WebCore::GraphicsContext*, const WebCore::IntRect&);
     virtual void setPreload(WebCore::MediaPlayer::Preload);
     virtual bool hasSingleSecurityOrigin() const;
+    virtual bool didPassCORSAccessCheck() const;
     virtual WebCore::MediaPlayer::MovieLoadType movieLoadType() const;
     virtual float mediaTimeForTimeValue(float timeValue) const;
     virtual unsigned decodedFrameCount() const;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to