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

Reviewed by Sam Weinig.

Source/WebKit2:

Add NSCoding implementation.

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

Tools:

Test encoding and decoding WKPreferences.

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

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKPreferences.h
Source/WebKit2/UIProcess/API/Cocoa/WKPreferences.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm [new file with mode: 0644]

index fa3cd67..b80c832 100644 (file)
@@ -1,3 +1,17 @@
+2016-02-23  Anders Carlsson  <andersca@apple.com>
+
+        WKPreferences should conform to NSCoding
+        https://bugs.webkit.org/show_bug.cgi?id=154597
+
+        Reviewed by Sam Weinig.
+
+        Add NSCoding implementation.
+
+        * UIProcess/API/Cocoa/WKPreferences.h:
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences encodeWithCoder:]):
+        (-[WKPreferences initWithCoder:]):
+
 2016-02-23  Alex Christensen  <achristensen@webkit.org>
 
         Implement downloads with NetworkSession
index 6603a89..9ab8e98 100644 (file)
@@ -35,7 +35,7 @@
  its web view configuration.
  */
 WK_CLASS_AVAILABLE(10_10, 8_0)
-@interface WKPreferences : NSObject
+@interface WKPreferences : NSObject <NSCoding>
 
 /*! @abstract The minimum font size in points.
  @discussion The default value is 0.
index ed9156d..cb96bab 100644 (file)
     [super dealloc];
 }
 
+// FIXME: We currently only encode/decode API preferences. We should consider whether we should
+// encode/decode SPI preferences as well.
+
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+    [coder encodeDouble:self.minimumFontSize forKey:@"minimumFontSize"];
+    [coder encodeBool:self.javaScriptEnabled forKey:@"javaScriptEnabled"];
+    [coder encodeBool:self.javaScriptCanOpenWindowsAutomatically forKey:@"javaScriptCanOpenWindowsAutomatically"];
+
+#if PLATFORM(MAC)
+    [coder encodeBool:self.javaEnabled forKey:@"javaEnabled"];
+    [coder encodeBool:self.plugInsEnabled forKey:@"plugInsEnabled"];
+#endif
+}
+
+- (instancetype)initWithCoder:(NSCoder *)coder
+{
+    if (!(self = [self init]))
+        return nil;
+
+    self.minimumFontSize = [coder decodeDoubleForKey:@"minimumFontSize"];
+    self.javaScriptEnabled = [coder decodeBoolForKey:@"javaScriptEnabled"];
+    self.javaScriptCanOpenWindowsAutomatically = [coder decodeBoolForKey:@"javaScriptCanOpenWindowsAutomatically"];
+
+#if PLATFORM(MAC)
+    self.javaEnabled = [coder decodeBoolForKey:@"javaEnabled"];
+    self.plugInsEnabled = [coder decodeBoolForKey:@"plugInsEnabled"];
+#endif
+
+    return self;
+}
+
 - (CGFloat)minimumFontSize
 {
     return _preferences->minimumFontSize();
index c802348..54f0be7 100644 (file)
@@ -1,5 +1,18 @@
 2016-02-23  Anders Carlsson  <andersca@apple.com>
 
+        WKPreferences should conform to NSCoding
+        https://bugs.webkit.org/show_bug.cgi?id=154597
+
+        Reviewed by Sam Weinig.
+
+        Test encoding and decoding WKPreferences.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm:
+        (encodeAndDecode):
+        (TEST):
+
+2016-02-23  Anders Carlsson  <andersca@apple.com>
+
         Fix build.
 
         * TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.m:
index 6e2bf3b..76918aa 100644 (file)
@@ -21,6 +21,7 @@
                1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93D3D19B17B1A7B000C7C415 /* all-content-in-one-iframe.html */; };
                1A7E8B3618120B2F00AEB74A /* FragmentNavigation.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A7E8B351812093600AEB74A /* FragmentNavigation.html */; };
                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C045F9461385C2F800C0F3CD /* 18-characters.html */; };
