Title: [270669] trunk
Revision
270669
Author
[email protected]
Date
2020-12-10 23:41:15 -0800 (Thu, 10 Dec 2020)

Log Message

Accept click measurement data from hosting application
https://bugs.webkit.org/show_bug.cgi?id=219763
<rdar://problem/72121094>

Patch by Alex Christensen <[email protected]> on 2020-12-10
Reviewed by John Wilander.

Source/WebCore:

Covered by an API test.

* loader/PrivateClickMeasurement.h:
(WebCore::PrivateClickMeasurement::PrivateClickMeasurement):
(WebCore::PrivateClickMeasurement::sourceID const):
(WebCore::PrivateClickMeasurement::sourceDescription const):
(WebCore::PrivateClickMeasurement::purchaser const):
(WebCore::PrivateClickMeasurement::encode const):
(WebCore::PrivateClickMeasurement::decode):
(WebCore::PrivateClickMeasurement::sourceID): Deleted.

Source/WebKit:

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::buildPrivateClickMeasurementFromDatabase):
* Platform/ios/UIKitSoftLink.h: Added.
* Platform/ios/UIKitSoftLink.mm: Added.
* Platform/spi/ios/UIKitSPI.h:
* SourcesCocoa.txt:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _setPrivateClickMeasurementOverrideTimerForTesting:completionHandler:]):
(-[WKWebView _setPrivateClickMeasurementConversionURLForTesting:completionHandler:]):
* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _setEventAttribution:]):
(-[WKWebView _eventAttribution]):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didCommitLoadForFrame):
(WebKit::WebPageProxy::createNewPage):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::setPrivateClickMeasurement):
(WebKit::WebPageProxy::privateClickMeasurement const):
* WebKit.xcodeproj/project.pbxproj:

Tools:

* TestWebKitAPI/SourcesCocoa.txt:
* TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
(testCertificate):
* TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: Added.
(-[MockEventAttribution initWithReportEndpoint:attributeOn:]):
(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/HTTPServer.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270668 => 270669)


--- trunk/Source/WebCore/ChangeLog	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebCore/ChangeLog	2020-12-11 07:41:15 UTC (rev 270669)
@@ -1,3 +1,22 @@
+2020-12-10  Alex Christensen  <[email protected]>
+
+        Accept click measurement data from hosting application
+        https://bugs.webkit.org/show_bug.cgi?id=219763
+        <rdar://problem/72121094>
+
+        Reviewed by John Wilander.
+
+        Covered by an API test.
+
+        * loader/PrivateClickMeasurement.h:
+        (WebCore::PrivateClickMeasurement::PrivateClickMeasurement):
+        (WebCore::PrivateClickMeasurement::sourceID const):
+        (WebCore::PrivateClickMeasurement::sourceDescription const):
+        (WebCore::PrivateClickMeasurement::purchaser const):
+        (WebCore::PrivateClickMeasurement::encode const):
+        (WebCore::PrivateClickMeasurement::decode):
+        (WebCore::PrivateClickMeasurement::sourceID): Deleted.
+
 2020-12-10  Peng Liu  <[email protected]>
 
         [Media in GPU Process][MSE] Implement several methods in SourceBufferPrivateRemote to make seeking more reliable

Modified: trunk/Source/WebCore/loader/PrivateClickMeasurement.h (270668 => 270669)


--- trunk/Source/WebCore/loader/PrivateClickMeasurement.h	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebCore/loader/PrivateClickMeasurement.h	2020-12-11 07:41:15 UTC (rev 270669)
@@ -235,10 +235,12 @@
     };
 
     PrivateClickMeasurement() = default;
-    PrivateClickMeasurement(SourceID sourceID, const SourceSite& sourceSite, const AttributeOnSite& attributeOnSite, WallTime timeOfAdClick = WallTime::now())
+    PrivateClickMeasurement(SourceID sourceID, const SourceSite& sourceSite, const AttributeOnSite& attributeOnSite, String&& sourceDescription = { }, String&& purchaser = { }, WallTime timeOfAdClick = WallTime::now())
         : m_sourceID { sourceID }
         , m_sourceSite { sourceSite }
         , m_attributeOnSite { attributeOnSite }
+        , m_sourceDescription { WTFMove(sourceDescription) }
+        , m_purchaser { WTFMove(purchaser) }
         , m_timeOfAdClick { timeOfAdClick }
     {
     }
