Title: [289255] trunk
Revision
289255
Author
[email protected]
Date
2022-02-07 18:05:05 -0800 (Mon, 07 Feb 2022)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289254 => 289255)


--- trunk/Source/WebCore/ChangeLog	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Source/WebCore/ChangeLog	2022-02-08 02:05:05 UTC (rev 289255)
@@ -1,3 +1,29 @@
+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-02-07  Lauro Moura  <[email protected]>
 
         Unreviewed, non-unified build fixes after 246907@main

Modified: trunk/Source/WebCore/platform/network/ResourceRequestBase.cpp (289254 => 289255)


--- trunk/Source/WebCore/platform/network/ResourceRequestBase.cpp	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.cpp	2022-02-08 02:05:05 UTC (rev 289255)
@@ -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: trunk/Source/WebCore/platform/network/ResourceRequestBase.h (289254 => 289255)


--- trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2022-02-08 02:05:05 UTC (rev 289255)
@@ -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: trunk/Source/WebCore/platform/network/cf/ResourceRequest.h (289254 => 289255)


--- trunk/Source/WebCore/platform/network/cf/ResourceRequest.h	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Source/WebCore/platform/network/cf/ResourceRequest.h	2022-02-08 02:05:05 UTC (rev 289255)
@@ -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: trunk/Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm (289254 => 289255)


--- trunk/Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm	2022-02-08 02:05:05 UTC (rev 289255)
@@ -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: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (289254 => 289255)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2022-02-08 02:05:05 UTC (rev 289255)
@@ -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: trunk/Tools/ChangeLog (289254 => 289255)


--- trunk/Tools/ChangeLog	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Tools/ChangeLog	2022-02-08 02:05:05 UTC (rev 289255)
@@ -1,3 +1,14 @@
+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-02-07  Jonathan Bedard  <[email protected]>
 
         [webkitscmpy] Adopt webkitbugspy for GitHub issues (Part 3)

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm (289254 => 289255)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2022-02-08 01:45:48 UTC (rev 289254)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/AppPrivacyReport.mm	2022-02-08 02:05:05 UTC (rev 289255)
@@ -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