Add _drawsBackground to WKWebViewConfiguration.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Jul 2018 00:03:49 +0000 (00:03 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Jul 2018 00:03:49 +0000 (00:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187665
rdar://problem/42182268

Reviewed by Tim Horton.

Source/WebKit:

* UIProcess/API/APIPageConfiguration.cpp:
(API::PageConfiguration::copy const): Copy m_drawsBackground, and some missing values.
* UIProcess/API/APIPageConfiguration.h:
(API::PageConfiguration::drawsBackground const): Added.
(API::PageConfiguration::setDrawsBackground): Added.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]): Transfer _drawsBackground to page config.
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]): Set _drawsBackground to YES.
(-[WKWebViewConfiguration encodeWithCoder:]): Encode _drawsBackground.
(-[WKWebViewConfiguration initWithCoder:]): Decode _drawsBackground.
(-[WKWebViewConfiguration copyWithZone:]): Copy _drawsBackground.
(-[WKWebViewConfiguration _drawsBackground]): Added.
(-[WKWebViewConfiguration _setDrawsBackground:]): Added.
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
* UIProcess/WebPageProxy.cpp: Set m_drawsBackground based on configuration.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/Configuration.mm:
(TestWebKitAPI.WebKit.ConfigurationDrawsBackground): Added.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIPageConfiguration.cpp
Source/WebKit/UIProcess/API/APIPageConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/Configuration.mm

index 288dd60..08a9f8f 100644 (file)
@@ -1,3 +1,28 @@
+2018-07-13  Timothy Hatcher  <timothy@apple.com>
+
+        Add _drawsBackground to WKWebViewConfiguration.
+        https://bugs.webkit.org/show_bug.cgi?id=187665
+        rdar://problem/42182268
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/APIPageConfiguration.cpp:
+        (API::PageConfiguration::copy const): Copy m_drawsBackground, and some missing values.
+        * UIProcess/API/APIPageConfiguration.h:
+        (API::PageConfiguration::drawsBackground const): Added.
+        (API::PageConfiguration::setDrawsBackground): Added.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]): Transfer _drawsBackground to page config.
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration init]): Set _drawsBackground to YES.
+        (-[WKWebViewConfiguration encodeWithCoder:]): Encode _drawsBackground.
+        (-[WKWebViewConfiguration initWithCoder:]): Decode _drawsBackground.
+        (-[WKWebViewConfiguration copyWithZone:]): Copy _drawsBackground.
+        (-[WKWebViewConfiguration _drawsBackground]): Added.
+        (-[WKWebViewConfiguration _setDrawsBackground:]): Added.
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+        * UIProcess/WebPageProxy.cpp: Set m_drawsBackground based on configuration.
+
 2018-07-13  Tim Horton  <timothy_horton@apple.com>
 
         WebKit sometimes holds WiFi/BT assertions while the Networking process is suspended
index 4b7dcbc..0cab677 100644 (file)
@@ -73,8 +73,10 @@ Ref<PageConfiguration> PageConfiguration::copy() const
     copy->m_alwaysRunsAtForegroundPriority = this->m_alwaysRunsAtForegroundPriority;
 #endif
     copy->m_initialCapitalizationEnabled = this->m_initialCapitalizationEnabled;
-    copy->m_cpuLimit = this->m_cpuLimit;
+    copy->m_waitsForPaintAfterViewDidMoveToWindow = this->m_waitsForPaintAfterViewDidMoveToWindow;
+    copy->m_drawsBackground = this->m_drawsBackground;
     copy->m_controlledByAutomation = this->m_controlledByAutomation;
+    copy->m_cpuLimit = this->m_cpuLimit;
     copy->m_overrideContentSecurityPolicy = this->m_overrideContentSecurityPolicy;
 #if ENABLE(APPLICATION_MANIFEST)
     copy->m_applicationManifest = this->m_applicationManifest;
