Teach MiniBrowser how to disable per-window web processes
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Feb 2015 04:53:43 +0000 (04:53 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Feb 2015 04:53:43 +0000 (04:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141988

Reviewed by Darin Adler.

* MiniBrowser/mac/AppDelegate.m:
(defaultConfiguration): Created a _WKProcessPoolConfiguration with maximumProcessCount == 1 if per-window web processes are disabled.
* MiniBrowser/mac/SettingsController.h:
* MiniBrowser/mac/SettingsController.m:
(-[SettingsController _populateMenu]): Added a new Settings menu item.
(-[SettingsController validateMenuItem:]): Validated the new Settings menu item.
(-[SettingsController togglePerWindowWebProcessesDisabled:]): Displayed an alert informing the user that MiniBrowser must be restarted for the setting to take effect.
(-[SettingsController perWindowWebProcessesDisabled]): Returned the value from user defaults.

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

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

index 0d58991..db12aed 100644 (file)
@@ -1,3 +1,19 @@
+2015-02-24  Andy Estes  <aestes@apple.com>
+
+        Teach MiniBrowser how to disable per-window web processes
+        https://bugs.webkit.org/show_bug.cgi?id=141988
+
+        Reviewed by Darin Adler.
+
+        * MiniBrowser/mac/AppDelegate.m:
+        (defaultConfiguration): Created a _WKProcessPoolConfiguration with maximumProcessCount == 1 if per-window web processes are disabled.
+        * MiniBrowser/mac/SettingsController.h:
+        * MiniBrowser/mac/SettingsController.m:
+        (-[SettingsController _populateMenu]): Added a new Settings menu item.
+        (-[SettingsController validateMenuItem:]): Validated the new Settings menu item.
+        (-[SettingsController togglePerWindowWebProcessesDisabled:]): Displayed an alert informing the user that MiniBrowser must be restarted for the setting to take effect.
+        (-[SettingsController perWindowWebProcessesDisabled]): Returned the value from user defaults.
+
 2015-02-24  Alexey Proskuryakov  <ap@apple.com>
 
         Bot watcher's dashboard sometimes hits an assertion: data.num_missing === this.layoutTestResults.testsWithMissingResults.length
index d37d16e..12fc553 100644 (file)
 #import "WK1BrowserWindowController.h"
 #import "WK2BrowserWindowController.h"
 #import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WebKit.h>
+#import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKWebsiteDataStore.h>
 
 enum {
@@ -66,6 +68,13 @@ static WKWebViewConfiguration *defaultConfiguration()
         configuration = [[WKWebViewConfiguration alloc] init];
         configuration.preferences._fullScreenEnabled = YES;
         configuration.preferences._developerExtrasEnabled = YES;
+
+        if ([SettingsController shared].perWindowWebProcessesDisabled) {
+            _WKProcessPoolConfiguration *singleProcessConfiguration = [[_WKProcessPoolConfiguration alloc] init];
+            singleProcessConfiguration.maximumProcessCount = 1;
+            configuration.processPool = [[[WKProcessPool alloc] _initWithConfiguration:singleProcessConfiguration] autorelease];
+            [singleProcessConfiguration release];
+        }
     }
 
     return configuration;
index 91e2cfb..4f21987 100644 (file)
@@ -42,6 +42,7 @@
 @property (nonatomic, readonly) BOOL nonFastScrollableRegionOverlayVisible;
 @property (nonatomic, readonly) BOOL wheelEventHandlerRegionOverlayVisible;
 @property (nonatomic, readonly) BOOL useUISideCompositing;
+@property (nonatomic, readonly) BOOL perWindowWebProcessesDisabled;
 @property (nonatomic, readonly) BOOL subPixelCSSOMMetricsEnabled;
 @property (nonatomic, readonly) NSString *defaultURL;
 
index 009c1f7..f67906b 100644 (file)
@@ -46,6 +46,8 @@ static NSString * const EnableSubPixelCSSOMMetricsPreferenceKey = @"EnableSubPix
 // This default name intentionally overlaps with the key that WebKit2 checks when creating a view.
 static NSString * const UseRemoteLayerTreeDrawingAreaPreferenceKey = @"WebKit2UseRemoteLayerTreeDrawingArea";
 
+static NSString * const PerWindowWebProcessesDisabledKey = @"PerWindowWebProcessesDisabled";
+
 typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     NonFastScrollableRegionOverlayTag = 100,
     WheelEventHandlerRegionOverlayTag
@@ -107,6 +109,7 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
 
     [self _addItemWithTitle:@"Show Tiled Scrolling Indicator" action:@selector(toggleShowTiledScrollingIndicator:) indented:YES];
     [self _addItemWithTitle:@"Use UI-Side Compositing" action:@selector(toggleUseUISideCompositing:) indented:YES];
+    [self _addItemWithTitle:@"Disable Per-Window Web Processes" action:@selector(togglePerWindowWebProcessesDisabled:) indented:YES];
 
     NSMenuItem *debugOverlaysSubmenuItem = [[NSMenuItem alloc] initWithTitle:@"Debug Overlays" action:nil keyEquivalent:@""];
     NSMenu *debugOverlaysMenu = [[NSMenu alloc] initWithTitle:@"Debug Overlays"];
@@ -148,6 +151,8 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
         [menuItem setState:[self tiledScrollingIndicatorVisible] ? NSOnState : NSOffState];
     else if (action == @selector(toggleUseUISideCompositing:))
         [menuItem setState:[self useUISideCompositing] ? NSOnState : NSOffState];
+    else if (action == @selector(togglePerWindowWebProcessesDisabled:))
+        [menuItem setState:[self perWindowWebProcessesDisabled] ? NSOnState : NSOffState];
     else if (action == @selector(toggleEnableSubPixelCSSOMMetrics:))
         [menuItem setState:[self subPixelCSSOMMetricsEnabled] ? NSOnState : NSOffState];
     else if (action == @selector(toggleDebugOverlay:))
@@ -204,6 +209,26 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     return [[NSUserDefaults standardUserDefaults] boolForKey:UseRemoteLayerTreeDrawingAreaPreferenceKey];
 }
 
+- (void)togglePerWindowWebProcessesDisabled:(id)sender
+{
+    NSAlert *alert = [[NSAlert alloc] init];
+    [alert setMessageText:self.perWindowWebProcessesDisabled ? @"Are you sure you want to switch to per-window web processes?" : @"Are you sure you want to switch to a single web process?"];
+    [alert setInformativeText:@"This requires quitting and relaunching MiniBrowser. I'll do the quitting. You will have to do the relaunching."];
+    [alert addButtonWithTitle:@"Switch and Quit"];
+    [alert addButtonWithTitle:@"Cancel"];
+
+    if ([alert runModal] != NSAlertFirstButtonReturn)
+        return;
+
+    [self _toggleBooleanDefault:PerWindowWebProcessesDisabledKey];
+    [NSApp terminate:self];
+}
+
+- (BOOL)perWindowWebProcessesDisabled
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:PerWindowWebProcessesDisabledKey];
+}
+
 - (void)toggleShowLayerBorders:(id)sender
 {
     [self _toggleBooleanDefault:LayerBordersVisiblePreferenceKey];