Add SPI to show a safe browsing warning
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Nov 2018 19:47:00 +0000 (19:47 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Nov 2018 19:47:00 +0000 (19:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191604

Reviewed by Andy Estes.

Source/WebKit:

Safari has a case where it shows safe browsing warnings for a reason other than being told to by the SafeBrowsing framework.
Because safe browsing is moving to WebKit, we will have Safari call this WebKit SPI in that case.
The warning looks a little different, so I had to change the structure of a SafeBrowsingResult and the location of the string processing,
but the existing behavior is the same as verified by existing unit tests.  I added a unit test to verify behavior of the new SPI.

* SourcesCocoa.txt:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _showSafeBrowsingWarningWithTitle:warning:details:completionHandler:]):
(-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
(+[WKWebView _confirmMalwareSentinel]):
(+[WKWebView _visitUnsafeWebsiteSentinel]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/Cocoa/SafeBrowsingResultCocoa.mm: Removed.
* UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm: Copied from Source/WebKit/UIProcess/Cocoa/SafeBrowsingResultCocoa.mm.
(WebKit::malwareDetailsBase):
(WebKit::learnMoreURL):
(WebKit::reportAnErrorBase):
(WebKit::localizedProvider):
(WebKit::SafeBrowsingWarning::visitUnsafeWebsiteSentinel):
(WebKit::SafeBrowsingWarning::confirmMalwareSentinel):
(WebKit::replace):
(WebKit::addLinkAndReplace):
(WebKit::reportAnErrorURL):
(WebKit::malwareDetailsURL):
(WebKit::safeBrowsingTitleText):
(WebKit::safeBrowsingWarningText):
(WebKit::safeBrowsingDetailsText):
(WebKit::SafeBrowsingWarning::SafeBrowsingWarning):
(WebKit::learnMore): Deleted.
(WebKit::SafeBrowsingResult::SafeBrowsingResult): Deleted.
* UIProcess/Cocoa/WKSafeBrowsingWarning.h:
* UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
(-[WKSafeBrowsingWarning initWithFrame:safeBrowsingWarning:completionHandler:]):
(-[WKSafeBrowsingWarning addContent]):
(-[WKSafeBrowsingWarning showDetailsClicked]):
(-[WKSafeBrowsingWarning clickedOnLink:]):
(-[WKSafeBrowsingTextView initWithAttributedString:forWarning:]):
(confirmMalwareSentinel): Deleted.
(visitUnsafeWebsiteSentinel): Deleted.
(replace): Deleted.
(addLinkAndReplace): Deleted.
(reportAnErrorURL): Deleted.
(malwareDetailsURL): Deleted.
(titleText): Deleted.
(warningText): Deleted.
(detailsText): Deleted.
(-[WKSafeBrowsingWarning initWithFrame:safeBrowsingResult:completionHandler:]): Deleted.
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::beginSafeBrowsingCheck):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::showSafeBrowsingWarning):
* UIProcess/PageClient.h:
(WebKit::PageClient::showSafeBrowsingWarning):
* UIProcess/SafeBrowsingResult.h: Removed.
* UIProcess/SafeBrowsingWarning.h: Copied from Source/WebKit/UIProcess/SafeBrowsingResult.h.
(WebKit::SafeBrowsingWarning::create):
(WebKit::SafeBrowsingWarning::title const):
(WebKit::SafeBrowsingWarning::warning const):
(WebKit::SafeBrowsingWarning::details const):
(WebKit::SafeBrowsingResult::create): Deleted.
(WebKit::SafeBrowsingResult::isPhishing const): Deleted.
(WebKit::SafeBrowsingResult::isMalware const): Deleted.
(WebKit::SafeBrowsingResult::isUnwantedSoftware const): Deleted.
(WebKit::SafeBrowsingResult::url const): Deleted.
(WebKit::SafeBrowsingResult::provider const): Deleted.
(WebKit::SafeBrowsingResult::localizedProviderName const): Deleted.
(WebKit::SafeBrowsingResult::malwareDetailsURLBase const): Deleted.
(WebKit::SafeBrowsingResult::reportAnErrorURLBase const): Deleted.
(WebKit::SafeBrowsingResult::learnMoreURL const): Deleted.
(WebKit::SafeBrowsingResult::needsSafeBrowsingWarning const): Deleted.
(): Deleted.
* UIProcess/WebFramePolicyListenerProxy.cpp:
(WebKit::WebFramePolicyListenerProxy::didReceiveSafeBrowsingResults):
(WebKit::WebFramePolicyListenerProxy::use):
* UIProcess/WebFramePolicyListenerProxy.h:
* UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::WebFrameProxy):
(WebKit::WebFrameProxy::setUpPolicyListenerProxy):
(WebKit::WebFrameProxy::didHandleContentFilterUnblockNavigation):
* UIProcess/WebFrameProxy.h:
(WebKit::WebFrameProxy::create):
(WebKit::WebFrameProxy::page const):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::swapToWebProcess):
(WebKit::WebPageProxy::didCreateMainFrame):
(WebKit::WebPageProxy::didCreateSubframe):
(WebKit::WebPageProxy::decidePolicyForNavigationAction):
(WebKit::WebPageProxy::decidePolicyForNewWindowAction):
(WebKit::WebPageProxy::decidePolicyForResponse):
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::showSafeBrowsingWarning):
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::showSafeBrowsingWarning):
* UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
* WebKit.xcodeproj/project.pbxproj:

Tools:

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

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

26 files changed:
Source/WebKit/ChangeLog
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/Cocoa/SafeBrowsingResultCocoa.mm [deleted file]
Source/WebKit/UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm [new file with mode: 0644]
Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h
Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm
Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/SafeBrowsingWarning.h [moved from Source/WebKit/UIProcess/SafeBrowsingResult.h with 55% similarity]
Source/WebKit/UIProcess/WebFramePolicyListenerProxy.cpp
Source/WebKit/UIProcess/WebFramePolicyListenerProxy.h
Source/WebKit/UIProcess/WebFrameProxy.cpp
Source/WebKit/UIProcess/WebFrameProxy.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/ios/PageClientImplIOS.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit/UIProcess/mac/PageClientImplMac.h
Source/WebKit/UIProcess/mac/PageClientImplMac.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

