Title: [290919] branches/safari-613-branch
Revision
290919
Author
[email protected]
Date
2022-03-07 14:09:09 -0800 (Mon, 07 Mar 2022)

Log Message

Cherry-pick r289255. rdar://problem/88490742

    Always sync ResourceRequest isAppInitiated request with NSURLRequest attribution value
    https://bugs.webkit.org/show_bug.cgi?id=236167
    <rdar://88490742>

    Reviewed by Darin Adler.

    Source/WebCore:

    We should always keep the state of our 'isAppInitiated' flag in sync with the underlying
    NSURLRequest object. This also corrects a problem where the 'setIsAppInitiated' method
    does not mark the platform URL request as dirty, so it does not update with the correct
    state of the flag.

    Tests: New TestWebKitAPI Test (AppPrivacyReport.NSURLRequestConstructorAttribution)

    * platform/network/ResourceRequestBase.cpp:
    (WebCore::ResourceRequestBase::setIsAppInitiated):
    * platform/network/ResourceRequestBase.h:
    * platform/network/cf/ResourceRequest.h:
    * platform/network/cocoa/ResourceRequestCocoa.mm:
    (WebCore::ResourceRequest::ResourceRequest):
    (WebCore::ResourceRequest::doUpdatePlatformRequest):
    (WebCore::ResourceRequest::doUpdatePlatformHTTPBody):
    (WebCore::copyRequestWithStorageSession):
    * rendering/RenderThemeIOS.mm:

    Tools:

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme:
    * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@289255 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (290918 => 290919)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-03-07 22:09:09 UTC (rev 290919)
@@ -1,5 +1,69 @@
 2022-03-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r289255. rdar://problem/88490742
+
+    Always sync ResourceRequest isAppInitiated request with NSURLRequest attribution value
+    https://bugs.webkit.org/show_bug.cgi?id=236167
+    <rdar://88490742>
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebCore:
+    
+    We should always keep the state of our 'isAppInitiated' flag in sync with the underlying
+    NSURLRequest object. This also corrects a problem where the 'setIsAppInitiated' method
+    does not mark the platform URL request as dirty, so it does not update with the correct
+    state of the flag.
+    
+    Tests: New TestWebKitAPI Test (AppPrivacyReport.NSURLRequestConstructorAttribution)
+    
+    * platform/network/ResourceRequestBase.cpp:
+    (WebCore::ResourceRequestBase::setIsAppInitiated):
+    * platform/network/ResourceRequestBase.h:
+    * platform/network/cf/ResourceRequest.h:
+    * platform/network/cocoa/ResourceRequestCocoa.mm:
+    (WebCore::ResourceRequest::ResourceRequest):
+    (WebCore::ResourceRequest::doUpdatePlatformRequest):
+    (WebCore::ResourceRequest::doUpdatePlatformHTTPBody):
+    (WebCore::copyRequestWithStorageSession):
+    * rendering/RenderThemeIOS.mm:
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme:
+    * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@289255 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-02-07  Brent Fulgham  <[email protected]>
+
+            Always sync ResourceRequest isAppInitiated request with NSURLRequest attribution value
+            https://bugs.webkit.org/show_bug.cgi?id=236167
+            <rdar://88490742>
+
+            Reviewed by Darin Adler.
+
+            We should always keep the state of our 'isAppInitiated' flag in sync with the underlying
+            NSURLRequest object. This also corrects a problem where the 'setIsAppInitiated' method
+            does not mark the platform URL request as dirty, so it does not update with the correct
+            state of the flag.
+
+            Tests: New TestWebKitAPI Test (AppPrivacyReport.NSURLRequestConstructorAttribution)
+
+            * platform/network/ResourceRequestBase.cpp:
+            (WebCore::ResourceRequestBase::setIsAppInitiated):
+            * platform/network/ResourceRequestBase.h:
+            * platform/network/cf/ResourceRequest.h:
+            * platform/network/cocoa/ResourceRequestCocoa.mm:
+            (WebCore::ResourceRequest::ResourceRequest):
+            (WebCore::ResourceRequest::doUpdatePlatformRequest):
+            (WebCore::ResourceRequest::doUpdatePlatformHTTPBody):
+            (WebCore::copyRequestWithStorageSession):
+            * rendering/RenderThemeIOS.mm:
+
+2022-03-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r289121. rdar://problem/88492251
 
     Fix App Privacy Report redirect attribution

