Expose a way for MiniBrowser to simulate header and footer banners
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2016 21:09:34 +0000 (21:09 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2016 21:09:34 +0000 (21:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166005

Reviewed by Wenson Hsieh.

Source/WebKit2:

Expose testing SPI that allows a client to simulate the presence of header
and footer banners. These are simply plumbed through to set FrameView's
m_headerHeight and m_footerHeight.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setHeaderBannerHeightForTesting:]):
(-[WKWebView _setFooterBannerHeightForTesting:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setHeaderBannerHeightForTesting):
(WebKit::WebPageProxy::setFooterBannerHeightForTesting):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setHeaderBannerHeightForTesting):
(WebKit::WebPage::setFooterBannerHeightForTesting):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

Add a MiniBrowser menu item and setting to toggle adding space for header and footer
banners. This only works in WebKit2.

We need to reset these on each navigation, since newly created FrameViews
don't re-fetch the header and footer height stored on Page.

Also fix the signature of webView:didFinishNavigation: to follow API changes,
as well as fixing webViewWebContentProcessDidTerminate:

* MiniBrowser/mac/SettingsController.h:
* MiniBrowser/mac/SettingsController.m:
(-[SettingsController _populateMenu]):
(-[SettingsController validateMenuItem:]):
(-[SettingsController toggleReserveSpaceForBanners:]):
(-[SettingsController isSpaceReservedForBanners]):
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController didChangeSettings]):
(-[WK2BrowserWindowController webView:didFinishNavigation:]):
(-[WK2BrowserWindowController webViewWebContentProcessDidTerminate:]):
(-[WK2BrowserWindowController webView:didFinishLoadingNavigation:]): Deleted.
(-[WK2BrowserWindowController _webViewWebProcessDidCrash:]): Deleted.

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Tools/ChangeLog
Tools/MiniBrowser/mac/SettingsController.h
Tools/MiniBrowser/mac/SettingsController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m

index 55dd86e..5d12e73 100644 (file)
@@ -1,3 +1,28 @@
+2016-12-18  Simon Fraser  <simon.fraser@apple.com>
+
+        Expose a way for MiniBrowser to simulate header and footer banners
+        https://bugs.webkit.org/show_bug.cgi?id=166005
+
+        Reviewed by Wenson Hsieh.
+        
+        Expose testing SPI that allows a client to simulate the presence of header
+        and footer banners. These are simply plumbed through to set FrameView's
+        m_headerHeight and m_footerHeight.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _setHeaderBannerHeightForTesting:]):
+        (-[WKWebView _setFooterBannerHeightForTesting:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setHeaderBannerHeightForTesting):
+        (WebKit::WebPageProxy::setFooterBannerHeightForTesting):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setHeaderBannerHeightForTesting):
+        (WebKit::WebPage::setFooterBannerHeightForTesting):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2016-12-16  Dave Hyatt  <hyatt@apple.com>
 
         [CSS Values] Make separate wrapper classes for the deprecated CSS Values OM
index f5741cf..5d10694 100644 (file)
@@ -4863,6 +4863,17 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
 {
     [self insertText:string replacementRange:replacementRange];
 }