index f0c1ec5..97c36fa 100644 (file)
@@ -1,3 +1,110 @@
+2018-11-14  Alex Christensen  <achristensen@webkit.org>
+
+        Add SPI to show a safe browsing warning
+        https://bugs.webkit.org/show_bug.cgi?id=191604
+
+        Reviewed by Andy Estes.
+
+        Safari has a case where it shows safe browsing warnings for a reason other than being told to by the SafeBrowsing framework.
+        Because safe browsing is moving to WebKit, we will have Safari call this WebKit SPI in that case.
+        The warning looks a little different, so I had to change the structure of a SafeBrowsingResult and the location of the string processing,
+        but the existing behavior is the same as verified by existing unit tests.  I added a unit test to verify behavior of the new SPI.
+
+        * SourcesCocoa.txt:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _showSafeBrowsingWarningWithTitle:warning:details:completionHandler:]):
+        (-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
+        (+[WKWebView _confirmMalwareSentinel]):
+        (+[WKWebView _visitUnsafeWebsiteSentinel]):
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/Cocoa/SafeBrowsingResultCocoa.mm: Removed.
+        * UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm: Copied from Source/WebKit/UIProcess/Cocoa/SafeBrowsingResultCocoa.mm.
+        (WebKit::malwareDetailsBase):
+        (WebKit::learnMoreURL):
+        (WebKit::reportAnErrorBase):
+        (WebKit::localizedProvider):
+        (WebKit::SafeBrowsingWarning::visitUnsafeWebsiteSentinel):
+        (WebKit::SafeBrowsingWarning::confirmMalwareSentinel):
+        (WebKit::replace):
+        (WebKit::addLinkAndReplace):
+        (WebKit::reportAnErrorURL):
+        (WebKit::malwareDetailsURL):
+        (WebKit::safeBrowsingTitleText):
+        (WebKit::safeBrowsingWarningText):
+        (WebKit::safeBrowsingDetailsText):
+        (WebKit::SafeBrowsingWarning::SafeBrowsingWarning):
+        (WebKit::learnMore): Deleted.
+        (WebKit::SafeBrowsingResult::SafeBrowsingResult): Deleted.
+        * UIProcess/Cocoa/WKSafeBrowsingWarning.h:
+        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
+        (-[WKSafeBrowsingWarning initWithFrame:safeBrowsingWarning:completionHandler:]):
+        (-[WKSafeBrowsingWarning addContent]):
+        (-[WKSafeBrowsingWarning showDetailsClicked]):
+        (-[WKSafeBrowsingWarning clickedOnLink:]):
+        (-[WKSafeBrowsingTextView initWithAttributedString:forWarning:]):
+        (confirmMalwareSentinel): Deleted.
+        (visitUnsafeWebsiteSentinel): Deleted.
+        (replace): Deleted.
+        (addLinkAndReplace): Deleted.
+        (reportAnErrorURL): Deleted.
+        (malwareDetailsURL): Deleted.
+        (titleText): Deleted.
+        (warningText): Deleted.
+        (detailsText): Deleted.
+        (-[WKSafeBrowsingWarning initWithFrame:safeBrowsingResult:completionHandler:]): Deleted.
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::beginSafeBrowsingCheck):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::showSafeBrowsingWarning):
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::showSafeBrowsingWarning):
+        * UIProcess/SafeBrowsingResult.h: Removed.
+        * UIProcess/SafeBrowsingWarning.h: Copied from Source/WebKit/UIProcess/SafeBrowsingResult.h.
+        (WebKit::SafeBrowsingWarning::create):
+        (WebKit::SafeBrowsingWarning::title const):
+        (WebKit::SafeBrowsingWarning::warning const):
+        (WebKit::SafeBrowsingWarning::details const):
+        (WebKit::SafeBrowsingResult::create): Deleted.
+        (WebKit::SafeBrowsingResult::isPhishing const): Deleted.
+        (WebKit::SafeBrowsingResult::isMalware const): Deleted.
+        (WebKit::SafeBrowsingResult::isUnwantedSoftware const): Deleted.
+        (WebKit::SafeBrowsingResult::url const): Deleted.
+        (WebKit::SafeBrowsingResult::provider const): Deleted.
+        (WebKit::SafeBrowsingResult::localizedProviderName const): Deleted.
+        (WebKit::SafeBrowsingResult::malwareDetailsURLBase const): Deleted.
+        (WebKit::SafeBrowsingResult::reportAnErrorURLBase const): Deleted.
+        (WebKit::SafeBrowsingResult::learnMoreURL const): Deleted.
+        (WebKit::SafeBrowsingResult::needsSafeBrowsingWarning const): Deleted.
+        (): Deleted.
+        * UIProcess/WebFramePolicyListenerProxy.cpp:
+        (WebKit::WebFramePolicyListenerProxy::didReceiveSafeBrowsingResults):
+        (WebKit::WebFramePolicyListenerProxy::use):
+        * UIProcess/WebFramePolicyListenerProxy.h:
+        * UIProcess/WebFrameProxy.cpp:
+        (WebKit::WebFrameProxy::WebFrameProxy):
+        (WebKit::WebFrameProxy::setUpPolicyListenerProxy):
+        (WebKit::WebFrameProxy::didHandleContentFilterUnblockNavigation):
+        * UIProcess/WebFrameProxy.h:
+        (WebKit::WebFrameProxy::create):
+        (WebKit::WebFrameProxy::page const):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::swapToWebProcess):
+        (WebKit::WebPageProxy::didCreateMainFrame):
+        (WebKit::WebPageProxy::didCreateSubframe):
+        (WebKit::WebPageProxy::decidePolicyForNavigationAction):
+        (WebKit::WebPageProxy::decidePolicyForNewWindowAction):
+        (WebKit::WebPageProxy::decidePolicyForResponse):
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::showSafeBrowsingWarning):
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::showSafeBrowsingWarning):
+        * UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
+        * WebKit.xcodeproj/project.pbxproj:
+
 2018-11-14  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] A few drag and drop tests are crashing after r238146
index 3abaa80..ecc82d1 100644 (file)
@@ -322,7 +322,7 @@ UIProcess/Cocoa/NavigationState.mm
 UIProcess/Cocoa/PageClientImplCocoa.mm
 UIProcess/Cocoa/PlaybackSessionManagerProxy.mm
 UIProcess/Cocoa/ResourceLoadStatisticsMemoryStoreCocoa.mm
-UIProcess/Cocoa/SafeBrowsingResultCocoa.mm
+UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm
 UIProcess/Cocoa/SessionStateCoding.mm
 UIProcess/Cocoa/SystemPreviewControllerCocoa.mm
 UIProcess/Cocoa/UIDelegate.mm
index 1553f9f..ba6f8ce 100644 (file)
 #import "Logging.h"
 #import "NavigationState.h"
 #import "ObjCObjectGraph.h"
+#import "PageClient.h"
 #import "RemoteLayerTreeScrollingPerformanceData.h"
 #import "RemoteLayerTreeTransaction.h"
 #import "RemoteObjectRegistry.h"
 #import "RemoteObjectRegistryMessages.h"
+#import "SafeBrowsingWarning.h"
 #import "StringUtilities.h"
 #import "UIDelegate.h"
 #import "UserMediaProcessManager.h"
@@ -1277,9 +1279,9 @@ static NSDictionary *dictionaryRepresentationForEditorState(const WebKit::Editor
         [uiDelegate _webView:self editorStateDidChange:dictionaryRepresentationForEditorState(_page->editorState())];
 }
 
