Title: [239408] trunk
Revision
239408
Author
achristen...@apple.com
Date
2018-12-19 16:55:10 -0800 (Wed, 19 Dec 2018)

Log Message

Navigations away from the SafeBrowsing interstitial show a flash of old content
https://bugs.webkit.org/show_bug.cgi?id=192676

Reviewed by Chris Dumez.

Source/WebKit:

When a user clicks through a safe browsing warning, do not remove the warning until content is drawn for the destination.
Otherwise, the user will confusingly see the page before the warning while the navigation happens.
We can only do this for warnings caused by main frame navigations, though.  Other warnings (such as those caused by iframes)
need to be cleared immediately, and we still need to clear the warning immediately if the user has said to go back.

This change is reflected in an updated API test.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
* UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm:
(WebKit::SafeBrowsingWarning::SafeBrowsingWarning):
* UIProcess/Cocoa/WKSafeBrowsingWarning.h:
* UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
(-[WKSafeBrowsingWarning forMainFrameNavigation]):
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::beginSafeBrowsingCheck):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::showSafeBrowsingWarning):
(WebKit::WebViewImpl::clearSafeBrowsingWarningIfForMainFrameNavigation):
* UIProcess/PageClient.h:
(WebKit::PageClient::clearSafeBrowsingWarningIfForMainFrameNavigation):
* UIProcess/SafeBrowsingWarning.h:
(WebKit::SafeBrowsingWarning::create):
(WebKit::SafeBrowsingWarning::forMainFrameNavigation const):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didReachLayoutMilestone):
(WebKit::WebPageProxy::beginSafeBrowsingCheck):
(WebKit::WebPageProxy::decidePolicyForNavigationAction):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::clearSafeBrowsingWarningIfForMainFrameNavigation):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
(safeBrowsingView):
(TEST):
(-[SafeBrowsingHelper webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (239407 => 239408)


--- trunk/Source/WebKit/ChangeLog	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/ChangeLog	2018-12-20 00:55:10 UTC (rev 239408)
@@ -1,3 +1,45 @@
+2018-12-19  Alex Christensen  <achristen...@webkit.org>
+
+        Navigations away from the SafeBrowsing interstitial show a flash of old content
+        https://bugs.webkit.org/show_bug.cgi?id=192676
+
+        Reviewed by Chris Dumez.
+
+        When a user clicks through a safe browsing warning, do not remove the warning until content is drawn for the destination.
+        Otherwise, the user will confusingly see the page before the warning while the navigation happens.
+        We can only do this for warnings caused by main frame navigations, though.  Other warnings (such as those caused by iframes)
+        need to be cleared immediately, and we still need to clear the warning immediately if the user has said to go back.
+
+        This change is reflected in an updated API test.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
+        * UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm:
+        (WebKit::SafeBrowsingWarning::SafeBrowsingWarning):
+        * UIProcess/Cocoa/WKSafeBrowsingWarning.h:
+        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
+        (-[WKSafeBrowsingWarning forMainFrameNavigation]):
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::beginSafeBrowsingCheck):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::showSafeBrowsingWarning):
+        (WebKit::WebViewImpl::clearSafeBrowsingWarningIfForMainFrameNavigation):
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::clearSafeBrowsingWarningIfForMainFrameNavigation):
+        * UIProcess/SafeBrowsingWarning.h:
+        (WebKit::SafeBrowsingWarning::create):
+        (WebKit::SafeBrowsingWarning::forMainFrameNavigation const):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didReachLayoutMilestone):
+        (WebKit::WebPageProxy::beginSafeBrowsingCheck):
+        (WebKit::WebPageProxy::decidePolicyForNavigationAction):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::clearSafeBrowsingWarningIfForMainFrameNavigation):
+
 2018-12-19  Tim Horton  <timothy_hor...@apple.com>
 
         UI process crash when focusing an editable image

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -1279,9 +1279,17 @@
 - (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&)completionHandler
 {
     _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));
