blob: 9f5261425162791668c2d15b7ffba091f831d652 [file] [log] [blame]
Robert Sesekb1cd8fe1a2018-08-21 18:32:531// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "sandbox/mac/system_services.h"
6
7#include <Carbon/Carbon.h>
8#include <CoreFoundation/CoreFoundation.h>
9
10#include "base/mac/mac_logging.h"
11
12extern "C" {
13OSStatus SetApplicationIsDaemon(Boolean isDaemon);
14void _LSSetApplicationLaunchServicesServerConnectionStatus(
15 uint64_t flags,
16 bool (^connection_allowed)(CFDictionaryRef options));
Robert Sesekedfd32d2020-09-10 18:38:3217
18// See
19// https://github.com/WebKit/webkit/commit/8da694b0b3febcc262653d01a45e946ce91845ed.
20void _CSCheckFixDisable() API_AVAILABLE(macosx(10.15));
Robert Sesekb1cd8fe1a2018-08-21 18:32:5321} // extern "C"
22
23namespace sandbox {
24
25void DisableLaunchServices() {
26 // Allow the process to continue without a LaunchServices ASN. The
27 // INIT_Process function in HIServices will abort if it cannot connect to
28 // launchservicesd to get an ASN. By setting this flag, HIServices skips
29 // that.
30 OSStatus status = SetApplicationIsDaemon(true);
31 OSSTATUS_LOG_IF(ERROR, status != noErr, status) << "SetApplicationIsDaemon";
32
33 // Close any connections to launchservicesd and use an always-false predicate
34 // to discourage future attempts to connect.
35 _LSSetApplicationLaunchServicesServerConnectionStatus(
36 0, ^bool(CFDictionaryRef options) {
37 return false;
38 });
39}
40
Robert Sesekedfd32d2020-09-10 18:38:3241void DisableCoreServicesCheckFix() {
42 if (__builtin_available(macOS 10.15, *)) {
43 _CSCheckFixDisable();
44 }
45}
46
Robert Sesekb1cd8fe1a2018-08-21 18:32:5347} // namespace sandbox