Title: [264178] trunk/Source
Revision
264178
Author
[email protected]
Date
2020-07-09 10:06:14 -0700 (Thu, 09 Jul 2020)

Log Message

[Cocoa] Update Launch Services database in the WebContent process from the Network process
https://bugs.webkit.org/show_bug.cgi?id=213794

Reviewed by Brent Fulgham.

Source/WebCore/PAL:

Declare interface for observing and consuming the Launch Services database.

* pal/spi/cocoa/LaunchServicesSPI.h:

Source/WebKit:

To be able to deny mach lookup access to the Launch Services database mapping service in the WebContent process, the database needs to be
sent from the Networking process to the WebContent process, represented by an xpc object. The Networking process is chosen instead of the UI
process, since WebKit is controlling the sandbox of the Networking process. There is already a direct connection between the Networking
process and the WebContent process, but this is a CoreIPC connection. Since the database is represented by an xpc object, an xpc connection
is requiered to transfer the database. This patch creates a direct xpc connection between the Networking process and the WebContent process,
by creating an xpc endpoint in the Networking process, sending this to the UI process over the bootstrap xpc connection, and then providing
each WebContent process with this endpoint by sending it over the bootstrap xpc connection between the UI process and the WebContent process.
This endpoint has to be sent via the xpc connections to the UI process, since the already existing direct connection between the Networking
process and the WebContent process is a lower level CoreIPC connection, which does not support transferring xpc objects like the xpc endpoint.
When the WebContent process receives the endpoint, it will create an xpc connection from the endpoint, which will create a direct connection
with the Networking process. A message is then sent over the connection to request the database xpc object. When the Networking process
receives this message, it checks the entitlement of the remote end to make sure it is communicating with a WebContent process, and then sends
the database if the entitlement check succeeds. When the WebContent process receives this message, it performs an entitlement check as well,
and if successful, the database object is consumed. Consuming this database object, will make sure UTI to MIME type mapping is working
correctly in the WebContent process.

For the UI process to be able to pick up xpc messages on the bootstrap connection, a new virtual method, handleXPCEvent, is added to the
ProcessLauncher Client class. This way, a ProcessLauncher client will be able to pick up xpc messages from the xpc bootstrap connection.
Previously the event handler for the bootstrap connection in the UI process would handle only xpc error messages. It has now been expanded
to handle normal messages, which are being forwarded to the ProcessLauncher client. In this case the client is the Network process proxy,
which will check the message received, and if it turns out to be a message containing an xpc endpoint, the message will be forwarded to
all Web processes. The ProcessLauncher client can be expanded to handle any xpc message, but right not the Network process proxy only
handles the xpc endpoint message. The handleXPCEvent virtual method return a RefPtr to an XPCEventHandler, which is captured in the event
handler of the bootstrap xpc connection.

No new tests, since there already exist tests for this. UTI to MIME type mapping is being used in WebKit and underlying framework, and many
tests would fail if this mapping was not working.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeConnection):
* NetworkProcess/cocoa/LaunchServicesDatabaseObserver.h: Added.
* NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm: Added.
(WebKit::LaunchServicesDatabaseObserver::singleton):
(WebKit::LaunchServicesDatabaseObserver::LaunchServicesDatabaseObserver):
(WebKit::LaunchServicesDatabaseObserver::startObserving):
(WebKit::LaunchServicesDatabaseObserver::~LaunchServicesDatabaseObserver):
(WebKit::LaunchServicesDatabaseObserver::xpcEndpointMessageNameKey const):
(WebKit::LaunchServicesDatabaseObserver::xpcEndpointMessageName const):
(WebKit::LaunchServicesDatabaseObserver::xpcEndpointNameKey const):
(WebKit::LaunchServicesDatabaseObserver::handleEvent):
* Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
* Scripts/process-entitlements.sh:
* Shared/Cocoa/LaunchServicesDatabaseXPCConstants.h: Added.
* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
* SourcesCocoa.txt:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::xpcEndpointMessage const):
(WebKit::WebProcessPool::sendNetworkProcessXPCEndpointToWebProcess):
* UIProcess/Cocoa/XPCEventHandler.h: Added.
(WebKit::XPCEventHandler::~XPCEventHandler):
* UIProcess/Launcher/ProcessLauncher.h:
(WebKit::ProcessLauncher::Client::xpcEventHandler const):
* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::ProcessLauncher::launchProcess):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/Network/NetworkProcessProxyCocoa.mm: Added.
(WebKit::NetworkProcessProxy::xpcEventHandler const):
(WebKit::NetworkProcessProxy::XPCEventHandler::handleXPCEvent const):
(WebKit::NetworkProcessProxy::XPCEventHandler::XPCEventHandler):
(WebKit::NetworkProcessProxy::XPCEventHandler::~XPCEventHandler):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didFinishLaunching):
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::platformDidReceiveLoadParameters):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeConnection):
* WebProcess/WebProcess.h:
* WebProcess/cocoa/LaunchServicesDatabaseManager.h: Added.
* WebProcess/cocoa/LaunchServicesDatabaseManager.mm: Added.
(WebKit::LaunchServicesDatabaseManager::singleton):
(WebKit::LaunchServicesDatabaseManager::handleEvent):
(WebKit::LaunchServicesDatabaseManager::didConnect):
(WebKit::LaunchServicesDatabaseManager::waitForDatabaseUpdate):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::handleXPCEndpointMessages const):
(WebKit::WebProcess::platformInitializeWebProcess):

Source/WTF:

Added HAVE define for determining if the class LSDatabaseContext is present.

* wtf/PlatformHave.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (264177 => 264178)


--- trunk/Source/WTF/ChangeLog	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WTF/ChangeLog	2020-07-09 17:06:14 UTC (rev 264178)
@@ -1,3 +1,14 @@
+2020-07-09  Per Arne Vollan  <[email protected]>
+
+        [Cocoa] Update Launch Services database in the WebContent process from the Network process
+        https://bugs.webkit.org/show_bug.cgi?id=213794
+
+        Reviewed by Brent Fulgham.
+
+        Added HAVE define for determining if the class LSDatabaseContext is present.
+
+        * wtf/PlatformHave.h:
+
 2020-07-09  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r264148.

Modified: trunk/Source/WTF/wtf/PlatformHave.h (264177 => 264178)


--- trunk/Source/WTF/wtf/PlatformHave.h	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -672,3 +672,10 @@
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101600
 #define HAVE_APP_ACCENT_COLORS 1
 #endif
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101600) \
+    || ((PLATFORM(IOS) || PLATFORM(MACCATALYST)) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) \
+    || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 70000) \
+    || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 140000)
+#define HAVE_LSDATABASECONTEXT 1
+#endif