+        auto strongSelf = weakSelf.get();
+        if (!strongSelf)
+            return;
+        bool navigatesMainFrame = WTF::switchOn(result,
+            [] (WebKit::ContinueUnsafeLoad continueUnsafeLoad) { return continueUnsafeLoad == WebKit::ContinueUnsafeLoad::Yes; },
+            [] (const URL&) { return true; }
+        );
+        if (navigatesMainFrame && [strongSelf->_safeBrowsingWarning forMainFrameNavigation])
+            return;
+        [std::exchange(strongSelf->_safeBrowsingWarning, nullptr) removeFromSuperview];
     }]);
     [self addSubview:_safeBrowsingWarning.get()];
 }
@@ -1291,6 +1299,12 @@
     [std::exchange(_safeBrowsingWarning, nullptr) removeFromSuperview];
 }
 
+- (void)_clearSafeBrowsingWarningIfForMainFrameNavigation
+{
+    if ([_safeBrowsingWarning forMainFrameNavigation])
+        [self _clearSafeBrowsingWarning];
+}
+
 #if ENABLE(ATTACHMENT_ELEMENT)
 
 - (void)_didInsertAttachment:(API::Attachment&)attachment withSource:(NSString *)source

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -182,6 +182,7 @@
 
 - (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&)completionHandler;
 - (void)_clearSafeBrowsingWarning;
+- (void)_clearSafeBrowsingWarningIfForMainFrameNavigation;
 
 - (std::optional<BOOL>)_resolutionForShareSheetImmediateCompletionForTesting;
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SafeBrowsingWarningCocoa.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -149,10 +149,11 @@
     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 URL& url, SSBServiceLookupResult *result)
+SafeBrowsingWarning::SafeBrowsingWarning(const URL& url, bool forMainFrameNavigation, SSBServiceLookupResult *result)
     : m_url(url)
     , m_title(safeBrowsingTitleText(result))
     , m_warning(safeBrowsingWarningText(result))
+    , m_forMainFrameNavigation(forMainFrameNavigation)
     , m_details(safeBrowsingDetailsText(url, result))
 {
 }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -61,4 +61,6 @@
 
 - (instancetype)initWithFrame:(RectType)frame safeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&)completionHandler;
 
+- (BOOL)forMainFrameNavigation;
+
 @end

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -510,6 +510,11 @@
     _completionHandler((NSURL *)link);
 }
 
+- (BOOL)forMainFrameNavigation
+{
+    return _warning->forMainFrameNavigation();
+}
+
 @end
 
 @implementation WKSafeBrowsingTextView

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -72,14 +72,14 @@
     searchItems = WebCore::loadRecentSearches(name);
 }
 