@@ -254,10 +256,13 @@
     WallTime timeOfAdClick() const { return m_timeOfAdClick; }
     Optional<WallTime> earliestTimeToSend() const { return m_earliestTimeToSend; };
     void setEarliestTimeToSend(WallTime time) { m_earliestTimeToSend = time; }
-    SourceID sourceID() { return m_sourceID; }
+    const SourceID& sourceID() const { return m_sourceID; }
     Optional<AttributionTriggerData> attributionTriggerData() { return m_attributionTriggerData; }
     void setAttribution(AttributionTriggerData&& attributionTriggerData) { m_attributionTriggerData = WTFMove(attributionTriggerData); }
 
+    const String& sourceDescription() const { return m_sourceDescription; }
+    const String& purchaser() const { return m_purchaser; }
+
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static Optional<PrivateClickMeasurement> decode(Decoder&);
 
@@ -268,6 +273,8 @@
     SourceID m_sourceID;
     SourceSite m_sourceSite;
     AttributeOnSite m_attributeOnSite;
+    String m_sourceDescription;
+    String m_purchaser;
     WallTime m_timeOfAdClick;
 
     Optional<AttributionTriggerData> m_attributionTriggerData;
@@ -277,7 +284,14 @@
 template<class Encoder>
 void PrivateClickMeasurement::encode(Encoder& encoder) const
 {
-    encoder << m_sourceID.id << m_sourceSite.registrableDomain << m_attributeOnSite.registrableDomain << m_timeOfAdClick << m_attributionTriggerData << m_earliestTimeToSend;
+    encoder << m_sourceID.id
+        << m_sourceSite.registrableDomain
+        << m_attributeOnSite.registrableDomain
+        << m_sourceDescription
+        << m_purchaser
+        << m_timeOfAdClick
+        << m_attributionTriggerData
+        << m_earliestTimeToSend;
 }
 
 template<class Decoder>
@@ -298,6 +312,16 @@
     if (!attributeOnRegistrableDomain)
         return WTF::nullopt;
     
+    Optional<String> sourceDescription;
+    decoder >> sourceDescription;
+    if (!sourceDescription)
+        return WTF::nullopt;
+    
+    Optional<String> purchaser;
+    decoder >> purchaser;
+    if (!purchaser)
+        return WTF::nullopt;
+    
     Optional<WallTime> timeOfAdClick;
     decoder >> timeOfAdClick;
     if (!timeOfAdClick)
@@ -313,7 +337,14 @@
     if (!earliestTimeToSend)
         return WTF::nullopt;
     
-    PrivateClickMeasurement attribution { SourceID { WTFMove(*sourceID) }, SourceSite { WTFMove(*sourceRegistrableDomain) }, AttributeOnSite { WTFMove(*attributeOnRegistrableDomain) } };
+    PrivateClickMeasurement attribution {
+        SourceID { WTFMove(*sourceID) },
+        SourceSite { WTFMove(*sourceRegistrableDomain) },
+        AttributeOnSite { WTFMove(*attributeOnRegistrableDomain) },
+        WTFMove(*sourceDescription),
+        WTFMove(*purchaser),
+        WTFMove(*timeOfAdClick)
+    };
     attribution.m_attributionTriggerData = WTFMove(*attributionTriggerData);
     attribution.m_earliestTimeToSend = WTFMove(*earliestTimeToSend);
     

Modified: trunk/Source/WebKit/ChangeLog (270668 => 270669)


