Changeset 240490 in webkit


Ignore:
Timestamp:
Jan 25, 2019 11:42:27 AM (5 years ago)
Author:
achristensen@apple.com
Message:

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):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r240485 r240490  
     12019-01-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        WKWebView.goBack should reload if there is a safe browsing warning
     4        https://bugs.webkit.org/show_bug.cgi?id=193805
     5        <rdar://problem/46908216>
     6
     7        Reviewed by Geoff Garen.
     8
     9        If a WKWebView is showing a safe browsing warning and the user clicks a back button
     10        in the app which calls WKWebView.goBack, the WKWebView is in a state where it has not navigated yet,
     11        so actually going back will appear to the user to go back twice.  We can't just do nothing because the
     12        app is in a state where it is expecting a navigation to happen.  Reloading achieves what the user expects
     13        and makes the app work like the app expects.
     14
     15        * UIProcess/API/C/WKPage.cpp:
     16        (WKPageGoBack):
     17        * UIProcess/API/Cocoa/WKWebView.mm:
     18        (-[WKWebView goBack]):
     19        * UIProcess/PageClient.h:
     20        (WebKit::PageClient::hasSafeBrowsingWarning const):
     21        * UIProcess/mac/PageClientImplMac.h:
     22        * UIProcess/mac/PageClientImplMac.mm:
     23        (WebKit::PageClientImpl::hasSafeBrowsingWarning const):
     24
    1252019-01-25  Chris Dumez  <cdumez@apple.com>
    226
  • trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp

    r240100 r240490  
    5858#include "NativeWebWheelEvent.h"
    5959#include "NavigationActionData.h"
     60#include "PageClient.h"
    6061#include "PluginInformation.h"
    6162#include "PrintInfo.h"
     
    321322void WKPageGoBack(WKPageRef pageRef)
    322323{
    323     toImpl(pageRef)->goBack();
     324    auto& page = *toImpl(pageRef);
     325    if (page.pageClient().hasSafeBrowsingWarning()) {
     326        WKPageReload(pageRef);
     327        return;
     328    }
     329    page.goBack();
    324330}
    325331
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r240466 r240490  
    10091009- (WKNavigation *)goBack
    10101010{
     1011    if (self._safeBrowsingWarning)
     1012        return [self reload];
    10111013    return wrapper(_page->goBack());
    10121014}
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r240199 r240490  
    425425    virtual void pinnedStateDidChange() { }
    426426
     427    virtual bool hasSafeBrowsingWarning() const { return false; }
     428   
    427429#if PLATFORM(MAC)
    428430    virtual void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) = 0;
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h

    r240046 r240490  
    108108    void clearSafeBrowsingWarning() override;
    109109    void clearSafeBrowsingWarningIfForMainFrameNavigation() override;
     110    bool hasSafeBrowsingWarning() const override;
    110111   
    111112#if WK_API_ENABLED
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm

    r240046 r240490  
    497497}
    498498
     499bool PageClientImpl::hasSafeBrowsingWarning() const
     500{
     501    if (!m_impl)
     502        return false;
     503    return !!m_impl->safeBrowsingWarning();
     504}
     505
    499506void PageClientImpl::clearSafeBrowsingWarning()
    500507{
  • trunk/Tools/ChangeLog

    r240485 r240490  
     12019-01-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        WKWebView.goBack should reload if there is a safe browsing warning
     4        https://bugs.webkit.org/show_bug.cgi?id=193805
     5        <rdar://problem/46908216>
     6
     7        Reviewed by Geoff Garen.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
     10        (+[Simple3LookupContext sharedLookupContext]):
     11        (-[Simple3LookupContext lookUpURL:completionHandler:]):
     12        (-[WKWebViewGoBackNavigationDelegate webView:didFinishNavigation:]):
     13        (TEST):
     14
    1152019-01-25  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

    r239408 r240490  
    356356}
    357357
     358@interface Simple3LookupContext : NSObject
     359@end
     360
     361@implementation Simple3LookupContext
     362
     363+ (Simple3LookupContext *)sharedLookupContext
     364{
     365    static Simple3LookupContext *context = [[Simple3LookupContext alloc] init];
     366    return context;
     367}
     368
     369- (void)lookUpURL:(NSURL *)URL completionHandler:(void (^)(TestLookupResult *, NSError *))completionHandler
     370{
     371    BOOL phishing = NO;
     372    if ([URL isEqual:resourceURL(@"simple3")])
     373        phishing = YES;
     374    completionHandler([TestLookupResult resultWithResults:@[[TestServiceLookupResult resultWithProvider:@"TestProvider" phishing:phishing malware:NO unwantedSoftware:NO]]], nil);
     375}
     376
     377@end
     378
     379static bool navigationFinished;
     380
     381@interface WKWebViewGoBackNavigationDelegate : NSObject <WKNavigationDelegate>
     382@end
     383
     384@implementation WKWebViewGoBackNavigationDelegate
     385
     386- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
     387{
     388    navigationFinished = true;
     389}
     390
     391@end
     392
     393TEST(SafeBrowsing, WKWebViewGoBack)
     394{
     395    ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [Simple3LookupContext methodForSelector:@selector(sharedLookupContext)]);
     396   
     397    auto delegate = adoptNS([WKWebViewGoBackNavigationDelegate new]);
     398    auto webView = adoptNS([WKWebView new]);
     399    [webView setNavigationDelegate:delegate.get()];
     400    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple")]];
     401    TestWebKitAPI::Util::run(&navigationFinished);
     402
     403    navigationFinished = false;
     404    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple2")]];
     405    TestWebKitAPI::Util::run(&navigationFinished);
     406
     407    navigationFinished = false;
     408    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple3")]];
     409    while (![webView _safeBrowsingWarning])
     410        TestWebKitAPI::Util::spinRunLoop();
     411    [webView goBack];
     412    TestWebKitAPI::Util::run(&navigationFinished);
     413    EXPECT_TRUE([[webView URL] isEqual:resourceURL(@"simple2")]);
     414}
     415
    358416@interface NullLookupContext : NSObject
    359417@end
Note: See TracChangeset for help on using the changeset viewer.