_WKResourceLoadInfo should conform to NSSecureCoding
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Feb 2020 23:10:46 +0000 (23:10 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Feb 2020 23:10:46 +0000 (23:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207667

Reviewed by Brady Eidson.

Source/WebKit:

This makes rdar://problem/57132290 nicer.
Covered by API tests.

* UIProcess/API/Cocoa/_WKResourceLoadInfo.h:
* UIProcess/API/Cocoa/_WKResourceLoadInfo.mm:
(+[_WKResourceLoadInfo supportsSecureCoding]):
(-[_WKResourceLoadInfo initWithCoder:]):
(-[_WKResourceLoadInfo encodeWithCoder:]):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIResourceLoadInfo.h
Source/WebKit/UIProcess/API/Cocoa/_WKResourceLoadInfo.h
Source/WebKit/UIProcess/API/Cocoa/_WKResourceLoadInfo.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm

index 9afb74a..ef607fc 100644 (file)
@@ -1,5 +1,21 @@
 2020-02-13  Alex Christensen  <achristensen@webkit.org>
 
+        _WKResourceLoadInfo should conform to NSSecureCoding
+        https://bugs.webkit.org/show_bug.cgi?id=207667
+
+        Reviewed by Brady Eidson.
+
+        This makes rdar://problem/57132290 nicer.
+        Covered by API tests.
+
+        * UIProcess/API/Cocoa/_WKResourceLoadInfo.h:
+        * UIProcess/API/Cocoa/_WKResourceLoadInfo.mm:
+        (+[_WKResourceLoadInfo supportsSecureCoding]):
+        (-[_WKResourceLoadInfo initWithCoder:]):
+        (-[_WKResourceLoadInfo encodeWithCoder:]):
+
+2020-02-13  Alex Christensen  <achristensen@webkit.org>
+
         Deprecate _WKUserContentWorld replaced by WKContentWorld
         https://bugs.webkit.org/show_bug.cgi?id=207514
 
index 21bdb6b..6f86601 100644 (file)
@@ -37,16 +37,14 @@ public:
         return adoptRef(*new ResourceLoadInfo(WTFMove(info)));
     }
 
+    explicit ResourceLoadInfo(WebKit::ResourceLoadInfo&& info)
+        : m_info(WTFMove(info)) { }
+
     WebKit::NetworkResourceLoadIdentifier resourceLoadID() const { return m_info.resourceLoadID; }
     Optional<WebCore::FrameIdentifier> frameID() const { return m_info.frameID; }
     Optional<WebCore::FrameIdentifier> parentFrameID() const { return m_info.parentFrameID; }
 
 private:
-    explicit ResourceLoadInfo(WebKit::ResourceLoadInfo&& info)
-        : m_info(WTFMove(info))
-    {
-    }
-
     const WebKit::ResourceLoadInfo m_info;
 
 };
index 39f6c64..3260840 100644 (file)
@@ -30,7 +30,7 @@
 NS_ASSUME_NONNULL_BEGIN
 
 WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
-@interface _WKResourceLoadInfo : NSObject
+@interface _WKResourceLoadInfo : NSObject <NSSecureCoding>
 
 + (instancetype)new NS_UNAVAILABLE;
 - (instancetype)init NS_UNAVAILABLE;
index 8fb8cd3..0d38690 100644 (file)
@@ -28,6 +28,7 @@
 
 #import "APIFrameHandle.h"
 #import "APIResourceLoadInfo.h"
+#import "ResourceLoadInfo.h"
 #import "_WKFrameHandleInternal.h"
 #import "_WKResourceLoadInfoInternal.h"
 
     return *_info;
 }
 
++ (BOOL)supportsSecureCoding
+{
+    return YES;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)coder
+{
+    if (!(self = [super init]))
+        return nil;
+
+    NSNumber *resourceLoadID = [coder decodeObjectOfClass:[NSNumber class] forKey:@"resourceLoadID"];
+    if (!resourceLoadID) {
+        [self release];
+        return nil;
+    }
+
+    NSNumber *frame = [coder decodeObjectOfClass:[NSNumber class] forKey:@"frame"];
+    if (!frame) {
+        [self release];
+        return nil;
+    }
+
+    NSNumber *parentFrame = [coder decodeObjectOfClass:[NSNumber class] forKey:@"parentFrame"];
+    if (!parentFrame) {
+        [self release];
+        return nil;
+    }
+
+    WebKit::ResourceLoadInfo info {
+        makeObjectIdentifier<WebKit::NetworkResourceLoadIdentifierType>(resourceLoadID.unsignedLongLongValue),
+        makeObjectIdentifier<WebCore::FrameIdentifierType>(frame.unsignedLongLongValue),
+        makeObjectIdentifier<WebCore::FrameIdentifierType>(parentFrame.unsignedLongLongValue)
+    };
+
+    API::Object::constructInWrapper<API::ResourceLoadInfo>(self, WTFMove(info));
+
+    return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+    [coder encodeObject:@(self.resourceLoadID) forKey:@"resourceLoadID"];
+    [coder encodeObject:@(self.frame.frameID) forKey:@"frame"];
+    [coder encodeObject:@(self.parentFrame.frameID) forKey:@"parentFrame"];
+}
+
 @end
 
index 056fe8e..1be74ff 100644 (file)
@@ -1,3 +1,13 @@
+2020-02-13  Alex Christensen  <achristensen@webkit.org>
+
+        _WKResourceLoadInfo should conform to NSSecureCoding
+        https://bugs.webkit.org/show_bug.cgi?id=207667
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
+        (TEST):
+
 2020-02-13  Stephan Szabo  <stephan.szabo@sony.com>
 
         [PlayStation] Add Buildbots for Debug/Release builds
index eec46de..844a279 100644 (file)
@@ -305,6 +305,17 @@ TEST(ResourceLoadDelegate, LoadInfo)
     EXPECT_WK_STREQ(NSStringFromClass([otherParameters[7] class]), "NSHTTPURLResponse");
     EXPECT_WK_STREQ([otherParameters[7] URL].path, "/fetchTarget");
     EXPECT_EQ(otherParameters[8], nil);
+    
+    _WKResourceLoadInfo *original = loadInfos[0].get();
+    NSError *error = nil;
+    NSData *archiveData = [NSKeyedArchiver archivedDataWithRootObject:original requiringSecureCoding:YES error:&error];
+    EXPECT_EQ(archiveData.length, 299ull);
+    EXPECT_FALSE(error);
+    _WKResourceLoadInfo *deserialized = [NSKeyedUnarchiver unarchivedObjectOfClass:[_WKResourceLoadInfo class] fromData:archiveData error:&error];
+    EXPECT_FALSE(error);
+    EXPECT_TRUE(deserialized.resourceLoadID == original.resourceLoadID);
+    EXPECT_TRUE(deserialized.frame.frameID == original.frame.frameID);
+    EXPECT_TRUE(deserialized.parentFrame.frameID == original.parentFrame.frameID);
 }
 
 #endif // HAVE(NETWORK_FRAMEWORK)