index d43b91d..992a968 100644 (file)
@@ -101,6 +101,9 @@ public:
     bool waitsForPaintAfterViewDidMoveToWindow() const { return m_waitsForPaintAfterViewDidMoveToWindow; }
     void setWaitsForPaintAfterViewDidMoveToWindow(bool shouldSynchronize) { m_waitsForPaintAfterViewDidMoveToWindow = shouldSynchronize; }
 
+    bool drawsBackground() const { return m_drawsBackground; }
+    void setDrawsBackground(bool drawsBackground) { m_drawsBackground = drawsBackground; }
+
     bool isControlledByAutomation() const { return m_controlledByAutomation; }
     void setControlledByAutomation(bool controlledByAutomation) { m_controlledByAutomation = controlledByAutomation; }
 
@@ -133,6 +136,7 @@ private:
 #endif
     bool m_initialCapitalizationEnabled = true;
     bool m_waitsForPaintAfterViewDidMoveToWindow = true;
+    bool m_drawsBackground = true;
     bool m_controlledByAutomation = false;
     std::optional<double> m_cpuLimit;
 
index 2f9fdab..e79559b 100644 (file)
@@ -554,6 +554,7 @@ static void validate(WKWebViewConfiguration *configuration)
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::allowUniversalAccessFromFileURLsKey(), WebKit::WebPreferencesStore::Value(!![_configuration _allowUniversalAccessFromFileURLs]));
     pageConfiguration->setInitialCapitalizationEnabled([_configuration _initialCapitalizationEnabled]);
     pageConfiguration->setWaitsForPaintAfterViewDidMoveToWindow([_configuration _waitsForPaintAfterViewDidMoveToWindow]);
+    pageConfiguration->setDrawsBackground([_configuration _drawsBackground]);
     pageConfiguration->setControlledByAutomation([_configuration _isControlledByAutomation]);
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::incompleteImageBorderEnabledKey(), WebKit::WebPreferencesStore::Value(!![_configuration _incompleteImageBorderEnabled]));
 
index d298ef7..8169b80 100644 (file)
@@ -164,6 +164,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     BOOL _allowMediaContentTypesRequiringHardwareSupportAsFallback;
     BOOL _colorFilterEnabled;
     BOOL _incompleteImageBorderEnabled;
+    BOOL _drawsBackground;
 
     RetainPtr<NSString> _overrideContentSecurityPolicy;
     RetainPtr<NSString> _mediaContentTypesRequiringHardwareSupport;
@@ -249,6 +250,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
 
     _colorFilterEnabled = NO;
     _incompleteImageBorderEnabled = NO;
+    _drawsBackground = YES;
 
     return self;
 }
@@ -263,8 +265,6 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     return YES;
 }
 
-// FIXME: Encode the process pool, user content controller and website data store.
-
 - (void)encodeWithCoder:(NSCoder *)coder
 {
     [coder encodeObject:self.processPool forKey:@"processPool"];
@@ -276,6 +276,8 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     [coder encodeObject:self.applicationNameForUserAgent forKey:@"applicationNameForUserAgent"];
     [coder encodeBool:self.allowsAirPlayForMediaPlayback forKey:@"allowsAirPlayForMediaPlayback"];
 
+    [coder encodeBool:self._drawsBackground forKey:@"drawsBackground"];
+
 #if PLATFORM(IOS)
     [coder encodeInteger:self.dataDetectorTypes forKey:@"dataDetectorTypes"];
     [coder encodeBool:self.allowsInlineMediaPlayback forKey:@"allowsInlineMediaPlayback"];
@@ -307,6 +309,9 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     self.applicationNameForUserAgent = decodeObjectOfClassForKeyFromCoder([NSString class], @"applicationNameForUserAgent", coder);
     self.allowsAirPlayForMediaPlayback = [coder decodeBoolForKey:@"allowsAirPlayForMediaPlayback"];
 
+    if ([coder containsValueForKey:@"drawsBackground"])
+        self._drawsBackground = [coder decodeBoolForKey:@"drawsBackground"];
+
 #if PLATFORM(IOS)
     self.dataDetectorTypes = [coder decodeIntegerForKey:@"dataDetectorTypes"];
     self.allowsInlineMediaPlayback = [coder decodeBoolForKey:@"allowsInlineMediaPlayback"];
@@ -409,6 +414,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     configuration->_groupIdentifier = adoptNS([self->_groupIdentifier copyWithZone:zone]);
     configuration->_colorFilterEnabled = self->_colorFilterEnabled;
     configuration->_incompleteImageBorderEnabled = self->_incompleteImageBorderEnabled;
+    configuration->_drawsBackground = self->_drawsBackground;
 
     return configuration;
 }
