[iOS] <video> element requests are missing session cookies; sometimes persistant...
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Aug 2014 00:36:33 +0000 (00:36 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Aug 2014 00:36:33 +0000 (00:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135816

Reviewed by Alexey Proskuryakov.

On iOS, the AVFoundation framework will copy appropriate cookies for the requested URL across to the
mediaserverd process. For WebKit2, the WebProcess does not have access to session cookies for the
current browsing session. When creating an AVURLAsset, fetch the appropriate cookies for the requested
URL, and pass them into AVURLAsset in the options dictionary.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerGetRawCookies): Call CookieJar's equivalent method.
* html/HTMLMediaElement.h:
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::getRawCookies): Pass to HTMLMediaElement.
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaPlayerGetRawCookies):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::toNSHTTPCookie): Convert a WebCore Cookie -> NSHTTPCookie.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL): Fetch cookies for the requested
    URL, and if successful, add them to the AVURLAsset options dictionary.

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

index 463b3ab..b4ed872 100644 (file)
@@ -1,3 +1,27 @@
+2014-08-11  Jer Noble  <jer.noble@apple.com>
+
+        [iOS] <video> element requests are missing session cookies; sometimes persistant cookies.
+        https://bugs.webkit.org/show_bug.cgi?id=135816
+
+        Reviewed by Alexey Proskuryakov.
+
+        On iOS, the AVFoundation framework will copy appropriate cookies for the requested URL across to the
+        mediaserverd process. For WebKit2, the WebProcess does not have access to session cookies for the 
+        current browsing session. When creating an AVURLAsset, fetch the appropriate cookies for the requested
+        URL, and pass them into AVURLAsset in the options dictionary.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerGetRawCookies): Call CookieJar's equivalent method.
+        * html/HTMLMediaElement.h:
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::getRawCookies): Pass to HTMLMediaElement.
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayerClient::mediaPlayerGetRawCookies):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::toNSHTTPCookie): Convert a WebCore Cookie -> NSHTTPCookie.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL): Fetch cookies for the requested
+            URL, and if successful, add them to the AVURLAsset options dictionary.
+
 2014-08-11  Roger Fong  <roger_fong@apple.com>
 
         Adjustments to CueBox CSS Width calculations Part 2.
index eae5fc8..2d58074 100644 (file)
@@ -37,6 +37,7 @@
 #include "ClientRectList.h"
 #include "ContentSecurityPolicy.h"
 #include "ContentType.h"
+#include "CookieJar.h"
 #include "DiagnosticLoggingKeys.h"
 #include "DisplaySleepDisabler.h"
 #include "DocumentLoader.h"
@@ -5744,6 +5745,11 @@ String HTMLMediaElement::mediaPlayerNetworkInterfaceName() const
 
     return settings->networkInterfaceName();
 }
+
+bool HTMLMediaElement::mediaPlayerGetRawCookies(const URL& url, Vector<Cookie>& cookies) const
+{
+    return getRawCookies(&document(), url, cookies);
+}
 #endif
     
 void HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture()
index 08a18e6..3d1ef8b 100644 (file)
@@ -572,6 +572,7 @@ private:
 
 #if PLATFORM(IOS)
     virtual String mediaPlayerNetworkInterfaceName() const;
+    virtual bool mediaPlayerGetRawCookies(const URL&, Vector<Cookie>&) const override;
 #endif
 
     void loadTimerFired(Timer<HTMLMediaElement>&);
index c27b591..796a65f 100644 (file)
@@ -1428,6 +1428,14 @@ String MediaPlayer::mediaPlayerNetworkInterfaceName() const
 
     return m_mediaPlayerClient->mediaPlayerNetworkInterfaceName();
 }
+
+bool MediaPlayer::getRawCookies(const URL& url, Vector<Cookie>& cookies) const
+{
+    if (!m_mediaPlayerClient)
+        return false;
+
+    return m_mediaPlayerClient->mediaPlayerGetRawCookies(url, cookies);
+}
 #endif
 
 }
index f21778e..1bb85d7 100644 (file)
@@ -76,6 +76,7 @@ class MediaSourcePrivateClient;
 #endif
 class MediaPlayerPrivateInterface;
 class TextTrackRepresentation;
+struct Cookie;
 
 // Structure that will hold every native
 // types supported by the current media player.
@@ -264,6 +265,7 @@ public:
 
 #if PLATFORM(IOS)
     virtual String mediaPlayerNetworkInterfaceName() const { return String(); }