Modified: branches/safari-613-branch/Source/WebCore/platform/network/ResourceRequestBase.cpp (290918 => 290919)


--- branches/safari-613-branch/Source/WebCore/platform/network/ResourceRequestBase.cpp	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Source/WebCore/platform/network/ResourceRequestBase.cpp	2022-03-07 22:09:09 UTC (rev 290919)
@@ -619,6 +619,18 @@
     m_platformRequestUpdated = false;
 }
 
+void ResourceRequestBase::setIsAppInitiated(bool isAppInitiated)
+{
+    updateResourceRequest();
+
+    if (m_isAppInitiated == isAppInitiated)
+        return;
+
+    m_isAppInitiated = isAppInitiated;
+
+    m_platformRequestUpdated = false;
+};
+
 #if USE(SYSTEM_PREVIEW)
 
 bool ResourceRequestBase::isSystemPreview() const

Modified: branches/safari-613-branch/Source/WebCore/platform/network/ResourceRequestBase.h (290918 => 290919)


--- branches/safari-613-branch/Source/WebCore/platform/network/ResourceRequestBase.h	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Source/WebCore/platform/network/ResourceRequestBase.h	2022-03-07 22:09:09 UTC (rev 290919)
@@ -198,7 +198,7 @@
     WEBCORE_EXPORT static bool equal(const ResourceRequest&, const ResourceRequest&);
 
     bool isAppInitiated() const { return m_isAppInitiated; }
-    void setIsAppInitiated(bool isAppInitiated) { m_isAppInitiated = isAppInitiated; };
+    WEBCORE_EXPORT void setIsAppInitiated(bool);
 
 protected:
     // Used when ResourceRequest is initialized from a platform representation of the request

Modified: branches/safari-613-branch/Source/WebCore/platform/network/cf/ResourceRequest.h (290918 => 290919)


--- branches/safari-613-branch/Source/WebCore/platform/network/cf/ResourceRequest.h	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Source/WebCore/platform/network/cf/ResourceRequest.h	2022-03-07 22:09:09 UTC (rev 290919)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2003-2022 Apple Inc.  All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <[email protected]>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -69,11 +69,7 @@
     {
     }
 #else
-    ResourceRequest(NSURLRequest *nsRequest)
-        : ResourceRequestBase()
-        , m_nsRequest(nsRequest)
-    {
-    }
+    WEBCORE_EXPORT ResourceRequest(NSURLRequest *);
 #endif
 
     WEBCORE_EXPORT void updateFromDelegatePreservingOldProperties(const ResourceRequest&);

Modified: branches/safari-613-branch/Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm (290918 => 290919)


--- branches/safari-613-branch/Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm	2022-03-07 22:09:09 UTC (rev 290919)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2017 Apple, Inc.  All rights reserved.
+ * Copyright (C) 2014-2022 Apple, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -34,6 +34,7 @@
 #import "ResourceRequestCFNet.h"
 #import "RuntimeApplicationChecks.h"
 #import <Foundation/Foundation.h>
+#import <Foundation/NSURLRequest.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/FileSystem.h>
 #import <wtf/cocoa/VectorCocoa.h>
@@ -41,6 +42,14 @@
 
 namespace WebCore {
 
+ResourceRequest::ResourceRequest(NSURLRequest *nsRequest)
+    : m_nsRequest(nsRequest)
+{
+#if ENABLE(APP_PRIVACY_REPORT)
+    setIsAppInitiated(nsRequest.attribution == NSURLRequestAttributionDeveloper);
+#endif
+}
+
 NSURLRequest *ResourceRequest::nsURLRequest(HTTPBodyUpdatePolicy bodyPolicy) const
 {
     updatePlatformRequest(bodyPolicy);
@@ -165,7 +174,7 @@
         return;
     }
 
-    auto nsRequest = adoptNS([m_nsRequest mutableCopy]);
+    auto nsRequest = adoptNS<NSMutableURLRequest *>([m_nsRequest mutableCopy]);
 
     if (nsRequest)
         [nsRequest setURL:url()];
@@ -172,6 +181,10 @@
     else
         nsRequest = adoptNS([[NSMutableURLRequest alloc] initWithURL:url()]);
 
+#if ENABLE(APP_PRIVACY_REPORT)
+    nsRequest.get().attribution = m_isAppInitiated ? NSURLRequestAttributionDeveloper : NSURLRequestAttributionUser;
+#endif
+
     if (ResourceRequest::httpPipeliningEnabled())
         CFURLRequestSetShouldPipelineHTTP([nsRequest _CFURLRequest], true, true);
 
@@ -241,7 +254,7 @@
         return;
     }
 
