mas_no_private_api.patch 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Tue, 9 Oct 2018 10:36:20 -0700
  4. Subject: mas: avoid some private APIs
  5. Guard usages in blink of private Mac APIs by MAS_BUILD, so they can be
  6. excluded for people who want to submit their apps to the Mac App store.
  7. diff --git a/base/process/process_info_mac.cc b/base/process/process_info_mac.cc
  8. index 94a028be3c315edc0056408ab9ab41b6b001a1c1..0d830234edb5621f57e39f4a951d357a23f677c1 100644
  9. --- a/base/process/process_info_mac.cc
  10. +++ b/base/process/process_info_mac.cc
  11. @@ -8,15 +8,21 @@
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14. +#if !IS_MAS_BUILD()
  15. extern "C" {
  16. pid_t responsibility_get_pid_responsible_for_pid(pid_t);
  17. }
  18. +#endif
  19. namespace base {
  20. bool IsProcessSelfResponsible() {
  21. +#if !IS_MAS_BUILD()
  22. const pid_t pid = getpid();
  23. return responsibility_get_pid_responsible_for_pid(pid) == pid;
  24. +#else
  25. + return true;
  26. +#endif
  27. }
  28. } // namespace base
  29. diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
  30. index d4db3b179725cb96bcbd0f73db7d52ef8b7522db..6afbf1defb0591d9fe59a81e6c74746d3e15f081 100644
  31. --- a/content/renderer/renderer_main_platform_delegate_mac.mm
  32. +++ b/content/renderer/renderer_main_platform_delegate_mac.mm
  33. @@ -10,9 +10,11 @@
  34. #include "sandbox/mac/seatbelt.h"
  35. #include "sandbox/mac/system_services.h"
  36. +#if !IS_MAS_BUILD()
  37. extern "C" {
  38. CGError CGSSetDenyWindowServerConnections(bool);
  39. }
  40. +#endif
  41. namespace content {
  42. @@ -22,6 +24,7 @@
  43. // verifies there are no existing open connections), and then indicates that
  44. // Chrome should continue execution without access to launchservicesd.
  45. void DisableSystemServices() {
  46. +#if !IS_MAS_BUILD()
  47. // Tell the WindowServer that we don't want to make any future connections.
  48. // This will return Success as long as there are no open connections, which
  49. // is what we want.
  50. @@ -30,6 +33,7 @@ void DisableSystemServices() {
  51. sandbox::DisableLaunchServices();
  52. sandbox::DisableCoreServicesCheckFix();
  53. +#endif
  54. }
  55. } // namespace
  56. diff --git a/content/renderer/theme_helper_mac.mm b/content/renderer/theme_helper_mac.mm
  57. index a119b4439bfb9218c7aaf09dca8e78527da7f20d..faa813b003940280c6eeb87e70173019bdd5280c 100644
  58. --- a/content/renderer/theme_helper_mac.mm
  59. +++ b/content/renderer/theme_helper_mac.mm
  60. @@ -8,10 +8,11 @@
  61. #include "base/strings/sys_string_conversions.h"
  62. +#if !IS_MAS_BUILD()
  63. extern "C" {
  64. bool CGFontRenderingGetFontSmoothingDisabled(void);
  65. }
  66. -
  67. +#endif
  68. namespace content {
  69. void SystemColorsDidChange(int aqua_color_variant) {
  70. @@ -24,8 +25,18 @@ void SystemColorsDidChange(int aqua_color_variant) {
  71. }
  72. bool IsSubpixelAntialiasingAvailable() {
  73. +#if !IS_MAS_BUILD()
  74. // See https://trac.webkit.org/changeset/239306/webkit for more info.
  75. return !CGFontRenderingGetFontSmoothingDisabled();
  76. +#else
  77. + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  78. + NSString *default_key = @"CGFontRenderingGetFontSmoothingDisabled";
  79. + // Check that key exists since boolForKey defaults to NO when the
  80. + // key is missing and this key in fact defaults to YES;
  81. + if ([defaults objectForKey:default_key] == nil)
  82. + return false;
  83. + return ![defaults boolForKey:default_key];
  84. +#endif
  85. }
  86. } // namespace content
  87. diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
  88. index 4b1d57ef72d6a9235edc7a2591c8c3242c283235..680cf1ee57e0a9748a3b1efa93cb2d1569ac5655 100644
  89. --- a/device/bluetooth/bluetooth_adapter_mac.mm
  90. +++ b/device/bluetooth/bluetooth_adapter_mac.mm
  91. @@ -37,6 +37,7 @@
  92. #include "device/bluetooth/bluetooth_socket_mac.h"
  93. #include "device/bluetooth/public/cpp/bluetooth_address.h"
  94. +#if !IS_MAS_BUILD()
  95. extern "C" {
  96. // Undocumented IOBluetooth Preference API [1]. Used by `blueutil` [2] and
  97. // `Karabiner` [3] to programmatically control the Bluetooth state. Calling the
  98. @@ -50,6 +51,7 @@
  99. // [4] https://support.apple.com/kb/PH25091
  100. void IOBluetoothPreferenceSetControllerPowerState(int state);
  101. }
  102. +#endif
  103. namespace {
  104. @@ -93,8 +95,10 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  105. : controller_state_function_(
  106. base::BindRepeating(&BluetoothAdapterMac::GetHostControllerState,
  107. base::Unretained(this))),
  108. +#if !IS_MAS_BUILD()
  109. power_state_function_(
  110. base::BindRepeating(IOBluetoothPreferenceSetControllerPowerState)),
  111. +#endif
  112. classic_discovery_manager_(
  113. BluetoothDiscoveryManagerMac::CreateClassic(this)),
  114. device_paired_status_callback_(
  115. @@ -243,8 +247,12 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  116. }
  117. bool BluetoothAdapterMac::SetPoweredImpl(bool powered) {
  118. +#if !IS_MAS_BUILD()
  119. power_state_function_.Run(base::strict_cast<int>(powered));
  120. return true;
  121. +#else
  122. + return false;
  123. +#endif
  124. }
  125. base::WeakPtr<BluetoothLowEnergyAdapterApple>
  126. diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
  127. index 2f7b9f4fb591f92fc570a271cf7e557f0dce00f7..209d356ea8562f5af4d64c9a7699a7c4f67526e2 100644
  128. --- a/media/audio/mac/audio_manager_mac.cc
  129. +++ b/media/audio/mac/audio_manager_mac.cc
  130. @@ -969,7 +969,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
  131. void AudioManagerMac::InitializeOnAudioThread() {
  132. DCHECK(GetTaskRunner()->BelongsToCurrentThread());
  133. - InitializeCoreAudioDispatchOverride();
  134. + // InitializeCoreAudioDispatchOverride();
  135. power_observer_ = std::make_unique<AudioPowerObserver>();
  136. }
  137. diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
  138. index a93e7cd74d2a9d692304ecf10279fae8e96bb695..3506d6ca555701bad6623cc1c614e0081892e42b 100644
  139. --- a/net/dns/dns_config_service_posix.cc
  140. +++ b/net/dns/dns_config_service_posix.cc
  141. @@ -130,8 +130,8 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  142. bool Watch() override {
  143. CheckOnCorrectSequence();
  144. -
  145. bool success = true;
  146. +#if !IS_MAS_BUILD()
  147. if (!config_watcher_.Watch(base::BindRepeating(&Watcher::OnConfigChanged,
  148. base::Unretained(this)))) {
  149. LOG(ERROR) << "DNS config watch failed to start.";
  150. @@ -148,6 +148,7 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  151. success = false;
  152. }
  153. #endif // !BUILDFLAG(IS_IOS)
  154. +#endif
  155. return success;
  156. }
  157. diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
  158. index f35d9ef2a2df3db8ecbf1d7b909c7b1cf33f3cd9..a710b8b4f851666fd65bb37f69ec2fa70259697b 100644
  159. --- a/sandbox/mac/sandbox_compiler.cc
  160. +++ b/sandbox/mac/sandbox_compiler.cc
  161. @@ -47,6 +47,7 @@ bool SandboxCompiler::SetParameter(const std::string& key,
  162. }
  163. bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  164. +#if !IS_MAS_BUILD()
  165. if (mode_ == Target::kSource) {
  166. std::vector<const char*> params;
  167. @@ -67,6 +68,9 @@ bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  168. }
  169. }
  170. return false;
  171. +#else
  172. + return true;
  173. +#endif
  174. }
  175. bool SandboxCompiler::CompilePolicyToProto(mac::SandboxPolicy& policy,
  176. diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
  177. index 15c835e118456394c0a00ac98c11241c14ca75bd..83759e5fbc252fa57ca2fa122873dfac3d61d46d 100644
  178. --- a/sandbox/mac/seatbelt.cc
  179. +++ b/sandbox/mac/seatbelt.cc
  180. @@ -9,7 +9,7 @@
  181. extern "C" {
  182. #include <sandbox.h>
  183. -
  184. +#if !IS_MAS_BUILD()
  185. int sandbox_init_with_parameters(const char* profile,
  186. uint64_t flags,
  187. const char* const parameters[],
  188. @@ -40,13 +40,13 @@ sandbox_profile_t* sandbox_compile_string(const char* data,
  189. char** error);
  190. int sandbox_apply(sandbox_profile_t*);
  191. void sandbox_free_profile(sandbox_profile_t*);
  192. -
  193. +#endif
  194. } // extern "C"
  195. namespace sandbox {
  196. namespace {
  197. -
  198. +#if !IS_MAS_BUILD()
  199. bool HandleSandboxResult(int rv, char* errorbuf, std::string* error) {
  200. if (rv == 0) {
  201. if (error)
  202. @@ -74,36 +74,48 @@ bool HandleSandboxErrno(int rv, const char* message, std::string* error) {
  203. }
  204. return false;
  205. }
  206. -
  207. +#endif
  208. } // namespace
  209. // static
  210. Seatbelt::Parameters Seatbelt::Parameters::Create() {
  211. Parameters params;
  212. +#if !IS_MAS_BUILD()
  213. params.params_ = ::sandbox_create_params();
  214. +#endif
  215. return params;
  216. }
  217. Seatbelt::Parameters::Parameters() = default;
  218. Seatbelt::Parameters::Parameters(Seatbelt::Parameters&& other) {
  219. +#if !IS_MAS_BUILD()
  220. params_ = std::exchange(other.params_, nullptr);
  221. +#endif
  222. }
  223. Seatbelt::Parameters& Seatbelt::Parameters::operator=(
  224. Seatbelt::Parameters&& other) {
  225. +#if !IS_MAS_BUILD()
  226. params_ = std::exchange(other.params_, nullptr);
  227. +#endif
  228. return *this;
  229. }
  230. bool Seatbelt::Parameters::Set(const char* key, const char* value) {
  231. +#if !IS_MAS_BUILD()
  232. return ::sandbox_set_param(params_, key, value) == 0;
  233. +#else
  234. + return true;
  235. +#endif
  236. }
  237. Seatbelt::Parameters::~Parameters() {
  238. +#if !IS_MAS_BUILD()
  239. if (params_) {
  240. ::sandbox_free_params(params_);
  241. }
  242. +#endif
  243. }
  244. // Initialize the static member variables.
  245. @@ -114,6 +126,7 @@ const char* Seatbelt::kProfilePureComputation = kSBXProfilePureComputation;
  246. // static
  247. bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  248. +#if !IS_MAS_BUILD()
  249. // OS X deprecated these functions, but did not provide a suitable replacement,
  250. // so ignore the deprecation warning.
  251. #pragma clang diagnostic push
  252. @@ -122,6 +135,9 @@ bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  253. int rv = ::sandbox_init(profile, flags, &errorbuf);
  254. return HandleSandboxResult(rv, errorbuf, error);
  255. #pragma clang diagnostic pop
  256. +#else
  257. + return true;
  258. +#endif
  259. }
  260. // static
  261. @@ -129,10 +145,14 @@ bool Seatbelt::InitWithParams(const char* profile,
  262. uint64_t flags,
  263. const char* const parameters[],
  264. std::string* error) {
  265. +#if !IS_MAS_BUILD()
  266. char* errorbuf = nullptr;
  267. int rv =
  268. ::sandbox_init_with_parameters(profile, flags, parameters, &errorbuf);
  269. return HandleSandboxResult(rv, errorbuf, error);
  270. +#else
  271. + return true;
  272. +#endif
  273. }
  274. // static
  275. @@ -140,6 +160,7 @@ bool Seatbelt::Compile(const char* profile,
  276. const Seatbelt::Parameters& params,
  277. std::string& compiled_profile,
  278. std::string* error) {
  279. +#if !IS_MAS_BUILD()
  280. char* errorbuf = nullptr;
  281. sandbox_profile_t* sandbox_profile =
  282. ::sandbox_compile_string(profile, params.params(), &errorbuf);
  283. @@ -149,33 +170,44 @@ bool Seatbelt::Compile(const char* profile,
  284. compiled_profile.assign(reinterpret_cast<const char*>(sandbox_profile->data),
  285. sandbox_profile->size);
  286. ::sandbox_free_profile(sandbox_profile);
  287. +#endif
  288. return true;
  289. }
  290. // static
  291. bool Seatbelt::ApplyCompiledProfile(const std::string& profile,
  292. std::string* error) {
  293. +#if !IS_MAS_BUILD()
  294. sandbox_profile_t sbox_profile = {
  295. .builtin = nullptr,
  296. .data = reinterpret_cast<const uint8_t*>(profile.data()),
  297. .size = profile.size()};
  298. return HandleSandboxErrno(::sandbox_apply(&sbox_profile),
  299. "sandbox_apply: ", error);
  300. +#else
  301. + return true;
  302. +#endif
  303. }
  304. // static
  305. void Seatbelt::FreeError(char* errorbuf) {
  306. +#if !IS_MAS_BUILD()
  307. // OS X deprecated these functions, but did not provide a suitable replacement,
  308. // so ignore the deprecation warning.
  309. #pragma clang diagnostic push
  310. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  311. return ::sandbox_free_error(errorbuf);
  312. #pragma clang diagnostic pop
  313. +#endif
  314. }
  315. // static
  316. bool Seatbelt::IsSandboxed() {
  317. +#if !IS_MAS_BUILD()
  318. return ::sandbox_check(getpid(), NULL, 0);
  319. +#else
  320. + return true;
  321. +#endif
  322. }
  323. } // namespace sandbox
  324. diff --git a/sandbox/mac/seatbelt_extension.cc b/sandbox/mac/seatbelt_extension.cc
  325. index 18479382a277cb2b25626ec8d31442bfd1377ee6..7d80d7fa8337523c3a70f317f883f0cc26c6f40b 100644
  326. --- a/sandbox/mac/seatbelt_extension.cc
  327. +++ b/sandbox/mac/seatbelt_extension.cc
  328. @@ -11,6 +11,7 @@
  329. #include "base/notreached.h"
  330. #include "sandbox/mac/seatbelt_extension_token.h"
  331. +#if !IS_MAS_BUILD()
  332. // libsandbox private API.
  333. extern "C" {
  334. extern const char* APP_SANDBOX_READ;
  335. @@ -22,6 +23,7 @@ char* sandbox_extension_issue_file(const char* type,
  336. const char* path,
  337. uint32_t flags);
  338. }
  339. +#endif
  340. namespace sandbox {
  341. @@ -50,7 +52,11 @@ std::unique_ptr<SeatbeltExtension> SeatbeltExtension::FromToken(
  342. bool SeatbeltExtension::Consume() {
  343. DCHECK(!token_.empty());
  344. +#if !IS_MAS_BUILD()
  345. handle_ = sandbox_extension_consume(token_.c_str());
  346. +#else
  347. + handle_ = -1;
  348. +#endif
  349. return handle_ > 0;
  350. }
  351. @@ -62,7 +68,11 @@ bool SeatbeltExtension::ConsumePermanently() {
  352. }
  353. bool SeatbeltExtension::Revoke() {
  354. +#if !IS_MAS_BUILD()
  355. int rv = sandbox_extension_release(handle_);
  356. +#else
  357. + int rv = -1;
  358. +#endif
  359. handle_ = 0;
  360. token_.clear();
  361. return rv == 0;
  362. @@ -80,12 +90,14 @@ SeatbeltExtension::SeatbeltExtension(const std::string& token)
  363. char* SeatbeltExtension::IssueToken(SeatbeltExtension::Type type,
  364. const std::string& resource) {
  365. switch (type) {
  366. +#if !IS_MAS_BUILD()
  367. case FILE_READ:
  368. return sandbox_extension_issue_file(APP_SANDBOX_READ, resource.c_str(),
  369. 0);
  370. case FILE_READ_WRITE:
  371. return sandbox_extension_issue_file(APP_SANDBOX_READ_WRITE,
  372. resource.c_str(), 0);
  373. +#endif
  374. default:
  375. NOTREACHED();
  376. return nullptr;
  377. diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.mm b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  378. index 701b59231f2e5fbd31482775a248a0ff9755a480..271f9d1eebcf29aa7a8b98a0655038e75464a56b 100644
  379. --- a/ui/accessibility/platform/inspect/ax_transform_mac.mm
  380. +++ b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  381. @@ -108,6 +108,7 @@
  382. }
  383. }
  384. +#if !IS_MAS_BUILD()
  385. // AXTextMarker
  386. if (IsAXTextMarker(value)) {
  387. return AXTextMarkerToBaseValue(value, indexer);
  388. @@ -117,6 +118,7 @@
  389. if (IsAXTextMarkerRange(value)) {
  390. return AXTextMarkerRangeToBaseValue(value, indexer);
  391. }
  392. +#endif
  393. // Accessible object
  394. if (AXElementWrapper::IsValidElement(value)) {