-void WebPageProxy::beginSafeBrowsingCheck(const URL& url, WebFramePolicyListenerProxy& listener)
+void WebPageProxy::beginSafeBrowsingCheck(const URL& url, bool forMainFrameNavigation, WebFramePolicyListenerProxy& listener)
 {
 #if HAVE(SAFE_BROWSING)
     SSBLookupContext *context = [SSBLookupContext sharedLookupContext];
     if (!context)
         return listener.didReceiveSafeBrowsingResults({ });
-    [context lookUpURL:url completionHandler:makeBlockPtr([listener = makeRef(listener), url = "" (SSBLookupResult *result, NSError *error) mutable {
-        RunLoop::main().dispatch([listener = WTFMove(listener), result = retainPtr(result), error = retainPtr(error), url = "" {
+    [context lookUpURL:url completionHandler:makeBlockPtr([listener = makeRef(listener), forMainFrameNavigation, url = "" (SSBLookupResult *result, NSError *error) mutable {
+        RunLoop::main().dispatch([listener = WTFMove(listener), result = retainPtr(result), error = retainPtr(error), forMainFrameNavigation, url = "" {
             if (error) {
                 listener->didReceiveSafeBrowsingResults({ });
                 return;
@@ -87,7 +87,7 @@
 
             for (SSBServiceLookupResult *lookupResult in [result serviceLookupResults]) {
                 if (lookupResult.isPhishing || lookupResult.isMalware || lookupResult.isUnwantedSoftware) {
-                    listener->didReceiveSafeBrowsingResults(SafeBrowsingWarning::create(url, lookupResult));
+                    listener->didReceiveSafeBrowsingResults(SafeBrowsingWarning::create(url, forMainFrameNavigation, lookupResult));
                     return;
                 }
             }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -229,6 +229,7 @@
 
     void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<ContinueUnsafeLoad, URL>&&)>&&);
     void clearSafeBrowsingWarning();
+    void clearSafeBrowsingWarningIfForMainFrameNavigation();
 
     WKLayoutMode layoutMode() const;
     void setLayoutMode(WKLayoutMode);

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -1622,9 +1622,16 @@
         return completionHandler(ContinueUnsafeLoad::Yes);
 
     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));
+        if (!weakThis)
+            return;
+        bool navigatesMainFrame = WTF::switchOn(result,
+            [] (ContinueUnsafeLoad continueUnsafeLoad) { return continueUnsafeLoad == ContinueUnsafeLoad::Yes; },
+            [] (const URL&) { return true; }
+        );
+        if (navigatesMainFrame && [weakThis->m_safeBrowsingWarning forMainFrameNavigation])
+            return;
+        [std::exchange(weakThis->m_safeBrowsingWarning, nullptr) removeFromSuperview];
     }]);
     [m_view addSubview:m_safeBrowsingWarning.get()];
 }
@@ -1634,6 +1641,12 @@
     [std::exchange(m_safeBrowsingWarning, nullptr) removeFromSuperview];
 }
 
+void WebViewImpl::clearSafeBrowsingWarningIfForMainFrameNavigation()
+{
+    if ([m_safeBrowsingWarning forMainFrameNavigation])
+        clearSafeBrowsingWarning();
+}
+
 bool WebViewImpl::isFocused() const
 {
     if (m_inBecomeFirstResponder)

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -218,6 +218,7 @@
 
     virtual void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<ContinueUnsafeLoad, URL>&&)>&& completionHandler) { completionHandler(ContinueUnsafeLoad::Yes); }
     virtual void clearSafeBrowsingWarning() { }
+    virtual void clearSafeBrowsingWarningIfForMainFrameNavigation() { }
     
 #if ENABLE(DRAG_SUPPORT)
 #if PLATFORM(GTK)

Modified: trunk/Source/WebKit/UIProcess/SafeBrowsingWarning.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/SafeBrowsingWarning.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/SafeBrowsingWarning.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -39,9 +39,9 @@
 class SafeBrowsingWarning : public RefCounted<SafeBrowsingWarning> {
 public:
 #if HAVE(SAFE_BROWSING)
-    static Ref<SafeBrowsingWarning> create(const URL& url, SSBServiceLookupResult *result)
+    static Ref<SafeBrowsingWarning> create(const URL& url, bool forMainFrameNavigation, SSBServiceLookupResult *result)
     {
-        return adoptRef(*new SafeBrowsingWarning(url, result));
+        return adoptRef(*new SafeBrowsingWarning(url, forMainFrameNavigation, result));
     }
 #endif
 #if PLATFORM(COCOA)
@@ -54,6 +54,7 @@
     const URL& url() const { return m_url; }
     const String& title() const { return m_title; }
     const String& warning() const { return m_warning; }
+    bool forMainFrameNavigation() const { return m_forMainFrameNavigation; }
 #if PLATFORM(COCOA)
     RetainPtr<NSAttributedString> details() const { return m_details; }
 #endif
@@ -63,7 +64,7 @@
     
 private:
 #if HAVE(SAFE_BROWSING)
-    SafeBrowsingWarning(const URL&, SSBServiceLookupResult *);
+    SafeBrowsingWarning(const URL&, bool, SSBServiceLookupResult *);
 #endif
 #if PLATFORM(COCOA)
     SafeBrowsingWarning(URL&&, String&&, String&&, RetainPtr<NSAttributedString>&&);
@@ -72,6 +73,7 @@
     URL m_url;
     String m_title;
     String m_warning;
+    bool m_forMainFrameNavigation { false };
 #if PLATFORM(COCOA)
     RetainPtr<NSAttributedString> m_details;
 #endif

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-12-20 00:55:10 UTC (rev 239408)
@@ -4195,6 +4195,9 @@
 {
     PageClientProtector protector(pageClient());
 
+    if (layoutMilestones.contains(DidFirstVisuallyNonEmptyLayout))
+        pageClient().clearSafeBrowsingWarningIfForMainFrameNavigation();
+    
     if (m_loaderClient)
         m_loaderClient->didReachLayoutMilestone(*this, layoutMilestones);
     m_navigationClient->renderingProgressDidChange(*this, layoutMilestones);
@@ -4250,7 +4253,7 @@
 }
 
 #if !PLATFORM(COCOA)
-void WebPageProxy::beginSafeBrowsingCheck(const URL&, WebFramePolicyListenerProxy& listener)
+void WebPageProxy::beginSafeBrowsingCheck(const URL&, bool, WebFramePolicyListenerProxy& listener)
 {
     listener.didReceiveSafeBrowsingResults({ });
 }
@@ -4367,7 +4370,7 @@
 
     }, shouldExpectSafeBrowsingResult));
     if (shouldExpectSafeBrowsingResult == ShouldExpectSafeBrowsingResult::Yes)
-        beginSafeBrowsingCheck(request.url(), listener);
+        beginSafeBrowsingCheck(request.url(), frame.isMainFrame(), listener);
 
     API::Navigation* mainFrameNavigation = frame.isMainFrame() ? navigation.get() : nullptr;
     WebFrameProxy* originatingFrame = m_process->webFrame(originatingFrameInfoData.frameID);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -1494,7 +1494,7 @@
     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 URL&, WebFramePolicyListenerProxy&);
+    void beginSafeBrowsingCheck(const URL&, bool, WebFramePolicyListenerProxy&);
 
     void willSubmitForm(uint64_t frameID, uint64_t sourceFrameID, const Vector<std::pair<String, String>>& textFieldValues, uint64_t listenerID, const UserData&);
         

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -117,6 +117,7 @@
 
     void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&) override;
     void clearSafeBrowsingWarning() override;
+    void clearSafeBrowsingWarningIfForMainFrameNavigation() override;
 
     void enterAcceleratedCompositingMode(const LayerTreeContext&) override;
     void exitAcceleratedCompositingMode() override;

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -485,6 +485,11 @@
     [m_webView _clearSafeBrowsingWarning];
 }
 
+void PageClientImpl::clearSafeBrowsingWarningIfForMainFrameNavigation()
+{
+    [m_webView _clearSafeBrowsingWarningIfForMainFrameNavigation];
+}
+
 void PageClientImpl::exitAcceleratedCompositingMode()
 {
     notImplemented();

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2018-12-20 00:55:10 UTC (rev 239408)
@@ -106,6 +106,7 @@
     void selectionDidChange() override;
     void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&) override;
     void clearSafeBrowsingWarning() override;
+    void clearSafeBrowsingWarningIfForMainFrameNavigation() override;
     
 #if WK_API_ENABLED
     bool showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (239407 => 239408)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -501,6 +501,11 @@
     m_impl->clearSafeBrowsingWarning();
 }
 