Modified: trunk/Source/WebCore/PAL/ChangeLog (264177 => 264178)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-07-09 17:06:14 UTC (rev 264178)
@@ -1,3 +1,14 @@
+2020-07-09  Per Arne Vollan  <[email protected]>
+
+        [Cocoa] Update Launch Services database in the WebContent process from the Network process
+        https://bugs.webkit.org/show_bug.cgi?id=213794
+
+        Reviewed by Brent Fulgham.
+
+        Declare interface for observing and consuming the Launch Services database.
+
+        * pal/spi/cocoa/LaunchServicesSPI.h:
+
 2020-07-09  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r264148.

Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h (264177 => 264178)


--- trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -25,16 +25,10 @@
 
 #import <Foundation/Foundation.h>
 
+#include <wtf/spi/darwin/XPCSPI.h>
+
 #if USE(APPLE_INTERNAL_SDK)
-
-#if PLATFORM(MAC)
 #import <CoreServices/CoreServicesPriv.h>
-#elif PLATFORM(IOS_FAMILY)
-#import <MobileCoreServices/LSAppLinkPriv.h>
-#elif PLATFORM(IOS)
-#import <MobileCoreServices/MobileCoreServicesPriv.h>
-#endif
-
 #endif // USE(APPLE_INTERNAL_SDK)
 
 #if HAVE(APP_LINKS)
@@ -83,15 +77,22 @@
 };
 #endif
 
+#if HAVE(LSDATABASECONTEXT)
+@interface LSDatabaseContext : NSObject
+@property (class, readonly) LSDatabaseContext *sharedDatabaseContext;
+@end
+#endif
+
 #endif // !USE(APPLE_INTERNAL_SDK)
 
-@interface _LSDService : NSObject <NSXPCListenerDelegate>
-+ (NSXPCConnection *)XPCConnectionToService;
+#if HAVE(LSDATABASECONTEXT)
+@interface LSDatabaseContext (WebKitChangeTracking)
+- (id <NSObject>)addDatabaseChangeObserver4WebKit:(void (^)(xpc_object_t change))observer;
+- (void)removeDatabaseChangeObserver4WebKit:(id <NSObject>)token;
+- (void)observeDatabaseChange4WebKit:(xpc_object_t)change;
 @end
+#endif
 
-@interface _LSDReadService : _LSDService
-@end
-
 #if PLATFORM(MAC)
 
 typedef const struct CF_BRIDGED_TYPE(id) __LSASN* LSASNRef;

Modified: trunk/Source/WebKit/ChangeLog (264177 => 264178)


--- trunk/Source/WebKit/ChangeLog	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/ChangeLog	2020-07-09 17:06:14 UTC (rev 264178)
@@ -1,3 +1,89 @@
+2020-07-09  Per Arne Vollan  <[email protected]>
+
+        [Cocoa] Update Launch Services database in the WebContent process from the Network process
+        https://bugs.webkit.org/show_bug.cgi?id=213794
+
+        Reviewed by Brent Fulgham.
+
+        To be able to deny mach lookup access to the Launch Services database mapping service in the WebContent process, the database needs to be
+        sent from the Networking process to the WebContent process, represented by an xpc object. The Networking process is chosen instead of the UI
+        process, since WebKit is controlling the sandbox of the Networking process. There is already a direct connection between the Networking
+        process and the WebContent process, but this is a CoreIPC connection. Since the database is represented by an xpc object, an xpc connection
+        is requiered to transfer the database. This patch creates a direct xpc connection between the Networking process and the WebContent process,
+        by creating an xpc endpoint in the Networking process, sending this to the UI process over the bootstrap xpc connection, and then providing
+        each WebContent process with this endpoint by sending it over the bootstrap xpc connection between the UI process and the WebContent process.
+        This endpoint has to be sent via the xpc connections to the UI process, since the already existing direct connection between the Networking
+        process and the WebContent process is a lower level CoreIPC connection, which does not support transferring xpc objects like the xpc endpoint.
+        When the WebContent process receives the endpoint, it will create an xpc connection from the endpoint, which will create a direct connection
+        with the Networking process. A message is then sent over the connection to request the database xpc object. When the Networking process
+        receives this message, it checks the entitlement of the remote end to make sure it is communicating with a WebContent process, and then sends
+        the database if the entitlement check succeeds. When the WebContent process receives this message, it performs an entitlement check as well,
+        and if successful, the database object is consumed. Consuming this database object, will make sure UTI to MIME type mapping is working
+        correctly in the WebContent process.
+
+        For the UI process to be able to pick up xpc messages on the bootstrap connection, a new virtual method, handleXPCEvent, is added to the
+        ProcessLauncher Client class. This way, a ProcessLauncher client will be able to pick up xpc messages from the xpc bootstrap connection.
+        Previously the event handler for the bootstrap connection in the UI process would handle only xpc error messages. It has now been expanded
+        to handle normal messages, which are being forwarded to the ProcessLauncher client. In this case the client is the Network process proxy,
+        which will check the message received, and if it turns out to be a message containing an xpc endpoint, the message will be forwarded to
+        all Web processes. The ProcessLauncher client can be expanded to handle any xpc message, but right not the Network process proxy only
+        handles the xpc endpoint message. The handleXPCEvent virtual method return a RefPtr to an XPCEventHandler, which is captured in the event
+        handler of the bootstrap xpc connection.
+
+        No new tests, since there already exist tests for this. UTI to MIME type mapping is being used in WebKit and underlying framework, and many
+        tests would fail if this mapping was not working.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::initializeConnection):
+        * NetworkProcess/cocoa/LaunchServicesDatabaseObserver.h: Added.
+        * NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm: Added.
+        (WebKit::LaunchServicesDatabaseObserver::singleton):
+        (WebKit::LaunchServicesDatabaseObserver::LaunchServicesDatabaseObserver):
+        (WebKit::LaunchServicesDatabaseObserver::startObserving):
+        (WebKit::LaunchServicesDatabaseObserver::~LaunchServicesDatabaseObserver):
+        (WebKit::LaunchServicesDatabaseObserver::xpcEndpointMessageNameKey const):
+        (WebKit::LaunchServicesDatabaseObserver::xpcEndpointMessageName const):
+        (WebKit::LaunchServicesDatabaseObserver::xpcEndpointNameKey const):
+        (WebKit::LaunchServicesDatabaseObserver::handleEvent):
+        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
+        * Scripts/process-entitlements.sh:
+        * Shared/Cocoa/LaunchServicesDatabaseXPCConstants.h: Added.
+        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
+        * SourcesCocoa.txt:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::xpcEndpointMessage const):
+        (WebKit::WebProcessPool::sendNetworkProcessXPCEndpointToWebProcess):
+        * UIProcess/Cocoa/XPCEventHandler.h: Added.
+        (WebKit::XPCEventHandler::~XPCEventHandler):
+        * UIProcess/Launcher/ProcessLauncher.h:
+        (WebKit::ProcessLauncher::Client::xpcEventHandler const):
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::ProcessLauncher::launchProcess):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/Network/NetworkProcessProxyCocoa.mm: Added.
+        (WebKit::NetworkProcessProxy::xpcEventHandler const):
+        (WebKit::NetworkProcessProxy::XPCEventHandler::handleXPCEvent const):
+        (WebKit::NetworkProcessProxy::XPCEventHandler::XPCEventHandler):
+        (WebKit::NetworkProcessProxy::XPCEventHandler::~XPCEventHandler):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didFinishLaunching):
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+        (WebKit::WebPage::platformDidReceiveLoadParameters):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeConnection):
+        * WebProcess/WebProcess.h:
+        * WebProcess/cocoa/LaunchServicesDatabaseManager.h: Added.
+        * WebProcess/cocoa/LaunchServicesDatabaseManager.mm: Added.
+        (WebKit::LaunchServicesDatabaseManager::singleton):
+        (WebKit::LaunchServicesDatabaseManager::handleEvent):
+        (WebKit::LaunchServicesDatabaseManager::didConnect):
+        (WebKit::LaunchServicesDatabaseManager::waitForDatabaseUpdate):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::handleXPCEndpointMessages const):
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2020-07-09  Eric Carlson  <[email protected]>
 
         Reset AVSystemController_PIDToInheritApplicationStateFrom when mediaserverd dies

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (264177 => 264178)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-07-09 17:06:14 UTC (rev 264178)
@@ -97,6 +97,7 @@
 #include "NetworkCacheCoders.h"
 
 #if PLATFORM(COCOA)
