Add a private browsing mode to MiniBrowser
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Dec 2014 20:48:20 +0000 (20:48 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Dec 2014 20:48:20 +0000 (20:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139308

Reviewed by Sam Weinig.

Source/WebCore:

Use -1 instead of -2 for the deleted value.

* page/SessionIDHash.h:

Tools:

* MiniBrowser/mac/AppDelegate.m:
(defaultConfiguration):
(-[BrowserAppDelegate newWindow:]):
(-[BrowserAppDelegate newPrivateWindow:]):
* MiniBrowser/mac/MainMenu.xib:
* MiniBrowser/mac/WK2BrowserWindowController.h:
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController awakeFromNib]):
(-[WK2BrowserWindowController initWithConfiguration:]):
(-[WK2BrowserWindowController dealloc]):
(-[WK2BrowserWindowController observeValueForKeyPath:ofObject:change:context:]):

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

Source/WebCore/ChangeLog
Source/WebCore/page/SessionIDHash.h
Tools/ChangeLog
Tools/MiniBrowser/mac/AppDelegate.m
Tools/MiniBrowser/mac/MainMenu.xib
Tools/MiniBrowser/mac/WK2BrowserWindowController.h
Tools/MiniBrowser/mac/WK2BrowserWindowController.m

index 36d859c..fc49284 100644 (file)
@@ -1,3 +1,14 @@
+2014-12-05  Anders Carlsson  <andersca@apple.com>
+
+        Add a private browsing mode to MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=139308
+
+        Reviewed by Sam Weinig.
+
+        Use -1 instead of -2 for the deleted value.
+
+        * page/SessionIDHash.h:
+
 2014-12-05  Chris Dumez  <cdumez@apple.com>
 
         Move 'text-emphasis-style' CSS property to the new StyleBuilder
index abbfd1a..02d3d38 100644 (file)
 
 namespace WTF {
 
-// The empty value is emptySessionID(), the deleted value is (-2)
+// The empty value is emptySessionID(), the deleted value is (-1)
 struct SessionIDHash {
     static unsigned hash(const WebCore::SessionID& p) { return (unsigned)p.sessionID(); }
     static bool equal(const WebCore::SessionID& a, const WebCore::SessionID& b) { return a == b; }
     static const bool safeToCompareToEmptyOrDeleted = true;
 };
 template<> struct HashTraits<WebCore::SessionID> : GenericHashTraits<WebCore::SessionID> {
-    static const uint64_t deletedValueIdentifier = 0xFFFFFFFFFFFFFFFE;
+    static const uint64_t deletedValueIdentifier = std::numeric_limits<uint64_t>::max();
     static const bool needsDestruction = false;
     static WebCore::SessionID emptyValue() { return WebCore::SessionID::emptySessionID(); }
 
index 62f3cd8..8b8da02 100644 (file)
@@ -1,3 +1,22 @@
+2014-12-05  Anders Carlsson  <andersca@apple.com>
+
+        Add a private browsing mode to MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=139308
+
+        Reviewed by Sam Weinig.
+
+        * MiniBrowser/mac/AppDelegate.m:
+        (defaultConfiguration):
+        (-[BrowserAppDelegate newWindow:]):
+        (-[BrowserAppDelegate newPrivateWindow:]):
+        * MiniBrowser/mac/MainMenu.xib:
+        * MiniBrowser/mac/WK2BrowserWindowController.h:
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController awakeFromNib]):
+        (-[WK2BrowserWindowController initWithConfiguration:]):
+        (-[WK2BrowserWindowController dealloc]):
+        (-[WK2BrowserWindowController observeValueForKeyPath:ofObject:change:context:]):
+
 2014-12-04  Alexey Proskuryakov  <ap@apple.com>
 
         Run http tests parallel
index 97f793e..804d1a1 100644 (file)
 #import "SettingsController.h"
 #import "WK1BrowserWindowController.h"
 #import "WK2BrowserWindowController.h"