+void PageClientImpl::clearSafeBrowsingWarningIfForMainFrameNavigation()
+{
+    m_impl->clearSafeBrowsingWarningIfForMainFrameNavigation();
+}
+
 void PageClientImpl::setTextIndicator(Ref<TextIndicator> textIndicator, WebCore::TextIndicatorWindowLifetime lifetime)
 {
     m_impl->setTextIndicator(textIndicator.get(), lifetime);

Modified: trunk/Tools/ChangeLog (239407 => 239408)


--- trunk/Tools/ChangeLog	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Tools/ChangeLog	2018-12-20 00:55:10 UTC (rev 239408)
@@ -1,3 +1,15 @@
+2018-12-19  Alex Christensen  <achristen...@webkit.org>
+
+        Navigations away from the SafeBrowsing interstitial show a flash of old content
+        https://bugs.webkit.org/show_bug.cgi?id=192676
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
+        (safeBrowsingView):
+        (TEST):
+        (-[SafeBrowsingHelper webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]): Deleted.
+
 2018-12-19  Adrian Perez de Castro  <ape...@igalia.com>
 
         [GTK][WPE] Unify TestController::platformRunUntil() and honor condition flag

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm (239407 => 239408)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm	2018-12-20 00:54:10 UTC (rev 239407)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm	2018-12-20 00:55:10 UTC (rev 239408)
@@ -281,12 +281,11 @@
 }
 
 static Vector<URL> urls;
