Title: [285080] trunk
Revision
285080
Author
katherine_che...@apple.com
Date
2021-10-30 09:08:17 -0700 (Sat, 30 Oct 2021)

Log Message

[iOS 15] Loads after WKWebView session restore are marked as app-initiated
https://bugs.webkit.org/show_bug.cgi?id=232486
<rdar://problem/84811692>

Reviewed by Brent Fulgham.

Source/WebKit:

Return app initiated value in the page's SessionState so it can be restored
by third party apps using the [WKWebView setInteractionState] API.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::sessionState const):
* UIProcess/mac/LegacySessionStateCoding.cpp:
(WebKit::encodeLegacySessionState):
(WebKit::decodeLegacySessionState):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (285079 => 285080)


--- trunk/Source/WebKit/ChangeLog	2021-10-30 13:44:39 UTC (rev 285079)
+++ trunk/Source/WebKit/ChangeLog	2021-10-30 16:08:17 UTC (rev 285080)
@@ -1,3 +1,20 @@
+2021-10-30  Kate Cheney  <katherine_che...@apple.com>
+
+        [iOS 15] Loads after WKWebView session restore are marked as app-initiated 
+        https://bugs.webkit.org/show_bug.cgi?id=232486
+        <rdar://problem/84811692>
+
+        Reviewed by Brent Fulgham.
+
+        Return app initiated value in the page's SessionState so it can be restored
+        by third party apps using the [WKWebView setInteractionState] API.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::sessionState const):
+        * UIProcess/mac/LegacySessionStateCoding.cpp:
+        (WebKit::encodeLegacySessionState):
+        (WebKit::decodeLegacySessionState):
+
 2021-10-29  Lauro Moura  <lmo...@igalia.com>
 
         [GLIB][SOUP] Unify memoryPressureMonitorDisabled implementation

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (285079 => 285080)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-10-30 13:44:39 UTC (rev 285079)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-10-30 16:08:17 UTC (rev 285080)
@@ -3773,6 +3773,7 @@
         sessionState.provisionalURL = URL(URL(), provisionalURLString);
 
     sessionState.renderTreeSize = renderTreeSize();
+    sessionState.isAppInitiated = m_lastNavigationWasAppInitiated;
     return sessionState;
 }
 

Modified: trunk/Source/WebKit/UIProcess/mac/LegacySessionStateCoding.cpp (285079 => 285080)


--- trunk/Source/WebKit/UIProcess/mac/LegacySessionStateCoding.cpp	2021-10-30 13:44:39 UTC (rev 285079)
+++ trunk/Source/WebKit/UIProcess/mac/LegacySessionStateCoding.cpp	2021-10-30 16:08:17 UTC (rev 285080)
@@ -41,6 +41,7 @@
 static const CFStringRef sessionHistoryKey = CFSTR("SessionHistory");
 static const CFStringRef provisionalURLKey = CFSTR("ProvisionalURL");
 static const CFStringRef renderTreeSizeKey = CFSTR("RenderTreeSize");
+static const CFStringRef isAppInitiatedKey = CFSTR("IsAppInitiated");
 
 // Session history keys.
 static const uint32_t sessionHistoryVersion = 1;
@@ -481,6 +482,7 @@
     auto sessionHistoryDictionary = encodeSessionHistory(sessionState.backForwardListState);
     auto provisionalURLString = sessionState.provisionalURL.isNull() ? nullptr : sessionState.provisionalURL.string().createCFString();
     RetainPtr<CFNumberRef> renderTreeSizeNumber(adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &sessionState.renderTreeSize)));
+    RetainPtr<CFBooleanRef> isAppInitiated = adoptCF(sessionState.isAppInitiated ? kCFBooleanTrue : kCFBooleanFalse);
 
     RetainPtr<CFDictionaryRef> stateDictionary;
     if (provisionalURLString) {
@@ -487,12 +489,14 @@
         stateDictionary = createDictionary({
             { sessionHistoryKey, sessionHistoryDictionary.get() },
             { provisionalURLKey, provisionalURLString.get() },
-            { renderTreeSizeKey, renderTreeSizeNumber.get() }
+            { renderTreeSizeKey, renderTreeSizeNumber.get() },
+            { isAppInitiatedKey, isAppInitiated.get() }
         });
     } else {
         stateDictionary = createDictionary({
             { sessionHistoryKey, sessionHistoryDictionary.get() },
-            { renderTreeSizeKey, renderTreeSizeNumber.get() }
+            { renderTreeSizeKey, renderTreeSizeNumber.get() },
+            { isAppInitiatedKey, isAppInitiated.get() }
         });
     }
 
@@ -1152,6 +1156,11 @@
     else
         sessionState.renderTreeSize = 0;
 
+    if (auto isAppInitiated = dynamic_cf_cast<CFBooleanRef>(CFDictionaryGetValue(sessionStateDictionary, isAppInitiatedKey)))
+        sessionState.isAppInitiated = isAppInitiated == kCFBooleanTrue;
+    else
+        sessionState.isAppInitiated = true;
+
     return true;
 }
 

Modified: trunk/Tools/ChangeLog (285079 => 285080)


--- trunk/Tools/ChangeLog	2021-10-30 13:44:39 UTC (rev 285079)
+++ trunk/Tools/ChangeLog	2021-10-30 16:08:17 UTC (rev 285080)
@@ -1,3 +1,13 @@
+2021-10-30  Kate Cheney  <katherine_che...@apple.com>
+
+        [iOS 15] Loads after WKWebView session restore are marked as app-initiated 
+        https://bugs.webkit.org/show_bug.cgi?id=232486
+        <rdar://problem/84811692>
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
+
 2021-10-29  Stephan Szabo  <stephan.sz...@sony.com>
 
         [PlayStation] Build fix after r285020

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm (285079 => 285080)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2021-10-30 13:44:39 UTC (rev 285079)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2021-10-30 16:08:17 UTC (rev 285080)
@@ -781,4 +781,49 @@
     restoreFromSessionStateTest(IsAppInitiated::No);
 }
 
+static void restoreFromInteractionStateTest(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];
+
+    id interactionState = [webView1 interactionState];
+    [webView1 _close];
+
+    static bool isDone = false;
+    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        isDone = true;
+    }];
+    TestWebKitAPI::Util::run(&isDone);
+
+    auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView2 setInteractionState:interactionState];
+    [webView2 _test_waitForDidFinishNavigation];
+
+    EXPECT_WK_STREQ(@"https://www.apple.com/", [[webView2 URL] absoluteString]);
+
+    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, RestoreFromInteractionStateIsAppInitiated)
+{
+    restoreFromInteractionStateTest(IsAppInitiated::Yes);
+}
+
+TEST(AppPrivacyReport, RestoreFromInteractionStateIsNonAppInitiated)
+{
+    restoreFromInteractionStateTest(IsAppInitiated::No);
+}
+
 #endif // APP_PRIVACY_REPORT
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to