-    auto nsRequest = adoptNS([m_nsRequest mutableCopy]);
+    auto nsRequest = adoptNS<NSMutableURLRequest *>([m_nsRequest mutableCopy]);
 
     if (nsRequest)
         [nsRequest setURL:url()];
@@ -248,6 +261,10 @@
     else
         nsRequest = adoptNS([[NSMutableURLRequest alloc] initWithURL:url()]);
 
+#if ENABLE(APP_PRIVACY_REPORT)
+    nsRequest.get().attribution = m_isAppInitiated ? NSURLRequestAttributionDeveloper : NSURLRequestAttributionUser;
+#endif
+
     FormData* formData = httpBody();
     if (formData && !formData->isEmpty())
         WebCore::setHTTPBody(nsRequest.get(), formData);
@@ -279,7 +296,11 @@
 
     auto cfRequest = adoptCF(CFURLRequestCreateMutableCopy(kCFAllocatorDefault, [request _CFURLRequest]));
     _CFURLRequestSetStorageSession(cfRequest.get(), storageSession);
-    return adoptNS([[NSURLRequest alloc] _initWithCFURLRequest:cfRequest.get()]);
+    auto nsRequest = adoptNS([[NSMutableURLRequest alloc] _initWithCFURLRequest:cfRequest.get()]);
+#if ENABLE(APP_PRIVACY_REPORT)
+    nsRequest.get().attribution = request.attribution;
+#endif
+    return nsRequest;
 }
 
 NSCachedURLResponse *cachedResponseForRequest(CFURLStorageSessionRef storageSession, NSURLRequest *request)

Modified: branches/safari-613-branch/Source/WebCore/rendering/RenderThemeIOS.mm (290918 => 290919)


--- branches/safari-613-branch/Source/WebCore/rendering/RenderThemeIOS.mm	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Source/WebCore/rendering/RenderThemeIOS.mm	2022-03-07 22:09:09 UTC (rev 290919)
@@ -35,6 +35,7 @@
 #import "CSSValueKeywords.h"
 #import "ColorBlending.h"
 #import "ColorCocoa.h"
+#import "ColorTypes.h"
 #import "DateComponents.h"
 #import "Document.h"
 #import "DrawGlyphsRecorder.h"

Modified: branches/safari-613-branch/Tools/ChangeLog (290918 => 290919)


--- branches/safari-613-branch/Tools/ChangeLog	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Tools/ChangeLog	2022-03-07 22:09:09 UTC (rev 290919)
@@ -1,5 +1,54 @@
 2022-03-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r289255. rdar://problem/88490742
+
+    Always sync ResourceRequest isAppInitiated request with NSURLRequest attribution value
+    https://bugs.webkit.org/show_bug.cgi?id=236167
+    <rdar://88490742>
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebCore:
+    
+    We should always keep the state of our 'isAppInitiated' flag in sync with the underlying
+    NSURLRequest object. This also corrects a problem where the 'setIsAppInitiated' method
+    does not mark the platform URL request as dirty, so it does not update with the correct
+    state of the flag.
+    
+    Tests: New TestWebKitAPI Test (AppPrivacyReport.NSURLRequestConstructorAttribution)
+    
+    * platform/network/ResourceRequestBase.cpp:
+    (WebCore::ResourceRequestBase::setIsAppInitiated):
+    * platform/network/ResourceRequestBase.h:
+    * platform/network/cf/ResourceRequest.h:
+    * platform/network/cocoa/ResourceRequestCocoa.mm:
+    (WebCore::ResourceRequest::ResourceRequest):
+    (WebCore::ResourceRequest::doUpdatePlatformRequest):
+    (WebCore::ResourceRequest::doUpdatePlatformHTTPBody):
+    (WebCore::copyRequestWithStorageSession):
+    * rendering/RenderThemeIOS.mm:
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme:
+    * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@289255 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-02-07  Brent Fulgham  <[email protected]>
+
+            Always sync ResourceRequest isAppInitiated request with NSURLRequest attribution value
+            https://bugs.webkit.org/show_bug.cgi?id=236167
+            <rdar://88490742>
+
+            Reviewed by Darin Adler.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme:
+            * TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm:
+
+2022-03-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288700. rdar://problem/86602114
 
     Default to 32 bit refcount for CanMakeCheckedPtr

