Skip to content
Permalink
Browse files
Adopt SPI to get default content of Launch Services database
https://bugs.webkit.org/show_bug.cgi?id=241286
<rdar://64528683>

Reviewed by Geoffrey Garen.

Adopt SPI to get system content of Launch Services database. If this SPI is available,
it will replace the SPI we currently use to retrieve the database in the Network process.

* Source/WebCore/PAL/pal/spi/cocoa/LaunchServicesSPI.h:
* Source/WebKit/NetworkProcess/cocoa/LaunchServicesDatabaseObserver.mm:
(WebKit::LaunchServicesDatabaseObserver::LaunchServicesDatabaseObserver):
(WebKit::LaunchServicesDatabaseObserver::startObserving):
(WebKit::LaunchServicesDatabaseObserver::~LaunchServicesDatabaseObserver):

Canonical link: https://commits.webkit.org/251428@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pvollan committed Jun 9, 2022
1 parent 321d351 commit 53534744963f787811701ff01a7a283a105f749f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
@@ -120,6 +120,8 @@ WTF_EXTERN_C_END
- (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
@@ -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
}

0 comments on commit 5353474

Please sign in to comment.