-static bool done;
 
-@interface SafeBrowsingHelper : NSObject<WKNavigationDelegate, WKUIDelegate>
+@interface SafeBrowsingObserver : NSObject
 @end
 
-@implementation SafeBrowsingHelper
+@implementation SafeBrowsingObserver
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context
 {
@@ -293,12 +292,6 @@
     urls.append((NSURL *)[change objectForKey:NSKeyValueChangeNewKey]);
 }
 
-- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
-{
-    done = true;
-    completionHandler();
-}
-
 @end
 
 TEST(SafeBrowsing, URLObservation)
@@ -307,15 +300,13 @@
 
     RetainPtr<NSURL> simpleURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     RetainPtr<NSURL> simple2URL = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
-    auto helper = adoptNS([SafeBrowsingHelper new]);
+    auto observer = adoptNS([SafeBrowsingObserver new]);
 
     auto webViewWithWarning = [&] () -> RetainPtr<WKWebView> {
         auto webView = adoptNS([WKWebView new]);
-        [webView setUIDelegate:helper.get()];
-        [webView setNavigationDelegate:helper.get()];
-        [webView addObserver:helper.get() forKeyPath:@"URL" options:NSKeyValueObservingOptionNew context:nil];
+        [webView addObserver:observer.get() forKeyPath:@"URL" options:NSKeyValueObservingOptionNew context:nil];
 
-        [webView loadHTMLString:@"<script>alert('loaded')</script>" baseURL:simpleURL.get()];
+        [webView loadHTMLString:@"meaningful content to be drawn" baseURL:simpleURL.get()];
         while (![webView _safeBrowsingWarning])
             TestWebKitAPI::Util::spinRunLoop();
 #if !PLATFORM(MAC)
@@ -322,10 +313,11 @@
         [[webView _safeBrowsingWarning] didMoveToWindow];
 #endif
         visitUnsafeSite([webView _safeBrowsingWarning]);
-        TestWebKitAPI::Util::run(&done);
+        EXPECT_TRUE(!![webView _safeBrowsingWarning]);
+        while ([webView _safeBrowsingWarning])
+            TestWebKitAPI::Util::spinRunLoop();
         EXPECT_FALSE(!![webView _safeBrowsingWarning]);
 
-        done = false;
         [webView evaluateJavaScript:[NSString stringWithFormat:@"window.location='%@'", simple2URL.get()] completionHandler:nil];
         while (![webView _safeBrowsingWarning])
             TestWebKitAPI::Util::spinRunLoop();
@@ -348,7 +340,7 @@
         checkURLs({ simpleURL, simple2URL });
         goBack([webView _safeBrowsingWarning]);
         checkURLs({ simpleURL, simple2URL, simpleURL });
-        [webView removeObserver:helper.get() forKeyPath:@"URL"];
+        [webView removeObserver:observer.get() forKeyPath:@"URL"];
     }
     
     urls.clear();
@@ -359,7 +351,7 @@
         visitUnsafeSite([webView _safeBrowsingWarning]);
         TestWebKitAPI::Util::spinRunLoop(5);
         checkURLs({ simpleURL, simple2URL });
-        [webView removeObserver:helper.get() forKeyPath:@"URL"];
+        [webView removeObserver:observer.get() forKeyPath:@"URL"];
     }
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to