Title: [281817] trunk
Revision
281817
Author
[email protected]
Date
2021-08-31 13:26:48 -0700 (Tue, 31 Aug 2021)

Log Message

Loads after session restore marked app initiated in Safari
https://bugs.webkit.org/show_bug.cgi?id=229721
<rdar://problem/82084236>

Reviewed by Brent Fulgham.

Source/WebCore:

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadDifferentDocumentItem):
Set the proper app initiated value when creating a new request.

Source/WebKit:

Offer a way to set the app initiated value when restoring a session.

* Shared/SessionState.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _restoreSessionState:andNavigate:]):
* UIProcess/API/Cocoa/_WKSessionState.h:
* UIProcess/API/Cocoa/_WKSessionState.mm:
(-[_WKSessionState _sessionStateWithAppInitiatedValue]):
* UIProcess/API/Cocoa/_WKSessionStateInternal.h:
* UIProcess/ProvisionalPageProxy.cpp:
(WebKit::ProvisionalPageProxy::goToBackForwardItem):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::launchProcessForReload):
(WebKit::WebPageProxy::goToBackForwardItem):
(WebKit::WebPageProxy::restoreFromSessionState):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::goToBackForwardItem):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

API test coverage.

* TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281816 => 281817)


--- trunk/Source/WebCore/ChangeLog	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebCore/ChangeLog	2021-08-31 20:26:48 UTC (rev 281817)
@@ -1,3 +1,15 @@
+2021-08-31  Kate Cheney  <[email protected]>
+
+        Loads after session restore marked app initiated in Safari
+        https://bugs.webkit.org/show_bug.cgi?id=229721
+        <rdar://problem/82084236>
+
+        Reviewed by Brent Fulgham.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::loadDifferentDocumentItem):
+        Set the proper app initiated value when creating a new request.
+
 2021-08-31  Antti Koivisto  <[email protected]>
 
         REGRESSION (r272900): wpt.fyi loading performance is very slow (regressed, and slower than other browsers)

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (281816 => 281817)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2021-08-31 20:26:48 UTC (rev 281817)
@@ -3804,6 +3804,9 @@
     bool isFormSubmission = false;
     Event* event = nullptr;
 
+    if (auto* documentLoader = m_frame.mainFrame().loader().documentLoader())
+        request.setIsAppInitiated(documentLoader->lastNavigationWasAppInitiated());
+
     // If this was a repost that failed the page cache, we might try to repost the form.
     NavigationAction action;
     if (formData) {

Modified: trunk/Source/WebKit/ChangeLog (281816 => 281817)


--- trunk/Source/WebKit/ChangeLog	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/ChangeLog	2021-08-31 20:26:48 UTC (rev 281817)
@@ -1,3 +1,32 @@
+2021-08-31  Kate Cheney  <[email protected]>
+
+        Loads after session restore marked app initiated in Safari
+        https://bugs.webkit.org/show_bug.cgi?id=229721
+        <rdar://problem/82084236>
+
+        Reviewed by Brent Fulgham.
+
+        Offer a way to set the app initiated value when restoring a session.
+
+        * Shared/SessionState.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _restoreSessionState:andNavigate:]):
+        * UIProcess/API/Cocoa/_WKSessionState.h:
+        * UIProcess/API/Cocoa/_WKSessionState.mm:
+        (-[_WKSessionState _sessionStateWithAppInitiatedValue]):
+        * UIProcess/API/Cocoa/_WKSessionStateInternal.h:
+        * UIProcess/ProvisionalPageProxy.cpp:
+        (WebKit::ProvisionalPageProxy::goToBackForwardItem):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::launchProcessForReload):
+        (WebKit::WebPageProxy::goToBackForwardItem):
+        (WebKit::WebPageProxy::restoreFromSessionState):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::goToBackForwardItem):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2021-08-31  Carlos Garcia Campos  <[email protected]>
 
         [SOUP] Assertion in startObservingCookieChanges()

Modified: trunk/Source/WebKit/Shared/SessionState.h (281816 => 281817)