-- (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingResult&)result completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler
+- (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler
 {
-    _safeBrowsingWarning = adoptNS([[WKSafeBrowsingWarning alloc] initWithFrame:self.bounds safeBrowsingResult:result completionHandler:[weakSelf = WeakObjCPtr<WKWebView>(self), completionHandler = WTFMove(completionHandler)] (auto&& result) mutable {
+    _safeBrowsingWarning = adoptNS([[WKSafeBrowsingWarning alloc] initWithFrame:self.bounds safeBrowsingWarning:warning completionHandler:[weakSelf = WeakObjCPtr<WKWebView>(self), completionHandler = WTFMove(completionHandler)] (auto&& result) mutable {
         if (auto strongSelf = weakSelf.get())
             [std::exchange(strongSelf->_safeBrowsingWarning, nullptr) removeFromSuperview];
         completionHandler(WTFMove(result));
@@ -4733,6 +4735,28 @@ 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
+{
+    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);
+        });
+    };
+#if PLATFORM(MAC)
+    _impl->showSafeBrowsingWarning(safeBrowsingWarning, WTFMove(wrapper));
+#else
+    [self _showSafeBrowsingWarning:safeBrowsingWarning completionHandler:WTFMove(wrapper)];
+#endif
+}
+
++ (NSURL *)_confirmMalwareSentinel
+{
+    return WebKit::SafeBrowsingWarning::confirmMalwareSentinel();
+}
+
 - (void)_evaluateJavaScriptWithoutUserGesture:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler
 {
     [self _evaluateJavaScript:javaScriptString forceUserGesture:NO completionHandler:completionHandler];
index ff45a52..5c3dc34 100644 (file)
@@ -66,7 +66,7 @@ class Attachment;
 
 namespace WebKit {
 enum class ContinueUnsafeLoad : bool;
-class SafeBrowsingResult;
+class SafeBrowsingWarning;
 class ViewSnapshot;
 class WebPageProxy;
 struct PrintInfo;
@@ -179,7 +179,7 @@ class URL;
 - (void)_didInsertAttachment:(API::Attachment&)attachment withSource:(NSString *)source;
 #endif
 
-- (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingResult&)result completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler;
+- (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler;
 - (void)_clearSafeBrowsingWarning;
 
 - (std::optional<BOOL>)_resolutionForShareSheetImmediateCompletionForTesting;
index 43825e9..8dde8bb 100644 (file)
@@ -103,6 +103,7 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) {
 @class _WKIconLoadingDelegate;
 @class _WKInspector;
 @class _WKRemoteObjectRegistry;
+@class _WKSafeBrowsingWarning;
 @class _WKSessionState;
 @class _WKThumbnailView;
 @class _WKWebsitePolicies;
@@ -187,6 +188,8 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) {
 - (_WKAttachment *)_attachmentForIdentifier:(NSString *)identifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 + (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));
 
 - (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));
diff --git a/Source/WebKit/UIProcess/Cocoa/SafeBrowsingResultCocoa.mm b/Source/WebKit/UIProcess/Cocoa/SafeBrowsingResultCocoa.mm
deleted file mode 100644 (file)
index d14e1d9..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "SafeBrowsingResult.h"
-
-#import "SafeBrowsingSPI.h"
-#import <WebCore/LocalizedStrings.h>
-
-namespace WebKit {
-
-#if HAVE(SAFE_BROWSING)
-
-// FIXME: These ought to be API calls to the SafariSafeBrowsing framework when such SPI is available.
-static const char* malwareDetailsBase(const String& provider)
-{
-    if (provider == String(SSBProviderTencent))
-        return "https://www.urlsec.qq.com/check.html?tpl=safari";
-    return "https://google.com/safebrowsing/diagnostic?tpl=safari";
-}
-
-static WebCore::URL learnMore(const String& provider)
-{
-    if (provider == String(SSBProviderTencent))
-        return {{ }, "https://www.urlsec.qq.com/standard/s1.html?tpl=safari"};
-    return {{ }, "https://www.google.com/support/bin/answer.py?answer=106318"};
-}
-
-static const char* reportAnErrorBase(const String& provider)
-{
-    if (provider == String(SSBProviderTencent))
-        return "https://www.urlsec.qq.com/complain.html?tpl=safari";
-    return "https://www.google.com/safebrowsing/report_error/?tpl=safari";
-}
-
-static String localizedProvider(const String& provider)
-{
-    if (provider == String(SSBProviderTencent))
-        return WEB_UI_NSSTRING(@"Tencent Safe Browsing", "Tencent Safe Browsing");
-    return WEB_UI_NSSTRING(@"Google Safe Browsing", "Google Safe Browsing");
-}
-
-SafeBrowsingResult::SafeBrowsingResult(WebCore::URL&& url, SSBServiceLookupResult *result)
-    : m_url(WTFMove(url))
-    , m_isPhishing([result isPhishing])
-    , m_isMalware([result isMalware])
-    , m_isUnwantedSoftware([result isUnwantedSoftware])
-    , m_provider([result provider])
-    , m_localizedProviderName(localizedProvider([result provider]))
-    , m_malwareDetailsURLBase(malwareDetailsBase([result provider]))
-    , m_reportAnErrorURLBase(reportAnErrorBase([result provider]))
-    , m_learnMoreURL(learnMore([result provider]))
-{
-}
-#endif
-
-}
diff --git a/Source/WebKit/UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm b/Source/WebKit/UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm
new file mode 100644 (file)
index 0000000..83ffed3
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "SafeBrowsingWarning.h"
+
+#import "SafeBrowsingSPI.h"
+#import <WebCore/LocalizedStrings.h>
+#import <wtf/Language.h>
+
+namespace WebKit {
+
+#if HAVE(SAFE_BROWSING)
+
+// FIXME: These four functions ought to be API calls to the SafariSafeBrowsing framework when such SPI is available.
+// That way WebKit does not need to know about the SafariSafeBrowsing framework's possible providers.
+static const char* malwareDetailsBase(SSBServiceLookupResult *result)
+{
+    if ([result.provider isEqualToString:SSBProviderTencent])
+        return "https://www.urlsec.qq.com/check.html?tpl=safari";
+    return "https://google.com/safebrowsing/diagnostic?tpl=safari";
+}
+
+static NSURL *learnMoreURL(SSBServiceLookupResult *result)
+{
+    if ([result.provider isEqualToString:SSBProviderTencent])
+        return [NSURL URLWithString:@"https://www.urlsec.qq.com/standard/s1.html?tpl=safari"];
+    return [NSURL URLWithString:@"https://www.google.com/support/bin/answer.py?answer=106318"];
+}
+
+static const char* reportAnErrorBase(SSBServiceLookupResult *result)
+{
+    if ([result.provider isEqualToString:SSBProviderTencent])
+        return "https://www.urlsec.qq.com/complain.html?tpl=safari";
+    return "https://www.google.com/safebrowsing/report_error/?tpl=safari";
+}
+
+static String localizedProvider(SSBServiceLookupResult *result)
+{
+    if ([result.provider isEqualToString:SSBProviderTencent])
+        return WEB_UI_NSSTRING(@"Tencent Safe Browsing", "Tencent Safe Browsing");
+    return WEB_UI_NSSTRING(@"Google Safe Browsing", "Google Safe Browsing");
+}
+
+
+static void replace(NSMutableAttributedString *string, NSString *toReplace, NSString *replaceWith)
+{
+    [string replaceCharactersInRange:[string.string rangeOfString:toReplace] withString:replaceWith];
+}
+
+static void addLinkAndReplace(NSMutableAttributedString *string, NSString *toReplace, NSString *replaceWith, NSURL *linkTarget)
+{
+    NSMutableAttributedString *stringWithLink = [[[NSMutableAttributedString alloc] initWithString:replaceWith] autorelease];
+    [stringWithLink addAttributes:@{
+        NSLinkAttributeName: linkTarget,
+        NSUnderlineStyleAttributeName: @1
+    } range:NSMakeRange(0, replaceWith.length)];
+    [string replaceCharactersInRange:[string.string rangeOfString:toReplace] withAttributedString:stringWithLink];
+}
+
+static NSURL *reportAnErrorURL(const WebCore::URL& url, SSBServiceLookupResult *result)
+{
+    return WebCore::URL({ }, makeString(reportAnErrorBase(result), "&url=", encodeWithURLEscapeSequences(url), "&hl=", defaultLanguage()));
+}
+
+static NSURL *malwareDetailsURL(const WebCore::URL& url, SSBServiceLookupResult *result)
+{
+    return WebCore::URL({ }, makeString(malwareDetailsBase(result), "&site=", url.host(), "&hl=", defaultLanguage()));
+}
+
+static NSString *safeBrowsingTitleText(SSBServiceLookupResult *result)
+{
+    if (result.isPhishing)
+        return WEB_UI_NSSTRING(@"Deceptive Website Warning", "Phishing warning title");
+    if (result.isMalware)
+        return WEB_UI_NSSTRING(@"Malware Website Warning", "Malware warning title");
+    ASSERT(result.isUnwantedSoftware);
+    return WEB_UI_NSSTRING(@"Website With Harmful Software Warning", "Unwanted software warning title");
+}
+
+static NSString *safeBrowsingWarningText(SSBServiceLookupResult *result)
+{
+    if (result.isPhishing)
+        return WEB_UI_NSSTRING(@"This website may try to trick you into doing something dangerous, like installing software or disclosing personal or financial information, like passwords, phone numbers, or credit cards.", "Phishing warning");
+    if (result.isMalware)
+        return WEB_UI_NSSTRING(@"This website may attempt to install dangerous software, which could harm your computer or steal your personal or financial information, like passwords, photos, or credit cards.", "Malware warning");
+
+    ASSERT(result.isUnwantedSoftware);
+    return WEB_UI_NSSTRING(@"This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove.", "Unwanted software warning");
+}
+
+static NSMutableAttributedString *safeBrowsingDetailsText(const WebCore::URL& url, SSBServiceLookupResult *result)
+{
+    if (result.isPhishing) {
+        NSString *phishingDescription = WEB_UI_NSSTRING(@"Warnings are shown for websites that have been reported as deceptive. Deceptive websites try to trick you into believing they are legitimate websites you trust.", "Phishing warning description");
+        NSString *learnMore = WEB_UI_NSSTRING(@"Learn more…", "Action from safe browsing warning");
+        NSString *phishingActions = WEB_UI_NSSTRING(@"If you believe this website is safe, you can %report-an-error%. Or, if you understand the risks involved, you can %bypass-link%.", "Phishing warning description");
+        NSString *reportAnError = WEB_UI_NSSTRING(@"report an error", "Action from safe browsing warning");
+        NSString *visitUnsafeWebsite = WEB_UI_NSSTRING(@"visit this unsafe website", "Action from safe browsing warning");
+
+        NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@\n\n%@", phishingDescription, learnMore, phishingActions]] autorelease];
+        addLinkAndReplace(attributedString, learnMore, learnMore, learnMoreURL(result));
+        addLinkAndReplace(attributedString, @"%report-an-error%", reportAnError, reportAnErrorURL(url, result));
+        addLinkAndReplace(attributedString, @"%bypass-link%", visitUnsafeWebsite, SafeBrowsingWarning::visitUnsafeWebsiteSentinel());
+        return attributedString;
+    }
+
+    auto malwareOrUnwantedSoftwareDetails = [&] (NSString *description, NSString *statusStringToReplace, bool confirmMalware) {
+        NSMutableAttributedString *malwareDescription = [[[NSMutableAttributedString alloc] initWithString:description] autorelease];
+        replace(malwareDescription, @"%safeBrowsingProvider%", localizedProvider(result));
+        NSMutableAttributedString *statusLink = [[[NSMutableAttributedString alloc] initWithString:WEB_UI_NSSTRING(@"the status of “%site%”", "Part of malware description")] autorelease];
+        replace(statusLink, @"%site%", url.host().toString());
+        addLinkAndReplace(malwareDescription, statusStringToReplace, statusLink.string, malwareDetailsURL(url, result));
+
+        NSMutableAttributedString *ifYouUnderstand = [[[NSMutableAttributedString alloc] initWithString:WEB_UI_NSSTRING(@"If you understand the risks involved, you can %visit-this-unsafe-site-link%.", "Action from safe browsing warning")] autorelease];
+        addLinkAndReplace(ifYouUnderstand, @"%visit-this-unsafe-site-link%", WEB_UI_NSSTRING(@"visit this unsafe website", "Action from safe browsing warning"), confirmMalware ? SafeBrowsingWarning::confirmMalwareSentinel() : SafeBrowsingWarning::visitUnsafeWebsiteSentinel());
+
+        [malwareDescription appendAttributedString:[[[NSMutableAttributedString alloc] initWithString:@"\n\n"] autorelease]];
+        [malwareDescription appendAttributedString:ifYouUnderstand];
+        return malwareDescription;
+    };
+
+    if (result.isMalware)
+        return malwareOrUnwantedSoftwareDetails(WEB_UI_NSSTRING(@"Warnings are shown for websites where malicious software has been detected. You can check the %status-link% on the %safeBrowsingProvider% diagnostic page.", "Malware warning description"), @"%status-link%", true);
+    ASSERT(result.isUnwantedSoftware);
+    return malwareOrUnwantedSoftwareDetails(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);
+}
+
+SafeBrowsingWarning::SafeBrowsingWarning(const WebCore::URL& url, SSBServiceLookupResult *result)
+    : m_title(safeBrowsingTitleText(result))
+    , m_warning(safeBrowsingWarningText(result))
+    , m_details(safeBrowsingDetailsText(url, result))
+{
+}
+#endif
+
+SafeBrowsingWarning::SafeBrowsingWarning(String&& title, String&& warning, RetainPtr<NSAttributedString>&& details)
+    : m_title(WTFMove(title))
+    , m_warning(WTFMove(warning))
+    , m_details(WTFMove(details))
+{
+}
+
+NSURL *SafeBrowsingWarning::visitUnsafeWebsiteSentinel()
+{
+    return [NSURL URLWithString:@"WKVisitUnsafeWebsiteSentinel"];
+}
+
+NSURL *SafeBrowsingWarning::confirmMalwareSentinel()
+{
+    return [NSURL URLWithString:@"WKConfirmMalwareSentinel"];
+}
+
+}
index fb4b915..16025d9 100644 (file)
@@ -40,7 +40,7 @@ class URL;
 }
 
 namespace WebKit {
-class SafeBrowsingResult;
+class SafeBrowsingWarning;
 enum class ContinueUnsafeLoad : bool;
 }
 
@@ -56,10 +56,10 @@ using RectType = CGRect;
 {
 @package
     CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)> _completionHandler;
-    RefPtr<const WebKit::SafeBrowsingResult> _result;
+    RefPtr<const WebKit::SafeBrowsingWarning> _warning;
     RetainPtr<NSMutableArray<WKSafeBrowsingTextView *>> _textViews;
 }
 
-- (instancetype)initWithFrame:(RectType)frame safeBrowsingResult:(const WebKit::SafeBrowsingResult&)result completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler;
+- (instancetype)initWithFrame:(RectType)frame safeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler;
 
 @end
index adcd576..5f62f7f 100644 (file)
@@ -27,7 +27,7 @@
 #import "WKSafeBrowsingWarning.h"
 
 #import "PageClient.h"
-#import "SafeBrowsingResult.h"
+#import "SafeBrowsingWarning.h"
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/URL.h>
 #import <wtf/BlockPtr.h>
@@ -71,16 +71,6 @@ enum class WarningItem : uint8_t {
     GoBackButton
 };
 
-static NSURL *confirmMalwareSentinel()
-{
-    return [NSURL URLWithString:@"WKConfirmMalwareSentinel"];
-}
-
-static NSURL *visitUnsafeWebsiteSentinel()
-{
-    return [NSURL URLWithString:@"WKVisitUnsafeWebsiteSentinel"];
-}
-
 static ColorType *colorForItem(WarningItem item, ViewType *warning)
 {
     ASSERT([warning isKindOfClass:[WKSafeBrowsingWarning class]]);
@@ -134,21 +124,6 @@ static ColorType *colorForItem(WarningItem item, ViewType *warning)
     return nil;
 }
 
-static void replace(NSMutableAttributedString *string, NSString *toReplace, NSString *replaceWith)
-{
-    [string replaceCharactersInRange:[string.string rangeOfString:toReplace] withString:replaceWith];
-}
-
-static void addLinkAndReplace(NSMutableAttributedString *string, NSString *toReplace, NSString *replaceWith, NSURL *linkTarget)
-{
-    NSMutableAttributedString *stringWithLink = [[[NSMutableAttributedString alloc] initWithString:replaceWith] autorelease];
-    [stringWithLink addAttributes:@{
-        NSLinkAttributeName: linkTarget,
-        NSUnderlineStyleAttributeName: @1
-    } range:NSMakeRange(0, replaceWith.length)];
-    [string replaceCharactersInRange:[string.string rangeOfString:toReplace] withAttributedString:stringWithLink];
-}
-
 @interface WKSafeBrowsingExclamationPoint : ViewType
 @end
 
@@ -198,73 +173,6 @@ static void addLinkAndReplace(NSMutableAttributedString *string, NSString *toRep
 
 @end
 
-static NSURL *reportAnErrorURL(const WebKit::SafeBrowsingResult& result)
-{
-    return WebCore::URL({ }, makeString(result.reportAnErrorURLBase(), "&url=", encodeWithURLEscapeSequences(result.url()), "&hl=", defaultLanguage()));
-}
-
-static NSURL *malwareDetailsURL(const WebKit::SafeBrowsingResult& result)
-{
-    return WebCore::URL({ }, makeString(result.malwareDetailsURLBase(), "&site=", result.url().host(), "&hl=", defaultLanguage()));
-}
-
-static NSString *titleText(const WebKit::SafeBrowsingResult& result)
-{
-    if (result.isPhishing())
-        return WEB_UI_NSSTRING(@"Deceptive Website Warning", "Phishing warning title");
-    if (result.isMalware())
-        return WEB_UI_NSSTRING(@"Malware Website Warning", "Malware warning title");
-    ASSERT(result.isUnwantedSoftware());
-    return WEB_UI_NSSTRING(@"Website With Harmful Software Warning", "Unwanted software warning title");
-}
-
-static NSString *warningText(const WebKit::SafeBrowsingResult& result)
-{
-    if (result.isPhishing())
-        return WEB_UI_NSSTRING(@"This website may try to trick you into doing something dangerous, like installing software or disclosing personal or financial information, like passwords, phone numbers, or credit cards.", "Phishing warning");
-    if (result.isMalware())
-        return WEB_UI_NSSTRING(@"This website may attempt to install dangerous software, which could harm your computer or steal your personal or financial information, like passwords, photos, or credit cards.", "Malware warning");
-    ASSERT(result.isUnwantedSoftware());
-    return WEB_UI_NSSTRING(@"This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove.", "Unwanted software warning");
-}
-
-static NSMutableAttributedString *detailsText(const WebKit::SafeBrowsingResult& result)
-{
-    if (result.isPhishing()) {
-        NSString *phishingDescription = WEB_UI_NSSTRING(@"Warnings are shown for websites that have been reported as deceptive. Deceptive websites try to trick you into believing they are legitimate websites you trust.", "Phishing warning description");
-        NSString *learnMore = WEB_UI_NSSTRING(@"Learn more…", "Action from safe browsing warning");
-        NSString *phishingActions = WEB_UI_NSSTRING(@"If you believe this website is safe, you can %report-an-error%. Or, if you understand the risks involved, you can %bypass-link%.", "Phishing warning description");
-        NSString *reportAnError = WEB_UI_NSSTRING(@"report an error", "Action from safe browsing warning");
-        NSString *visitUnsafeWebsite = WEB_UI_NSSTRING(@"visit this unsafe website", "Action from safe browsing warning");
-        
-        NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@\n\n%@", phishingDescription, learnMore, phishingActions]] autorelease];
-        addLinkAndReplace(attributedString, learnMore, learnMore, result.learnMoreURL());
-        addLinkAndReplace(attributedString, @"%report-an-error%", reportAnError, reportAnErrorURL(result));
-        addLinkAndReplace(attributedString, @"%bypass-link%", visitUnsafeWebsite, visitUnsafeWebsiteSentinel());
-        return attributedString;
-    }
-    
-    auto malwareOrUnwantedSoftwareDetails = [] (const WebKit::SafeBrowsingResult& result, NSString *description, NSString *statusStringToReplace, bool confirmMalware) {
-        NSMutableAttributedString *malwareDescription = [[[NSMutableAttributedString alloc] initWithString:description] autorelease];
-        replace(malwareDescription, @"%safeBrowsingProvider%", result.localizedProviderName());
-        NSMutableAttributedString *statusLink = [[[NSMutableAttributedString alloc] initWithString:WEB_UI_NSSTRING(@"the status of “%site%”", "Part of malware description")] autorelease];
-        replace(statusLink, @"%site%", result.url().host().toString());
-        addLinkAndReplace(malwareDescription, statusStringToReplace, statusLink.string, malwareDetailsURL(result));
-        
-        NSMutableAttributedString *ifYouUnderstand = [[[NSMutableAttributedString alloc] initWithString:WEB_UI_NSSTRING(@"If you understand the risks involved, you can %visit-this-unsafe-site-link%.", "Action from safe browsing warning")] autorelease];
-        addLinkAndReplace(ifYouUnderstand, @"%visit-this-unsafe-site-link%", WEB_UI_NSSTRING(@"visit this unsafe website", "Action from safe browsing warning"), confirmMalware ? confirmMalwareSentinel() : visitUnsafeWebsiteSentinel());
-        
-        [malwareDescription appendAttributedString:[[[NSMutableAttributedString alloc] initWithString:@"\n\n"] autorelease]];
-        [malwareDescription appendAttributedString:ifYouUnderstand];
-        return malwareDescription;
-    };
-    
-    if (result.isMalware())
-        return malwareOrUnwantedSoftwareDetails(result, WEB_UI_NSSTRING(@"Warnings are shown for websites where malicious software has been detected. You can check the %status-link% on the %safeBrowsingProvider% diagnostic page.", "Malware warning description"), @"%status-link%", true);
-    ASSERT(result.isUnwantedSoftware());
-    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);
-}
-
 static ButtonType *makeButton(WarningItem item, WKSafeBrowsingWarning *warning, SEL action)
 {
     NSString *title = nil;
@@ -325,14 +233,14 @@ static void setBackground(ViewType *view, ColorType *color)
 
 @implementation WKSafeBrowsingWarning
 
-- (instancetype)initWithFrame:(RectType)frame safeBrowsingResult:(const WebKit::SafeBrowsingResult&)result completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler
+- (instancetype)initWithFrame:(RectType)frame safeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&)completionHandler
 {
     if (!(self = [super initWithFrame:frame])) {
         completionHandler(WebKit::ContinueUnsafeLoad::Yes);
         return nil;
     }
     _completionHandler = WTFMove(completionHandler);
-    _result = makeRef(result);
+    _warning = makeRef(warning);
     setBackground(self, colorForItem(WarningItem::Background, self));
 #if PLATFORM(MAC)
     [self addContent];
@@ -343,8 +251,8 @@ static void setBackground(ViewType *view, ColorType *color)
 - (void)addContent
 {
     auto exclamationPoint = [[WKSafeBrowsingExclamationPoint new] autorelease];
-    auto title = makeTitleLabel(titleText(*_result), self);
-    auto warning = [[[WKSafeBrowsingTextView alloc] initWithAttributedString:[[[NSAttributedString alloc] initWithString:warningText(*_result) attributes:@{ NSFontAttributeName:[FontType systemFontOfSize:textSize] }] autorelease] forWarning:self] autorelease];
+    auto title = makeTitleLabel(_warning->title(), self);
+    auto warning = [[[WKSafeBrowsingTextView alloc] initWithAttributedString:[[[NSAttributedString alloc] initWithString:_warning->warning() attributes:@{ NSFontAttributeName:[FontType systemFontOfSize:textSize] }] autorelease] forWarning:self] autorelease];
     auto showDetails = makeButton(WarningItem::ShowDetailsButton, self, @selector(showDetailsClicked));
     auto goBack = makeButton(WarningItem::GoBackButton, self, @selector(goBackClicked));
     auto box = [[ViewType new] autorelease];
@@ -395,7 +303,7 @@ static void setBackground(ViewType *view, ColorType *color)
     ButtonType *showDetails = box.subviews.lastObject;
     [showDetails removeFromSuperview];
 
-    NSMutableAttributedString *text = detailsText(*_result);
+    NSMutableAttributedString *text = [[_warning->details() mutableCopy] autorelease];
     [text addAttributes:@{ NSFontAttributeName:[FontType systemFontOfSize:textSize] } range:NSMakeRange(0, text.length)];
     WKSafeBrowsingTextView *details = [[[WKSafeBrowsingTextView alloc] initWithAttributedString:text forWarning:self] autorelease];
     [_textViews addObject:details];
@@ -503,10 +411,10 @@ static void setBackground(ViewType *view, ColorType *color)
     if (!_completionHandler)
         return;
 
-    if ([link isEqual:visitUnsafeWebsiteSentinel()])
+    if ([link isEqual:WebKit::SafeBrowsingWarning::visitUnsafeWebsiteSentinel()])
         return _completionHandler(WebKit::ContinueUnsafeLoad::Yes);
 
-    if ([link isEqual:confirmMalwareSentinel()]) {
+    if ([link isEqual:WebKit::SafeBrowsingWarning::confirmMalwareSentinel()]) {
 #if PLATFORM(MAC)
         auto alert = adoptNS([NSAlert new]);
         [alert setMessageText:WEB_UI_NSSTRING(@"Are you sure you wish to go to this site?", "Malware confirmation dialog title")];
@@ -541,7 +449,7 @@ static void setBackground(ViewType *view, ColorType *color)
     self.delegate = warning;
 
     ColorType *foregroundColor = colorForItem(WarningItem::MessageText, warning);
-    NSMutableAttributedString *string = [attributedString mutableCopy];
+    NSMutableAttributedString *string = [[attributedString mutableCopy] autorelease];
     [string addAttributes:@{ NSForegroundColorAttributeName : foregroundColor } range:NSMakeRange(0, string.length)];
     [self setBackgroundColor:colorForItem(WarningItem::BoxBackground, warning)];
     [self setLinkTextAttributes:@{ NSForegroundColorAttributeName : foregroundColor }];
index 3953d0a..f56875d 100644 (file)
@@ -31,8 +31,8 @@
 #import "DataDetectionResult.h"
 #import "LoadParameters.h"
 #import "PageClient.h"
-#import "SafeBrowsingResult.h"
 #import "SafeBrowsingSPI.h"
+#import "SafeBrowsingWarning.h"
 #import "WebProcessProxy.h"
 #import <WebCore/DragItem.h>
 #import <WebCore/NotImplemented.h>
@@ -84,12 +84,13 @@ void WebPageProxy::beginSafeBrowsingCheck(const URL& url, WebFramePolicyListener
                 return;
             }
 
-            NSArray<SSBServiceLookupResult *> *results = [result serviceLookupResults];
-            Vector<Ref<SafeBrowsingResult>> resultsVector;
-            resultsVector.reserveInitialCapacity([results count]);
-            for (SSBServiceLookupResult *result in results)
-                resultsVector.uncheckedAppend(SafeBrowsingResult::create(URL(url), result));
-            listener->didReceiveSafeBrowsingResults(WTFMove(resultsVector));
+            for (SSBServiceLookupResult *lookupResult in [result serviceLookupResults]) {
+                if (lookupResult.isPhishing || lookupResult.isMalware || lookupResult.isUnwantedSoftware) {
+                    listener->didReceiveSafeBrowsingResults(SafeBrowsingWarning::create(url, lookupResult));
+                    return;
+                }
+            }
+            listener->didReceiveSafeBrowsingResults({ });
         });
     }).get()];
 #else
index 3b5946d..5058216 100644 (file)
@@ -226,7 +226,7 @@ public:
     void setViewScale(CGFloat);
     CGFloat viewScale() const;
 
-    void showSafeBrowsingWarning(const SafeBrowsingResult&, CompletionHandler<void(Variant<ContinueUnsafeLoad, WebCore::URL>&&)>&&);
+    void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<ContinueUnsafeLoad, WebCore::URL>&&)>&&);
     void clearSafeBrowsingWarning();
 
     WKLayoutMode layoutMode() const;