+    virtual bool mediaPlayerGetRawCookies(const URL&, Vector<Cookie>&) const { return false; }
 #endif
     
     virtual bool mediaPlayerShouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge&) { return false; }
@@ -560,6 +562,7 @@ public:
 
 #if PLATFORM(IOS)
     String mediaPlayerNetworkInterfaceName() const;
+    bool getRawCookies(const URL&, Vector<Cookie>&) const;
 #endif
 
     static void resetMediaEngines();
index b589a3f..0a7885e 100644 (file)
@@ -33,6 +33,7 @@
 #import "AuthenticationChallenge.h"
 #import "BlockExceptions.h"
 #import "CDMSessionAVFoundationObjC.h"
+#import "Cookie.h"
 #import "ExceptionCodePlaceholder.h"
 #import "FloatConversion.h"
 #import "FloatConversion.h"
@@ -228,6 +229,7 @@ SOFT_LINK_POINTER(AVFoundation, AVPlayerItemLegibleOutputTextStylingResolutionSo
 #endif
 
 #if ENABLE(AVF_CAPTIONS)
+SOFT_LINK_POINTER(AVFoundation, AVURLAssetHTTPCookiesKey, NSString*)
 SOFT_LINK_POINTER(AVFoundation, AVURLAssetOutOfBandAlternateTracksKey, NSString*)
 SOFT_LINK_POINTER(AVFoundation, AVOutOfBandAlternateTrackDisplayNameKey, NSString*)
 SOFT_LINK_POINTER(AVFoundation, AVOutOfBandAlternateTrackExtendedLanguageTagKey, NSString*)
@@ -238,6 +240,7 @@ SOFT_LINK_POINTER(AVFoundation, AVOutOfBandAlternateTrackSourceKey, NSString*)
 SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicDescribesMusicAndSoundForAccessibility, NSString*)
 SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicTranscribesSpokenDialogForAccessibility, NSString*)
 
+#define AVURLAssetHTTPCookiesKey getAVURLAssetHTTPCookiesKey()
 #define AVURLAssetOutOfBandAlternateTracksKey getAVURLAssetOutOfBandAlternateTracksKey()
 #define AVOutOfBandAlternateTrackDisplayNameKey getAVOutOfBandAlternateTrackDisplayNameKey()
 #define AVOutOfBandAlternateTrackExtendedLanguageTagKey getAVOutOfBandAlternateTrackExtendedLanguageTagKey()
@@ -712,6 +715,24 @@ static NSURL *canonicalURL(const String& url)
     return [canonicalRequest URL];
 }
 
+static NSHTTPCookie* toNSHTTPCookie(const Cookie& cookie)
+{
+    RetainPtr<NSMutableDictionary> properties = adoptNS([[NSMutableDictionary alloc] init]);
+    [properties setDictionary:@{
+        NSHTTPCookieName: cookie.name,
+        NSHTTPCookieValue: cookie.value,
+        NSHTTPCookieDomain: cookie.domain,
+        NSHTTPCookiePath: cookie.path,
+        NSHTTPCookieExpires: [NSDate dateWithTimeIntervalSince1970:(cookie.expires / 1000)],
+    }];
+    if (cookie.secure)
+        [properties setObject:@YES forKey:NSHTTPCookieSecure];
+    if (cookie.session)
+        [properties setObject:@YES forKey:NSHTTPCookieDiscard];
+
+    return [NSHTTPCookie cookieWithProperties:properties.get()];
+}
+
 void MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL(const String& url)
 {
     if (m_avAsset)
@@ -774,6 +795,17 @@ void MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL(const String& url)
         [options setObject:networkInterfaceName forKey:AVURLAssetBoundNetworkInterfaceName];
 #endif
 
+#if PLATFORM(IOS)
+    Vector<Cookie> cookies;
+    if (player()->getRawCookies(URL(ParsedURLString, url), cookies)) {
+        RetainPtr<NSMutableArray> nsCookies = adoptNS([[NSMutableArray alloc] initWithCapacity:cookies.size()]);
+        for (auto& cookie : cookies)
+            [nsCookies addObject:toNSHTTPCookie(cookie)];
+
+        [options setObject:nsCookies.get() forKey:AVURLAssetHTTPCookiesKey];
+    }
+#endif
+
     NSURL *cocoaURL = canonicalURL(url);
     m_avAsset = adoptNS([[AVURLAsset alloc] initWithURL:cocoaURL options:options.get()]);