Changeset 238115 in webkit


Ignore:
Timestamp:
Nov 12, 2018, 5:08:07 PM (6 years ago)
Author:
achristensen@apple.com
Message:

[iOS] Implement safe browsing in WebKit
https://bugs.webkit.org/show_bug.cgi?id=191441

Reviewed by Tim Horton.

Source/WebKit:

In r237863 I implemented this for Mac. This refines the UI and implements it for iOS.

  • Shared/WebPreferences.yaml:
  • Shared/WebPreferencesDefaultValues.h:
  • UIProcess/API/C/mac/WKContextPrivateMac.mm:

(WKContextHandlesSafeBrowsing):

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
(-[WKWebView _clearSafeBrowsingWarning]):
(-[WKWebView layoutSubviews]):
(-[WKWebView setFrameSize:]):
(+[WKWebView _handlesSafeBrowsing]):
(-[WKWebView _safeBrowsingWarningForTesting]):

  • UIProcess/API/Cocoa/WKWebViewInternal.h:
  • UIProcess/Cocoa/PageClientImplCocoa.h:
  • UIProcess/Cocoa/PageClientImplCocoa.mm:

(WebKit::PageClientImplCocoa::allocFileWrapperInstance const):
(WebKit::PageClientImplCocoa::serializableFileWrapperClasses const):

  • UIProcess/Cocoa/WKSafeBrowsingWarning.h:
  • UIProcess/Cocoa/WKSafeBrowsingWarning.mm:

(confirmMalwareSentinel):
(visitUnsafeWebsiteSentinel):
(colorForItem):
(addLinkAndReplace):
(-[WKSafeBrowsingExclamationPoint drawRect:]):
(makeButton):
(makeTitleLabel):
(setBackground):
(-[WKSafeBrowsingWarning initWithFrame:safeBrowsingResult:completionHandler:]):
(-[WKSafeBrowsingWarning addContent]):
(-[WKSafeBrowsingWarning showDetailsClicked]):
(-[WKSafeBrowsingWarning layoutText]):
(-[WKSafeBrowsingWarning textView:clickedOnLink:atIndex:]):
(-[WKSafeBrowsingWarning layout]):
(-[WKSafeBrowsingWarning layoutSubviews]):
(-[WKSafeBrowsingWarning textView:shouldInteractWithURL:inRange:interaction:]):
(-[WKSafeBrowsingWarning didMoveToWindow]):
(-[WKSafeBrowsingWarning clickedOnLink:]):
(-[WKSafeBrowsingTextView initWithAttributedString:forWarning:]):
(-[WKSafeBrowsingTextView intrinsicContentSize]):
(colorNamed): Deleted.
(+[WKSafeBrowsingTextView viewWithAttributedString:linkTarget:]): Deleted.
(+[WKSafeBrowsingTextView viewWithString:]): Deleted.
(-[WKSafeBrowsingTextView clickedOnLink:atIndex:]): Deleted.

  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::isViewWindowActive):
(WebKit::PageClientImpl::isViewFocused):
(WebKit::PageClientImpl::isViewVisible):
(WebKit::PageClientImpl::isViewInWindow):
(WebKit::PageClientImpl::decidePolicyForGeolocationPermissionRequest):
(WebKit::PageClientImpl::enterAcceleratedCompositingMode):
(WebKit::PageClientImpl::showSafeBrowsingWarning):
(WebKit::PageClientImpl::clearSafeBrowsingWarning):
(WebKit::PageClientImpl::mimeTypesWithCustomContentProviders):
(WebKit::PageClientImpl::navigationGestureDidBegin):
(WebKit::PageClientImpl::navigationGestureWillEnd):
(WebKit::PageClientImpl::navigationGestureDidEnd):
(WebKit::PageClientImpl::willRecordNavigationSnapshot):
(WebKit::PageClientImpl::didRemoveNavigationGestureSnapshot):
(WebKit::PageClientImpl::requestPasswordForQuickLookDocument):

  • UIProcess/mac/PageClientImplMac.mm:

(WebKit::PageClientImpl::showShareSheet):
(WebKit::PageClientImpl::navigationGestureDidBegin):
(WebKit::PageClientImpl::navigationGestureWillEnd):
(WebKit::PageClientImpl::navigationGestureDidEnd):
(WebKit::PageClientImpl::willRecordNavigationSnapshot):
(WebKit::PageClientImpl::didRemoveNavigationGestureSnapshot):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:

(checkTitleAndClick):
(TEST):

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r238108 r238115  
     12018-11-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        [iOS] Implement safe browsing in WebKit
     4        https://bugs.webkit.org/show_bug.cgi?id=191441
     5
     6        Reviewed by Tim Horton.
     7
     8        In r237863 I implemented this for Mac.  This refines the UI and implements it for iOS.
     9
     10        * Shared/WebPreferences.yaml:
     11        * Shared/WebPreferencesDefaultValues.h:
     12        * UIProcess/API/C/mac/WKContextPrivateMac.mm:
     13        (WKContextHandlesSafeBrowsing):
     14        * UIProcess/API/Cocoa/WKWebView.mm:
     15        (-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
     16        (-[WKWebView _clearSafeBrowsingWarning]):
     17        (-[WKWebView layoutSubviews]):
     18        (-[WKWebView setFrameSize:]):
     19        (+[WKWebView _handlesSafeBrowsing]):
     20        (-[WKWebView _safeBrowsingWarningForTesting]):
     21        * UIProcess/API/Cocoa/WKWebViewInternal.h:
     22        * UIProcess/Cocoa/PageClientImplCocoa.h:
     23        * UIProcess/Cocoa/PageClientImplCocoa.mm:
     24        (WebKit::PageClientImplCocoa::allocFileWrapperInstance const):
     25        (WebKit::PageClientImplCocoa::serializableFileWrapperClasses const):
     26        * UIProcess/Cocoa/WKSafeBrowsingWarning.h:
     27        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
     28        (confirmMalwareSentinel):
     29        (visitUnsafeWebsiteSentinel):
     30        (colorForItem):
     31        (addLinkAndReplace):
     32        (-[WKSafeBrowsingExclamationPoint drawRect:]):
     33        (makeButton):
     34        (makeTitleLabel):
     35        (setBackground):
     36        (-[WKSafeBrowsingWarning initWithFrame:safeBrowsingResult:completionHandler:]):
     37        (-[WKSafeBrowsingWarning addContent]):
     38        (-[WKSafeBrowsingWarning showDetailsClicked]):
     39        (-[WKSafeBrowsingWarning layoutText]):
     40        (-[WKSafeBrowsingWarning textView:clickedOnLink:atIndex:]):
     41        (-[WKSafeBrowsingWarning layout]):
     42        (-[WKSafeBrowsingWarning layoutSubviews]):
     43        (-[WKSafeBrowsingWarning textView:shouldInteractWithURL:inRange:interaction:]):
     44        (-[WKSafeBrowsingWarning didMoveToWindow]):
     45        (-[WKSafeBrowsingWarning clickedOnLink:]):
     46        (-[WKSafeBrowsingTextView initWithAttributedString:forWarning:]):
     47        (-[WKSafeBrowsingTextView intrinsicContentSize]):
     48        (colorNamed): Deleted.
     49        (+[WKSafeBrowsingTextView viewWithAttributedString:linkTarget:]): Deleted.
     50        (+[WKSafeBrowsingTextView viewWithString:]): Deleted.
     51        (-[WKSafeBrowsingTextView clickedOnLink:atIndex:]): Deleted.
     52        * UIProcess/ios/PageClientImplIOS.mm:
     53        (WebKit::PageClientImpl::isViewWindowActive):
     54        (WebKit::PageClientImpl::isViewFocused):
     55        (WebKit::PageClientImpl::isViewVisible):
     56        (WebKit::PageClientImpl::isViewInWindow):
     57        (WebKit::PageClientImpl::decidePolicyForGeolocationPermissionRequest):
     58        (WebKit::PageClientImpl::enterAcceleratedCompositingMode):
     59        (WebKit::PageClientImpl::showSafeBrowsingWarning):
     60        (WebKit::PageClientImpl::clearSafeBrowsingWarning):
     61        (WebKit::PageClientImpl::mimeTypesWithCustomContentProviders):
     62        (WebKit::PageClientImpl::navigationGestureDidBegin):
     63        (WebKit::PageClientImpl::navigationGestureWillEnd):
     64        (WebKit::PageClientImpl::navigationGestureDidEnd):
     65        (WebKit::PageClientImpl::willRecordNavigationSnapshot):
     66        (WebKit::PageClientImpl::didRemoveNavigationGestureSnapshot):
     67        (WebKit::PageClientImpl::requestPasswordForQuickLookDocument):
     68        * UIProcess/mac/PageClientImplMac.mm:
     69        (WebKit::PageClientImpl::showShareSheet):
     70        (WebKit::PageClientImpl::navigationGestureDidBegin):
     71        (WebKit::PageClientImpl::navigationGestureWillEnd):
     72        (WebKit::PageClientImpl::navigationGestureDidEnd):
     73        (WebKit::PageClientImpl::willRecordNavigationSnapshot):
     74        (WebKit::PageClientImpl::didRemoveNavigationGestureSnapshot):
     75
    1762018-11-12  Tim Horton  <timothy_horton@apple.com>
    277
  • trunk/Source/WebKit/Shared/WebPreferences.yaml

    r238108 r238115  
    5757SafeBrowsingEnabled:
    5858  type: bool
    59   defaultValue: DEFAULT_SAFE_BROWSING_ENABLED
     59  defaultValue: true
    6060  webcoreBinding: none
    6161
  • trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h

    r237863 r238115  
    5959
    6060#if PLATFORM(IOS_FAMILY)
    61 #define DEFAULT_SAFE_BROWSING_ENABLED false
    6261#define DEFAULT_ALLOWS_PICTURE_IN_PICTURE_MEDIA_PLAYBACK true
    6362#define DEFAULT_BACKSPACE_KEY_NAVIGATION_ENABLED false
     
    7978#define EXPERIMENTAL_FULLSCREEN_API_HIDDEN false
    8079#else
    81 #define DEFAULT_SAFE_BROWSING_ENABLED true
    8280#define DEFAULT_ALLOWS_PICTURE_IN_PICTURE_MEDIA_PLAYBACK false
    8381#define DEFAULT_BACKSPACE_KEY_NAVIGATION_ENABLED true
  • trunk/Source/WebKit/UIProcess/API/C/mac/WKContextPrivateMac.mm

    r237863 r238115  
    174174bool WKContextHandlesSafeBrowsing()
    175175{
    176     return DEFAULT_SAFE_BROWSING_ENABLED;
     176    return true;
    177177}
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r238108 r238115  
    275275
    276276    std::optional<BOOL> _resolutionForShareSheetImmediateCompletionForTesting;
     277    RetainPtr<WKSafeBrowsingWarning> _safeBrowsingWarning;
    277278
    278279#if PLATFORM(IOS_FAMILY)
     
    12771278}
    12781279
     1280- (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingResult&)result completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler
     1281{
     1282    _safeBrowsingWarning = adoptNS([[WKSafeBrowsingWarning alloc] initWithFrame:self.bounds safeBrowsingResult:result completionHandler:[weakSelf = WeakObjCPtr<WKWebView>(self), completionHandler = WTFMove(completionHandler)] (auto&& result) mutable {
     1283        if (auto strongSelf = weakSelf.get())
     1284            [std::exchange(strongSelf->_safeBrowsingWarning, nullptr) removeFromSuperview];
     1285        completionHandler(WTFMove(result));
     1286    }]);
     1287    [self addSubview:_safeBrowsingWarning.get()];
     1288}
     1289
     1290- (void)_clearSafeBrowsingWarning
     1291{
     1292    [std::exchange(_safeBrowsingWarning, nullptr) removeFromSuperview];
     1293}
     1294
    12791295#if ENABLE(ATTACHMENT_ELEMENT)
    12801296
     
    13531369- (void)layoutSubviews
    13541370{
     1371    [_safeBrowsingWarning setFrame:self.bounds];
    13551372    [super layoutSubviews];
    13561373    [self _frameOrBoundsChanged];
     
    33133330{
    33143331    [super setFrameSize:size];
     3332    [_safeBrowsingWarning setFrame:self.bounds];
    33153333    _impl->setFrameSize(NSSizeToCGSize(size));
    33163334}
     
    47124730+ (BOOL)_handlesSafeBrowsing
    47134731{
    4714     return DEFAULT_SAFE_BROWSING_ENABLED;
     4732    return true;
    47154733}
    47164734
     
    67506768- (UIView *)_safeBrowsingWarningForTesting
    67516769{
    6752     return nil;
     6770    return _safeBrowsingWarning.get();
    67536771}
    67546772#endif
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h

    r237266 r238115  
    3333#import "_WKAttachmentInternal.h"
    3434#import "_WKWebViewPrintFormatterInternal.h"
     35#import <wtf/CompletionHandler.h>
    3536#import <wtf/RefPtr.h>
    3637#import <wtf/RetainPtr.h>
     38#import <wtf/Variant.h>
    3739
    3840#if PLATFORM(IOS_FAMILY)
     
    6466
    6567namespace WebKit {
     68enum class ContinueUnsafeLoad : bool;
     69class SafeBrowsingResult;
    6670class ViewSnapshot;
    6771class WebPageProxy;
    6872struct PrintInfo;
     73}
     74
     75namespace WebCore {
     76class URL;
    6977}
    7078
     
    172180#endif
    173181
     182- (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingResult&)result completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler;
     183- (void)_clearSafeBrowsingWarning;
     184
    174185- (std::optional<BOOL>)_resolutionForShareSheetImmediateCompletionForTesting;
    175186
  • trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h

    r237624 r238115  
    2727
    2828#include "PageClient.h"
     29#include <wtf/WeakObjCPtr.h>
    2930
    3031@class WKWebView;
     
    5152
    5253protected:
    53     WKWebView *m_webView;
     54    WeakObjCPtr<WKWebView> m_webView;
    5455};
    5556
  • trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm

    r237624 r238115  
    7070{
    7171#if WK_API_ENABLED
    72     Class cls = m_webView.configuration._attachmentFileWrapperClass ?: [NSFileWrapper self];
     72    Class cls = [m_webView configuration]._attachmentFileWrapperClass ?: [NSFileWrapper self];
    7373    return [cls alloc];
    7474#else
     
    8181    Class defaultFileWrapperClass = NSFileWrapper.self;
    8282#if WK_API_ENABLED
    83     Class configuredFileWrapperClass = m_webView.configuration._attachmentFileWrapperClass;
     83    Class configuredFileWrapperClass = [m_webView configuration]._attachmentFileWrapperClass;
    8484    if (configuredFileWrapperClass && configuredFileWrapperClass != defaultFileWrapperClass)
    8585        return [NSSet setWithObjects:configuredFileWrapperClass, defaultFileWrapperClass, nil];
  • trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h

    r237863 r238115  
    4545}
    4646
     47OBJC_CLASS WKSafeBrowsingTextView;
     48
    4749#if PLATFORM(MAC)
    4850using RectType = NSRect;
    49 using StackViewType = NSStackView;
     51@interface WKSafeBrowsingWarning : NSView<NSTextViewDelegate>
    5052#else
    5153using RectType = CGRect;
    52 using StackViewType = UIStackView;
     54@interface WKSafeBrowsingWarning : UIScrollView<UITextViewDelegate>
    5355#endif
    54 
    55 @interface WKSafeBrowsingWarning : StackViewType {
     56{
    5657@package
    5758    CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)> _completionHandler;
    5859    RefPtr<const WebKit::SafeBrowsingResult> _result;
     60    RetainPtr<NSMutableArray<WKSafeBrowsingTextView *>> _textViews;
    5961}
    6062
  • trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm

    r237863 r238115  
    3434#import <wtf/Language.h>
    3535
    36 const CGFloat exclamationPointSize = 30;
    37 const CGFloat textSize = 13;
    38 #if PLATFORM(MAC)
    39 const CGFloat marginSize = 20;
    40 const size_t maxWidth = 600;
     36constexpr CGFloat exclamationPointSize = 30;
     37constexpr CGFloat titleSize = 26;
     38constexpr CGFloat boxCornerRadius = 6;
     39#if HAVE(SAFE_BROWSING)
     40constexpr CGFloat marginSize = 20;
     41constexpr CGFloat maxWidth = 675;
     42#endif
     43
     44#if PLATFORM(MAC)
     45constexpr CGFloat textSize = 14;
    4146using ColorType = NSColor;
    4247using FontType = NSFont;
     48using TextViewType = NSTextView;
     49using ButtonType = NSButton;
     50using AlignmentType = NSLayoutAttribute;
    4351using ViewType = NSView;
    44 using BezierPathType = NSBezierPath;
    45 using TextViewType = NSTextView;
    46 #else
     52using SizeType = NSSize;
     53#else
     54constexpr CGFloat textSize = 20;
    4755using ColorType = UIColor;
    4856using FontType = UIFont;
     57using TextViewType = UITextView;
     58using ButtonType = UIButton;
     59using AlignmentType = UIStackViewAlignment;
    4960using ViewType = UIView;
    50 using BezierPathType = UIBezierPath;
    51 using TextViewType = UITextView;
    52 #endif
    53 
    54 static id confirmMalwareSentinel()
    55 {
    56     return @"WKConfirmMalwareSentinel";
    57 }
    58 
    59 static id visitUnsafeWebsiteSentinel()
    60 {
    61     return @"WKVisitUnsafeWebsiteSentinel";
    62 }
    63 
    64 static ColorType *colorNamed(NSString *name)
    65 {
    66 #if PLATFORM(MAC)
     61using SizeType = CGSize;
     62#endif
     63
     64enum class WarningItem : uint8_t {
     65    Background,
     66    BoxBackground,
     67    ExclamationPoint,
     68    TitleText,
     69    MessageText,
     70    ShowDetailsButton,
     71    GoBackButton
     72};
     73
     74static NSURL *confirmMalwareSentinel()
     75{
     76    return [NSURL URLWithString:@"WKConfirmMalwareSentinel"];
     77}
     78
     79static NSURL *visitUnsafeWebsiteSentinel()
     80{
     81    return [NSURL URLWithString:@"WKVisitUnsafeWebsiteSentinel"];
     82}
     83
     84static ColorType *colorForItem(WarningItem item, ViewType *warning)
     85{
     86    ASSERT([warning isKindOfClass:[WKSafeBrowsingWarning class]]);
     87#if PLATFORM(MAC)
     88
     89    auto colorNamed = [] (NSString *name) -> ColorType* {
    6790#if HAVE(SAFE_BROWSING)
    68     return [NSColor colorNamed:name bundle:[NSBundle bundleWithIdentifier:@"com.apple.WebKit"]];
    69 #else
     91        return [NSColor colorNamed:name bundle:[NSBundle bundleWithIdentifier:@"com.apple.WebKit"]];
     92#else
     93        ASSERT_NOT_REACHED();
     94        return nil;
     95#endif
     96    };
     97
     98    switch (item) {
     99    case WarningItem::Background:
     100        return colorNamed(@"WKSafeBrowsingWarningBackground");
     101    case WarningItem::BoxBackground:
     102        return [NSColor windowBackgroundColor];
     103    case WarningItem::TitleText:
     104    case WarningItem::ExclamationPoint:
     105        return colorNamed(@"WKSafeBrowsingWarningTitle");
     106    case WarningItem::MessageText:
     107        return colorNamed(@"WKSafeBrowsingWarningText");
     108    case WarningItem::ShowDetailsButton:
     109    case WarningItem::GoBackButton:
     110        ASSERT_NOT_REACHED();
     111        return nil;
     112    }
     113#else
     114    UIColor *red = [UIColor colorWithRed:0.998 green:0.239 blue:0.233 alpha:1.0];
     115    UIColor *white = [UIColor whiteColor];
     116    bool narrow = warning.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact;
     117
     118    switch (item) {
     119    case WarningItem::Background:
     120        return red;
     121    case WarningItem::BoxBackground:
     122        return narrow ? red : white;
     123    case WarningItem::TitleText:
     124    case WarningItem::ExclamationPoint:
     125        return narrow ? white : red;
     126    case WarningItem::MessageText:
     127    case WarningItem::ShowDetailsButton:
     128        return narrow ? white : [UIColor darkTextColor];
     129    case WarningItem::GoBackButton:
     130        return narrow ? white : warning.tintColor;
     131    }
     132#endif
    70133    ASSERT_NOT_REACHED();
    71134    return nil;
    72 #endif
    73 #else
    74     return [UIColor colorNamed:name inBundle:[NSBundle bundleWithIdentifier:@"com.apple.WebKit"] compatibleWithTraitCollection:nil];
    75 #endif
    76 }
    77 
    78 #if PLATFORM(MAC)
     135}
     136
    79137static void replace(NSMutableAttributedString *string, NSString *toReplace, NSString *replaceWith)
    80138{
     
    91149    [string replaceCharactersInRange:[string.string rangeOfString:toReplace] withAttributedString:stringWithLink];
    92150}
    93 #endif
    94151
    95152@interface WKSafeBrowsingExclamationPoint : ViewType
     
    100157- (void)drawRect:(RectType)rect
    101158{
    102     [colorNamed(@"WKSafeBrowsingWarningTitle") set];
    103 #if PLATFORM(MAC)
    104 #define addArcWithCenter appendBezierPathWithArcWithCenter
    105     NSRect square = NSMakeRect(0, 0, exclamationPointSize, exclamationPointSize);
    106 #else
    107     CGRect square = CGRectMake(0, 0, exclamationPointSize, exclamationPointSize);
    108 #endif
    109     BezierPathType *exclamationPoint = [BezierPathType bezierPathWithOvalInRect:square];
    110     [exclamationPoint addArcWithCenter: { exclamationPointSize / 2, exclamationPointSize * 13 / 30 } radius:1.75 startAngle:0 endAngle:180 clockwise:YES];
    111     [exclamationPoint addArcWithCenter: { exclamationPointSize / 2, exclamationPointSize * 23 / 30 } radius:1.75 startAngle:180 endAngle:360 clockwise:YES];
    112     [exclamationPoint addArcWithCenter: { exclamationPointSize / 2, exclamationPointSize * 7 / 30 } radius:2.25 startAngle:0 endAngle:180 clockwise:YES];
    113     [exclamationPoint addArcWithCenter: { exclamationPointSize / 2, exclamationPointSize * 7 / 30 } radius:2.25 startAngle:180 endAngle:360 clockwise:YES];
     159    constexpr CGFloat centerX = exclamationPointSize / 2;
     160    constexpr CGFloat pointCenterY = exclamationPointSize * 7 / 30;
     161    constexpr CGFloat pointRadius = 2.25 * exclamationPointSize / 30;
     162    constexpr CGFloat lineBottomCenterY = exclamationPointSize * 13 / 30;
     163    constexpr CGFloat lineTopCenterY = exclamationPointSize * 23 / 30;
     164    constexpr CGFloat lineRadius = 1.75 * exclamationPointSize / 30;
     165    ViewType *warning = self.superview.superview;
     166#if PLATFORM(MAC)
     167    [colorForItem(WarningItem::ExclamationPoint, warning) set];
     168    NSBezierPath *exclamationPoint = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(0, 0, exclamationPointSize, exclamationPointSize)];
     169    [exclamationPoint appendBezierPathWithArcWithCenter: { centerX, lineBottomCenterY } radius:lineRadius startAngle:0 endAngle:180 clockwise:YES];
     170    [exclamationPoint appendBezierPathWithArcWithCenter: { centerX, lineTopCenterY } radius:lineRadius startAngle:180 endAngle:360 clockwise:YES];
     171    [exclamationPoint lineToPoint: { centerX + lineRadius, lineBottomCenterY }];
     172    [exclamationPoint appendBezierPathWithArcWithCenter: { centerX, pointCenterY } radius:pointRadius startAngle:0 endAngle:180 clockwise:YES];
     173    [exclamationPoint appendBezierPathWithArcWithCenter: { centerX, pointCenterY } radius:pointRadius startAngle:180 endAngle:360 clockwise:YES];
     174#else
     175    auto flip = [] (auto y) {
     176        return exclamationPointSize - y;
     177    };
     178    [colorForItem(WarningItem::BoxBackground, warning) set];
     179    auto square = CGRectMake(0, 0, exclamationPointSize, exclamationPointSize);
     180    [[UIBezierPath bezierPathWithRect:square] fill];
     181   
     182    [colorForItem(WarningItem::ExclamationPoint, warning) set];
     183    UIBezierPath *exclamationPoint = [UIBezierPath bezierPathWithOvalInRect:square];
     184    [exclamationPoint addArcWithCenter: { centerX, flip(lineTopCenterY) } radius:lineRadius startAngle:2 * piDouble endAngle:piDouble clockwise:NO];
     185    [exclamationPoint addArcWithCenter: { centerX, flip(lineBottomCenterY) } radius:lineRadius startAngle:piDouble endAngle:0 clockwise:NO];
     186    [exclamationPoint addArcWithCenter: { centerX, flip(pointCenterY) } radius:pointRadius startAngle:0 endAngle:piDouble clockwise:NO];
     187    [exclamationPoint addArcWithCenter: { centerX, flip(pointCenterY) } radius:pointRadius startAngle:piDouble endAngle:piDouble * 2 clockwise:NO];
     188    [exclamationPoint addLineToPoint: { centerX + lineRadius, flip(lineBottomCenterY) }];
     189    [exclamationPoint addLineToPoint: { centerX + lineRadius, flip(lineTopCenterY) }];
     190#endif
    114191    [exclamationPoint fill];
    115 #if PLATFORM(MAC)
    116 #undef addArcWithCenter
    117 #endif
    118192}
    119193
     
    125199@end
    126200
    127 #if PLATFORM(MAC)
    128201static NSURL *reportAnErrorURL(const WebKit::SafeBrowsingResult& result)
    129202{
     
    192265    return malwareOrUnwantedSoftwareDetails(result, WEB_UI_NSSTRING(@"Warnings are shown for websites where harmful software has been detected. You can check %the-status-of-site% on the %safeBrowsingProvider% diagnostic page.", "Unwanted software warning description"), @"%the-status-of-site%", false);
    193266}
    194 #endif
     267
     268static ButtonType *makeButton(WarningItem item, WKSafeBrowsingWarning *warning, SEL action)
     269{
     270    NSString *title = nil;
     271    if (item == WarningItem::ShowDetailsButton)
     272        title = WEB_UI_NSSTRING(@"Show details", "Action from safe browsing warning");
     273    else
     274        title = WEB_UI_NSSTRING(@"Go back", "Action from safe browsing warning");
     275    title = [title capitalizedString];
     276#if PLATFORM(MAC)
     277    return [NSButton buttonWithTitle:title target:warning action:action];
     278#else
     279    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
     280    NSAttributedString *attributedTitle = [[[NSAttributedString alloc] initWithString:title attributes:@{
     281        NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),
     282        NSUnderlineColorAttributeName:[UIColor whiteColor],
     283        NSForegroundColorAttributeName:colorForItem(item, warning),
     284        NSFontAttributeName:[FontType systemFontOfSize:textSize]
     285    }] autorelease];
     286    [button setAttributedTitle:attributedTitle forState:UIControlStateNormal];
     287    [button addTarget:warning action:action forControlEvents:UIControlEventTouchUpInside];
     288    return button;
     289#endif
     290}
     291
     292static ViewType *makeTitleLabel(NSString *title, ViewType *warning)
     293{
     294    auto attributedString = [[[NSAttributedString alloc] initWithString:title attributes:@{
     295        NSFontAttributeName:[FontType boldSystemFontOfSize:titleSize],
     296        NSForegroundColorAttributeName:colorForItem(WarningItem::TitleText, warning)
     297    }] autorelease];
     298#if PLATFORM(MAC)
     299    return [NSTextField labelWithAttributedString:attributedString];
     300#else
     301    auto label = [[UILabel new] autorelease];
     302    label.attributedText = attributedString;
     303    label.lineBreakMode = NSLineBreakByWordWrapping;
     304    label.numberOfLines = 0;
     305    return label;
     306#endif
     307}
     308
     309static void setBackground(ViewType *view, ColorType *color)
     310{
     311#if PLATFORM(MAC)
     312    view.wantsLayer = YES;
     313    view.layer.backgroundColor = color.CGColor;
     314#else
     315    view.backgroundColor = color;
     316#endif
     317}
    195318
    196319@interface WKSafeBrowsingTextView : TextViewType {
    197320@package
    198     WeakObjCPtr<WKSafeBrowsingWarning> _target;
    199 }
    200 + (instancetype)viewWithAttributedString:(NSAttributedString *)attributedString linkTarget:(WKSafeBrowsingWarning *)target;
    201 + (instancetype)viewWithString:(NSString *)string;
     321    WeakObjCPtr<WKSafeBrowsingWarning> _warning;
     322}
     323- (instancetype)initWithAttributedString:(NSAttributedString *)attributedString forWarning:(WKSafeBrowsingWarning *)warning;
    202324@end
    203325
     
    210332        return nil;
    211333    }
    212 
    213334    _completionHandler = WTFMove(completionHandler);
    214335    _result = makeRef(result);
    215 
    216 #if PLATFORM(MAC)
    217     self.wantsLayer = YES;
    218     self.layer.backgroundColor = [colorNamed(@"WKSafeBrowsingWarningBackground") CGColor];
    219 
    220     NSStackView *top = [NSStackView stackViewWithViews:@[
    221         [[WKSafeBrowsingExclamationPoint new] autorelease],
    222         [NSTextField labelWithAttributedString:[[[NSAttributedString alloc] initWithString:titleText(result) attributes:@{
    223             NSFontAttributeName:[NSFont systemFontOfSize:exclamationPointSize],
    224             NSForegroundColorAttributeName:colorNamed(@"WKSafeBrowsingWarningText")
    225         }] autorelease]]
     336    setBackground(self, colorForItem(WarningItem::Background, self));
     337#if PLATFORM(MAC)
     338    [self addContent];
     339#endif
     340    return self;
     341}
     342
     343- (void)addContent
     344{
     345    auto exclamationPoint = [[WKSafeBrowsingExclamationPoint new] autorelease];
     346    auto title = makeTitleLabel(titleText(*_result), self);
     347    auto warning = [[[WKSafeBrowsingTextView alloc] initWithAttributedString:[[[NSAttributedString alloc] initWithString:warningText(*_result) attributes:@{ NSFontAttributeName:[FontType systemFontOfSize:textSize] }] autorelease] forWarning:self] autorelease];
     348    auto showDetails = makeButton(WarningItem::ShowDetailsButton, self, @selector(showDetailsClicked));
     349    auto goBack = makeButton(WarningItem::GoBackButton, self, @selector(goBackClicked));
     350    auto box = [[ViewType new] autorelease];
     351    setBackground(box, colorForItem(WarningItem::BoxBackground, self));
     352    box.layer.cornerRadius = boxCornerRadius;
     353    _textViews = adoptNS([NSMutableArray new]);
     354    [_textViews addObject:warning];
     355
     356    for (ViewType *view in @[exclamationPoint, title, warning, goBack, showDetails]) {
     357        view.translatesAutoresizingMaskIntoConstraints = NO;
     358        [box addSubview:view];
     359    }
     360    box.translatesAutoresizingMaskIntoConstraints = NO;
     361    [self addSubview:box];
     362
     363#if HAVE(SAFE_BROWSING)
     364    [NSLayoutConstraint activateConstraints:@[
     365        [[self.topAnchor anchorWithOffsetToAnchor:box.topAnchor] constraintEqualToAnchor:[box.bottomAnchor anchorWithOffsetToAnchor:self.bottomAnchor] multiplier:0.5],
     366        [[self.leftAnchor anchorWithOffsetToAnchor:box.leftAnchor] constraintEqualToAnchor:[box.rightAnchor anchorWithOffsetToAnchor:self.rightAnchor]],
     367
     368        [box.widthAnchor constraintLessThanOrEqualToConstant:maxWidth],
     369        [box.widthAnchor constraintLessThanOrEqualToAnchor:self.widthAnchor],
     370
     371        [[box.leadingAnchor anchorWithOffsetToAnchor:exclamationPoint.leadingAnchor] constraintEqualToConstant:marginSize],
     372        [[box.leadingAnchor anchorWithOffsetToAnchor:title.leadingAnchor] constraintEqualToConstant:marginSize * 1.5 + exclamationPointSize],
     373        [[box.leadingAnchor anchorWithOffsetToAnchor:warning.leadingAnchor] constraintEqualToConstant:marginSize],
     374
     375        [[title.trailingAnchor anchorWithOffsetToAnchor:box.trailingAnchor] constraintGreaterThanOrEqualToConstant:marginSize],
     376        [[warning.trailingAnchor anchorWithOffsetToAnchor:box.trailingAnchor] constraintGreaterThanOrEqualToConstant:marginSize],
     377        [[goBack.trailingAnchor anchorWithOffsetToAnchor:box.trailingAnchor] constraintEqualToConstant:marginSize],
     378
     379        [[title.topAnchor anchorWithOffsetToAnchor:exclamationPoint.topAnchor] constraintEqualToAnchor:[exclamationPoint.bottomAnchor anchorWithOffsetToAnchor:title.bottomAnchor]],
     380
     381        [goBack.topAnchor constraintEqualToAnchor:showDetails.topAnchor],
     382        [[showDetails.trailingAnchor anchorWithOffsetToAnchor:goBack.leadingAnchor] constraintEqualToConstant:marginSize],
     383
     384        [[box.topAnchor anchorWithOffsetToAnchor:title.topAnchor] constraintEqualToConstant:marginSize],
     385        [[title.bottomAnchor anchorWithOffsetToAnchor:warning.topAnchor] constraintEqualToConstant:marginSize],
     386        [[warning.bottomAnchor anchorWithOffsetToAnchor:goBack.topAnchor] constraintEqualToConstant:marginSize],
     387        [[goBack.bottomAnchor anchorWithOffsetToAnchor:box.bottomAnchor] constraintEqualToConstant:marginSize]
    226388    ]];
    227 
    228     WKSafeBrowsingTextView *middle = [WKSafeBrowsingTextView viewWithString:warningText(result)];
    229 
    230     NSStackView *bottom = [NSStackView stackViewWithViews:@[
    231         [NSButton buttonWithTitle:WEB_UI_NSSTRING(@"Show details", "Action from safe browsing warning") target:self action:@selector(showDetailsClicked)],
    232         [NSButton buttonWithTitle:WEB_UI_NSSTRING(@"Go back", "Action from safe browsing warning") target:self action:@selector(goBackClicked)]
     389#endif
     390}
     391
     392- (void)showDetailsClicked
     393{
     394    ViewType *box = self.subviews.lastObject;
     395    ButtonType *showDetails = box.subviews.lastObject;
     396    [showDetails removeFromSuperview];
     397
     398    NSMutableAttributedString *text = detailsText(*_result);
     399    [text addAttributes:@{ NSFontAttributeName:[FontType systemFontOfSize:textSize] } range:NSMakeRange(0, text.length)];
     400    WKSafeBrowsingTextView *details = [[[WKSafeBrowsingTextView alloc] initWithAttributedString:text forWarning:self] autorelease];
     401    [_textViews addObject:details];
     402    ViewType *bottom = [[ViewType new] autorelease];
     403    setBackground(bottom, colorForItem(WarningItem::BoxBackground, self));
     404    bottom.layer.cornerRadius = boxCornerRadius;
     405
     406#if HAVE(SAFE_BROWSING)
     407    constexpr auto maxY = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
     408    constexpr auto minY = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
     409#if PLATFORM(MAC)
     410    box.layer.maskedCorners = maxY;
     411    bottom.layer.maskedCorners = minY;
     412#else
     413    box.layer.maskedCorners = minY;
     414    bottom.layer.maskedCorners = maxY;
     415#endif
     416#endif
     417
     418    ViewType *line = [[ViewType new] autorelease];
     419    setBackground(line, [ColorType lightGrayColor]);
     420    for (ViewType *view in @[details, bottom, line])
     421        view.translatesAutoresizingMaskIntoConstraints = NO;
     422
     423    [self addSubview:bottom];
     424    [bottom addSubview:line];
     425    [bottom addSubview:details];
     426#if HAVE(SAFE_BROWSING)
     427    [NSLayoutConstraint activateConstraints:@[
     428        [box.widthAnchor constraintEqualToAnchor:bottom.widthAnchor],
     429        [box.bottomAnchor constraintEqualToAnchor:bottom.topAnchor],
     430        [box.leadingAnchor constraintEqualToAnchor:bottom.leadingAnchor],
     431        [line.widthAnchor constraintEqualToAnchor:bottom.widthAnchor],
     432        [line.leadingAnchor constraintEqualToAnchor:bottom.leadingAnchor],
     433        [line.topAnchor constraintEqualToAnchor:bottom.topAnchor],
     434        [line.heightAnchor constraintEqualToConstant:1],
     435        [[bottom.topAnchor anchorWithOffsetToAnchor:details.topAnchor] constraintEqualToConstant:marginSize],
     436        [[details.bottomAnchor anchorWithOffsetToAnchor:bottom.bottomAnchor] constraintEqualToConstant:marginSize],
     437        [[bottom.leadingAnchor anchorWithOffsetToAnchor:details.leadingAnchor] constraintEqualToConstant:marginSize],
     438        [[details.trailingAnchor anchorWithOffsetToAnchor:bottom.trailingAnchor] constraintEqualToConstant:marginSize],
    233439    ]];
    234 
    235     for (NSStackView *view in @[top, bottom])
    236         [view setHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
    237 
    238     StackViewType *box = [NSStackView stackViewWithViews:@[top, middle, bottom]];
    239     box.wantsLayer = YES;
    240     box.layer.backgroundColor = [[NSColor windowBackgroundColor] CGColor];
    241     box.layer.cornerRadius = 6;
    242     box.alignment = NSLayoutAttributeCenterX;
    243     [box.widthAnchor constraintEqualToConstant:maxWidth].active = true;
    244     box.edgeInsets = { marginSize, marginSize, marginSize, marginSize };
    245     [box setHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
    246     [self addView:box inGravity:NSStackViewGravityCenter];
    247 #else
    248     // FIXME: Get this working on iOS.
    249     completionHandler(WebKit::ContinueUnsafeLoad::Yes);
    250 #endif
    251     return self;
    252 }
    253 
    254 #if PLATFORM(MAC)
     440#endif
     441    [self layoutText];
     442#if !PLATFORM(MAC)
     443    [self layoutIfNeeded];
     444    CGFloat height = 0;
     445    for (ViewType *subview in self.subviews)
     446        height += subview.frame.size.height;
     447    [self setContentSize: { self.frame.size.width, self.frame.size.height / 2 + height }];
     448#endif
     449}
     450
     451- (void)layoutText
     452{
     453    for (WKSafeBrowsingTextView *view in _textViews.get())
     454        [view invalidateIntrinsicContentSize];
     455}
     456
     457#if PLATFORM(MAC)
     458- (BOOL)textView:(NSTextView *)textView clickedOnLink:(id)link atIndex:(NSUInteger)charIndex
     459{
     460    [self clickedOnLink:link];
     461    return YES;
     462}
     463
    255464- (void)layout
    256465{
    257     for (NSView *view in self.subviews.firstObject.subviews)
    258         [view invalidateIntrinsicContentSize];
    259466    [super layout];
     467    [self layoutText];
     468}
     469#else
     470- (void)layoutSubviews
     471{
     472    [super layoutSubviews];
     473    [self layoutText];
     474}
     475
     476- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction
     477{
     478    [self clickedOnLink:URL];
     479    return NO;
     480}
     481
     482- (void)didMoveToWindow
     483{
     484    [self addContent];
    260485}
    261486#endif
     
    274499}
    275500
    276 - (void)clickedOnLink:(id)link
     501- (void)clickedOnLink:(NSURL *)link
    277502{
    278503    if (!_completionHandler)
     
    305530}
    306531
    307 - (void)showDetailsClicked
    308 {
    309 #if PLATFORM(MAC)
    310     NSStackView *box = self.views.firstObject;
    311     NSStackView *bottom = box.views.lastObject;
    312     NSButton *showDetailsButton = bottom.views.firstObject;
    313     [bottom removeView:showDetailsButton];
    314     WKSafeBrowsingTextView *details = [WKSafeBrowsingTextView viewWithAttributedString:detailsText(*_result) linkTarget:self];
    315     [box addView:details inGravity:NSStackViewGravityCenter];
    316 #else
    317     // FIXME: Get this working on iOS.
    318 #endif
    319 }
    320 
    321532@end
    322533
    323534@implementation WKSafeBrowsingTextView
    324535
    325 + (instancetype)viewWithAttributedString:(NSAttributedString *)attributedString linkTarget:(WKSafeBrowsingWarning *)target
    326 {
    327     WKSafeBrowsingTextView *instance = [[self new] autorelease];
    328     if (!instance)
     536- (instancetype)initWithAttributedString:(NSAttributedString *)attributedString forWarning:(WKSafeBrowsingWarning *)warning
     537{
     538    if (!(self = [super init]))
    329539        return nil;
    330     instance->_target = target;
    331 
    332     ColorType *foregroundColor = colorNamed(@"WKSafeBrowsingWarningText");
     540    self->_warning = warning;
     541    self.delegate = warning;
     542
     543    ColorType *foregroundColor = colorForItem(WarningItem::MessageText, warning);
    333544    NSMutableAttributedString *string = [attributedString mutableCopy];
    334     [string addAttributes:@{
    335         NSForegroundColorAttributeName : foregroundColor,
    336         NSFontAttributeName:[FontType systemFontOfSize:textSize]
    337     } range:NSMakeRange(0, string.length)];
    338 
    339 #if PLATFORM(MAC)
    340     [instance setLinkTextAttributes:@{ NSForegroundColorAttributeName : foregroundColor }];
    341     [instance setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
    342     [instance setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
    343     [instance.widthAnchor constraintLessThanOrEqualToConstant:maxWidth - 2 * marginSize].active = true;
    344     [instance setBackgroundColor:[NSColor windowBackgroundColor]];
    345     [instance.textStorage appendAttributedString:string];
    346 #endif
    347     return instance;
    348 }
    349 
    350 + (instancetype)viewWithString:(NSString *)string
    351 {
    352     return [WKSafeBrowsingTextView viewWithAttributedString:[[[NSMutableAttributedString alloc] initWithString:string] autorelease] linkTarget:nil];
    353 }
    354 
    355 - (NSSize)intrinsicContentSize
    356 {
     545    [string addAttributes:@{ NSForegroundColorAttributeName : foregroundColor } range:NSMakeRange(0, string.length)];
     546    [self setBackgroundColor:colorForItem(WarningItem::BoxBackground, warning)];
     547    [self setLinkTextAttributes:@{ NSForegroundColorAttributeName : foregroundColor }];
     548    [self.textStorage appendAttributedString:string];
     549    self.editable = NO;
     550#if !PLATFORM(MAC)
     551    self.scrollEnabled = NO;
     552#endif
     553
     554    return self;
     555}
     556
     557- (SizeType)intrinsicContentSize
     558{
     559#if PLATFORM(MAC)
    357560    [self.layoutManager ensureLayoutForTextContainer:self.textContainer];
    358     auto size = [self.layoutManager usedRectForTextContainer:self.textContainer].size;
    359 #if PLATFORM(MAC)
    360     return { NSViewNoIntrinsicMetric, size.height };
    361 #else
    362     return { UIViewNoIntrinsicMetric, size.height };
    363 #endif
    364 }
    365 
    366 - (void)clickedOnLink:(id)link atIndex:(NSUInteger)charIndex
    367 {
    368     [_target clickedOnLink:link];
     561    return { NSViewNoIntrinsicMetric, [self.layoutManager usedRectForTextContainer:self.textContainer].size.height };
     562#else
     563    auto width = std::min<CGFloat>(maxWidth, [_warning frame].size.width) - 2 * marginSize;
     564    constexpr auto noHeightConstraint = CGFLOAT_MAX;
     565    return { width, [self sizeThatFits: { width, noHeightConstraint }].height };
     566#endif
    369567}
    370568
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm

    r237863 r238115  
    6363#import <wtf/BlockPtr.h>
    6464
    65 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_webView->_page->process().connection())
     65#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_webView.get()->_page->process().connection())
    6666
    6767@interface WKEditCommandObjC : NSObject
     
    162162{
    163163    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
    164     return isViewVisible() || (m_webView && [m_webView _isRetainingActiveFocusedState]);
     164    return isViewVisible() || [m_webView _isRetainingActiveFocusedState];
    165165}
    166166
     
    168168{
    169169    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
    170     return isViewWindowActive() || (m_webView && [m_webView _isRetainingActiveFocusedState]);
     170    return isViewWindowActive() || [m_webView _isRetainingActiveFocusedState];
    171171}
    172172
    173173bool PageClientImpl::isViewVisible()
    174174{
    175     if (isViewInWindow() && !m_webView._isBackground)
     175    if (isViewInWindow() && ![m_webView _isBackground])
    176176        return true;
    177177   
     
    188188{
    189189    // FIXME: in WebKitTestRunner, m_webView is nil, so check the content view instead.
    190     if (m_webView)
    191         return [m_webView window];
     190    if (auto webView = m_webView.get())
     191        return [webView window];
    192192
    193193    return [m_contentView window];
     
    249249void PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler)
    250250{
    251     [[wrapper(m_webView->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:std::exchange(completionHandler, nullptr) view:m_webView];
     251    [[wrapper(m_webView.get()->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:std::exchange(completionHandler, nullptr) view:m_webView.get().get()];
    252252}
    253253
     
    470470}
    471471
    472 void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingResult&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
    473 {
    474     completionHandler(WebKit::ContinueUnsafeLoad::Yes); // FIXME: Implement.
     472void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
     473{
     474}
     475
     476void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingResult& result, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
     477{
     478    if (auto webView = m_webView.get())
     479        [webView _showSafeBrowsingWarning:result completionHandler:WTFMove(completionHandler)];
     480    else
     481        completionHandler(ContinueUnsafeLoad::No);
    475482}
    476483
    477484void PageClientImpl::clearSafeBrowsingWarning()
    478485{
    479     // FIXME: Implement.
    480 }
    481 
    482 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
    483 {
     486    [m_webView _clearSafeBrowsingWarning];
    484487}
    485488
     
    696699Vector<String> PageClientImpl::mimeTypesWithCustomContentProviders()
    697700{
    698     return m_webView._contentProviderRegistry._mimeTypesWithCustomContentProviders;
     701    return [m_webView _contentProviderRegistry]._mimeTypesWithCustomContentProviders;
    699702}
    700703
     
    702705{
    703706    [m_webView _navigationGestureDidBegin];
    704     NavigationState::fromWebPage(*m_webView->_page).navigationGestureDidBegin();
     707    NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidBegin();
    705708}
    706709
    707710void PageClientImpl::navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem& item)
    708711{
    709     NavigationState::fromWebPage(*m_webView->_page).navigationGestureWillEnd(willNavigate, item);
     712    NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureWillEnd(willNavigate, item);
    710713}
    711714
    712715void PageClientImpl::navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem& item)
    713716{
    714     NavigationState::fromWebPage(*m_webView->_page).navigationGestureDidEnd(willNavigate, item);
     717    NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidEnd(willNavigate, item);
    715718    [m_webView _navigationGestureDidEnd];
    716719}
     
    723726void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem& item)
    724727{
    725     NavigationState::fromWebPage(*m_webView->_page).willRecordNavigationSnapshot(item);
     728    NavigationState::fromWebPage(*m_webView.get()->_page).willRecordNavigationSnapshot(item);
    726729}
    727730
    728731void PageClientImpl::didRemoveNavigationGestureSnapshot()
    729732{
    730     NavigationState::fromWebPage(*m_webView->_page).navigationGestureSnapshotWasRemoved();
     733    NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureSnapshotWasRemoved();
    731734}
    732735
     
    841844    });
    842845
    843     if (WKPasswordView *passwordView = m_webView._passwordView) {
     846    if (WKPasswordView *passwordView = [m_webView _passwordView]) {
    844847        ASSERT(fileName == String { passwordView.documentName });
    845848        [passwordView showPasswordFailureAlert];
     
    849852
    850853    [m_webView _showPasswordViewWithDocumentName:fileName passwordHandler:passwordHandler.get()];
    851     NavigationState::fromWebPage(*m_webView->_page).didRequestPasswordForQuickLookDocument();
     854    NavigationState::fromWebPage(*m_webView.get()->_page).didRequestPasswordForQuickLookDocument();
    852855}
    853856#endif
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm

    r238014 r238115  
    565565bool PageClientImpl::showShareSheet(const ShareDataWithParsedURL& shareData, WTF::CompletionHandler<void(bool)>&& completionHandler)
    566566{
    567     m_impl->showShareSheet(shareData, WTFMove(completionHandler), m_webView);
     567    m_impl->showShareSheet(shareData, WTFMove(completionHandler), m_webView.get().get());
    568568    return true;
    569569}
     
    754754
    755755#if WK_API_ENABLED
    756     if (m_webView)
    757         NavigationState::fromWebPage(*m_webView->_page).navigationGestureDidBegin();
     756    if (auto webView = m_webView.get())
     757        NavigationState::fromWebPage(*webView->_page).navigationGestureDidBegin();
    758758#endif
    759759}
     
    762762{
    763763#if WK_API_ENABLED
    764     if (m_webView)
    765         NavigationState::fromWebPage(*m_webView->_page).navigationGestureWillEnd(willNavigate, item);
     764    if (auto webView = m_webView.get())
     765        NavigationState::fromWebPage(*webView->_page).navigationGestureWillEnd(willNavigate, item);
    766766#else
    767767    UNUSED_PARAM(willNavigate);
     
    773773{
    774774#if WK_API_ENABLED
    775     if (m_webView)
    776         NavigationState::fromWebPage(*m_webView->_page).navigationGestureDidEnd(willNavigate, item);
     775    if (auto webView = m_webView.get())
     776        NavigationState::fromWebPage(*webView->_page).navigationGestureDidEnd(willNavigate, item);
    777777#else
    778778    UNUSED_PARAM(willNavigate);
     
    788788{
    789789#if WK_API_ENABLED
    790     if (m_webView)
    791         NavigationState::fromWebPage(*m_webView->_page).willRecordNavigationSnapshot(item);
     790    if (auto webView = m_webView.get())
     791        NavigationState::fromWebPage(*webView->_page).willRecordNavigationSnapshot(item);
    792792#else
    793793    UNUSED_PARAM(item);
     
    798798{
    799799#if WK_API_ENABLED
    800     if (m_webView)
    801         NavigationState::fromWebPage(*m_webView->_page).navigationGestureSnapshotWasRemoved();
     800    if (auto webView = m_webView.get())
     801        NavigationState::fromWebPage(*webView->_page).navigationGestureSnapshotWasRemoved();
    802802#endif
    803803}
  • trunk/Tools/ChangeLog

    r238111 r238115  
     12018-11-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        [iOS] Implement safe browsing in WebKit
     4        https://bugs.webkit.org/show_bug.cgi?id=191441
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
     9        (checkTitleAndClick):
     10        (TEST):
     11
    1122018-11-12  Basuke Suzuki  <basuke.suzuki@sony.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

    r237863 r238115  
    138138@end
    139139
    140 #if PLATFORM(MAC) // FIXME: Test on iOS once implemented.
    141 
    142140static NSURL *simpleURL()
    143141{
     
    155153    while (![webView _safeBrowsingWarningForTesting])
    156154        TestWebKitAPI::Util::spinRunLoop();
     155#if !PLATFORM(MAC)
     156    [[webView _safeBrowsingWarningForTesting] didMoveToWindow];
     157#endif
    157158    return webView;
    158159}
    159160
     161#if PLATFORM(MAC)
     162static void checkTitleAndClick(NSButton *button, const char* expectedTitle)
     163{
     164    EXPECT_STREQ(button.title.UTF8String, expectedTitle);
     165    [button performClick:nil];
     166}
     167#else
     168static void checkTitleAndClick(UIButton *button, const char* expectedTitle)
     169{
     170    EXPECT_STREQ([button attributedTitleForState:UIControlStateNormal].string.UTF8String, expectedTitle);
     171    UIView *target = button.superview.superview;
     172    SEL selector = NSSelectorFromString(strcmp(expectedTitle, "Go Back") ? @"showDetailsClicked" : @"goBackClicked");
     173    [target performSelector:selector];
     174}
     175#endif
     176
    160177TEST(SafeBrowsing, GoBack)
    161178{
    162179    auto webView = safeBrowsingView();
    163     NSView *bottom = [webView _safeBrowsingWarningForTesting].subviews.firstObject.subviews.lastObject;
    164     NSButton *goBack = (NSButton *)bottom.subviews.lastObject;
    165     EXPECT_STREQ(goBack.title.UTF8String, "Go back");
    166     [goBack performClick:nil];
     180    auto warning = [webView _safeBrowsingWarningForTesting];
     181    auto box = warning.subviews.firstObject;
     182    checkTitleAndClick(box.subviews[3], "Go Back");
    167183    EXPECT_EQ([webView _safeBrowsingWarningForTesting], nil);
    168184}
     
    171187{
    172188    auto webView = safeBrowsingView();
    173     NSView *warning = [webView _safeBrowsingWarningForTesting];
    174     NSView *box = warning.subviews.firstObject;
    175     NSButton *showDetails = (NSButton *)box.subviews.lastObject.subviews.firstObject;
    176     EXPECT_STREQ(showDetails.title.UTF8String, "Show details");
    177     EXPECT_EQ(box.subviews.count, 3ull);
    178     [showDetails performClick:nil];
    179     EXPECT_EQ(box.subviews.count, 4ull);
     189    auto warning = [webView _safeBrowsingWarningForTesting];
     190    EXPECT_EQ(warning.subviews.count, 1ull);
     191    checkTitleAndClick(warning.subviews.firstObject.subviews[4], "Show Details");
     192    EXPECT_EQ(warning.subviews.count, 2ull);
    180193    EXPECT_FALSE(committedNavigation);
    181     [warning performSelector:NSSelectorFromString(@"clickedOnLink:") withObject:@"WKVisitUnsafeWebsiteSentinel"];
     194    [warning performSelector:NSSelectorFromString(@"clickedOnLink:") withObject:[NSURL URLWithString:@"WKVisitUnsafeWebsiteSentinel"]];
    182195    TestWebKitAPI::Util::run(&committedNavigation);
    183196}
     
    192205}
    193206
    194 #endif // PLATFORM(MAC)
    195 
    196207@interface NullLookupContext : NSObject
    197208@end
Note: See TracChangeset for help on using the changeset viewer.