--- trunk/Source/WebKit/Shared/SessionState.h	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/Shared/SessionState.h	2021-08-31 20:26:48 UTC (rev 281817)
@@ -158,6 +158,7 @@
     BackForwardListState backForwardListState;
     uint64_t renderTreeSize;
     URL provisionalURL;
+    bool isAppInitiated { true };
 };
 
 } // namespace WebKit

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-08-31 20:26:48 UTC (rev 281817)
@@ -2641,7 +2641,7 @@
 - (WKNavigation *)_restoreSessionState:(_WKSessionState *)sessionState andNavigate:(BOOL)navigate
 {
     THROW_IF_SUSPENDED;
-    return wrapper(_page->restoreFromSessionState(sessionState ? sessionState->_sessionState : WebKit::SessionState { }, navigate));
+    return wrapper(_page->restoreFromSessionState(sessionState ? sessionState._sessionStateWithAppInitiatedValue : WebKit::SessionState { }, navigate));
 }
 
 - (void)_close

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionState.h (281816 => 281817)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionState.h	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionState.h	2021-08-31 20:26:48 UTC (rev 281817)
@@ -33,5 +33,6 @@
 - (instancetype)initWithData:(NSData *)data;
 
 @property (nonatomic, readonly, copy) NSData *data;
+@property (nonatomic) BOOL isAppInitiated;
 
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionState.mm (281816 => 281817)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionState.mm	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionState.mm	2021-08-31 20:26:48 UTC (rev 281817)
@@ -58,4 +58,10 @@
     return WebKit::encodeSessionState(_sessionState).autorelease();
 }
 
+- (WebKit::SessionState)_sessionStateWithAppInitiatedValue
+{
+    _sessionState.isAppInitiated = _isAppInitiated;
+    return _sessionState;
+}
+
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionStateInternal.h (281816 => 281817)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionStateInternal.h	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKSessionStateInternal.h	2021-08-31 20:26:48 UTC (rev 281817)
@@ -32,6 +32,7 @@
     WebKit::SessionState _sessionState;
 }
 
+- (WebKit::SessionState)_sessionStateWithAppInitiatedValue;
 - (instancetype)_initWithSessionState:(WebKit::SessionState)sessionState;
 
 @end

Modified: trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp (281816 => 281817)


--- trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp	2021-08-31 20:26:48 UTC (rev 281817)
@@ -202,7 +202,7 @@
         websitePoliciesData = websitePolicies->data();
     
     send(Messages::WebPage::UpdateBackForwardListForReattach(WTFMove(itemStates)));
-    send(Messages::WebPage::GoToBackForwardItem(navigation.navigationID(), item.itemID(), *navigation.backForwardFrameLoadType(), WebCore::ShouldTreatAsContinuingLoad::YesAfterNavigationPolicyDecision, WTFMove(websitePoliciesData)));
+    send(Messages::WebPage::GoToBackForwardItem(navigation.navigationID(), item.itemID(), *navigation.backForwardFrameLoadType(), WebCore::ShouldTreatAsContinuingLoad::YesAfterNavigationPolicyDecision, WTFMove(websitePoliciesData), m_page.lastNavigationWasAppInitiated()));
     m_process->startResponsivenessTimer();
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (281816 => 281817)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-08-31 20:26:48 UTC (rev 281817)
@@ -1084,7 +1084,7 @@
     }
 
     // We allow stale content when reloading a WebProcess that's been killed or crashed.
-    send(Messages::WebPage::GoToBackForwardItem(navigation->navigationID(), m_backForwardList->currentItem()->itemID(), FrameLoadType::IndexedBackForward, ShouldTreatAsContinuingLoad::No, std::nullopt));
+    send(Messages::WebPage::GoToBackForwardItem(navigation->navigationID(), m_backForwardList->currentItem()->itemID(), FrameLoadType::IndexedBackForward, ShouldTreatAsContinuingLoad::No, std::nullopt, m_lastNavigationWasAppInitiated));
     m_process->startResponsivenessTimer();
 
     return navigation;
