<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[285208] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/285208">285208</a></dd>
<dt>Author</dt> <dd>katherine_cheney@apple.com</dd>
<dt>Date</dt> <dd>2021-11-03 09:17:21 -0700 (Wed, 03 Nov 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Need API for marking file requests as non-app-initiated
https://bugs.webkit.org/show_bug.cgi?id=232506
<rdar://problem/84824703>

Reviewed by Brent Fulgham.

Source/WebKit:

Pass app initiated value through to the WebPage so file loads
can be attributed correctly.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView loadFileRequest:allowingReadAccessToURL:]):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::loadFile):
* UIProcess/WebPageProxy.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
* TestWebKitAPI/Tests/WebKitCocoa/file-with-iframe.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxycpp">trunk/Source/WebKit/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxyh">trunk/Source/WebKit/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaAppPrivacyReportmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoafilewithiframehtml">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/file-with-iframe.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (285207 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-11-03 16:14:05 UTC (rev 285207)
+++ trunk/Source/WebKit/ChangeLog       2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2021-11-03  Kate Cheney  <katherine_cheney@apple.com>
+
+        [iOS] Need API for marking file requests as non-app-initiated
+        https://bugs.webkit.org/show_bug.cgi?id=232506
+        <rdar://problem/84824703>
+
+        Reviewed by Brent Fulgham.
+
+        Pass app initiated value through to the WebPage so file loads
+        can be attributed correctly.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView loadFileRequest:allowingReadAccessToURL:]):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::loadFile):
+        * UIProcess/WebPageProxy.h:
+
</ins><span class="cx"> 2021-11-02  Don Olmstead  <don.olmstead@sony.com>
</span><span class="cx"> 
</span><span class="cx">         Non-unified build fixes early November 2021 edition
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (285207 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm     2021-11-03 16:14:05 UTC (rev 285207)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm        2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -1763,7 +1763,12 @@
</span><span class="cx">     if (![readAccessURL isFileURL])
</span><span class="cx">         [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", readAccessURL];
</span><span class="cx"> 
</span><del>-    return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString));
</del><ins>+    bool isAppInitiated = true;
+#if ENABLE(APP_PRIVACY_REPORT)
+    isAppInitiated = request.attribution == NSURLRequestAttributionDeveloper;
+#endif
+
+    return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString, isAppInitiated));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (CocoaColor *)themeColor
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (285207 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp   2021-11-03 16:14:05 UTC (rev 285207)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp      2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -1435,7 +1435,7 @@
</span><span class="cx">     process->startResponsivenessTimer();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr<API::Navigation> WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, API::Object* userData)
</del><ins>+RefPtr<API::Navigation> WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, bool isAppInitiated, API::Object* userData)
</ins><span class="cx"> {
</span><span class="cx">     WEBPAGEPROXY_RELEASE_LOG(Loading, "loadFile:");
</span><span class="cx"> 
</span><span class="lines">@@ -1480,9 +1480,13 @@
</span><span class="cx"> 
</span><span class="cx">     m_pageLoadState.setPendingAPIRequest(transaction, { navigation->navigationID(), fileURLString }, resourceDirectoryURL);
</span><span class="cx"> 
</span><ins>+    auto request = ResourceRequest(fileURL);
+    request.setIsAppInitiated(isAppInitiated);
+    m_lastNavigationWasAppInitiated = isAppInitiated;
+
</ins><span class="cx">     LoadParameters loadParameters;
</span><span class="cx">     loadParameters.navigationID = navigation->navigationID();
</span><del>-    loadParameters.request = fileURL;
</del><ins>+    loadParameters.request = WTFMove(request);
</ins><span class="cx">     loadParameters.shouldOpenExternalURLsPolicy = ShouldOpenExternalURLsPolicy::ShouldNotAllow;
</span><span class="cx">     loadParameters.userData = UserData(process().transformObjectsToHandles(userData).get());
</span><span class="cx">     const bool checkAssumedReadAccessToResourceURL = false;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (285207 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.h     2021-11-03 16:14:05 UTC (rev 285207)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h        2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -647,7 +647,7 @@
</span><span class="cx"> 
</span><span class="cx">     void addPlatformLoadParameters(WebProcessProxy&, LoadParameters&);
</span><span class="cx">     RefPtr<API::Navigation> loadRequest(WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemesButNotAppLinks, API::Object* userData = nullptr);
</span><del>-    RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr);
</del><ins>+    RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, bool isAppInitiated = true, API::Object* userData = nullptr);
</ins><span class="cx">     RefPtr<API::Navigation> loadData(const IPC::DataReference&, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow);
</span><span class="cx">     RefPtr<API::Navigation> loadSimulatedRequest(WebCore::ResourceRequest&&, WebCore::ResourceResponse&&, const IPC::DataReference&);
</span><span class="cx">     void loadAlternateHTML(const IPC::DataReference&, const String& encoding, const URL& baseURL, const URL& unreachableURL, API::Object* userData = nullptr);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (285207 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-11-03 16:14:05 UTC (rev 285207)
+++ trunk/Tools/ChangeLog       2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2021-11-03  Kate Cheney  <katherine_cheney@apple.com>
+
+        [iOS] Need API for marking file requests as non-app-initiated
+        https://bugs.webkit.org/show_bug.cgi?id=232506
+        <rdar://problem/84824703>
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/file-with-iframe.html: Added.
+
</ins><span class="cx"> 2021-11-03  Brady Eidson  <beidson@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Fix iOS API tests after r285199 
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (285207 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2021-11-03 16:14:05 UTC (rev 285207)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj   2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -322,6 +322,7 @@
</span><span class="cx">          498D030A26376B34009CBFAD /* resourceLoadStatisticsMissingUniqueIndex.db in Copy Resources */ = {isa = PBXBuildFile; fileRef = 498D030926376B2C009CBFAD /* resourceLoadStatisticsMissingUniqueIndex.db */; };
</span><span class="cx">          4995A6F025E8772000E5F0A9 /* csp-document-uri-report.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4995A6EF25E876A300E5F0A9 /* csp-document-uri-report.html */; };
</span><span class="cx">          49AEEF6D2407359D00C87E4C /* InAppBrowserPrivacy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49AEEF6B2407358600C87E4C /* InAppBrowserPrivacy.mm */; };
</span><ins>+               49D2E5C22731E3BC00BCCAED /* file-with-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 49D2E5C12731E37400BCCAED /* file-with-iframe.html */; };
</ins><span class="cx">           49EF6AD52677C0BE007967DC /* AppPrivacyReport.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49EF6AD42677C0BE007967DC /* AppPrivacyReport.mm */; };
</span><span class="cx">          4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
</span><span class="cx">          510477721D298DDD009747EB /* IDBDeleteRecovery.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5104776F1D298D85009747EB /* IDBDeleteRecovery.sqlite3 */; };
</span><span class="lines">@@ -1389,6 +1390,7 @@
</span><span class="cx">                  dstPath = TestWebKitAPI.resources;
</span><span class="cx">                  dstSubfolderSpec = 7;
</span><span class="cx">                  files = (
</span><ins>+                               49D2E5C22731E3BC00BCCAED /* file-with-iframe.html in Copy Resources */,
</ins><span class="cx">                           55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
</span><span class="cx">                          1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
</span><span class="cx">                          55A81800218102210004A39A /* 400x400-green.png in Copy Resources */,
</span><span class="lines">@@ -2178,6 +2180,7 @@
</span><span class="cx">          4995A6EF25E876A300E5F0A9 /* csp-document-uri-report.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "csp-document-uri-report.html"; sourceTree = "<group>"; };
</span><span class="cx">          49AEEF682407276F00C87E4C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
</span><span class="cx">          49AEEF6B2407358600C87E4C /* InAppBrowserPrivacy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InAppBrowserPrivacy.mm; sourceTree = "<group>"; };
</span><ins>+               49D2E5C12731E37400BCCAED /* file-with-iframe.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "file-with-iframe.html"; sourceTree = "<group>"; };
</ins><span class="cx">           49D7FBA7241FDDDA00AB67FA /* in-app-browser-privacy-local-file.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "in-app-browser-privacy-local-file.html"; sourceTree = "<group>"; };
</span><span class="cx">          49EF6AD42677C0BE007967DC /* AppPrivacyReport.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppPrivacyReport.mm; sourceTree = "<group>"; };
</span><span class="cx">          4A410F4B19AF7BD6002EBAB5 /* UserMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMedia.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -4289,6 +4292,7 @@
</span><span class="cx">                          51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */,
</span><span class="cx">                          5120C83B1E674E350025B250 /* WebsiteDataStoreCustomPaths.html */,
</span><span class="cx">                          2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */,
</span><ins>+                               49D2E5C12731E37400BCCAED /* file-with-iframe.html */,
</ins><span class="cx">                   );
</span><span class="cx">                  name = Resources;
</span><span class="cx">                  sourceTree = "<group>";
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaAppPrivacyReportmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm (285207 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm  2021-11-03 16:14:05 UTC (rev 285207)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm     2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -825,4 +825,35 @@
</span><span class="cx">     restoreFromInteractionStateTest(IsAppInitiated::No);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void loadFileTest(IsAppInitiated isAppInitiated)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+
+    NSURL *file = [[NSBundle mainBundle] URLForResource:@"file-with-iframe" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:file];
+    request.attribution = isAppInitiated == IsAppInitiated::Yes ? NSURLRequestAttributionDeveloper : NSURLRequestAttributionUser;
+
+    [webView loadFileRequest:request allowingReadAccessToURL:file.URLByDeletingLastPathComponent];
+    [webView _test_waitForDidFinishNavigation];
+
+    static bool isDone = false;
+    bool expectingAppInitiatedRequests = isAppInitiated == IsAppInitiated::Yes ? true : false;
+    [webView _appPrivacyReportTestingData:^(struct WKAppPrivacyReportTestingData data) {
+        EXPECT_EQ(data.hasLoadedAppInitiatedRequestTesting, expectingAppInitiatedRequests);
+        EXPECT_EQ(data.hasLoadedNonAppInitiatedRequestTesting, !expectingAppInitiatedRequests);
+        isDone = true;
+    }];
+    TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(AppPrivacyReport, LoadFileRequestIsAppInitiated)
+{
+    loadFileTest(IsAppInitiated::Yes);
+}
+
+TEST(AppPrivacyReport, LoadFileRequestIsNonAppInitiated)
+{
+    loadFileTest(IsAppInitiated::No);
+}
+
</ins><span class="cx"> #endif // APP_PRIVACY_REPORT
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoafilewithiframehtml"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/file-with-iframe.html (0 => 285208)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/file-with-iframe.html                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/file-with-iframe.html   2021-11-03 16:17:21 UTC (rev 285208)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+<html>
+<body>
+  <iframe src="https://www.apple.com"></iframe>
+</body>
+</html>
</ins></span></pre>
</div>
</div>

</body>
</html>