Add a WKPageGroupRef setter in WKWebViewConfiguration
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 00:53:30 +0000 (00:53 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 00:53:30 +0000 (00:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180674
<rdar://problem/35920392>

Reviewed by Brady Eidson.

There is a Mac app trying to transition to WKWebView, and it uses WKPageGroupRef extensively.
To help it transition, we are temporarily giving it an ObjC way to use this organization for
its UserContentControllers to be united per PageGroup before it transitions away from SPIs like
WKBundleAddUserScript.  Make it Mac-only to indicate that this should be transitioned away from,
rather than adopted on iOS.

No change in behavior for apps not using the new WKWebViewConfiguration._pageGroup SPI.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _pageGroup]):
(-[WKWebViewConfiguration _setPageGroup:]):
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h

index 2299930..026a836 100644 (file)
@@ -1,3 +1,27 @@
+2017-12-11  Alex Christensen  <achristensen@webkit.org>
+
+        Add a WKPageGroupRef setter in WKWebViewConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=180674
+        <rdar://problem/35920392>
+
+        Reviewed by Brady Eidson.
+
+        There is a Mac app trying to transition to WKWebView, and it uses WKPageGroupRef extensively.
+        To help it transition, we are temporarily giving it an ObjC way to use this organization for
+        its UserContentControllers to be united per PageGroup before it transitions away from SPIs like
+        WKBundleAddUserScript.  Make it Mac-only to indicate that this should be transitioned away from,
+        rather than adopted on iOS.
+        
+        No change in behavior for apps not using the new WKWebViewConfiguration._pageGroup SPI.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _pageGroup]):
+        (-[WKWebViewConfiguration _setPageGroup:]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+
 2017-12-11  Brent Fulgham  <bfulgham@apple.com>
 
         [iOS] Remove unused services from WebContent Process sandbox
index 0688a6e..c3e51cd 100644 (file)
@@ -517,11 +517,16 @@ static void validate(WKWebViewConfiguration *configuration)
     if (NSString *overrideContentSecurityPolicy = configuration._overrideContentSecurityPolicy)
         pageConfiguration->setOverrideContentSecurityPolicy(overrideContentSecurityPolicy);
 
-    RefPtr<WebKit::WebPageGroup> pageGroup;
-    NSString *groupIdentifier = configuration._groupIdentifier;
-    if (groupIdentifier.length) {
-        pageGroup = WebKit::WebPageGroup::create(configuration._groupIdentifier);
-        pageConfiguration->setPageGroup(pageGroup.get());
+#if PLATFORM(MAC)
+    if (auto pageGroup = WebKit::toImpl([configuration _pageGroup])) {
+        pageConfiguration->setPageGroup(pageGroup);
+        pageConfiguration->setUserContentController(&pageGroup->userContentController());
+    } else
+#endif
+    {
+        NSString *groupIdentifier = configuration._groupIdentifier;
+        if (groupIdentifier.length)
+            pageConfiguration->setPageGroup(WebKit::WebPageGroup::create(configuration._groupIdentifier).ptr());
     }
 
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::suppressesIncrementalRenderingKey(), WebKit::WebPreferencesStore::Value(!![_configuration suppressesIncrementalRendering]));
index 91a3905..2b489fb 100644 (file)
@@ -32,6 +32,7 @@
 #import "VersionChecks.h"
 #import "WKPreferences.h"
 #import "WKProcessPool.h"
+#import "WKRetainPtr.h"
 #import "WKUserContentController.h"
 #import "WKWebView.h"
 #import "WKWebViewContentProviderRegistry.h"
@@ -136,6 +137,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     BOOL _mainContentUserGestureOverrideEnabled;
 
 #if PLATFORM(MAC)
+    WKRetainPtr<WKPageGroupRef> _pageGroup;
     double _cpuLimit;
     BOOL _showsURLsInToolTips;
     BOOL _serviceControlsEnabled;
@@ -347,6 +349,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     configuration->_serviceControlsEnabled = self->_serviceControlsEnabled;
     configuration->_imageControlsEnabled = self->_imageControlsEnabled;
     configuration->_requiresUserActionForEditingControlsManager = self->_requiresUserActionForEditingControlsManager;
+    configuration->_pageGroup = self._pageGroup;
 #endif
 #if ENABLE(DATA_DETECTION) && PLATFORM(IOS)
     configuration->_dataDetectorTypes = self->_dataDetectorTypes;
@@ -810,6 +813,16 @@ static NSString *defaultApplicationNameForUserAgent()
     _requiresUserActionForEditingControlsManager = requiresUserAction;
 }
 
+- (WKPageGroupRef)_pageGroup
+{
+    return _pageGroup.get();
+}
+
+- (void)_setPageGroup:(WKPageGroupRef)pageGroup
+{
+    _pageGroup = pageGroup;
+}
+
 - (void)_setCPULimit:(double)cpuLimit
 {
     _cpuLimit = cpuLimit;
index b9f408c..9a01348 100644 (file)
@@ -27,6 +27,8 @@
 
 #if WK_API_ENABLED
 
+#import <WebKit/WKBase.h>
+
 #if TARGET_OS_IPHONE
 typedef NS_ENUM(NSUInteger, _WKDragLiftDelay) {
     _WKDragLiftDelayShort = 0,
@@ -80,6 +82,7 @@ typedef NS_ENUM(NSUInteger, _WKDragLiftDelay) {
 @property (nonatomic, setter=_setImageControlsEnabled:) BOOL _imageControlsEnabled WK_API_AVAILABLE(macosx(10.12));
 @property (nonatomic, readwrite, setter=_setRequiresUserActionForEditingControlsManager:) BOOL _requiresUserActionForEditingControlsManager WK_API_AVAILABLE(macosx(10.12));
 @property (nonatomic, readwrite, setter=_setCPULimit:) double _cpuLimit WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+@property (nonatomic, readwrite, setter=_setPageGroup:) WKPageGroupRef _pageGroup WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 #endif
 
 @property (nonatomic, strong, setter=_setWebsiteDataStore:) _WKWebsiteDataStore *_websiteDataStore WK_API_DEPRECATED_WITH_REPLACEMENT("websiteDataStore", macosx(10.10, 10.11), ios(8.0, 9.0));