+#include "LaunchServicesDatabaseObserver.h"
 #include "NetworkSessionCocoa.h"
 #endif
 
@@ -163,6 +164,9 @@
 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
     addSupplement<LegacyCustomProtocolManager>();
 #endif
+#if PLATFORM(COCOA)
+    addSupplement<LaunchServicesDatabaseObserver>();
+#endif
 #if PLATFORM(COCOA) && ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
     LegacyCustomProtocolManager::networkProcessCreated(*this);
 #endif

Added: trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.h (0 => 264178)


--- trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.h	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -0,0 +1,60 @@
+/*
+ * 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
+
+#include "NetworkProcess.h"
+#include "NetworkProcessSupplement.h"
+#include <WebCore/XPCEndpoint.h>
+#include <wtf/OSObjectPtr.h>
+#include <wtf/RetainPtr.h>
+
+namespace WebKit {
+
+class LaunchServicesDatabaseObserver : public WebCore::XPCEndpoint, public NetworkProcessSupplement {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    LaunchServicesDatabaseObserver(NetworkProcess&);
+    virtual ~LaunchServicesDatabaseObserver();
+
+    static const char* supplementName();
+
+private:
+    void startObserving(OSObjectPtr<xpc_connection_t>);
+
+    // XPCEndpoint
+    const char* xpcEndpointMessageNameKey() const override;
+    const char* xpcEndpointMessageName() const override;
+    const char* xpcEndpointNameKey() const override;
+    void handleEvent(xpc_connection_t, xpc_object_t) override;
+
+    // NetworkProcessSupplement
+    void initializeConnection(IPC::Connection*) final;
+
+    RetainPtr<id> m_observer;
+    Vector<OSObjectPtr<xpc_connection_t>> m_connections;
+};
+
+}

Added: trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm (0 => 264178)


--- trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -0,0 +1,150 @@
+/*
+ * 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"
+#import "LaunchServicesDatabaseObserver.h"
+
+#import "LaunchServicesDatabaseXPCConstants.h"
+#import <pal/spi/cocoa/LaunchServicesSPI.h>
+#import <wtf/cocoa/Entitlements.h>
+#import <wtf/spi/cocoa/SecuritySPI.h>
+
+namespace WebKit {
+
+#if HAVE(LSDATABASECONTEXT)
+static LSDatabaseContext *databaseContext()
+{
+    static dispatch_once_t once;
+    static LSDatabaseContext *context = nullptr;
+    dispatch_once(&once, ^{
+        context = [NSClassFromString(@"LSDatabaseContext") sharedDatabaseContext];
+    });
+    return context;
+}
+#endif
+
+LaunchServicesDatabaseObserver::LaunchServicesDatabaseObserver(NetworkProcess&)
+{
+#if HAVE(LSDATABASECONTEXT)
+    if (![databaseContext() respondsToSelector:@selector(addDatabaseChangeObserver4WebKit:)])
+        return;
+
+    m_observer = [databaseContext() addDatabaseChangeObserver4WebKit:^(xpc_object_t change) {
+        auto message = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+        xpc_dictionary_set_string(message.get(), XPCEndpoint::xpcMessageNameKey, LaunchServicesDatabaseXPCConstants::xpcUpdateLaunchServicesDatabaseMessageName);
+        xpc_dictionary_set_value(message.get(), LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseKey, change);
+
+        for (auto& connection : m_connections)
+            xpc_connection_send_message(connection.get(), message.get());
+    }];
+#endif
+}
+
+const char* LaunchServicesDatabaseObserver::supplementName()
+{
+    return "LaunchServicesDatabaseObserverSupplement";
+}
+
+void LaunchServicesDatabaseObserver::startObserving(OSObjectPtr<xpc_connection_t> connection)
+{
+    m_connections.append(connection);
+
+#if HAVE(LSDATABASECONTEXT)
+    if (![databaseContext() respondsToSelector:@selector(addDatabaseChangeObserver4WebKit:)]) {
+        auto message = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+        xpc_dictionary_set_string(message.get(), XPCEndpoint::xpcMessageNameKey, LaunchServicesDatabaseXPCConstants::xpcUpdateLaunchServicesDatabaseMessageName);
+        xpc_connection_send_message(connection.get(), message.get());
+        return;
+    }
+
+    RetainPtr<id> observer = [databaseContext() addDatabaseChangeObserver4WebKit:^(xpc_object_t change) {
+        auto message = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+        xpc_dictionary_set_string(message.get(), XPCEndpoint::xpcMessageNameKey, LaunchServicesDatabaseXPCConstants::xpcUpdateLaunchServicesDatabaseMessageName);
+        xpc_dictionary_set_value(message.get(), LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseKey, change);
+
+        xpc_connection_send_message(connection.get(), message.get());
+    }];
+
+    [databaseContext() removeDatabaseChangeObserver4WebKit:observer.get()];
+#else
+    auto message = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+    xpc_dictionary_set_string(message.get(), XPCEndpoint::xpcMessageNameKey, LaunchServicesDatabaseXPCConstants::xpcUpdateLaunchServicesDatabaseMessageName);
+    xpc_connection_send_message(connection.get(), message.get());
+#endif
+}
+
+LaunchServicesDatabaseObserver::~LaunchServicesDatabaseObserver()
+{
+#if HAVE(LSDATABASECONTEXT)
+    if (![databaseContext() respondsToSelector:@selector(removeDatabaseChangeObserver4WebKit:)])
+        return;
+
+    [databaseContext() removeDatabaseChangeObserver4WebKit:m_observer.get()];
+#endif
+}
+
+const char* LaunchServicesDatabaseObserver::xpcEndpointMessageNameKey() const
+{
+    return xpcMessageNameKey;
+}
+
+const char* LaunchServicesDatabaseObserver::xpcEndpointMessageName() const
+{
+    return LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointMessageName;
+}
+
+const char* LaunchServicesDatabaseObserver::xpcEndpointNameKey() const
+{
+    return LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointNameKey;
+}
+
+void LaunchServicesDatabaseObserver::handleEvent(xpc_connection_t connection, xpc_object_t event)
+{
+    if (xpc_get_type(event) == XPC_TYPE_ERROR) {
+        if (event != XPC_ERROR_CONNECTION_INVALID && event != XPC_ERROR_TERMINATION_IMMINENT)
+            return;
+
+        for (size_t i = 0; i < m_connections.size(); i++) {
+            if (m_connections[i].get() == connection) {
+                m_connections.remove(i);
+                break;
+            }
+        }
+        return;
+    }
+    if (xpc_get_type(event) == XPC_TYPE_DICTIONARY) {
+        String messageName = xpc_dictionary_get_string(event, xpcMessageNameKey);
+        if (messageName != LaunchServicesDatabaseXPCConstants::xpcRequestLaunchServicesDatabaseUpdateMessageName)
+            return;
+        startObserving(connection);
+    }
+}
+
+void LaunchServicesDatabaseObserver::initializeConnection(IPC::Connection* connection)
+{
+    sendEndpointToConnection(connection->xpcConnection());
+}
+
+}

Modified: trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb (264177 => 264178)


--- trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb	2020-07-09 17:06:14 UTC (rev 264178)
@@ -588,7 +588,7 @@
 (allow ipc-posix-shm-read*
        (ipc-posix-name-prefix "apple.cfprefs."))
  
-(allow mach-lookup
+(deny mach-lookup
     (global-name "com.apple.lsd.mapdb"))
 
 ;; <rdar://problem/12413942>

Modified: trunk/Source/WebKit/Scripts/process-entitlements.sh (264177 => 264178)


--- trunk/Source/WebKit/Scripts/process-entitlements.sh	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/Scripts/process-entitlements.sh	2020-07-09 17:06:14 UTC (rev 264178)
@@ -15,6 +15,7 @@
 
     if [[ "${WK_USE_RESTRICTED_ENTITLEMENTS}" == YES ]]
     then
+        plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
         plistbuddy Add :com.apple.rootless.storage.WebKitWebContentSandbox bool YES
     fi
 
@@ -51,6 +52,7 @@
             plistbuddy Add :com.apple.private.tcc.manager.check-by-audit-token:0 string kTCCServiceWebKitIntelligentTrackingPrevention
         fi
 
+        plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
         plistbuddy Add :com.apple.rootless.storage.WebKitNetworkingSandbox bool YES
     fi
 }
@@ -144,6 +146,7 @@
     plistbuddy Add :com.apple.private.security.message-filter bool YES
     plistbuddy Add :com.apple.private.webinspector.allow-remote-inspection bool YES
     plistbuddy Add :com.apple.private.webinspector.proxy-application bool YES
+    plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
     plistbuddy Add :com.apple.runningboard.assertions.webkit bool YES
     plistbuddy Add :dynamic-codesigning bool YES
 
@@ -184,6 +187,7 @@
     plistbuddy Add :com.apple.private.dmd.policy bool YES
     plistbuddy Add :com.apple.private.memorystatus bool YES
     plistbuddy Add :com.apple.private.network.socket-delegate bool YES
+    plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
     plistbuddy Add :com.apple.runningboard.assertions.webkit bool YES
 
     plistbuddy Add :com.apple.private.tcc.manager.check-by-audit-token array

Added: trunk/Source/WebKit/Shared/Cocoa/LaunchServicesDatabaseXPCConstants.h (0 => 264178)


--- trunk/Source/WebKit/Shared/Cocoa/LaunchServicesDatabaseXPCConstants.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/Cocoa/LaunchServicesDatabaseXPCConstants.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -0,0 +1,39 @@
+/*
+ * 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
+
+namespace WebKit {
+
+namespace LaunchServicesDatabaseXPCConstants {
+
+constexpr auto xpcUpdateLaunchServicesDatabaseMessageName = "update-launch-services-database-message";
+constexpr auto xpcLaunchServicesDatabaseKey = "launch-services-database";
+constexpr auto xpcRequestLaunchServicesDatabaseUpdateMessageName = "request-launch-services-database-update-message";
+constexpr auto xpcLaunchServicesDatabaseXPCEndpointNameKey = "xpc-endpoint-launch-services-database";
+constexpr auto xpcLaunchServicesDatabaseXPCEndpointMessageName = "xpc-endpoint-launch-services-database-message";
+} // namespace LaunchServicesDatabaseXPCConstants
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm (264177 => 264178)


--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -29,6 +29,7 @@
 
 #import <CoreFoundation/CoreFoundation.h>
 #import <pal/spi/cf/CFUtilitiesSPI.h>
+#import <pal/spi/cocoa/LaunchServicesSPI.h>
 #import <wtf/OSObjectPtr.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/spi/darwin/XPCSPI.h>

Modified: trunk/Source/WebKit/SourcesCocoa.txt (264177 => 264178)


--- trunk/Source/WebKit/SourcesCocoa.txt	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2020-07-09 17:06:14 UTC (rev 264178)
@@ -415,6 +415,8 @@
 UIProcess/Inspector/mac/WKInspectorViewController.mm
 UIProcess/Inspector/mac/WKInspectorWKWebView.mm
 
+UIProcess/Network/NetworkProcessProxyCocoa.mm
+
 UIProcess/ios/forms/WKAirPlayRoutePicker.mm
 UIProcess/ios/forms/WKDatePickerViewController.mm
 UIProcess/ios/forms/WKDateTimeInputControl.mm

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (264177 => 264178)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -934,4 +934,23 @@
 }
 #endif
 
+OSObjectPtr<xpc_object_t> WebProcessPool::xpcEndpointMessage() const
+{
+    return m_endpointMessage;
+}
+
+void WebProcessPool::sendNetworkProcessXPCEndpointToWebProcess(OSObjectPtr<xpc_object_t> endpointMessage)
+{
+    m_endpointMessage = endpointMessage;
+
+    for (auto process : m_processes) {
+        if (process->state() != AuxiliaryProcessProxy::State::Running)
+            continue;
+        if (!process->connection())
+            continue;
+        auto connection = process->connection()->xpcConnection();
+        xpc_connection_send_message(connection, endpointMessage.get());
+    }
+}
+
 } // namespace WebKit

Added: trunk/Source/WebKit/UIProcess/Cocoa/XPCEventHandler.h (0 => 264178)


--- trunk/Source/WebKit/UIProcess/Cocoa/XPCEventHandler.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/XPCEventHandler.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -0,0 +1,39 @@
+/*
+ * 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
+
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebKit {
+
+class XPCEventHandler : public ThreadSafeRefCounted<XPCEventHandler> {
+public:
+    virtual ~XPCEventHandler() { }
+
+    virtual bool handleXPCEvent(xpc_object_t) const = 0;
+};
+
+}

Modified: trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h (264177 => 264178)


--- trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -39,6 +39,10 @@
 #include <wtf/win/Win32Handle.h>
 #endif
 
+#if PLATFORM(COCOA)
+#include "XPCEventHandler.h"
+#endif
+
 namespace WebKit {
 
 #if PLATFORM(GTK) || PLATFORM(WPE)
@@ -57,6 +61,9 @@
         virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) = 0;
         virtual bool shouldConfigureJSCForTesting() const { return false; }
         virtual bool isJITEnabled() const { return true; }
+#if PLATFORM(COCOA)
+        virtual RefPtr<XPCEventHandler> xpcEventHandler() const { return nullptr; }
+#endif
     };
     
     enum class ProcessType {

Modified: trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm (264177 => 264178)


--- trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -238,18 +238,28 @@
         processLauncher->didFinishLaunchingProcess(0, IPC::Connection::Identifier());
     };
 
-    auto errorHandler = [errorHandlerImpl = WTFMove(errorHandlerImpl)] (xpc_object_t event) mutable {
-        RunLoop::main().dispatch([errorHandlerImpl = WTFMove(errorHandlerImpl), event] {
-            errorHandlerImpl(event);
-        });
+    auto eventHandler = [errorHandlerImpl = WTFMove(errorHandlerImpl), eventHandler = m_client->xpcEventHandler()] (xpc_object_t event) mutable {
+
+        if (!event || xpc_get_type(event) == XPC_TYPE_ERROR) {
+            RunLoop::main().dispatch([errorHandlerImpl = WTFMove(errorHandlerImpl), event = OSObjectPtr(event)] {
+                errorHandlerImpl(event.get());
+            });
+            return;
+        }
+
+        if (eventHandler) {
+            RunLoop::main().dispatch([eventHandler = eventHandler, event = OSObjectPtr(event)] {
+                eventHandler->handleXPCEvent(event.get());
+            });
+        }
     };
 
-    xpc_connection_set_event_handler(m_xpcConnection.get(), errorHandler);
+    xpc_connection_set_event_handler(m_xpcConnection.get(), eventHandler);
 
     xpc_connection_resume(m_xpcConnection.get());
 
     if (UNLIKELY(m_launchOptions.shouldMakeProcessLaunchFailForTesting)) {
-        errorHandler(nullptr);
+        eventHandler(nullptr);
         return;
     }
 

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (264177 => 264178)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -44,6 +44,10 @@
 #include "LegacyCustomProtocolManagerProxy.h"
 #endif
 
+#if PLATFORM(COCOA)
+#include "XPCEventHandler.h"
+#endif
+
 namespace IPC {
 class FormDataReference;
 }
@@ -297,6 +301,9 @@
 
     // ProcessLauncher::Client
     void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
+#if PLATFORM(COCOA)
+    RefPtr<XPCEventHandler> xpcEventHandler() const override;
+#endif
 
     void processAuthenticationChallenge(PAL::SessionID, Ref<AuthenticationChallengeProxy>&&);
 
@@ -327,6 +334,18 @@
         HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>> webProcessAssertions;
     };
     Optional<UploadActivity> m_uploadActivity;
+
+#if PLATFORM(COCOA)
+    class XPCEventHandler : public WebKit::XPCEventHandler {
+    public:
+        XPCEventHandler(const NetworkProcessProxy&);
+
+        bool handleXPCEvent(xpc_object_t) const override;
+
+    private:
+        WeakPtr<NetworkProcessProxy> m_networkProcess;
+    };
+#endif
 };
 
 } // namespace WebKit

Added: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm (0 => 264178)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxyCocoa.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -0,0 +1,65 @@
+/*
+ * 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"
+#import "NetworkProcessProxy.h"
+
+#import "LaunchServicesDatabaseXPCConstants.h"
+#import "WebProcessPool.h"
+#import <WebCore/XPCEndpoint.h>
+
+namespace WebKit {
+
+using namespace WebCore;
+
+RefPtr<XPCEventHandler> NetworkProcessProxy::xpcEventHandler() const
+{
+    return adoptRef(new NetworkProcessProxy::XPCEventHandler(*this));
+}
+
+bool NetworkProcessProxy::XPCEventHandler::handleXPCEvent(xpc_object_t event) const
+{
+    if (!m_networkProcess)
+        return false;
+
+    if (!event || xpc_get_type(event) == XPC_TYPE_ERROR)
+        return false;
+
+    String messageName = xpc_dictionary_get_string(event, XPCEndpoint::xpcMessageNameKey);
+    if (messageName.isEmpty())
+        return false;
+
+    if (messageName == LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointMessageName)
+        m_networkProcess->processPool().sendNetworkProcessXPCEndpointToWebProcess(event);
+
+    return true;
+}
+
+NetworkProcessProxy::XPCEventHandler::XPCEventHandler(const NetworkProcessProxy& networkProcess)
+    : m_networkProcess(makeWeakPtr(networkProcess))
+{
+}
+
+}

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (264177 => 264178)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -389,7 +389,7 @@
 
     // Network Process Management
     NetworkProcessProxy& ensureNetworkProcess(WebsiteDataStore* withWebsiteDataStore = nullptr);
-    NetworkProcessProxy* networkProcess() { return m_networkProcess.get(); }
+    NetworkProcessProxy* networkProcess() const { return m_networkProcess.get(); }
     void networkProcessCrashed(NetworkProcessProxy&);
 
     void getNetworkProcessConnection(WebProcessProxy&, Messages::WebProcessProxy::GetNetworkProcessConnectionDelayedReply&&);
@@ -541,6 +541,11 @@
     int32_t userId() const { return m_userId; }
 #endif
 
+#if PLATFORM(COCOA)
+    OSObjectPtr<xpc_object_t> xpcEndpointMessage() const;
+    void sendNetworkProcessXPCEndpointToWebProcess(OSObjectPtr<xpc_object_t> endpointMessage);
+#endif
+
 private:
     void platformInitialize();
 
@@ -825,6 +830,10 @@
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     HashSet<WebCore::RegistrableDomain> m_domainsWithUserInteraction;
 #endif
+
+#if PLATFORM(COCOA)
+    OSObjectPtr<xpc_object_t> m_endpointMessage;
+#endif
 };
 
 template<typename T>

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (264177 => 264178)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-07-09 17:06:14 UTC (rev 264178)
@@ -953,6 +953,12 @@
         return;
     }
 
+#if PLATFORM(COCOA)
+    auto endpointMessage = processPool().xpcEndpointMessage();
+    if (endpointMessage)
+        xpc_connection_send_message(connection()->xpcConnection(), endpointMessage.get());
+#endif
+
     RELEASE_ASSERT(!m_webConnection);
     m_webConnection = WebConnectionToWebProcess::create(this);
 

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (264177 => 264178)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-07-09 17:06:14 UTC (rev 264178)
@@ -1684,8 +1684,11 @@
 		C11A9ECC214035F800CFB20A /* WebSwitchingGPUClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C11A9ECB214035F800CFB20A /* WebSwitchingGPUClient.h */; };
 		C11E1694212B87C500985FF6 /* WKMockDisplay.h in Headers */ = {isa = PBXBuildFile; fileRef = C11E1692212B87C500985FF6 /* WKMockDisplay.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C149380922347104000CD707 /* WebSpeechSynthesisClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C149380222341C60000CD707 /* WebSpeechSynthesisClient.h */; };
