⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 264178 in webkit


Ignore:
Timestamp:
Jul 9, 2020, 10:06:14 AM (6 years ago)
Author:
pvollan@apple.com
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:
Location:
trunk/Source
Files:
7 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r264167 r264178  
     12020-07-09  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Cocoa] Update Launch Services database in the WebContent process from the Network process
     4        https://bugs.webkit.org/show_bug.cgi?id=213794
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Added HAVE define for determining if the class LSDatabaseContext is present.
     9
     10        * wtf/PlatformHave.h:
     11
    1122020-07-09  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/Source/WTF/wtf/PlatformHave.h

    r264167 r264178  
    673673#define HAVE_APP_ACCENT_COLORS 1
    674674#endif
     675
     676#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101600) \
     677    || ((PLATFORM(IOS) || PLATFORM(MACCATALYST)) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) \
     678    || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 70000) \
     679    || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 140000)
     680#define HAVE_LSDATABASECONTEXT 1
     681#endif
  • trunk/Source/WebCore/PAL/ChangeLog

    r264167 r264178  
     12020-07-09  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Cocoa] Update Launch Services database in the WebContent process from the Network process
     4        https://bugs.webkit.org/show_bug.cgi?id=213794
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Declare interface for observing and consuming the Launch Services database.
     9
     10        * pal/spi/cocoa/LaunchServicesSPI.h:
     11
    1122020-07-09  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h

    r264167 r264178  
    2626#import <Foundation/Foundation.h>
    2727
     28#include <wtf/spi/darwin/XPCSPI.h>
     29
    2830#if USE(APPLE_INTERNAL_SDK)
    29 
    30 #if PLATFORM(MAC)
    3131#import <CoreServices/CoreServicesPriv.h>
    32 #elif PLATFORM(IOS_FAMILY)
    33 #import <MobileCoreServices/LSAppLinkPriv.h>
    34 #elif PLATFORM(IOS)
    35 #import <MobileCoreServices/MobileCoreServicesPriv.h>
    36 #endif
    37 
    3832#endif // USE(APPLE_INTERNAL_SDK)
    3933
    … …  
    8478#endif
    8579
     80#if HAVE(LSDATABASECONTEXT)
     81@interface LSDatabaseContext : NSObject
     82@property (class, readonly) LSDatabaseContext *sharedDatabaseContext;
     83@end
     84#endif
     85
    8686#endif // !USE(APPLE_INTERNAL_SDK)
    8787
    88 @interface _LSDService : NSObject <NSXPCListenerDelegate>
    89 + (NSXPCConnection *)XPCConnectionToService;
     88#if HAVE(LSDATABASECONTEXT)
     89@interface LSDatabaseContext (WebKitChangeTracking)
     90- (id <NSObject>)addDatabaseChangeObserver4WebKit:(void (^)(xpc_object_t change))observer;
     91- (void)removeDatabaseChangeObserver4WebKit:(id <NSObject>)token;
     92- (void)observeDatabaseChange4WebKit:(xpc_object_t)change;
    9093@end
    91 
    92 @interface _LSDReadService : _LSDService
    93 @end
     94#endif
    9495
    9596#if PLATFORM(MAC)
  • trunk/Source/WebKit/ChangeLog

    r264177 r264178  
     12020-07-09  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Cocoa] Update Launch Services database in the WebContent process from the Network process
     4        https://bugs.webkit.org/show_bug.cgi?id=213794
     5
     6        Reviewed by Brent Fulgham.
     7
     8        To be able to deny mach lookup access to the Launch Services database mapping service in the WebContent process, the database needs to be
     9        sent from the Networking process to the WebContent process, represented by an xpc object. The Networking process is chosen instead of the UI
     10        process, since WebKit is controlling the sandbox of the Networking process. There is already a direct connection between the Networking
     11        process and the WebContent process, but this is a CoreIPC connection. Since the database is represented by an xpc object, an xpc connection
     12        is requiered to transfer the database. This patch creates a direct xpc connection between the Networking process and the WebContent process,
     13        by creating an xpc endpoint in the Networking process, sending this to the UI process over the bootstrap xpc connection, and then providing
     14        each WebContent process with this endpoint by sending it over the bootstrap xpc connection between the UI process and the WebContent process.
     15        This endpoint has to be sent via the xpc connections to the UI process, since the already existing direct connection between the Networking
     16        process and the WebContent process is a lower level CoreIPC connection, which does not support transferring xpc objects like the xpc endpoint.
     17        When the WebContent process receives the endpoint, it will create an xpc connection from the endpoint, which will create a direct connection
     18        with the Networking process. A message is then sent over the connection to request the database xpc object. When the Networking process
     19        receives this message, it checks the entitlement of the remote end to make sure it is communicating with a WebContent process, and then sends
     20        the database if the entitlement check succeeds. When the WebContent process receives this message, it performs an entitlement check as well,
     21        and if successful, the database object is consumed. Consuming this database object, will make sure UTI to MIME type mapping is working
     22        correctly in the WebContent process.
     23
     24        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
     25        ProcessLauncher Client class. This way, a ProcessLauncher client will be able to pick up xpc messages from the xpc bootstrap connection.
     26        Previously the event handler for the bootstrap connection in the UI process would handle only xpc error messages. It has now been expanded
     27        to handle normal messages, which are being forwarded to the ProcessLauncher client. In this case the client is the Network process proxy,
     28        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
     29        all Web processes. The ProcessLauncher client can be expanded to handle any xpc message, but right not the Network process proxy only
     30        handles the xpc endpoint message. The handleXPCEvent virtual method return a RefPtr to an XPCEventHandler, which is captured in the event
     31        handler of the bootstrap xpc connection.
     32
     33        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
     34        tests would fail if this mapping was not working.
     35
     36        * NetworkProcess/NetworkProcess.cpp:
     37        (WebKit::NetworkProcess::initializeConnection):
     38        * NetworkProcess/cocoa/LaunchServicesDatabaseObserver.h: Added.
     39        * NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm: Added.
     40        (WebKit::LaunchServicesDatabaseObserver::singleton):
     41        (WebKit::LaunchServicesDatabaseObserver::LaunchServicesDatabaseObserver):
     42        (WebKit::LaunchServicesDatabaseObserver::startObserving):
     43        (WebKit::LaunchServicesDatabaseObserver::~LaunchServicesDatabaseObserver):
     44        (WebKit::LaunchServicesDatabaseObserver::xpcEndpointMessageNameKey const):
     45        (WebKit::LaunchServicesDatabaseObserver::xpcEndpointMessageName const):
     46        (WebKit::LaunchServicesDatabaseObserver::xpcEndpointNameKey const):
     47        (WebKit::LaunchServicesDatabaseObserver::handleEvent):
     48        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
     49        * Scripts/process-entitlements.sh:
     50        * Shared/Cocoa/LaunchServicesDatabaseXPCConstants.h: Added.
     51        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
     52        * SourcesCocoa.txt:
     53        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     54        (WebKit::WebProcessPool::xpcEndpointMessage const):
     55        (WebKit::WebProcessPool::sendNetworkProcessXPCEndpointToWebProcess):
     56        * UIProcess/Cocoa/XPCEventHandler.h: Added.
     57        (WebKit::XPCEventHandler::~XPCEventHandler):
     58        * UIProcess/Launcher/ProcessLauncher.h:
     59        (WebKit::ProcessLauncher::Client::xpcEventHandler const):
     60        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     61        (WebKit::ProcessLauncher::launchProcess):
     62        * UIProcess/Network/NetworkProcessProxy.h:
     63        * UIProcess/Network/NetworkProcessProxyCocoa.mm: Added.
     64        (WebKit::NetworkProcessProxy::xpcEventHandler const):
     65        (WebKit::NetworkProcessProxy::XPCEventHandler::handleXPCEvent const):
     66        (WebKit::NetworkProcessProxy::XPCEventHandler::XPCEventHandler):
     67        (WebKit::NetworkProcessProxy::XPCEventHandler::~XPCEventHandler):
     68        * UIProcess/WebProcessPool.h:
     69        * UIProcess/WebProcessProxy.cpp:
     70        (WebKit::WebProcessProxy::didFinishLaunching):
     71        * WebKit.xcodeproj/project.pbxproj:
     72        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
     73        (WebKit::WebPage::platformDidReceiveLoadParameters):
     74        * WebProcess/WebProcess.cpp:
     75        (WebKit::WebProcess::initializeConnection):
     76        * WebProcess/WebProcess.h:
     77        * WebProcess/cocoa/LaunchServicesDatabaseManager.h: Added.
     78        * WebProcess/cocoa/LaunchServicesDatabaseManager.mm: Added.
     79        (WebKit::LaunchServicesDatabaseManager::singleton):
     80        (WebKit::LaunchServicesDatabaseManager::handleEvent):
     81        (WebKit::LaunchServicesDatabaseManager::didConnect):
     82        (WebKit::LaunchServicesDatabaseManager::waitForDatabaseUpdate):
     83        * WebProcess/cocoa/WebProcessCocoa.mm:
     84        (WebKit::WebProcess::handleXPCEndpointMessages const):
     85        (WebKit::WebProcess::platformInitializeWebProcess):
     86
    1872020-07-09  Eric Carlson  <eric.carlson@apple.com>
    288
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r264167 r264178  
    9898
    9999#if PLATFORM(COCOA)
     100#include "LaunchServicesDatabaseObserver.h"
    100101#include "NetworkSessionCocoa.h"
    101102#endif
    … …  
    163164#if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
    164165    addSupplement<LegacyCustomProtocolManager>();
     166#endif
     167#if PLATFORM(COCOA)
     168    addSupplement<LaunchServicesDatabaseObserver>();
    165169#endif
    166170#if PLATFORM(COCOA) && ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
  • trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb

    r264167 r264178  
    589589       (ipc-posix-name-prefix "apple.cfprefs."))
    590590 
    591 (allow mach-lookup
     591(deny mach-lookup
    592592    (global-name "com.apple.lsd.mapdb"))
    593593
  • trunk/Source/WebKit/Scripts/process-entitlements.sh

    r264167 r264178  
    1616    if [[ "${WK_USE_RESTRICTED_ENTITLEMENTS}" == YES ]]
    1717    then
     18        plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
    1819        plistbuddy Add :com.apple.rootless.storage.WebKitWebContentSandbox bool YES
    1920    fi
    … …  
    5253        fi
    5354
     55        plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
    5456        plistbuddy Add :com.apple.rootless.storage.WebKitNetworkingSandbox bool YES
    5557    fi
    … …  
    145147    plistbuddy Add :com.apple.private.webinspector.allow-remote-inspection bool YES
    146148    plistbuddy Add :com.apple.private.webinspector.proxy-application bool YES
     149    plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
    147150    plistbuddy Add :com.apple.runningboard.assertions.webkit bool YES
    148151    plistbuddy Add :dynamic-codesigning bool YES
    … …  
    185188    plistbuddy Add :com.apple.private.memorystatus bool YES
    186189    plistbuddy Add :com.apple.private.network.socket-delegate bool YES
     190    plistbuddy Add :com.apple.private.webkit.use-xpc-endpoint bool YES
    187191    plistbuddy Add :com.apple.runningboard.assertions.webkit bool YES
    188192
  • trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm

    r264167 r264178  
    3030#import <CoreFoundation/CoreFoundation.h>
    3131#import <pal/spi/cf/CFUtilitiesSPI.h>
     32#import <pal/spi/cocoa/LaunchServicesSPI.h>
    3233#import <wtf/OSObjectPtr.h>
    3334#import <wtf/RetainPtr.h>
  • trunk/Source/WebKit/SourcesCocoa.txt

    r264167 r264178  
    416416UIProcess/Inspector/mac/WKInspectorWKWebView.mm
    417417
     418UIProcess/Network/NetworkProcessProxyCocoa.mm
     419
    418420UIProcess/ios/forms/WKAirPlayRoutePicker.mm
    419421UIProcess/ios/forms/WKDatePickerViewController.mm
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r264167 r264178  
    935935#endif
    936936
     937OSObjectPtr<xpc_object_t> WebProcessPool::xpcEndpointMessage() const
     938{
     939    return m_endpointMessage;
     940}
     941
     942void WebProcessPool::sendNetworkProcessXPCEndpointToWebProcess(OSObjectPtr<xpc_object_t> endpointMessage)
     943{
     944    m_endpointMessage = endpointMessage;
     945
     946    for (auto process : m_processes) {
     947        if (process->state() != AuxiliaryProcessProxy::State::Running)
     948            continue;
     949        if (!process->connection())
     950            continue;
     951        auto connection = process->connection()->xpcConnection();
     952        xpc_connection_send_message(connection, endpointMessage.get());
     953    }
     954}
     955
    937956} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/Launcher/ProcessLauncher.h

    r264167 r264178  
    4040#endif
    4141
     42#if PLATFORM(COCOA)
     43#include "XPCEventHandler.h"
     44#endif
     45
    4246namespace WebKit {
    4347
    … …  
    5862        virtual bool shouldConfigureJSCForTesting() const { return false; }
    5963        virtual bool isJITEnabled() const { return true; }
     64#if PLATFORM(COCOA)
     65        virtual RefPtr<XPCEventHandler> xpcEventHandler() const { return nullptr; }
     66#endif
    6067    };
    6168   
  • trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r264167 r264178  
    239239    };
    240240
    241     auto errorHandler = [errorHandlerImpl = WTFMove(errorHandlerImpl)] (xpc_object_t event) mutable {
    242         RunLoop::main().dispatch([errorHandlerImpl = WTFMove(errorHandlerImpl), event] {
    243             errorHandlerImpl(event);
    244         });
     241    auto eventHandler = [errorHandlerImpl = WTFMove(errorHandlerImpl), eventHandler = m_client->xpcEventHandler()] (xpc_object_t event) mutable {
     242
     243        if (!event || xpc_get_type(event) == XPC_TYPE_ERROR) {
     244            RunLoop::main().dispatch([errorHandlerImpl = WTFMove(errorHandlerImpl), event = OSObjectPtr(event)] {
     245                errorHandlerImpl(event.get());
     246            });
     247            return;
     248        }
     249
     250        if (eventHandler) {
     251            RunLoop::main().dispatch([eventHandler = eventHandler, event = OSObjectPtr(event)] {
     252                eventHandler->handleXPCEvent(event.get());
     253            });
     254        }
    245255    };
    246256
    247     xpc_connection_set_event_handler(m_xpcConnection.get(), errorHandler);
     257    xpc_connection_set_event_handler(m_xpcConnection.get(), eventHandler);
    248258
    249259    xpc_connection_resume(m_xpcConnection.get());
    250260
    251261    if (UNLIKELY(m_launchOptions.shouldMakeProcessLaunchFailForTesting)) {
    252         errorHandler(nullptr);
     262        eventHandler(nullptr);
    253263        return;
    254264    }
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r264167 r264178  
    4343#if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
    4444#include "LegacyCustomProtocolManagerProxy.h"
     45#endif
     46
     47#if PLATFORM(COCOA)
     48#include "XPCEventHandler.h"
    4549#endif
    4650
    … …  
    298302    // ProcessLauncher::Client
    299303    void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
     304#if PLATFORM(COCOA)
     305    RefPtr<XPCEventHandler> xpcEventHandler() const override;
     306#endif
    300307
    301308    void processAuthenticationChallenge(PAL::SessionID, Ref<AuthenticationChallengeProxy>&&);
    … …  
    328335    };
    329336    Optional<UploadActivity> m_uploadActivity;
     337
     338#if PLATFORM(COCOA)
     339    class XPCEventHandler : public WebKit::XPCEventHandler {
     340    public:
     341        XPCEventHandler(const NetworkProcessProxy&);
     342
     343        bool handleXPCEvent(xpc_object_t) const override;
     344
     345    private:
     346        WeakPtr<NetworkProcessProxy> m_networkProcess;
     347    };
     348#endif
    330349};
    331350
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r264167 r264178  
    390390    // Network Process Management
    391391    NetworkProcessProxy& ensureNetworkProcess(WebsiteDataStore* withWebsiteDataStore = nullptr);
    392     NetworkProcessProxy* networkProcess() { return m_networkProcess.get(); }
     392    NetworkProcessProxy* networkProcess() const { return m_networkProcess.get(); }
    393393    void networkProcessCrashed(NetworkProcessProxy&);
    394394
    … …  
    542542#endif
    543543
     544#if PLATFORM(COCOA)
     545    OSObjectPtr<xpc_object_t> xpcEndpointMessage() const;
     546    void sendNetworkProcessXPCEndpointToWebProcess(OSObjectPtr<xpc_object_t> endpointMessage);
     547#endif
     548
    544549private:
    545550    void platformInitialize();
    … …  
    825830#if ENABLE(RESOURCE_LOAD_STATISTICS)
    826831    HashSet<WebCore::RegistrableDomain> m_domainsWithUserInteraction;
     832#endif
     833
     834#if PLATFORM(COCOA)
     835    OSObjectPtr<xpc_object_t> m_endpointMessage;
    827836#endif
    828837};
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp

    r264167 r264178  
    954954    }
    955955
     956#if PLATFORM(COCOA)
     957    auto endpointMessage = processPool().xpcEndpointMessage();
     958    if (endpointMessage)
     959        xpc_connection_send_message(connection()->xpcConnection(), endpointMessage.get());
     960#endif
     961
    956962    RELEASE_ASSERT(!m_webConnection);
    957963    m_webConnection = WebConnectionToWebProcess::create(this);
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r264167 r264178  
    16851685                C11E1694212B87C500985FF6 /* WKMockDisplay.h in Headers */ = {isa = PBXBuildFile; fileRef = C11E1692212B87C500985FF6 /* WKMockDisplay.h */; settings = {ATTRIBUTES = (Private, ); }; };
    16861686                C149380922347104000CD707 /* WebSpeechSynthesisClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C149380222341C60000CD707 /* WebSpeechSynthesisClient.h */; };
     1687                C14D37FE24ACE086007FF014 /* LaunchServicesDatabaseManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = C14D37FD24ACE086007FF014 /* LaunchServicesDatabaseManager.mm */; };
    16871688                C15CBB3623F3777100300CC7 /* PreferenceObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C145CC0E23DCA427003A5EEB /* PreferenceObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
    16881689                C15CBB3723F37ECB00300CC7 /* PreferenceObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB3323F34C3800300CC7 /* PreferenceObserver.mm */; };
     1690                C1663E5B24AEAA2F00C6A3B2 /* LaunchServicesDatabaseXPCConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = C1663E5A24AEA74200C6A3B2 /* LaunchServicesDatabaseXPCConstants.h */; };
     1691                C1710CF724AA643200D7C112 /* LaunchServicesDatabaseObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1710CF624AA643200D7C112 /* LaunchServicesDatabaseObserver.mm */; };
    16891692                C18173612058424700DFDA65 /* DisplayLink.h in Headers */ = {isa = PBXBuildFile; fileRef = C18173602058424700DFDA65 /* DisplayLink.h */; };
    16901693                C1E123BA20A11573002646F4 /* PDFContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = C1E123B920A11572002646F4 /* PDFContextMenu.h */; };
    … …  
    50195022                C149380322341DF7000CD707 /* WebSpeechSynthesisClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebSpeechSynthesisClient.cpp; sourceTree = "<group>"; };
    50205023                C149380A223853BE000CD707 /* WebSpeechSynthesisVoice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebSpeechSynthesisVoice.h; sourceTree = "<group>"; };
     5024                C14D37FC24ACDF45007FF014 /* LaunchServicesDatabaseManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchServicesDatabaseManager.h; sourceTree = "<group>"; };
     5025                C14D37FD24ACE086007FF014 /* LaunchServicesDatabaseManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LaunchServicesDatabaseManager.mm; sourceTree = "<group>"; };
    50215026                C15CBB3323F34C3800300CC7 /* PreferenceObserver.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferenceObserver.mm; sourceTree = "<group>"; };
     5027                C1663E5A24AEA74200C6A3B2 /* LaunchServicesDatabaseXPCConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchServicesDatabaseXPCConstants.h; sourceTree = "<group>"; };
     5028                C1710CF224A7BD0300D7C112 /* XPCEventHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPCEventHandler.h; sourceTree = "<group>"; };
     5029                C1710CF524AA634500D7C112 /* LaunchServicesDatabaseObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchServicesDatabaseObserver.h; sourceTree = "<group>"; };
     5030                C1710CF624AA643200D7C112 /* LaunchServicesDatabaseObserver.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LaunchServicesDatabaseObserver.mm; sourceTree = "<group>"; };
    50225031                C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DrawingAreaMac.cpp; sourceTree = "<group>"; };
    50235032                C18173602058424700DFDA65 /* DisplayLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayLink.h; sourceTree = "<group>"; };
    … …  
    50265035                C18FB51E242F9F77007E9875 /* WebSleepDisablerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSleepDisablerClient.h; sourceTree = "<group>"; };
    50275036                C1E123B920A11572002646F4 /* PDFContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFContextMenu.h; sourceTree = "<group>"; };
     5037                C1ED723724A5690E003F6CD3 /* NetworkProcessProxyCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkProcessProxyCocoa.mm; sourceTree = "<group>"; };
    50285038                C517388012DF8F4F00EE3F47 /* DragControllerAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragControllerAction.h; sourceTree = "<group>"; };
    50295039                C5237F5F12441CA300780472 /* WebEditorClientMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebEditorClientMac.mm; sourceTree = "<group>"; };
    … …  
    63856395                                2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
    63866396                                2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */,
     6397                                C1710CF224A7BD0300D7C112 /* XPCEventHandler.h */,
    63876398                        );
    63886399                        path = Cocoa;
    … …  
    74827493                                CE550E132283744400D28791 /* InsertTextOptions.cpp */,
    74837494                                CE550E12228373C800D28791 /* InsertTextOptions.h */,
     7495                                C1663E5A24AEA74200C6A3B2 /* LaunchServicesDatabaseXPCConstants.h */,
    74847496                                2D1087621D2C641B00B85F82 /* LoadParametersCocoa.mm */,
    74857497                                CD2865EC2255562000606AC7 /* ProcessTaskStateObserver.h */,
    … …  
    78457857                        isa = PBXGroup;
    78467858                        children = (
     7859                                C1ED723624A568F5003F6CD3 /* cocoa */,
    78477860                                29AD3091164B4C100072DEA9 /* CustomProtocols */,
    78487861                                516319931628980E00E22F00 /* mac */,
    … …  
    83758388                                CD4570CB2440FB2A00A3DCEB /* AudioSessionRoutingArbitrator.cpp */,
    83768389                                CD4570CA2440FB2A00A3DCEB /* AudioSessionRoutingArbitrator.h */,
     8390                                C14D37FC24ACDF45007FF014 /* LaunchServicesDatabaseManager.h */,
     8391                                C14D37FD24ACE086007FF014 /* LaunchServicesDatabaseManager.mm */,
    83778392                                446DC64B24A2D8AD0061F390 /* PlaybackSessionContextIdentifier.h */,
    83788393                                CDA29A191CBDBF4100901CCF /* PlaybackSessionManager.h */,
    … …  
    84268441                                2D0C56FB229F1DEA00BD33E7 /* DeviceManagementSoftLink.h */,
    84278442                                2D0C56FC229F1DEA00BD33E7 /* DeviceManagementSoftLink.mm */,
     8443                                C1710CF524AA634500D7C112 /* LaunchServicesDatabaseObserver.h */,
     8444                                C1710CF624AA643200D7C112 /* LaunchServicesDatabaseObserver.mm */,
    84288445                                5315876B2076B713004BF9F3 /* NetworkActivityTrackerCocoa.mm */,
    84298446                                5321594F1DBAE6D70054AA3C /* NetworkDataTaskCocoa.h */,
    … …  
    1025210269                        tabWidth = 8;
    1025310270                        usesTabs = 0;
     10271                };
     10272                C1ED723624A568F5003F6CD3 /* cocoa */ = {
     10273                        isa = PBXGroup;
     10274                        children = (
     10275                                C1ED723724A5690E003F6CD3 /* NetworkProcessProxyCocoa.mm */,
     10276                        );
     10277                        name = cocoa;
     10278                        sourceTree = "<group>";
    1025410279                };
    1025510280                C54256AE18BEC16100DE4179 /* forms */ = {
    … …  
    1085910884                                1AE49A4911FFA8CE0048B464 /* JSNPMethod.h in Headers */,
    1086010885                                1AE4987811FF7FAA0048B464 /* JSNPObject.h in Headers */,
     10886                                C1663E5B24AEAA2F00C6A3B2 /* LaunchServicesDatabaseXPCConstants.h in Headers */,
    1086110887                                BCE0937814FB128C001138D9 /* LayerHostingContext.h in Headers */,
    1086210888                                1A92DC1112F8BA460017AF65 /* LayerTreeContext.h in Headers */,
    … …  
    1272712753                                2D913441212CF9F000128AFD /* JSNPMethod.cpp in Sources */,
    1272812754                                2D913442212CF9F000128AFD /* JSNPObject.cpp in Sources */,
     12755                                C14D37FE24ACE086007FF014 /* LaunchServicesDatabaseManager.mm in Sources */,
     12756                                C1710CF724AA643200D7C112 /* LaunchServicesDatabaseObserver.mm in Sources */,
    1272912757                                2984F588164BA095004BC0C6 /* LegacyCustomProtocolManagerMessageReceiver.cpp in Sources */,
    1273012758                                2984F57C164B915F004BC0C6 /* LegacyCustomProtocolManagerProxyMessageReceiver.cpp in Sources */,
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm

    r264167 r264178  
    2828
    2929#import "InsertTextOptions.h"
     30#import "LaunchServicesDatabaseManager.h"
    3031#import "LoadParameters.h"
    3132#import "PluginView.h"
    … …  
    6364void WebPage::platformDidReceiveLoadParameters(const LoadParameters& parameters)
    6465{
     66    bool databaseUpdated =  LaunchServicesDatabaseManager::singleton().waitForDatabaseUpdate(5_s);
     67    ASSERT_UNUSED(databaseUpdated, databaseUpdated);
     68
    6569    m_dataDetectionContext = parameters.dataDetectionContext;
    6670
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r264167 r264178  
    291291    AuxiliaryProcess::initializeConnection(connection);
    292292
     293#if PLATFORM(COCOA)
     294    handleXPCEndpointMessages();
     295#endif
     296
    293297    // We call _exit() directly from the background queue in case the main thread is unresponsive
    294298    // and AuxiliaryProcess::didClose() does not get called.
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r264167 r264178  
    516516    bool isAlwaysOnLoggingAllowed() { return m_sessionID ? m_sessionID->isAlwaysOnLoggingAllowed() : true; }
    517517
     518#if PLATFORM(COCOA)
     519    void handleXPCEndpointMessages() const;
     520#endif
     521
    518522    RefPtr<WebConnectionToUIProcess> m_webConnection;
    519523
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r264167 r264178  
    2828#import "WebProcessCocoa.h"
    2929
     30#import "LaunchServicesDatabaseManager.h"
     31#import "LaunchServicesDatabaseXPCConstants.h"
    3032#import "LegacyCustomProtocolManager.h"
    3133#import "LogInitialization.h"
    … …  
    7072#import <WebCore/SystemBattery.h>
    7173#import <WebCore/UTIUtilities.h>
     74#import <WebCore/XPCEndpoint.h>
    7275#import <algorithm>
    7376#import <dispatch/dispatch.h>
    … …  
    162165#endif
    163166
     167void WebProcess::handleXPCEndpointMessages() const
     168{
     169    if (!parentProcessConnection())
     170        return;
     171
     172    auto connection = parentProcessConnection()->xpcConnection();
     173
     174    xpc_connection_set_target_queue(connection, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
     175    xpc_connection_set_event_handler(connection, ^(xpc_object_t event) {
     176        if (xpc_get_type(event) != XPC_TYPE_DICTIONARY)
     177            return;
     178
     179        String messageName = xpc_dictionary_get_string(event, XPCEndpoint::xpcMessageNameKey);
     180        if (messageName.isEmpty())
     181            return;
     182
     183        if (messageName == LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointMessageName) {
     184            auto endpoint = xpc_dictionary_get_value(event, LaunchServicesDatabaseXPCConstants::xpcLaunchServicesDatabaseXPCEndpointNameKey);
     185            LaunchServicesDatabaseManager::singleton().setEndpoint(endpoint);
     186            return;
     187        }
     188    });
     189}
     190
    164191void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
    165192{
    166     // Map Launch Services database. This should be done as early as possible, as the mapping will fail
    167     // if 'com.apple.lsd.mapdb' is being accessed before this.
    168     if (parameters.mapDBExtensionHandle) {
    169         auto extension = SandboxExtension::create(WTFMove(*parameters.mapDBExtensionHandle));
    170         bool ok = extension->consume();
    171         ASSERT_UNUSED(ok, ok);
    172         // Perform API calls which will communicate with the database mapping service, and map the database.
    173         auto uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0));
    174 
    175         [[objc_getClass("_LSDReadService") XPCConnectionToService] invalidate];
    176 
    177         ok = extension->revoke();
    178         ASSERT_UNUSED(ok, ok);
    179 
    180         ASSERT(String(uti.get()) == String(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0)).get()));
    181     }
    182 
     193#if HAVE(LSDATABASECONTEXT)
     194    // FIXME: Remove this entire section when the selector observeDatabaseChange4WebKit is present
     195    auto context = [NSClassFromString(@"LSDatabaseContext") sharedDatabaseContext];
     196    if (![context respondsToSelector:@selector(observeDatabaseChange4WebKit:)]) {
     197        // Map Launch Services database. This should be done as early as possible, as the mapping will fail
     198        // if 'com.apple.lsd.mapdb' is being accessed before this.
     199        if (parameters.mapDBExtensionHandle) {
     200            auto extension = SandboxExtension::create(WTFMove(*parameters.mapDBExtensionHandle));
     201            bool ok = extension->consume();
     202            ASSERT_UNUSED(ok, ok);
     203            // Perform API calls which will communicate with the database mapping service, and map the database.
     204            auto uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0));
     205            ok = extension->revoke();
     206            ASSERT_UNUSED(ok, ok);
     207            ASSERT(String(uti.get()) == String(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, CFSTR("text/html"), 0)).get()));
     208        }
     209    }
     210#endif
    183211#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    184212    WebCore::initializeLogChannelsIfNecessary(parameters.webCoreLoggingChannels);
Note: See TracChangeset for help on using the changeset viewer.