index 80ba69c..0b21d53 100644 (file)
@@ -1606,12 +1606,12 @@ bool WebViewImpl::resignFirstResponder()
     return true;
 }
 
-void WebViewImpl::showSafeBrowsingWarning(const SafeBrowsingResult& result, CompletionHandler<void(Variant<ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
+void WebViewImpl::showSafeBrowsingWarning(const SafeBrowsingWarning& warning, CompletionHandler<void(Variant<ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
 {
     if (!m_view)
         return completionHandler(ContinueUnsafeLoad::Yes);
 
-    m_safeBrowsingWarning = adoptNS([[WKSafeBrowsingWarning alloc] initWithFrame:[m_view bounds] safeBrowsingResult:result completionHandler:[weakThis = makeWeakPtr(*this), completionHandler = WTFMove(completionHandler)] (auto&& result) mutable {
+    m_safeBrowsingWarning = adoptNS([[WKSafeBrowsingWarning alloc] initWithFrame:[m_view bounds] safeBrowsingWarning:warning completionHandler:[weakThis = makeWeakPtr(*this), completionHandler = WTFMove(completionHandler)] (auto&& result) mutable {
         if (weakThis)
             [std::exchange(weakThis->m_safeBrowsingWarning, nullptr) removeFromSuperview];
         completionHandler(WTFMove(result));
index 6c38cbd..a16ae20 100644 (file)
@@ -110,7 +110,7 @@ class NativeWebKeyboardEvent;
 class NativeWebMouseEvent;
 class NativeWebWheelEvent;
 class RemoteLayerTreeTransaction;
-class SafeBrowsingResult;
+class SafeBrowsingWarning;
 class UserData;
 class ViewSnapshot;
 class WebBackForwardListItem;
@@ -216,7 +216,7 @@ public:
 
     virtual void didChangeContentSize(const WebCore::IntSize&) = 0;
 
-    virtual void showSafeBrowsingWarning(const SafeBrowsingResult&, CompletionHandler<void(Variant<ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler) { completionHandler(ContinueUnsafeLoad::Yes); }
+    virtual void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler) { completionHandler(ContinueUnsafeLoad::Yes); }
     virtual void clearSafeBrowsingWarning() { }
     
 #if ENABLE(DRAG_SUPPORT)
similarity index 55%
rename from Source/WebKit/UIProcess/SafeBrowsingResult.h
rename to Source/WebKit/UIProcess/SafeBrowsingWarning.h
index 0e895ad..616f478 100644 (file)
 
 #include <WebCore/URL.h>
 #include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
 #include <wtf/text/WTFString.h>
 
+OBJC_CLASS NSAttributedString;
+OBJC_CLASS NSURL;
 OBJC_CLASS SSBServiceLookupResult;
 
 namespace WebKit {
 
-class SafeBrowsingResult : public RefCounted<SafeBrowsingResult> {
+class SafeBrowsingWarning : public RefCounted<SafeBrowsingWarning> {
 public:
 #if HAVE(SAFE_BROWSING)
-    static Ref<SafeBrowsingResult> create(WebCore::URL&& url, SSBServiceLookupResult *result)
+    static Ref<SafeBrowsingWarning> create(const WebCore::URL& url, SSBServiceLookupResult *result)
     {
-        return adoptRef(*new SafeBrowsingResult(WTFMove(url), result));
+        return adoptRef(*new SafeBrowsingWarning(url, result));
+    }
+#endif
+#if PLATFORM(COCOA)
+    static Ref<SafeBrowsingWarning> create(String&& title, String&& warning, RetainPtr<NSAttributedString>&& details)
+    {
+        return adoptRef(*new SafeBrowsingWarning(WTFMove(title), WTFMove(warning), WTFMove(details)));
     }
 #endif
 
-    bool isPhishing() const { return m_isPhishing; }
-    bool isMalware() const { return m_isMalware; }
-    bool isUnwantedSoftware() const { return m_isUnwantedSoftware; }
-
-    const WebCore::URL& url() const { return m_url; }
-    const String& provider() const { return m_provider; }
-    const String& localizedProviderName() const { return m_localizedProviderName; }
-    const String& malwareDetailsURLBase() const { return m_malwareDetailsURLBase; }
-    const String& reportAnErrorURLBase() const { return m_reportAnErrorURLBase; }
-    const WebCore::URL& learnMoreURL() const { return m_learnMoreURL; }
-
-    bool needsSafeBrowsingWarning() const { return m_isPhishing || m_isMalware || m_isUnwantedSoftware; }
+    const String& title() const { return m_title; }
+    const String& warning() const { return m_warning; }
+#if PLATFORM(COCOA)
+    RetainPtr<NSAttributedString> details() const { return m_details; }
+#endif
 
+    static NSURL *visitUnsafeWebsiteSentinel();
+    static NSURL *confirmMalwareSentinel();
+    
 private:
 #if HAVE(SAFE_BROWSING)
-    SafeBrowsingResult(WebCore::URL&&, SSBServiceLookupResult *);
+    SafeBrowsingWarning(const WebCore::URL&, SSBServiceLookupResult *);
+#endif
+#if PLATFORM(COCOA)
+    SafeBrowsingWarning(String&&, String&&, RetainPtr<NSAttributedString>&&);
 #endif
-    WebCore::URL m_url;
-    bool m_isPhishing { false };
-    bool m_isMalware { false };
-    bool m_isUnwantedSoftware { false };
 
-    String m_provider;
-    String m_localizedProviderName;
-    String m_malwareDetailsURLBase;
-    String m_reportAnErrorURLBase;
-    WebCore::URL m_learnMoreURL;
+    String m_title;
+    String m_warning;
+#if PLATFORM(COCOA)
+    RetainPtr<NSAttributedString> m_details;
+#endif
 };
 
 } // namespace WebKit
index 568e745..8e31f07 100644 (file)
@@ -29,7 +29,7 @@
 #include "APINavigation.h"
 #include "APIWebsiteDataStore.h"
 #include "APIWebsitePolicies.h"
-#include "SafeBrowsingResult.h"
+#include "SafeBrowsingWarning.h"
 #include "WebFrameProxy.h"
 #include "WebsiteDataStore.h"
 #include "WebsitePoliciesData.h"
@@ -45,21 +45,21 @@ WebFramePolicyListenerProxy::WebFramePolicyListenerProxy(Reply&& reply, ShouldEx
 
 WebFramePolicyListenerProxy::~WebFramePolicyListenerProxy() = default;
 
-void WebFramePolicyListenerProxy::didReceiveSafeBrowsingResults(Vector<Ref<SafeBrowsingResult>>&& safeBrowsingResults)
+void WebFramePolicyListenerProxy::didReceiveSafeBrowsingResults(RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning)
 {
-    ASSERT(!m_safeBrowsingResults);
+    ASSERT(!m_safeBrowsingWarning);
     if (m_policyResult) {
         if (m_reply)
-            m_reply(WebCore::PolicyAction::Use, m_policyResult->first.get(), m_policyResult->second, WTFMove(safeBrowsingResults));
+            m_reply(WebCore::PolicyAction::Use, m_policyResult->first.get(), m_policyResult->second, WTFMove(safeBrowsingWarning));
     } else
-        m_safeBrowsingResults = WTFMove(safeBrowsingResults);
+        m_safeBrowsingWarning = WTFMove(safeBrowsingWarning);
 }
 
 void WebFramePolicyListenerProxy::use(API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient)
 {
-    if (m_safeBrowsingResults) {
+    if (m_safeBrowsingWarning) {
         if (m_reply)
-            m_reply(WebCore::PolicyAction::Use, policies, processSwapRequestedByClient, WTFMove(*m_safeBrowsingResults));
+            m_reply(WebCore::PolicyAction::Use, policies, processSwapRequestedByClient, WTFMove(*m_safeBrowsingWarning));
     } else if (!m_policyResult)
         m_policyResult = {{ policies, processSwapRequestedByClient }};
 }
index fa1cd2a..9598da7 100644 (file)
@@ -39,7 +39,7 @@ enum class PolicyAction : uint8_t;
 
 namespace WebKit {
 
-class SafeBrowsingResult;
+class SafeBrowsingWarning;
 
 enum class ProcessSwapRequestedByClient { No, Yes };
 enum class ShouldExpectSafeBrowsingResult { No, Yes };
@@ -47,7 +47,7 @@ enum class ShouldExpectSafeBrowsingResult { No, Yes };
 class WebFramePolicyListenerProxy : public API::ObjectImpl<API::Object::Type::FramePolicyListener> {
 public:
 
-    using Reply = CompletionHandler<void(WebCore::PolicyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient, Vector<Ref<SafeBrowsingResult>>&&)>;
+    using Reply = CompletionHandler<void(WebCore::PolicyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&&)>;
     static Ref<WebFramePolicyListenerProxy> create(Reply&& reply, ShouldExpectSafeBrowsingResult expect)
     {
         return adoptRef(*new WebFramePolicyListenerProxy(WTFMove(reply), expect));
@@ -58,13 +58,13 @@ public:
     void download();
     void ignore();
     
-    void didReceiveSafeBrowsingResults(Vector<Ref<SafeBrowsingResult>>&&);
+    void didReceiveSafeBrowsingResults(RefPtr<SafeBrowsingWarning>&&);
 
 private:
     WebFramePolicyListenerProxy(Reply&&, ShouldExpectSafeBrowsingResult);
 
     std::optional<std::pair<RefPtr<API::WebsitePolicies>, ProcessSwapRequestedByClient>> m_policyResult;
-    std::optional<Vector<Ref<SafeBrowsingResult>>> m_safeBrowsingResults;
+    std::optional<RefPtr<SafeBrowsingWarning>> m_safeBrowsingWarning;
     Reply m_reply;
 };
 
index b160ce4..6928849 100644 (file)
@@ -43,8 +43,8 @@
 namespace WebKit {
 using namespace WebCore;
 
-WebFrameProxy::WebFrameProxy(WebPageProxy* page, uint64_t frameID)
-    : m_page(page)
+WebFrameProxy::WebFrameProxy(WebPageProxy& page, uint64_t frameID)
+    : m_page(makeWeakPtr(page))
     , m_isFrameSet(false)
     , m_frameID(frameID)
 {
@@ -177,12 +177,12 @@ void WebFrameProxy::didChangeTitle(const String& title)
     m_title = title;
 }
 
-WebFramePolicyListenerProxy& WebFrameProxy::setUpPolicyListenerProxy(CompletionHandler<void(WebCore::PolicyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient, Vector<Ref<SafeBrowsingResult>>&&)>&& completionHandler, ShouldExpectSafeBrowsingResult expect)
+WebFramePolicyListenerProxy& WebFrameProxy::setUpPolicyListenerProxy(CompletionHandler<void(WebCore::PolicyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&&)>&& completionHandler, ShouldExpectSafeBrowsingResult expect)
 {
     if (m_activeListener)
         m_activeListener->ignore();
-    m_activeListener = WebFramePolicyListenerProxy::create([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)] (WebCore::PolicyAction action, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, Vector<Ref<SafeBrowsingResult>>&& safeBrowsingResults) mutable {
-        completionHandler(action, policies, processSwapRequestedByClient, WTFMove(safeBrowsingResults));
+    m_activeListener = WebFramePolicyListenerProxy::create([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)] (WebCore::PolicyAction action, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning) mutable {
+        completionHandler(action, policies, processSwapRequestedByClient, WTFMove(safeBrowsingWarning));
         m_activeListener = nullptr;
     }, expect);
     return *m_activeListener;
@@ -231,7 +231,7 @@ bool WebFrameProxy::didHandleContentFilterUnblockNavigation(const ResourceReques
         return false;
     }
 
-    RefPtr<WebPageProxy> page { m_page };
+    RefPtr<WebPageProxy> page { m_page.get() };
     ASSERT(page);
     m_contentFilterUnblockHandler.requestUnblockAsync([page](bool unblocked) {
         if (unblocked)
index 297aa8a..624d806 100644 (file)
@@ -48,7 +48,7 @@ class Decoder;
 }
 
 namespace WebKit {
-class SafeBrowsingResult;
+class SafeBrowsingWarning;
 class WebCertificateInfo;
 class WebFramePolicyListenerProxy;
 class WebPageProxy;
@@ -61,7 +61,7 @@ typedef GenericCallback<API::Data*> DataCallback;
 
 class WebFrameProxy : public API::ObjectImpl<API::Object::Type::Frame> {
 public:
-    static Ref<WebFrameProxy> create(WebPageProxy* page, uint64_t frameID)
+    static Ref<WebFrameProxy> create(WebPageProxy& page, uint64_t frameID)
     {
         return adoptRef(*new WebFrameProxy(page, frameID));
     }
@@ -69,7 +69,7 @@ public:
     virtual ~WebFrameProxy();
 
     uint64_t frameID() const { return m_frameID; }
-    WebPageProxy* page() const { return m_page; }
+    WebPageProxy* page() const { return m_page.get(); }
 
     void webProcessWillShutDown();
 
@@ -117,7 +117,7 @@ public:
     void didSameDocumentNavigation(const WebCore::URL&); // eg. anchor navigation, session state change.
     void didChangeTitle(const String&);
 
-    WebFramePolicyListenerProxy& setUpPolicyListenerProxy(CompletionHandler<void(WebCore::PolicyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient, Vector<Ref<SafeBrowsingResult>>&&)>&&, ShouldExpectSafeBrowsingResult);
+    WebFramePolicyListenerProxy& setUpPolicyListenerProxy(CompletionHandler<void(WebCore::PolicyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&&)>&&, ShouldExpectSafeBrowsingResult);
 
 #if ENABLE(CONTENT_FILTERING)
     void contentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler contentFilterUnblockHandler) { m_contentFilterUnblockHandler = WTFMove(contentFilterUnblockHandler); }
@@ -129,9 +129,9 @@ public:
 #endif
 
 private:
-    WebFrameProxy(WebPageProxy* page, uint64_t frameID);
+    WebFrameProxy(WebPageProxy&, uint64_t frameID);
 
-    WebPageProxy* m_page;
+    WeakPtr<WebPageProxy> m_page;
 
     FrameLoadState m_frameLoadState;
 
index 05e5fdd..ba0cdbc 100644 (file)
@@ -77,7 +77,7 @@
 #include "PluginInformation.h"
 #include "PluginProcessManager.h"
 #include "PrintInfo.h"
-#include "SafeBrowsingResult.h"
+#include "SafeBrowsingWarning.h"
 #include "ShareSheetCallbackID.h"
 #include "SharedBufferDataReference.h"
 #include "TextChecker.h"
@@ -761,7 +761,7 @@ void WebPageProxy::swapToWebProcess(Ref<WebProcessProxy>&& process, API::Navigat
     if (destinationSuspendedPage) {
         ASSERT(!m_mainFrame);
         ASSERT(&destinationSuspendedPage->process() == m_process.ptr());
-        m_mainFrame = WebFrameProxy::create(this, destinationSuspendedPage->mainFrameID());
+        m_mainFrame = WebFrameProxy::create(*this, destinationSuspendedPage->mainFrameID());
         m_process->frameCreated(destinationSuspendedPage->mainFrameID(), *m_mainFrame);
     }
 
@@ -3468,7 +3468,7 @@ void WebPageProxy::didCreateMainFrame(uint64_t frameID)
     MESSAGE_CHECK(!m_mainFrame);
     MESSAGE_CHECK(m_process->canCreateFrame(frameID));
 
-    m_mainFrame = WebFrameProxy::create(this, frameID);
+    m_mainFrame = WebFrameProxy::create(*this, frameID);
 
     // Add the frame to the process wide map.
     m_process->frameCreated(frameID, *m_mainFrame);
@@ -3493,7 +3493,7 @@ void WebPageProxy::didCreateSubframe(uint64_t frameID)
 
     MESSAGE_CHECK(m_process->canCreateFrame(frameID));
     
-    RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(this, frameID);
+    RefPtr<WebFrameProxy> subFrame = WebFrameProxy::create(*this, frameID);
 
     // Add the frame to the process wide map.
     m_process->frameCreated(frameID, *subFrame);
@@ -4160,7 +4160,7 @@ void WebPageProxy::decidePolicyForNavigationAction(WebFrameProxy& frame, const W
     if (!m_preferences->safeBrowsingEnabled())
         shouldSkipSafeBrowsingCheck = ShouldSkipSafeBrowsingCheck::Yes;
 
-    auto listener = makeRef(frame.setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), frame = makeRef(frame), sender = WTFMove(sender), navigation] (WebCore::PolicyAction policyAction, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, Vector<Ref<SafeBrowsingResult>>&& safeBrowsingResults) mutable {
+    auto listener = makeRef(frame.setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), frame = makeRef(frame), sender = WTFMove(sender), navigation] (WebCore::PolicyAction policyAction, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning) mutable {
         
         auto completionHandler = [this, protectedThis = protectedThis.copyRef(), frame = frame.copyRef(), sender = WTFMove(sender), navigation = WTFMove(navigation), processSwapRequestedByClient, policies = makeRefPtr(policies)] (PolicyAction policyAction) mutable {
             receivedNavigationPolicyDecision(policyAction, navigation.get(), processSwapRequestedByClient, frame, policies.get(), WTFMove(sender));
@@ -4171,10 +4171,8 @@ void WebPageProxy::decidePolicyForNavigationAction(WebFrameProxy& frame, const W
 
         m_pageClient->clearSafeBrowsingWarning();
 
-        for (auto& result : safeBrowsingResults) {
-            if (!result->needsSafeBrowsingWarning())
-                continue;
-            m_pageClient->showSafeBrowsingWarning(result, [protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), policyAction] (auto&& result) mutable {
+        if (safeBrowsingWarning) {
+            m_pageClient->showSafeBrowsingWarning(*safeBrowsingWarning, [protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), policyAction] (auto&& result) mutable {
                 switchOn(result, [&] (const URL& url) {
                     completionHandler(PolicyAction::Ignore);
                     protectedThis->loadRequest({ url });
@@ -4254,10 +4252,10 @@ void WebPageProxy::decidePolicyForNewWindowAction(uint64_t frameID, const Securi
     MESSAGE_CHECK(frame);
     MESSAGE_CHECK_URL(request.url());
 
-    auto listener = makeRef(frame->setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), listenerID, frameID] (WebCore::PolicyAction policyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient processSwapRequestedByClient, Vector<Ref<SafeBrowsingResult>>&& safeBrowsingResults) mutable {
+    auto listener = makeRef(frame->setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), listenerID, frameID] (WebCore::PolicyAction policyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning) mutable {
         // FIXME: Assert the API::WebsitePolicies* is nullptr here once clients of WKFramePolicyListenerUseWithPolicies go away.
         RELEASE_ASSERT(processSwapRequestedByClient == ProcessSwapRequestedByClient::No);
-        ASSERT_UNUSED(safeBrowsingResults, safeBrowsingResults.isEmpty());
+        ASSERT_UNUSED(safeBrowsingWarning, !safeBrowsingWarning);
         receivedPolicyDecision(policyAction, nullptr, std::nullopt, PolicyDecisionSender::create([this, protectedThis = WTFMove(protectedThis), frameID, listenerID] (auto... args) {
             m_process->send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, args...), m_pageID);
         }));
@@ -4292,10 +4290,10 @@ void WebPageProxy::decidePolicyForResponse(uint64_t frameID, const SecurityOrigi
     MESSAGE_CHECK_URL(response.url());
 
     RefPtr<API::Navigation> navigation = navigationID ? m_navigationState->navigation(navigationID) : nullptr;
-    auto listener = makeRef(frame->setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), frameID, listenerID, navigation = WTFMove(navigation)] (WebCore::PolicyAction policyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient processSwapRequestedByClient, Vector<Ref<SafeBrowsingResult>>&& safeBrowsingResults) mutable {
+    auto listener = makeRef(frame->setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), frameID, listenerID, navigation = WTFMove(navigation)] (WebCore::PolicyAction policyAction, API::WebsitePolicies*, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning) mutable {
         // FIXME: Assert the API::WebsitePolicies* is nullptr here once clients of WKFramePolicyListenerUseWithPolicies go away.
         RELEASE_ASSERT(processSwapRequestedByClient == ProcessSwapRequestedByClient::No);
-        ASSERT_UNUSED(safeBrowsingResults, safeBrowsingResults.isEmpty());
+        ASSERT_UNUSED(safeBrowsingWarning, !safeBrowsingWarning);
         receivedPolicyDecision(policyAction, navigation.get(), std::nullopt, PolicyDecisionSender::create([this, protectedThis = WTFMove(protectedThis), frameID, listenerID] (auto... args) {
             m_process->send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, args...), m_pageID);
         }));
index 06aca07..479b56a 100644 (file)
@@ -115,7 +115,7 @@ private:
     void clearTextIndicator(WebCore::TextIndicatorWindowDismissalAnimation) override;
     void setTextIndicatorAnimationProgress(float) override;
 
-    void showSafeBrowsingWarning(const SafeBrowsingResult&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&) override;
+    void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&) override;
     void clearSafeBrowsingWarning() override;
 
     void enterAcceleratedCompositingMode(const LayerTreeContext&) override;
index 4ab814a..d140da3 100644 (file)
@@ -473,10 +473,10 @@ void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext& lay
 {
 }
 
-void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingResult& result, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
+void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingWarning& warning, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
 {
     if (auto webView = m_webView.get())
-        [webView _showSafeBrowsingWarning:result completionHandler:WTFMove(completionHandler)];
+        [webView _showSafeBrowsingWarning:warning completionHandler:WTFMove(completionHandler)];
     else
         completionHandler(ContinueUnsafeLoad::No);
 }
index 4c22a85..08f45db 100644 (file)
@@ -104,7 +104,7 @@ private:
     void resetSecureInputState() override;
     void notifyInputContextAboutDiscardedComposition() override;
     void selectionDidChange() override;
-    void showSafeBrowsingWarning(const SafeBrowsingResult&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&) override;
+    void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&&) override;
     void clearSafeBrowsingWarning() override;
     
 #if WK_API_ENABLED
index c98a547..9134168 100644 (file)
@@ -489,11 +489,11 @@ Ref<ValidationBubble> PageClientImpl::createValidationBubble(const String& messa
     return ValidationBubble::create(m_view, message, settings);
 }
 
-void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingResult& result, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
+void PageClientImpl::showSafeBrowsingWarning(const SafeBrowsingWarning& warning, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, WebCore::URL>&&)>&& completionHandler)
 {
     if (!m_impl)
         return completionHandler(ContinueUnsafeLoad::Yes);
-    m_impl->showSafeBrowsingWarning(result, WTFMove(completionHandler));
+    m_impl->showSafeBrowsingWarning(warning, WTFMove(completionHandler));
 }
 
 void PageClientImpl::clearSafeBrowsingWarning()
index 603e9ec..d3a73db 100644 (file)
                5C9E56831DF7F1B300C9EE33 /* WKWebsitePolicies.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C9E56811DF7F05500C9EE33 /* WKWebsitePolicies.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5CA26D81217ABD5B00F97A35 /* WKSafeBrowsingWarning.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CA26D80217ABBB600F97A35 /* WKSafeBrowsingWarning.h */; };
                5CA26D83217AD1B800F97A35 /* WKSafeBrowsingWarning.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CA26D7F217ABBB600F97A35 /* WKSafeBrowsingWarning.mm */; };
-               5CA9854A210BEB640057EB6B /* SafeBrowsingResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CA98549210BEB5A0057EB6B /* SafeBrowsingResult.h */; };
+               5CA9854A210BEB640057EB6B /* SafeBrowsingWarning.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CA98549210BEB5A0057EB6B /* SafeBrowsingWarning.h */; };
                5CADDE05215046BD0067D309 /* WKWebProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C74300E21500492004BFA17 /* WKWebProcess.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5CAFDE452130846300B1F7E1 /* _WKInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CAFDE422130843500B1F7E1 /* _WKInspector.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5CAFDE472130846A00B1F7E1 /* _WKInspectorInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CAFDE442130843600B1F7E1 /* _WKInspectorInternal.h */; };
                5C9E56811DF7F05500C9EE33 /* WKWebsitePolicies.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebsitePolicies.h; sourceTree = "<group>"; };
                5CA26D7F217ABBB600F97A35 /* WKSafeBrowsingWarning.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKSafeBrowsingWarning.mm; sourceTree = "<group>"; };
                5CA26D80217ABBB600F97A35 /* WKSafeBrowsingWarning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKSafeBrowsingWarning.h; sourceTree = "<group>"; };
-               5CA98549210BEB5A0057EB6B /* SafeBrowsingResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SafeBrowsingResult.h; sourceTree = "<group>"; };
-               5CA9854B210BEB730057EB6B /* SafeBrowsingResultCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SafeBrowsingResultCocoa.mm; sourceTree = "<group>"; };
+               5CA98549210BEB5A0057EB6B /* SafeBrowsingWarning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SafeBrowsingWarning.h; sourceTree = "<group>"; };
+               5CA9854B210BEB730057EB6B /* SafeBrowsingWarningCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SafeBrowsingWarningCocoa.mm; sourceTree = "<group>"; };
                5CADDE0D2151AA010067D309 /* AuthenticationChallengeDisposition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AuthenticationChallengeDisposition.h; path = Authentication/AuthenticationChallengeDisposition.h; sourceTree = "<group>"; };
                5CAFDE422130843500B1F7E1 /* _WKInspector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspector.h; sourceTree = "<group>"; };
                5CAFDE432130843600B1F7E1 /* _WKInspector.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKInspector.mm; sourceTree = "<group>"; };
                                CDA29A221CBEB61A00901CCF /* PlaybackSessionManagerProxy.messages.in */,
                                CDA29A1F1CBEB5FB00901CCF /* PlaybackSessionManagerProxy.mm */,
                                837A660020E2AD8400A9DBD8 /* ResourceLoadStatisticsMemoryStoreCocoa.mm */,
-                               5CA9854B210BEB730057EB6B /* SafeBrowsingResultCocoa.mm */,
+                               5CA9854B210BEB730057EB6B /* SafeBrowsingWarningCocoa.mm */,
                                1A002D47196B345D00B9AD44 /* SessionStateCoding.h */,
                                1A002D46196B345D00B9AD44 /* SessionStateCoding.mm */,
                                3157135C2040A9B20084F9CF /* SystemPreviewControllerCocoa.mm */,
                                51E6C1611F2935CD00FD3437 /* ResourceLoadStatisticsPersistentStorage.h */,
                                BC111B08112F5E3C00337BAB /* ResponsivenessTimer.cpp */,
                                1A30066C1110F4F70031937C /* ResponsivenessTimer.h */,
-                               5CA98549210BEB5A0057EB6B /* SafeBrowsingResult.h */,
+                               5CA98549210BEB5A0057EB6B /* SafeBrowsingWarning.h */,
                                414DEDD61F9EDDE00047C40D /* ServiceWorkerProcessProxy.cpp */,
                                414DEDD51F9EDDDF0047C40D /* ServiceWorkerProcessProxy.h */,
                                51A4D5A816CAC4FF000E615E /* StatisticsRequest.cpp */,
                                51E6C1641F2935DD00FD3437 /* ResourceLoadStatisticsPersistentStorage.h in Headers */,
                                1A30066E1110F4F70031937C /* ResponsivenessTimer.h in Headers */,
                                410482CE1DDD324F00F006D0 /* RTCNetwork.h in Headers */,
-                               5CA9854A210BEB640057EB6B /* SafeBrowsingResult.h in Headers */,
                                0E97D74D200E900400BF6643 /* SafeBrowsingSPI.h in Headers */,
+                               5CA9854A210BEB640057EB6B /* SafeBrowsingWarning.h in Headers */,
                                BC2D021712AC41CB00E732A3 /* SameDocumentNavigationType.h in Headers */,
                                1AAB4A8D1296F0A20023952F /* SandboxExtension.h in Headers */,
                                E1E552C516AE065F004ED653 /* SandboxInitializationParameters.h in Headers */,
index 6b1295d..8c535c7 100644 (file)
@@ -1,3 +1,13 @@
+2018-11-14  Alex Christensen  <achristensen@webkit.org>
+
+        Add SPI to show a safe browsing warning
+        https://bugs.webkit.org/show_bug.cgi?id=191604
+
+        Reviewed by Andy Estes.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
+        (TEST):
+
 2018-11-14  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] A few drag and drop tests are crashing after r238146
index 48b99ef..0811ebc 100644 (file)
@@ -204,6 +204,33 @@ TEST(SafeBrowsing, NavigationClearsWarning)
         TestWebKitAPI::Util::spinRunLoop();
 }
 
+TEST(SafeBrowsing, ShowWarningSPI)
+{
+    __block bool completionHandlerCalled = false;
+    __block RetainPtr<NSURL> urlClicked;
+    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;
+            completionHandlerCalled = true;
+        }];
+#if !PLATFORM(MAC)
+        [[webView _safeBrowsingWarningForTesting] didMoveToWindow];
+#endif
+    };
+
+    showWarning();
+    checkTitleAndClick([webView _safeBrowsingWarningForTesting].subviews.firstObject.subviews[3], "Go Back");
+    TestWebKitAPI::Util::run(&completionHandlerCalled);
+    EXPECT_TRUE(!urlClicked);
+
+    showWarning();
+    [[webView _safeBrowsingWarningForTesting] performSelector:NSSelectorFromString(@"clickedOnLink:") withObject:[NSURL URLWithString:@"http://webkit.org/testlink"]];
+    TestWebKitAPI::Util::run(&completionHandlerCalled);
+    EXPECT_STREQ([urlClicked absoluteString].UTF8String, "http://webkit.org/testlink");
+}
+
 @interface NullLookupContext : NSObject
 @end
 @implementation NullLookupContext