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

Changeset 285208 in webkit


Ignore:
Timestamp:
Nov 3, 2021, 9:17:21 AM (5 years ago)
Author:
Kate Cheney
Message:

[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.
Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r285195 r285208  
     12021-11-03  Kate Cheney  <katherine_cheney@apple.com>
     2
     3        [iOS] Need API for marking file requests as non-app-initiated
     4        https://bugs.webkit.org/show_bug.cgi?id=232506
     5        <rdar://problem/84824703>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Pass app initiated value through to the WebPage so file loads
     10        can be attributed correctly.
     11
     12        * UIProcess/API/Cocoa/WKWebView.mm:
     13        (-[WKWebView loadFileRequest:allowingReadAccessToURL:]):
     14        * UIProcess/WebPageProxy.cpp:
     15        (WebKit::WebPageProxy::loadFile):
     16        * UIProcess/WebPageProxy.h:
     17
    1182021-11-02  Don Olmstead  <don.olmstead@sony.com>
    219
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r285163 r285208  
    17641764        [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", readAccessURL];
    17651765
    1766     return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString));
     1766    bool isAppInitiated = true;
     1767#if ENABLE(APP_PRIVACY_REPORT)
     1768    isAppInitiated = request.attribution == NSURLRequestAttributionDeveloper;
     1769#endif
     1770
     1771    return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString, isAppInitiated));
    17671772}
    17681773
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r285165 r285208  
    14361436}
    14371437
    1438 RefPtr<API::Navigation> WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, API::Object* userData)
     1438RefPtr<API::Navigation> WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, bool isAppInitiated, API::Object* userData)
    14391439{
    14401440    WEBPAGEPROXY_RELEASE_LOG(Loading, "loadFile:");
    … …  
    14811481    m_pageLoadState.setPendingAPIRequest(transaction, { navigation->navigationID(), fileURLString }, resourceDirectoryURL);
    14821482
     1483    auto request = ResourceRequest(fileURL);
     1484    request.setIsAppInitiated(isAppInitiated);
     1485    m_lastNavigationWasAppInitiated = isAppInitiated;
     1486
    14831487    LoadParameters loadParameters;
    14841488    loadParameters.navigationID = navigation->navigationID();
    1485     loadParameters.request = fileURL;
     1489    loadParameters.request = WTFMove(request);
    14861490    loadParameters.shouldOpenExternalURLsPolicy = ShouldOpenExternalURLsPolicy::ShouldNotAllow;
    14871491    loadParameters.userData = UserData(process().transformObjectsToHandles(userData).get());
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r285165 r285208  
    648648    void addPlatformLoadParameters(WebProcessProxy&, LoadParameters&);
    649649    RefPtr<API::Navigation> loadRequest(WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemesButNotAppLinks, API::Object* userData = nullptr);
    650     RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr);
     650    RefPtr<API::Navigation> loadFile(const String& fileURL, const String& resourceDirectoryURL, bool isAppInitiated = true, API::Object* userData = nullptr);
    651651    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);
    652652    RefPtr<API::Navigation> loadSimulatedRequest(WebCore::ResourceRequest&&, WebCore::ResourceResponse&&, const IPC::DataReference&);
  • trunk/Tools/ChangeLog

    r285207 r285208  
     12021-11-03  Kate Cheney  <katherine_cheney@apple.com>
     2
     3        [iOS] Need API for marking file requests as non-app-initiated
     4        https://bugs.webkit.org/show_bug.cgi?id=232506
     5        <rdar://problem/84824703>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
     11        * TestWebKitAPI/Tests/WebKitCocoa/file-with-iframe.html: Added.
     12
    1132021-11-03  Brady Eidson  <beidson@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r284890 r285208  
    323323                4995A6F025E8772000E5F0A9 /* csp-document-uri-report.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4995A6EF25E876A300E5F0A9 /* csp-document-uri-report.html */; };
    324324                49AEEF6D2407359D00C87E4C /* InAppBrowserPrivacy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49AEEF6B2407358600C87E4C /* InAppBrowserPrivacy.mm */; };
     325                49D2E5C22731E3BC00BCCAED /* file-with-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 49D2E5C12731E37400BCCAED /* file-with-iframe.html */; };
    325326                49EF6AD52677C0BE007967DC /* AppPrivacyReport.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49EF6AD42677C0BE007967DC /* AppPrivacyReport.mm */; };
    326327                4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
    … …  
    13901391                        dstSubfolderSpec = 7;
    13911392                        files = (
     1393                                49D2E5C22731E3BC00BCCAED /* file-with-iframe.html in Copy Resources */,
    13921394                                55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
    13931395                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
    … …  
    21792181                49AEEF682407276F00C87E4C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
    21802182                49AEEF6B2407358600C87E4C /* InAppBrowserPrivacy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InAppBrowserPrivacy.mm; sourceTree = "<group>"; };
     2183                49D2E5C12731E37400BCCAED /* file-with-iframe.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "file-with-iframe.html"; sourceTree = "<group>"; };
    21812184                49D7FBA7241FDDDA00AB67FA /* in-app-browser-privacy-local-file.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "in-app-browser-privacy-local-file.html"; sourceTree = "<group>"; };
    21822185                49EF6AD42677C0BE007967DC /* AppPrivacyReport.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppPrivacyReport.mm; sourceTree = "<group>"; };
    … …  
    42904293                                5120C83B1E674E350025B250 /* WebsiteDataStoreCustomPaths.html */,
    42914294                                2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */,
     4295                                49D2E5C12731E37400BCCAED /* file-with-iframe.html */,
    42924296                        );
    42934297                        name = Resources;
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm

    r285163 r285208  
    826826}
    827827
     828static void loadFileTest(IsAppInitiated isAppInitiated)
     829{
     830    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     831
     832    NSURL *file = [[NSBundle mainBundle] URLForResource:@"file-with-iframe" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     833    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:file];
     834    request.attribution = isAppInitiated == IsAppInitiated::Yes ? NSURLRequestAttributionDeveloper : NSURLRequestAttributionUser;
     835
     836    [webView loadFileRequest:request allowingReadAccessToURL:file.URLByDeletingLastPathComponent];
     837    [webView _test_waitForDidFinishNavigation];
     838
     839    static bool isDone = false;
     840    bool expectingAppInitiatedRequests = isAppInitiated == IsAppInitiated::Yes ? true : false;
     841    [webView _appPrivacyReportTestingData:^(struct WKAppPrivacyReportTestingData data) {
     842        EXPECT_EQ(data.hasLoadedAppInitiatedRequestTesting, expectingAppInitiatedRequests);
     843        EXPECT_EQ(data.hasLoadedNonAppInitiatedRequestTesting, !expectingAppInitiatedRequests);
     844        isDone = true;
     845    }];
     846    TestWebKitAPI::Util::run(&isDone);
     847}
     848
     849TEST(AppPrivacyReport, LoadFileRequestIsAppInitiated)
     850{
     851    loadFileTest(IsAppInitiated::Yes);
     852}
     853
     854TEST(AppPrivacyReport, LoadFileRequestIsNonAppInitiated)
     855{
     856    loadFileTest(IsAppInitiated::No);
     857}
     858
    828859#endif // APP_PRIVACY_REPORT
Note: See TracChangeset for help on using the changeset viewer.