Title: [197004] trunk
Revision
197004
Author
[email protected]
Date
2016-02-23 16:20:01 -0800 (Tue, 23 Feb 2016)

Log Message

WKWebView should implement NSCoding
https://bugs.webkit.org/show_bug.cgi?id=137160
Source/WebKit2:

rdar://problem/17380562

Reviewed by Dan Bernstein.

* UIProcess/API/Cocoa/WKUserContentController.mm:
(-[WKUserContentController initWithCoder:]):
We need to call [self init] here, so that the wrapper will be initialized.

* UIProcess/API/Cocoa/WKWebView.h:
-initWithCoder: shouldn't be unavailable, it should be a designated initializer.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
Move initialization out into a common method.

(-[WKWebView initWithFrame:configuration:]):
Call -initializeWithConfiguration: here.

(-[WKWebView initWithCoder:]):
Decode everything.

(-[WKWebView encodeWithCoder:]):
Encode everything.

Tools:

Reviewed by Dan Bernstein.

Add tests.

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

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (197003 => 197004)


--- trunk/Source/WebKit2/ChangeLog	2016-02-23 23:41:53 UTC (rev 197003)
+++ trunk/Source/WebKit2/ChangeLog	2016-02-24 00:20:01 UTC (rev 197004)
@@ -1,5 +1,33 @@
 2016-02-23  Anders Carlsson  <[email protected]>
 
