Add setters on WKWebsiteDataStore for sourceApplicationBundleIdentifier and sourceApp...
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Mar 2019 02:27:21 +0000 (02:27 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Mar 2019 02:27:21 +0000 (02:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195229
<rdar://problem/48520362>

Reviewed by Chris Dumez.

Source/WebKit:

Just like _setBoundInterfaceIdentifier, we need a way to set these properties after instantiation of a WKWebsiteDataStore,
but we need to make sure we don't set it after the parameters have been copied to the NetworkProcess.

Functionality verified by manual testing.  See radar.
Added an API test that verifies the setter restrictions work as expected.

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _sourceApplicationBundleIdentifier]):
(-[WKWebsiteDataStore _setSourceApplicationBundleIdentifier:]):
(-[WKWebsiteDataStore _sourceApplicationSecondaryIdentifier]):
(-[WKWebsiteDataStore _setSourceApplicationSecondaryIdentifier:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::toPKPaymentRequest):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::WebsiteDataStore):
(WebKit::WebsiteDataStore::setSourceApplicationSecondaryIdentifier):
(WebKit::WebsiteDataStore::setSourceApplicationBundleIdentifier):
* UIProcess/WebsiteData/WebsiteDataStore.h:
(WebKit::WebsiteDataStore::sourceApplicationBundleIdentifier):
(WebKit::WebsiteDataStore::sourceApplicationSecondaryIdentifier):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm

index a3c29ac..d862d95 100644 (file)
@@ -1,3 +1,35 @@
+2019-03-01  Alex Christensen  <achristensen@webkit.org>
+
+        Add setters on WKWebsiteDataStore for sourceApplicationBundleIdentifier and sourceApplicationSecondaryIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=195229
+        <rdar://problem/48520362>
+
+        Reviewed by Chris Dumez.
+
+        Just like _setBoundInterfaceIdentifier, we need a way to set these properties after instantiation of a WKWebsiteDataStore,
+        but we need to make sure we don't set it after the parameters have been copied to the NetworkProcess.
+
+        Functionality verified by manual testing.  See radar.
+        Added an API test that verifies the setter restrictions work as expected.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _sourceApplicationBundleIdentifier]):
+        (-[WKWebsiteDataStore _setSourceApplicationBundleIdentifier:]):
+        (-[WKWebsiteDataStore _sourceApplicationSecondaryIdentifier]):
+        (-[WKWebsiteDataStore _setSourceApplicationSecondaryIdentifier:]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
+        (WebKit::toPKPaymentRequest):
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::WebsiteDataStore):
+        (WebKit::WebsiteDataStore::setSourceApplicationSecondaryIdentifier):
+        (WebKit::WebsiteDataStore::setSourceApplicationBundleIdentifier):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        (WebKit::WebsiteDataStore::sourceApplicationBundleIdentifier):
+        (WebKit::WebsiteDataStore::sourceApplicationSecondaryIdentifier):
+
 2019-03-01  Antoine Quint  <graouts@apple.com>
 
         [iOS] Turn mouse event simulation on by default
index 9540d72..3f57c1e 100644 (file)
@@ -363,6 +363,28 @@ static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecor
     _websiteDataStore->websiteDataStore().setProxyConfiguration((__bridge CFDictionaryRef)configuration);
 }
 
