[Mac][WK2] Unable to play video protected by session cookies
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jan 2014 18:29:18 +0000 (18:29 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jan 2014 18:29:18 +0000 (18:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127207

Reviewed by Sam Weinig.

Recent changes in our underlying media frameworks caused our shimmed methods
in CookieStorageShim to stop being called. Insert an objective-c shim in addition
to our original shim to intercept pulling cookies out of cookie storage.

* Shared/mac/CookieStorageShim.mm: Renamed from Source/WebKit2/Shared/mac/CookieStorageShim.cpp.
(WebKit::CookieStorageShim::initialize): Insert the shim.
(-[WKNSURLSessionLocal _copyCookiesForRequestUsingAllAppropriateStorageSemantics:]):
    Pass through to webKitCookieStorageCopyRequestHeaderFieldsForURL().
* WebKit2.xcodeproj/project.pbxproj: Rename CookieStorageShim.cpp -> .mm.

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/CookieStorageShim.mm [moved from Source/WebKit2/Shared/mac/CookieStorageShim.cpp with 72% similarity]
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index 328ea13..bc9889c 100644 (file)
@@ -1,3 +1,20 @@
+2014-01-22  Jer Noble  <jer.noble@apple.com>
+
+        [Mac][WK2] Unable to play video protected by session cookies
+        https://bugs.webkit.org/show_bug.cgi?id=127207
+
+        Reviewed by Sam Weinig.
+
+        Recent changes in our underlying media frameworks caused our shimmed methods
+        in CookieStorageShim to stop being called. Insert an objective-c shim in addition
+        to our original shim to intercept pulling cookies out of cookie storage.
+
+        * Shared/mac/CookieStorageShim.mm: Renamed from Source/WebKit2/Shared/mac/CookieStorageShim.cpp.
+        (WebKit::CookieStorageShim::initialize): Insert the shim.
+        (-[WKNSURLSessionLocal _copyCookiesForRequestUsingAllAppropriateStorageSemantics:]):
+            Pass through to webKitCookieStorageCopyRequestHeaderFieldsForURL().
+        * WebKit2.xcodeproj/project.pbxproj: Rename CookieStorageShim.cpp -> .mm.
+
 2014-01-22  Yongjun Zhang  <yongjun_zhang@apple.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=127380
 #include "WebCoreArgumentCoders.h"
 #include "WebProcess.h"
 #include <WebCore/URL.h>
+#include <WebCore/SoftLinking.h>
 #include <dlfcn.h>
 #include <wtf/MainThread.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/text/WTFString.h>
 
+typedef const struct _CFURLRequest* CFURLRequestRef;
+
+SOFT_LINK_FRAMEWORK(CFNetwork)
+SOFT_LINK(CFNetwork, CFURLRequestGetURL, CFURLRef, (CFURLRequestRef request), (request))
+
 using namespace WebCore;
 
+@interface WKNSURLSessionLocal : NSObject
+- (CFDictionaryRef) _copyCookiesForRequestUsingAllAppropriateStorageSemantics:(CFURLRequestRef) request;
+@end
+
 namespace WebKit {
 
 static CFDictionaryRef webKitCookieStorageCopyRequestHeaderFieldsForURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inRequestURL)
@@ -69,8 +79,28 @@ void CookieStorageShim::initialize()
     CookieStorageShimInitializeFunc func = reinterpret_cast<CookieStorageShimInitializeFunc>(dlsym(RTLD_DEFAULT, "WebKitCookieStorageShimInitialize"));
     if (func)
         func(callbacks);
+
+    Class __NSURLSessionLocalClass = objc_getClass("__NSURLSessionLocal");
+    if (!__NSURLSessionLocalClass)
+        return;
+
+    Method original = class_getInstanceMethod(__NSURLSessionLocalClass, @selector(_copyCookiesForRequestUsingAllAppropriateStorageSemantics:));
+    if (!original)
+        return;
+
+    Method replacement = class_getInstanceMethod([WKNSURLSessionLocal class], @selector(_copyCookiesForRequestUsingAllAppropriateStorageSemantics:));
+    ASSERT(replacement);
+
+    method_exchangeImplementations(original, replacement);
 }
 
 }
 
