Tweak _showSafeBrowsingWarningWithTitle SPI
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Nov 2018 06:03:19 +0000 (06:03 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Nov 2018 06:03:19 +0000 (06:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191799

Reviewed by Wenson Hsieh.

Source/WebCore:

It turns out I needed to expose both sentinel values used in safe browsing for my application of this SPI in Mac Safari.
Allowing the caller to make its own sentinel values is insufficient because the malware confirmation needs to be over the warning.
The completion handler parameter should just be a bool indicating whether the user has chosen to continue after all warnings.

Covered by updated API tests.

* en.lproj/Localizable.strings:
* platform/LocalizedStrings.cpp:
(WebCore::formControlCancelButtonTitle):
Make "Cancel"'s description a little more generic.

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _showSafeBrowsingWarningWithTitle:warning:details:completionHandler:]):
(+[WKWebView _visitUnsafeWebsiteSentinel]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
(-[WKSafeBrowsingWarning clickedOnLink:]):
I need to localize "Continue" and "Cancel" so they aren't always in English.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
(TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/en.lproj/Localizable.strings
Source/WebCore/platform/LocalizedStrings.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

index 62b654e..4c66254 100644 (file)
@@ -1,3 +1,21 @@
+2018-11-16  Alex Christensen  <achristensen@webkit.org>
+
+        Tweak _showSafeBrowsingWarningWithTitle SPI
+        https://bugs.webkit.org/show_bug.cgi?id=191799
+
+        Reviewed by Wenson Hsieh.
+
+        It turns out I needed to expose both sentinel values used in safe browsing for my application of this SPI in Mac Safari.
+        Allowing the caller to make its own sentinel values is insufficient because the malware confirmation needs to be over the warning.
+        The completion handler parameter should just be a bool indicating whether the user has chosen to continue after all warnings.
+
+        Covered by updated API tests.
+
+        * en.lproj/Localizable.strings:
+        * platform/LocalizedStrings.cpp:
+        (WebCore::formControlCancelButtonTitle):
+        Make "Cancel"'s description a little more generic.
+
 2018-11-16  Simon Fraser  <simon.fraser@apple.com>
 
         Optimize composited iframe layer hookup
index d2809d0..a43fdd4 100644 (file)
 /* Option in segmented control for inserting a bulleted list in text editing */
 "Bulleted list" = "Bulleted list";
 
-/* Title of the Cancel button for zoomed form controls. */
+/* Cancel */
 "Cancel" = "Cancel";
 
 /* Title for Cancel button label in button bar */
 /* WebKitErrorCannotShowMIMEType description */
 "Content with specified MIME type can’t be shown" = "Content with specified MIME type can’t be shown";
 
+/* Continue */
+"Continue" = "Continue";
+
 /* Media Controls context menu item */
 "Controls" = "Controls";
 
index bb83bfa..7f55201 100644 (file)
@@ -1043,7 +1043,7 @@ String formControlDoneButtonTitle()
 
 String formControlCancelButtonTitle()
 {
-    return WEB_UI_STRING("Cancel", "Title of the Cancel button for zoomed form controls.");
+    return WEB_UI_STRING("Cancel", "Cancel");
 }
 
 String formControlHideButtonTitle()
index 92256d6..d90dd27 100644 (file)
@@ -1,3 +1,18 @@
+2018-11-16  Alex Christensen  <achristensen@webkit.org>
+
+        Tweak _showSafeBrowsingWarningWithTitle SPI
+        https://bugs.webkit.org/show_bug.cgi?id=191799
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _showSafeBrowsingWarningWithTitle:warning:details:completionHandler:]):
+        (+[WKWebView _visitUnsafeWebsiteSentinel]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
+        (-[WKSafeBrowsingWarning clickedOnLink:]):
+        I need to localize "Continue" and "Cancel" so they aren't always in English.
+
 2018-11-16  Chris Dumez  <cdumez@apple.com>
 
         WKWebViewMacEditingTests.DoNotCrashWhenInterpretingKeyEventWhileDeallocatingView API test is crashing in debug
index 3c56b6e..278ef1b 100644 (file)
@@ -4735,14 +4735,20 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
     return true;
 }
 