+		C14D37FE24ACE086007FF014 /* LaunchServicesDatabaseManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = C14D37FD24ACE086007FF014 /* LaunchServicesDatabaseManager.mm */; };
 		C15CBB3623F3777100300CC7 /* PreferenceObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C145CC0E23DCA427003A5EEB /* PreferenceObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C15CBB3723F37ECB00300CC7 /* PreferenceObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB3323F34C3800300CC7 /* PreferenceObserver.mm */; };
+		C1663E5B24AEAA2F00C6A3B2 /* LaunchServicesDatabaseXPCConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = C1663E5A24AEA74200C6A3B2 /* LaunchServicesDatabaseXPCConstants.h */; };
+		C1710CF724AA643200D7C112 /* LaunchServicesDatabaseObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1710CF624AA643200D7C112 /* LaunchServicesDatabaseObserver.mm */; };
 		C18173612058424700DFDA65 /* DisplayLink.h in Headers */ = {isa = PBXBuildFile; fileRef = C18173602058424700DFDA65 /* DisplayLink.h */; };
 		C1E123BA20A11573002646F4 /* PDFContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = C1E123B920A11572002646F4 /* PDFContextMenu.h */; };
 		C517388112DF8F4F00EE3F47 /* DragControllerAction.h in Headers */ = {isa = PBXBuildFile; fileRef = C517388012DF8F4F00EE3F47 /* DragControllerAction.h */; };
