Add WK2 ExperimentalFeature support to MiniBrowser.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2016 00:35:21 +0000 (00:35 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2016 00:35:21 +0000 (00:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160788

Reviewed by Alex Christensen.

* MiniBrowser/mac/AppDelegate.h:
* MiniBrowser/mac/AppDelegate.m:
(defaultConfiguration):
(defaultPreferences):

* MiniBrowser/mac/SettingsController.m:
(-[SettingsController _populateMenu]):
(-[SettingsController validateMenuItem:]):
(-[SettingsController toggleExperimentalFeature:]):

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

Tools/ChangeLog
Tools/MiniBrowser/mac/AppDelegate.h
Tools/MiniBrowser/mac/AppDelegate.m
Tools/MiniBrowser/mac/SettingsController.m

index 7945e64..2f74abc 100644 (file)
@@ -1,3 +1,20 @@
+2016-08-11  Brady Eidson  <beidson@apple.com>
+
+        Add WK2 ExperimentalFeature support to MiniBrowser.
+        https://bugs.webkit.org/show_bug.cgi?id=160788
+
+        Reviewed by Alex Christensen.
+
+        * MiniBrowser/mac/AppDelegate.h:
+        * MiniBrowser/mac/AppDelegate.m:
+        (defaultConfiguration):
+        (defaultPreferences):
+        
+        * MiniBrowser/mac/SettingsController.m:
+        (-[SettingsController _populateMenu]):
+        (-[SettingsController validateMenuItem:]):
+        (-[SettingsController toggleExperimentalFeature:]):
+
 2016-08-11  Aakash Jain  <aakash_jain@apple.com>
 
         Keep EWS logs for longer
index 0bb93be..e739ded 100644 (file)
@@ -44,3 +44,7 @@
 #endif
 
 @end
+
+#if WK_API_ENABLED
+WKPreferences *defaultPreferences();
+#endif
index 0678aca..3bf75ec 100644 (file)
@@ -35,6 +35,7 @@
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/WebKit.h>
+#import <WebKit/_WKExperimentalFeature.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKUserContentExtensionStore.h>
 
@@ -81,12 +82,24 @@ static WKWebViewConfiguration *defaultConfiguration()
             configuration.processPool = [[[WKProcessPool alloc] _initWithConfiguration:singleProcessConfiguration] autorelease];
             [singleProcessConfiguration release];
         }
+
+        NSArray<_WKExperimentalFeature *> *features = [WKPreferences _experimentalFeatures];
+        for (_WKExperimentalFeature *feature in features) {
+            BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:feature.key];
+            [configuration.preferences _setEnabled:enabled forFeature:feature];
+        }
     }
 
     configuration.suppressesIncrementalRendering = [SettingsController shared].incrementalRenderingSuppressed;
     configuration.websiteDataStore._resourceLoadStatisticsEnabled = [SettingsController shared].resourceLoadStatisticsEnabled;
     return configuration;
 }
+
+WKPreferences *defaultPreferences()
+{
+    return defaultConfiguration().preferences;
+}
+
 #endif
 
 
index f5e1501..5d38aea 100644 (file)
@@ -27,6 +27,8 @@
 
 #import "AppDelegate.h"
 #import "BrowserWindowController.h"
+#import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/_WKExperimentalFeature.h>
 
 static NSString * const defaultURL = @"http://www.webkit.org/";
 static NSString * const DefaultURLPreferenceKey = @"DefaultURL";
@@ -55,7 +57,8 @@ static NSString * const PerWindowWebProcessesDisabledKey = @"PerWindowWebProcess
 
 typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     NonFastScrollableRegionOverlayTag = 100,
-    WheelEventHandlerRegionOverlayTag
+    WheelEventHandlerRegionOverlayTag,
+    ExperimentalFeatureTag,
 };
 
 @implementation SettingsController
@@ -140,6 +143,24 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     [_menu addItem:debugOverlaysSubmenuItem];
     [debugOverlaysSubmenuItem release];
 
+    NSMenuItem *experimentalFeaturesSubmenuItem = [[NSMenuItem alloc] initWithTitle:@"Experimental Features" action:nil keyEquivalent:@""];
+    NSMenu *experimentalFeaturesMenu = [[NSMenu alloc] initWithTitle:@"Experimental Features"];
+    [experimentalFeaturesSubmenuItem setSubmenu:experimentalFeaturesMenu];
+
+    NSArray<_WKExperimentalFeature *> *features = [WKPreferences _experimentalFeatures];
+
+    for (_WKExperimentalFeature *feature in features) {
+        NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:feature.name action:@selector(toggleExperimentalFeature:) keyEquivalent:@""];
+        item.representedObject = feature;
+
+        [item setTag:ExperimentalFeatureTag];
+        [item setTarget:self];
+        [experimentalFeaturesMenu addItem:[item autorelease]];
+    }
+
+    [_menu addItem:experimentalFeaturesSubmenuItem];
+    [experimentalFeaturesSubmenuItem release];
+
     [self _addHeaderWithTitle:@"WebKit1-only Settings"];
     [self _addItemWithTitle:@"Enable Subpixel CSSOM Metrics" action:@selector(toggleEnableSubPixelCSSOMMetrics:) indented:YES];
 }
@@ -179,6 +200,11 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     else if (action == @selector(toggleDebugOverlay:))
         [menuItem setState:[self debugOverlayVisible:menuItem] ? NSOnState : NSOffState];
 
+    if (menuItem.tag == ExperimentalFeatureTag) {
+        _WKExperimentalFeature *feature = menuItem.representedObject;
+        [menuItem setState:[defaultPreferences() _isEnabledForFeature:feature] ? NSOnState : NSOffState];
+    }
+
     return YES;
 }
 
@@ -369,6 +395,17 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
         [self _toggleBooleanDefault:preferenceKey];
 }
 
+- (void)toggleExperimentalFeature:(id)sender
+{
+    _WKExperimentalFeature *feature = ((NSMenuItem *)sender).representedObject;
+    WKPreferences *preferences = defaultPreferences();
+
+    BOOL currentlyEnabled = [preferences _isEnabledForFeature:feature];
+    [preferences _setEnabled:!currentlyEnabled forFeature:feature];
+
+    [[NSUserDefaults standardUserDefaults] setBool:!currentlyEnabled forKey:feature.key];
+}
+
 - (BOOL)debugOverlayVisible:(NSMenuItem *)menuItem
 {
     NSString *preferenceKey = [self preferenceKeyForRegionOverlayTag:[menuItem tag]];