Modified: branches/safari-613-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm (290918 => 290919)


--- branches/safari-613-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2022-03-07 22:09:04 UTC (rev 290918)
+++ branches/safari-613-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2022-03-07 22:09:09 UTC (rev 290919)
@@ -36,6 +36,7 @@
 #import <WebKit/WKWebViewPrivateForTesting.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/_WKSessionState.h>
+#import <WebCore/ResourceRequest.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/RunLoop.h>
 #import <wtf/text/WTFString.h>
@@ -853,4 +854,53 @@
     loadFileTest(IsAppInitiated::No);
 }
 
+TEST(AppPrivacyReport, NSURLRequestConstructorAttribution)
+{
+    NSString *url = ""
+
+    NSMutableURLRequest *appInitiatedRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
+    EXPECT_EQ(appInitiatedRequest.attribution, NSURLRequestAttributionDeveloper);
+
+    WebCore::ResourceRequest testRequest(appInitiatedRequest);
+    EXPECT_TRUE(testRequest.isAppInitiated());
+
+    WebCore::ResourceRequest testRequestCopy(testRequest);
+    EXPECT_TRUE(testRequestCopy.isAppInitiated());
+
+    auto nsRequestFromCopy = testRequestCopy.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
+    EXPECT_EQ(nsRequestFromCopy.attribution, NSURLRequestAttributionDeveloper);
+    
+    appInitiatedRequest.attribution = NSURLRequestAttributionUser;
+    WebCore::ResourceRequest testRequest2(appInitiatedRequest);
+    EXPECT_FALSE(testRequest2.isAppInitiated());
+
+    WebCore::ResourceRequest testRequestCopy2(testRequest2);
+    EXPECT_FALSE(testRequestCopy2.isAppInitiated());
+
+    auto nsRequestFromCopy2 = testRequestCopy2.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
+    EXPECT_EQ(nsRequestFromCopy2.attribution, NSURLRequestAttributionUser);
+
+    appInitiatedRequest.attribution = NSURLRequestAttributionDeveloper;
+    WebCore::ResourceRequest testRequest3(appInitiatedRequest);
+    EXPECT_TRUE(testRequest3.isAppInitiated());
+
+    auto nsRequestFromModifiedRequest = testRequest3.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
+    EXPECT_EQ(nsRequestFromModifiedRequest.attribution, NSURLRequestAttributionDeveloper);
+
+    testRequest3.setIsAppInitiated(false);
+    auto nsRequestFromModifiedRequest2 = testRequest3.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
+    EXPECT_EQ(nsRequestFromModifiedRequest2.attribution, NSURLRequestAttributionUser);
+
+    testRequest3.setIsAppInitiated(true);
+    auto nsRequestFromModifiedRequest3 = testRequest3.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
+    EXPECT_EQ(nsRequestFromModifiedRequest3.attribution, NSURLRequestAttributionDeveloper);
+
+    // Changing the nsURLRequest copy generated by the accessor doesn't change the ResourceRequest
+    appInitiatedRequest.attribution = NSURLRequestAttributionUser;
+    EXPECT_TRUE(testRequest.isAppInitiated());
+
+    WebCore::ResourceRequest testRequest4(appInitiatedRequest);
+    EXPECT_FALSE(testRequest4.isAppInitiated());
+}
+
 #endif // APP_PRIVACY_REPORT
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to