@@ -5018,7 +5021,13 @@
 		C149380222341C60000CD707 /* WebSpeechSynthesisClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebSpeechSynthesisClient.h; sourceTree = "<group>"; };
 		C149380322341DF7000CD707 /* WebSpeechSynthesisClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebSpeechSynthesisClient.cpp; sourceTree = "<group>"; };
 		C149380A223853BE000CD707 /* WebSpeechSynthesisVoice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebSpeechSynthesisVoice.h; sourceTree = "<group>"; };
+		C14D37FC24ACDF45007FF014 /* LaunchServicesDatabaseManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchServicesDatabaseManager.h; sourceTree = "<group>"; };
+		C14D37FD24ACE086007FF014 /* LaunchServicesDatabaseManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LaunchServicesDatabaseManager.mm; sourceTree = "<group>"; };
 		C15CBB3323F34C3800300CC7 /* PreferenceObserver.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferenceObserver.mm; sourceTree = "<group>"; };
+		C1663E5A24AEA74200C6A3B2 /* LaunchServicesDatabaseXPCConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchServicesDatabaseXPCConstants.h; sourceTree = "<group>"; };
+		C1710CF224A7BD0300D7C112 /* XPCEventHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPCEventHandler.h; sourceTree = "<group>"; };
+		C1710CF524AA634500D7C112 /* LaunchServicesDatabaseObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchServicesDatabaseObserver.h; sourceTree = "<group>"; };
+		C1710CF624AA643200D7C112 /* LaunchServicesDatabaseObserver.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LaunchServicesDatabaseObserver.mm; sourceTree = "<group>"; };
 		C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DrawingAreaMac.cpp; sourceTree = "<group>"; };
 		C18173602058424700DFDA65 /* DisplayLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayLink.h; sourceTree = "<group>"; };
 		C1817362205844A900DFDA65 /* DisplayLink.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayLink.cpp; sourceTree = "<group>"; };
@@ -5025,6 +5034,7 @@
 		C18FB51D242F9F76007E9875 /* WebSleepDisablerClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSleepDisablerClient.cpp; sourceTree = "<group>"; };
 		C18FB51E242F9F77007E9875 /* WebSleepDisablerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSleepDisablerClient.h; sourceTree = "<group>"; };
 		C1E123B920A11572002646F4 /* PDFContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFContextMenu.h; sourceTree = "<group>"; };
+		C1ED723724A5690E003F6CD3 /* NetworkProcessProxyCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkProcessProxyCocoa.mm; sourceTree = "<group>"; };
 		C517388012DF8F4F00EE3F47 /* DragControllerAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragControllerAction.h; sourceTree = "<group>"; };
 		C5237F5F12441CA300780472 /* WebEditorClientMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebEditorClientMac.mm; sourceTree = "<group>"; };
 		C54256AF18BEC18B00DE4179 /* WKDateTimeInputControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKDateTimeInputControl.h; path = ios/forms/WKDateTimeInputControl.h; sourceTree = "<group>"; };
@@ -6384,6 +6394,7 @@
 				2D7AAFD218C8640600A7ACD4 /* WKWebViewContentProvider.h */,
 				2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
 				2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */,