+- (NSString *)_sourceApplicationBundleIdentifier
+{
+    return _websiteDataStore->websiteDataStore().sourceApplicationBundleIdentifier();
+}
+
+- (void)_setSourceApplicationBundleIdentifier:(NSString *)identifier
+{
+    if (!_websiteDataStore->websiteDataStore().setSourceApplicationBundleIdentifier(identifier))
+        [NSException raise:NSGenericException format:@"_setSourceApplicationBundleIdentifier cannot be called after networking has begun"];
+}
+
+- (NSString *)_sourceApplicationSecondaryIdentifier
+{
+    return _websiteDataStore->websiteDataStore().sourceApplicationSecondaryIdentifier();
+}
+
+- (void)_setSourceApplicationSecondaryIdentifier:(NSString *)identifier
+{
+    if (!_websiteDataStore->websiteDataStore().setSourceApplicationSecondaryIdentifier(identifier))
+        [NSException raise:NSGenericException format:@"_setSourceApplicationSecondaryIdentifier cannot be called after networking has begun"];
+}
+
 - (NSDictionary *)_proxyConfiguration
 {
     return (__bridge NSDictionary *)_websiteDataStore->websiteDataStore().proxyConfiguration();
index 88de4f3..b3ca718 100644 (file)
@@ -57,6 +57,8 @@ typedef NS_OPTIONS(NSUInteger, _WKWebsiteDataStoreFetchOptions) {
 @property (nonatomic, setter=_setBoundInterfaceIdentifier:) NSString *_boundInterfaceIdentifier WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
 @property (nonatomic, setter=_setAllowsCellularAccess:) BOOL _allowsCellularAccess WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
 @property (nonatomic, setter=_setProxyConfiguration:) NSDictionary *_proxyConfiguration WK_API_AVAILABLE(macosx(10.14), ios(12.0));
+@property (nonatomic, copy, setter=_setSourceApplicationBundleIdentifier:) NSString *_sourceApplicationBundleIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, copy, setter=_setSourceApplicationSecondaryIdentifier:) NSString *_sourceApplicationSecondaryIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @property (nonatomic, readonly) NSURL *_indexedDBDatabaseDirectory;
 
index eaf5bcd..331054d 100644 (file)
@@ -506,13 +506,13 @@ RetainPtr<PKPaymentRequest> toPKPaymentRequest(WebPageProxy& webPageProxy, const
 #endif
 
     // FIXME: Instead of using respondsToSelector, this should use a proper #if version check.
-    auto& configuration = webPageProxy.websiteDataStore().configuration();
+    auto& websiteDataStore = webPageProxy.websiteDataStore();
 
-    if (!configuration.sourceApplicationBundleIdentifier().isEmpty() && [result respondsToSelector:@selector(setSourceApplicationBundleIdentifier:)])
-        [result setSourceApplicationBundleIdentifier:configuration.sourceApplicationBundleIdentifier()];
+    if (!websiteDataStore.sourceApplicationBundleIdentifier().isEmpty() && [result respondsToSelector:@selector(setSourceApplicationBundleIdentifier:)])
+        [result setSourceApplicationBundleIdentifier:websiteDataStore.sourceApplicationBundleIdentifier()];
 
-    if (!configuration.sourceApplicationSecondaryIdentifier().isEmpty() && [result respondsToSelector:@selector(setSourceApplicationSecondaryIdentifier:)])
-        [result setSourceApplicationSecondaryIdentifier:configuration.sourceApplicationSecondaryIdentifier()];
+    if (!websiteDataStore.sourceApplicationSecondaryIdentifier().isEmpty() && [result respondsToSelector:@selector(setSourceApplicationSecondaryIdentifier:)])
+        [result setSourceApplicationSecondaryIdentifier:websiteDataStore.sourceApplicationSecondaryIdentifier()];
 
 #if PLATFORM(IOS_FAMILY)
     if (!webPageProxy.process().processPool().configuration().ctDataConnectionServiceType().isEmpty() && [result respondsToSelector:@selector(setCTDataConnectionServiceType:)])
index 68a13fd..a0934b7 100644 (file)
@@ -490,6 +490,9 @@ NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* with
     if (m_websiteDataStore) {
         parameters.defaultDataStoreParameters.pendingCookies = copyToVector(m_websiteDataStore->websiteDataStore().pendingCookies());
         m_websiteDataStore->websiteDataStore().clearPendingCookies();
+        parameters.defaultDataStoreParameters.networkSessionParameters.sourceApplicationBundleIdentifier = m_websiteDataStore->websiteDataStore().sourceApplicationBundleIdentifier();
+        parameters.defaultDataStoreParameters.networkSessionParameters.sourceApplicationSecondaryIdentifier = m_websiteDataStore->websiteDataStore().sourceApplicationSecondaryIdentifier();
+        m_websiteDataStore->websiteDataStore().finalizeApplicationIdentifiers();
     }
 
     parameters.cacheModel = cacheModel();
index fcb89aa..3acf50c 100644 (file)
@@ -94,8 +94,8 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
         m_boundInterfaceIdentifier,
         m_allowsCellularAccess,
         m_proxyConfiguration,
-        m_configuration->sourceApplicationBundleIdentifier(),
-        m_configuration->sourceApplicationSecondaryIdentifier(),
+        m_sourceApplicationBundleIdentifier,
+        m_sourceApplicationSecondaryIdentifier,
         shouldLogCookieInformation,
         Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. },
         WTFMove(httpProxy),
@@ -104,6 +104,7 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
         WTFMove(resourceLoadStatisticsDirectoryHandle),
         false
     };
+    finalizeApplicationIdentifiers();
 
     auto cookieFile = resolvedCookieStorageFile();
 
@@ -115,8 +116,8 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
     }
 
     parameters.uiProcessCookieStorageIdentifier = m_uiProcessCookieStorageIdentifier;
-    parameters.networkSessionParameters.sourceApplicationBundleIdentifier = m_configuration->sourceApplicationBundleIdentifier();
-    parameters.networkSessionParameters.sourceApplicationSecondaryIdentifier = m_configuration->sourceApplicationSecondaryIdentifier();
+    parameters.networkSessionParameters.sourceApplicationBundleIdentifier = m_sourceApplicationBundleIdentifier;
+    parameters.networkSessionParameters.sourceApplicationSecondaryIdentifier = m_sourceApplicationSecondaryIdentifier;
 
     parameters.pendingCookies = copyToVector(m_pendingCookies);
 
