WebKit Bugzilla
Attachment 346437 Details for
Bug 188290
: Add a test for using SafeBrowsing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188290-20180802173213.patch (text/plain), 18.32 KB, created by
Alex Christensen
on 2018-08-02 17:32:14 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Alex Christensen
Created:
2018-08-02 17:32:14 PDT
Size:
18.32 KB
patch
obsolete
>Index: Source/WebKit/ChangeLog >=================================================================== >--- Source/WebKit/ChangeLog (revision 234513) >+++ Source/WebKit/ChangeLog (working copy) >@@ -1,3 +1,28 @@ >+2018-08-02 Alex Christensen <achristensen@webkit.org> >+ >+ Add SPI to test safe browsing >+ https://bugs.webkit.org/show_bug.cgi?id=188290 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * Platform/spi/Cocoa/SafeBrowsingSPI.h: >+ Replace HAVE and USE macros with their definitions so our private header checking script is happy. >+ * UIProcess/API/Cocoa/WKWebView.mm: >+ (-[WKWebView _setSafeBrowsingOverrideForTesting:]): >+ Add new SPI for testing. The WKWebView will ask the given block whether a load is considered phishing >+ instead of the SafariSafeBrowsing framework if this block is called. >+ * UIProcess/API/Cocoa/WKWebViewPrivate.h: >+ * UIProcess/Cocoa/WebPageProxyCocoa.mm: >+ (WebKit::WebPageProxy::beginSafeBrowsingCheck): >+ * UIProcess/SafeBrowsingResult.h: >+ (WebKit::SafeBrowsingResult::SafeBrowsingResult): >+ * UIProcess/WebPageProxy.cpp: >+ (WebKit::WebPageProxy::beginSafeBrowsingCheck): >+ (WebKit::WebPageProxy::decidePolicyForNavigationAction): >+ Use a CompletionHandler instead of passing the listener around to make it more conducive to the SPI which gives a block. >+ * UIProcess/WebPageProxy.h: >+ (WebKit::WebPageProxy::setSafeBrowsingOverrideForTesting): >+ > 2018-08-02 Alex Christensen <achristensen@webkit.org> > > Check with SafeBrowsing during navigation in WKWebView >Index: Source/WebKit/Platform/spi/Cocoa/SafeBrowsingSPI.h >=================================================================== >--- Source/WebKit/Platform/spi/Cocoa/SafeBrowsingSPI.h (revision 234513) >+++ Source/WebKit/Platform/spi/Cocoa/SafeBrowsingSPI.h (working copy) >@@ -25,11 +25,11 @@ > > #pragma once > >-#if HAVE(SAFE_BROWSING) >+#if ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)) && !defined(__i386__) > > #import <Foundation/Foundation.h> > >-#if USE(APPLE_INTERNAL_SDK) >+#if defined __has_include && __has_include(<SafariSafeBrowsing/SafariSafeBrowsing.h>) > > #import <SafariSafeBrowsing/SafariSafeBrowsing.h> > >Index: Source/WebKit/UIProcess/SafeBrowsingResult.h >=================================================================== >--- Source/WebKit/UIProcess/SafeBrowsingResult.h (revision 234513) >+++ Source/WebKit/UIProcess/SafeBrowsingResult.h (working copy) >@@ -35,6 +35,13 @@ class SafeBrowsingResult { > public: > #if HAVE(SAFE_BROWSING) > SafeBrowsingResult(SSBServiceLookupResult *); >+ SafeBrowsingResult(String&& provider, bool isPhishing, bool isMalware, bool isUnwantedSoftware, bool isKnownToBeUnsafe) >+ : m_provider(WTFMove(provider)) >+ , m_isPhishing(isPhishing) >+ , m_isMalware(isMalware) >+ , m_isUnwantedSoftware(isUnwantedSoftware) >+ , m_isKnownToBeUnsafe(isKnownToBeUnsafe) >+ { } > #endif > SafeBrowsingResult() = default; > >Index: Source/WebKit/UIProcess/WebPageProxy.cpp >=================================================================== >--- Source/WebKit/UIProcess/WebPageProxy.cpp (revision 234513) >+++ Source/WebKit/UIProcess/WebPageProxy.cpp (working copy) >@@ -4004,9 +4004,9 @@ void WebPageProxy::frameDidBecomeFrameSe > } > > #if !PLATFORM(COCOA) >-void WebPageProxy::beginSafeBrowsingCheck(const URL&, WebFramePolicyListenerProxy& listener) >+void WebPageProxy::beginSafeBrowsingCheck(const URL&, , CompletionHandler<void(Vector<SafeBrowsingResult>&&)>&& completionHandler) > { >- listener.didReceiveSafeBrowsingResults({ }); >+ completionHandler({ }); > } > #endif > >@@ -4095,7 +4095,9 @@ void WebPageProxy::decidePolicyForNaviga > > receivedPolicyDecision(policyAction, navigation.get(), WTFMove(data), WTFMove(sender)); > }, ShouldExpectSafeBrowsingResult::Yes)); >- beginSafeBrowsingCheck(request.url(), listener); >+ beginSafeBrowsingCheck(request.url(), [listener = listener.copyRef()] (Vector<SafeBrowsingResult>&& results) { >+ listener->didReceiveSafeBrowsingResults(WTFMove(results)); >+ }); > > API::Navigation* mainFrameNavigation = frame->isMainFrame() ? navigation.get() : nullptr; > WebFrameProxy* originatingFrame = m_process->webFrame(originatingFrameInfoData.frameID); >Index: Source/WebKit/UIProcess/WebPageProxy.h >=================================================================== >--- Source/WebKit/UIProcess/WebPageProxy.h (revision 234513) >+++ Source/WebKit/UIProcess/WebPageProxy.h (working copy) >@@ -1210,6 +1210,7 @@ public: > void setHeaderBannerHeightForTesting(int); > void setFooterBannerHeightForTesting(int); > #endif >+ void setSafeBrowsingOverrideForTesting(Function<void(const WebCore::URL&, CompletionHandler<void(Vector<SafeBrowsingResult>&&)>&&)>&& function) { m_safeBrowsingOverrideForTesting = WTFMove(function); } > > #if USE(UNIFIED_TEXT_CHECKING) > void checkTextOfParagraph(const String& text, uint64_t checkingTypes, int32_t insertionPoint, Vector<WebCore::TextCheckingResult>& results); >@@ -1428,7 +1429,7 @@ private: > void decidePolicyForNewWindowAction(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, NavigationActionData&&, WebCore::ResourceRequest&&, const String& frameName, uint64_t listenerID, const UserData&); > void decidePolicyForResponse(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, bool canShowMIMEType, uint64_t listenerID, const UserData&); > void unableToImplementPolicy(uint64_t frameID, const WebCore::ResourceError&, const UserData&); >- void beginSafeBrowsingCheck(const WebCore::URL&, WebFramePolicyListenerProxy&); >+ void beginSafeBrowsingCheck(const WebCore::URL&, CompletionHandler<void(Vector<SafeBrowsingResult>&&)>&&); > > void willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, const UserData&); > >@@ -2219,6 +2220,8 @@ private: > > RunLoop::Timer<WebPageProxy> m_resetRecentCrashCountTimer; > unsigned m_recentCrashCount { 0 }; >+ >+ Function<void(const WebCore::URL&, CompletionHandler<void(Vector<SafeBrowsingResult>&&)>&&)> m_safeBrowsingOverrideForTesting; > }; > > } // namespace WebKit >Index: Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >=================================================================== >--- Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (revision 234511) >+++ Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (working copy) >@@ -46,6 +46,7 @@ > #import "RemoteLayerTreeTransaction.h" > #import "RemoteObjectRegistry.h" > #import "RemoteObjectRegistryMessages.h" >+#import "SafeBrowsingResult.h" > #import "UIDelegate.h" > #import "UserMediaProcessManager.h" > #import "VersionChecks.h" >@@ -5864,6 +5865,20 @@ - (NSDictionary *)_contentsOfUserInterfa > #endif > } > >+- (void)_setSafeBrowsingOverrideForTesting:(void(^)(NSURL *, void (^)(BOOL)))handler >+{ >+#if HAVE(SAFE_BROWSING) >+ if (!handler) >+ return _page->setSafeBrowsingOverrideForTesting(nullptr); >+ >+ _page->setSafeBrowsingOverrideForTesting([handler = makeBlockPtr(handler)] (const WebCore::URL& url, CompletionHandler<void(Vector<WebKit::SafeBrowsingResult>&&)>&& completionHandler) { >+ handler.get()(url, BlockPtr<void(BOOL)>::fromCallable([completionHandler = WTFMove(completionHandler)] (BOOL phishing) mutable { >+ completionHandler({{ "MockSafeBrowsingProvider"_s, !!phishing, false, false, false }}); >+ }).get()); >+ }); >+#endif >+} >+ > #if PLATFORM(IOS) > - (void)_requestActivatedElementAtPosition:(CGPoint)position completionBlock:(void (^)(_WKActivatedElementInfo *))block > { >Index: Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h >=================================================================== >--- Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (revision 234511) >+++ Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (working copy) >@@ -96,6 +96,7 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEd > > #endif > >+@class SSBLookupResult; > @class WKBrowsingContextHandle; > @class _WKApplicationManifest; > @class _WKFrameHandle; >@@ -465,6 +466,7 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEd > - (BOOL)_beginBackSwipeForTesting; > - (BOOL)_completeBackSwipeForTesting; > - (void)_setDefersLoadingForTesting:(BOOL)defersLoading; >+- (void)_setSafeBrowsingOverrideForTesting:(void(^)(NSURL *, void (^)(BOOL)))handler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > > @end > >Index: Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm >=================================================================== >--- Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (revision 234513) >+++ Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (working copy) >@@ -71,26 +71,27 @@ void WebPageProxy::loadRecentSearches(co > searchItems = WebCore::loadRecentSearches(name); > } > >-void WebPageProxy::beginSafeBrowsingCheck(const URL& url, WebFramePolicyListenerProxy& listener) >+void WebPageProxy::beginSafeBrowsingCheck(const URL& url, CompletionHandler<void(Vector<SafeBrowsingResult>&&)>&& completionHandler) > { > #if HAVE(SAFE_BROWSING) >- [[SSBLookupContext sharedLookupContext] lookUpURL:url completionHandler:BlockPtr<void(SSBLookupResult *, NSError *)>::fromCallable([listener = makeRef(listener)] (SSBLookupResult *result, NSError *error) mutable { >- RunLoop::main().dispatch([listener = WTFMove(listener), result = retainPtr(result), error = retainPtr(error)] { >- if (error) { >- listener->didReceiveSafeBrowsingResults({ }); >- return; >- } >+ if (m_safeBrowsingOverrideForTesting) >+ return m_safeBrowsingOverrideForTesting(url, WTFMove(completionHandler)); >+ >+ [[SSBLookupContext sharedLookupContext] lookUpURL:url completionHandler:BlockPtr<void(SSBLookupResult *, NSError *)>::fromCallable([completionHandler = WTFMove(completionHandler)] (SSBLookupResult *result, NSError *error) mutable { >+ RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), result = retainPtr(result), error = retainPtr(error)] () mutable { >+ if (error) >+ return completionHandler({ }); > > NSArray<SSBServiceLookupResult *> *results = [result serviceLookupResults]; > Vector<SafeBrowsingResult> resultsVector; > resultsVector.reserveInitialCapacity([results count]); > for (SSBServiceLookupResult *result in results) > resultsVector.uncheckedAppend({ result }); >- listener->didReceiveSafeBrowsingResults(WTFMove(resultsVector)); >+ completionHandler(WTFMove(resultsVector)); > }); > }).get()]; > #else >- listener.didReceiveSafeBrowsingResults({ }); >+ completionHandler({ }); > #endif > } > >Index: Tools/ChangeLog >=================================================================== >--- Tools/ChangeLog (revision 234528) >+++ Tools/ChangeLog (working copy) >@@ -1,3 +1,19 @@ >+2018-08-02 Alex Christensen <achristensen@webkit.org> >+ >+ Add SPI to test safe browsing >+ https://bugs.webkit.org/show_bug.cgi?id=188290 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add a test that exercises this new SPI. Safe browsing results currently >+ have no effect (see the FIXME added in r234513) but when they do, I'll use >+ this test to verify their behavior. >+ >+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: >+ * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm: Added. >+ (-[SafeBrowsingDelegate webView:didFinishNavigation:]): >+ (TestWebKitAPI::TEST): >+ > 2018-08-02 Nan Wang <n_wang@apple.com> > > AX: [iOS] add support to return the attributed string under the element >Index: Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >=================================================================== >--- Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (revision 234511) >+++ Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (working copy) >@@ -282,6 +282,7 @@ > 5C9E59431D3EB5AC00E3C62E /* ApplicationCache.db-wal in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5C9E59401D3EB1DE00E3C62E /* ApplicationCache.db-wal */; }; > 5CA1DEC81F71F70100E71BD3 /* HTTPHeaderField.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CA1DEC71F71F40700E71BD3 /* HTTPHeaderField.cpp */; }; > 5CA1DED91F74A91A00E71BD3 /* ContentRuleListNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CA1DED81F74A87100E71BD3 /* ContentRuleListNotification.mm */; }; >+ 5CA985532113CF780057EB6B /* SafeBrowsing.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CA985512113CB8C0057EB6B /* SafeBrowsing.mm */; }; > 5CAE463820193B6A0051610F /* NetworkProcessCrashNonPersistentDataStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CAE4637201937CD0051610F /* NetworkProcessCrashNonPersistentDataStore.mm */; }; > 5CB18BA81F5645E300EE23C4 /* ClickAutoFillButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB18BA71F5645B200EE23C4 /* ClickAutoFillButton.mm */; }; > 5CB3CE391FA1697F00C3A2D6 /* WKWebViewConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB3CE381FA1691700C3A2D6 /* WKWebViewConfiguration.mm */; }; >@@ -1551,6 +1552,7 @@ > 5C9E59401D3EB1DE00E3C62E /* ApplicationCache.db-wal */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ApplicationCache.db-wal"; sourceTree = "<group>"; }; > 5CA1DEC71F71F40700E71BD3 /* HTTPHeaderField.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPHeaderField.cpp; sourceTree = "<group>"; }; > 5CA1DED81F74A87100E71BD3 /* ContentRuleListNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentRuleListNotification.mm; sourceTree = "<group>"; }; >+ 5CA985512113CB8C0057EB6B /* SafeBrowsing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SafeBrowsing.mm; sourceTree = "<group>"; }; > 5CAE4637201937CD0051610F /* NetworkProcessCrashNonPersistentDataStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkProcessCrashNonPersistentDataStore.mm; sourceTree = "<group>"; }; > 5CB18BA71F5645B200EE23C4 /* ClickAutoFillButton.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ClickAutoFillButton.mm; sourceTree = "<group>"; }; > 5CB3CE381FA1691700C3A2D6 /* WKWebViewConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewConfiguration.mm; sourceTree = "<group>"; }; >@@ -2344,6 +2346,7 @@ > 51C8E1A41F26AC5400BF731B /* ResourceLoadStatistics.mm */, > A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */, > F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */, >+ 5CA985512113CB8C0057EB6B /* SafeBrowsing.mm */, > CE0947362063223B003C9BA0 /* SchemeRegistry.mm */, > 51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */, > 37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */, >@@ -3871,6 +3874,7 @@ > F418BE151F71B7DC001970E6 /* RoundedRectTests.cpp in Sources */, > A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */, > F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */, >+ 5CA985532113CF780057EB6B /* SafeBrowsing.mm in Sources */, > CDCFA7AA1E45183200C2433D /* SampleMap.cpp in Sources */, > CE0947372063223B003C9BA0 /* SchemeRegistry.mm in Sources */, > 7CCE7F121A411AE600447C4C /* ScrollPinningBehaviors.cpp in Sources */, >Index: Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm >=================================================================== >--- Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm (nonexistent) >+++ Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm (working copy) >@@ -0,0 +1,66 @@ >+/* >+ * 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" >+ >+#if WK_API_ENABLED && ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)) && !defined(__i386__) >+ >+#import "PlatformUtilities.h" >+#import <WebKit/WKNavigationDelegate.h> >+#import <WebKit/WKWebViewPrivate.h> >+#import <wtf/RetainPtr.h> >+ >+static bool done; >+ >+@interface SafeBrowsingDelegate : NSObject <WKNavigationDelegate> >+@end >+ >+@implementation SafeBrowsingDelegate >+ >+- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation >+{ >+ done = true; >+} >+ >+@end >+ >+namespace TestWebKitAPI { >+ >+TEST(WebKit, SafeBrowsing) >+{ >+ auto webView = adoptNS([[WKWebView alloc] init]); >+ [webView _setSafeBrowsingOverrideForTesting:^(NSURL *url, void (^isPhishing)(BOOL)) { >+ isPhishing(YES); >+ }]; >+ [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]]; >+ >+ // FIXME: Check that the loading happens as expected once we do something with safe browsing results. >+ >+ TestWebKitAPI::Util::run(&done); >+} >+ >+} // namespace TestWebKitAPI >+ >+#endif // WK_API_ENABLED
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188290
:
346437
|
346476
|
346501
|
346506
|
346739