Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h (295421 => 295422)
--- trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h 2022-06-09 15:58:02 UTC (rev 295421)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h 2022-06-09 17:16:02 UTC (rev 295422)
@@ -120,6 +120,8 @@
- (id <NSObject>)addDatabaseChangeObserver4WebKit:(void (^)(xpc_object_t change))observer;
- (void)removeDatabaseChangeObserver4WebKit:(id <NSObject>)token;
- (void)observeDatabaseChange4WebKit:(xpc_object_t)change;
+
+- (void)getSystemContentDatabaseObject4WebKit:(void (^)(xpc_object_t object, NSError *error))completion;
@end
#endif
#endif
Modified: trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm (295421 => 295422)
--- trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm 2022-06-09 15:58:02 UTC (rev 295421)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm 2022-06-09 17:16:02 UTC (rev 295422)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020, 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,14 +28,23 @@
#import "LaunchServicesDatabaseXPCConstants.h"
#import <pal/spi/cocoa/LaunchServicesSPI.h>
+#import <wtf/BlockPtr.h>
#import <wtf/cocoa/Entitlements.h>
#import <wtf/spi/cocoa/SecuritySPI.h>
namespace WebKit {
+static bool hasSystemContentDatabase()
+{
+ return [LSDatabaseContext.sharedDatabaseContext respondsToSelector:@selector(getSystemContentDatabaseObject4WebKit:)];
+}
+
LaunchServicesDatabaseObserver::LaunchServicesDatabaseObserver(NetworkProcess&)
{
#if HAVE(LSDATABASECONTEXT)
+ if (hasSystemContentDatabase())
+ return;
+
m_observer = [LSDatabaseContext.sharedDatabaseContext addDatabaseChangeObserver4WebKit:^(xpc_object_t change) {
auto message = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
xpc_dictionary_set_string(message.get(), XPCEndpoint::xpcMessageNameKey, LaunchServicesDatabaseXPCConstants::xpcUpdateLaunchServicesDatabaseMessageName);
@@ -63,6 +72,20 @@
}
#if HAVE(LSDATABASECONTEXT)
+ if (hasSystemContentDatabase()) {
+ [LSDatabaseContext.sharedDatabaseContext getSystemContentDatabaseObject4WebKit:makeBlockPtr([connection = connection] (xpc_object_t _Nullable object, NSError * _Nullable error) {
+ if (!object)
+ return;
+ 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, object);
+
+ xpc_connection_send_message(connection.get(), message.get());
+
+ }).get()];
+ return;
+ }
+
RetainPtr<id> observer = [LSDatabaseContext.sharedDatabaseContext addDatabaseChangeObserver4WebKit:^(xpc_object_t change) {
auto message = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
xpc_dictionary_set_string(message.get(), XPCEndpoint::xpcMessageNameKey, LaunchServicesDatabaseXPCConstants::xpcUpdateLaunchServicesDatabaseMessageName);
@@ -82,6 +105,8 @@
LaunchServicesDatabaseObserver::~LaunchServicesDatabaseObserver()
{
#if HAVE(LSDATABASECONTEXT)
+ if (hasSystemContentDatabase())
+ return;
[LSDatabaseContext.sharedDatabaseContext removeDatabaseChangeObserver4WebKit:m_observer.get()];
#endif
}