+@implementation WKNSURLSessionLocal
+- (CFDictionaryRef)_copyCookiesForRequestUsingAllAppropriateStorageSemantics:(CFURLRequestRef) request
+{
+    return WebKit::webKitCookieStorageCopyRequestHeaderFieldsForURL(nullptr, CFURLRequestGetURL(request));
+}
+@end
+
 #endif // ENABLE(NETWORK_PROCESS)
index a20b4c1..52abc1d 100644 (file)
                CDC38307172117DD008A2FC3 /* CookieStorageShimLibrary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDC382F9172116D3008A2FC3 /* CookieStorageShimLibrary.cpp */; };
                CDC3830817211890008A2FC3 /* WebProcessShim.dylib in Copy WebProcessShim */ = {isa = PBXBuildFile; fileRef = CDC3830617211799008A2FC3 /* WebProcessShim.dylib */; };
                CDC3830C17212282008A2FC3 /* CookieStorageShimLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC3830B172121CE008A2FC3 /* CookieStorageShimLibrary.h */; };
-               CDC3831017212440008A2FC3 /* CookieStorageShim.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDC3830D1721242D008A2FC3 /* CookieStorageShim.cpp */; };
+               CDC3831017212440008A2FC3 /* CookieStorageShim.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC3830D1721242D008A2FC3 /* CookieStorageShim.mm */; };
                CDCA85C8132ABA4E00E961DF /* WKFullScreenWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */; };
                CDCA85C9132ABA4E00E961DF /* WKFullScreenWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */; };
                CEDA12E2152CD1AE00D9E08D /* WebAlternativeTextClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEDA12DF152CCAE800D9E08D /* WebAlternativeTextClient.cpp */; };
                CDC382F9172116D3008A2FC3 /* CookieStorageShimLibrary.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CookieStorageShimLibrary.cpp; sourceTree = "<group>"; };
                CDC3830617211799008A2FC3 /* WebProcessShim.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = WebProcessShim.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
                CDC3830B172121CE008A2FC3 /* CookieStorageShimLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CookieStorageShimLibrary.h; sourceTree = "<group>"; };
-               CDC3830D1721242D008A2FC3 /* CookieStorageShim.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CookieStorageShim.cpp; sourceTree = "<group>"; };
+               CDC3830D1721242D008A2FC3 /* CookieStorageShim.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieStorageShim.mm; sourceTree = "<group>"; };
                CDC3830E1721242D008A2FC3 /* CookieStorageShim.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CookieStorageShim.h; sourceTree = "<group>"; };
                CDC8F4881725E67800166F6E /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
                CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKFullScreenWindowController.mm; sourceTree = "<group>"; };
                                1A2A4AFE158693920090C9E9 /* ColorSpaceData.h */,
                                1A2A4AFD158693920090C9E9 /* ColorSpaceData.mm */,
                                1A6F9FB611E1408500DB1371 /* CommandLineMac.cpp */,
-                               CDC3830D1721242D008A2FC3 /* CookieStorageShim.cpp */,
+                               CDC3830D1721242D008A2FC3 /* CookieStorageShim.mm */,
                                CDC3830E1721242D008A2FC3 /* CookieStorageShim.h */,
                                CDC382F9172116D3008A2FC3 /* CookieStorageShimLibrary.cpp */,
                                CDC3830B172121CE008A2FC3 /* CookieStorageShimLibrary.h */,
                                378E1A4D18208D700031007A /* WKNSURL.mm in Sources */,
                                515E772F184015800007203F /* UniqueIDBDatabase.cpp in Sources */,
                                2DA049B3180CCCD300AAFA9E /* PlatformCALayerRemote.cpp in Sources */,
-                               CDC3831017212440008A2FC3 /* CookieStorageShim.cpp in Sources */,
+                               CDC3831017212440008A2FC3 /* CookieStorageShim.mm in Sources */,
                                B878B616133428DC006888E9 /* CorrectionPanel.mm in Sources */,
                                2989A411167D1834004F96D2 /* CustomProtocolManagerMac.mm in Sources */,
                                2984F588164BA095004BC0C6 /* CustomProtocolManagerMessageReceiver.cpp in Sources */,