mas_no_private_api.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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/content/common/pseudonymization_salt.cc b/content/common/pseudonymization_salt.cc
  8. index 28e003bef910abff022def659fe18d4cd0549f8a..530bcbdb5d350f6486dc1e8536f7b279be69e241 100644
  9. --- a/content/common/pseudonymization_salt.cc
  10. +++ b/content/common/pseudonymization_salt.cc
  11. @@ -41,11 +41,13 @@ uint32_t GetPseudonymizationSalt() {
  12. uint32_t salt = g_salt.load();
  13. if (salt == 0) {
  14. +#ifndef MAS_BUILD
  15. #if DCHECK_IS_ON()
  16. // Only the Browser process needs to initialize the `salt` on demand.
  17. // Other processes (identified via the IsProcessSandboxed heuristic) should
  18. // receive the salt from their parent processes.
  19. DCHECK(!sandbox::policy::Sandbox::IsProcessSandboxed());
  20. +#endif
  21. #endif
  22. salt = InitializeSalt();
  23. }
  24. diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
  25. index 894ac47e596c1c96a7e0659be80ed8a5629d0304..eca797a24df79b8502b9698e6ed8830ad1c5cb59 100644
  26. --- a/content/renderer/renderer_main_platform_delegate_mac.mm
  27. +++ b/content/renderer/renderer_main_platform_delegate_mac.mm
  28. @@ -10,9 +10,11 @@
  29. #include "sandbox/mac/seatbelt.h"
  30. #include "sandbox/mac/system_services.h"
  31. +#ifndef MAS_BUILD
  32. extern "C" {
  33. CGError CGSSetDenyWindowServerConnections(bool);
  34. }
  35. +#endif
  36. namespace content {
  37. @@ -22,6 +24,7 @@
  38. // verifies there are no existing open connections), and then indicates that
  39. // Chrome should continue execution without access to launchservicesd.
  40. void DisableSystemServices() {
  41. +#ifndef MAS_BUILD
  42. // Tell the WindowServer that we don't want to make any future connections.
  43. // This will return Success as long as there are no open connections, which
  44. // is what we want.
  45. @@ -30,6 +33,7 @@ void DisableSystemServices() {
  46. sandbox::DisableLaunchServices();
  47. sandbox::DisableCoreServicesCheckFix();
  48. +#endif
  49. }
  50. } // namespace
  51. diff --git a/content/renderer/theme_helper_mac.mm b/content/renderer/theme_helper_mac.mm
  52. index c15f3a631292b538698625328fb429ee3c9964f5..37e038753ecf1b82ec92c06b2c0729b5328781c9 100644
  53. --- a/content/renderer/theme_helper_mac.mm
  54. +++ b/content/renderer/theme_helper_mac.mm
  55. @@ -7,11 +7,11 @@
  56. #include <Cocoa/Cocoa.h>
  57. #include "base/strings/sys_string_conversions.h"
  58. -
  59. +#if !defined(MAS_BUILD)
  60. extern "C" {
  61. bool CGFontRenderingGetFontSmoothingDisabled(void) API_AVAILABLE(macos(10.14));
  62. }
  63. -
  64. +#endif
  65. namespace content {
  66. void SystemColorsDidChange(int aqua_color_variant,
  67. @@ -59,8 +59,19 @@ void SystemColorsDidChange(int aqua_color_variant,
  68. bool IsSubpixelAntialiasingAvailable() {
  69. if (__builtin_available(macOS 10.14, *)) {
  70. // See https://trac.webkit.org/changeset/239306/webkit for more info.
  71. +#if !defined(MAS_BUILD)
  72. return !CGFontRenderingGetFontSmoothingDisabled();
  73. +#else
  74. + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  75. + NSString *default_key = @"CGFontRenderingGetFontSmoothingDisabled";
  76. + // Check that key exists since boolForKey defaults to NO when the
  77. + // key is missing and this key in fact defaults to YES;
  78. + if ([defaults objectForKey:default_key] == nil)
  79. + return false;
  80. + return ![defaults boolForKey:default_key];
  81. +#endif
  82. }
  83. +
  84. return true;
  85. }
  86. diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
  87. index 3f7dce0281f7b5a540d7b9377ef14a8a6aa9a2fa..11d8419791f3e45d5242081422d452d4fc703833 100644
  88. --- a/device/bluetooth/bluetooth_adapter_mac.mm
  89. +++ b/device/bluetooth/bluetooth_adapter_mac.mm
  90. @@ -42,6 +42,7 @@
  91. #include "device/bluetooth/bluetooth_socket_mac.h"
  92. #include "device/bluetooth/public/cpp/bluetooth_address.h"
  93. +#ifndef MAS_BUILD
  94. extern "C" {
  95. // Undocumented IOBluetooth Preference API [1]. Used by `blueutil` [2] and
  96. // `Karabiner` [3] to programmatically control the Bluetooth state. Calling the
  97. @@ -55,6 +56,7 @@
  98. // [4] https://support.apple.com/kb/PH25091
  99. void IOBluetoothPreferenceSetControllerPowerState(int state);
  100. }
  101. +#endif
  102. namespace {
  103. @@ -123,8 +125,10 @@ CBCentralManagerState GetCBManagerState(CBCentralManager* manager) {
  104. controller_state_function_(
  105. base::BindRepeating(&BluetoothAdapterMac::GetHostControllerState,
  106. base::Unretained(this))),
  107. +#ifndef MAS_BUILD
  108. power_state_function_(
  109. base::BindRepeating(IOBluetoothPreferenceSetControllerPowerState)),
  110. +#endif
  111. classic_discovery_manager_(
  112. BluetoothDiscoveryManagerMac::CreateClassic(this)),
  113. low_energy_discovery_manager_(
  114. @@ -365,8 +369,12 @@ CBCentralManagerState GetCBManagerState(CBCentralManager* manager) {
  115. }
  116. bool BluetoothAdapterMac::SetPoweredImpl(bool powered) {
  117. +#ifndef MAS_BUILD
  118. power_state_function_.Run(base::strict_cast<int>(powered));
  119. return true;
  120. +#else
  121. + return false;
  122. +#endif
  123. }
  124. void BluetoothAdapterMac::RemovePairingDelegateInternal(
  125. diff --git a/media/audio/BUILD.gn b/media/audio/BUILD.gn
  126. index ebe37172d254e8441fe2b8c290bd5a59af38d754..6a131f5c41f3e43a1467efeec2ce63f6903691b7 100644
  127. --- a/media/audio/BUILD.gn
  128. +++ b/media/audio/BUILD.gn
  129. @@ -173,6 +173,12 @@ source_set("audio") {
  130. "mac/scoped_audio_unit.cc",
  131. "mac/scoped_audio_unit.h",
  132. ]
  133. + if (is_mas_build) {
  134. + sources -= [
  135. + "mac/coreaudio_dispatch_override.cc",
  136. + "mac/coreaudio_dispatch_override.h",
  137. + ]
  138. + }
  139. frameworks = [
  140. "AudioToolbox.framework",
  141. "AudioUnit.framework",
  142. diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
  143. index ebdc6364312ee710d416318836c03aeec9bfb65c..aa9b50de7efaf0e1b64effea93204984c91790b5 100644
  144. --- a/media/audio/mac/audio_manager_mac.cc
  145. +++ b/media/audio/mac/audio_manager_mac.cc
  146. @@ -886,7 +886,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
  147. void AudioManagerMac::InitializeOnAudioThread() {
  148. DCHECK(GetTaskRunner()->BelongsToCurrentThread());
  149. - InitializeCoreAudioDispatchOverride();
  150. + // InitializeCoreAudioDispatchOverride();
  151. power_observer_ = std::make_unique<AudioPowerObserver>();
  152. }
  153. diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
  154. index 3cce5f20af78f4456466df64fe0d040b5dba5fa8..1814ebbca91007b242a4e4ef359896594c23616a 100644
  155. --- a/net/dns/dns_config_service_posix.cc
  156. +++ b/net/dns/dns_config_service_posix.cc
  157. @@ -129,8 +129,8 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  158. bool Watch() override {
  159. CheckOnCorrectSequence();
  160. -
  161. bool success = true;
  162. +#ifndef MAS_BUILD
  163. if (!config_watcher_.Watch(base::BindRepeating(&Watcher::OnConfigChanged,
  164. base::Unretained(this)))) {
  165. LOG(ERROR) << "DNS config watch failed to start.";
  166. @@ -147,6 +147,7 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  167. success = false;
  168. }
  169. #endif // !BUILDFLAG(IS_IOS)
  170. +#endif
  171. return success;
  172. }
  173. diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
  174. index e524aa7b851022abed1edac39e18d8d92e5349b4..718d3f963da5c1a15a1bdb0e6043f89bc0f940f8 100644
  175. --- a/sandbox/mac/sandbox_compiler.cc
  176. +++ b/sandbox/mac/sandbox_compiler.cc
  177. @@ -28,6 +28,7 @@ bool SandboxCompiler::InsertStringParam(const std::string& key,
  178. }
  179. bool SandboxCompiler::CompileAndApplyProfile(std::string* error) {
  180. +#ifndef MAS_BUILD
  181. char* error_internal = nullptr;
  182. std::vector<const char*> params;
  183. @@ -44,6 +45,7 @@ bool SandboxCompiler::CompileAndApplyProfile(std::string* error) {
  184. sandbox::Seatbelt::FreeError(error_internal);
  185. return false;
  186. }
  187. +#endif
  188. return true;
  189. }
  190. diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
  191. index e0c31170acd13c9997c6b1d04c6de1420feaf422..0e561f97b33380bfbe52e64c2c4a6988095e8074 100644
  192. --- a/sandbox/mac/seatbelt.cc
  193. +++ b/sandbox/mac/seatbelt.cc
  194. @@ -64,7 +64,11 @@ void Seatbelt::FreeError(char* errorbuf) {
  195. // static
  196. bool Seatbelt::IsSandboxed() {
  197. +#ifndef MAS_BUILD
  198. return ::sandbox_check(getpid(), NULL, 0);
  199. +#else
  200. + return true;
  201. +#endif
  202. }
  203. } // namespace sandbox
  204. diff --git a/sandbox/mac/seatbelt_extension.cc b/sandbox/mac/seatbelt_extension.cc
  205. index d59a16112d27e2696437163483c44eca414c225c..1ccd20fe7efa3cbae48f99d0660b025283dd370e 100644
  206. --- a/sandbox/mac/seatbelt_extension.cc
  207. +++ b/sandbox/mac/seatbelt_extension.cc
  208. @@ -11,6 +11,7 @@
  209. #include "base/notreached.h"
  210. #include "sandbox/mac/seatbelt_extension_token.h"
  211. +#ifndef MAS_BUILD
  212. // libsandbox private API.
  213. extern "C" {
  214. extern const char* APP_SANDBOX_READ;
  215. @@ -22,6 +23,7 @@ char* sandbox_extension_issue_file(const char* type,
  216. const char* path,
  217. uint32_t flags);
  218. }
  219. +#endif
  220. namespace sandbox {
  221. @@ -50,7 +52,11 @@ std::unique_ptr<SeatbeltExtension> SeatbeltExtension::FromToken(
  222. bool SeatbeltExtension::Consume() {
  223. DCHECK(!token_.empty());
  224. +#ifndef MAS_BUILD
  225. handle_ = sandbox_extension_consume(token_.c_str());
  226. +#else
  227. + handle_ = -1;
  228. +#endif
  229. return handle_ > 0;
  230. }
  231. @@ -62,7 +68,11 @@ bool SeatbeltExtension::ConsumePermanently() {
  232. }
  233. bool SeatbeltExtension::Revoke() {
  234. +#ifndef MAS_BUILD
  235. int rv = sandbox_extension_release(handle_);
  236. +#else
  237. + int rv = -1;
  238. +#endif
  239. handle_ = 0;
  240. token_.clear();
  241. return rv == 0;
  242. @@ -80,12 +90,14 @@ SeatbeltExtension::SeatbeltExtension(const std::string& token)
  243. char* SeatbeltExtension::IssueToken(SeatbeltExtension::Type type,
  244. const std::string& resource) {
  245. switch (type) {
  246. +#ifndef MAS_BUILD
  247. case FILE_READ:
  248. return sandbox_extension_issue_file(APP_SANDBOX_READ, resource.c_str(),
  249. 0);
  250. case FILE_READ_WRITE:
  251. return sandbox_extension_issue_file(APP_SANDBOX_READ_WRITE,
  252. resource.c_str(), 0);
  253. +#endif
  254. default:
  255. NOTREACHED();
  256. return nullptr;
  257. diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.mm b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  258. index 7cb34e119cd30353fe56e7c71ed5e1d417896888..dbb6cc8e37eff9b30269687f29808ec3ca46b243 100644
  259. --- a/ui/accessibility/platform/inspect/ax_transform_mac.mm
  260. +++ b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  261. @@ -86,6 +86,7 @@
  262. }
  263. }
  264. +#ifndef MAS_BUILD
  265. // AXTextMarker
  266. if (IsAXTextMarker(value)) {
  267. return AXTextMarkerToBaseValue(value, indexer);
  268. @@ -94,6 +95,7 @@
  269. // AXTextMarkerRange
  270. if (IsAXTextMarkerRange(value))
  271. return AXTextMarkerRangeToBaseValue(value, indexer);
  272. +#endif
  273. // Accessible object
  274. if (IsNSAccessibilityElement(value) || IsAXUIElement(value)) {