Changeset 239134 in webkit


Ignore:
Timestamp:
Dec 12, 2018 4:41:21 PM (5 years ago)
Author:
achristensen@apple.com
Message:

Implement safe browsing in WebKit on WatchOS
https://bugs.webkit.org/show_bug.cgi?id=192641
<rdar://problem/46376188>

Reviewed by Geoff Garen.

Source/WebKit:

WatchOS has a few special requirements:

  1. The margin size needs to be smaller and the title font smaller to fit on the screen.
  2. The exclamation point cannot be beside the title or it won't fit on the screen. I put it above the title.
  3. The application must be told when the safe browsing warning has been shown. I added a new delegate callback.
  4. The UIScrollView's contentSize must be set even before the details are shown to be able to scroll down to the buttons. This was already an issue on small WKWebViews on iOS, so this fixes both operating systems.
  • Configurations/WebKit.xcconfig:
  • UIProcess/API/APIUIClient.h:

(API::UIClient::didShowSafeBrowsingWarning):

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::didShowSafeBrowsingWarning):

  • UIProcess/Cocoa/WKSafeBrowsingWarning.mm:

(fontOfSize):
(buttonSize):
(-[WKSafeBrowsingWarning addContent]):
(-[WKSafeBrowsingWarning showDetailsClicked]):
(-[WKSafeBrowsingWarning updateContentSize]):
(buttonWidth): Deleted.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::decidePolicyForNavigationAction):

Source/WTF:

  • wtf/Platform.h:

WatchOS has safe browsing, too!

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:

(-[SafeBrowsingNavigationDelegate _webViewDidShowSafeBrowsingWarning:]):
(safeBrowsingView):
Add a test that the new delegate callback is called.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r239093 r239134  
     12018-12-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement safe browsing in WebKit on WatchOS
     4        https://bugs.webkit.org/show_bug.cgi?id=192641
     5        <rdar://problem/46376188>
     6
     7        Reviewed by Geoff Garen.
     8
     9        * wtf/Platform.h:
     10        WatchOS has safe browsing, too!
     11
    1122018-12-11  Fujii Hironori  <Hironori.Fujii@sony.com>
    213
  • trunk/Source/WTF/wtf/Platform.h

    r239068 r239134  
    14381438#endif
    14391439
    1440 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || PLATFORM(IOS)) && !defined(__i386__)
     1440#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 && !defined(__i386__)) || PLATFORM(IOS) || PLATFORM(WATCHOS)
    14411441#define HAVE_SAFE_BROWSING 1
    14421442#endif
  • trunk/Source/WebKit/ChangeLog

    r239133 r239134  
     12018-12-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement safe browsing in WebKit on WatchOS
     4        https://bugs.webkit.org/show_bug.cgi?id=192641
     5        <rdar://problem/46376188>
     6
     7        Reviewed by Geoff Garen.
     8
     9        WatchOS has a few special requirements:
     10        1. The margin size needs to be smaller and the title font smaller to fit on the screen.
     11        2. The exclamation point cannot be beside the title or it won't fit on the screen.  I put it above the title.
     12        3. The application must be told when the safe browsing warning has been shown.  I added a new delegate callback.
     13        4. The UIScrollView's contentSize must be set even before the details are shown to be able to scroll down to the buttons.
     14           This was already an issue on small WKWebViews on iOS, so this fixes both operating systems.
     15
     16        * Configurations/WebKit.xcconfig:
     17        * UIProcess/API/APIUIClient.h:
     18        (API::UIClient::didShowSafeBrowsingWarning):
     19        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     20        * UIProcess/Cocoa/UIDelegate.h:
     21        * UIProcess/Cocoa/UIDelegate.mm:
     22        (WebKit::UIDelegate::setDelegate):
     23        (WebKit::UIDelegate::UIClient::didShowSafeBrowsingWarning):
     24        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
     25        (fontOfSize):
     26        (buttonSize):
     27        (-[WKSafeBrowsingWarning addContent]):
     28        (-[WKSafeBrowsingWarning showDetailsClicked]):
     29        (-[WKSafeBrowsingWarning updateContentSize]):
     30        (buttonWidth): Deleted.
     31        * UIProcess/WebPageProxy.cpp:
     32        (WebKit::WebPageProxy::decidePolicyForNavigationAction):
     33
    1342018-12-12  Commit Queue  <commit-queue@webkit.org>
    235
  • trunk/Source/WebKit/Configurations/WebKit.xcconfig

    r238849 r239134  
    112112WK_SAFE_BROWSING_LDFLAGS_iphoneos = -framework SafariSafeBrowsing;
    113113WK_SAFE_BROWSING_LDFLAGS_iphonesimulator = -framework SafariSafeBrowsing;
     114WK_SAFE_BROWSING_LDFLAGS_watchos = -framework SafariSafeBrowsing;
     115WK_SAFE_BROWSING_LDFLAGS_watchsimulator = -framework SafariSafeBrowsing;
    114116WK_SAFE_BROWSING_LDFLAGS_iphoneos[sdk=iphone*10.*] = ;
    115117WK_SAFE_BROWSING_LDFLAGS_iphonesimulator[sdk=iphone*10.*] = ;
  • trunk/Source/WebKit/UIProcess/API/APIUIClient.h

    r238771 r239134  
    181181
    182182    virtual void didExceedBackgroundResourceLimitWhileInForeground(WebKit::WebPageProxy&, WKResourceLimit) { }
     183   
     184    virtual void didShowSafeBrowsingWarning() { }
    183185};
    184186
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r239049 r239134  
    100100- (void)_webViewRequestPointerLock:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.12.3));
    101101- (void)_webViewDidRequestPointerLock:(WKWebView *)webView completionHandler:(void (^)(BOOL))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     102- (void)_webViewDidShowSafeBrowsingWarning:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    102103- (void)_webViewDidLosePointerLock:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.12.3));
    103104- (void)_webView:(WKWebView *)webView hasVideoInPictureInPictureDidChange:(BOOL)hasVideoInPictureInPicture WK_API_AVAILABLE(macosx(10.13), ios(11.0));
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r238771 r239134  
    147147
    148148        void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
     149        void didShowSafeBrowsingWarning() final;
    149150
    150151        UIDelegate& m_uiDelegate;
     
    223224#endif
    224225        bool webViewHasVideoInPictureInPictureDidChange : 1;
     226        bool webViewDidShowSafeBrowsingWarning : 1;
    225227    } m_delegateMethods;
    226228};
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r239078 r239134  
    170170   
    171171    m_delegateMethods.webViewHasVideoInPictureInPictureDidChange = [delegate respondsToSelector:@selector(_webView:hasVideoInPictureInPictureDidChange:)];
     172    m_delegateMethods.webViewDidShowSafeBrowsingWarning = [delegate respondsToSelector:@selector(_webViewDidShowSafeBrowsingWarning:)];
    172173}
    173174
     
    12181219#endif
    12191220   
     1221void UIDelegate::UIClient::didShowSafeBrowsingWarning()
     1222{
     1223    if (!m_uiDelegate.m_delegateMethods.webViewDidShowSafeBrowsingWarning)
     1224        return;
     1225
     1226    auto delegate = m_uiDelegate.m_delegate.get();
     1227    if (!delegate)
     1228        return;
     1229
     1230    [static_cast<id <WKUIDelegatePrivate>>(delegate) _webViewDidShowSafeBrowsingWarning:m_uiDelegate.m_webView];
     1231}
     1232
    12201233void UIDelegate::UIClient::hasVideoInPictureInPictureDidChange(WebPageProxy*, bool hasVideoInPictureInPicture)
    12211234{
  • trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm

    r239078 r239134  
    3737constexpr CGFloat boxCornerRadius = 6;
    3838#if HAVE(SAFE_BROWSING)
     39#if PLATFORM(WATCHOS)
     40constexpr CGFloat marginSize = 10;
     41#else
    3942constexpr CGFloat marginSize = 20;
     43#endif
    4044constexpr CGFloat maxWidth = 675;
    4145#endif
     
    8690    switch (size) {
    8791    case WarningTextSize::Title:
     92#if PLATFORM(WATCHOS)
     93        return [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
     94#else
    8895        return [UIFont preferredFontForTextStyle:UIFontTextStyleLargeTitle];
     96#endif
    8997    case WarningTextSize::Body:
    9098        return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
     
    221229
    222230#if HAVE(SAFE_BROWSING)
    223 static CGFloat buttonWidth(ButtonType *button)
    224 {
    225 #if PLATFORM(MAC)
    226     return button.frame.size.width;
    227 #else
    228     return button.titleLabel.intrinsicContentSize.width;
     231static CGSize buttonSize(ButtonType *button)
     232{
     233#if PLATFORM(MAC)
     234    return button.frame.size;
     235#else
     236    return button.titleLabel.intrinsicContentSize;
    229237#endif
    230238}
     
    302310    [self addSubview:box];
    303311
     312#if PLATFORM(WATCHOS)
     313    [NSLayoutConstraint activateConstraints:@[
     314        [[box.leadingAnchor anchorWithOffsetToAnchor:exclamationPoint.leadingAnchor] constraintEqualToAnchor:[exclamationPoint.trailingAnchor anchorWithOffsetToAnchor:box.trailingAnchor]],
     315        [[box.leadingAnchor anchorWithOffsetToAnchor:title.leadingAnchor] constraintEqualToConstant:marginSize],
     316        [[title.bottomAnchor anchorWithOffsetToAnchor:warning.topAnchor] constraintEqualToConstant:marginSize],
     317        [[exclamationPoint.bottomAnchor anchorWithOffsetToAnchor:title.topAnchor] constraintEqualToConstant:marginSize],
     318        [[box.topAnchor anchorWithOffsetToAnchor:exclamationPoint.topAnchor] constraintEqualToConstant:marginSize + self.frame.size.height / 2],
     319        [[self.topAnchor anchorWithOffsetToAnchor:box.topAnchor] constraintEqualToAnchor:[box.bottomAnchor anchorWithOffsetToAnchor:self.bottomAnchor] multiplier:0.2],
     320    ]];
     321#elif HAVE(SAFE_BROWSING)
     322    [NSLayoutConstraint activateConstraints:@[
     323        [[box.leadingAnchor anchorWithOffsetToAnchor:exclamationPoint.leadingAnchor] constraintEqualToConstant:marginSize],
     324        [[box.leadingAnchor anchorWithOffsetToAnchor:title.leadingAnchor] constraintEqualToConstant:marginSize * 1.5 + exclamationPointSize],
     325        [[title.topAnchor anchorWithOffsetToAnchor:exclamationPoint.topAnchor] constraintEqualToAnchor:[exclamationPoint.bottomAnchor anchorWithOffsetToAnchor:title.bottomAnchor]],
     326        [[title.bottomAnchor anchorWithOffsetToAnchor:warning.topAnchor] constraintEqualToConstant:marginSize],
     327        [[box.topAnchor anchorWithOffsetToAnchor:title.topAnchor] constraintEqualToConstant:marginSize],
     328        [[self.topAnchor anchorWithOffsetToAnchor:box.topAnchor] constraintEqualToAnchor:[box.bottomAnchor anchorWithOffsetToAnchor:self.bottomAnchor] multiplier:0.5],
     329    ]];
     330#endif
     331
    304332#if HAVE(SAFE_BROWSING)
    305333    [NSLayoutConstraint activateConstraints:@[
    306         [[self.topAnchor anchorWithOffsetToAnchor:box.topAnchor] constraintEqualToAnchor:[box.bottomAnchor anchorWithOffsetToAnchor:self.bottomAnchor] multiplier:0.5],
    307334        [[self.leftAnchor anchorWithOffsetToAnchor:box.leftAnchor] constraintEqualToAnchor:[box.rightAnchor anchorWithOffsetToAnchor:self.rightAnchor]],
    308335
     
    310337        [box.widthAnchor constraintLessThanOrEqualToAnchor:self.widthAnchor],
    311338
    312         [[box.leadingAnchor anchorWithOffsetToAnchor:exclamationPoint.leadingAnchor] constraintEqualToConstant:marginSize],
    313         [[box.leadingAnchor anchorWithOffsetToAnchor:title.leadingAnchor] constraintEqualToConstant:marginSize * 1.5 + exclamationPointSize],
    314339        [[box.leadingAnchor anchorWithOffsetToAnchor:warning.leadingAnchor] constraintEqualToConstant:marginSize],
    315340
     
    318343        [[goBack.trailingAnchor anchorWithOffsetToAnchor:box.trailingAnchor] constraintEqualToConstant:marginSize],
    319344
    320         [[title.topAnchor anchorWithOffsetToAnchor:exclamationPoint.topAnchor] constraintEqualToAnchor:[exclamationPoint.bottomAnchor anchorWithOffsetToAnchor:title.bottomAnchor]],
    321 
    322         [[box.topAnchor anchorWithOffsetToAnchor:title.topAnchor] constraintEqualToConstant:marginSize],
    323         [[title.bottomAnchor anchorWithOffsetToAnchor:warning.topAnchor] constraintEqualToConstant:marginSize],
    324345        [[warning.bottomAnchor anchorWithOffsetToAnchor:goBack.topAnchor] constraintEqualToConstant:marginSize],
    325346    ]];
    326347   
    327     bool needsVerticalButtonLayout = buttonWidth(showDetails) + buttonWidth(goBack) + 3 * marginSize > self.frame.size.width;
     348    bool needsVerticalButtonLayout = buttonSize(showDetails).width + buttonSize(goBack).width + 3 * marginSize > self.frame.size.width;
    328349    if (needsVerticalButtonLayout) {
    329350        [NSLayoutConstraint activateConstraints:@[
    330351            [[showDetails.trailingAnchor anchorWithOffsetToAnchor:box.trailingAnchor] constraintEqualToConstant:marginSize],
    331352            [[goBack.bottomAnchor anchorWithOffsetToAnchor:showDetails.topAnchor] constraintEqualToConstant:marginSize],
    332             [[goBack.bottomAnchor anchorWithOffsetToAnchor:box.bottomAnchor] constraintEqualToConstant:marginSize * 2 + showDetails.frame.size.height],
     353            [[goBack.bottomAnchor anchorWithOffsetToAnchor:box.bottomAnchor] constraintEqualToConstant:marginSize * 2 + buttonSize(showDetails).height],
    333354        ]];
    334355    } else {
     
    339360        ]];
    340361    }
     362#if !PLATFORM(MAC)
     363    [self updateContentSize];
     364#endif
    341365#endif
    342366}
     
    393417    [self layoutText];
    394418#if !PLATFORM(MAC)
     419    [self updateContentSize];
     420#endif
     421}
     422
     423#if !PLATFORM(MAC)
     424- (void)updateContentSize
     425{
    395426    [self layoutIfNeeded];
    396427    CGFloat height = 0;
     
    398429        height += subview.frame.size.height;
    399430    [self setContentSize: { self.frame.size.width, self.frame.size.height / 2 + height }];
    400 #endif
    401 }
     431}
     432#endif
    402433
    403434- (void)layoutText
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r239133 r239134  
    43244324                });
    43254325            });
     4326            m_uiClient->didShowSafeBrowsingWarning();
    43264327            return;
    43274328        }
  • trunk/Tools/ChangeLog

    r239123 r239134  
     12018-12-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement safe browsing in WebKit on WatchOS
     4        https://bugs.webkit.org/show_bug.cgi?id=192641
     5        <rdar://problem/46376188>
     6
     7        Reviewed by Geoff Garen.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
     10        (-[SafeBrowsingNavigationDelegate _webViewDidShowSafeBrowsingWarning:]):
     11        (safeBrowsingView):
     12        Add a test that the new delegate callback is called.
     13
    1142018-12-12  Michael Catanzaro  <mcatanzaro@igalia.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

    r238921 r239134  
    3333#import "TestWKWebView.h"
    3434#import <WebKit/WKNavigationDelegate.h>
     35#import <WebKit/WKUIDelegatePrivate.h>
    3536#import <WebKit/WKWebViewPrivate.h>
    3637#import <wtf/RetainPtr.h>
    3738
    3839static bool committedNavigation;
    39 
    40 @interface SafeBrowsingNavigationDelegate : NSObject <WKNavigationDelegate>
     40static bool warningShown;
     41
     42@interface SafeBrowsingNavigationDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>
    4143@end
    4244
     
    4648{
    4749    committedNavigation = true;
     50}
     51
     52- (void)_webViewDidShowSafeBrowsingWarning:(WKWebView *)webView
     53{
     54    warningShown = true;
    4855}
    4956
     
    174181    auto webView = adoptNS([WKWebView new]);
    175182    [webView setNavigationDelegate:delegate.get()];
     183    [webView setUIDelegate:delegate.get()];
    176184    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple")]];
     185    EXPECT_FALSE(warningShown);
    177186    while (![webView _safeBrowsingWarning])
    178187        TestWebKitAPI::Util::spinRunLoop();
     188    EXPECT_TRUE(warningShown);
    179189#if !PLATFORM(MAC)
    180190    [[webView _safeBrowsingWarning] didMoveToWindow];
Note: See TracChangeset for help on using the changeset viewer.