--- trunk/Source/WebKit/ChangeLog	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/ChangeLog	2020-12-11 07:41:15 UTC (rev 270669)
@@ -1,3 +1,33 @@
+2020-12-10  Alex Christensen  <[email protected]>
+
+        Accept click measurement data from hosting application
+        https://bugs.webkit.org/show_bug.cgi?id=219763
+        <rdar://problem/72121094>
+
+        Reviewed by John Wilander.
+
+        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
+        (WebKit::ResourceLoadStatisticsDatabaseStore::buildPrivateClickMeasurementFromDatabase):
+        * Platform/ios/UIKitSoftLink.h: Added.
+        * Platform/ios/UIKitSoftLink.mm: Added.
+        * Platform/spi/ios/UIKitSPI.h:
+        * SourcesCocoa.txt:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
+        * UIProcess/API/Cocoa/WKWebViewTesting.mm:
+        (-[WKWebView _setPrivateClickMeasurementOverrideTimerForTesting:completionHandler:]):
+        (-[WKWebView _setPrivateClickMeasurementConversionURLForTesting:completionHandler:]):
+        * UIProcess/API/ios/WKWebViewIOS.mm:
+        (-[WKWebView _setEventAttribution:]):
+        (-[WKWebView _eventAttribution]):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didCommitLoadForFrame):
+        (WebKit::WebPageProxy::createNewPage):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::setPrivateClickMeasurement):
+        (WebKit::WebPageProxy::privateClickMeasurement const):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2020-12-10  Peng Liu  <[email protected]>
 
         [Media in GPU Process][MSE] Implement several methods in SourceBufferPrivateRemote to make seeking more reliable

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp (270668 => 270669)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2020-12-11 07:41:15 UTC (rev 270669)
@@ -2939,7 +2939,7 @@
     auto sourceID = statement->getColumnInt(2);
     auto timeOfAdClick = attributionType == PrivateClickMeasurementAttributionType::Attributed ? statement->getColumnDouble(5) : statement->getColumnDouble(3);
 