-#import <WebKit/WebHistory.h>
-#import <WebKit/WebKit2.h>
+#import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WebKit.h>
+#import <WebKit/_WKWebsiteDataStore.h>
 
 enum {
     WebKit1NewWindowTag = 1,
@@ -55,6 +57,22 @@ enum {
     [[NSApp mainMenu] insertItem:[item autorelease] atIndex:[[NSApp mainMenu] indexOfItemWithTitle:@"Debug"]];
 }
 
+#if WK_API_ENABLED
+static WKWebViewConfiguration *defaultConfiguration()
+{
+    static WKWebViewConfiguration *configuration;
+
+    if (!configuration) {
+        configuration = [[WKWebViewConfiguration alloc] init];
+        configuration.preferences._fullScreenEnabled = YES;
+        configuration.preferences._developerExtrasEnabled = YES;
+    }
+
+    return configuration;
+}
+#endif
+
+
 - (IBAction)newWindow:(id)sender
 {
     BrowserWindowController *controller = nil;
@@ -70,7 +88,7 @@ enum {
         controller = [[WK1BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
 #if WK_API_ENABLED
     else
-        controller = [[WK2BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
+        controller = [[WK2BrowserWindowController alloc] initWithConfiguration:defaultConfiguration()];
 #endif
     if (!controller)
         return;
@@ -81,6 +99,23 @@ enum {
     [controller loadURLString:[SettingsController shared].defaultURL];
 }
 
+- (IBAction)newPrivateWindow:(id)sender
+{
+#if WK_API_ENABLED
+    WKWebViewConfiguration *privateConfiguraton = [defaultConfiguration() copy];
+    privateConfiguraton._websiteDataStore = [_WKWebsiteDataStore nonPersistentDataStore];
+
+    BrowserWindowController *controller = [[WK2BrowserWindowController alloc] initWithConfiguration:privateConfiguraton];
+    [privateConfiguraton release];
+
+    [[controller window] makeKeyAndOrderFront:sender];
+    [_browserWindowControllers addObject:controller];
+    [controller release];
+
+    [controller loadURLString:[SettingsController shared].defaultURL];
+#endif
+}
+
 - (void)browserWindowWillClose:(NSWindow *)window
 {
     [_browserWindowControllers removeObject:window.windowController];
index c5df401..f5f9770 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7096" systemVersion="14D42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7096"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -10,7 +10,7 @@
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
-        <customObject id="-3" userLabel="Application"/>
+        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <menu title="AMainMenu" systemMenu="main" id="29">
             <items>
                 <menuItem title="MiniBrowser" id="56">
                                     <action selector="newWindow:" target="-1" id="572"/>
                                 </connections>
                             </menuItem>
+                            <menuItem title="New WebKit2 Private Window" tag="2" id="Zqs-AO-XAX">
+                                <modifierMask key="keyEquivalentModifierMask"/>
+                                <connections>
+                                    <action selector="newPrivateWindow:" target="-1" id="mf5-zi-a5R"/>
+                                </connections>
+                            </menuItem>
                             <menuItem title="Open…" keyEquivalent="o" id="72">
                                 <connections>
                                     <action selector="openDocument:" target="-1" id="374"/>
index ffa1d1e..1632994 100644 (file)
@@ -28,6 +28,9 @@
 #if WK_API_ENABLED
 
 @interface WK2BrowserWindowController : BrowserWindowController <BrowserController>
+
+- (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration;
+
 @end
 
 #endif // WK_API_ENABLED
index 93341c7..7a6674c 100644 (file)
@@ -34,8 +34,9 @@
 #import <WebKit/WKPreferencesPrivate.h>
 #import <WebKit/WKUIDelegate.h>
 #import <WebKit/WKWebView.h>
-#import <WebKit/WKWebViewConfiguration.h>
+#import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/_WKWebsiteDataStore.h>
 
 static void* keyValueObservingContext = &keyValueObservingContext;
 
@@ -43,19 +44,15 @@ static void* keyValueObservingContext = &keyValueObservingContext;
 @end
 
 @implementation WK2BrowserWindowController {
+    WKWebViewConfiguration *_configuration;
     WKWebView *_webView;
     BOOL _zoomTextOnly;
+    BOOL _isPrivateBrowsingWindow;
 }
 
 - (void)awakeFromNib
 {
-    static WKWebViewConfiguration *configuration;
-    if (!configuration) {
-        configuration = [[WKWebViewConfiguration alloc] init];
-        configuration.preferences._fullScreenEnabled = YES;
-        configuration.preferences._developerExtrasEnabled = YES;
-    }
-    _webView = [[WKWebView alloc] initWithFrame:[containerView bounds] configuration:configuration];
+    _webView = [[WKWebView alloc] initWithFrame:[containerView bounds] configuration:_configuration];
     [self didChangeSettings];
 
     _webView.allowsMagnification = YES;
@@ -76,6 +73,17 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     _zoomTextOnly = NO;
 }
 
+- (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration
+{
+    if (!(self = [super initWithWindowNibName:@"BrowserWindow"]))
+        return nil;
+
+    _configuration = [configuration copy];
+    _isPrivateBrowsingWindow = _configuration._websiteDataStore.isNonPersistent;
+
+    return self;
+}
+
 - (void)dealloc
 {
     [_webView removeObserver:self forKeyPath:@"title"];
@@ -85,6 +93,7 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     [progressIndicator unbind:NSValueBinding];
 
     [_webView release];
+    [_configuration release];
 
     [super dealloc];
 }
@@ -315,7 +324,7 @@ static void* keyValueObservingContext = &keyValueObservingContext;
         return;
 
     if ([keyPath isEqualToString:@"title"])
-        self.window.title = [_webView.title stringByAppendingFormat:@" [WK2, %d]", _webView._webProcessIdentifier];
+        self.window.title = [NSString stringWithFormat:@"%@%@ [WK2 %d]", _isPrivateBrowsingWindow ? @"🙈 " : @"", _webView.title, _webView._webProcessIdentifier];
     else if ([keyPath isEqualToString:@"URL"])
         [self updateTextFieldFromURL:_webView.URL];
 }