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

Changeset 259770 in webkit


Ignore:
Timestamp:
Apr 8, 2020, 5:38:51 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

WKWebViews should behave as if they had loaded something after restoring session state
https://bugs.webkit.org/show_bug.cgi?id=210097
<rdar://problem/58778490>

Patch by Alex Christensen <achristensen@webkit.org> on 2020-04-08
Reviewed by Chris Dumez.

Source/WebKit:

Specifically, we don't want to close a WKWebView after restoring the session state into another
WKWebView into it then navigating to a phishing page. We want to be at the previous page after
the user clicks "Go back".

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::restoreFromSessionState):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:

(TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r259768 r259770  
     12020-04-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        WKWebViews should behave as if they had loaded something after restoring session state
     4        https://bugs.webkit.org/show_bug.cgi?id=210097
     5        <rdar://problem/58778490>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Specifically, we don't want to close a WKWebView after restoring the session state into another
     10        WKWebView into it then navigating to a phishing page.  We want to be at the previous page after
     11        the user clicks "Go back".
     12
     13        * UIProcess/WebPageProxy.cpp:
     14        (WebKit::WebPageProxy::restoreFromSessionState):
     15
    1162020-04-08  Kate Cheney  <katherine_cheney@apple.com>
    217
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r259731 r259770  
    51375137            }
    51385138
    5139             m_pageClient->showSafeBrowsingWarning(*safeBrowsingWarning, [protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), policyAction] (auto&& result) mutable {
     5139            m_pageClient->showSafeBrowsingWarning(*safeBrowsingWarning, [this, protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), policyAction] (auto&& result) mutable {
    51405140                switchOn(result, [&] (const URL& url) {
    51415141                    completionHandler(PolicyAction::Ignore);
    5142                     protectedThis->loadRequest({ url });
     5142                    loadRequest({ url });
    51435143                }, [&] (ContinueUnsafeLoad continueUnsafeLoad) {
    51445144                    switch (continueUnsafeLoad) {
    51455145                    case ContinueUnsafeLoad::No:
    5146                         if (!protectedThis->hasCommittedAnyProvisionalLoads())
    5147                             protectedThis->m_uiClient->close(protectedThis.ptr());
     5146                        if (!hasCommittedAnyProvisionalLoads() && !m_sessionStateWasRestoredByAPIRequest)
     5147                            m_uiClient->close(protectedThis.ptr());
    51485148                        completionHandler(PolicyAction::Ignore);
    51495149                        break;
  • trunk/Tools/ChangeLog

    r259767 r259770  
     12020-04-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        WKWebViews should behave as if they had loaded something after restoring session state
     4        https://bugs.webkit.org/show_bug.cgi?id=210097
     5        <rdar://problem/58778490>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm:
     10        (TEST):
     11
    1122020-04-08  Ross Kirsling  <ross.kirsling@sony.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SafeBrowsing.mm

    r246892 r259770  
    240240}
    241241
     242TEST(SafeBrowsing, GoBackAfterRestoreFromSessionState)
     243{
     244    auto webView1 = adoptNS([WKWebView new]);
     245    [webView1 loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
     246    [webView1 _test_waitForDidFinishNavigation];
     247    _WKSessionState *state = [webView1 _sessionState];
     248
     249    ClassMethodSwizzler swizzler(objc_getClass("SSBLookupContext"), @selector(sharedLookupContext), [TestLookupContext methodForSelector:@selector(sharedLookupContext)]);
     250
     251    auto delegate = adoptNS([SafeBrowsingNavigationDelegate new]);
     252    auto webView2 = adoptNS([WKWebView new]);
     253    [webView2 configuration].preferences.fraudulentWebsiteWarningEnabled = YES;
     254    [webView2 setNavigationDelegate:delegate.get()];
     255    [webView2 setUIDelegate:delegate.get()];
     256    [webView2 _restoreSessionState:state andNavigate:YES];
     257    EXPECT_FALSE(warningShown);
     258    while (![webView2 _safeBrowsingWarning])
     259        TestWebKitAPI::Util::spinRunLoop();
     260    EXPECT_TRUE(warningShown);
     261#if !PLATFORM(MAC)
     262    [[webView2 _safeBrowsingWarning] didMoveToWindow];
     263#endif
     264    EXPECT_FALSE(didCloseCalled);
     265    goBack([webView2 _safeBrowsingWarning]);
     266    EXPECT_FALSE(didCloseCalled);
     267    WKBackForwardList *list = [webView2 backForwardList];
     268    EXPECT_FALSE(!!list.backItem);
     269    EXPECT_FALSE(!!list.forwardItem);
     270    EXPECT_TRUE([list.currentItem.URL.path hasSuffix:@"/simple.html"]);
     271}
     272
    242273template<typename ViewType> void visitUnsafeSite(ViewType *view)
    243274{
Note: See TracChangeset for help on using the changeset viewer.