+
+- (void)_setHeaderBannerHeight:(int)height
+{
+    _page->setHeaderBannerHeightForTesting(height);
+}
+
+- (void)_setFooterBannerHeight:(int)height
+{
+    _page->setFooterBannerHeightForTesting(height);
+}
+
 #endif // PLATFORM(MAC)
 
 - (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin
index 071f6bc..313b338 100644 (file)
@@ -312,6 +312,9 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 - (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession title:(NSString *)title duration:(double)duration elapsedTime:(double)elapsedTime WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 
 - (void)_insertText:(id)string replacementRange:(NSRange)replacementRange WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+
+- (void)_setHeaderBannerHeight:(int)height WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_setFooterBannerHeight:(int)height WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 #endif
 
 - (void)_setPageScale:(CGFloat)scale withOrigin:(CGPoint)origin WK_API_AVAILABLE(ios(WK_IOS_TBA));
index 2c8d52d..a3d9bd8 100644 (file)
@@ -6574,6 +6574,17 @@ void WebPageProxy::didHandleAcceptedCandidate()
 {
     m_pageClient.didHandleAcceptedCandidate();
 }
+
+void WebPageProxy::setHeaderBannerHeightForTesting(int height)
+{
+    m_process->send(Messages::WebPage::SetHeaderBannerHeightForTesting(height), m_pageID);
+}
+
+void WebPageProxy::setFooterBannerHeightForTesting(int height)
+{
+    m_process->send(Messages::WebPage::SetFooterBannerHeightForTesting(height), m_pageID);
+}
+
 #endif
 
 void WebPageProxy::imageOrMediaDocumentSizeChanged(const WebCore::IntSize& newSize)
index 3a47230..ef56b1c 100644 (file)
@@ -1088,6 +1088,9 @@ public:
 
     void handleAcceptedCandidate(WebCore::TextCheckingResult);
     void didHandleAcceptedCandidate();
+
+    void setHeaderBannerHeightForTesting(int);
+    void setFooterBannerHeightForTesting(int);
 #endif
 
 #if PLATFORM(EFL) && HAVE(ACCESSIBILITY) && defined(HAVE_ECORE_X)
index 64f0934..4fdd8cb 100644 (file)
@@ -1833,6 +1833,21 @@ void WebPage::showPageBanners()
     if (m_footerBanner)
         m_footerBanner->showIfHidden();
 }
+
+void WebPage::setHeaderBannerHeightForTesting(int height)
+{
+#if ENABLE(RUBBER_BANDING)
+    corePage()->addHeaderWithHeight(height);
+#endif
+}
+
+void WebPage::setFooterBannerHeightForTesting(int height)
+{
+#if ENABLE(RUBBER_BANDING)
+    corePage()->addFooterWithHeight(height);
+#endif
+}
+
 #endif // !PLATFORM(IOS)
 
 void WebPage::takeSnapshot(IntRect snapshotRect, IntSize bitmapSize, uint32_t options, uint64_t callbackID)
index 9255c14..8104082 100644 (file)
@@ -475,6 +475,8 @@ public:
     void hidePageBanners();
     void showPageBanners();
     
+    void setHeaderBannerHeightForTesting(int);
+    void setFooterBannerHeightForTesting(int);
 #endif // !PLATFORM(IOS)
 
     WebCore::IntPoint screenToRootView(const WebCore::IntPoint&);
index 40a3b81..d415ffe 100644 (file)
@@ -416,11 +416,16 @@ messages -> WebPage LegacyReceiver {
     ImmediateActionDidUpdate()
     ImmediateActionDidCancel()
     ImmediateActionDidComplete()
+
     DataDetectorsDidPresentUI(WebCore::PageOverlay::PageOverlayID pageOverlay)
     DataDetectorsDidChangeUI(WebCore::PageOverlay::PageOverlayID pageOverlay)
     DataDetectorsDidHideUI(WebCore::PageOverlay::PageOverlayID pageOverlay)
+
     HandleAcceptedCandidate(struct WebCore::TextCheckingResult acceptedCandidate)
     RequestActiveNowPlayingSessionInfo()
+
+    SetHeaderBannerHeightForTesting(int height);
+    SetFooterBannerHeightForTesting(int height);
 #endif
 
     SetShouldDispatchFakeMouseMoveEvents(bool shouldDispatchFakeMouseMoveEvents)
index f4510f4..f8cd369 100644 (file)
@@ -1,3 +1,32 @@
+2016-12-18  Simon Fraser  <simon.fraser@apple.com>
+
+        Expose a way for MiniBrowser to simulate header and footer banners
+        https://bugs.webkit.org/show_bug.cgi?id=166005
+
+        Reviewed by Wenson Hsieh.
+        
+        Add a MiniBrowser menu item and setting to toggle adding space for header and footer
+        banners. This only works in WebKit2.
+        
+        We need to reset these on each navigation, since newly created FrameViews
+        don't re-fetch the header and footer height stored on Page.
+        
+        Also fix the signature of webView:didFinishNavigation: to follow API changes,
+        as well as fixing webViewWebContentProcessDidTerminate:
+
+        * MiniBrowser/mac/SettingsController.h:
+        * MiniBrowser/mac/SettingsController.m:
+        (-[SettingsController _populateMenu]):
+        (-[SettingsController validateMenuItem:]):
+        (-[SettingsController toggleReserveSpaceForBanners:]):
+        (-[SettingsController isSpaceReservedForBanners]):
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController didChangeSettings]):
+        (-[WK2BrowserWindowController webView:didFinishNavigation:]):
+        (-[WK2BrowserWindowController webViewWebContentProcessDidTerminate:]):
+        (-[WK2BrowserWindowController webView:didFinishLoadingNavigation:]): Deleted.
+        (-[WK2BrowserWindowController _webViewWebProcessDidCrash:]): Deleted.
+
 2016-12-17  Simon Fraser  <simon.fraser@apple.com>
 
         Fix iOS test results after r209967.
index f20fe60..aac5e8d 100644 (file)
@@ -40,6 +40,7 @@
 @property (nonatomic, readonly) BOOL simpleLineLayoutDebugBordersEnabled;
 @property (nonatomic, readonly) BOOL incrementalRenderingSuppressed;
 @property (nonatomic, readonly) BOOL tiledScrollingIndicatorVisible;
+@property (nonatomic, readonly, getter=isSpaceReservedForBanners) BOOL spaceReservedForBanners;
 @property (nonatomic, readonly) BOOL resourceUsageOverlayVisible;
 @property (nonatomic, readonly) BOOL nonFastScrollableRegionOverlayVisible;
 @property (nonatomic, readonly) BOOL wheelEventHandlerRegionOverlayVisible;