-- (void)_showSafeBrowsingWarningWithTitle:(NSString *)title warning:(NSString *)warning details:(NSAttributedString *)details completionHandler:(void(^)(NSURL *))completionHandler
+- (void)_showSafeBrowsingWarningWithTitle:(NSString *)title warning:(NSString *)warning details:(NSAttributedString *)details completionHandler:(void(^)(BOOL))completionHandler
 {
     auto safeBrowsingWarning = WebKit::SafeBrowsingWarning::create(title, warning, details);
     auto wrapper = [completionHandler = makeBlockPtr(completionHandler)] (Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&& variant) {
-        switchOn(variant, [&] (WebKit::ContinueUnsafeLoad) {
-            completionHandler(nil);
-        }, [&] (WebCore::URL url) {
-            completionHandler(url);
+        switchOn(variant, [&] (WebKit::ContinueUnsafeLoad continueUnsafeLoad) {
+            switch (continueUnsafeLoad) {
+            case WebKit::ContinueUnsafeLoad::Yes:
+                return completionHandler(YES);
+            case WebKit::ContinueUnsafeLoad::No:
+                return completionHandler(NO);
+            }
+        }, [&] (WebCore::URL) {
+            ASSERT_NOT_REACHED();
+            completionHandler(NO);
         });
     };
 #if PLATFORM(MAC)
@@ -4757,6 +4763,11 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
     return WebKit::SafeBrowsingWarning::confirmMalwareSentinel();
 }
 
++ (NSURL *)_visitUnsafeWebsiteSentinel
+{
+    return WebKit::SafeBrowsingWarning::visitUnsafeWebsiteSentinel();
+}
+
 - (void)_evaluateJavaScriptWithoutUserGesture:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler
 {
     [self _evaluateJavaScript:javaScriptString forceUserGesture:NO completionHandler:completionHandler];
index 8dde8bb..c6865bc 100644 (file)
@@ -189,7 +189,8 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) {
 
 + (BOOL)_handlesSafeBrowsing WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 + (NSURL *)_confirmMalwareSentinel WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
-- (void)_showSafeBrowsingWarningWithTitle:(NSString *)title warning:(NSString *)warning details:(NSAttributedString *)details completionHandler:(void(^)(NSURL *))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
++ (NSURL *)_visitUnsafeWebsiteSentinel WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_showSafeBrowsingWarningWithTitle:(NSString *)title warning:(NSString *)warning details:(NSAttributedString *)details completionHandler:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 - (IBAction)_alignCenter:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (IBAction)_alignJustified:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
index 5f62f7f..bed1cfe 100644 (file)
@@ -419,8 +419,8 @@ static void setBackground(ViewType *view, ColorType *color)
         auto alert = adoptNS([NSAlert new]);
         [alert setMessageText:WEB_UI_NSSTRING(@"Are you sure you wish to go to this site?", "Malware confirmation dialog title")];
         [alert setInformativeText:WEB_UI_NSSTRING(@"Merely visiting a site is sufficient for malware to install itself and harm your computer.", "Malware confirmation dialog")];
-        [alert addButtonWithTitle:@"Cancel"];
-        [alert addButtonWithTitle:@"Continue"];
+        [alert addButtonWithTitle:WEB_UI_NSSTRING(@"Cancel", "Cancel")];
+        [alert addButtonWithTitle:WEB_UI_NSSTRING(@"Continue", "Continue")];
         [alert beginSheetModalForWindow:self.window completionHandler:BlockPtr<void(NSModalResponse)>::fromCallable([weakSelf = WeakObjCPtr<WKSafeBrowsingWarning>(self), alert](NSModalResponse returnCode) {
             if (auto strongSelf = weakSelf.get()) {
                 if (returnCode == NSAlertSecondButtonReturn && strongSelf->_completionHandler)
index 4b7627b..cb1ad0b 100644 (file)
@@ -1,3 +1,13 @@
+2018-11-16  Alex Christensen  <achristensen@webkit.org>
+
+        Tweak _showSafeBrowsingWarningWithTitle SPI
+        https://bugs.webkit.org/show_bug.cgi?id=191799
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
+        (TEST):
+
 2018-11-16  Ryosuke Niwa  <rniwa@webkit.org>
 
         REGRESSION (r238294): TestWebKitAPI.WKNavigation.ProcessCrashDuringCallback failing on iOS
index 97630fb..cf8f4ba 100644 (file)
@@ -231,12 +231,12 @@ TEST(SafeBrowsing, NavigationClearsWarning)
 TEST(SafeBrowsing, ShowWarningSPI)
 {
     __block bool completionHandlerCalled = false;
-    __block RetainPtr<NSURL> urlClicked;
+    __block BOOL shouldContinueValue = NO;
     auto webView = adoptNS([WKWebView new]);
     auto showWarning = ^{
         completionHandlerCalled = false;
-        [webView _showSafeBrowsingWarningWithTitle:@"test title" warning:@"test warning" details:[[[NSAttributedString alloc] initWithString:@"test details"] autorelease] completionHandler:^(NSURL *url) {
-            urlClicked = url;
+        [webView _showSafeBrowsingWarningWithTitle:@"test title" warning:@"test warning" details:[[[NSAttributedString alloc] initWithString:@"test details"] autorelease] completionHandler:^(BOOL shouldContinue) {
+            shouldContinueValue = shouldContinue;
             completionHandlerCalled = true;
         }];
 #if !PLATFORM(MAC)
@@ -247,12 +247,12 @@ TEST(SafeBrowsing, ShowWarningSPI)
     showWarning();
     checkTitleAndClick([webView _safeBrowsingWarningForTesting].subviews.firstObject.subviews[3], "Go Back");
     TestWebKitAPI::Util::run(&completionHandlerCalled);
-    EXPECT_TRUE(!urlClicked);
+    EXPECT_FALSE(shouldContinueValue);
 
     showWarning();
-    [[webView _safeBrowsingWarningForTesting] performSelector:NSSelectorFromString(@"clickedOnLink:") withObject:[NSURL URLWithString:@"http://webkit.org/testlink"]];
+    [[webView _safeBrowsingWarningForTesting] performSelector:NSSelectorFromString(@"clickedOnLink:") withObject:[WKWebView _visitUnsafeWebsiteSentinel]];
     TestWebKitAPI::Util::run(&completionHandlerCalled);
-    EXPECT_STREQ([urlClicked absoluteString].UTF8String, "http://webkit.org/testlink");
+    EXPECT_TRUE(shouldContinueValue);
 }
 
 @interface NullLookupContext : NSObject