Add API to disable safe browsing checks
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2018 19:59:45 +0000 (19:59 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2018 19:59:45 +0000 (19:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191610

Reviewed by Dean Jackson.

Source/WebKit:

* UIProcess/API/Cocoa/WKPreferences.h:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences setSafeBrowsingEnabled:]):
(-[WKPreferences isSafeBrowsingEnabled]):
(-[WKPreferences _setSafeBrowsingEnabled:]): Deleted.
(-[WKPreferences _safeBrowsingEnabled]): Deleted.
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
(resourceURL):
(TEST):
(safeBrowsingView):
(simpleURL): Deleted.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.h
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

index 19d5416..27b9898 100644 (file)
@@ -1,3 +1,18 @@
+2018-11-16  Alex Christensen  <achristensen@webkit.org>
+
+        Add API to disable safe browsing checks
+        https://bugs.webkit.org/show_bug.cgi?id=191610
+
+        Reviewed by Dean Jackson.
+
+        * UIProcess/API/Cocoa/WKPreferences.h:
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences setSafeBrowsingEnabled:]):
+        (-[WKPreferences isSafeBrowsingEnabled]):
+        (-[WKPreferences _setSafeBrowsingEnabled:]): Deleted.
+        (-[WKPreferences _safeBrowsingEnabled]): Deleted.
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+
 2018-11-16  Chris Dumez  <cdumez@apple.com>
 
         WebKit.UnavailablePlugIn API test is crashing in debug
index e35b719..560f8aa 100644 (file)
@@ -53,6 +53,12 @@ WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0))
  */
 @property (nonatomic) BOOL javaScriptCanOpenWindowsAutomatically;
 
+/*! @abstract A Boolean value indicating whether warnings should be
+ shown for suspected unsafe content such as phishing or malware.
+ @discussion The default value is YES.
+ */
+@property (nonatomic, getter=isSafeBrowsingEnabled) BOOL safeBrowsingEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 #if !TARGET_OS_IPHONE
 /*! @abstract A Boolean value indicating whether Java is enabled.
  @discussion The default value is NO.
index 53177ec..6dbdca6 100644 (file)
@@ -697,12 +697,12 @@ static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPo
     _preferences->setICECandidateFilteringEnabled(enabled);
 }
 
-- (void)_setSafeBrowsingEnabled:(BOOL)enabled
+- (void)setSafeBrowsingEnabled:(BOOL)enabled
 {
     _preferences->setSafeBrowsingEnabled(enabled);
 }
 
-- (BOOL)_safeBrowsingEnabled
+- (BOOL)isSafeBrowsingEnabled
 {
     return _preferences->safeBrowsingEnabled();
 }
index ce9889f..28698bf 100644 (file)
@@ -121,7 +121,6 @@ typedef NS_ENUM(NSInteger, _WKEditableLinkBehavior) {
 @property (nonatomic, setter=_setICECandidateFilteringEnabled:) BOOL _iceCandidateFilteringEnabled WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
 @property (nonatomic, setter=_setWebRTCLegacyAPIEnabled:) BOOL _webRTCLegacyAPIEnabled WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 @property (nonatomic, setter=_setInactiveMediaCaptureSteamRepromptIntervalInMinutes:) double _inactiveMediaCaptureSteamRepromptIntervalInMinutes WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
-@property (nonatomic, setter=_setSafeBrowsingEnabled:) BOOL _safeBrowsingEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @property (nonatomic, setter=_setJavaScriptCanAccessClipboard:) BOOL _javaScriptCanAccessClipboard WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 @property (nonatomic, setter=_setDOMPasteAllowed:) BOOL _domPasteAllowed WK_API_AVAILABLE(macosx(10.13), ios(11.0));
index b6925b8..aff008e 100644 (file)
@@ -1,3 +1,16 @@
+2018-11-16  Alex Christensen  <achristensen@webkit.org>
+
+        Add API to disable safe browsing checks
+        https://bugs.webkit.org/show_bug.cgi?id=191610
+
+        Reviewed by Dean Jackson.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
+        (resourceURL):
+        (TEST):
+        (safeBrowsingView):
+        (simpleURL): Deleted.
+
 2018-11-16  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Add support for out-of-flow positioned boxes
index 0811ebc..97630fb 100644 (file)
@@ -29,6 +29,7 @@
 
 #import "ClassMethodSwizzler.h"
 #import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
 #import "TestWKWebView.h"
 #import <WebKit/WKNavigationDelegate.h>
 #import <WebKit/WKWebViewPrivate.h>
@@ -137,9 +138,32 @@ static bool committedNavigation;
 
 @end
 
-static NSURL *simpleURL()
+static NSURL *resourceURL(NSString *resource)
 {
-    return [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    return [[NSBundle mainBundle] URLForResource:resource withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+}
+
+TEST(SafeBrowsing, Preference)
+{
+    TestWebKitAPI::ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [TestLookupContext methodForSelector:@selector(sharedLookupContext)]);
+
+    __block bool done = false;
+    auto delegate = adoptNS([TestNavigationDelegate new]);
+    delegate.get().didStartProvisionalNavigation = ^(WKWebView *, WKNavigation *) {
+        done = true;
+    };
+
+    auto webView = adoptNS([WKWebView new]);
+    [webView setNavigationDelegate:delegate.get()];
+    EXPECT_TRUE([webView configuration].preferences.safeBrowsingEnabled);
+    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple")]];
+    while (![webView _safeBrowsingWarningForTesting])
+        TestWebKitAPI::Util::spinRunLoop();
+    [webView configuration].preferences.safeBrowsingEnabled = NO;
+    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple2")]];
+    TestWebKitAPI::Util::run(&done);
+    EXPECT_FALSE([webView configuration].preferences.safeBrowsingEnabled);
+    EXPECT_FALSE([webView _safeBrowsingWarningForTesting]);
 }
 
 static RetainPtr<WKWebView> safeBrowsingView()
@@ -149,7 +173,7 @@ static RetainPtr<WKWebView> safeBrowsingView()
     static auto delegate = adoptNS([SafeBrowsingNavigationDelegate new]);
     auto webView = adoptNS([WKWebView new]);
     [webView setNavigationDelegate:delegate.get()];
-    [webView loadRequest:[NSURLRequest requestWithURL:simpleURL()]];
+    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple")]];
     while (![webView _safeBrowsingWarningForTesting])
         TestWebKitAPI::Util::spinRunLoop();
 #if !PLATFORM(MAC)