mas_avoid_private_macos_api_usage.patch.patch 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677
  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 a989a351a87650d33342cc8eea9d719bcad31fb6..6c8cfaec9e3034d7f05d257211bfdd8172b0136b 100644
  36. --- a/base/BUILD.gn
  37. +++ b/base/BUILD.gn
  38. @@ -1053,6 +1053,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 2bad2ed2f5205b3a2599aa3a620812aa32d52f87..ab3d4c953556d4f94075671436565a6c442f30d5 100644
  47. --- a/base/enterprise_util_mac.mm
  48. +++ b/base/enterprise_util_mac.mm
  49. @@ -115,6 +115,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. @@ -218,5 +226,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 b267bc2272fa82334a70d897a900f1ea37b1a598..967e22699bf565368704972c021f9b425a570f08 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 a5815d7c1cab4795dbaf20bfd152810cb78ce0a9..5bb13f382e08f66ed3cb8cd67512b86767e7368a 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. "alert.h",
  164. "alert.mm",
  165. diff --git a/components/remote_cocoa/app_shim/application_bridge.mm b/components/remote_cocoa/app_shim/application_bridge.mm
  166. index 5a096477c123a782341115f964c4975301ccaf9a..ecfbb3b405425af346a6ba6788fc1d8ff89760cd 100644
  167. --- a/components/remote_cocoa/app_shim/application_bridge.mm
  168. +++ b/components/remote_cocoa/app_shim/application_bridge.mm
  169. @@ -51,6 +51,7 @@
  170. // NativeWidgetNSWindowHostHelper:
  171. id GetNativeViewAccessible() override {
  172. +#if !IS_MAS_BUILD()
  173. if (!remote_accessibility_element_) {
  174. int64_t browser_pid = 0;
  175. std::vector<uint8_t> element_token;
  176. @@ -61,6 +62,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. @@ -99,7 +103,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 25672be4a7dac9a8cd53498184f537292e14d5c2..ef0844ae2845990832fc9777eade94550fb8ffaa 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 4c60785c1998677abc8845c087f672f51dc2ce8f..4c06d59cefb630a2cf7f79f1b41bd8a53ae84643 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. @@ -104,7 +104,9 @@ void OrderChildWindow(NSWindow* child_window,
  273. } // namespace
  274. @interface NSWindow (Private)
  275. +#if !IS_MAS_BUILD()
  276. + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle;
  277. +#endif
  278. - (BOOL)hasKeyAppearance;
  279. - (long long)_resizeDirectionForMouseLocation:(CGPoint)location;
  280. - (BOOL)_isConsideredOpenForPersistentState;
  281. @@ -143,6 +145,8 @@ - (void)cr_mouseDownOnFrameView:(NSEvent*)event {
  282. }
  283. @end
  284. +#if !IS_MAS_BUILD()
  285. +
  286. @implementation NativeWidgetMacNSWindowTitledFrame
  287. - (void)mouseDown:(NSEvent*)event {
  288. if (self.window.isMovable)
  289. @@ -169,6 +173,8 @@ - (BOOL)usesCustomDrawing {
  290. }
  291. @end
  292. +#endif // MAS_BUILD
  293. +
  294. @implementation NativeWidgetMacNSWindow {
  295. @private
  296. CommandDispatcher* __strong _commandDispatcher;
  297. @@ -357,6 +363,8 @@ - (NSAccessibilityRole)accessibilityRole {
  298. // NSWindow overrides.
  299. +#if !IS_MAS_BUILD()
  300. +
  301. + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
  302. if (windowStyle & NSWindowStyleMaskTitled) {
  303. if (Class customFrame = [NativeWidgetMacNSWindowTitledFrame class])
  304. @@ -368,6 +376,8 @@ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
  305. return [super frameViewClassForStyleMask:windowStyle];
  306. }
  307. +#endif
  308. +
  309. - (BOOL)_isTitleHidden {
  310. bool shouldShowWindowTitle = YES;
  311. if (_bridge)
  312. 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
  313. index fbc23284b997d80c31f6fb62d8de7fc3076b3195..2d264b95ef73d243fedfe12a24fb4c665805e630 100644
  314. --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  315. +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  316. @@ -601,10 +601,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
  317. // this should be treated as an error and caught early.
  318. CHECK(bridged_view_);
  319. +#if !IS_MAS_BUILD()
  320. // Send the accessibility tokens for the NSView now that it exists.
  321. host_->SetRemoteAccessibilityTokens(
  322. ui::RemoteAccessibility::GetTokenForLocalElement(window_),
  323. ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
  324. +#endif
  325. // Beware: This view was briefly removed (in favor of a bare CALayer) in
  326. // https://crrev.com/c/1236675. The ordering of unassociated layers relative
  327. diff --git a/components/viz/service/BUILD.gn b/components/viz/service/BUILD.gn
  328. index 5756139efd53eb9ec6e74007fc10d9f7dfe51d44..8faf652dee5720e066b6ab5f2d4997ee31bfbf1a 100644
  329. --- a/components/viz/service/BUILD.gn
  330. +++ b/components/viz/service/BUILD.gn
  331. @@ -356,6 +356,7 @@ viz_component("service") {
  332. "frame_sinks/external_begin_frame_source_mac.h",
  333. ]
  334. }
  335. + configs = ["//electron/build/config:mas_build"]
  336. }
  337. if (is_android || use_ozone) {
  338. @@ -622,6 +623,7 @@ viz_source_set("unit_tests") {
  339. "display_embedder/software_output_device_mac_unittest.mm",
  340. ]
  341. frameworks = [ "IOSurface.framework" ]
  342. + configs += ["//electron/build/config:mas_build"]
  343. }
  344. if (is_win) {
  345. 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
  346. index b15bca430f99aaf02733061d986b3ea78204e748..6ad3b61e20361a68f8d799b5826b0ff303d98b69 100644
  347. --- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  348. +++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  349. @@ -90,8 +90,10 @@ id GetFocusedBrowserAccessibilityElement() override {
  350. return [bridgedContentView accessibilityFocusedUIElement];
  351. }
  352. void SetAccessibilityWindow(NSWindow* window) override {
  353. +#if !IS_MAS_BUILD()
  354. host_->SetRemoteAccessibilityWindowToken(
  355. ui::RemoteAccessibility::GetTokenForLocalElement(window));
  356. +#endif
  357. }
  358. void ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& key_event,
  359. 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
  360. index 5f6e5b078672c0336cee72300a7a37d6284db226..76650bac392c650946636cedc2f5d9c35ca113fa 100644
  361. --- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  362. +++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  363. @@ -2014,15 +2014,21 @@ - (NSAccessibilityRole)accessibilityRole {
  364. // Since this implementation doesn't have to wait any IPC calls, this doesn't
  365. // make any key-typing jank. --hbono 7/23/09
  366. //
  367. +#if !IS_MAS_BUILD()
  368. extern "C" {
  369. extern NSString* NSTextInputReplacementRangeAttributeName;
  370. }
  371. +#endif
  372. - (NSArray*)validAttributesForMarkedText {
  373. // This code is just copied from WebKit except renaming variables.
  374. static NSArray* const kAttributes = @[
  375. NSUnderlineStyleAttributeName, NSUnderlineColorAttributeName,
  376. +#if !IS_MAS_BUILD()
  377. NSMarkedClauseSegmentAttributeName, NSTextInputReplacementRangeAttributeName
  378. +#else
  379. + NSMarkedClauseSegmentAttributeName
  380. +#endif
  381. ];
  382. return kAttributes;
  383. }
  384. diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
  385. index 64d7c47759e9c7899aaf1c513d0b1b8ee6d97f98..6f885f7ea451310cca7c7686548cd3467984874f 100644
  386. --- a/content/browser/BUILD.gn
  387. +++ b/content/browser/BUILD.gn
  388. @@ -54,6 +54,7 @@ source_set("browser") {
  389. "//content:content_implementation",
  390. "//v8:external_startup_data",
  391. ]
  392. + configs += ["//electron/build/config:mas_build"]
  393. defines = []
  394. libs = []
  395. frameworks = []
  396. diff --git a/content/browser/accessibility/browser_accessibility_manager_mac.mm b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  397. index ce3623bd6353674fee92ba1c36eeda8da8906882..62746522bf5f398b12a8cee35f49bb4fc3b51b53 100644
  398. --- a/content/browser/accessibility/browser_accessibility_manager_mac.mm
  399. +++ b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  400. @@ -21,7 +21,9 @@
  401. #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
  402. #include "ui/accessibility/ax_role_properties.h"
  403. #include "ui/accessibility/platform/ax_private_webkit_constants_mac.h"
  404. +#if !IS_MAS_BUILD()
  405. #include "ui/base/cocoa/remote_accessibility_api.h"
  406. +#endif
  407. namespace {
  408. @@ -225,6 +227,7 @@ void PostAnnouncementNotification(NSString* announcement,
  409. return;
  410. }
  411. +#if !IS_MAS_BUILD()
  412. BrowserAccessibilityManager* root_manager = GetManagerForRootFrame();
  413. if (root_manager) {
  414. BrowserAccessibilityManagerMac* root_manager_mac =
  415. @@ -247,6 +250,7 @@ void PostAnnouncementNotification(NSString* announcement,
  416. return;
  417. }
  418. }
  419. +#endif
  420. // Use native VoiceOver support for live regions.
  421. BrowserAccessibilityCocoa* retained_node = native_node;
  422. @@ -633,6 +637,7 @@ void PostAnnouncementNotification(NSString* announcement,
  423. return window == [NSApp accessibilityFocusedWindow];
  424. }
  425. +#if !IS_MAS_BUILD()
  426. // TODO(accessibility): We need a solution to the problem described below.
  427. // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
  428. // 1. NSApp is the browser which spawned the PWA, and what it considers the
  429. @@ -661,6 +666,7 @@ void PostAnnouncementNotification(NSString* announcement,
  430. if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]]) {
  431. return true;
  432. }
  433. +#endif
  434. return false;
  435. }
  436. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  437. index 032a1da13d5f75e3b31aa868c5ff138f88c2eed2..2a190ba1e4fed6fa11ddfbf167aac2196dd16d86 100644
  438. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  439. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  440. @@ -49,7 +49,9 @@ class ScopedPasswordInputEnabler;
  441. @protocol RenderWidgetHostViewMacDelegate;
  442. +#if !IS_MAS_BUILD()
  443. @class NSAccessibilityRemoteUIElement;
  444. +#endif
  445. @class RenderWidgetHostViewCocoa;
  446. @class CursorAccessibilityScaleFactorObserver;
  447. @@ -678,9 +680,11 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  448. // EnsureSurfaceSynchronizedForWebTest().
  449. uint32_t latest_capture_sequence_number_ = 0u;
  450. +#if !IS_MAS_BUILD()
  451. // Remote accessibility objects corresponding to the NSWindow that this is
  452. // displayed to the user in.
  453. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  454. +#endif
  455. // Used to force the NSApplication's focused accessibility element to be the
  456. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  457. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  458. index 947af40d33f81c47ad7c3fa0ebcf3a45b697b530..e0fa7a8edcd3a71784d35cb3f18d0b2b8d77c816 100644
  459. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  460. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  461. @@ -272,8 +272,10 @@
  462. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  463. remote_cocoa::mojom::Application* remote_cocoa_application,
  464. uint64_t parent_ns_view_id) {
  465. +#if !IS_MAS_BUILD()
  466. // Destroy the previous remote accessibility element.
  467. remote_window_accessible_ = nil;
  468. +#endif
  469. // Reset `ns_view_` before resetting `remote_ns_view_` to avoid dangling
  470. // pointers. `ns_view_` gets reinitialized later in this method.
  471. @@ -1649,8 +1651,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  472. gfx::NativeViewAccessible
  473. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  474. +#if !IS_MAS_BUILD()
  475. if (remote_window_accessible_)
  476. return remote_window_accessible_;
  477. +#endif
  478. return [GetInProcessNSView() window];
  479. }
  480. @@ -1695,9 +1699,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  481. }
  482. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  483. +#if !IS_MAS_BUILD()
  484. // When running in-process, just use the NSView's NSWindow as its own
  485. // accessibility element.
  486. remote_window_accessible_ = nil;
  487. +#endif
  488. }
  489. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  490. @@ -2204,12 +2210,14 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  491. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  492. const std::vector<uint8_t>& window_token) {
  493. +#if !IS_MAS_BUILD()
  494. if (window_token.empty()) {
  495. remote_window_accessible_ = nil;
  496. } else {
  497. remote_window_accessible_ =
  498. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  499. }
  500. +#endif
  501. }
  502. ///////////////////////////////////////////////////////////////////////////////
  503. diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn
  504. index 250d68fe80384f4409e91dd94a37ebc6ad34d383..4f5f1021dcdf2ca45531b8f56fed44b4c1097e8f 100644
  505. --- a/content/common/BUILD.gn
  506. +++ b/content/common/BUILD.gn
  507. @@ -240,6 +240,7 @@ source_set("common") {
  508. "//content:content_implementation",
  509. "//build/config:precompiled_headers",
  510. ]
  511. + configs += ["//electron/build/config:mas_build"]
  512. public_deps = [
  513. ":mojo_bindings",
  514. diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn
  515. index 6fae0b5280d5e5220f4e8695cb898a44de9dd22e..5dc89a6b06799e05051af025985964be4e2c9260 100644
  516. --- a/content/renderer/BUILD.gn
  517. +++ b/content/renderer/BUILD.gn
  518. @@ -227,6 +227,7 @@ target(link_target_type, "renderer") {
  519. }
  520. configs += [ "//content:content_implementation" ]
  521. + configs += ["//electron/build/config:mas_build"]
  522. defines = []
  523. public_deps = [
  524. diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
  525. index d4db3b179725cb96bcbd0f73db7d52ef8b7522db..6afbf1defb0591d9fe59a81e6c74746d3e15f081 100644
  526. --- a/content/renderer/renderer_main_platform_delegate_mac.mm
  527. +++ b/content/renderer/renderer_main_platform_delegate_mac.mm
  528. @@ -10,9 +10,11 @@
  529. #include "sandbox/mac/seatbelt.h"
  530. #include "sandbox/mac/system_services.h"
  531. +#if !IS_MAS_BUILD()
  532. extern "C" {
  533. CGError CGSSetDenyWindowServerConnections(bool);
  534. }
  535. +#endif
  536. namespace content {
  537. @@ -22,6 +24,7 @@
  538. // verifies there are no existing open connections), and then indicates that
  539. // Chrome should continue execution without access to launchservicesd.
  540. void DisableSystemServices() {
  541. +#if !IS_MAS_BUILD()
  542. // Tell the WindowServer that we don't want to make any future connections.
  543. // This will return Success as long as there are no open connections, which
  544. // is what we want.
  545. @@ -30,6 +33,7 @@ void DisableSystemServices() {
  546. sandbox::DisableLaunchServices();
  547. sandbox::DisableCoreServicesCheckFix();
  548. +#endif
  549. }
  550. } // namespace
  551. diff --git a/content/renderer/theme_helper_mac.mm b/content/renderer/theme_helper_mac.mm
  552. index a119b4439bfb9218c7aaf09dca8e78527da7f20d..faa813b003940280c6eeb87e70173019bdd5280c 100644
  553. --- a/content/renderer/theme_helper_mac.mm
  554. +++ b/content/renderer/theme_helper_mac.mm
  555. @@ -8,10 +8,11 @@
  556. #include "base/strings/sys_string_conversions.h"
  557. +#if !IS_MAS_BUILD()
  558. extern "C" {
  559. bool CGFontRenderingGetFontSmoothingDisabled(void);
  560. }
  561. -
  562. +#endif
  563. namespace content {
  564. void SystemColorsDidChange(int aqua_color_variant) {
  565. @@ -24,8 +25,18 @@ void SystemColorsDidChange(int aqua_color_variant) {
  566. }
  567. bool IsSubpixelAntialiasingAvailable() {
  568. +#if !IS_MAS_BUILD()
  569. // See https://trac.webkit.org/changeset/239306/webkit for more info.
  570. return !CGFontRenderingGetFontSmoothingDisabled();
  571. +#else
  572. + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  573. + NSString *default_key = @"CGFontRenderingGetFontSmoothingDisabled";
  574. + // Check that key exists since boolForKey defaults to NO when the
  575. + // key is missing and this key in fact defaults to YES;
  576. + if ([defaults objectForKey:default_key] == nil)
  577. + return false;
  578. + return ![defaults boolForKey:default_key];
  579. +#endif
  580. }
  581. } // namespace content
  582. diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn
  583. index 8d0a789cccacc4d6a54d9bc499c606f076a3d3b6..0c9dc99d03928defceaae741d588d292301b6ba8 100644
  584. --- a/content/test/BUILD.gn
  585. +++ b/content/test/BUILD.gn
  586. @@ -479,6 +479,7 @@ static_library("test_support") {
  587. configs += [
  588. "//build/config:precompiled_headers",
  589. "//v8:external_startup_data",
  590. + "//electron/build/config:mas_build",
  591. ]
  592. public_deps = [
  593. @@ -1075,6 +1076,7 @@ static_library("browsertest_support") {
  594. }
  595. configs += [ "//v8:external_startup_data" ]
  596. + configs += ["//electron/build/config:mas_build"]
  597. }
  598. mojom("content_test_mojo_bindings") {
  599. @@ -1690,6 +1692,7 @@ test("content_browsertests") {
  600. defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
  601. configs += [ "//build/config:precompiled_headers" ]
  602. + configs += ["//electron/build/config:mas_build"]
  603. public_deps = [
  604. ":test_interfaces",
  605. @@ -2932,6 +2935,7 @@ test("content_unittests") {
  606. }
  607. configs += [ "//build/config:precompiled_headers" ]
  608. + configs += ["//electron/build/config:mas_build"]
  609. public_deps = [ "//content:content_resources" ]
  610. diff --git a/content/web_test/BUILD.gn b/content/web_test/BUILD.gn
  611. index 24facc48c2b6b30db3a7cb36e4222019b471e84b..d1d3e72407682b01e6c2173cd34445dbc44cb86d 100644
  612. --- a/content/web_test/BUILD.gn
  613. +++ b/content/web_test/BUILD.gn
  614. @@ -149,6 +149,8 @@ static_library("web_test_browser") {
  615. "browser/web_test_tts_platform.h",
  616. ]
  617. + configs += ["//electron/build/config:mas_build"]
  618. +
  619. if (is_mac) {
  620. sources += [ "browser/web_test_shell_platform_delegate_mac.mm" ]
  621. } else if (toolkit_views && !is_castos) {
  622. diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn
  623. index e09b425de7f7c799f675d385d6a8189baaeb13dd..3ddb0afe42879933c7a15c1bb82309736e78a15a 100644
  624. --- a/device/bluetooth/BUILD.gn
  625. +++ b/device/bluetooth/BUILD.gn
  626. @@ -243,6 +243,7 @@ component("bluetooth") {
  627. "IOKit.framework",
  628. "Foundation.framework",
  629. ]
  630. + configs += ["//electron/build/config:mas_build"]
  631. }
  632. if (is_mac) {
  633. diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
  634. index 3033b23a07041d375d5733bad1901f9a61bdf3b6..9dd6cb1aa49d03c167d1a92100d4ba5f08f93abe 100644
  635. --- a/device/bluetooth/bluetooth_adapter_mac.mm
  636. +++ b/device/bluetooth/bluetooth_adapter_mac.mm
  637. @@ -37,6 +37,7 @@
  638. #include "device/bluetooth/bluetooth_socket_mac.h"
  639. #include "device/bluetooth/public/cpp/bluetooth_address.h"
  640. +#if !IS_MAS_BUILD()
  641. extern "C" {
  642. // Undocumented IOBluetooth Preference API [1]. Used by `blueutil` [2] and
  643. // `Karabiner` [3] to programmatically control the Bluetooth state. Calling the
  644. @@ -50,6 +51,7 @@
  645. // [4] https://support.apple.com/kb/PH25091
  646. void IOBluetoothPreferenceSetControllerPowerState(int state);
  647. }
  648. +#endif
  649. namespace {
  650. @@ -93,8 +95,10 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  651. : controller_state_function_(
  652. base::BindRepeating(&BluetoothAdapterMac::GetHostControllerState,
  653. base::Unretained(this))),
  654. +#if !IS_MAS_BUILD()
  655. power_state_function_(
  656. base::BindRepeating(IOBluetoothPreferenceSetControllerPowerState)),
  657. +#endif
  658. device_paired_status_callback_(
  659. base::BindRepeating(&IsDeviceSystemPaired)) {
  660. }
  661. @@ -242,8 +246,12 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  662. }
  663. bool BluetoothAdapterMac::SetPoweredImpl(bool powered) {
  664. +#if !IS_MAS_BUILD()
  665. power_state_function_.Run(base::strict_cast<int>(powered));
  666. return true;
  667. +#else
  668. + return false;
  669. +#endif
  670. }
  671. base::WeakPtr<BluetoothLowEnergyAdapterApple>
  672. diff --git a/gpu/ipc/service/BUILD.gn b/gpu/ipc/service/BUILD.gn
  673. index e321b406a8375986b41d64342919bb0e8c5e58eb..8081d53adab80a6fccfdb4cd6f608c3bf7112c47 100644
  674. --- a/gpu/ipc/service/BUILD.gn
  675. +++ b/gpu/ipc/service/BUILD.gn
  676. @@ -133,6 +133,7 @@ component("service") {
  677. "QuartzCore.framework",
  678. ]
  679. defines += [ "GL_SILENCE_DEPRECATION" ]
  680. + configs += ["//electron/build/config:mas_build"]
  681. }
  682. if (is_ios) {
  683. sources += [ "image_transport_surface_ios.mm" ]
  684. diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.h b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  685. index b994079339dc0aebd86dac807645f81c2974fb96..b05e35c8eabccfd3147030d03453d78e76cdc5d2 100644
  686. --- a/gpu/ipc/service/image_transport_surface_overlay_mac.h
  687. +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  688. @@ -23,7 +23,9 @@
  689. #include "ui/display/types/display_constants.h"
  690. #endif
  691. +#if !IS_MAS_BUILD()
  692. @class CAContext;
  693. +#endif
  694. @class CALayer;
  695. namespace ui {
  696. @@ -76,8 +78,10 @@ class ImageTransportSurfaceOverlayMacEGL : public gl::Presenter {
  697. const gfx::PresentationFeedback& feedback);
  698. void PopulateCALayerParameters();
  699. +#if !IS_MAS_BUILD()
  700. const bool use_remote_layer_api_;
  701. CAContext* __strong ca_context_;
  702. +#endif
  703. std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator_;
  704. gfx::Size pixel_size_;
  705. diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.mm b/gpu/ipc/service/image_transport_surface_overlay_mac.mm
  706. index 3af7bb0fddf848f3c76d14c24730c6aba07fd83e..b23f152143d4958b7492cae47b8a3b01992e235f 100644
  707. --- a/gpu/ipc/service/image_transport_surface_overlay_mac.mm
  708. +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.mm
  709. @@ -75,12 +75,16 @@
  710. } // namespace
  711. ImageTransportSurfaceOverlayMacEGL::ImageTransportSurfaceOverlayMacEGL()
  712. - : use_remote_layer_api_(ui::RemoteLayerAPISupported()),
  713. + :
  714. +#if !IS_MAS_BUILD()
  715. + use_remote_layer_api_(ui::RemoteLayerAPISupported()),
  716. +#endif
  717. scale_factor_(1),
  718. weak_ptr_factory_(this) {
  719. static bool av_disabled_at_command_line =
  720. !base::FeatureList::IsEnabled(kAVFoundationOverlays);
  721. +#if !IS_MAS_BUILD()
  722. ca_layer_tree_coordinator_ = std::make_unique<ui::CALayerTreeCoordinator>(
  723. use_remote_layer_api_, !av_disabled_at_command_line);
  724. @@ -101,6 +105,10 @@
  725. #endif
  726. ca_context_.layer = ca_layer_tree_coordinator_->GetCALayerForDisplay();
  727. }
  728. +#else
  729. + ca_layer_tree_coordinator_ = std::make_unique<ui::CALayerTreeCoordinator>(
  730. + /*allow_remote_layers=*/false, !av_disabled_at_command_line);
  731. +#endif
  732. }
  733. ImageTransportSurfaceOverlayMacEGL::~ImageTransportSurfaceOverlayMacEGL() {
  734. @@ -233,9 +241,13 @@
  735. TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD,
  736. "GLImpl", static_cast<int>(gl::GetGLImplementation()),
  737. "width", pixel_size_.width());
  738. +#if !IS_MAS_BUILD()
  739. if (use_remote_layer_api_) {
  740. params.ca_context_id = [ca_context_ contextId];
  741. } else {
  742. +#else
  743. + if (true) {
  744. +#endif
  745. IOSurfaceRef io_surface =
  746. ca_layer_tree_coordinator_->GetIOSurfaceForDisplay();
  747. if (io_surface) {
  748. diff --git a/media/audio/BUILD.gn b/media/audio/BUILD.gn
  749. index 90e093cd2d499ba0f37f3246bab288c758b51e19..6027134a4de53e6fe39fdbfdb67885e0b5f56e40 100644
  750. --- a/media/audio/BUILD.gn
  751. +++ b/media/audio/BUILD.gn
  752. @@ -199,6 +199,7 @@ source_set("audio") {
  753. "CoreMedia.framework",
  754. ]
  755. weak_frameworks = [ "ScreenCaptureKit.framework" ] # macOS 13.0
  756. + configs += ["//electron/build/config:mas_build"]
  757. }
  758. if (is_ios) {
  759. diff --git a/media/audio/apple/audio_low_latency_input.cc b/media/audio/apple/audio_low_latency_input.cc
  760. index 8cd474c33e514fd0aa90daf68a56ed7fc902d713..9fff9cc7b00b257c3bebb02c75a3c2e809ffdf0a 100644
  761. --- a/media/audio/apple/audio_low_latency_input.cc
  762. +++ b/media/audio/apple/audio_low_latency_input.cc
  763. @@ -33,19 +33,23 @@
  764. namespace {
  765. extern "C" {
  766. +#if !IS_MAS_BUILD()
  767. // See:
  768. // https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/PAL/pal/spi/cf/CoreAudioSPI.h?rev=228264
  769. OSStatus AudioDeviceDuck(AudioDeviceID inDevice,
  770. Float32 inDuckedLevel,
  771. const AudioTimeStamp* __nullable inStartTime,
  772. Float32 inRampDuration) __attribute__((weak_import));
  773. +#endif
  774. }
  775. void UndoDucking(AudioDeviceID output_device_id) {
  776. +#if !IS_MAS_BUILD()
  777. if (AudioDeviceDuck != nullptr) {
  778. // Ramp the volume back up over half a second.
  779. AudioDeviceDuck(output_device_id, 1.0, nullptr, 0.5);
  780. }
  781. +#endif
  782. }
  783. } // namespace
  784. #endif
  785. diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
  786. index ac44f991c6cbe464d8867d8b3c77e1a5082793a7..7933a70a4b88b3cd00724aa025e82aecd867a5f3 100644
  787. --- a/media/audio/mac/audio_manager_mac.cc
  788. +++ b/media/audio/mac/audio_manager_mac.cc
  789. @@ -969,7 +969,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
  790. void AudioManagerMac::InitializeOnAudioThread() {
  791. DCHECK(GetTaskRunner()->BelongsToCurrentThread());
  792. - InitializeCoreAudioDispatchOverride();
  793. + // InitializeCoreAudioDispatchOverride();
  794. power_observer_ = std::make_unique<AudioPowerObserver>();
  795. }
  796. diff --git a/net/dns/BUILD.gn b/net/dns/BUILD.gn
  797. index 0c5cb82b1248997ef3b97f17bef52f880fed26fd..8adecabe9aee119c7474834c038c79b271ad888e 100644
  798. --- a/net/dns/BUILD.gn
  799. +++ b/net/dns/BUILD.gn
  800. @@ -183,6 +183,8 @@ source_set("dns") {
  801. ":host_resolver_manager",
  802. ":mdns_client",
  803. ]
  804. +
  805. + configs += ["//electron/build/config:mas_build"]
  806. }
  807. # The standard API of net/dns.
  808. diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
  809. index 04c2079aac882cb2913583d4692302fdf564a74d..2a03be8bb4b089473e61601323646d257da5e39e 100644
  810. --- a/net/dns/dns_config_service_posix.cc
  811. +++ b/net/dns/dns_config_service_posix.cc
  812. @@ -130,8 +130,8 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  813. bool Watch() override {
  814. CheckOnCorrectSequence();
  815. -
  816. bool success = true;
  817. +#if !IS_MAS_BUILD()
  818. if (!config_watcher_.Watch(base::BindRepeating(&Watcher::OnConfigChanged,
  819. base::Unretained(this)))) {
  820. LOG(ERROR) << "DNS config watch failed to start.";
  821. @@ -148,6 +148,7 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  822. success = false;
  823. }
  824. #endif // !BUILDFLAG(IS_IOS)
  825. +#endif
  826. return success;
  827. }
  828. diff --git a/sandbox/mac/BUILD.gn b/sandbox/mac/BUILD.gn
  829. index 299a028f23314f479d2da8f914a5bdf34698d854..672dcb04dd3cf4e3cc71403f727a1dde91ad4402 100644
  830. --- a/sandbox/mac/BUILD.gn
  831. +++ b/sandbox/mac/BUILD.gn
  832. @@ -39,6 +39,7 @@ component("seatbelt") {
  833. ]
  834. public_deps = [ "//third_party/protobuf:protobuf_lite" ]
  835. defines = [ "SEATBELT_IMPLEMENTATION" ]
  836. + configs += ["//electron/build/config:mas_build"]
  837. }
  838. component("seatbelt_extension") {
  839. @@ -52,6 +53,7 @@ component("seatbelt_extension") {
  840. libs = [ "sandbox" ]
  841. public_deps = [ "//base" ]
  842. defines = [ "SEATBELT_IMPLEMENTATION" ]
  843. + configs += ["//electron/build/config:mas_build"]
  844. }
  845. component("system_services") {
  846. @@ -66,6 +68,7 @@ component("system_services") {
  847. deps = [ ":seatbelt_export" ]
  848. public_deps = [ "//base" ]
  849. defines = [ "SEATBELT_IMPLEMENTATION" ]
  850. + configs += ["//electron/build/config:mas_build"]
  851. }
  852. source_set("sandbox_unittests") {
  853. diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
  854. index f35d9ef2a2df3db8ecbf1d7b909c7b1cf33f3cd9..a710b8b4f851666fd65bb37f69ec2fa70259697b 100644
  855. --- a/sandbox/mac/sandbox_compiler.cc
  856. +++ b/sandbox/mac/sandbox_compiler.cc
  857. @@ -47,6 +47,7 @@ bool SandboxCompiler::SetParameter(const std::string& key,
  858. }
  859. bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  860. +#if !IS_MAS_BUILD()
  861. if (mode_ == Target::kSource) {
  862. std::vector<const char*> params;
  863. @@ -67,6 +68,9 @@ bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  864. }
  865. }
  866. return false;
  867. +#else
  868. + return true;
  869. +#endif
  870. }
  871. bool SandboxCompiler::CompilePolicyToProto(mac::SandboxPolicy& policy,
  872. diff --git a/sandbox/mac/sandbox_logging.cc b/sandbox/mac/sandbox_logging.cc
  873. index 095c639b9893e885d8937e29ed7d47a7c28bc6b6..cfa5e307de8326fbc335996feaf9595d1572cd3d 100644
  874. --- a/sandbox/mac/sandbox_logging.cc
  875. +++ b/sandbox/mac/sandbox_logging.cc
  876. @@ -33,9 +33,11 @@
  877. }
  878. #endif
  879. +#if !IS_MAS_BUILD()
  880. extern "C" {
  881. void abort_report_np(const char*, ...);
  882. }
  883. +#endif
  884. namespace sandbox::logging {
  885. @@ -76,9 +78,11 @@ void SendOsLog(Level level, const char* message) {
  886. sandbox::crash_message::SetCrashMessage(message);
  887. }
  888. +#if !IS_MAS_BUILD()
  889. if (level == Level::FATAL) {
  890. abort_report_np(message);
  891. }
  892. +#endif
  893. }
  894. // |error| is strerror(errno) when a P* logging function is called. Pass
  895. diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
  896. index 15c835e118456394c0a00ac98c11241c14ca75bd..83759e5fbc252fa57ca2fa122873dfac3d61d46d 100644
  897. --- a/sandbox/mac/seatbelt.cc
  898. +++ b/sandbox/mac/seatbelt.cc
  899. @@ -9,7 +9,7 @@
  900. extern "C" {
  901. #include <sandbox.h>
  902. -
  903. +#if !IS_MAS_BUILD()
  904. int sandbox_init_with_parameters(const char* profile,
  905. uint64_t flags,
  906. const char* const parameters[],
  907. @@ -40,13 +40,13 @@ sandbox_profile_t* sandbox_compile_string(const char* data,
  908. char** error);
  909. int sandbox_apply(sandbox_profile_t*);
  910. void sandbox_free_profile(sandbox_profile_t*);
  911. -
  912. +#endif
  913. } // extern "C"
  914. namespace sandbox {
  915. namespace {
  916. -
  917. +#if !IS_MAS_BUILD()
  918. bool HandleSandboxResult(int rv, char* errorbuf, std::string* error) {
  919. if (rv == 0) {
  920. if (error)
  921. @@ -74,36 +74,48 @@ bool HandleSandboxErrno(int rv, const char* message, std::string* error) {
  922. }
  923. return false;
  924. }
  925. -
  926. +#endif
  927. } // namespace
  928. // static
  929. Seatbelt::Parameters Seatbelt::Parameters::Create() {
  930. Parameters params;
  931. +#if !IS_MAS_BUILD()
  932. params.params_ = ::sandbox_create_params();
  933. +#endif
  934. return params;
  935. }
  936. Seatbelt::Parameters::Parameters() = default;
  937. Seatbelt::Parameters::Parameters(Seatbelt::Parameters&& other) {
  938. +#if !IS_MAS_BUILD()
  939. params_ = std::exchange(other.params_, nullptr);
  940. +#endif
  941. }
  942. Seatbelt::Parameters& Seatbelt::Parameters::operator=(
  943. Seatbelt::Parameters&& other) {
  944. +#if !IS_MAS_BUILD()
  945. params_ = std::exchange(other.params_, nullptr);
  946. +#endif
  947. return *this;
  948. }
  949. bool Seatbelt::Parameters::Set(const char* key, const char* value) {
  950. +#if !IS_MAS_BUILD()
  951. return ::sandbox_set_param(params_, key, value) == 0;
  952. +#else
  953. + return true;
  954. +#endif
  955. }
  956. Seatbelt::Parameters::~Parameters() {
  957. +#if !IS_MAS_BUILD()
  958. if (params_) {
  959. ::sandbox_free_params(params_);
  960. }
  961. +#endif
  962. }
  963. // Initialize the static member variables.
  964. @@ -114,6 +126,7 @@ const char* Seatbelt::kProfilePureComputation = kSBXProfilePureComputation;
  965. // static
  966. bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  967. +#if !IS_MAS_BUILD()
  968. // OS X deprecated these functions, but did not provide a suitable replacement,
  969. // so ignore the deprecation warning.
  970. #pragma clang diagnostic push
  971. @@ -122,6 +135,9 @@ bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  972. int rv = ::sandbox_init(profile, flags, &errorbuf);
  973. return HandleSandboxResult(rv, errorbuf, error);
  974. #pragma clang diagnostic pop
  975. +#else
  976. + return true;
  977. +#endif
  978. }
  979. // static
  980. @@ -129,10 +145,14 @@ bool Seatbelt::InitWithParams(const char* profile,
  981. uint64_t flags,
  982. const char* const parameters[],
  983. std::string* error) {
  984. +#if !IS_MAS_BUILD()
  985. char* errorbuf = nullptr;
  986. int rv =
  987. ::sandbox_init_with_parameters(profile, flags, parameters, &errorbuf);
  988. return HandleSandboxResult(rv, errorbuf, error);
  989. +#else
  990. + return true;
  991. +#endif
  992. }
  993. // static
  994. @@ -140,6 +160,7 @@ bool Seatbelt::Compile(const char* profile,
  995. const Seatbelt::Parameters& params,
  996. std::string& compiled_profile,
  997. std::string* error) {
  998. +#if !IS_MAS_BUILD()
  999. char* errorbuf = nullptr;
  1000. sandbox_profile_t* sandbox_profile =
  1001. ::sandbox_compile_string(profile, params.params(), &errorbuf);
  1002. @@ -149,33 +170,44 @@ bool Seatbelt::Compile(const char* profile,
  1003. compiled_profile.assign(reinterpret_cast<const char*>(sandbox_profile->data),
  1004. sandbox_profile->size);
  1005. ::sandbox_free_profile(sandbox_profile);
  1006. +#endif
  1007. return true;
  1008. }
  1009. // static
  1010. bool Seatbelt::ApplyCompiledProfile(const std::string& profile,
  1011. std::string* error) {
  1012. +#if !IS_MAS_BUILD()
  1013. sandbox_profile_t sbox_profile = {
  1014. .builtin = nullptr,
  1015. .data = reinterpret_cast<const uint8_t*>(profile.data()),
  1016. .size = profile.size()};
  1017. return HandleSandboxErrno(::sandbox_apply(&sbox_profile),
  1018. "sandbox_apply: ", error);
  1019. +#else
  1020. + return true;
  1021. +#endif
  1022. }
  1023. // static
  1024. void Seatbelt::FreeError(char* errorbuf) {
  1025. +#if !IS_MAS_BUILD()
  1026. // OS X deprecated these functions, but did not provide a suitable replacement,
  1027. // so ignore the deprecation warning.
  1028. #pragma clang diagnostic push
  1029. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  1030. return ::sandbox_free_error(errorbuf);
  1031. #pragma clang diagnostic pop
  1032. +#endif
  1033. }
  1034. // static
  1035. bool Seatbelt::IsSandboxed() {
  1036. +#if !IS_MAS_BUILD()
  1037. return ::sandbox_check(getpid(), NULL, 0);
  1038. +#else
  1039. + return true;
  1040. +#endif
  1041. }
  1042. } // namespace sandbox
  1043. diff --git a/sandbox/mac/seatbelt_extension.cc b/sandbox/mac/seatbelt_extension.cc
  1044. index 18479382a277cb2b25626ec8d31442bfd1377ee6..7d80d7fa8337523c3a70f317f883f0cc26c6f40b 100644
  1045. --- a/sandbox/mac/seatbelt_extension.cc
  1046. +++ b/sandbox/mac/seatbelt_extension.cc
  1047. @@ -11,6 +11,7 @@
  1048. #include "base/notreached.h"
  1049. #include "sandbox/mac/seatbelt_extension_token.h"
  1050. +#if !IS_MAS_BUILD()
  1051. // libsandbox private API.
  1052. extern "C" {
  1053. extern const char* APP_SANDBOX_READ;
  1054. @@ -22,6 +23,7 @@ char* sandbox_extension_issue_file(const char* type,
  1055. const char* path,
  1056. uint32_t flags);
  1057. }
  1058. +#endif
  1059. namespace sandbox {
  1060. @@ -50,7 +52,11 @@ std::unique_ptr<SeatbeltExtension> SeatbeltExtension::FromToken(
  1061. bool SeatbeltExtension::Consume() {
  1062. DCHECK(!token_.empty());
  1063. +#if !IS_MAS_BUILD()
  1064. handle_ = sandbox_extension_consume(token_.c_str());
  1065. +#else
  1066. + handle_ = -1;
  1067. +#endif
  1068. return handle_ > 0;
  1069. }
  1070. @@ -62,7 +68,11 @@ bool SeatbeltExtension::ConsumePermanently() {
  1071. }
  1072. bool SeatbeltExtension::Revoke() {
  1073. +#if !IS_MAS_BUILD()
  1074. int rv = sandbox_extension_release(handle_);
  1075. +#else
  1076. + int rv = -1;
  1077. +#endif
  1078. handle_ = 0;
  1079. token_.clear();
  1080. return rv == 0;
  1081. @@ -80,12 +90,14 @@ SeatbeltExtension::SeatbeltExtension(const std::string& token)
  1082. char* SeatbeltExtension::IssueToken(SeatbeltExtension::Type type,
  1083. const std::string& resource) {
  1084. switch (type) {
  1085. +#if !IS_MAS_BUILD()
  1086. case FILE_READ:
  1087. return sandbox_extension_issue_file(APP_SANDBOX_READ, resource.c_str(),
  1088. 0);
  1089. case FILE_READ_WRITE:
  1090. return sandbox_extension_issue_file(APP_SANDBOX_READ_WRITE,
  1091. resource.c_str(), 0);
  1092. +#endif
  1093. default:
  1094. NOTREACHED();
  1095. return nullptr;
  1096. diff --git a/sandbox/mac/system_services.cc b/sandbox/mac/system_services.cc
  1097. index eb81a70e4d5d5cd3e6ae9b45f8cd1c795ea76c51..dc30306f2c5d20503399fc3a8860773aa0044352 100644
  1098. --- a/sandbox/mac/system_services.cc
  1099. +++ b/sandbox/mac/system_services.cc
  1100. @@ -9,6 +9,7 @@
  1101. #include "base/apple/osstatus_logging.h"
  1102. +#if !IS_MAS_BUILD()
  1103. extern "C" {
  1104. OSStatus SetApplicationIsDaemon(Boolean isDaemon);
  1105. void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1106. @@ -19,10 +20,12 @@ void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1107. // https://github.com/WebKit/WebKit/blob/24aaedc770d192d03a07ba4a71727274aaa8fc07/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm#L840
  1108. void _CSCheckFixDisable();
  1109. } // extern "C"
  1110. +#endif
  1111. namespace sandbox {
  1112. void DisableLaunchServices() {
  1113. + #if !IS_MAS_BUILD()
  1114. // Allow the process to continue without a LaunchServices ASN. The
  1115. // INIT_Process function in HIServices will abort if it cannot connect to
  1116. // launchservicesd to get an ASN. By setting this flag, HIServices skips
  1117. @@ -36,10 +39,13 @@ void DisableLaunchServices() {
  1118. 0, ^bool(CFDictionaryRef options) {
  1119. return false;
  1120. });
  1121. + #endif
  1122. }
  1123. void DisableCoreServicesCheckFix() {
  1124. +#if !IS_MAS_BUILD()
  1125. _CSCheckFixDisable();
  1126. +#endif
  1127. }
  1128. } // namespace sandbox
  1129. diff --git a/third_party/blink/renderer/core/BUILD.gn b/third_party/blink/renderer/core/BUILD.gn
  1130. index 421b11f8839a7304b0dd8a976b9f2176832c32bc..7738b5a04fb020681dfdd03dae5ac4331db08e4a 100644
  1131. --- a/third_party/blink/renderer/core/BUILD.gn
  1132. +++ b/third_party/blink/renderer/core/BUILD.gn
  1133. @@ -312,6 +312,7 @@ component("core") {
  1134. configs -= core_config_remove
  1135. configs += core_config_add
  1136. configs += [ "//v8:external_startup_data" ]
  1137. + configs += ["//electron/build/config:mas_build"]
  1138. public_deps = [
  1139. ":core_generated",
  1140. diff --git a/third_party/blink/renderer/core/editing/build.gni b/third_party/blink/renderer/core/editing/build.gni
  1141. index 16bc33b36fa860214a6b4647d69939080df1b556..3c170e36fbeaddee2790f79039d81c0ef958572f 100644
  1142. --- a/third_party/blink/renderer/core/editing/build.gni
  1143. +++ b/third_party/blink/renderer/core/editing/build.gni
  1144. @@ -354,10 +354,14 @@ blink_core_sources_editing = [
  1145. if (is_mac) {
  1146. blink_core_sources_editing += [
  1147. "commands/smart_replace_cf.cc",
  1148. - "kill_ring_mac.mm",
  1149. "substring_util.h",
  1150. "substring_util.mm",
  1151. ]
  1152. + if (is_mas_build) {
  1153. + blink_core_sources_editing += [ "kill_ring_mac.mm" ]
  1154. + } else {
  1155. + blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1156. + }
  1157. } else {
  1158. blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1159. }
  1160. diff --git a/ui/accelerated_widget_mac/BUILD.gn b/ui/accelerated_widget_mac/BUILD.gn
  1161. index 3ead42e14ad9d41a30c5637678a3ac49296ce2a6..8dec61ee6a62e54ec3c8c5dd5e08601c28d04dfe 100644
  1162. --- a/ui/accelerated_widget_mac/BUILD.gn
  1163. +++ b/ui/accelerated_widget_mac/BUILD.gn
  1164. @@ -33,6 +33,8 @@ component("accelerated_widget_mac") {
  1165. "QuartzCore.framework",
  1166. ]
  1167. + configs += ["//electron/build/config:mas_build"]
  1168. +
  1169. if (is_ios) {
  1170. sources += [ "ca_layer_frame_sink_provider.h" ]
  1171. }
  1172. diff --git a/ui/accelerated_widget_mac/display_ca_layer_tree.mm b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1173. index dcf493d62990018040a3f84b6f875af737bd2214..6ffffe8b3946e0427aead8be19878c537c841294 100644
  1174. --- a/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1175. +++ b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1176. @@ -121,6 +121,7 @@ - (void)setContentsChanged;
  1177. }
  1178. void DisplayCALayerTree::GotCALayerFrame(uint32_t ca_context_id) {
  1179. +#if !IS_MAS_BUILD()
  1180. // Early-out if the remote layer has not changed.
  1181. if (remote_layer_.contextId == ca_context_id) {
  1182. return;
  1183. @@ -150,6 +151,9 @@ - (void)setContentsChanged;
  1184. [io_surface_layer_ removeFromSuperlayer];
  1185. io_surface_layer_ = nil;
  1186. }
  1187. +#else
  1188. + NOTREACHED() << "Remote layer is being used in MAS build";
  1189. +#endif
  1190. }
  1191. void DisplayCALayerTree::GotIOSurfaceFrame(
  1192. diff --git a/ui/accessibility/platform/BUILD.gn b/ui/accessibility/platform/BUILD.gn
  1193. index fc99800e70eb29b94ac356b55caef81a25518896..e9fe9be7f737372b0111e113bd120b520fb4568a 100644
  1194. --- a/ui/accessibility/platform/BUILD.gn
  1195. +++ b/ui/accessibility/platform/BUILD.gn
  1196. @@ -254,6 +254,7 @@ component("platform") {
  1197. weak_frameworks = [
  1198. "Accessibility.framework", # macOS 11
  1199. ]
  1200. + configs += ["//electron/build/config:mas_build"]
  1201. }
  1202. if (use_atk) {
  1203. diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.mm b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1204. index c737a2ca1afb44083aef33c6aa4518bea68d1aba..879f1357b5129849c5a1aa1731cf769712569e9e 100644
  1205. --- a/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1206. +++ b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1207. @@ -108,6 +108,7 @@
  1208. }
  1209. }
  1210. +#if !IS_MAS_BUILD()
  1211. // AXTextMarker
  1212. if (IsAXTextMarker(value)) {
  1213. return AXTextMarkerToBaseValue(value, indexer);
  1214. @@ -117,6 +118,7 @@
  1215. if (IsAXTextMarkerRange(value)) {
  1216. return AXTextMarkerRangeToBaseValue(value, indexer);
  1217. }
  1218. +#endif
  1219. // Accessible object
  1220. if (AXElementWrapper::IsValidElement(value)) {
  1221. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  1222. index 3452178f0db87d7d18af3fea5386dc56b85e7fd2..fa510698a6ccc1c3d0e800733d69e167364b1663 100644
  1223. --- a/ui/base/BUILD.gn
  1224. +++ b/ui/base/BUILD.gn
  1225. @@ -361,6 +361,7 @@ component("base") {
  1226. "interaction/element_tracker_mac.mm",
  1227. "resource/resource_bundle_mac.mm",
  1228. ]
  1229. + configs += ["//electron/build/config:mas_build"]
  1230. }
  1231. if (is_apple) {
  1232. @@ -378,6 +379,13 @@ component("base") {
  1233. sources += [ "resource/resource_bundle_lacros.cc" ]
  1234. }
  1235. + if (is_mas_build) {
  1236. + sources -= [
  1237. + "cocoa/remote_accessibility_api.h",
  1238. + "cocoa/remote_accessibility_api.mm",
  1239. + ]
  1240. + }
  1241. +
  1242. if (is_ios) {
  1243. sources += [
  1244. "device_form_factor_ios.mm",
  1245. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  1246. index 3182458838aa96d34911280ab4c6c3aa4aa22d6d..17b57f54492421743a0d69106eefce2c9beb8e87 100644
  1247. --- a/ui/base/cocoa/remote_accessibility_api.h
  1248. +++ b/ui/base/cocoa/remote_accessibility_api.h
  1249. @@ -13,6 +13,8 @@
  1250. // NSAccessibilityRemoteUIElement is a private class in AppKit.
  1251. +#if !IS_MAS_BUILD()
  1252. +
  1253. @interface NSAccessibilityRemoteUIElement : NSObject
  1254. + (void)setRemoteUIApp:(BOOL)flag;
  1255. + (BOOL)isRemoteUIApp;
  1256. @@ -38,4 +40,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  1257. } // namespace ui
  1258. +#endif // MAS_BUILD
  1259. +
  1260. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  1261. diff --git a/ui/base/cocoa/remote_layer_api.h b/ui/base/cocoa/remote_layer_api.h
  1262. index 59dc2f82214cfd883b6ebef3b0fb25af6387a9cd..d585ba14b34021a93c878d0d9f9d9ef70eed32ca 100644
  1263. --- a/ui/base/cocoa/remote_layer_api.h
  1264. +++ b/ui/base/cocoa/remote_layer_api.h
  1265. @@ -17,6 +17,7 @@
  1266. #if BUILDFLAG(IS_MAC)
  1267. +#if !IS_MAS_BUILD()
  1268. // The CGSConnectionID is used to create the CAContext in the process that is
  1269. // going to share the CALayers that it is rendering to another process to
  1270. // display.
  1271. @@ -68,6 +69,8 @@ extern NSString* const kCAContextIgnoresHitTest;
  1272. #endif // __OBJC__
  1273. +#endif // MAS_BUILD
  1274. +
  1275. namespace ui {
  1276. // This function will check if all of the interfaces listed above are supported
  1277. diff --git a/ui/base/cocoa/remote_layer_api.mm b/ui/base/cocoa/remote_layer_api.mm
  1278. index fc25ba79d2b0e1acdb7ba54b89e7d6e16f94771b..962df2d65d61ec0836cf465d847eb666033846f2 100644
  1279. --- a/ui/base/cocoa/remote_layer_api.mm
  1280. +++ b/ui/base/cocoa/remote_layer_api.mm
  1281. @@ -10,6 +10,7 @@
  1282. namespace ui {
  1283. +#if !IS_MAS_BUILD()
  1284. namespace {
  1285. // Control use of cross-process CALayers to display content directly from the
  1286. // GPU process on Mac.
  1287. @@ -17,8 +18,10 @@
  1288. "RemoteCoreAnimationAPI",
  1289. base::FEATURE_ENABLED_BY_DEFAULT);
  1290. } // namespace
  1291. +#endif
  1292. bool RemoteLayerAPISupported() {
  1293. +#if !IS_MAS_BUILD()
  1294. if (!base::FeatureList::IsEnabled(kRemoteCoreAnimationAPI))
  1295. return false;
  1296. @@ -55,6 +58,9 @@ bool RemoteLayerAPISupported() {
  1297. // If everything is there, we should be able to use the API.
  1298. return true;
  1299. +#else
  1300. + return false;
  1301. +#endif // MAS_BUILD
  1302. }
  1303. } // namespace
  1304. diff --git a/ui/display/BUILD.gn b/ui/display/BUILD.gn
  1305. index fb806dddc33f8dc880ae5fdefb9389bf38a18931..3d8c09b5deed91b1381793578e17afe2750bc3ee 100644
  1306. --- a/ui/display/BUILD.gn
  1307. +++ b/ui/display/BUILD.gn
  1308. @@ -69,6 +69,10 @@ component("display") {
  1309. "mac/display_link_mac.h",
  1310. "mac/screen_mac.mm",
  1311. ]
  1312. +
  1313. + configs += [
  1314. + "//electron/build/config:mas_build"
  1315. + ]
  1316. }
  1317. if (is_win) {
  1318. diff --git a/ui/display/mac/screen_mac.mm b/ui/display/mac/screen_mac.mm
  1319. index a771c1c03fd1afe3a5e563b4421721a5ddc2eb93..a6cbdfcbeff30508d921d4637aac543dce9e8ad3 100644
  1320. --- a/ui/display/mac/screen_mac.mm
  1321. +++ b/ui/display/mac/screen_mac.mm
  1322. @@ -171,7 +171,17 @@ DisplayMac BuildDisplayForScreen(NSScreen* screen) {
  1323. display.set_color_depth(Display::kDefaultBitsPerPixel);
  1324. display.set_depth_per_component(Display::kDefaultBitsPerComponent);
  1325. }
  1326. +#if IS_MAS_BUILD()
  1327. + // This is equivalent to the CGDisplayUsesForceToGray() API as at 2018-08-06,
  1328. + // but avoids usage of the private API.
  1329. + CFStringRef app = CFSTR("com.apple.CoreGraphics");
  1330. + CFStringRef key = CFSTR("DisplayUseForcedGray");
  1331. + Boolean key_valid = false;
  1332. + display.set_is_monochrome(
  1333. + CFPreferencesGetAppBooleanValue(key, app, &key_valid));
  1334. +#else
  1335. display.set_is_monochrome(CGDisplayUsesForceToGray());
  1336. +#endif
  1337. // Query the display's refresh rate.
  1338. {
  1339. diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
  1340. index 3702eefa91a9dd22752b3d06d531885928a4d7a6..a78fd474d63d709a703f9c530c687305ddebcea0 100644
  1341. --- a/ui/gfx/BUILD.gn
  1342. +++ b/ui/gfx/BUILD.gn
  1343. @@ -204,6 +204,7 @@ component("gfx") {
  1344. "scoped_ns_graphics_context_save_gstate_mac.h",
  1345. "scoped_ns_graphics_context_save_gstate_mac.mm",
  1346. ]
  1347. + configs += ["//electron/build/config:mas_build"]
  1348. }
  1349. if (is_win) {
  1350. sources += [
  1351. diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm
  1352. index 0ab5fbd2a81d8860c73f29c08896f6755b5ca5fa..9400c6c7698258ff2834c550fb8901b49ced35bd 100644
  1353. --- a/ui/gfx/platform_font_mac.mm
  1354. +++ b/ui/gfx/platform_font_mac.mm
  1355. @@ -28,9 +28,11 @@
  1356. using Weight = Font::Weight;
  1357. +#if !IS_MAS_BUILD()
  1358. extern "C" {
  1359. bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
  1360. }
  1361. +#endif
  1362. namespace {
  1363. @@ -245,7 +247,13 @@ CTFontRef SystemFontForConstructorOfType(PlatformFontMac::SystemFontType type) {
  1364. // TODO(avi, etienneb): Figure out this font stuff.
  1365. base::apple::ScopedCFTypeRef<CTFontDescriptorRef> descriptor(
  1366. CTFontCopyFontDescriptor(font));
  1367. +#if IS_MAS_BUILD()
  1368. + CFNumberRef priority = (CFNumberRef)CTFontDescriptorCopyAttribute(descriptor.get(), (CFStringRef)kCTFontPriorityAttribute);
  1369. + SInt64 v;
  1370. + if (CFNumberGetValue(priority, kCFNumberSInt64Type, &v) && v == kCTFontPrioritySystem) {
  1371. +#else
  1372. if (CTFontDescriptorIsSystemUIFont(descriptor.get())) {
  1373. +#endif
  1374. // Assume it's the standard system font. The fact that this much is known is
  1375. // enough.
  1376. return PlatformFontMac::SystemFontType::kGeneral;
  1377. diff --git a/ui/views/BUILD.gn b/ui/views/BUILD.gn
  1378. index a64df51a061e4d1b1d923fab830e5b3be4c389ba..e0cb6abb7a5010c69f82a3edcea5700cda3895cf 100644
  1379. --- a/ui/views/BUILD.gn
  1380. +++ b/ui/views/BUILD.gn
  1381. @@ -710,6 +710,7 @@ component("views") {
  1382. "IOSurface.framework",
  1383. "QuartzCore.framework",
  1384. ]
  1385. + configs += ["//electron/build/config:mas_build"]
  1386. }
  1387. if (is_win) {
  1388. @@ -1139,6 +1140,8 @@ source_set("test_support") {
  1389. "//testing/gtest",
  1390. ]
  1391. + configs += ["//electron/build/config:mas_build"]
  1392. +
  1393. if (is_win) {
  1394. sources += [
  1395. "test/desktop_window_tree_host_win_test_api.cc",
  1396. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1397. index f37c02488e6ba943ebf9b880a04bcfef9afc9d97..b10ed25b5cdf5eb2f314ed72226f71c8bc35e58e 100644
  1398. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1399. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1400. @@ -30,7 +30,9 @@
  1401. #include "ui/views/window/dialog_observer.h"
  1402. @class NativeWidgetMacNSWindow;
  1403. +#if !IS_MAS_BUILD()
  1404. @class NSAccessibilityRemoteUIElement;
  1405. +#endif
  1406. @class NSView;
  1407. namespace remote_cocoa {
  1408. @@ -465,10 +467,12 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  1409. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  1410. remote_ns_window_remote_;
  1411. +#if !IS_MAS_BUILD()
  1412. // Remote accessibility objects corresponding to the NSWindow and its root
  1413. // NSView.
  1414. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  1415. NSAccessibilityRemoteUIElement* __strong remote_view_accessible_;
  1416. +#endif
  1417. // Used to force the NSApplication's focused accessibility element to be the
  1418. // views::Views accessibility tree when the NSView for this is focused.
  1419. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1420. index 52ee42399fdec85ab31da6cf6392698f58c4f2cb..9592cf7eadccbba522661da5a906896f11f69942 100644
  1421. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1422. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1423. @@ -345,7 +345,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1424. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  1425. if (in_process_ns_window_bridge_)
  1426. return in_process_ns_window_bridge_->ns_view();
  1427. +#if !IS_MAS_BUILD()
  1428. return remote_view_accessible_;
  1429. +#else
  1430. + return nullptr;
  1431. +#endif
  1432. }
  1433. gfx::NativeViewAccessible
  1434. @@ -360,7 +364,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1435. return [in_process_ns_window_bridge_->ns_view() window];
  1436. }
  1437. +#if !IS_MAS_BUILD()
  1438. return remote_window_accessible_;
  1439. +#else
  1440. + return nullptr;
  1441. +#endif
  1442. }
  1443. remote_cocoa::mojom::NativeWidgetNSWindow*
  1444. @@ -1410,6 +1418,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1445. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  1446. const std::vector<uint8_t>& window_token,
  1447. const std::vector<uint8_t>& view_token) {
  1448. +#if !IS_MAS_BUILD()
  1449. remote_window_accessible_ =
  1450. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  1451. remote_view_accessible_ =
  1452. @@ -1421,11 +1430,13 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1453. ![NSAccessibilityRemoteUIElement isRemoteUIApp]) {
  1454. [NSAccessibilityRemoteUIElement setRemoteUIApp:YES];
  1455. }
  1456. +#endif
  1457. }
  1458. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  1459. int64_t* pid,
  1460. std::vector<uint8_t>* token) {
  1461. +#if !IS_MAS_BUILD()
  1462. *pid = getpid();
  1463. id element_id = GetNativeViewAccessible();
  1464. @@ -1438,6 +1449,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1465. }
  1466. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  1467. +#endif
  1468. return true;
  1469. }
  1470. diff --git a/ui/views/controls/webview/BUILD.gn b/ui/views/controls/webview/BUILD.gn
  1471. index e3dd4fab3a1cac0138f8dac60247e0ea3343e87e..f31130eaa3719eda0da5b3f0e8c294775faf6bd4 100644
  1472. --- a/ui/views/controls/webview/BUILD.gn
  1473. +++ b/ui/views/controls/webview/BUILD.gn
  1474. @@ -19,6 +19,9 @@ component("webview") {
  1475. if (is_mac) {
  1476. sources += [ "unhandled_keyboard_event_handler_mac.mm" ]
  1477. + configs += [
  1478. + "//electron/build/config:mas_build",
  1479. + ]
  1480. }
  1481. if (is_win) {