- Revision
- 240570
- Author
- [email protected]
- Date
- 2019-01-28 01:41:08 -0800 (Mon, 28 Jan 2019)
Log Message
Cherry-pick r240490. rdar://problem/47586864
WKWebView.goBack should reload if there is a safe browsing warning
https://bugs.webkit.org/show_bug.cgi?id=193805
<rdar://problem/46908216>
Reviewed by Geoff Garen.
Source/WebKit:
If a WKWebView is showing a safe browsing warning and the user clicks a back button
in the app which calls WKWebView.goBack, the WKWebView is in a state where it has not navigated yet,
so actually going back will appear to the user to go back twice. We can't just do nothing because the
app is in a state where it is expecting a navigation to happen. Reloading achieves what the user expects
and makes the app work like the app expects.
* UIProcess/API/C/WKPage.cpp:
(WKPageGoBack):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView goBack]):
* UIProcess/PageClient.h:
(WebKit::PageClient::hasSafeBrowsingWarning const):
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::hasSafeBrowsingWarning const):
Tools:
* TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
(+[Simple3LookupContext sharedLookupContext]):
(-[Simple3LookupContext lookUpURL:completionHandler:]):
(-[WKWebViewGoBackNavigationDelegate webView:didFinishNavigation:]):
(TEST):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240490 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-607-branch/Source/WebKit/ChangeLog (240569 => 240570)
--- branches/safari-607-branch/Source/WebKit/ChangeLog 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Source/WebKit/ChangeLog 2019-01-28 09:41:08 UTC (rev 240570)
@@ -1,5 +1,69 @@
2019-01-28 Babak Shafiei <[email protected]>
+ Cherry-pick r240490. rdar://problem/47586864
+
+ WKWebView.goBack should reload if there is a safe browsing warning
+ https://bugs.webkit.org/show_bug.cgi?id=193805
+ <rdar://problem/46908216>
+
+ Reviewed by Geoff Garen.
+
+ Source/WebKit:
+
+ If a WKWebView is showing a safe browsing warning and the user clicks a back button
+ in the app which calls WKWebView.goBack, the WKWebView is in a state where it has not navigated yet,
+ so actually going back will appear to the user to go back twice. We can't just do nothing because the
+ app is in a state where it is expecting a navigation to happen. Reloading achieves what the user expects
+ and makes the app work like the app expects.
+
+ * UIProcess/API/C/WKPage.cpp:
+ (WKPageGoBack):
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView goBack]):
+ * UIProcess/PageClient.h:
+ (WebKit::PageClient::hasSafeBrowsingWarning const):
+ * UIProcess/mac/PageClientImplMac.h:
+ * UIProcess/mac/PageClientImplMac.mm:
+ (WebKit::PageClientImpl::hasSafeBrowsingWarning const):
+
+ Tools:
+
+ * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
+ (+[Simple3LookupContext sharedLookupContext]):
+ (-[Simple3LookupContext lookUpURL:completionHandler:]):
+ (-[WKWebViewGoBackNavigationDelegate webView:didFinishNavigation:]):
+ (TEST):
+
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240490 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-01-25 Alex Christensen <[email protected]>
+
+ WKWebView.goBack should reload if there is a safe browsing warning
+ https://bugs.webkit.org/show_bug.cgi?id=193805
+ <rdar://problem/46908216>
+
+ Reviewed by Geoff Garen.
+
+ If a WKWebView is showing a safe browsing warning and the user clicks a back button
+ in the app which calls WKWebView.goBack, the WKWebView is in a state where it has not navigated yet,
+ so actually going back will appear to the user to go back twice. We can't just do nothing because the
+ app is in a state where it is expecting a navigation to happen. Reloading achieves what the user expects
+ and makes the app work like the app expects.
+
+ * UIProcess/API/C/WKPage.cpp:
+ (WKPageGoBack):
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView goBack]):
+ * UIProcess/PageClient.h:
+ (WebKit::PageClient::hasSafeBrowsingWarning const):
+ * UIProcess/mac/PageClientImplMac.h:
+ * UIProcess/mac/PageClientImplMac.mm:
+ (WebKit::PageClientImpl::hasSafeBrowsingWarning const):
+
+2019-01-28 Babak Shafiei <[email protected]>
+
Cherry-pick r240485. rdar://problem/47586895
Regression(PSON) cross-site provisional page is not canceled if a new same-site one is started
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/C/WKPage.cpp (240569 => 240570)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/C/WKPage.cpp 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/C/WKPage.cpp 2019-01-28 09:41:08 UTC (rev 240570)
@@ -57,6 +57,7 @@
#include "NativeWebKeyboardEvent.h"
#include "NativeWebWheelEvent.h"
#include "NavigationActionData.h"
+#include "PageClient.h"
#include "PluginInformation.h"
#include "PrintInfo.h"
#include "WKAPICast.h"
@@ -321,7 +322,12 @@
void WKPageGoBack(WKPageRef pageRef)
{
- toImpl(pageRef)->goBack();
+ auto& page = *toImpl(pageRef);
+ if (page.pageClient().hasSafeBrowsingWarning()) {
+ WKPageReload(pageRef);
+ return;
+ }
+ page.goBack();
}
bool WKPageCanGoBack(WKPageRef pageRef)
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (240569 => 240570)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-01-28 09:41:08 UTC (rev 240570)
@@ -1005,6 +1005,8 @@
- (WKNavigation *)goBack
{
+ if (self._safeBrowsingWarning)
+ return [self reload];
return wrapper(_page->goBack());
}
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/PageClient.h (240569 => 240570)
--- branches/safari-607-branch/Source/WebKit/UIProcess/PageClient.h 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/PageClient.h 2019-01-28 09:41:08 UTC (rev 240570)
@@ -421,6 +421,8 @@
virtual void pinnedStateWillChange() { }
virtual void pinnedStateDidChange() { }
+ virtual bool hasSafeBrowsingWarning() const { return false; }
+
#if PLATFORM(MAC)
virtual void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) = 0;
virtual NSObject *immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult>, uint64_t, RefPtr<API::Object>) = 0;
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/mac/PageClientImplMac.h (240569 => 240570)
--- branches/safari-607-branch/Source/WebKit/UIProcess/mac/PageClientImplMac.h 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/mac/PageClientImplMac.h 2019-01-28 09:41:08 UTC (rev 240570)
@@ -107,6 +107,7 @@
void showSafeBrowsingWarning(const SafeBrowsingWarning&, CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&) override;
void clearSafeBrowsingWarning() override;
void clearSafeBrowsingWarningIfForMainFrameNavigation() override;
+ bool hasSafeBrowsingWarning() const override;
#if WK_API_ENABLED
bool showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (240569 => 240570)
--- branches/safari-607-branch/Source/WebKit/UIProcess/mac/PageClientImplMac.mm 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/mac/PageClientImplMac.mm 2019-01-28 09:41:08 UTC (rev 240570)
@@ -496,6 +496,13 @@
m_impl->showSafeBrowsingWarning(warning, WTFMove(completionHandler));
}
+bool PageClientImpl::hasSafeBrowsingWarning() const
+{
+ if (!m_impl)
+ return false;
+ return !!m_impl->safeBrowsingWarning();
+}
+
void PageClientImpl::clearSafeBrowsingWarning()
{
m_impl->clearSafeBrowsingWarning();
Modified: branches/safari-607-branch/Tools/ChangeLog (240569 => 240570)
--- branches/safari-607-branch/Tools/ChangeLog 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Tools/ChangeLog 2019-01-28 09:41:08 UTC (rev 240570)
@@ -1,5 +1,59 @@
2019-01-28 Babak Shafiei <[email protected]>
+ Cherry-pick r240490. rdar://problem/47586864
+
+ WKWebView.goBack should reload if there is a safe browsing warning
+ https://bugs.webkit.org/show_bug.cgi?id=193805
+ <rdar://problem/46908216>
+
+ Reviewed by Geoff Garen.
+
+ Source/WebKit:
+
+ If a WKWebView is showing a safe browsing warning and the user clicks a back button
+ in the app which calls WKWebView.goBack, the WKWebView is in a state where it has not navigated yet,
+ so actually going back will appear to the user to go back twice. We can't just do nothing because the
+ app is in a state where it is expecting a navigation to happen. Reloading achieves what the user expects
+ and makes the app work like the app expects.
+
+ * UIProcess/API/C/WKPage.cpp:
+ (WKPageGoBack):
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView goBack]):
+ * UIProcess/PageClient.h:
+ (WebKit::PageClient::hasSafeBrowsingWarning const):
+ * UIProcess/mac/PageClientImplMac.h:
+ * UIProcess/mac/PageClientImplMac.mm:
+ (WebKit::PageClientImpl::hasSafeBrowsingWarning const):
+
+ Tools:
+
+ * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
+ (+[Simple3LookupContext sharedLookupContext]):
+ (-[Simple3LookupContext lookUpURL:completionHandler:]):
+ (-[WKWebViewGoBackNavigationDelegate webView:didFinishNavigation:]):
+ (TEST):
+
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240490 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-01-25 Alex Christensen <[email protected]>
+
+ WKWebView.goBack should reload if there is a safe browsing warning
+ https://bugs.webkit.org/show_bug.cgi?id=193805
+ <rdar://problem/46908216>
+
+ Reviewed by Geoff Garen.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
+ (+[Simple3LookupContext sharedLookupContext]):
+ (-[Simple3LookupContext lookUpURL:completionHandler:]):
+ (-[WKWebViewGoBackNavigationDelegate webView:didFinishNavigation:]):
+ (TEST):
+
+2019-01-28 Babak Shafiei <[email protected]>
+
Cherry-pick r240485. rdar://problem/47586895
Regression(PSON) cross-site provisional page is not canceled if a new same-site one is started
Modified: branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm (240569 => 240570)
--- branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm 2019-01-28 09:41:03 UTC (rev 240569)
+++ branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm 2019-01-28 09:41:08 UTC (rev 240570)
@@ -355,6 +355,64 @@
}
}
+@interface Simple3LookupContext : NSObject
+@end
+
+@implementation Simple3LookupContext
+
++ (Simple3LookupContext *)sharedLookupContext
+{
+ static Simple3LookupContext *context = [[Simple3LookupContext alloc] init];
+ return context;
+}
+
+- (void)lookUpURL:(NSURL *)URL completionHandler:(void (^)(TestLookupResult *, NSError *))completionHandler
+{
+ BOOL phishing = NO;
+ if ([URL isEqual:resourceURL(@"simple3")])
+ phishing = YES;
+ completionHandler([TestLookupResult resultWithResults:@[[TestServiceLookupResult resultWithProvider:@"TestProvider" phishing:phishing malware:NO unwantedSoftware:NO]]], nil);
+}
+
+@end
+
+static bool navigationFinished;
+
+@interface WKWebViewGoBackNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation WKWebViewGoBackNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
+{
+ navigationFinished = true;
+}
+
+@end
+
+TEST(SafeBrowsing, WKWebViewGoBack)
+{
+ ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [Simple3LookupContext methodForSelector:@selector(sharedLookupContext)]);
+
+ auto delegate = adoptNS([WKWebViewGoBackNavigationDelegate new]);
+ auto webView = adoptNS([WKWebView new]);
+ [webView setNavigationDelegate:delegate.get()];
+ [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple")]];
+ TestWebKitAPI::Util::run(&navigationFinished);
+
+ navigationFinished = false;
+ [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple2")]];
+ TestWebKitAPI::Util::run(&navigationFinished);
+
+ navigationFinished = false;
+ [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple3")]];
+ while (![webView _safeBrowsingWarning])
+ TestWebKitAPI::Util::spinRunLoop();
+ [webView goBack];
+ TestWebKitAPI::Util::run(&navigationFinished);
+ EXPECT_TRUE([[webView URL] isEqual:resourceURL(@"simple2")]);
+}
+
@interface NullLookupContext : NSObject
@end
@implementation NullLookupContext