index 728324d..edd7663 100644 (file)
@@ -98,6 +98,8 @@ WebsiteDataStore::WebsiteDataStore(Ref<WebsiteDataStoreConfiguration>&& configur
     , m_storageManager(StorageManager::create(m_configuration->localStorageDirectory()))
     , m_deviceIdHashSaltStorage(DeviceIdHashSaltStorage::create(isPersistent() ? m_configuration->deviceIdHashSaltsStorageDirectory() : String()))
     , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
+    , m_sourceApplicationBundleIdentifier(m_configuration->sourceApplicationBundleIdentifier())
+    , m_sourceApplicationSecondaryIdentifier(m_configuration->sourceApplicationSecondaryIdentifier())
 #if ENABLE(WEB_AUTHN)
     , m_authenticatorManager(makeUniqueRef<AuthenticatorManager>())
 #endif
@@ -2101,4 +2103,20 @@ void WebsiteDataStore::didCreateNetworkProcess()
 {
 }
 
+bool WebsiteDataStore::setSourceApplicationSecondaryIdentifier(String&& identifier)
+{
+    if (!m_allowedToSetApplicationIdentifiers)
+        return false;
+    m_sourceApplicationSecondaryIdentifier = WTFMove(identifier);
+    return true;
+}
+
+bool WebsiteDataStore::setSourceApplicationBundleIdentifier(String&& identifier)
+{
+    if (!m_allowedToSetApplicationIdentifiers)
+        return false;
+    m_sourceApplicationBundleIdentifier = WTFMove(identifier);
+    return true;
+}
+
 }
index 0c635cf..e375d15 100644 (file)
@@ -200,6 +200,14 @@ public:
 
     void setBoundInterfaceIdentifier(String&& identifier) { m_boundInterfaceIdentifier = WTFMove(identifier); }
     const String& boundInterfaceIdentifier() { return m_boundInterfaceIdentifier; }
+
+    const String& sourceApplicationBundleIdentifier() const { return m_sourceApplicationBundleIdentifier; }
+    bool setSourceApplicationBundleIdentifier(String&&);
+
+    const String& sourceApplicationSecondaryIdentifier() const { return m_sourceApplicationSecondaryIdentifier; }
+    bool setSourceApplicationSecondaryIdentifier(String&&);
+    
+    void finalizeApplicationIdentifiers() { m_allowedToSetApplicationIdentifiers = false; }
     
     void setAllowsCellularAccess(AllowsCellularAccess allows) { m_allowsCellularAccess = allows; }
     AllowsCellularAccess allowsCellularAccess() { return m_allowsCellularAccess; }
@@ -304,6 +312,9 @@ private:
 
     String m_boundInterfaceIdentifier;
     AllowsCellularAccess m_allowsCellularAccess { AllowsCellularAccess::Yes };
+    String m_sourceApplicationBundleIdentifier;
+    String m_sourceApplicationSecondaryIdentifier;
+    bool m_allowedToSetApplicationIdentifiers { true };
 
 #if HAVE(SEC_KEY_PROXY)
     Vector<Ref<SecKeyProxyStore>> m_secKeyProxyStores;
index ec4f305..5b59fb4 100644 (file)
@@ -1,3 +1,14 @@
+2019-03-01  Alex Christensen  <achristensen@webkit.org>
+
+        Add setters on WKWebsiteDataStore for sourceApplicationBundleIdentifier and sourceApplicationSecondaryIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=195229
+        <rdar://problem/48520362>
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+        (TEST):
+
 2019-03-01  Simon Fraser  <simon.fraser@apple.com>
 
         Add a system trace scope for event region building
index fa1d9f8..1f4b801 100644 (file)
@@ -28,6 +28,7 @@
 #import "PlatformUtilities.h"
 #import "Test.h"
 #import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
 #import <WebKit/WKPreferencesRef.h>
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUserContentControllerPrivate.h>
@@ -452,4 +453,29 @@ TEST(WebKit, DoLoadWithNonDefaultDataStoreAfterTerminatingNetworkProcess)
     [webView _test_waitForDidFinishNavigation];
 }
 
+TEST(WebKit, ApplicationIdentifiers)
+{
+    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+    [websiteDataStoreConfiguration setSourceApplicationBundleIdentifier:@"testidentifier"];
+
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()] autorelease];
+    EXPECT_TRUE([websiteDataStore._sourceApplicationBundleIdentifier isEqualToString:@"testidentifier"]);
+    [websiteDataStore _setSourceApplicationBundleIdentifier:@"otheridentifier"];
+
+    [webViewConfiguration setWebsiteDataStore:websiteDataStore];
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    
+    RetainPtr<NSException> exception;
+    @try {
+        [websiteDataStore _setSourceApplicationBundleIdentifier:@"settingShouldFailNow"];
+    } @catch(NSException *caught) {
+        exception = caught;
+    }
+    EXPECT_TRUE([[exception reason] isEqualToString:@"_setSourceApplicationBundleIdentifier cannot be called after networking has begun"]);
+    EXPECT_TRUE([websiteDataStore._sourceApplicationBundleIdentifier isEqualToString:@"otheridentifier"]);
+    EXPECT_TRUE([[websiteDataStoreConfiguration sourceApplicationBundleIdentifier] isEqualToString:@"testidentifier"]);
+}
+
 #endif