mas_avoid_private_macos_api_usage.patch.patch 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Samuel Attard <[email protected]>
  3. Date: Thu, 20 Sep 2018 17:48:49 -0700
  4. Subject: mas: avoid private macOS API usage
  5. * Use the stub killring file when building blink
  6. * Remove usage of the following private APIs
  7. * abort_report_np
  8. * pthread_fchdir_np
  9. * pthread_chdir_np
  10. * SetApplicationIsDaemon
  11. * _LSSetApplicationLaunchServicesServerConnectionStatus
  12. * AreDeviceAndUserJoinedToDomain
  13. * _CFIsObjC
  14. * AudioDeviceDuck
  15. * NSNextStepFrame
  16. * NSThemeFrame
  17. * NSTextInputReplacementRangeAttributeName
  18. * NSAccessibilityRemoteUIElement is unnecessary for Electron's use-case. We use it
  19. for progressive web apps (where the AXTree is in the browser process, but macOS
  20. needs to think it's coming from the PWA process). I think it can just be chopped
  21. out -- if there are any side-effects, we should be able to work around them.
  22. * CAContext removal
  23. * For apps that spend a lot of time watching video (especially fullscreen video),
  24. the power/battery usage will likely increase 1.5x to 2x. For something that is,
  25. e.g, scrolling, it'll be smaller, more like 1.15x or 1.25x.
  26. In terms of performance, the impact will likely be fairly small -- any app that
  27. could hit 60fps before will likely still be able to hit 60fps. There may even be
  28. cases where performance improves when disabling remote CoreAnimation (remote
  29. CoreAnimation is really only about battery usage).
  30. * CTFontDescriptorIsSystemUIFont is a private API, we're using an
  31. _interesting_ technique in the MAS build to determine if the font is a
  32. system font by checking if it's kCTFontPriorityAttribute is set to
  33. system priority.
  34. diff --git a/base/BUILD.gn b/base/BUILD.gn
  35. index e80597587f9afc01bc5b3e9f2a1dc9a5d9c4d4e0..5cf0e7276cdc167b42a45d680e7ba5fc58979e22 100644
  36. --- a/base/BUILD.gn
  37. +++ b/base/BUILD.gn
  38. @@ -1048,6 +1048,7 @@ component("base") {
  39. "//build/config/compiler:prevent_unsafe_narrowing",
  40. "//build/config/compiler:wexit_time_destructors",
  41. "//build/config/compiler:wglobal_constructors",
  42. + "//electron/build/config:mas_build",
  43. ]
  44. deps = [
  45. diff --git a/base/enterprise_util_mac.mm b/base/enterprise_util_mac.mm
  46. index 4bf9a3c27e05c6635b2beb8e880b5b43dbed61b5..57d4756c0d87b9313e8566b3083c0132966fcd78 100644
  47. --- a/base/enterprise_util_mac.mm
  48. +++ b/base/enterprise_util_mac.mm
  49. @@ -116,6 +116,14 @@ DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
  50. DeviceUserDomainJoinState state{.device_joined = false,
  51. .user_joined = false};
  52. +#if IS_MAS_BUILD()
  53. + return state;
  54. + }();
  55. +
  56. + return state;
  57. +}
  58. +#else
  59. +
  60. @autoreleasepool {
  61. ODSession* session = [ODSession defaultSession];
  62. if (session == nil) {
  63. @@ -219,5 +227,6 @@ DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
  64. return state;
  65. }
  66. +#endif
  67. } // namespace base
  68. diff --git a/base/process/launch_mac.cc b/base/process/launch_mac.cc
  69. index d1b09cb1a75000cf41f31bddcdcb739f776920aa..825a6ecd65bc4e3412db83413d6de34ea997ddd0 100644
  70. --- a/base/process/launch_mac.cc
  71. +++ b/base/process/launch_mac.cc
  72. @@ -21,13 +21,18 @@
  73. #include "base/threading/scoped_blocking_call.h"
  74. #include "base/threading/thread_restrictions.h"
  75. #include "base/trace_event/base_tracing.h"
  76. +#if IS_MAS_BUILD()
  77. +#include <sys/syscall.h>
  78. +#endif
  79. extern "C" {
  80. // Changes the current thread's directory to a path or directory file
  81. // descriptor.
  82. +#if !IS_MAS_BUILD()
  83. int pthread_chdir_np(const char* dir);
  84. int pthread_fchdir_np(int fd);
  85. +#endif
  86. int responsibility_spawnattrs_setdisclaim(posix_spawnattr_t attrs,
  87. int disclaim);
  88. @@ -99,13 +104,27 @@ class PosixSpawnFileActions {
  89. #if !BUILDFLAG(IS_MAC)
  90. int ChangeCurrentThreadDirectory(const char* path) {
  91. +#if IS_MAS_BUILD()
  92. + #pragma clang diagnostic push
  93. + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  94. + return syscall(SYS___pthread_chdir, path);
  95. + #pragma clang diagnostic pop
  96. +#else
  97. return pthread_chdir_np(path);
  98. +#endif
  99. }
  100. // The recommended way to unset a per-thread cwd is to set a new value to an
  101. // invalid file descriptor, per libpthread-218.1.3/private/private.h.
  102. int ResetCurrentThreadDirectory() {
  103. +#if IS_MAS_BUILD()
  104. + #pragma clang diagnostic push
  105. + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  106. + return syscall(SYS___pthread_fchdir, -1);
  107. + #pragma clang diagnostic pop
  108. +#else
  109. return pthread_fchdir_np(-1);
  110. +#endif
  111. }
  112. #endif
  113. @@ -226,7 +245,7 @@ Process LaunchProcess(const std::vector<std::string>& argv,
  114. file_actions.Inherit(STDERR_FILENO);
  115. }
  116. -#if BUILDFLAG(IS_MAC)
  117. +#if 0
  118. if (options.disclaim_responsibility) {
  119. DPSXCHECK(responsibility_spawnattrs_setdisclaim(attr.get(), 1));
  120. }
  121. diff --git a/base/process/process_info_mac.cc b/base/process/process_info_mac.cc
  122. index 94a028be3c315edc0056408ab9ab41b6b001a1c1..0d830234edb5621f57e39f4a951d357a23f677c1 100644
  123. --- a/base/process/process_info_mac.cc
  124. +++ b/base/process/process_info_mac.cc
  125. @@ -8,15 +8,21 @@
  126. #include <stdlib.h>
  127. #include <unistd.h>
  128. +#if !IS_MAS_BUILD()
  129. extern "C" {
  130. pid_t responsibility_get_pid_responsible_for_pid(pid_t);
  131. }
  132. +#endif
  133. namespace base {
  134. bool IsProcessSelfResponsible() {
  135. +#if !IS_MAS_BUILD()
  136. const pid_t pid = getpid();
  137. return responsibility_get_pid_responsible_for_pid(pid) == pid;
  138. +#else
  139. + return true;
  140. +#endif
  141. }
  142. } // namespace base
  143. diff --git a/components/os_crypt/sync/BUILD.gn b/components/os_crypt/sync/BUILD.gn
  144. index 4fe7a0bfaa5b3398372f55c6454e738f140efe6b..b1c70281c45aaca4ae483f1f28e9d21929d17815 100644
  145. --- a/components/os_crypt/sync/BUILD.gn
  146. +++ b/components/os_crypt/sync/BUILD.gn
  147. @@ -46,6 +46,7 @@ component("os_crypt") {
  148. "os_crypt_mac.mm",
  149. ]
  150. deps += [ "//crypto:mock_apple_keychain" ]
  151. + configs += ["//electron/build/config:mas_build"]
  152. }
  153. if (is_win) {
  154. diff --git a/components/remote_cocoa/app_shim/BUILD.gn b/components/remote_cocoa/app_shim/BUILD.gn
  155. index 459f14da45419a2a0340199d9cf311e3bba437e6..3b7908c559ddd3d6101801f8de256aa80a9411a2 100644
  156. --- a/components/remote_cocoa/app_shim/BUILD.gn
  157. +++ b/components/remote_cocoa/app_shim/BUILD.gn
  158. @@ -16,6 +16,7 @@ component("app_shim") {
  159. assert(is_mac)
  160. configs += [ ":app_shim_warnings" ]
  161. + configs += ["//electron/build/config:mas_build"]
  162. sources = [
  163. "NSToolbar+Private.h",
  164. "NSToolbar+Private.mm",
  165. diff --git a/components/remote_cocoa/app_shim/application_bridge.mm b/components/remote_cocoa/app_shim/application_bridge.mm
  166. index c8682418893584aaf61eb6db859b30c99b064698..5d1550030b519f3599dcb855007b25180f0606e9 100644
  167. --- a/components/remote_cocoa/app_shim/application_bridge.mm
  168. +++ b/components/remote_cocoa/app_shim/application_bridge.mm
  169. @@ -50,6 +50,7 @@
  170. // NativeWidgetNSWindowHostHelper:
  171. id GetNativeViewAccessible() override {
  172. +#if !IS_MAS_BUILD()
  173. if (!remote_accessibility_element_) {
  174. base::ProcessId browser_pid = base::kNullProcessId;
  175. std::vector<uint8_t> element_token;
  176. @@ -60,6 +61,9 @@ id GetNativeViewAccessible() override {
  177. ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
  178. }
  179. return remote_accessibility_element_;
  180. +#else
  181. + return nil;
  182. +#endif
  183. }
  184. void DispatchKeyEvent(ui::KeyEvent* event) override {
  185. bool event_handled = false;
  186. @@ -98,7 +102,9 @@ void GetWordAt(const gfx::Point& location_in_content,
  187. mojo::AssociatedRemote<mojom::TextInputHost> text_input_host_remote_;
  188. std::unique_ptr<NativeWidgetNSWindowBridge> bridge_;
  189. +#if !IS_MAS_BUILD()
  190. NSAccessibilityRemoteUIElement* __strong remote_accessibility_element_;
  191. +#endif
  192. };
  193. } // namespace
  194. diff --git a/components/remote_cocoa/app_shim/browser_native_widget_window_mac.mm b/components/remote_cocoa/app_shim/browser_native_widget_window_mac.mm
  195. index 53553a707a646012c50b0bd2d0ffd8d4dbd67e11..e9df78b2cf8ca8cb4cb8321769e9a56b96d368b6 100644
  196. --- a/components/remote_cocoa/app_shim/browser_native_widget_window_mac.mm
  197. +++ b/components/remote_cocoa/app_shim/browser_native_widget_window_mac.mm
  198. @@ -9,6 +9,7 @@
  199. #include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
  200. #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
  201. +#if !IS_MAS_BUILD()
  202. @interface NSWindow (PrivateBrowserNativeWidgetAPI)
  203. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
  204. @end
  205. @@ -65,10 +66,13 @@ - (BOOL)_shouldCenterTrafficLights {
  206. @end
  207. +#endif // MAS_BUILD
  208. +
  209. @implementation BrowserNativeWidgetWindow
  210. // NSWindow (PrivateAPI) overrides.
  211. +#if !IS_MAS_BUILD()
  212. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
  213. // - NSThemeFrame and its subclasses will be nil if it's missing at runtime.
  214. if ([BrowserWindowFrame class])
  215. @@ -115,6 +119,8 @@ - (BOOL)_usesCustomDrawing {
  216. return NO;
  217. }
  218. +#endif // MAS_BUILD
  219. +
  220. // Handle "Move focus to the window toolbar" configured in System Preferences ->
  221. // Keyboard -> Shortcuts -> Keyboard. Usually Ctrl+F5. The argument (|unknown|)
  222. // tends to just be nil.
  223. diff --git a/components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.mm b/components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.mm
  224. index 3a815ebf505bd95fa7f6b61ba433d98fbfe20225..dbbebbdc1735bc14224dfcde0b7fe3a6fd9f9e40 100644
  225. --- a/components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.mm
  226. +++ b/components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.mm
  227. @@ -4,6 +4,8 @@
  228. #import "components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.h"
  229. +#if !IS_MAS_BUILD()
  230. +
  231. @interface NSWindow (PrivateAPI)
  232. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
  233. @end
  234. @@ -18,8 +20,12 @@ - (CGFloat)_titlebarHeight {
  235. }
  236. @end
  237. +#endif // MAS_BUILD
  238. +
  239. @implementation NativeWidgetMacFramelessNSWindow
  240. +#if !IS_MAS_BUILD()
  241. +
  242. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
  243. if ([NativeWidgetMacFramelessNSWindowFrame class]) {
  244. return [NativeWidgetMacFramelessNSWindowFrame class];
  245. @@ -27,4 +33,6 @@ + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
  246. return [super frameViewClassForStyleMask:windowStyle];
  247. }
  248. +#endif // MAS_BUILD
  249. +
  250. @end
  251. diff --git a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h
  252. index 945b01f2132547fa0f6a97ee4895994c500d1410..c01b2fdecf9b54fa01e5be9f45eaa234fc42d06b 100644
  253. --- a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h
  254. +++ b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h
  255. @@ -17,6 +17,7 @@ class NativeWidgetNSWindowBridge;
  256. @protocol WindowTouchBarDelegate;
  257. +#if !IS_MAS_BUILD()
  258. // Weak lets Chrome launch even if a future macOS doesn't have the below classes
  259. WEAK_IMPORT_ATTRIBUTE
  260. @interface NSNextStepFrame : NSView
  261. @@ -33,6 +34,7 @@ REMOTE_COCOA_APP_SHIM_EXPORT
  262. REMOTE_COCOA_APP_SHIM_EXPORT
  263. @interface NativeWidgetMacNSWindowTitledFrame : NSThemeFrame
  264. @end
  265. +#endif
  266. // The NSWindow used by BridgedNativeWidget. Provides hooks into AppKit that
  267. // can only be accomplished by overriding methods.
  268. diff --git a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
  269. index 5df3e394a693939e021be4e9e3222989ae6e5122..06ec9f081f22afbda243bb69759dd1972dff8dd0 100644
  270. --- a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
  271. +++ b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
  272. @@ -106,14 +106,18 @@ void OrderChildWindow(NSWindow* child_window,
  273. } // namespace
  274. +#if !IS_MAS_BUILD()
  275. @interface NSNextStepFrame (Private)
  276. - (instancetype)initWithFrame:(NSRect)frame
  277. styleMask:(NSUInteger)styleMask
  278. owner:(id)owner;
  279. @end
  280. +#endif
  281. @interface NSWindow (Private)
  282. +#if !IS_MAS_BUILD()
  283. + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle;
  284. +#endif
  285. - (BOOL)hasKeyAppearance;
  286. - (long long)_resizeDirectionForMouseLocation:(CGPoint)location;
  287. - (BOOL)_isConsideredOpenForPersistentState;
  288. @@ -152,6 +156,8 @@ - (void)cr_mouseDownOnFrameView:(NSEvent*)event {
  289. }
  290. @end
  291. +#if !IS_MAS_BUILD()
  292. +
  293. @implementation NativeWidgetMacNSWindowTitledFrame
  294. - (void)mouseDown:(NSEvent*)event {
  295. if (self.window.isMovable)
  296. @@ -214,6 +220,8 @@ - (BOOL)usesCustomDrawing {
  297. }
  298. @end
  299. +#endif // MAS_BUILD
  300. +
  301. @implementation NativeWidgetMacNSWindow {
  302. @private
  303. CommandDispatcher* __strong _commandDispatcher;
  304. @@ -402,6 +410,8 @@ - (NSAccessibilityRole)accessibilityRole {
  305. // NSWindow overrides.
  306. +#if !IS_MAS_BUILD()
  307. +
  308. + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
  309. if (windowStyle & NSWindowStyleMaskTitled) {
  310. if (Class customFrame = [NativeWidgetMacNSWindowTitledFrame class])
  311. @@ -413,6 +423,8 @@ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
  312. return [super frameViewClassForStyleMask:windowStyle];
  313. }
  314. +#endif
  315. +
  316. - (BOOL)_isTitleHidden {
  317. bool shouldShowWindowTitle = YES;
  318. if (_bridge)
  319. diff --git a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  320. index b3c087eda0561d94d205ef0cbbb341a7e2a34638..035202378209e32e6f7c630140367cda7a34e483 100644
  321. --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  322. +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  323. @@ -627,10 +627,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
  324. // this should be treated as an error and caught early.
  325. CHECK(bridged_view_);
  326. +#if !IS_MAS_BUILD()
  327. // Send the accessibility tokens for the NSView now that it exists.
  328. host_->SetRemoteAccessibilityTokens(
  329. ui::RemoteAccessibility::GetTokenForLocalElement(window_),
  330. ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
  331. +#endif
  332. // Beware: This view was briefly removed (in favor of a bare CALayer) in
  333. // https://crrev.com/c/1236675. The ordering of unassociated layers relative
  334. diff --git a/components/viz/service/BUILD.gn b/components/viz/service/BUILD.gn
  335. index 2ce093d0818f52433670e889847fbf00b7d398cc..3c5ab7a6e6608b3f5e35f8b46a59880100b2a627 100644
  336. --- a/components/viz/service/BUILD.gn
  337. +++ b/components/viz/service/BUILD.gn
  338. @@ -364,6 +364,7 @@ viz_component("service") {
  339. "frame_sinks/external_begin_frame_source_mac.h",
  340. ]
  341. }
  342. + configs = ["//electron/build/config:mas_build"]
  343. }
  344. if (is_android || use_ozone) {
  345. @@ -635,6 +636,7 @@ viz_source_set("unit_tests") {
  346. "display_embedder/software_output_device_mac_unittest.mm",
  347. ]
  348. frameworks = [ "IOSurface.framework" ]
  349. + configs += ["//electron/build/config:mas_build"]
  350. }
  351. if (is_win) {
  352. diff --git a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  353. index dbf334caa3a6d10017b69ad76802e389a011436b..0cdb0def975e457651771b43fd5432610481c7d0 100644
  354. --- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  355. +++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  356. @@ -63,7 +63,9 @@ explicit RenderWidgetHostNSViewBridgeOwner(
  357. const RenderWidgetHostNSViewBridgeOwner&) = delete;
  358. private:
  359. +#if !IS_MAS_BUILD()
  360. NSAccessibilityRemoteUIElement* __strong remote_accessibility_element_;
  361. +#endif
  362. void OnMojoDisconnect() { delete this; }
  363. std::unique_ptr<blink::WebCoalescedInputEvent> TranslateEvent(
  364. @@ -75,6 +77,7 @@ explicit RenderWidgetHostNSViewBridgeOwner(
  365. }
  366. id GetAccessibilityElement() override {
  367. +#if !IS_MAS_BUILD()
  368. if (!remote_accessibility_element_) {
  369. base::ProcessId browser_pid = base::kNullProcessId;
  370. std::vector<uint8_t> element_token;
  371. @@ -85,6 +88,9 @@ id GetAccessibilityElement() override {
  372. ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
  373. }
  374. return remote_accessibility_element_;
  375. +#else
  376. + return nil;
  377. +#endif
  378. }
  379. // RenderWidgetHostNSViewHostHelper implementation.
  380. @@ -103,8 +109,10 @@ id GetFocusedBrowserAccessibilityElement() override {
  381. return [bridgedContentView accessibilityFocusedUIElement];
  382. }
  383. void SetAccessibilityWindow(NSWindow* window) override {
  384. +#if !IS_MAS_BUILD()
  385. host_->SetRemoteAccessibilityWindowToken(
  386. ui::RemoteAccessibility::GetTokenForLocalElement(window));
  387. +#endif
  388. }
  389. void ForwardKeyboardEvent(const input::NativeWebKeyboardEvent& key_event,
  390. diff --git a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  391. index 00493dc6c3f0229438b440a6fb2438ca668aba6b..6ce251058868529551cd6f008f840e06baa52bb7 100644
  392. --- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  393. +++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  394. @@ -2062,15 +2062,21 @@ - (NSAccessibilityRole)accessibilityRole {
  395. // Since this implementation doesn't have to wait any IPC calls, this doesn't
  396. // make any key-typing jank. --hbono 7/23/09
  397. //
  398. +#if !IS_MAS_BUILD()
  399. extern "C" {
  400. extern NSString* NSTextInputReplacementRangeAttributeName;
  401. }
  402. +#endif
  403. - (NSArray*)validAttributesForMarkedText {
  404. // This code is just copied from WebKit except renaming variables.
  405. static NSArray* const kAttributes = @[
  406. NSUnderlineStyleAttributeName, NSUnderlineColorAttributeName,
  407. +#if !IS_MAS_BUILD()
  408. NSMarkedClauseSegmentAttributeName, NSTextInputReplacementRangeAttributeName
  409. +#else
  410. + NSMarkedClauseSegmentAttributeName
  411. +#endif
  412. ];
  413. return kAttributes;
  414. }
  415. diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
  416. index 6b8d614f08dfe2e1c1b1458e70452195fb0934d6..684acd5d99dc1fa78261861870fb865a2d923c18 100644
  417. --- a/content/browser/BUILD.gn
  418. +++ b/content/browser/BUILD.gn
  419. @@ -70,6 +70,7 @@ source_set("browser") {
  420. "//content:content_implementation",
  421. "//v8:external_startup_data",
  422. ]
  423. + configs += ["//electron/build/config:mas_build"]
  424. defines = []
  425. libs = []
  426. frameworks = []
  427. diff --git a/content/browser/accessibility/browser_accessibility_manager_mac.mm b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  428. index 9485916338d16e11acbb56ea0b9b34e749db0281..45df87ec3bd98474513cef590b8312f8bd976947 100644
  429. --- a/content/browser/accessibility/browser_accessibility_manager_mac.mm
  430. +++ b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  431. @@ -20,7 +20,9 @@
  432. #include "ui/accessibility/ax_role_properties.h"
  433. #include "ui/accessibility/platform/ax_platform_tree_manager_delegate.h"
  434. #include "ui/accessibility/platform/ax_private_webkit_constants_mac.h"
  435. +#if !IS_MAS_BUILD()
  436. #include "ui/base/cocoa/remote_accessibility_api.h"
  437. +#endif
  438. namespace {
  439. @@ -224,6 +226,7 @@ void PostAnnouncementNotification(NSString* announcement,
  440. return;
  441. }
  442. +#if !IS_MAS_BUILD()
  443. BrowserAccessibilityManager* root_manager = GetManagerForRootFrame();
  444. if (root_manager) {
  445. BrowserAccessibilityManagerMac* root_manager_mac =
  446. @@ -246,6 +249,7 @@ void PostAnnouncementNotification(NSString* announcement,
  447. return;
  448. }
  449. }
  450. +#endif
  451. // Use native VoiceOver support for live regions.
  452. BrowserAccessibilityCocoa* retained_node = native_node;
  453. @@ -646,6 +650,7 @@ void PostAnnouncementNotification(NSString* announcement,
  454. return window == [NSApp accessibilityFocusedWindow];
  455. }
  456. +#if !IS_MAS_BUILD()
  457. // TODO(accessibility): We need a solution to the problem described below.
  458. // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
  459. // 1. NSApp is the browser which spawned the PWA, and what it considers the
  460. @@ -674,6 +679,7 @@ void PostAnnouncementNotification(NSString* announcement,
  461. if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]]) {
  462. return true;
  463. }
  464. +#endif
  465. return false;
  466. }
  467. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  468. index 940adeedcd38062b44afdeda1b41c89394e5e420..0809615a9818da6c6b5fd8363b168336a8f2e1ed 100644
  469. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  470. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  471. @@ -53,7 +53,9 @@ class CursorManager;
  472. @protocol RenderWidgetHostViewMacDelegate;
  473. +#if !IS_MAS_BUILD()
  474. @class NSAccessibilityRemoteUIElement;
  475. +#endif
  476. @class RenderWidgetHostViewCocoa;
  477. @class CursorAccessibilityScaleFactorObserver;
  478. @@ -685,9 +687,11 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  479. // EnsureSurfaceSynchronizedForWebTest().
  480. uint32_t latest_capture_sequence_number_ = 0u;
  481. +#if !IS_MAS_BUILD()
  482. // Remote accessibility objects corresponding to the NSWindow that this is
  483. // displayed to the user in.
  484. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  485. +#endif
  486. // Used to force the NSApplication's focused accessibility element to be the
  487. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  488. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  489. index 078f33c9c4b628b4427bb152912bf2a221e29efb..222a9cd87290efb0e30b503f9b6aaba122019bbe 100644
  490. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  491. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  492. @@ -272,8 +272,10 @@
  493. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  494. remote_cocoa::mojom::Application* remote_cocoa_application,
  495. uint64_t parent_ns_view_id) {
  496. +#if !IS_MAS_BUILD()
  497. // Destroy the previous remote accessibility element.
  498. remote_window_accessible_ = nil;
  499. +#endif
  500. // Reset `ns_view_` before resetting `remote_ns_view_` to avoid dangling
  501. // pointers. `ns_view_` gets reinitialized later in this method.
  502. @@ -1656,8 +1658,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  503. gfx::NativeViewAccessible
  504. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  505. +#if !IS_MAS_BUILD()
  506. if (remote_window_accessible_)
  507. return remote_window_accessible_;
  508. +#endif
  509. return [GetInProcessNSView() window];
  510. }
  511. @@ -1706,9 +1710,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  512. }
  513. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  514. +#if !IS_MAS_BUILD()
  515. // When running in-process, just use the NSView's NSWindow as its own
  516. // accessibility element.
  517. remote_window_accessible_ = nil;
  518. +#endif
  519. }
  520. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  521. @@ -2232,20 +2238,26 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  522. void RenderWidgetHostViewMac::GetRenderWidgetAccessibilityToken(
  523. GetRenderWidgetAccessibilityTokenCallback callback) {
  524. base::ProcessId pid = getpid();
  525. +#if !IS_MAS_BUILD()
  526. id element_id = GetNativeViewAccessible();
  527. std::vector<uint8_t> token =
  528. ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  529. std::move(callback).Run(pid, token);
  530. +#else
  531. + std::move(callback).Run(pid, std::vector<uint8_t>());
  532. +#endif
  533. }
  534. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  535. const std::vector<uint8_t>& window_token) {
  536. +#if !IS_MAS_BUILD()
  537. if (window_token.empty()) {
  538. remote_window_accessible_ = nil;
  539. } else {
  540. remote_window_accessible_ =
  541. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  542. }
  543. +#endif
  544. }
  545. ///////////////////////////////////////////////////////////////////////////////
  546. diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn
  547. index 0738636a7462fd973c12d0e26e298c3b767f0c53..977e90c5dc3d8ff48ba9674c1c7d5eb6b6bab662 100644
  548. --- a/content/common/BUILD.gn
  549. +++ b/content/common/BUILD.gn
  550. @@ -200,6 +200,7 @@ source_set("common") {
  551. "//content:content_implementation",
  552. "//build/config:precompiled_headers",
  553. ]
  554. + configs += ["//electron/build/config:mas_build"]
  555. public_deps = [
  556. ":mojo_bindings",
  557. diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn
  558. index 0208430b12c02be61bebee51a81f5a103d1f8e96..e1123d00068e6c007f869a6eb90d55fa66a84bdf 100644
  559. --- a/content/renderer/BUILD.gn
  560. +++ b/content/renderer/BUILD.gn
  561. @@ -230,6 +230,7 @@ target(link_target_type, "renderer") {
  562. }
  563. configs += [ "//content:content_implementation" ]
  564. + configs += ["//electron/build/config:mas_build"]
  565. defines = []
  566. public_deps = [
  567. diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
  568. index d4db3b179725cb96bcbd0f73db7d52ef8b7522db..6afbf1defb0591d9fe59a81e6c74746d3e15f081 100644
  569. --- a/content/renderer/renderer_main_platform_delegate_mac.mm
  570. +++ b/content/renderer/renderer_main_platform_delegate_mac.mm
  571. @@ -10,9 +10,11 @@
  572. #include "sandbox/mac/seatbelt.h"
  573. #include "sandbox/mac/system_services.h"
  574. +#if !IS_MAS_BUILD()
  575. extern "C" {
  576. CGError CGSSetDenyWindowServerConnections(bool);
  577. }
  578. +#endif
  579. namespace content {
  580. @@ -22,6 +24,7 @@
  581. // verifies there are no existing open connections), and then indicates that
  582. // Chrome should continue execution without access to launchservicesd.
  583. void DisableSystemServices() {
  584. +#if !IS_MAS_BUILD()
  585. // Tell the WindowServer that we don't want to make any future connections.
  586. // This will return Success as long as there are no open connections, which
  587. // is what we want.
  588. @@ -30,6 +33,7 @@ void DisableSystemServices() {
  589. sandbox::DisableLaunchServices();
  590. sandbox::DisableCoreServicesCheckFix();
  591. +#endif
  592. }
  593. } // namespace
  594. diff --git a/content/renderer/theme_helper_mac.mm b/content/renderer/theme_helper_mac.mm
  595. index a119b4439bfb9218c7aaf09dca8e78527da7f20d..faa813b003940280c6eeb87e70173019bdd5280c 100644
  596. --- a/content/renderer/theme_helper_mac.mm
  597. +++ b/content/renderer/theme_helper_mac.mm
  598. @@ -8,10 +8,11 @@
  599. #include "base/strings/sys_string_conversions.h"
  600. +#if !IS_MAS_BUILD()
  601. extern "C" {
  602. bool CGFontRenderingGetFontSmoothingDisabled(void);
  603. }
  604. -
  605. +#endif
  606. namespace content {
  607. void SystemColorsDidChange(int aqua_color_variant) {
  608. @@ -24,8 +25,18 @@ void SystemColorsDidChange(int aqua_color_variant) {
  609. }
  610. bool IsSubpixelAntialiasingAvailable() {
  611. +#if !IS_MAS_BUILD()
  612. // See https://trac.webkit.org/changeset/239306/webkit for more info.
  613. return !CGFontRenderingGetFontSmoothingDisabled();
  614. +#else
  615. + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  616. + NSString *default_key = @"CGFontRenderingGetFontSmoothingDisabled";
  617. + // Check that key exists since boolForKey defaults to NO when the
  618. + // key is missing and this key in fact defaults to YES;
  619. + if ([defaults objectForKey:default_key] == nil)
  620. + return false;
  621. + return ![defaults boolForKey:default_key];
  622. +#endif
  623. }
  624. } // namespace content
  625. diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn
  626. index 9be91de90914c3da214982e128ab3b506196232f..e0698a2ba0d23fd39702d19e34e1ef64c5cef0d4 100644
  627. --- a/content/test/BUILD.gn
  628. +++ b/content/test/BUILD.gn
  629. @@ -502,6 +502,7 @@ static_library("test_support") {
  630. configs += [
  631. "//build/config:precompiled_headers",
  632. "//v8:external_startup_data",
  633. + "//electron/build/config:mas_build",
  634. ]
  635. public_deps = [
  636. @@ -1103,6 +1104,7 @@ static_library("browsertest_support") {
  637. }
  638. configs += [ "//v8:external_startup_data" ]
  639. + configs += ["//electron/build/config:mas_build"]
  640. }
  641. mojom("content_test_mojo_bindings") {
  642. @@ -1718,6 +1720,7 @@ test("content_browsertests") {
  643. defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
  644. configs += [ "//build/config:precompiled_headers" ]
  645. + configs += ["//electron/build/config:mas_build"]
  646. public_deps = [
  647. ":test_interfaces",
  648. @@ -2974,6 +2977,7 @@ test("content_unittests") {
  649. }
  650. configs += [ "//build/config:precompiled_headers" ]
  651. + configs += ["//electron/build/config:mas_build"]
  652. public_deps = [ "//content:content_resources" ]
  653. diff --git a/content/web_test/BUILD.gn b/content/web_test/BUILD.gn
  654. index c28458b5ddc8ef74e82125a983344b1daf65dda6..48e6d48962a2228d26444dbdbcfa1637e67a8c56 100644
  655. --- a/content/web_test/BUILD.gn
  656. +++ b/content/web_test/BUILD.gn
  657. @@ -151,6 +151,8 @@ static_library("web_test_browser") {
  658. "browser/web_test_tts_platform.h",
  659. ]
  660. + configs += ["//electron/build/config:mas_build"]
  661. +
  662. if (is_mac) {
  663. sources += [ "browser/web_test_shell_platform_delegate_mac.mm" ]
  664. } else if (toolkit_views && !is_castos) {
  665. diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn
  666. index 2e53ca913d9b4380792df82f73dcfdd5177c0214..edb1e1a3283ee1978d64527c29ad207e9f06153a 100644
  667. --- a/device/bluetooth/BUILD.gn
  668. +++ b/device/bluetooth/BUILD.gn
  669. @@ -249,6 +249,7 @@ component("bluetooth") {
  670. "IOKit.framework",
  671. "Foundation.framework",
  672. ]
  673. + configs += ["//electron/build/config:mas_build"]
  674. }
  675. if (is_mac) {
  676. diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
  677. index 4244e70c523d584fb796f4ce741376c6f72531cd..25db1e83fefecd01820923e5d182b882426eebfd 100644
  678. --- a/device/bluetooth/bluetooth_adapter_mac.mm
  679. +++ b/device/bluetooth/bluetooth_adapter_mac.mm
  680. @@ -39,6 +39,7 @@
  681. #include "device/bluetooth/bluetooth_socket_mac.h"
  682. #include "device/bluetooth/public/cpp/bluetooth_address.h"
  683. +#if !IS_MAS_BUILD()
  684. extern "C" {
  685. // Undocumented IOBluetooth Preference API [1]. Used by `blueutil` [2] and
  686. // `Karabiner` [3] to programmatically control the Bluetooth state. Calling the
  687. @@ -52,6 +53,7 @@
  688. // [4] https://support.apple.com/kb/PH25091
  689. void IOBluetoothPreferenceSetControllerPowerState(int state);
  690. }
  691. +#endif
  692. // A simple helper class that forwards any Bluetooth device connect notification
  693. // to its wrapped |_adapter|.
  694. @@ -150,8 +152,10 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  695. : controller_state_function_(
  696. base::BindRepeating(&BluetoothAdapterMac::GetHostControllerState,
  697. base::Unretained(this))),
  698. +#if !IS_MAS_BUILD()
  699. power_state_function_(
  700. base::BindRepeating(IOBluetoothPreferenceSetControllerPowerState)),
  701. +#endif
  702. device_paired_status_callback_(
  703. base::BindRepeating(&IsDeviceSystemPaired)) {
  704. }
  705. @@ -297,8 +301,12 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  706. }
  707. bool BluetoothAdapterMac::SetPoweredImpl(bool powered) {
  708. +#if !IS_MAS_BUILD()
  709. power_state_function_.Run(base::strict_cast<int>(powered));
  710. return true;
  711. +#else
  712. + return false;
  713. +#endif
  714. }
  715. base::WeakPtr<BluetoothLowEnergyAdapterApple>
  716. diff --git a/gpu/ipc/service/BUILD.gn b/gpu/ipc/service/BUILD.gn
  717. index a4f541e3f4095a0f537137ae371555adc80c0023..f93f0b5bf8c47efbc67039d50e3bcd29e099459c 100644
  718. --- a/gpu/ipc/service/BUILD.gn
  719. +++ b/gpu/ipc/service/BUILD.gn
  720. @@ -135,6 +135,7 @@ component("service") {
  721. "QuartzCore.framework",
  722. ]
  723. defines += [ "GL_SILENCE_DEPRECATION" ]
  724. + configs += ["//electron/build/config:mas_build"]
  725. }
  726. if (is_ios) {
  727. sources += [ "image_transport_surface_ios.mm" ]
  728. diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.h b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  729. index 36322ddd3047f96569f35807541a37d3c6672b09..3162cb6e3dce2c44e5b1e5f33f9177da832d26aa 100644
  730. --- a/gpu/ipc/service/image_transport_surface_overlay_mac.h
  731. +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  732. @@ -23,7 +23,9 @@
  733. #include "ui/display/types/display_constants.h"
  734. #endif
  735. +#if !IS_MAS_BUILD()
  736. @class CAContext;
  737. +#endif
  738. @class CALayer;
  739. namespace ui {
  740. diff --git a/media/audio/BUILD.gn b/media/audio/BUILD.gn
  741. index 90e093cd2d499ba0f37f3246bab288c758b51e19..6027134a4de53e6fe39fdbfdb67885e0b5f56e40 100644
  742. --- a/media/audio/BUILD.gn
  743. +++ b/media/audio/BUILD.gn
  744. @@ -199,6 +199,7 @@ source_set("audio") {
  745. "CoreMedia.framework",
  746. ]
  747. weak_frameworks = [ "ScreenCaptureKit.framework" ] # macOS 13.0
  748. + configs += ["//electron/build/config:mas_build"]
  749. }
  750. if (is_ios) {
  751. diff --git a/media/audio/apple/audio_low_latency_input.cc b/media/audio/apple/audio_low_latency_input.cc
  752. index 808f4e1c7beb03cc5377465882940eea94ad61a7..d001436c3a5a8a0fc25995519772478f04ddb35f 100644
  753. --- a/media/audio/apple/audio_low_latency_input.cc
  754. +++ b/media/audio/apple/audio_low_latency_input.cc
  755. @@ -34,19 +34,23 @@
  756. namespace {
  757. extern "C" {
  758. +#if !IS_MAS_BUILD()
  759. // See:
  760. // https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/PAL/pal/spi/cf/CoreAudioSPI.h?rev=228264
  761. OSStatus AudioDeviceDuck(AudioDeviceID inDevice,
  762. Float32 inDuckedLevel,
  763. const AudioTimeStamp* __nullable inStartTime,
  764. Float32 inRampDuration) __attribute__((weak_import));
  765. +#endif
  766. }
  767. void UndoDucking(AudioDeviceID output_device_id) {
  768. +#if !IS_MAS_BUILD()
  769. if (AudioDeviceDuck != nullptr) {
  770. // Ramp the volume back up over half a second.
  771. AudioDeviceDuck(output_device_id, 1.0, nullptr, 0.5);
  772. }
  773. +#endif
  774. }
  775. } // namespace
  776. #endif
  777. diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
  778. index a5070091785d80a47d1d9d9977803cd1de8b2054..b280a0d58fc03257aa1763cd15791db4ddede7c1 100644
  779. --- a/media/audio/mac/audio_manager_mac.cc
  780. +++ b/media/audio/mac/audio_manager_mac.cc
  781. @@ -971,7 +971,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
  782. void AudioManagerMac::InitializeOnAudioThread() {
  783. DCHECK(GetTaskRunner()->BelongsToCurrentThread());
  784. - InitializeCoreAudioDispatchOverride();
  785. + // InitializeCoreAudioDispatchOverride();
  786. power_observer_ = std::make_unique<AudioPowerObserver>();
  787. }
  788. diff --git a/net/dns/BUILD.gn b/net/dns/BUILD.gn
  789. index 5f4ff9ff8172d4ad282cc9c781f85118b8ba7d1a..6a542c8f0d7afad876ab2739a1a2576a64cb6be9 100644
  790. --- a/net/dns/BUILD.gn
  791. +++ b/net/dns/BUILD.gn
  792. @@ -187,6 +187,8 @@ source_set("dns") {
  793. ":host_resolver_manager",
  794. ":mdns_client",
  795. ]
  796. +
  797. + configs += ["//electron/build/config:mas_build"]
  798. }
  799. # The standard API of net/dns.
  800. diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
  801. index 70d5665ad7b9ef62370497636af919ede2508ad4..3f6816de14f4bd19422a2b04830649d1d12e9179 100644
  802. --- a/net/dns/dns_config_service_posix.cc
  803. +++ b/net/dns/dns_config_service_posix.cc
  804. @@ -135,8 +135,8 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  805. bool Watch() override {
  806. CheckOnCorrectSequence();
  807. -
  808. bool success = true;
  809. +#if !IS_MAS_BUILD()
  810. if (!config_watcher_.Watch(base::BindRepeating(&Watcher::OnConfigChanged,
  811. base::Unretained(this)))) {
  812. LOG(ERROR) << "DNS config watch failed to start.";
  813. @@ -153,6 +153,7 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  814. success = false;
  815. }
  816. #endif // !BUILDFLAG(IS_IOS)
  817. +#endif
  818. return success;
  819. }
  820. diff --git a/sandbox/mac/BUILD.gn b/sandbox/mac/BUILD.gn
  821. index 299a028f23314f479d2da8f914a5bdf34698d854..672dcb04dd3cf4e3cc71403f727a1dde91ad4402 100644
  822. --- a/sandbox/mac/BUILD.gn
  823. +++ b/sandbox/mac/BUILD.gn
  824. @@ -39,6 +39,7 @@ component("seatbelt") {
  825. ]
  826. public_deps = [ "//third_party/protobuf:protobuf_lite" ]
  827. defines = [ "SEATBELT_IMPLEMENTATION" ]
  828. + configs += ["//electron/build/config:mas_build"]
  829. }
  830. component("seatbelt_extension") {
  831. @@ -52,6 +53,7 @@ component("seatbelt_extension") {
  832. libs = [ "sandbox" ]
  833. public_deps = [ "//base" ]
  834. defines = [ "SEATBELT_IMPLEMENTATION" ]
  835. + configs += ["//electron/build/config:mas_build"]
  836. }
  837. component("system_services") {
  838. @@ -66,6 +68,7 @@ component("system_services") {
  839. deps = [ ":seatbelt_export" ]
  840. public_deps = [ "//base" ]
  841. defines = [ "SEATBELT_IMPLEMENTATION" ]
  842. + configs += ["//electron/build/config:mas_build"]
  843. }
  844. source_set("sandbox_unittests") {
  845. diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
  846. index f35d9ef2a2df3db8ecbf1d7b909c7b1cf33f3cd9..a710b8b4f851666fd65bb37f69ec2fa70259697b 100644
  847. --- a/sandbox/mac/sandbox_compiler.cc
  848. +++ b/sandbox/mac/sandbox_compiler.cc
  849. @@ -47,6 +47,7 @@ bool SandboxCompiler::SetParameter(const std::string& key,
  850. }
  851. bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  852. +#if !IS_MAS_BUILD()
  853. if (mode_ == Target::kSource) {
  854. std::vector<const char*> params;
  855. @@ -67,6 +68,9 @@ bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  856. }
  857. }
  858. return false;
  859. +#else
  860. + return true;
  861. +#endif
  862. }
  863. bool SandboxCompiler::CompilePolicyToProto(mac::SandboxPolicy& policy,
  864. diff --git a/sandbox/mac/sandbox_logging.cc b/sandbox/mac/sandbox_logging.cc
  865. index 095c639b9893e885d8937e29ed7d47a7c28bc6b6..cfa5e307de8326fbc335996feaf9595d1572cd3d 100644
  866. --- a/sandbox/mac/sandbox_logging.cc
  867. +++ b/sandbox/mac/sandbox_logging.cc
  868. @@ -33,9 +33,11 @@
  869. }
  870. #endif
  871. +#if !IS_MAS_BUILD()
  872. extern "C" {
  873. void abort_report_np(const char*, ...);
  874. }
  875. +#endif
  876. namespace sandbox::logging {
  877. @@ -76,9 +78,11 @@ void SendOsLog(Level level, const char* message) {
  878. sandbox::crash_message::SetCrashMessage(message);
  879. }
  880. +#if !IS_MAS_BUILD()
  881. if (level == Level::FATAL) {
  882. abort_report_np(message);
  883. }
  884. +#endif
  885. }
  886. // |error| is strerror(errno) when a P* logging function is called. Pass
  887. diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
  888. index 15c835e118456394c0a00ac98c11241c14ca75bd..83759e5fbc252fa57ca2fa122873dfac3d61d46d 100644
  889. --- a/sandbox/mac/seatbelt.cc
  890. +++ b/sandbox/mac/seatbelt.cc
  891. @@ -9,7 +9,7 @@
  892. extern "C" {
  893. #include <sandbox.h>
  894. -
  895. +#if !IS_MAS_BUILD()
  896. int sandbox_init_with_parameters(const char* profile,
  897. uint64_t flags,
  898. const char* const parameters[],
  899. @@ -40,13 +40,13 @@ sandbox_profile_t* sandbox_compile_string(const char* data,
  900. char** error);
  901. int sandbox_apply(sandbox_profile_t*);
  902. void sandbox_free_profile(sandbox_profile_t*);
  903. -
  904. +#endif
  905. } // extern "C"
  906. namespace sandbox {
  907. namespace {
  908. -
  909. +#if !IS_MAS_BUILD()
  910. bool HandleSandboxResult(int rv, char* errorbuf, std::string* error) {
  911. if (rv == 0) {
  912. if (error)
  913. @@ -74,36 +74,48 @@ bool HandleSandboxErrno(int rv, const char* message, std::string* error) {
  914. }
  915. return false;
  916. }
  917. -
  918. +#endif
  919. } // namespace
  920. // static
  921. Seatbelt::Parameters Seatbelt::Parameters::Create() {
  922. Parameters params;
  923. +#if !IS_MAS_BUILD()
  924. params.params_ = ::sandbox_create_params();
  925. +#endif
  926. return params;
  927. }
  928. Seatbelt::Parameters::Parameters() = default;
  929. Seatbelt::Parameters::Parameters(Seatbelt::Parameters&& other) {
  930. +#if !IS_MAS_BUILD()
  931. params_ = std::exchange(other.params_, nullptr);
  932. +#endif
  933. }
  934. Seatbelt::Parameters& Seatbelt::Parameters::operator=(
  935. Seatbelt::Parameters&& other) {
  936. +#if !IS_MAS_BUILD()
  937. params_ = std::exchange(other.params_, nullptr);
  938. +#endif
  939. return *this;
  940. }
  941. bool Seatbelt::Parameters::Set(const char* key, const char* value) {
  942. +#if !IS_MAS_BUILD()
  943. return ::sandbox_set_param(params_, key, value) == 0;
  944. +#else
  945. + return true;
  946. +#endif
  947. }
  948. Seatbelt::Parameters::~Parameters() {
  949. +#if !IS_MAS_BUILD()
  950. if (params_) {
  951. ::sandbox_free_params(params_);
  952. }
  953. +#endif
  954. }
  955. // Initialize the static member variables.
  956. @@ -114,6 +126,7 @@ const char* Seatbelt::kProfilePureComputation = kSBXProfilePureComputation;
  957. // static
  958. bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  959. +#if !IS_MAS_BUILD()
  960. // OS X deprecated these functions, but did not provide a suitable replacement,
  961. // so ignore the deprecation warning.
  962. #pragma clang diagnostic push
  963. @@ -122,6 +135,9 @@ bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  964. int rv = ::sandbox_init(profile, flags, &errorbuf);
  965. return HandleSandboxResult(rv, errorbuf, error);
  966. #pragma clang diagnostic pop
  967. +#else
  968. + return true;
  969. +#endif
  970. }
  971. // static
  972. @@ -129,10 +145,14 @@ bool Seatbelt::InitWithParams(const char* profile,
  973. uint64_t flags,
  974. const char* const parameters[],
  975. std::string* error) {
  976. +#if !IS_MAS_BUILD()
  977. char* errorbuf = nullptr;
  978. int rv =
  979. ::sandbox_init_with_parameters(profile, flags, parameters, &errorbuf);
  980. return HandleSandboxResult(rv, errorbuf, error);
  981. +#else
  982. + return true;
  983. +#endif
  984. }
  985. // static
  986. @@ -140,6 +160,7 @@ bool Seatbelt::Compile(const char* profile,
  987. const Seatbelt::Parameters& params,
  988. std::string& compiled_profile,
  989. std::string* error) {
  990. +#if !IS_MAS_BUILD()
  991. char* errorbuf = nullptr;
  992. sandbox_profile_t* sandbox_profile =
  993. ::sandbox_compile_string(profile, params.params(), &errorbuf);
  994. @@ -149,33 +170,44 @@ bool Seatbelt::Compile(const char* profile,
  995. compiled_profile.assign(reinterpret_cast<const char*>(sandbox_profile->data),
  996. sandbox_profile->size);
  997. ::sandbox_free_profile(sandbox_profile);
  998. +#endif
  999. return true;
  1000. }
  1001. // static
  1002. bool Seatbelt::ApplyCompiledProfile(const std::string& profile,
  1003. std::string* error) {
  1004. +#if !IS_MAS_BUILD()
  1005. sandbox_profile_t sbox_profile = {
  1006. .builtin = nullptr,
  1007. .data = reinterpret_cast<const uint8_t*>(profile.data()),
  1008. .size = profile.size()};
  1009. return HandleSandboxErrno(::sandbox_apply(&sbox_profile),
  1010. "sandbox_apply: ", error);
  1011. +#else
  1012. + return true;
  1013. +#endif
  1014. }
  1015. // static
  1016. void Seatbelt::FreeError(char* errorbuf) {
  1017. +#if !IS_MAS_BUILD()
  1018. // OS X deprecated these functions, but did not provide a suitable replacement,
  1019. // so ignore the deprecation warning.
  1020. #pragma clang diagnostic push
  1021. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  1022. return ::sandbox_free_error(errorbuf);
  1023. #pragma clang diagnostic pop
  1024. +#endif
  1025. }
  1026. // static
  1027. bool Seatbelt::IsSandboxed() {
  1028. +#if !IS_MAS_BUILD()
  1029. return ::sandbox_check(getpid(), NULL, 0);
  1030. +#else
  1031. + return true;
  1032. +#endif
  1033. }
  1034. } // namespace sandbox
  1035. diff --git a/sandbox/mac/seatbelt_extension.cc b/sandbox/mac/seatbelt_extension.cc
  1036. index b3f017a8be25209a78ed6a1221abcdeeb7904752..506d520e41f321e02b227e07b7b41a4bbfec8d4d 100644
  1037. --- a/sandbox/mac/seatbelt_extension.cc
  1038. +++ b/sandbox/mac/seatbelt_extension.cc
  1039. @@ -11,6 +11,7 @@
  1040. #include "base/notreached.h"
  1041. #include "sandbox/mac/seatbelt_extension_token.h"
  1042. +#if !IS_MAS_BUILD()
  1043. // libsandbox private API.
  1044. extern "C" {
  1045. extern const char* APP_SANDBOX_READ;
  1046. @@ -22,6 +23,7 @@ char* sandbox_extension_issue_file(const char* type,
  1047. const char* path,
  1048. uint32_t flags);
  1049. }
  1050. +#endif
  1051. namespace sandbox {
  1052. @@ -50,7 +52,11 @@ std::unique_ptr<SeatbeltExtension> SeatbeltExtension::FromToken(
  1053. bool SeatbeltExtension::Consume() {
  1054. DCHECK(!token_.empty());
  1055. +#if !IS_MAS_BUILD()
  1056. handle_ = sandbox_extension_consume(token_.c_str());
  1057. +#else
  1058. + handle_ = -1;
  1059. +#endif
  1060. return handle_ > 0;
  1061. }
  1062. @@ -62,7 +68,11 @@ bool SeatbeltExtension::ConsumePermanently() {
  1063. }
  1064. bool SeatbeltExtension::Revoke() {
  1065. +#if !IS_MAS_BUILD()
  1066. int rv = sandbox_extension_release(handle_);
  1067. +#else
  1068. + int rv = -1;
  1069. +#endif
  1070. handle_ = 0;
  1071. token_.clear();
  1072. return rv == 0;
  1073. @@ -80,12 +90,14 @@ SeatbeltExtension::SeatbeltExtension(const std::string& token)
  1074. char* SeatbeltExtension::IssueToken(SeatbeltExtension::Type type,
  1075. const std::string& resource) {
  1076. switch (type) {
  1077. +#if !IS_MAS_BUILD()
  1078. case FILE_READ:
  1079. return sandbox_extension_issue_file(APP_SANDBOX_READ, resource.c_str(),
  1080. 0);
  1081. case FILE_READ_WRITE:
  1082. return sandbox_extension_issue_file(APP_SANDBOX_READ_WRITE,
  1083. resource.c_str(), 0);
  1084. +#endif
  1085. default:
  1086. NOTREACHED_IN_MIGRATION();
  1087. return nullptr;
  1088. diff --git a/sandbox/mac/system_services.cc b/sandbox/mac/system_services.cc
  1089. index eb81a70e4d5d5cd3e6ae9b45f8cd1c795ea76c51..dc30306f2c5d20503399fc3a8860773aa0044352 100644
  1090. --- a/sandbox/mac/system_services.cc
  1091. +++ b/sandbox/mac/system_services.cc
  1092. @@ -9,6 +9,7 @@
  1093. #include "base/apple/osstatus_logging.h"
  1094. +#if !IS_MAS_BUILD()
  1095. extern "C" {
  1096. OSStatus SetApplicationIsDaemon(Boolean isDaemon);
  1097. void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1098. @@ -19,10 +20,12 @@ void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1099. // https://github.com/WebKit/WebKit/blob/24aaedc770d192d03a07ba4a71727274aaa8fc07/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm#L840
  1100. void _CSCheckFixDisable();
  1101. } // extern "C"
  1102. +#endif
  1103. namespace sandbox {
  1104. void DisableLaunchServices() {
  1105. + #if !IS_MAS_BUILD()
  1106. // Allow the process to continue without a LaunchServices ASN. The
  1107. // INIT_Process function in HIServices will abort if it cannot connect to
  1108. // launchservicesd to get an ASN. By setting this flag, HIServices skips
  1109. @@ -36,10 +39,13 @@ void DisableLaunchServices() {
  1110. 0, ^bool(CFDictionaryRef options) {
  1111. return false;
  1112. });
  1113. + #endif
  1114. }
  1115. void DisableCoreServicesCheckFix() {
  1116. +#if !IS_MAS_BUILD()
  1117. _CSCheckFixDisable();
  1118. +#endif
  1119. }
  1120. } // namespace sandbox
  1121. diff --git a/third_party/blink/renderer/core/BUILD.gn b/third_party/blink/renderer/core/BUILD.gn
  1122. index fb1e7f7238358ca9d505f76a158b88f4412412f7..3340e675bed474cba55d78b249c4658dcf91f990 100644
  1123. --- a/third_party/blink/renderer/core/BUILD.gn
  1124. +++ b/third_party/blink/renderer/core/BUILD.gn
  1125. @@ -332,6 +332,7 @@ component("core") {
  1126. configs -= core_config_remove
  1127. configs += core_config_add
  1128. configs += [ "//v8:external_startup_data" ]
  1129. + configs += ["//electron/build/config:mas_build"]
  1130. public_deps = [
  1131. ":buildflags",
  1132. diff --git a/third_party/blink/renderer/core/editing/build.gni b/third_party/blink/renderer/core/editing/build.gni
  1133. index f12dd0a759fd8a79e648e14711274ccc40642a3d..63ae0ca4f63e68913c809b9440a922a95e914dcd 100644
  1134. --- a/third_party/blink/renderer/core/editing/build.gni
  1135. +++ b/third_party/blink/renderer/core/editing/build.gni
  1136. @@ -354,10 +354,14 @@ blink_core_sources_editing = [
  1137. if (is_mac) {
  1138. blink_core_sources_editing += [
  1139. "commands/smart_replace_cf.cc",
  1140. - "kill_ring_mac.mm",
  1141. "substring_util.h",
  1142. "substring_util.mm",
  1143. ]
  1144. + if (is_mas_build) {
  1145. + blink_core_sources_editing += [ "kill_ring_mac.mm" ]
  1146. + } else {
  1147. + blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1148. + }
  1149. } else {
  1150. blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1151. }
  1152. diff --git a/ui/accelerated_widget_mac/BUILD.gn b/ui/accelerated_widget_mac/BUILD.gn
  1153. index 3ead42e14ad9d41a30c5637678a3ac49296ce2a6..8dec61ee6a62e54ec3c8c5dd5e08601c28d04dfe 100644
  1154. --- a/ui/accelerated_widget_mac/BUILD.gn
  1155. +++ b/ui/accelerated_widget_mac/BUILD.gn
  1156. @@ -33,6 +33,8 @@ component("accelerated_widget_mac") {
  1157. "QuartzCore.framework",
  1158. ]
  1159. + configs += ["//electron/build/config:mas_build"]
  1160. +
  1161. if (is_ios) {
  1162. sources += [ "ca_layer_frame_sink_provider.h" ]
  1163. }
  1164. diff --git a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1165. index b11c365f42dd1ddc363de0d94c387b13ac65bef3..c274340cac7aaf22321b9cd35a8fad2c6eeae5ce 100644
  1166. --- a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1167. +++ b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1168. @@ -14,7 +14,9 @@
  1169. #include "ui/gl/gl_surface.h"
  1170. #include "ui/gl/presenter.h"
  1171. +#if !IS_MAS_BUILD()
  1172. @class CAContext;
  1173. +#endif
  1174. @class CALayer;
  1175. namespace ui {
  1176. @@ -110,7 +112,9 @@ class ACCELERATED_WIDGET_MAC_EXPORT CALayerTreeCoordinator {
  1177. // both the current tree and the pending trees.
  1178. size_t presented_ca_layer_trees_max_length_ = 2;
  1179. +#if !IS_MAS_BUILD()
  1180. CAContext* __strong ca_context_;
  1181. +#endif
  1182. // The root CALayer to display the current frame. This does not change
  1183. // over the lifetime of the object.
  1184. diff --git a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1185. index b99461d52e3a62b58330691e65f9956748cfbf02..09abf39af3e7115744778c7260a68f13a080b162 100644
  1186. --- a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1187. +++ b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1188. @@ -33,6 +33,7 @@
  1189. new_presentation_feedback_timestamps_(
  1190. new_presentation_feedback_timestamps),
  1191. buffer_presented_callback_(buffer_presented_callback) {
  1192. +#if !IS_MAS_BUILD()
  1193. if (allow_remote_layers_) {
  1194. root_ca_layer_ = [[CALayer alloc] init];
  1195. #if BUILDFLAG(IS_MAC)
  1196. @@ -61,6 +62,7 @@
  1197. #endif
  1198. ca_context_.layer = root_ca_layer_;
  1199. }
  1200. +#endif
  1201. }
  1202. CALayerTreeCoordinator::~CALayerTreeCoordinator() = default;
  1203. @@ -164,9 +166,13 @@
  1204. TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD,
  1205. "GLImpl", static_cast<int>(gl::GetGLImplementation()),
  1206. "width", pixel_size_.width());
  1207. +#if !IS_MAS_BUILD()
  1208. if (allow_remote_layers_) {
  1209. params.ca_context_id = [ca_context_ contextId];
  1210. } else {
  1211. +#else
  1212. + if (true) {
  1213. +#endif
  1214. IOSurfaceRef io_surface = frame->layer_tree->GetContentIOSurface();
  1215. if (io_surface) {
  1216. DCHECK(!allow_remote_layers_);
  1217. diff --git a/ui/accelerated_widget_mac/display_ca_layer_tree.mm b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1218. index dcf493d62990018040a3f84b6f875af737bd2214..6ffffe8b3946e0427aead8be19878c537c841294 100644
  1219. --- a/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1220. +++ b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1221. @@ -121,6 +121,7 @@ - (void)setContentsChanged;
  1222. }
  1223. void DisplayCALayerTree::GotCALayerFrame(uint32_t ca_context_id) {
  1224. +#if !IS_MAS_BUILD()
  1225. // Early-out if the remote layer has not changed.
  1226. if (remote_layer_.contextId == ca_context_id) {
  1227. return;
  1228. @@ -150,6 +151,9 @@ - (void)setContentsChanged;
  1229. [io_surface_layer_ removeFromSuperlayer];
  1230. io_surface_layer_ = nil;
  1231. }
  1232. +#else
  1233. + NOTREACHED() << "Remote layer is being used in MAS build";
  1234. +#endif
  1235. }
  1236. void DisplayCALayerTree::GotIOSurfaceFrame(
  1237. diff --git a/ui/accessibility/platform/BUILD.gn b/ui/accessibility/platform/BUILD.gn
  1238. index b7f86265ef2c79ce7a0c3eda2443a01a0242af89..96b8b4976ada0fcb2fd322e2ea42429a3c0757db 100644
  1239. --- a/ui/accessibility/platform/BUILD.gn
  1240. +++ b/ui/accessibility/platform/BUILD.gn
  1241. @@ -255,6 +255,7 @@ component("platform") {
  1242. weak_frameworks = [
  1243. "Accessibility.framework", # macOS 11
  1244. ]
  1245. + configs += ["//electron/build/config:mas_build"]
  1246. }
  1247. if (is_ios) {
  1248. diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.mm b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1249. index 84e156b7ff28abc2071dde155e56a2a92a53b142..bd73dac7fe3ed256cab805a0815d31d4f5e7dffc 100644
  1250. --- a/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1251. +++ b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1252. @@ -108,6 +108,7 @@
  1253. }
  1254. }
  1255. +#if !IS_MAS_BUILD()
  1256. // AXTextMarker
  1257. if (IsAXTextMarker(value)) {
  1258. return AXTextMarkerToBaseValue(value, indexer);
  1259. @@ -117,6 +118,7 @@
  1260. if (IsAXTextMarkerRange(value)) {
  1261. return AXTextMarkerRangeToBaseValue(value, indexer);
  1262. }
  1263. +#endif
  1264. // Accessible object
  1265. if (AXElementWrapper::IsValidElement(value)) {
  1266. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  1267. index 381ecc15e5cd3ef6275ce36335e95fc745788c32..08438eb0ed184c2afa1bf2501a5cccf77056cbed 100644
  1268. --- a/ui/base/BUILD.gn
  1269. +++ b/ui/base/BUILD.gn
  1270. @@ -363,6 +363,7 @@ component("base") {
  1271. "interaction/element_tracker_mac.mm",
  1272. "resource/resource_bundle_mac.mm",
  1273. ]
  1274. + configs += ["//electron/build/config:mas_build"]
  1275. }
  1276. if (is_apple) {
  1277. @@ -380,6 +381,13 @@ component("base") {
  1278. sources += [ "resource/resource_bundle_lacros.cc" ]
  1279. }
  1280. + if (is_mas_build) {
  1281. + sources -= [
  1282. + "cocoa/remote_accessibility_api.h",
  1283. + "cocoa/remote_accessibility_api.mm",
  1284. + ]
  1285. + }
  1286. +
  1287. if (is_ios) {
  1288. sources += [
  1289. "device_form_factor_ios.mm",
  1290. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  1291. index 3182458838aa96d34911280ab4c6c3aa4aa22d6d..17b57f54492421743a0d69106eefce2c9beb8e87 100644
  1292. --- a/ui/base/cocoa/remote_accessibility_api.h
  1293. +++ b/ui/base/cocoa/remote_accessibility_api.h
  1294. @@ -13,6 +13,8 @@
  1295. // NSAccessibilityRemoteUIElement is a private class in AppKit.
  1296. +#if !IS_MAS_BUILD()
  1297. +
  1298. @interface NSAccessibilityRemoteUIElement : NSObject
  1299. + (void)setRemoteUIApp:(BOOL)flag;
  1300. + (BOOL)isRemoteUIApp;
  1301. @@ -38,4 +40,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  1302. } // namespace ui
  1303. +#endif // MAS_BUILD
  1304. +
  1305. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  1306. diff --git a/ui/base/cocoa/remote_layer_api.h b/ui/base/cocoa/remote_layer_api.h
  1307. index 59dc2f82214cfd883b6ebef3b0fb25af6387a9cd..d585ba14b34021a93c878d0d9f9d9ef70eed32ca 100644
  1308. --- a/ui/base/cocoa/remote_layer_api.h
  1309. +++ b/ui/base/cocoa/remote_layer_api.h
  1310. @@ -17,6 +17,7 @@
  1311. #if BUILDFLAG(IS_MAC)
  1312. +#if !IS_MAS_BUILD()
  1313. // The CGSConnectionID is used to create the CAContext in the process that is
  1314. // going to share the CALayers that it is rendering to another process to
  1315. // display.
  1316. @@ -68,6 +69,8 @@ extern NSString* const kCAContextIgnoresHitTest;
  1317. #endif // __OBJC__
  1318. +#endif // MAS_BUILD
  1319. +
  1320. namespace ui {
  1321. // This function will check if all of the interfaces listed above are supported
  1322. diff --git a/ui/base/cocoa/remote_layer_api.mm b/ui/base/cocoa/remote_layer_api.mm
  1323. index fc25ba79d2b0e1acdb7ba54b89e7d6e16f94771b..962df2d65d61ec0836cf465d847eb666033846f2 100644
  1324. --- a/ui/base/cocoa/remote_layer_api.mm
  1325. +++ b/ui/base/cocoa/remote_layer_api.mm
  1326. @@ -10,6 +10,7 @@
  1327. namespace ui {
  1328. +#if !IS_MAS_BUILD()
  1329. namespace {
  1330. // Control use of cross-process CALayers to display content directly from the
  1331. // GPU process on Mac.
  1332. @@ -17,8 +18,10 @@
  1333. "RemoteCoreAnimationAPI",
  1334. base::FEATURE_ENABLED_BY_DEFAULT);
  1335. } // namespace
  1336. +#endif
  1337. bool RemoteLayerAPISupported() {
  1338. +#if !IS_MAS_BUILD()
  1339. if (!base::FeatureList::IsEnabled(kRemoteCoreAnimationAPI))
  1340. return false;
  1341. @@ -55,6 +58,9 @@ bool RemoteLayerAPISupported() {
  1342. // If everything is there, we should be able to use the API.
  1343. return true;
  1344. +#else
  1345. + return false;
  1346. +#endif // MAS_BUILD
  1347. }
  1348. } // namespace
  1349. diff --git a/ui/display/BUILD.gn b/ui/display/BUILD.gn
  1350. index 9fb3bee897513d262ac44dccfe6662cc145a8df7..5b7592d7f739b5e580429a69575e6df5ee7e4695 100644
  1351. --- a/ui/display/BUILD.gn
  1352. +++ b/ui/display/BUILD.gn
  1353. @@ -72,6 +72,10 @@ component("display") {
  1354. "mac/display_link_mac.mm",
  1355. "mac/screen_mac.mm",
  1356. ]
  1357. +
  1358. + configs += [
  1359. + "//electron/build/config:mas_build"
  1360. + ]
  1361. }
  1362. if (is_win) {
  1363. diff --git a/ui/display/mac/screen_mac.mm b/ui/display/mac/screen_mac.mm
  1364. index cd08cb3b7c95a8fd418524652bb345945291112a..13c6cc142262781450d1075fe85f86ada3f9f60f 100644
  1365. --- a/ui/display/mac/screen_mac.mm
  1366. +++ b/ui/display/mac/screen_mac.mm
  1367. @@ -171,7 +171,17 @@ DisplayMac BuildDisplayForScreen(NSScreen* screen) {
  1368. display.set_color_depth(Display::kDefaultBitsPerPixel);
  1369. display.set_depth_per_component(Display::kDefaultBitsPerComponent);
  1370. }
  1371. +#if IS_MAS_BUILD()
  1372. + // This is equivalent to the CGDisplayUsesForceToGray() API as at 2018-08-06,
  1373. + // but avoids usage of the private API.
  1374. + CFStringRef app = CFSTR("com.apple.CoreGraphics");
  1375. + CFStringRef key = CFSTR("DisplayUseForcedGray");
  1376. + Boolean key_valid = false;
  1377. + display.set_is_monochrome(
  1378. + CFPreferencesGetAppBooleanValue(key, app, &key_valid));
  1379. +#else
  1380. display.set_is_monochrome(CGDisplayUsesForceToGray());
  1381. +#endif
  1382. // Query the display's refresh rate.
  1383. {
  1384. diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
  1385. index 5255116a8e8f897607e5c5df2875dbaf275ec919..0a28b2832470f3c9d45f70499be29c2b29cb1b25 100644
  1386. --- a/ui/gfx/BUILD.gn
  1387. +++ b/ui/gfx/BUILD.gn
  1388. @@ -204,6 +204,7 @@ component("gfx") {
  1389. "scoped_ns_graphics_context_save_gstate_mac.h",
  1390. "scoped_ns_graphics_context_save_gstate_mac.mm",
  1391. ]
  1392. + configs += ["//electron/build/config:mas_build"]
  1393. }
  1394. if (is_win) {
  1395. sources += [
  1396. diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm
  1397. index 0ab5fbd2a81d8860c73f29c08896f6755b5ca5fa..9400c6c7698258ff2834c550fb8901b49ced35bd 100644
  1398. --- a/ui/gfx/platform_font_mac.mm
  1399. +++ b/ui/gfx/platform_font_mac.mm
  1400. @@ -28,9 +28,11 @@
  1401. using Weight = Font::Weight;
  1402. +#if !IS_MAS_BUILD()
  1403. extern "C" {
  1404. bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
  1405. }
  1406. +#endif
  1407. namespace {
  1408. @@ -245,7 +247,13 @@ CTFontRef SystemFontForConstructorOfType(PlatformFontMac::SystemFontType type) {
  1409. // TODO(avi, etienneb): Figure out this font stuff.
  1410. base::apple::ScopedCFTypeRef<CTFontDescriptorRef> descriptor(
  1411. CTFontCopyFontDescriptor(font));
  1412. +#if IS_MAS_BUILD()
  1413. + CFNumberRef priority = (CFNumberRef)CTFontDescriptorCopyAttribute(descriptor.get(), (CFStringRef)kCTFontPriorityAttribute);
  1414. + SInt64 v;
  1415. + if (CFNumberGetValue(priority, kCFNumberSInt64Type, &v) && v == kCTFontPrioritySystem) {
  1416. +#else
  1417. if (CTFontDescriptorIsSystemUIFont(descriptor.get())) {
  1418. +#endif
  1419. // Assume it's the standard system font. The fact that this much is known is
  1420. // enough.
  1421. return PlatformFontMac::SystemFontType::kGeneral;
  1422. diff --git a/ui/views/BUILD.gn b/ui/views/BUILD.gn
  1423. index cd6c9a924dce762ff935ef722c8873c974772225..b162795219e0fac3d9caa6bbfead126c033534cc 100644
  1424. --- a/ui/views/BUILD.gn
  1425. +++ b/ui/views/BUILD.gn
  1426. @@ -716,6 +716,7 @@ component("views") {
  1427. "IOSurface.framework",
  1428. "QuartzCore.framework",
  1429. ]
  1430. + configs += ["//electron/build/config:mas_build"]
  1431. }
  1432. if (is_win) {
  1433. @@ -1145,6 +1146,8 @@ source_set("test_support") {
  1434. "//testing/gtest",
  1435. ]
  1436. + configs += ["//electron/build/config:mas_build"]
  1437. +
  1438. if (is_win) {
  1439. sources += [
  1440. "test/desktop_window_tree_host_win_test_api.cc",
  1441. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1442. index 3911cb0691cb74c855c8edc9402cfd5a7fa7ddf3..8014af9cb95cdcb976c2f070b5a158c0947cc6ce 100644
  1443. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1444. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1445. @@ -31,7 +31,9 @@
  1446. #include "ui/views/window/dialog_observer.h"
  1447. @class NativeWidgetMacNSWindow;
  1448. +#if !IS_MAS_BUILD()
  1449. @class NSAccessibilityRemoteUIElement;
  1450. +#endif
  1451. @class NSView;
  1452. namespace remote_cocoa {
  1453. @@ -479,10 +481,12 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  1454. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  1455. remote_ns_window_remote_;
  1456. +#if !IS_MAS_BUILD()
  1457. // Remote accessibility objects corresponding to the NSWindow and its root
  1458. // NSView.
  1459. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  1460. NSAccessibilityRemoteUIElement* __strong remote_view_accessible_;
  1461. +#endif
  1462. // Used to force the NSApplication's focused accessibility element to be the
  1463. // views::Views accessibility tree when the NSView for this is focused.
  1464. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1465. index 5d03d63d5ac0f114269b03098364ee3ab2620daa..7200b48bd63e1c951d51781c92a7995ad80c26bb 100644
  1466. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1467. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1468. @@ -349,7 +349,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1469. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  1470. if (in_process_ns_window_bridge_)
  1471. return in_process_ns_window_bridge_->ns_view();
  1472. +#if !IS_MAS_BUILD()
  1473. return remote_view_accessible_;
  1474. +#else
  1475. + return nullptr;
  1476. +#endif
  1477. }
  1478. gfx::NativeViewAccessible
  1479. @@ -364,7 +368,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1480. return [in_process_ns_window_bridge_->ns_view() window];
  1481. }
  1482. +#if !IS_MAS_BUILD()
  1483. return remote_window_accessible_;
  1484. +#else
  1485. + return nullptr;
  1486. +#endif
  1487. }
  1488. remote_cocoa::mojom::NativeWidgetNSWindow*
  1489. @@ -1316,9 +1324,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1490. // for PWAs. However this breaks accessibility on in-process windows,
  1491. // so set it back to NO when a local window gains focus. See
  1492. // https://crbug.com/41485830.
  1493. +#if !IS_MAS_BUILD()
  1494. if (is_key && features::IsAccessibilityRemoteUIAppEnabled()) {
  1495. [NSAccessibilityRemoteUIElement setRemoteUIApp:!!application_host_];
  1496. }
  1497. +#endif
  1498. // Explicitly set the keyboard accessibility state on regaining key
  1499. // window status.
  1500. if (is_key && is_content_first_responder)
  1501. @@ -1481,17 +1491,20 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1502. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  1503. const std::vector<uint8_t>& window_token,
  1504. const std::vector<uint8_t>& view_token) {
  1505. +#if !IS_MAS_BUILD()
  1506. remote_window_accessible_ =
  1507. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  1508. remote_view_accessible_ =
  1509. ui::RemoteAccessibility::GetRemoteElementFromToken(view_token);
  1510. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_];
  1511. [remote_view_accessible_ setTopLevelUIElement:remote_window_accessible_];
  1512. +#endif
  1513. }
  1514. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  1515. base::ProcessId* pid,
  1516. std::vector<uint8_t>* token) {
  1517. +#if !IS_MAS_BUILD()
  1518. *pid = getpid();
  1519. id element_id = GetNativeViewAccessible();
  1520. @@ -1504,6 +1517,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1521. }
  1522. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  1523. +#endif
  1524. return true;
  1525. }
  1526. diff --git a/ui/views/controls/webview/BUILD.gn b/ui/views/controls/webview/BUILD.gn
  1527. index 111d6432586f47833dde50678b908c76ad88d37a..45601d06f85ba618fe38c96ae28c47d306784e53 100644
  1528. --- a/ui/views/controls/webview/BUILD.gn
  1529. +++ b/ui/views/controls/webview/BUILD.gn
  1530. @@ -19,6 +19,9 @@ component("webview") {
  1531. if (is_mac) {
  1532. sources += [ "unhandled_keyboard_event_handler_mac.mm" ]
  1533. + configs += [
  1534. + "//electron/build/config:mas_build",
  1535. + ]
  1536. }
  1537. if (is_win) {