-    PrivateClickMeasurement attribution(WebCore::PrivateClickMeasurement::SourceID(sourceID), WebCore::PrivateClickMeasurement::SourceSite(RegistrableDomain::uncheckedCreateFromRegistrableDomainString(sourceSiteDomain)), WebCore::PrivateClickMeasurement::AttributeOnSite(RegistrableDomain::uncheckedCreateFromRegistrableDomainString(attributeOnSiteDomain)), WallTime::fromRawSeconds(timeOfAdClick));
+    PrivateClickMeasurement attribution(WebCore::PrivateClickMeasurement::SourceID(sourceID), WebCore::PrivateClickMeasurement::SourceSite(RegistrableDomain::uncheckedCreateFromRegistrableDomainString(sourceSiteDomain)), WebCore::PrivateClickMeasurement::AttributeOnSite(RegistrableDomain::uncheckedCreateFromRegistrableDomainString(attributeOnSiteDomain)), { }, { }, WallTime::fromRawSeconds(timeOfAdClick));
     
     if (attributionType == PrivateClickMeasurementAttributionType::Attributed) {
         auto attributionTriggerData = statement->getColumnInt(3);

Added: trunk/Source/WebKit/Platform/ios/UIKitSoftLink.h (0 => 270669)


--- trunk/Source/WebKit/Platform/ios/UIKitSoftLink.h	                        (rev 0)
+++ trunk/Source/WebKit/Platform/ios/UIKitSoftLink.h	2020-12-11 07:41:15 UTC (rev 270669)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "UIKitSPI.h"
+#import <wtf/SoftLinking.h>
+
+SOFT_LINK_FRAMEWORK_FOR_HEADER(WebKit, UIKit)
+
+SOFT_LINK_CLASS_FOR_HEADER(WebKit, _UIEventAttribution);
+
+#endif

Added: trunk/Source/WebKit/Platform/ios/UIKitSoftLink.mm (0 => 270669)


--- trunk/Source/WebKit/Platform/ios/UIKitSoftLink.mm	                        (rev 0)
+++ trunk/Source/WebKit/Platform/ios/UIKitSoftLink.mm	2020-12-11 07:41:15 UTC (rev 270669)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "UIKitSPI.h"
+#import <wtf/SoftLinking.h>
+
+SOFT_LINK_FRAMEWORK_FOR_SOURCE(WebKit, UIKit)
+
+SOFT_LINK_CLASS_FOR_SOURCE(WebKit, UIKit, _UIEventAttribution)
+
+#endif

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (270668 => 270669)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-12-11 07:41:15 UTC (rev 270669)
@@ -1347,6 +1347,17 @@
 @property (nonatomic, setter=_setSuppressSoftwareKeyboard:) BOOL _suppressSoftwareKeyboard;
 @end
 
+@interface _UIEventAttribution : NSObject <NSCopying>
+@property (nonatomic, assign, readonly) uint8_t sourceIdentifier;
+@property (nonatomic, copy, readonly) NSURL *attributeOn;
+@property (nonatomic, /*nullable,*/ copy, readonly) NSURL *reportEndpoint;
+@property (nonatomic, copy, readonly) NSString *sourceDescription;
+@property (nonatomic, copy, readonly) NSString *purchaser;
+- (instancetype)initWithSourceIdentifier:(uint8_t)sourceIdentifier attributeOn:(NSURL *)attributeOn sourceDescription:(NSString *)sourceDescription purchaser:(NSString *)purchaser;
+- (instancetype)init NS_UNAVAILABLE;
++ (instancetype)new NS_UNAVAILABLE;
+@end
+
 @interface _UINavigationInteractiveTransitionBase ()
 - (void)_stopInteractiveTransition;
 @end

Modified: trunk/Source/WebKit/SourcesCocoa.txt (270668 => 270669)


--- trunk/Source/WebKit/SourcesCocoa.txt	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2020-12-11 07:41:15 UTC (rev 270669)
@@ -84,6 +84,7 @@
 
 Platform/ios/AccessibilityIOS.mm
 Platform/ios/PaymentAuthorizationController.mm
+Platform/ios/UIKitSoftLink.mm
 
 Platform/IPC/cocoa/ConnectionCocoa.mm
 Platform/IPC/cocoa/MachMessage.cpp

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (270668 => 270669)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2020-12-11 07:41:15 UTC (rev 270669)
@@ -112,6 +112,7 @@
 @class WKDownload;
 @class WKFrameInfo;
 @class WKWebpagePreferences;
+@class _UIEventAttribution;
 @class _WKApplicationManifest;
 @class _WKFrameHandle;
 @class _WKFrameTreeNode;
@@ -364,6 +365,8 @@
 
 @interface WKWebView (WKPrivateIOS)
 
+@property (nonatomic, copy, setter=_setEventAttribution:) _UIEventAttribution *_eventAttribution WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 @property (nonatomic, readonly) CGRect _contentVisibleRect WK_API_AVAILABLE(ios(10.0));
 
 // DERECATED: The setters of the three following function are deprecated, please use overrideLayoutParameters.

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h (270668 => 270669)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h	2020-12-11 07:41:15 UTC (rev 270669)
@@ -83,4 +83,8 @@
 - (void)_doAfterActivityStateUpdate:(void (^)(void))completionHandler;
 
 - (NSNumber *)_suspendMediaPlaybackCounter WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
+- (void)_setPrivateClickMeasurementOverrideTimerForTesting:(BOOL)overrideTimer completionHandler:(void(^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_setPrivateClickMeasurementConversionURLForTesting:(NSURL *)url completionHandler:(void(^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (270668 => 270669)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm	2020-12-11 07:41:15 UTC (rev 270669)
@@ -296,6 +296,20 @@
     return @(_page->suspendMediaPlaybackCounter());
 }
 
+- (void)_setPrivateClickMeasurementOverrideTimerForTesting:(BOOL)overrideTimer completionHandler:(void(^)(void))completionHandler
+{
+    _page->setPrivateClickMeasurementOverrideTimerForTesting(overrideTimer, [completionHandler = makeBlockPtr(completionHandler)] {
+        completionHandler();
+    });
+}
+
+- (void)_setPrivateClickMeasurementConversionURLForTesting:(NSURL *)url completionHandler:(void(^)(void))completionHandler
+{
+    _page->setPrivateClickMeasurementConversionURLForTesting(url, [completionHandler = makeBlockPtr(completionHandler)] {
+        completionHandler();
+    });
+}
+
 - (void)_didPresentContactPicker
 {
     // For subclasses to override.

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (270668 => 270669)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2020-12-11 07:41:15 UTC (rev 270669)
@@ -62,6 +62,8 @@
 #import "WKDataDetectorTypesInternal.h"
 #endif
 
+#include "UIKitSoftLink.h"
+
 #define FORWARD_ACTION_TO_WKCONTENTVIEW(_action) \
 - (void)_action:(id)sender \
 { \
@@ -2400,6 +2402,31 @@
 
 @implementation WKWebView (WKPrivateIOS)
 
+- (void)_setEventAttribution:(_UIEventAttribution *)attribution
+{
+    if (attribution) {
+        WebCore::PrivateClickMeasurement measurement(
+            WebCore::PrivateClickMeasurement::SourceID(attribution.sourceIdentifier),
+            WebCore::PrivateClickMeasurement::SourceSite(attribution.reportEndpoint),
+            WebCore::PrivateClickMeasurement::AttributeOnSite(attribution.attributeOn),
+            attribution.sourceDescription,
+            attribution.purchaser
+        );
+        _page->setPrivateClickMeasurement(WTFMove(measurement));
+    } else
+        _page->setPrivateClickMeasurement(WTF::nullopt);
+}
+
+- (_UIEventAttribution *)_eventAttribution
+{
+    auto& measurement = _page->privateClickMeasurement();
+    if (!measurement || !measurement->sourceID().isValid())
+        return nil;
+
+    auto attributeOnURL = URL(URL(), makeString("https://", measurement->attributeOnSite().registrableDomain.string()));
+    return [[WebKit::alloc_UIEventAttributionInstance() initWithSourceIdentifier:measurement->sourceID().id attributeOn:attributeOnURL sourceDescription:measurement->sourceDescription() purchaser:measurement->purchaser()] autorelease];
+}
+
 - (CGRect)_contentVisibleRect
 {
     return [self convertRect:[self bounds] toView:self._currentContentView];

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (270668 => 270669)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-12-11 07:41:15 UTC (rev 270669)
@@ -4679,8 +4679,8 @@
 
     if (frame->isMainFrame()) {
         Optional<WebCore::PrivateClickMeasurement> privateClickMeasurement;
-        if (m_newPageNavigationPrivateClickMeasurement)
-            privateClickMeasurement = m_newPageNavigationPrivateClickMeasurement;
+        if (m_privateClickMeasurement)
+            privateClickMeasurement = m_privateClickMeasurement;
         else if (navigation && navigation->privateClickMeasurement())
             privateClickMeasurement = navigation->privateClickMeasurement();
         if (privateClickMeasurement) {
@@ -4688,7 +4688,7 @@
                 websiteDataStore().networkProcess().send(Messages::NetworkProcess::StorePrivateClickMeasurement(m_websiteDataStore->sessionID(), *privateClickMeasurement), 0);
         }
     }
-    m_newPageNavigationPrivateClickMeasurement.reset();
+    m_privateClickMeasurement.reset();
 
     if (frame->isMainFrame()) {
         m_mainFrameHasCustomContentProvider = frameHasCustomContentProvider;
@@ -5561,7 +5561,7 @@
 
         newPage->m_shouldSuppressAppLinksInNextNavigationPolicyDecision = mainFrameURL.host() == request.url().host();
 
-        newPage->m_newPageNavigationPrivateClickMeasurement = privateClickMeasurement;
+        newPage->m_privateClickMeasurement = privateClickMeasurement;
 #if HAVE(APP_SSO)
         newPage->m_shouldSuppressSOAuthorizationInNextNavigationPolicyDecision = true;
 #endif

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (270668 => 270669)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-12-11 07:41:15 UTC (rev 270669)
@@ -672,6 +672,9 @@
     void setDelegatesScrolling(bool delegatesScrolling) { m_delegatesScrolling = delegatesScrolling; }
     bool delegatesScrolling() const { return m_delegatesScrolling; }
 
+    void setPrivateClickMeasurement(Optional<WebCore::PrivateClickMeasurement>&& measurement) { m_privateClickMeasurement = WTFMove(measurement); }
+    const Optional<WebCore::PrivateClickMeasurement>& privateClickMeasurement() const { return m_privateClickMeasurement; }
+
     enum class ActivityStateChangeDispatchMode : bool { Deferrable, Immediate };
     enum class ActivityStateChangeReplyMode : bool { Asynchronous, Synchronous };
     void activityStateDidChange(OptionSet<WebCore::ActivityState::Flag> mayHaveChanged, ActivityStateChangeDispatchMode = ActivityStateChangeDispatchMode::Deferrable, ActivityStateChangeReplyMode = ActivityStateChangeReplyMode::Asynchronous);
@@ -2905,7 +2908,7 @@
 
     size_t m_suspendMediaPlaybackCounter { 0 };
 
-    Optional<WebCore::PrivateClickMeasurement> m_newPageNavigationPrivateClickMeasurement;
+    Optional<WebCore::PrivateClickMeasurement> m_privateClickMeasurement;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (270668 => 270669)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-12-11 07:41:15 UTC (rev 270669)
@@ -5637,6 +5637,8 @@
 		DF74275C24F4955000F8ABE9 /* PDFPluginIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFPluginIdentifier.h; sourceTree = "<group>"; };
 		DF84CEE2249AA21F009096F6 /* WKPDFHUDView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKPDFHUDView.mm; path = PDF/WKPDFHUDView.mm; sourceTree = "<group>"; };
 		DF84CEE3249AA21F009096F6 /* WKPDFHUDView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKPDFHUDView.h; path = PDF/WKPDFHUDView.h; sourceTree = "<group>"; };
+		DF8523BA2583176F00AEADD0 /* UIKitSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIKitSoftLink.h; sourceTree = "<group>"; };
+		DF8523BB258317A900AEADD0 /* UIKitSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIKitSoftLink.mm; sourceTree = "<group>"; };
 		E105FE5318D7B9DE008F57A8 /* EditingRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditingRange.h; sourceTree = "<group>"; };
 		E133FD891423DD7F00FC7BFB /* WebKit.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = WebKit.icns; path = Resources/WebKit.icns; sourceTree = "<group>"; };
 		E14A954716E016A40068DE82 /* NetworkProcessPlatformStrategies.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkProcessPlatformStrategies.cpp; sourceTree = "<group>"; };
@@ -9304,6 +9306,8 @@
 				A182D5B21BE6BD250087A7CC /* AccessibilityIOS.mm */,
 				A1798B4F2230A0FE000764BD /* PaymentAuthorizationController.h */,
 				A1798B502230A0FE000764BD /* PaymentAuthorizationController.mm */,
+				DF8523BA2583176F00AEADD0 /* UIKitSoftLink.h */,
+				DF8523BB258317A900AEADD0 /* UIKitSoftLink.mm */,
 			);
 			path = ios;
 			sourceTree = "<group>";

Modified: trunk/Tools/ChangeLog (270668 => 270669)


--- trunk/Tools/ChangeLog	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Tools/ChangeLog	2020-12-11 07:41:15 UTC (rev 270669)
@@ -1,3 +1,19 @@
+2020-12-10  Alex Christensen  <[email protected]>
+
+        Accept click measurement data from hosting application
+        https://bugs.webkit.org/show_bug.cgi?id=219763
+        <rdar://problem/72121094>
+
+        Reviewed by John Wilander.
+
+        * TestWebKitAPI/SourcesCocoa.txt:
+        * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
+        (testCertificate):
+        * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: Added.
+        (-[MockEventAttribution initWithReportEndpoint:attributeOn:]):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/cocoa/HTTPServer.h:
+
 2020-12-10  Chris Dumez  <[email protected]>
 
         [GPUProcess] Cut in half amount of IPC needed to do WebAudio

Modified: trunk/Tools/TestWebKitAPI/SourcesCocoa.txt (270668 => 270669)


--- trunk/Tools/TestWebKitAPI/SourcesCocoa.txt	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Tools/TestWebKitAPI/SourcesCocoa.txt	2020-12-11 07:41:15 UTC (rev 270669)
@@ -33,4 +33,5 @@
 cocoa/TestUIDelegate.mm
 cocoa/TestWKWebView.mm
 
+Tests/WebKitCocoa/EventAttribution.mm
 Tests/WebKitCocoa/TLSDeprecation.mm

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm (270668 => 270669)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm	2020-12-11 07:41:15 UTC (rev 270669)
@@ -47,7 +47,7 @@
 
 static bool navigationFinished;
 
-static RetainPtr<SecCertificateRef> testCertificate()
+RetainPtr<SecCertificateRef> testCertificate()
 {
     auto certificateBytes = TestWebKitAPI::TCPServer::testCertificate();
     return adoptCF(SecCertificateCreateWithData(nullptr, (__bridge CFDataRef)[NSData dataWithBytes:certificateBytes.data() length:certificateBytes.size()]));

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm (0 => 270669)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm	2020-12-11 07:41:15 UTC (rev 270669)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "HTTPServer.h"
+#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
+#import "Utilities.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WKWebViewPrivateForTesting.h>
+#import <WebKit/WKWebsiteDataStorePrivate.h>
+
+@interface MockEventAttribution : NSObject
+
+@property (nonatomic, assign, readonly) uint8_t sourceIdentifier;
+@property (nonatomic, copy, readonly) NSURL *attributeOn;
+@property (nonatomic, copy, readonly) NSURL *reportEndpoint;
+@property (nonatomic, copy, readonly) NSString *sourceDescription;
+@property (nonatomic, copy, readonly) NSString *purchaser;
+- (instancetype)initWithReportEndpoint:(NSURL *)reportEndpoint attributeOn:(NSURL *)attributeOn;
+
+@end
+
+@implementation MockEventAttribution
+
+- (instancetype)initWithReportEndpoint:(NSURL *)reportEndpoint attributeOn:(NSURL *)attributeOn
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _sourceIdentifier = 42;
+    _attributeOn = attributeOn;
+    _reportEndpoint = reportEndpoint;
+    _sourceDescription = @"test source description";
+    _purchaser = @"test purchaser";
+
+    return self;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+TEST(EventAttribution, Basic)
+{
+    bool done = false;
+    HTTPServer server([&done, connectionCount = 0] (Connection connection) mutable {
+        switch (++connectionCount) {
+        case 1:
+            connection.receiveHTTPRequest([connection] (Vector<char>&& request1) {
+                EXPECT_TRUE(strnstr(request1.data(), "GET /conversionRequestBeforeRedirect HTTP/1.1\r\n", request1.size()));
+                const char* redirect = "HTTP/1.1 302 Found\r\n"
+                    "Location: /.well-known/private-click-measurement/12\r\n"
+                    "Content-Length: 0\r\n\r\n";
+                connection.send(redirect, [connection] {
+                    connection.receiveHTTPRequest([connection] (Vector<char>&& request2) {
+                        EXPECT_TRUE(strnstr(request2.data(), "GET /.well-known/private-click-measurement/12 HTTP/1.1\r\n", request2.size()));
+                        const char* response = "HTTP/1.1 200 OK\r\n"
+                            "Content-Length: 0\r\n\r\n";
+                        connection.send(response);
+                    });
+                });
+            });
+            break;
+        case 2:
+            connection.receiveHTTPRequest([&done] (Vector<char>&& request3) {
+                request3.append('\0');
+                EXPECT_TRUE(strnstr(request3.data(), "POST / HTTP/1.1\r\n", request3.size()));
+                const char* bodyBegin = strnstr(request3.data(), "\r\n\r\n", request3.size()) + strlen("\r\n\r\n");
+                EXPECT_STREQ(bodyBegin, "{\"source_engagement_type\":\"click\",\"source_site\":\"127.0.0.1\",\"source_id\":42,\"attributed_on_site\":\"example.com\",\"trigger_data\":12,\"version\":1}");
+                done = true;
+            });
+            break;
+        }
+    }, HTTPServer::Protocol::Https);
+    NSURL *serverURL = server.request().URL;
+
+    auto exampleURL = [NSURL URLWithString:@"https://example.com/"];
+    auto attribution = [[[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL attributeOn:exampleURL] autorelease];
+    auto webView = [[WKWebView new] autorelease];
+    webView._eventAttribution = (_UIEventAttribution *)attribution;
+    [webView.configuration.websiteDataStore _setResourceLoadStatisticsEnabled:YES];
+    [webView.configuration.websiteDataStore _allowTLSCertificateChain:@[(id)testCertificate().get()] forHost:serverURL.host];
+    [webView _setPrivateClickMeasurementConversionURLForTesting:serverURL completionHandler:^{
+        [webView _setPrivateClickMeasurementOverrideTimerForTesting:YES completionHandler:^{
+            NSString *html = [NSString stringWithFormat:@"<script>fetch('%@conversionRequestBeforeRedirect',{mode:'no-cors'})</script>", serverURL];
+            [webView loadHTMLString:html baseURL:exampleURL];
+        }];
+    }];
+    Util::run(&done);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h (270668 => 270669)


--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h	2020-12-11 07:11:01 UTC (rev 270668)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h	2020-12-11 07:41:15 UTC (rev 270669)
@@ -165,5 +165,6 @@
 
 } // namespace TestWebKitAPI
 
+RetainPtr<SecCertificateRef> testCertificate();
 RetainPtr<SecIdentityRef> testIdentity();
 RetainPtr<SecIdentityRef> testIdentity2();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to