WKWebsiteDataStore should conform to NSCoding
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Feb 2016 22:08:09 +0000 (22:08 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Feb 2016 22:08:09 +0000 (22:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154605

Reviewed by Dan Bernstein.

Source/WebKit2:

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

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm:
(TEST):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm

index eb3240f..d0c0a7f 100644 (file)
@@ -1,5 +1,17 @@
 2016-02-23  Anders Carlsson  <andersca@apple.com>
 
+        WKWebsiteDataStore should conform to NSCoding
+        https://bugs.webkit.org/show_bug.cgi?id=154605
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.h:
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore initWithCoder:]):
+        (-[WKWebsiteDataStore encodeWithCoder:]):
+
+2016-02-23  Anders Carlsson  <andersca@apple.com>
+
         Fix iOS build.
 
         * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
index 32a828f..426c2b2 100644 (file)
@@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
  IndexedDB databases, and local storage.
  */
 WK_CLASS_AVAILABLE(10_11, 9_0)
-@interface WKWebsiteDataStore : NSObject
+@interface WKWebsiteDataStore : NSObject <NSCoding>
 
 /* @abstract Returns the default data store. */
 + (WKWebsiteDataStore *)defaultDataStore;
index c737aa8..3a49fb1 100644 (file)
     [super dealloc];
 }
 
+- (instancetype)initWithCoder:(NSCoder *)coder
+{
+    if (!(self = [super init]))
+        return nil;
+
+    RetainPtr<WKWebsiteDataStore> dataStore;
+    if ([coder decodeBoolForKey:@"isDefaultDataStore"])
+        dataStore = [WKWebsiteDataStore defaultDataStore];
+    else
+        dataStore = [WKWebsiteDataStore nonPersistentDataStore];
+
+    [self release];
+
+    return dataStore.leakRef();
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+    if (self == [WKWebsiteDataStore defaultDataStore]) {
+        [coder encodeBool:YES forKey:@"isDefaultDataStore"];
+        return;
+    }
+
+    ASSERT(!self.persistent);
+}
+
 - (BOOL)isPersistent
 {
     return _websiteDataStore->isPersistent();
index 727f3c5..af91ede 100644 (file)
@@ -1,5 +1,15 @@
 2016-02-23  Anders Carlsson  <andersca@apple.com>
 
+        WKWebsiteDataStore should conform to NSCoding
+        https://bugs.webkit.org/show_bug.cgi?id=154605
+
+        Reviewed by Dan Bernstein.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm:
+        (TEST):
+
+2016-02-23  Anders Carlsson  <andersca@apple.com>
+
         WKWebViewConfiguration should conform to NSCoding
         https://bugs.webkit.org/show_bug.cgi?id=154602
 
index 099d827..be14ed4 100644 (file)
@@ -65,6 +65,18 @@ TEST(Coding, WKPreferences)
 #endif
 }
 
+TEST(Coding, WKWebsiteDataStore_Default)
+{
+    auto a = encodeAndDecode([WKWebsiteDataStore defaultDataStore]);
+    EXPECT_EQ([WKWebsiteDataStore defaultDataStore], a.get());
+}
+
+TEST(Coding, WKWebsiteDataStore_NonPersistent)
+{
+    auto a = encodeAndDecode([WKWebsiteDataStore nonPersistentDataStore]);
+    EXPECT_FALSE([a isPersistent]);
+}
+
 TEST(Coding, WKWebViewConfiguration)
 {
     auto a = adoptNS([[WKWebViewConfiguration alloc] init]);