@@ -1815,7 +1815,7 @@
     auto transaction = m_pageLoadState.transaction();
     m_pageLoadState.setPendingAPIRequest(transaction, { navigation ? navigation->navigationID() : 0, item.url() });
 
-    send(Messages::WebPage::GoToBackForwardItem(navigation ? navigation->navigationID() : 0, item.itemID(), frameLoadType, ShouldTreatAsContinuingLoad::No, std::nullopt));
+    send(Messages::WebPage::GoToBackForwardItem(navigation ? navigation->navigationID() : 0, item.itemID(), frameLoadType, ShouldTreatAsContinuingLoad::No, std::nullopt, m_lastNavigationWasAppInitiated));
     m_process->startResponsivenessTimer();
 
     return navigation;
@@ -3822,6 +3822,7 @@
 {
     WEBPAGEPROXY_RELEASE_LOG(Loading, "restoreFromSessionState:");
 
+    m_lastNavigationWasAppInitiated = sessionState.isAppInitiated;
     m_sessionRestorationRenderTreeSize = 0;
     m_hitRenderTreeSizeThreshold = false;
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (281816 => 281817)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-08-31 20:26:48 UTC (rev 281817)
@@ -1949,6 +1949,8 @@
     void createMediaSessionCoordinator(Ref<MediaSessionCoordinatorProxyPrivate>&&, CompletionHandler<void(bool)>&&);
 #endif
 
+    bool lastNavigationWasAppInitiated() const { return m_lastNavigationWasAppInitiated; }
+
 #if PLATFORM(COCOA)
     void setLastNavigationWasAppInitiated(WebCore::ResourceRequest&);
     void lastNavigationWasAppInitiated(CompletionHandler<void(bool)>&&);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (281816 => 281817)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-08-31 20:26:48 UTC (rev 281817)
@@ -1865,10 +1865,12 @@
     }
 }
 
-void WebPage::goToBackForwardItem(uint64_t navigationID, const BackForwardItemIdentifier& backForwardItemID, FrameLoadType backForwardType, ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad, std::optional<WebsitePoliciesData>&& websitePolicies)
+void WebPage::goToBackForwardItem(uint64_t navigationID, const BackForwardItemIdentifier& backForwardItemID, FrameLoadType backForwardType, ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad, std::optional<WebsitePoliciesData>&& websitePolicies, bool lastNavigationWasAppInitiated)
 {
     SendStopResponsivenessTimer stopper;
 
+    m_lastNavigationWasAppInitiated = lastNavigationWasAppInitiated;
+
     ASSERT(isBackForwardLoadType(backForwardType));
 
     HistoryItem* item = WebBackForwardListProxy::itemForID(backForwardItemID);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (281816 => 281817)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-08-31 20:26:48 UTC (rev 281817)
@@ -1588,7 +1588,7 @@
     void navigateToPDFLinkWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint);
     void getPDFFirstPageSize(WebCore::FrameIdentifier, CompletionHandler<void(WebCore::FloatSize)>&&);
     void reload(uint64_t navigationID, uint32_t reloadOptions, SandboxExtension::Handle&&);
-    void goToBackForwardItem(uint64_t navigationID, const WebCore::BackForwardItemIdentifier&, WebCore::FrameLoadType, WebCore::ShouldTreatAsContinuingLoad, std::optional<WebsitePoliciesData>&&);
+    void goToBackForwardItem(uint64_t navigationID, const WebCore::BackForwardItemIdentifier&, WebCore::FrameLoadType, WebCore::ShouldTreatAsContinuingLoad, std::optional<WebsitePoliciesData>&&, bool lastNavigationWasAppInitiated);
     void tryRestoreScrollPosition();
     void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&, CompletionHandler<void()>&&);
     void updateIsInWindow(bool isInitialState = false);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (281816 => 281817)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-08-31 20:26:48 UTC (rev 281817)
