⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 244089 in webkit


Ignore:
Timestamp:
Apr 9, 2019, 12:07:55 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Clicking "Go Back" from a safe browsing warning from an iframe should navigate the WKWebView back to the previous page
https://bugs.webkit.org/show_bug.cgi?id=196665
<rdar://45115669>

Patch by Alex Christensen <achristensen@webkit.org> on 2019-04-09
Reviewed by Geoff Garen.

Source/WebKit:

It is insufficient to just not navigate the subframe. We must leave the page that contained it.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _showSafeBrowsingWarning:completionHandler:]):

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::showSafeBrowsingWarning):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:

(goBack):
(+[SimpleLookupContext sharedLookupContext]):
(-[SimpleLookupContext lookUpURL:completionHandler:]):
(TEST):
(+[Simple3LookupContext sharedLookupContext]): Deleted.
(-[Simple3LookupContext lookUpURL:completionHandler:]): Deleted.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244086 r244089  
     12019-04-09  Alex Christensen  <achristensen@webkit.org>
     2
     3        Clicking "Go Back" from a safe browsing warning from an iframe should navigate the WKWebView back to the previous page
     4        https://bugs.webkit.org/show_bug.cgi?id=196665
     5        <rdar://45115669>
     6
     7        Reviewed by Geoff Garen.
     8
     9        It is insufficient to just not navigate the subframe.  We must leave the page that contained it.
     10
     11        * UIProcess/API/Cocoa/WKWebView.mm:
     12        (-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
     13        * UIProcess/Cocoa/WebViewImpl.mm:
     14        (WebKit::WebViewImpl::showSafeBrowsingWarning):
     15
    1162019-04-09  John Wilander  <wilander@apple.com>
    217
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r243969 r244089  
    13561356        if (!strongSelf)
    13571357            return;
    1358         bool navigatesMainFrame = WTF::switchOn(result,
     1358        bool navigatesFrame = WTF::switchOn(result,
    13591359            [] (WebKit::ContinueUnsafeLoad continueUnsafeLoad) { return continueUnsafeLoad == WebKit::ContinueUnsafeLoad::Yes; },
    13601360            [] (const URL&) { return true; }
    13611361        );
    1362         if (navigatesMainFrame && [strongSelf->_safeBrowsingWarning forMainFrameNavigation])
     1362        bool forMainFrameNavigation = [strongSelf->_safeBrowsingWarning forMainFrameNavigation];
     1363        if (navigatesFrame && forMainFrameNavigation) {
     1364            // The safe browsing warning will be hidden once the next page is shown.
    13631365            return;
     1366        }
     1367        if (!navigatesFrame && strongSelf->_safeBrowsingWarning && !forMainFrameNavigation) {
     1368            strongSelf->_page->goBack();
     1369            return;
     1370        }
    13641371        [std::exchange(strongSelf->_safeBrowsingWarning, nullptr) removeFromSuperview];
    13651372    }]);
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r243969 r244089  
    15881588        if (!weakThis)
    15891589            return;
    1590         bool navigatesMainFrame = WTF::switchOn(result,
     1590        bool navigatesFrame = WTF::switchOn(result,
    15911591            [] (ContinueUnsafeLoad continueUnsafeLoad) { return continueUnsafeLoad == ContinueUnsafeLoad::Yes; },
    15921592            [] (const URL&) { return true; }
    15931593        );
    1594         if (navigatesMainFrame && [weakThis->m_safeBrowsingWarning forMainFrameNavigation])
     1594        bool forMainFrameNavigation = [weakThis->m_safeBrowsingWarning forMainFrameNavigation];
     1595        if (navigatesFrame && forMainFrameNavigation) {
     1596            // The safe browsing warning will be hidden once the next page is shown.
    15951597            return;
     1598        }
     1599        if (!navigatesFrame && weakThis->m_safeBrowsingWarning && !forMainFrameNavigation) {
     1600            weakThis->m_page->goBack();
     1601            return;
     1602        }
    15961603        [std::exchange(weakThis->m_safeBrowsingWarning, nullptr) removeFromSuperview];
    15971604    }]);
  • trunk/Tools/ChangeLog

    r244086 r244089  
     12019-04-09  Alex Christensen  <achristensen@webkit.org>
     2
     3        Clicking "Go Back" from a safe browsing warning from an iframe should navigate the WKWebView back to the previous page
     4        https://bugs.webkit.org/show_bug.cgi?id=196665
     5        <rdar://45115669>
     6
     7        Reviewed by Geoff Garen.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
     10        (goBack):
     11        (+[SimpleLookupContext sharedLookupContext]):
     12        (-[SimpleLookupContext lookUpURL:completionHandler:]):
     13        (TEST):
     14        (+[Simple3LookupContext sharedLookupContext]): Deleted.
     15        (-[Simple3LookupContext lookUpURL:completionHandler:]): Deleted.
     16
    1172019-04-09  John Wilander  <wilander@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

    r243969 r244089  
    221221#endif
    222222
    223 template<typename ViewType> void goBack(ViewType *view)
     223template<typename ViewType> void goBack(ViewType *view, bool mainFrame = true)
    224224{
    225225    WKWebView *webView = (WKWebView *)view.superview;
    226226    auto box = view.subviews.firstObject;
    227227    checkTitleAndClick(box.subviews[3], "Go Back");
    228     EXPECT_EQ([webView _safeBrowsingWarning], nil);
     228    if (mainFrame)
     229        EXPECT_EQ([webView _safeBrowsingWarning], nil);
     230    else
     231        EXPECT_NE([webView _safeBrowsingWarning], nil);
    229232}
    230233
     
    369372}
    370373
    371 @interface Simple3LookupContext : NSObject
    372 @end
    373 
    374 @implementation Simple3LookupContext
    375 
    376 + (Simple3LookupContext *)sharedLookupContext
    377 {
    378     static Simple3LookupContext *context = [[Simple3LookupContext alloc] init];
     374static RetainPtr<NSString> phishingResourceName;
     375
     376@interface SimpleLookupContext : NSObject
     377@end
     378
     379@implementation SimpleLookupContext
     380
     381+ (SimpleLookupContext *)sharedLookupContext
     382{
     383    static SimpleLookupContext *context = [[SimpleLookupContext alloc] init];
    379384    return context;
    380385}
     
    383388{
    384389    BOOL phishing = NO;
    385     if ([URL isEqual:resourceURL(@"simple3")])
     390    if ([URL isEqual:resourceURL(phishingResourceName.get())])
    386391        phishing = YES;
    387392    completionHandler([TestLookupResult resultWithResults:@[[TestServiceLookupResult resultWithProvider:@"TestProvider" phishing:phishing malware:NO unwantedSoftware:NO]]], nil);
     
    406411TEST(SafeBrowsing, WKWebViewGoBack)
    407412{
    408     ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [Simple3LookupContext methodForSelector:@selector(sharedLookupContext)]);
     413    phishingResourceName = @"simple3";
     414    ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [SimpleLookupContext methodForSelector:@selector(sharedLookupContext)]);
    409415   
    410416    auto delegate = adoptNS([WKWebViewGoBackNavigationDelegate new]);
     
    428434}
    429435
     436TEST(SafeBrowsing, WKWebViewGoBackIFrame)
     437{
     438    phishingResourceName = @"simple";
     439    ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [SimpleLookupContext methodForSelector:@selector(sharedLookupContext)]);
     440   
     441    auto delegate = adoptNS([WKWebViewGoBackNavigationDelegate new]);
     442    auto webView = adoptNS([WKWebView new]);
     443    [webView configuration].preferences._safeBrowsingEnabled = YES;
     444    [webView setNavigationDelegate:delegate.get()];
     445    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple2")]];
     446    TestWebKitAPI::Util::run(&navigationFinished);
     447
     448    [webView loadRequest:[NSURLRequest requestWithURL:resourceURL(@"simple-iframe")]];
     449    while (![webView _safeBrowsingWarning])
     450        TestWebKitAPI::Util::spinRunLoop();
     451#if !PLATFORM(MAC)
     452    [[webView _safeBrowsingWarning] didMoveToWindow];
     453#endif
     454    navigationFinished = false;
     455    goBack([webView _safeBrowsingWarning], false);
     456    TestWebKitAPI::Util::run(&navigationFinished);
     457    EXPECT_TRUE([[webView URL] isEqual:resourceURL(@"simple2")]);
     458}
     459
    430460@interface NullLookupContext : NSObject
    431461@end
Note: See TracChangeset for help on using the changeset viewer.