index 0e1b735..bb584e8 100644 (file)
@@ -40,6 +40,8 @@ static NSString * const UseWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault
 static NSString * const LayerBordersVisiblePreferenceKey = @"LayerBordersVisible";
 static NSString * const SimpleLineLayoutDebugBordersEnabledPreferenceKey = @"SimpleLineLayoutDebugBordersEnabled";
 static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScrollingIndicatorVisible";
+static NSString * const ReserveSpaceForBannersPreferenceKey = @"ReserveSpaceForBanners";
+
 static NSString * const ResourceUsageOverlayVisiblePreferenceKey = @"ResourceUsageOverlayVisible";
 static NSString * const LoadsAllSiteIconsKey = @"LoadsAllSiteIcons";
 static NSString * const UsesGameControllerFrameworkKey = @"UsesGameControllerFramework";
@@ -135,6 +137,7 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
 
     [self _addHeaderWithTitle:@"WebKit2-only Settings"];
 
+    [self _addItemWithTitle:@"Reserve Space For Banners" action:@selector(toggleReserveSpaceForBanners:) indented:YES];
     [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];
@@ -213,6 +216,8 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
         [menuItem setState:[self animatedImageAsyncDecodingEnabled] ? NSOnState : NSOffState];
     else if (action == @selector(toggleVisualViewportEnabled:))
         [menuItem setState:[self visualViewportEnabled] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleReserveSpaceForBanners:))
+        [menuItem setState:[self isSpaceReservedForBanners] ? NSOnState : NSOffState];
     else if (action == @selector(toggleShowTiledScrollingIndicator:))
         [menuItem setState:[self tiledScrollingIndicatorVisible] ? NSOnState : NSOffState];
     else if (action == @selector(toggleShowResourceUsageOverlay:))
@@ -360,6 +365,11 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     return [[NSUserDefaults standardUserDefaults] boolForKey:DisplayListDrawingEnabledPreferenceKey];
 }
 
+- (void)toggleReserveSpaceForBanners:(id)sender
+{
+    [self _toggleBooleanDefault:ReserveSpaceForBannersPreferenceKey];
+}
+
 - (void)toggleShowTiledScrollingIndicator:(id)sender
 {
     [self _toggleBooleanDefault:TiledScrollingIndicatorVisiblePreferenceKey];
@@ -400,6 +410,11 @@ typedef NS_ENUM(NSInteger, DebugOverylayMenuItemTag) {
     [self _toggleBooleanDefault:NetworkCacheSpeculativeRevalidationDisabledKey];
 }
 
+- (BOOL)isSpaceReservedForBanners
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:ReserveSpaceForBannersPreferenceKey];
+}
+
 - (BOOL)tiledScrollingIndicatorVisible
 {
     return [[NSUserDefaults standardUserDefaults] boolForKey:TiledScrollingIndicatorVisiblePreferenceKey];
index b5898fb..fd0f6c4 100644 (file)
@@ -43,6 +43,8 @@
 #import <WebKit/_WKUserInitiatedAction.h>
 
 static void* keyValueObservingContext = &keyValueObservingContext;
+static const int testHeaderBannerHeight = 42;
+static const int testFooterBannerHeight = 58;
 
 @interface WK2BrowserWindowController () <WKNavigationDelegate, WKUIDelegate, _WKIconLoadingDelegate>
 @end
@@ -408,6 +410,9 @@ static BOOL areEssentiallyEqual(double a, double b)
         visibleOverlayRegions |= _WKWheelEventHandlerRegion;
     
     preferences._visibleDebugOverlayRegions = visibleOverlayRegions;
+
+    [_webView _setHeaderBannerHeight:[settings isSpaceReservedForBanners] ? testHeaderBannerHeight : 0];
+    [_webView _setFooterBannerHeight:[settings isSpaceReservedForBanners] ? testFooterBannerHeight : 0];
 }
 
 - (void)updateTitle:(NSString *)title
@@ -617,9 +622,15 @@ static NSSet *dataTypes()
     [self updateTitle:nil];
 }
 
-- (void)webView:(WKWebView *)webView didFinishLoadingNavigation:(WKNavigation *)navigation
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
 {
-    LOG(@"didFinishLoadingNavigation: %@", navigation);
+    LOG(@"didFinishNavigation: %@", navigation);
+    
+    // Banner heights don't persist across page loads (oddly, since Page stores them), so reset on every page load.
+    if ([[SettingsController shared] isSpaceReservedForBanners]) {
+        [_webView _setHeaderBannerHeight:testHeaderBannerHeight];
+        [_webView _setFooterBannerHeight:testFooterBannerHeight];
+    }
 }
 
 - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *__nullable credential))completionHandler
@@ -633,7 +644,7 @@ static NSSet *dataTypes()
     LOG(@"didFailNavigation: %@, error %@", navigation, error);
 }
 
-- (void)_webViewWebProcessDidCrash:(WKWebView *)webView
+- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
 {
     NSLog(@"WebContent process crashed; reloading");
     [self reload:nil];