+				C1710CF224A7BD0300D7C112 /* XPCEventHandler.h */,
 			);
 			path = Cocoa;
 			sourceTree = "<group>";
@@ -7481,6 +7492,7 @@
 				C55F916D1C595E440029E92D /* DataDetectionResult.mm */,
 				CE550E132283744400D28791 /* InsertTextOptions.cpp */,
 				CE550E12228373C800D28791 /* InsertTextOptions.h */,
+				C1663E5A24AEA74200C6A3B2 /* LaunchServicesDatabaseXPCConstants.h */,
 				2D1087621D2C641B00B85F82 /* LoadParametersCocoa.mm */,
 				CD2865EC2255562000606AC7 /* ProcessTaskStateObserver.h */,
 				CD2865ED2255562000606AC7 /* ProcessTaskStateObserver.mm */,
@@ -7844,6 +7856,7 @@
 		510CC7E716138E7200D03ED3 /* Network */ = {
 			isa = PBXGroup;
 			children = (
+				C1ED723624A568F5003F6CD3 /* cocoa */,
 				29AD3091164B4C100072DEA9 /* CustomProtocols */,
 				516319931628980E00E22F00 /* mac */,
 				510CC7EA16138E7200D03ED3 /* NetworkProcessProxy.cpp */,
@@ -8374,6 +8387,8 @@
 			children = (
 				CD4570CB2440FB2A00A3DCEB /* AudioSessionRoutingArbitrator.cpp */,
 				CD4570CA2440FB2A00A3DCEB /* AudioSessionRoutingArbitrator.h */,
+				C14D37FC24ACDF45007FF014 /* LaunchServicesDatabaseManager.h */,
+				C14D37FD24ACE086007FF014 /* LaunchServicesDatabaseManager.mm */,
 				446DC64B24A2D8AD0061F390 /* PlaybackSessionContextIdentifier.h */,
 				CDA29A191CBDBF4100901CCF /* PlaybackSessionManager.h */,
 				CDA29A1C1CBDBF5B00901CCF /* PlaybackSessionManager.messages.in */,
@@ -8425,6 +8440,8 @@
 			children = (
 				2D0C56FB229F1DEA00BD33E7 /* DeviceManagementSoftLink.h */,
 				2D0C56FC229F1DEA00BD33E7 /* DeviceManagementSoftLink.mm */,
+				C1710CF524AA634500D7C112 /* LaunchServicesDatabaseObserver.h */,
+				C1710CF624AA643200D7C112 /* LaunchServicesDatabaseObserver.mm */,
 				5315876B2076B713004BF9F3 /* NetworkActivityTrackerCocoa.mm */,
 				5321594F1DBAE6D70054AA3C /* NetworkDataTaskCocoa.h */,
 				5CBC9B8B1C65257300A8FDCF /* NetworkDataTaskCocoa.mm */,
@@ -10252,6 +10269,14 @@
 			tabWidth = 8;
 			usesTabs = 0;
 		};
+		C1ED723624A568F5003F6CD3 /* cocoa */ = {
+			isa = PBXGroup;
+			children = (
+				C1ED723724A5690E003F6CD3 /* NetworkProcessProxyCocoa.mm */,
+			);
+			name = cocoa;
+			sourceTree = "<group>";
+		};
 		C54256AE18BEC16100DE4179 /* forms */ = {
 			isa = PBXGroup;
 			children = (
@@ -10858,6 +10883,7 @@
 				2D4D2C811DF60BF3002EB10C /* InteractionInformationRequest.h in Headers */,
 				1AE49A4911FFA8CE0048B464 /* JSNPMethod.h in Headers */,
 				1AE4987811FF7FAA0048B464 /* JSNPObject.h in Headers */,
+				C1663E5B24AEAA2F00C6A3B2 /* LaunchServicesDatabaseXPCConstants.h in Headers */,
 				BCE0937814FB128C001138D9 /* LayerHostingContext.h in Headers */,
 				1A92DC1112F8BA460017AF65 /* LayerTreeContext.h in Headers */,
 				44E936FD2447C2D8009FA3E3 /* LegacyCustomProtocolID.h in Headers */,
@@ -12726,6 +12752,8 @@
 				2749F6452146561E008380BF /* InjectedBundleRangeHandle.cpp in Sources */,
 				2D913441212CF9F000128AFD /* JSNPMethod.cpp in Sources */,
 				2D913442212CF9F000128AFD /* JSNPObject.cpp in Sources */,
+				C14D37FE24ACE086007FF014 /* LaunchServicesDatabaseManager.mm in Sources */,
+				C1710CF724AA643200D7C112 /* LaunchServicesDatabaseObserver.mm in Sources */,
 				2984F588164BA095004BC0C6 /* LegacyCustomProtocolManagerMessageReceiver.cpp in Sources */,
 				2984F57C164B915F004BC0C6 /* LegacyCustomProtocolManagerProxyMessageReceiver.cpp in Sources */,
 				51F060E11654318500F3281C /* LibWebRTCNetworkMessageReceiver.cpp in Sources */,

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (264177 => 264178)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -27,6 +27,7 @@
 #import "WebPage.h"
 
 #import "InsertTextOptions.h"
+#import "LaunchServicesDatabaseManager.h"
 #import "LoadParameters.h"
 #import "PluginView.h"
 #import "WKAccessibilityWebPageObjectBase.h"
@@ -62,6 +63,9 @@
 
 void WebPage::platformDidReceiveLoadParameters(const LoadParameters& parameters)
 {
+    bool databaseUpdated =  LaunchServicesDatabaseManager::singleton().waitForDatabaseUpdate(5_s);
+    ASSERT_UNUSED(databaseUpdated, databaseUpdated);
+
     m_dataDetectionContext = parameters.dataDetectionContext;
 
     if (parameters.neHelperExtensionHandle)

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (264177 => 264178)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2020-07-09 17:06:14 UTC (rev 264178)
@@ -290,6 +290,10 @@
 {
     AuxiliaryProcess::initializeConnection(connection);
 
+#if PLATFORM(COCOA)
+    handleXPCEndpointMessages();
+#endif
+
     // We call _exit() directly from the background queue in case the main thread is unresponsive
     // and AuxiliaryProcess::didClose() does not get called.
     connection->setDidCloseOnConnectionWorkQueueCallback(callExit);

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (264177 => 264178)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -515,6 +515,10 @@
 
     bool isAlwaysOnLoggingAllowed() { return m_sessionID ? m_sessionID->isAlwaysOnLoggingAllowed() : true; }
 
+#if PLATFORM(COCOA)
+    void handleXPCEndpointMessages() const;
+#endif
+
     RefPtr<WebConnectionToUIProcess> m_webConnection;
 
     HashMap<WebCore::PageIdentifier, RefPtr<WebPage>> m_pageMap;

Added: trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h (0 => 264178)


--- trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.h	2020-07-09 17:06:14 UTC (rev 264178)
@@ -0,0 +1,48 @@
+/*
+ * 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
+
+#import <WebCore/XPCEndpointClient.h>
+#import <wtf/NeverDestroyed.h>
+#import <wtf/threads/BinarySemaphore.h>
+
+namespace WebKit {
+
+class LaunchServicesDatabaseManager : public WebCore::XPCEndpointClient {
+public:
+    static LaunchServicesDatabaseManager& singleton();
+
+    bool waitForDatabaseUpdate(Seconds);
+
+private:
+    void handleEvent(xpc_object_t) override;
+    void didConnect() override;
+
+    std::atomic<bool> m_hasReceivedLaunchServicesDatabase { false };
+    BinarySemaphore m_semaphore;
+};
+
+}

Added: trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm (0 => 264178)


--- trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/cocoa/LaunchServicesDatabaseManager.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -0,0 +1,82 @@
+/*
+ * 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"
+#import "LaunchServicesDatabaseManager.h"
+
+#import "LaunchServicesDatabaseXPCConstants.h"
+#import <WebCore/XPCEndpoint.h>
+#import <pal/spi/cocoa/LaunchServicesSPI.h>
+#import <wtf/cocoa/Entitlements.h>
+#import <wtf/spi/darwin/XPCSPI.h>
+#import <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+using namespace WebCore;
+
+LaunchServicesDatabaseManager& LaunchServicesDatabaseManager::singleton()
+{
+    static NeverDestroyed<LaunchServicesDatabaseManager> manager;
+    return manager.get();
+}
+
+void LaunchServicesDatabaseManager::handleEvent(xpc_object_t message)
+{
+    String messageName = xpc_dictionary_get_string(message, XPCEndpoint::xpcMessageNameKey);
+    if (messageName.isEmpty())
+        return;
+    if (messageName == LaunchServicesDatabaseXPCConstants::xpcUpdateLaunchServicesDatabaseMessageName) {
+#if HAVE(LSDATABASECONTEXT)
+        auto database = xpc_dictionary_get_value(message, LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseKey);
+
+        if (database) {
+            auto context = [NSClassFromString(@"LSDatabaseContext") sharedDatabaseContext];
+            if (![context respondsToSelector:@selector(observeDatabaseChange4WebKit:)])
+                return;
+            [context observeDatabaseChange4WebKit:database];
+        }
+#endif
+        m_semaphore.signal();
+        m_hasReceivedLaunchServicesDatabase = true;
+    }
+}
+
+void LaunchServicesDatabaseManager::didConnect()
+{
+    auto message = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+    xpc_dictionary_set_string(message.get(), XPCEndpoint::xpcMessageNameKey, LaunchServicesDatabaseXPCConstants::xpcRequestLaunchServicesDatabaseUpdateMessageName);
+
+    xpc_connection_send_message(connection().get(), message.get());
+}
+
+bool LaunchServicesDatabaseManager::waitForDatabaseUpdate(Seconds timeout)
+{
+    if (m_hasReceivedLaunchServicesDatabase)
+        return true;
+    return m_semaphore.waitFor(timeout);
+}
+
+}

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (264177 => 264178)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-07-09 16:57:19 UTC (rev 264177)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-07-09 17:06:14 UTC (rev 264178)
@@ -27,6 +27,8 @@
 #import "WebProcess.h"
 #import "WebProcessCocoa.h"
 
+#import "LaunchServicesDatabaseManager.h"
+#import "LaunchServicesDatabaseXPCConstants.h"
 #import "LegacyCustomProtocolManager.h"
 #import "LogInitialization.h"
 #import "Logging.h"
@@ -69,6 +71,7 @@
 #import <WebCore/SWContextManager.h>
 #import <WebCore/SystemBattery.h>
 #import <WebCore/UTIUtilities.h>
+#import <WebCore/XPCEndpoint.h>
 #import <algorithm>
 #import <dispatch/dispatch.h>
 #import <objc/runtime.h>
@@ -161,25 +164,50 @@
 }
 #endif
 
-void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
+void WebProcess::handleXPCEndpointMessages() const
 {
-    // Map Launch Services database. This should be done as early as possible, as the mapping will fail
-    // if 'com.apple.lsd.mapdb' is being accessed before this.
-    if (parameters.mapDBExtensionHandle) {
-        auto extension = SandboxExtension::create(WTFMove(*parameters.mapDBExtensionHandle));
-        bool ok = extension->consume();
-        ASSERT_UNUSED(ok, ok);
-        // Perform API calls which will communicate with the database mapping service, and map the database.
-        auto uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0));
+    if (!parentProcessConnection())
+        return;
 
-        [[objc_getClass("_LSDReadService") XPCConnectionToService] invalidate];
+    auto connection = parentProcessConnection()->xpcConnection();
 
-        ok = extension->revoke();
-        ASSERT_UNUSED(ok, ok);
+    xpc_connection_set_target_queue(connection, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
+    xpc_connection_set_event_handler(connection, ^(xpc_object_t event) {
+        if (xpc_get_type(event) != XPC_TYPE_DICTIONARY)
+            return;
 
-        ASSERT(String(uti.get()) == String(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0)).get()));
+        String messageName = xpc_dictionary_get_string(event, XPCEndpoint::xpcMessageNameKey);
+        if (messageName.isEmpty())
+            return;
+
+        if (messageName == LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointMessageName) {
+            auto endpoint = xpc_dictionary_get_value(event, LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointNameKey);
+            LaunchServicesDatabaseManager::singleton().setEndpoint(endpoint);
+            return;
+        }
+    });
+}
+
+void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
+{
+#if HAVE(LSDATABASECONTEXT)
+    // FIXME: Remove this entire section when the selector observeDatabaseChange4WebKit is present
+    auto context = [NSClassFromString(@"LSDatabaseContext") sharedDatabaseContext];
+    if (![context respondsToSelector:@selector(observeDatabaseChange4WebKit:)]) {
+        // Map Launch Services database. This should be done as early as possible, as the mapping will fail
+        // if 'com.apple.lsd.mapdb' is being accessed before this.
+        if (parameters.mapDBExtensionHandle) {
+            auto extension = SandboxExtension::create(WTFMove(*parameters.mapDBExtensionHandle));
+            bool ok = extension->consume();
+            ASSERT_UNUSED(ok, ok);
+            // Perform API calls which will communicate with the database mapping service, and map the database.
+            auto uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0));
+            ok = extension->revoke();
+            ASSERT_UNUSED(ok, ok);
+            ASSERT(String(uti.get()) == String(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0)).get()));
+        }
     }
-
+#endif
 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
     WebCore::initializeLogChannelsIfNecessary(parameters.webCoreLoggingChannels);
     WebKit::initializeLogChannelsIfNecessary(parameters.webKitLoggingChannels);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to