@@ -167,7 +167,7 @@
     ScrollBy(uint32_t scrollDirection, uint32_t scrollGranularity)
     CenterSelectionInVisibleArea()
 
-    GoToBackForwardItem(uint64_t navigationID, struct WebCore::BackForwardItemIdentifier backForwardItemID, enum:uint8_t WebCore::FrameLoadType backForwardType, enum:uint8_t WebCore::ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad, std::optional<WebKit::WebsitePoliciesData> websitePolicies)
+    GoToBackForwardItem(uint64_t navigationID, struct WebCore::BackForwardItemIdentifier backForwardItemID, enum:uint8_t WebCore::FrameLoadType backForwardType, enum:uint8_t WebCore::ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad, std::optional<WebKit::WebsitePoliciesData> websitePolicies, bool lastNavigationWasAppInitiated)
     TryRestoreScrollPosition()
 
     LoadURLInFrame(URL url, String referrer, WebCore::FrameIdentifier frameID)

Modified: trunk/Tools/ChangeLog (281816 => 281817)


--- trunk/Tools/ChangeLog	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Tools/ChangeLog	2021-08-31 20:26:48 UTC (rev 281817)
@@ -1,3 +1,15 @@
+2021-08-31  Kate Cheney  <[email protected]>
+
+        Loads after session restore marked app initiated in Safari
+        https://bugs.webkit.org/show_bug.cgi?id=229721
+        <rdar://problem/82084236>
+
+        Reviewed by Brent Fulgham.
+
+        API test coverage.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
+
 2021-08-31  Jonathan Bedard  <[email protected]>
 
         [contributors.json] Replace class=bot with status=bot

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm (281816 => 281817)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2021-08-31 20:23:43 UTC (rev 281816)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2021-08-31 20:26:48 UTC (rev 281817)
@@ -36,6 +36,7 @@
 #import <WebKit/WKPreferencesPrivate.h>
 #import <WebKit/WKWebViewPrivateForTesting.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <WebKit/_WKSessionState.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/RunLoop.h>
 #import <wtf/text/WTFString.h>
@@ -733,4 +734,45 @@
     loadSimulatedRequestTest(IsAppInitiated::No);
 }
 
+static void restoreFromSessionStateTest(IsAppInitiated isAppInitiated)
+{
+    auto webView1 = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+
+    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.apple.com/"]];
+    request.attribution = isAppInitiated == IsAppInitiated::Yes ? NSURLRequestAttributionDeveloper : NSURLRequestAttributionUser;
+
+    [webView1 loadRequest:request];
+    [webView1 _test_waitForDidFinishNavigation];
+
+    RetainPtr<_WKSessionState> sessionState = [webView1 _sessionState];
+    sessionState.get().isAppInitiated = isAppInitiated == IsAppInitiated::Yes ? true : false;
+    webView1 = nullptr;
+
+    auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView2 _restoreSessionState:sessionState.get() andNavigate:YES];
+    [webView2 _test_waitForDidFinishNavigation];
+
+    EXPECT_WK_STREQ(@"https://www.apple.com/", [[webView2 URL] absoluteString]);
+
+    static bool isDone = false;
+    bool expectingAppInitiatedRequests = isAppInitiated == IsAppInitiated::Yes ? true : false;
+    [webView2 _appPrivacyReportTestingData:^(struct WKAppPrivacyReportTestingData data) {
+        EXPECT_EQ(data.hasLoadedAppInitiatedRequestTesting, expectingAppInitiatedRequests);
+        EXPECT_EQ(data.hasLoadedNonAppInitiatedRequestTesting, !expectingAppInitiatedRequests);
+        isDone = true;
+    }];
+    TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(AppPrivacyReport, RestoreFromSessionStateIsAppInitiated)
+{
+    restoreFromSessionStateTest(IsAppInitiated::Yes);
+}
+
+TEST(AppPrivacyReport, RestoreFromSessionStateIsNonAppInitiated)
+{
+    restoreFromSessionStateTest(IsAppInitiated::No);
+}
+
 #endif // APP_PRIVACY_REPORT
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to