@@ -778,6 +784,16 @@ static NSString *defaultApplicationNameForUserAgent()
     _incompleteImageBorderEnabled = incompleteImageBorderEnabled;
 }
 
+- (BOOL)_drawsBackground
+{
+    return _drawsBackground;
+}
+
+- (void)_setDrawsBackground:(BOOL)drawsBackground
+{
+    _drawsBackground = drawsBackground;
+}
+
 - (BOOL)_requiresUserActionForVideoPlayback
 {
     return self.mediaTypesRequiringUserActionForPlayback & WKAudiovisualMediaTypeVideo;
index db49965..d6955f9 100644 (file)
@@ -72,6 +72,7 @@ typedef NS_ENUM(NSUInteger, _WKDragLiftDelay) {
 @property (nonatomic, setter=_setApplicationManifest:) _WKApplicationManifest *_applicationManifest WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
 @property (nonatomic, setter=_setColorFilterEnabled:) BOOL _colorFilterEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, setter=_setIncompleteImageBorderEnabled:) BOOL _incompleteImageBorderEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 #if TARGET_OS_IPHONE
 @property (nonatomic, setter=_setAlwaysRunsAtForegroundPriority:) BOOL _alwaysRunsAtForegroundPriority WK_API_AVAILABLE(ios(9_0));
index b611536..c66a7af 100644 (file)
@@ -405,6 +405,7 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
     , m_cpuLimit(m_configuration->cpuLimit())
     , m_backForwardList(WebBackForwardList::create(*this))
     , m_waitsForPaintAfterViewDidMoveToWindow(m_configuration->waitsForPaintAfterViewDidMoveToWindow())
+    , m_drawsBackground(m_configuration->drawsBackground())
     , m_pageID(pageID)
     , m_controlledByAutomation(m_configuration->isControlledByAutomation())
 #if PLATFORM(COCOA)
index d8ee123..bbace8b 100644 (file)
@@ -1,3 +1,14 @@
+2018-07-13  Timothy Hatcher  <timothy@apple.com>
+
+        Add _drawsBackground to WKWebViewConfiguration.
+        https://bugs.webkit.org/show_bug.cgi?id=187665
+        rdar://problem/42182268
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/Configuration.mm:
+        (TestWebKitAPI.WebKit.ConfigurationDrawsBackground): Added.
+
 2018-07-13  Chris Dumez  <cdumez@apple.com>
 
         Add a FrameLoaderClient willInjectUserScriptForFrame callback
index 617c56c..5de5fea 100644 (file)
@@ -29,6 +29,7 @@
 
 #import "Test.h"
 #import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
 TEST(WebKit, ConfigurationCPULimit)
@@ -41,4 +42,21 @@ TEST(WebKit, ConfigurationCPULimit)
     EXPECT_EQ([other _cpuLimit], 0.75);
 }
 
+TEST(WebKit, ConfigurationDrawsBackground)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    EXPECT_EQ([configuration _drawsBackground], YES);
+    [configuration _setDrawsBackground:NO];
+    EXPECT_EQ([configuration _drawsBackground], NO);
+
+    auto other = adoptNS([configuration copy]);
+    EXPECT_EQ([other _drawsBackground], NO);
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSZeroRect]);
+    EXPECT_EQ([webView _drawsBackground], YES);
+
+    auto configedWebView = adoptNS([[WKWebView alloc] initWithFrame:NSZeroRect configuration:configuration.get()]);
+    EXPECT_EQ([configedWebView _drawsBackground], NO);
+}
+
 #endif