Changeset 238115 in webkit
- Timestamp:
- Nov 12, 2018, 5:08:07 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r238108 r238115 1 2018-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 1 76 2018-11-12 Tim Horton <timothy_horton@apple.com> 2 77 -
trunk/Source/WebKit/Shared/WebPreferences.yaml
r238108 r238115 57 57 SafeBrowsingEnabled: 58 58 type: bool 59 defaultValue: DEFAULT_SAFE_BROWSING_ENABLED59 defaultValue: true 60 60 webcoreBinding: none 61 61 -
trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h
r237863 r238115 59 59 60 60 #if PLATFORM(IOS_FAMILY) 61 #define DEFAULT_SAFE_BROWSING_ENABLED false62 61 #define DEFAULT_ALLOWS_PICTURE_IN_PICTURE_MEDIA_PLAYBACK true 63 62 #define DEFAULT_BACKSPACE_KEY_NAVIGATION_ENABLED false … … 79 78 #define EXPERIMENTAL_FULLSCREEN_API_HIDDEN false 80 79 #else 81 #define DEFAULT_SAFE_BROWSING_ENABLED true82 80 #define DEFAULT_ALLOWS_PICTURE_IN_PICTURE_MEDIA_PLAYBACK false 83 81 #define DEFAULT_BACKSPACE_KEY_NAVIGATION_ENABLED true -
trunk/Source/WebKit/UIProcess/API/C/mac/WKContextPrivateMac.mm
r237863 r238115 174 174 bool WKContextHandlesSafeBrowsing() 175 175 { 176 return DEFAULT_SAFE_BROWSING_ENABLED;176 return true; 177 177 } -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r238108 r238115 275 275 276 276 std::optional<BOOL> _resolutionForShareSheetImmediateCompletionForTesting; 277 RetainPtr<WKSafeBrowsingWarning> _safeBrowsingWarning; 277 278 278 279 #if PLATFORM(IOS_FAMILY) … … 1277 1278 } 1278 1279 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 1279 1295 #if ENABLE(ATTACHMENT_ELEMENT) 1280 1296 … … 1353 1369 - (void)layoutSubviews 1354 1370 { 1371 [_safeBrowsingWarning setFrame:self.bounds]; 1355 1372 [super layoutSubviews]; 1356 1373 [self _frameOrBoundsChanged]; … … 3313 3330 { 3314 3331 [super setFrameSize:size]; 3332 [_safeBrowsingWarning setFrame:self.bounds]; 3315 3333 _impl->setFrameSize(NSSizeToCGSize(size)); 3316 3334 } … … 4712 4730 + (BOOL)_handlesSafeBrowsing 4713 4731 { 4714 return DEFAULT_SAFE_BROWSING_ENABLED;4732 return true; 4715 4733 } 4716 4734 … … 6750 6768 - (UIView *)_safeBrowsingWarningForTesting 6751 6769 { 6752 return nil;6770 return _safeBrowsingWarning.get(); 6753 6771 } 6754 6772 #endif -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
r237266 r238115 33 33 #import "_WKAttachmentInternal.h" 34 34 #import "_WKWebViewPrintFormatterInternal.h" 35 #import <wtf/CompletionHandler.h> 35 36 #import <wtf/RefPtr.h> 36 37 #import <wtf/RetainPtr.h> 38 #import <wtf/Variant.h> 37 39 38 40 #if PLATFORM(IOS_FAMILY) … … 64 66 65 67 namespace WebKit { 68 enum class ContinueUnsafeLoad : bool; 69 class SafeBrowsingResult; 66 70 class ViewSnapshot; 67 71 class WebPageProxy; 68 72 struct PrintInfo; 73 } 74 75 namespace WebCore { 76 class URL; 69 77 } 70 78 … … 172 180 #endif 173 181 182 - (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingResult&)result completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler; 183 - (void)_clearSafeBrowsingWarning; 184 174 185 - (std::optional<BOOL>)_resolutionForShareSheetImmediateCompletionForTesting; 175 186 -
trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h
r237624 r238115 27 27 28 28 #include "PageClient.h" 29 #include <wtf/WeakObjCPtr.h> 29 30 30 31 @class WKWebView; … … 51 52 52 53 protected: 53 W KWebView *m_webView;54 WeakObjCPtr<WKWebView> m_webView; 54 55 }; 55 56 -
trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm
r237624 r238115 70 70 { 71 71 #if WK_API_ENABLED 72 Class cls = m_webView.configuration._attachmentFileWrapperClass ?: [NSFileWrapper self];72 Class cls = [m_webView configuration]._attachmentFileWrapperClass ?: [NSFileWrapper self]; 73 73 return [cls alloc]; 74 74 #else … … 81 81 Class defaultFileWrapperClass = NSFileWrapper.self; 82 82 #if WK_API_ENABLED 83 Class configuredFileWrapperClass = m_webView.configuration._attachmentFileWrapperClass;83 Class configuredFileWrapperClass = [m_webView configuration]._attachmentFileWrapperClass; 84 84 if (configuredFileWrapperClass && configuredFileWrapperClass != defaultFileWrapperClass) 85 85 return [NSSet setWithObjects:configuredFileWrapperClass, defaultFileWrapperClass, nil]; -
trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h
r237863 r238115 45 45 } 46 46 47 OBJC_CLASS WKSafeBrowsingTextView; 48 47 49 #if PLATFORM(MAC) 48 50 using RectType = NSRect; 49 using StackViewType = NSStackView; 51 @interface WKSafeBrowsingWarning : NSView<NSTextViewDelegate> 50 52 #else 51 53 using RectType = CGRect; 52 using StackViewType = UIStackView; 54 @interface WKSafeBrowsingWarning : UIScrollView<UITextViewDelegate> 53 55 #endif 54 55 @interface WKSafeBrowsingWarning : StackViewType { 56 { 56 57 @package 57 58 CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)> _completionHandler; 58 59 RefPtr<const WebKit::SafeBrowsingResult> _result; 60 RetainPtr<NSMutableArray<WKSafeBrowsingTextView *>> _textViews; 59 61 } 60 62 -
trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm
r237863 r238115 34 34 #import <wtf/Language.h> 35 35 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; 36 constexpr CGFloat exclamationPointSize = 30; 37 constexpr CGFloat titleSize = 26; 38 constexpr CGFloat boxCornerRadius = 6; 39 #if HAVE(SAFE_BROWSING) 40 constexpr CGFloat marginSize = 20; 41 constexpr CGFloat maxWidth = 675; 42 #endif 43 44 #if PLATFORM(MAC) 45 constexpr CGFloat textSize = 14; 41 46 using ColorType = NSColor; 42 47 using FontType = NSFont; 48 using TextViewType = NSTextView; 49 using ButtonType = NSButton; 50 using AlignmentType = NSLayoutAttribute; 43 51 using ViewType = NSView; 44 using BezierPathType = NSBezierPath;45 using TextViewType = NSTextView; 46 #else 52 using SizeType = NSSize; 53 #else 54 constexpr CGFloat textSize = 20; 47 55 using ColorType = UIColor; 48 56 using FontType = UIFont; 57 using TextViewType = UITextView; 58 using ButtonType = UIButton; 59 using AlignmentType = UIStackViewAlignment; 49 60 using 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) 61 using SizeType = CGSize; 62 #endif 63 64 enum class WarningItem : uint8_t { 65 Background, 66 BoxBackground, 67 ExclamationPoint, 68 TitleText, 69 MessageText, 70 ShowDetailsButton, 71 GoBackButton 72 }; 73 74 static NSURL *confirmMalwareSentinel() 75 { 76 return [NSURL URLWithString:@"WKConfirmMalwareSentinel"]; 77 } 78 79 static NSURL *visitUnsafeWebsiteSentinel() 80 { 81 return [NSURL URLWithString:@"WKVisitUnsafeWebsiteSentinel"]; 82 } 83 84 static ColorType *colorForItem(WarningItem item, ViewType *warning) 85 { 86 ASSERT([warning isKindOfClass:[WKSafeBrowsingWarning class]]); 87 #if PLATFORM(MAC) 88 89 auto colorNamed = [] (NSString *name) -> ColorType* { 67 90 #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 70 133 ASSERT_NOT_REACHED(); 71 134 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 79 137 static void replace(NSMutableAttributedString *string, NSString *toReplace, NSString *replaceWith) 80 138 { … … 91 149 [string replaceCharactersInRange:[string.string rangeOfString:toReplace] withAttributedString:stringWithLink]; 92 150 } 93 #endif94 151 95 152 @interface WKSafeBrowsingExclamationPoint : ViewType … … 100 157 - (void)drawRect:(RectType)rect 101 158 { 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 114 191 [exclamationPoint fill]; 115 #if PLATFORM(MAC)116 #undef addArcWithCenter117 #endif118 192 } 119 193 … … 125 199 @end 126 200 127 #if PLATFORM(MAC)128 201 static NSURL *reportAnErrorURL(const WebKit::SafeBrowsingResult& result) 129 202 { … … 192 265 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); 193 266 } 194 #endif 267 268 static 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 292 static 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 309 static 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 } 195 318 196 319 @interface WKSafeBrowsingTextView : TextViewType { 197 320 @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; 202 324 @end 203 325 … … 210 332 return nil; 211 333 } 212 213 334 _completionHandler = WTFMove(completionHandler); 214 335 _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] 226 388 ]]; 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], 233 439 ]]; 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 255 464 - (void)layout 256 465 { 257 for (NSView *view in self.subviews.firstObject.subviews)258 [view invalidateIntrinsicContentSize];259 466 [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]; 260 485 } 261 486 #endif … … 274 499 } 275 500 276 - (void)clickedOnLink:( id)link501 - (void)clickedOnLink:(NSURL *)link 277 502 { 278 503 if (!_completionHandler) … … 305 530 } 306 531 307 - (void)showDetailsClicked308 {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 #else317 // FIXME: Get this working on iOS.318 #endif319 }320 321 532 @end 322 533 323 534 @implementation WKSafeBrowsingTextView 324 535 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])) 329 539 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); 333 544 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) 357 560 [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 369 567 } 370 568 -
trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
r237863 r238115 63 63 #import <wtf/BlockPtr.h> 64 64 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()) 66 66 67 67 @interface WKEditCommandObjC : NSObject … … 162 162 { 163 163 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098 164 return isViewVisible() || (m_webView && [m_webView _isRetainingActiveFocusedState]);164 return isViewVisible() || [m_webView _isRetainingActiveFocusedState]; 165 165 } 166 166 … … 168 168 { 169 169 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098 170 return isViewWindowActive() || (m_webView && [m_webView _isRetainingActiveFocusedState]);170 return isViewWindowActive() || [m_webView _isRetainingActiveFocusedState]; 171 171 } 172 172 173 173 bool PageClientImpl::isViewVisible() 174 174 { 175 if (isViewInWindow() && ! m_webView._isBackground)175 if (isViewInWindow() && ![m_webView _isBackground]) 176 176 return true; 177 177 … … 188 188 { 189 189 // 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]; 192 192 193 193 return [m_contentView window]; … … 249 249 void PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler) 250 250 { 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()]; 252 252 } 253 253 … … 470 470 } 471 471 472 void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingResult&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler) 473 { 474 completionHandler(WebKit::ContinueUnsafeLoad::Yes); // FIXME: Implement. 472 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) 473 { 474 } 475 476 void 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); 475 482 } 476 483 477 484 void PageClientImpl::clearSafeBrowsingWarning() 478 485 { 479 // FIXME: Implement. 480 } 481 482 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) 483 { 486 [m_webView _clearSafeBrowsingWarning]; 484 487 } 485 488 … … 696 699 Vector<String> PageClientImpl::mimeTypesWithCustomContentProviders() 697 700 { 698 return m_webView._contentProviderRegistry._mimeTypesWithCustomContentProviders;701 return [m_webView _contentProviderRegistry]._mimeTypesWithCustomContentProviders; 699 702 } 700 703 … … 702 705 { 703 706 [m_webView _navigationGestureDidBegin]; 704 NavigationState::fromWebPage(*m_webView ->_page).navigationGestureDidBegin();707 NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidBegin(); 705 708 } 706 709 707 710 void PageClientImpl::navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem& item) 708 711 { 709 NavigationState::fromWebPage(*m_webView ->_page).navigationGestureWillEnd(willNavigate, item);712 NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureWillEnd(willNavigate, item); 710 713 } 711 714 712 715 void PageClientImpl::navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem& item) 713 716 { 714 NavigationState::fromWebPage(*m_webView ->_page).navigationGestureDidEnd(willNavigate, item);717 NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureDidEnd(willNavigate, item); 715 718 [m_webView _navigationGestureDidEnd]; 716 719 } … … 723 726 void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem& item) 724 727 { 725 NavigationState::fromWebPage(*m_webView ->_page).willRecordNavigationSnapshot(item);728 NavigationState::fromWebPage(*m_webView.get()->_page).willRecordNavigationSnapshot(item); 726 729 } 727 730 728 731 void PageClientImpl::didRemoveNavigationGestureSnapshot() 729 732 { 730 NavigationState::fromWebPage(*m_webView ->_page).navigationGestureSnapshotWasRemoved();733 NavigationState::fromWebPage(*m_webView.get()->_page).navigationGestureSnapshotWasRemoved(); 731 734 } 732 735 … … 841 844 }); 842 845 843 if (WKPasswordView *passwordView = m_webView._passwordView) {846 if (WKPasswordView *passwordView = [m_webView _passwordView]) { 844 847 ASSERT(fileName == String { passwordView.documentName }); 845 848 [passwordView showPasswordFailureAlert]; … … 849 852 850 853 [m_webView _showPasswordViewWithDocumentName:fileName passwordHandler:passwordHandler.get()]; 851 NavigationState::fromWebPage(*m_webView ->_page).didRequestPasswordForQuickLookDocument();854 NavigationState::fromWebPage(*m_webView.get()->_page).didRequestPasswordForQuickLookDocument(); 852 855 } 853 856 #endif -
trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm
r238014 r238115 565 565 bool PageClientImpl::showShareSheet(const ShareDataWithParsedURL& shareData, WTF::CompletionHandler<void(bool)>&& completionHandler) 566 566 { 567 m_impl->showShareSheet(shareData, WTFMove(completionHandler), m_webView );567 m_impl->showShareSheet(shareData, WTFMove(completionHandler), m_webView.get().get()); 568 568 return true; 569 569 } … … 754 754 755 755 #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(); 758 758 #endif 759 759 } … … 762 762 { 763 763 #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); 766 766 #else 767 767 UNUSED_PARAM(willNavigate); … … 773 773 { 774 774 #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); 777 777 #else 778 778 UNUSED_PARAM(willNavigate); … … 788 788 { 789 789 #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); 792 792 #else 793 793 UNUSED_PARAM(item); … … 798 798 { 799 799 #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(); 802 802 #endif 803 803 } -
trunk/Tools/ChangeLog
r238111 r238115 1 2018-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 1 12 2018-11-12 Basuke Suzuki <basuke.suzuki@sony.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm
r237863 r238115 138 138 @end 139 139 140 #if PLATFORM(MAC) // FIXME: Test on iOS once implemented.141 142 140 static NSURL *simpleURL() 143 141 { … … 155 153 while (![webView _safeBrowsingWarningForTesting]) 156 154 TestWebKitAPI::Util::spinRunLoop(); 155 #if !PLATFORM(MAC) 156 [[webView _safeBrowsingWarningForTesting] didMoveToWindow]; 157 #endif 157 158 return webView; 158 159 } 159 160 161 #if PLATFORM(MAC) 162 static void checkTitleAndClick(NSButton *button, const char* expectedTitle) 163 { 164 EXPECT_STREQ(button.title.UTF8String, expectedTitle); 165 [button performClick:nil]; 166 } 167 #else 168 static 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 160 177 TEST(SafeBrowsing, GoBack) 161 178 { 162 179 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"); 167 183 EXPECT_EQ([webView _safeBrowsingWarningForTesting], nil); 168 184 } … … 171 187 { 172 188 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); 180 193 EXPECT_FALSE(committedNavigation); 181 [warning performSelector:NSSelectorFromString(@"clickedOnLink:") withObject: @"WKVisitUnsafeWebsiteSentinel"];194 [warning performSelector:NSSelectorFromString(@"clickedOnLink:") withObject:[NSURL URLWithString:@"WKVisitUnsafeWebsiteSentinel"]]; 182 195 TestWebKitAPI::Util::run(&committedNavigation); 183 196 } … … 192 205 } 193 206 194 #endif // PLATFORM(MAC)195 196 207 @interface NullLookupContext : NSObject 197 208 @end
Note:
See TracChangeset
for help on using the changeset viewer.