Expose WebPreferences::webGLEnabled through WKPreferences
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Sep 2017 00:29:19 +0000 (00:29 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Sep 2017 00:29:19 +0000 (00:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177692
<rdar://problem/24110556>

Reviewed by Andy Estes.

Source/WebKit:

* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _setWebGLEnabled:]):
(-[WKPreferences _webGLEnabled]):
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/Preferences.mm:
(-[AlertSaver alert]):
(-[AlertSaver webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/Preferences.mm

index 1c53475..3907b48 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-29  Alex Christensen  <achristensen@webkit.org>
+
+        Expose WebPreferences::webGLEnabled through WKPreferences
+        https://bugs.webkit.org/show_bug.cgi?id=177692
+        <rdar://problem/24110556>
+
+        Reviewed by Andy Estes.
+
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences _setWebGLEnabled:]):
+        (-[WKPreferences _webGLEnabled]):
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+
 2017-09-29  Chris Dumez  <cdumez@apple.com>
 
         [WK2][NETWORK_SESSION] Move some authentication-related code to avoid duplication
index 804b468..757f41c 100644 (file)
@@ -647,6 +647,7 @@ static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPo
     _preferences->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard);
 }
 
+#if PLATFORM(MAC)
 - (void)_setPlugInsEnabled:(BOOL)enabled
 {
     _preferences->setPluginsEnabled(enabled);
@@ -657,6 +658,17 @@ static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPo
     return _preferences->pluginsEnabled();
 }
 
+- (void)_setWebGLEnabled:(BOOL)enabled
+{
+    _preferences->setWebGLEnabled(enabled);
+}
+
+- (BOOL)_webGLEnabled
+{
+    return _preferences->webGLEnabled();
+}
+#endif // PLATFORM(MAC)
+
 - (BOOL)_javaScriptCanAccessClipboard
 {
     return _preferences->javaScriptCanAccessClipboard();
index f18b006..c5a1526 100644 (file)
@@ -120,6 +120,7 @@ typedef NS_OPTIONS(NSUInteger, _WKJavaScriptRuntimeFlags) {
 
 #if !TARGET_OS_IPHONE
 @property (nonatomic, setter=_setPlugInsEnabled:) BOOL _plugInsEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+@property (nonatomic, setter=_setWebGLEnabled:) BOOL _webGLEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 #endif
 
 @end
index 19dff49..ea3b34d 100644 (file)
@@ -1,5 +1,18 @@
 2017-09-29  Alex Christensen  <achristensen@webkit.org>
 
+        Expose WebPreferences::webGLEnabled through WKPreferences
+        https://bugs.webkit.org/show_bug.cgi?id=177692
+        <rdar://problem/24110556>
+
+        Reviewed by Andy Estes.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/Preferences.mm:
+        (-[AlertSaver alert]):
+        (-[AlertSaver webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+        (TEST):
+
+2017-09-29  Alex Christensen  <achristensen@webkit.org>
+
         Fix WKWebViewConfigurationPrivate after r222663
         https://bugs.webkit.org/show_bug.cgi?id=177644
 
index fc65772..ba865b7 100644 (file)
 #if WK_API_ENABLED
 
 #import "Test.h"
+#import "Utilities.h"
 #import <WebKit/WKFoundation.h>
 #import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKUIDelegate.h>
 #import <WebKit/_WKExperimentalFeature.h>
 #import <wtf/RetainPtr.h>
 
@@ -66,4 +68,52 @@ TEST(WebKit, ExperimentalFeatures)
     }
 }
 
-#endif
+#if PLATFORM(MAC)
+
+static bool receivedAlert;
+
+@interface AlertSaver : NSObject <WKUIDelegate>
+@end
+
+@implementation AlertSaver {
+    RetainPtr<NSString> alert;
+}
+
+- (NSString *)alert
+{
+    return alert.get();
+}
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+    alert = message;
+    completionHandler();
+    receivedAlert = true;
+}
+
+@end
+
+TEST(WebKit, WebGLEnabled)
+{
+    NSString *html = @"<script>if(document.createElement('canvas').getContext('webgl')){alert('enabled')}else{alert('disabled')}</script>";
+    auto delegate = adoptNS([[AlertSaver alloc] init]);
+
+    auto webView = adoptNS([[WKWebView alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+    [webView loadHTMLString:html baseURL:nil];
+    TestWebKitAPI::Util::run(&receivedAlert);
+    EXPECT_STREQ([delegate alert].UTF8String, "enabled");
+
+    receivedAlert = false;
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [[configuration preferences] _setWebGLEnabled:NO];
+    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    [webView setUIDelegate:delegate.get()];
+    [webView loadHTMLString:html baseURL:nil];
+    TestWebKitAPI::Util::run(&receivedAlert);
+    EXPECT_STREQ([delegate alert].UTF8String, "disabled");
+}
+
+#endif // PLATFORM(MAC)
+
+#endif // WK_API_ENABLED