+        WKWebView should implement NSCoding
+        https://bugs.webkit.org/show_bug.cgi?id=137160
+        rdar://problem/17380562
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/API/Cocoa/WKUserContentController.mm:
+        (-[WKUserContentController initWithCoder:]):
+        We need to call [self init] here, so that the wrapper will be initialized.
+
+        * UIProcess/API/Cocoa/WKWebView.h:
+        -initWithCoder: shouldn't be unavailable, it should be a designated initializer.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        Move initialization out into a common method.
+
+        (-[WKWebView initWithFrame:configuration:]):
+        Call -initializeWithConfiguration: here.
+
+        (-[WKWebView initWithCoder:]):
+        Decode everything.
+
+        (-[WKWebView encodeWithCoder:]):
+        Encode everything.
+
+2016-02-23  Anders Carlsson  <[email protected]>
+
         Fix an API test.
 
         * UIProcess/API/APIWebsiteDataStore.cpp:

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm (197003 => 197004)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm	2016-02-23 23:41:53 UTC (rev 197003)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm	2016-02-24 00:20:01 UTC (rev 197004)
@@ -68,7 +68,7 @@
 
 - (instancetype)initWithCoder:(NSCoder *)coder
 {
-    if (!(self = [super init]))
+    if (!(self = [self init]))
         return nil;
 
     return self;

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h (197003 => 197004)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h	2016-02-23 23:41:53 UTC (rev 197003)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h	2016-02-24 00:20:01 UTC (rev 197004)
@@ -83,7 +83,7 @@
  */
 - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
 
-- (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
+- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
 
 /*! @abstract Navigates to a requested URL.
  @param request The request specifying the URL to which to navigate.

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (197003 => 197004)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-02-23 23:41:53 UTC (rev 197003)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-02-24 00:20:01 UTC (rev 197004)
@@ -338,11 +338,8 @@
 }
 #endif
 
-- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
+- (void)_initializeWithConfiguration:(WKWebViewConfiguration *)configuration
 {
-    if (!(self = [super initWithFrame:frame]))
-        return nil;
-
     if (!configuration)
         [NSException raise:NSInvalidArgumentException format:@"Configuration cannot be nil"];
 
@@ -359,7 +356,6 @@
 
     [_configuration _validate];
 
-
     WebKit::WebProcessPool& processPool = *[_configuration processPool]->_processPool;
     
     auto pageConfiguration = API::PageConfiguration::create();
@@ -469,16 +465,52 @@
     _page->setDiagnosticLoggingClient(std::make_unique<WebKit::DiagnosticLoggingClient>(self));
 
     pageToViewMap().add(_page.get(), self);
+}
 
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
+{
+    if (!(self = [super initWithFrame:frame]))
+        return nil;
+
+    [self _initializeWithConfiguration:configuration];
+
     return self;
 }
 
 - (instancetype)initWithCoder:(NSCoder *)coder
 {
-    [self release];
-    return nil;
+    if (!(self = [super initWithCoder:coder]))
+        return nil;
+
+    WKWebViewConfiguration *configuration = [coder decodeObjectForKey:@"configuration"];
+    [self _initializeWithConfiguration:configuration];
+
+    self.allowsBackForwardNavigationGestures = [coder decodeBoolForKey:@"allowsBackForwardNavigationGestures"];
+    self.customUserAgent = [coder decodeObjectForKey:@"customUserAgent"];
+    self.allowsLinkPreview = [coder decodeBoolForKey:@"allowsLinkPreview"];
+
+#if PLATFORM(MAC)
+    self.allowsMagnification = [coder decodeBoolForKey:@"allowsMagnification"];
+    self.magnification = [coder decodeDoubleForKey:@"magnification"];
+#endif
+
+    return self;
 }
 
+- (void)encodeWithCoder:(NSCoder *)coder
+{
+    [coder encodeObject:_configuration.get() forKey:@"configuration"];
+
+    [coder encodeBool:self.allowsBackForwardNavigationGestures forKey:@"allowsBackForwardNavigationGestures"];
+    [coder encodeObject:self.customUserAgent forKey:@"customUserAgent"];
+    [coder encodeBool:self.allowsLinkPreview forKey:@"allowsLinkPreview"];
+
+#if PLATFORM(MAC)
+    [coder encodeBool:self.allowsMagnification forKey:@"allowsMagnification"];
+    [coder encodeDouble:self.magnification forKey:@"magnification"];
+#endif
+}
+
 - (void)dealloc
 {
 #if PLATFORM(MAC)

Modified: trunk/Tools/ChangeLog (197003 => 197004)


--- trunk/Tools/ChangeLog	2016-02-23 23:41:53 UTC (rev 197003)
+++ trunk/Tools/ChangeLog	2016-02-24 00:20:01 UTC (rev 197004)
@@ -1,5 +1,17 @@
 2016-02-23  Anders Carlsson  <[email protected]>
 
+        WKWebView should implement NSCoding
+        https://bugs.webkit.org/show_bug.cgi?id=137160
+
+        Reviewed by Dan Bernstein.
+
+        Add tests.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm:
+        (TEST):
+
+2016-02-23  Anders Carlsson  <[email protected]>
+
         WKProcessPool should conform to NSCoding
         https://bugs.webkit.org/show_bug.cgi?id=154608
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm (197003 => 197004)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm	2016-02-23 23:41:53 UTC (rev 197003)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm	2016-02-24 00:20:01 UTC (rev 197004)
@@ -120,4 +120,61 @@
     EXPECT_EQ([a allowsPictureInPictureMediaPlayback], [b allowsPictureInPictureMediaPlayback]);
 #endif
 }
+
+TEST(Coding, WKWebView)
+{
+    auto a = adoptNS([[WKWebView alloc] init]);
+
+    // Change all defaults to something else.
+    [a setAllowsBackForwardNavigationGestures:YES];
+    [a setCustomUserAgent:@"CustomUserAgent"];
+
+#if PLATFORM(IOS)
+    [a setAllowsLinkPreview:YES];
+#else
+    [a setAllowsLinkPreview:NO];
+    [a setAllowsMagnification:YES];
+    [a setMagnification:2];
 #endif
+
+    auto b = encodeAndDecode(a.get());
+
+    EXPECT_EQ([a allowsBackForwardNavigationGestures], [b allowsBackForwardNavigationGestures]);
+    EXPECT_TRUE([[a customUserAgent] isEqualToString:[b customUserAgent]]);
+    EXPECT_EQ([a allowsLinkPreview], [b allowsLinkPreview]);
+
+#if PLATFORM(MAC)
+    EXPECT_EQ([a allowsMagnification], [b allowsMagnification]);
+    EXPECT_EQ([a magnification], [b magnification]);
+#endif
+}
+
+TEST(Coding, WKWebView_SameConfiguration)
+{
+    // First, encode two WKWebViews sharing the same configuration.
+    RetainPtr<NSData> data;
+    {
+        auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+        auto a = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
+        auto b = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
+
+        data = "" archivedDataWithRootObject:@[a.get(), b.get()]];
+    }
+
+    // Then, decode and verify that the important configuration properties are the same.
+    NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data.get()];
+
+    WKWebView *aView = array[0];
+    WKWebView *bView = array[1];
+
+    WKWebViewConfiguration *a = aView.configuration;
+    WKWebViewConfiguration *b = bView.configuration;
+
+    EXPECT_EQ(a.processPool, b.processPool);
+    EXPECT_EQ(a.preferences, b.preferences);
+    EXPECT_EQ(a.userContentController, b.userContentController);
+    EXPECT_EQ(a.websiteDataStore, b.websiteDataStore);
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to