+               1AAD19F71C7CE20300831E47 /* Coding.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AAD19F51C7CE20300831E47 /* Coding.mm */; };
                1ADBEFE3130C6AA100D61D19 /* simple-accelerated-compositing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */; };
                1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */; };
                1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB9BC371A67482300FE5678 /* WeakPtr.cpp */; };
                1A7E8B33181208DE00AEB74A /* FragmentNavigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FragmentNavigation.mm; sourceTree = "<group>"; };
                1A7E8B351812093600AEB74A /* FragmentNavigation.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FragmentNavigation.html; sourceTree = "<group>"; };
                1AA9E55714980A9900001A8A /* Functional.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Functional.cpp; sourceTree = "<group>"; };
+               1AAD19F51C7CE20300831E47 /* Coding.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Coding.mm; sourceTree = "<group>"; };
                1ABC3DED1899BE6D004F0626 /* Navigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Navigation.mm; sourceTree = "<group>"; };
                1ADBEFAD130C689C00D61D19 /* ForceRepaint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ForceRepaint.cpp; sourceTree = "<group>"; };
                1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-accelerated-compositing.html"; sourceTree = "<group>"; };
                                A18AA8CC1C3FA218009B2B97 /* ContentFiltering.h */,
                                A14FC5861B8991B600D107EB /* ContentFiltering.mm */,
                                A14FC5891B89927100D107EB /* ContentFilteringPlugIn.mm */,
+                               1AAD19F51C7CE20300831E47 /* Coding.mm */,
                                A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
                                2D8104CB1BEC13E70020DA46 /* FindInPage.mm */,
                                2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */,
                                CD89D03A1C4EDB2A00040A04 /* WebCoreNSURLSession.mm in Sources */,
                                A1C4FB6E1BACCE50003742D0 /* QuickLook.mm in Sources */,
                                7A5623111AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp in Sources */,
+                               1AAD19F71C7CE20300831E47 /* Coding.mm in Sources */,
                                9B0786A31C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp in Sources */,
                                1A4F81CC1BDFFD37004E672E /* RemoteObjectRegistry.mm in Sources */,
                                51CB4AD81B3A079C00C1B1C6 /* ModalAlertsSPI.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm b/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm
new file mode 100644 (file)
index 0000000..ab87f69
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if WK_API_ENABLED
+
+#import <WebKit/WKPreferences.h>
+#import <wtf/RetainPtr.h>
+
+template<typename T>
+RetainPtr<T> encodeAndDecode(T* t)
+{
+    auto data = [NSKeyedArchiver archivedDataWithRootObject:t];
+
+    return [NSKeyedUnarchiver unarchiveObjectWithData:data];
+}
+
+TEST(Coding, WKPreferences)
+{
+    auto a = adoptNS([[WKPreferences alloc] init]);
+
+    // Change all defaults to something else.
+    [a setMinimumFontSize:10];
+    [a setJavaScriptEnabled:NO];
+#if PLATFORM(IOS)
+    [a setJavaScriptCanOpenWindowsAutomatically:YES];
+#else
+    [a setJavaScriptCanOpenWindowsAutomatically:NO];
+    [a setJavaEnabled:YES];
+    [a setPlugInsEnabled:YES];
+#endif
+
+    auto b = encodeAndDecode(a.get());
+
+    EXPECT_EQ([a minimumFontSize], [b minimumFontSize]);
+    EXPECT_EQ([a javaScriptEnabled], [b javaScriptEnabled]);
+    EXPECT_EQ([a javaScriptCanOpenWindowsAutomatically], [b javaScriptCanOpenWindowsAutomatically]);
+
+#if PLATFORM(MAC)
+    EXPECT_EQ([a javaEnabled], [b javaEnabled]);
+    EXPECT_EQ([a plugInsEnabled], [b plugInsEnabled]);
+#endif
+}
+
+#endif