mas_avoid_private_macos_api_usage.patch.patch 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  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 9247e9b3f4c92e6f573898049bca784cccb4b19c..a615fd0af29052246890ab2bf21a3d35b7637864 100644
  36. --- a/base/BUILD.gn
  37. +++ b/base/BUILD.gn
  38. @@ -1027,6 +1027,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 569c1c83d82517d9cb65282f766368ce3d9d0572..db9e7c7e76337468d9e2eb3fca93752ee2bd8ae1 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. @@ -104,13 +109,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. @@ -234,7 +253,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 3b81e00e1535ec729a521b83fe2471985d177e5c..b3706a4a0f77f8e5fbae3df97153b9cbed7d01f0 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 b7a2dede5c5e9a797d10627b7d804064bf13b3f4..d915dccc7dd53ef3eaaae3c50e04342be7c12b38 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 e9f4e5131238b9fb5f1b4b3e90a0cb84a7fc15b4..2202d42e472da0d9bd672e1c12c5d50fc4763c66 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. base::ProcessId browser_pid = base::kNullProcessId;
  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 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 2aa2bd8d68c08359461254875f02fc37f8693058..6ba759f96ffff4d31509248bb7add0477eb833ed 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. @@ -111,14 +111,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. @@ -157,6 +161,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. @@ -184,6 +190,8 @@ - (BOOL)usesCustomDrawing {
  297. }
  298. @end
  299. +#endif // MAS_BUILD
  300. +
  301. @implementation NativeWidgetMacNSWindow {
  302. @private
  303. CommandDispatcher* __strong _commandDispatcher;
  304. @@ -374,6 +382,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. @@ -385,6 +395,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 285a406e8cec06bf3beeca81b32e6561528279f9..0a08dc58852bc16edd3144e819276a0dc28a2580 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. @@ -643,10 +643,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 853a95c65674b1011898c64445024bdc30c9709b..8d048719e1b062b3115d185a47cd4c92e318a145 100644
  336. --- a/components/viz/service/BUILD.gn
  337. +++ b/components/viz/service/BUILD.gn
  338. @@ -371,6 +371,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. @@ -645,6 +646,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 7b306925815201084a92db192d623b7d2f4d2691..79b647b03826aadde3b58b448192943cabc182dd 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 4e163a30b7f987b0127cabf84a4610bfb81b9662..6ca8be361bcae47c7bc3ac606d7e42c5c66a056e 100644
  417. --- a/content/browser/BUILD.gn
  418. +++ b/content/browser/BUILD.gn
  419. @@ -73,6 +73,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/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  428. index 2285564db47ef15eb9a83affd1e481b5671c3940..bc18a276d3029c3b858cfcb378ae2e4255d4d83e 100644
  429. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  430. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  431. @@ -53,7 +53,9 @@ class CursorManager;
  432. @protocol RenderWidgetHostViewMacDelegate;
  433. +#if !IS_MAS_BUILD()
  434. @class NSAccessibilityRemoteUIElement;
  435. +#endif
  436. @class RenderWidgetHostViewCocoa;
  437. namespace content {
  438. @@ -684,9 +686,11 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  439. // EnsureSurfaceSynchronizedForWebTest().
  440. uint32_t latest_capture_sequence_number_ = 0u;
  441. +#if !IS_MAS_BUILD()
  442. // Remote accessibility objects corresponding to the NSWindow that this is
  443. // displayed to the user in.
  444. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  445. +#endif
  446. // Used to force the NSApplication's focused accessibility element to be the
  447. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  448. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  449. index d0dc93a37fec9fc22373a6aa08f03feb2839fde0..803a812ca36a45647bb4379a323adf395cc5bb38 100644
  450. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  451. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  452. @@ -273,8 +273,10 @@
  453. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  454. remote_cocoa::mojom::Application* remote_cocoa_application,
  455. uint64_t parent_ns_view_id) {
  456. +#if !IS_MAS_BUILD()
  457. // Destroy the previous remote accessibility element.
  458. remote_window_accessible_ = nil;
  459. +#endif
  460. // Reset `ns_view_` before resetting `remote_ns_view_` to avoid dangling
  461. // pointers. `ns_view_` gets reinitialized later in this method.
  462. @@ -1637,8 +1639,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  463. gfx::NativeViewAccessible
  464. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  465. +#if !IS_MAS_BUILD()
  466. if (remote_window_accessible_)
  467. return remote_window_accessible_;
  468. +#endif
  469. return [GetInProcessNSView() window];
  470. }
  471. @@ -1687,9 +1691,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  472. }
  473. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  474. +#if !IS_MAS_BUILD()
  475. // When running in-process, just use the NSView's NSWindow as its own
  476. // accessibility element.
  477. remote_window_accessible_ = nil;
  478. +#endif
  479. }
  480. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  481. @@ -2213,20 +2219,26 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  482. void RenderWidgetHostViewMac::GetRenderWidgetAccessibilityToken(
  483. GetRenderWidgetAccessibilityTokenCallback callback) {
  484. base::ProcessId pid = getpid();
  485. +#if !IS_MAS_BUILD()
  486. id element_id = GetNativeViewAccessible();
  487. std::vector<uint8_t> token =
  488. ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  489. std::move(callback).Run(pid, token);
  490. +#else
  491. + std::move(callback).Run(pid, std::vector<uint8_t>());
  492. +#endif
  493. }
  494. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  495. const std::vector<uint8_t>& window_token) {
  496. +#if !IS_MAS_BUILD()
  497. if (window_token.empty()) {
  498. remote_window_accessible_ = nil;
  499. } else {
  500. remote_window_accessible_ =
  501. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  502. }
  503. +#endif
  504. }
  505. ///////////////////////////////////////////////////////////////////////////////
  506. diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn
  507. index 9f48c905f4abbb0f2e184299a915232cf6a0f6b0..f2d36e7b59533d7514a61a931341ef612f12b107 100644
  508. --- a/content/common/BUILD.gn
  509. +++ b/content/common/BUILD.gn
  510. @@ -198,6 +198,7 @@ source_set("common") {
  511. "//content:content_implementation",
  512. "//build/config:precompiled_headers",
  513. ]
  514. + configs += ["//electron/build/config:mas_build"]
  515. public_deps = [
  516. ":mojo_bindings",
  517. diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn
  518. index 2ac766d0149f0405b3fcad0ec1b6e0685ed3658c..5554eb0e084becf8100579f1d15e4796345676ba 100644
  519. --- a/content/renderer/BUILD.gn
  520. +++ b/content/renderer/BUILD.gn
  521. @@ -230,6 +230,7 @@ target(link_target_type, "renderer") {
  522. }
  523. configs += [ "//content:content_implementation" ]
  524. + configs += ["//electron/build/config:mas_build"]
  525. defines = []
  526. public_deps = [
  527. diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
  528. index d4db3b179725cb96bcbd0f73db7d52ef8b7522db..6afbf1defb0591d9fe59a81e6c74746d3e15f081 100644
  529. --- a/content/renderer/renderer_main_platform_delegate_mac.mm
  530. +++ b/content/renderer/renderer_main_platform_delegate_mac.mm
  531. @@ -10,9 +10,11 @@
  532. #include "sandbox/mac/seatbelt.h"
  533. #include "sandbox/mac/system_services.h"
  534. +#if !IS_MAS_BUILD()
  535. extern "C" {
  536. CGError CGSSetDenyWindowServerConnections(bool);
  537. }
  538. +#endif
  539. namespace content {
  540. @@ -22,6 +24,7 @@
  541. // verifies there are no existing open connections), and then indicates that
  542. // Chrome should continue execution without access to launchservicesd.
  543. void DisableSystemServices() {
  544. +#if !IS_MAS_BUILD()
  545. // Tell the WindowServer that we don't want to make any future connections.
  546. // This will return Success as long as there are no open connections, which
  547. // is what we want.
  548. @@ -30,6 +33,7 @@ void DisableSystemServices() {
  549. sandbox::DisableLaunchServices();
  550. sandbox::DisableCoreServicesCheckFix();
  551. +#endif
  552. }
  553. } // namespace
  554. diff --git a/content/renderer/theme_helper_mac.mm b/content/renderer/theme_helper_mac.mm
  555. index a1068589ad844518038ee7bc15a3de9bc5cba525..2208a79d44a05d21eba200f94f89aa1bff7da668 100644
  556. --- a/content/renderer/theme_helper_mac.mm
  557. +++ b/content/renderer/theme_helper_mac.mm
  558. @@ -8,15 +8,26 @@
  559. #include "base/strings/sys_string_conversions.h"
  560. +#if !IS_MAS_BUILD()
  561. extern "C" {
  562. bool CGFontRenderingGetFontSmoothingDisabled(void);
  563. }
  564. -
  565. +#endif
  566. namespace content {
  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 14731a0b1d157a4c15a87dbcc6342d69de84a881..e1eced68e00dddfa74776992a3e4f1bbf557737c 100644
  584. --- a/content/test/BUILD.gn
  585. +++ b/content/test/BUILD.gn
  586. @@ -504,6 +504,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. @@ -1107,6 +1108,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. @@ -1788,6 +1790,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. @@ -3042,6 +3045,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 99e612f705c5dff041454802033564085718260a..dd2935c6ca926138b9d72e524b7c13b495e5335f 100644
  612. --- a/content/web_test/BUILD.gn
  613. +++ b/content/web_test/BUILD.gn
  614. @@ -159,6 +159,8 @@ static_library("web_test_browser") {
  615. ]
  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 82d4f2bf563f6bf489b1f257efb249ba4ec9a7f3..2959a166d0acf29d79b2c006e0d0f5ab50f90d8b 100644
  624. --- a/device/bluetooth/BUILD.gn
  625. +++ b/device/bluetooth/BUILD.gn
  626. @@ -258,6 +258,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 fa86583a2d82c4076cfcf64cdc3f6bbb533b95d7..71b731e2e25ba876639d169c2242087dcf9ff389 100644
  635. --- a/device/bluetooth/bluetooth_adapter_mac.mm
  636. +++ b/device/bluetooth/bluetooth_adapter_mac.mm
  637. @@ -39,6 +39,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. @@ -52,6 +53,7 @@
  645. // [4] https://support.apple.com/kb/PH25091
  646. void IOBluetoothPreferenceSetControllerPowerState(int state);
  647. }
  648. +#endif
  649. // A simple helper class that forwards any Bluetooth device connect notification
  650. // to its wrapped |_adapter|.
  651. @@ -161,8 +163,10 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  652. : controller_state_function_(
  653. base::BindRepeating(&BluetoothAdapterMac::GetHostControllerState,
  654. base::Unretained(this))),
  655. +#if !IS_MAS_BUILD()
  656. power_state_function_(
  657. base::BindRepeating(IOBluetoothPreferenceSetControllerPowerState)),
  658. +#endif
  659. device_paired_status_callback_(
  660. base::BindRepeating(&IsDeviceSystemPaired)) {
  661. }
  662. @@ -313,8 +317,12 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  663. }
  664. bool BluetoothAdapterMac::SetPoweredImpl(bool powered) {
  665. +#if !IS_MAS_BUILD()
  666. power_state_function_.Run(base::strict_cast<int>(powered));
  667. return true;
  668. +#else
  669. + return false;
  670. +#endif
  671. }
  672. base::WeakPtr<BluetoothLowEnergyAdapterApple>
  673. diff --git a/gpu/ipc/service/BUILD.gn b/gpu/ipc/service/BUILD.gn
  674. index 973cd337f2781271b4ca3e29db07939ec6917327..fda1b6535cd64a11369796d283b89e6a83449055 100644
  675. --- a/gpu/ipc/service/BUILD.gn
  676. +++ b/gpu/ipc/service/BUILD.gn
  677. @@ -135,6 +135,7 @@ component("service") {
  678. "QuartzCore.framework",
  679. ]
  680. defines += [ "GL_SILENCE_DEPRECATION" ]
  681. + configs += ["//electron/build/config:mas_build"]
  682. }
  683. if (is_ios) {
  684. sources += [ "image_transport_surface_ios.mm" ]
  685. diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.h b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  686. index 36322ddd3047f96569f35807541a37d3c6672b09..3162cb6e3dce2c44e5b1e5f33f9177da832d26aa 100644
  687. --- a/gpu/ipc/service/image_transport_surface_overlay_mac.h
  688. +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  689. @@ -23,7 +23,9 @@
  690. #include "ui/display/types/display_constants.h"
  691. #endif
  692. +#if !IS_MAS_BUILD()
  693. @class CAContext;
  694. +#endif
  695. @class CALayer;
  696. namespace ui {
  697. diff --git a/media/audio/BUILD.gn b/media/audio/BUILD.gn
  698. index 6f3b368103b05f07ae67da4c0307efe039b8dfce..a1b11c298ee8b2c9b3cbe6307bc7744c242976b6 100644
  699. --- a/media/audio/BUILD.gn
  700. +++ b/media/audio/BUILD.gn
  701. @@ -197,6 +197,7 @@ source_set("audio") {
  702. "CoreMedia.framework",
  703. ]
  704. weak_frameworks = [ "ScreenCaptureKit.framework" ] # macOS 13.0
  705. + configs += ["//electron/build/config:mas_build"]
  706. }
  707. if (is_ios) {
  708. diff --git a/media/audio/apple/audio_low_latency_input.cc b/media/audio/apple/audio_low_latency_input.cc
  709. index 9b78f60304a0e487904fdb22c9e6d85a237ca96e..fc5508c41aa08dd7bf1365a7c03b68723aae3a4b 100644
  710. --- a/media/audio/apple/audio_low_latency_input.cc
  711. +++ b/media/audio/apple/audio_low_latency_input.cc
  712. @@ -39,19 +39,23 @@
  713. namespace {
  714. extern "C" {
  715. +#if !IS_MAS_BUILD()
  716. // See:
  717. // https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/PAL/pal/spi/cf/CoreAudioSPI.h?rev=228264
  718. OSStatus AudioDeviceDuck(AudioDeviceID inDevice,
  719. Float32 inDuckedLevel,
  720. const AudioTimeStamp* __nullable inStartTime,
  721. Float32 inRampDuration) __attribute__((weak_import));
  722. +#endif
  723. }
  724. void UndoDucking(AudioDeviceID output_device_id) {
  725. +#if !IS_MAS_BUILD()
  726. if (AudioDeviceDuck != nullptr) {
  727. // Ramp the volume back up over half a second.
  728. AudioDeviceDuck(output_device_id, 1.0, nullptr, 0.5);
  729. }
  730. +#endif
  731. }
  732. } // namespace
  733. #endif
  734. diff --git a/net/dns/BUILD.gn b/net/dns/BUILD.gn
  735. index 5f4ff9ff8172d4ad282cc9c781f85118b8ba7d1a..6a542c8f0d7afad876ab2739a1a2576a64cb6be9 100644
  736. --- a/net/dns/BUILD.gn
  737. +++ b/net/dns/BUILD.gn
  738. @@ -187,6 +187,8 @@ source_set("dns") {
  739. ":host_resolver_manager",
  740. ":mdns_client",
  741. ]
  742. +
  743. + configs += ["//electron/build/config:mas_build"]
  744. }
  745. # The standard API of net/dns.
  746. diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
  747. index 70d5665ad7b9ef62370497636af919ede2508ad4..3f6816de14f4bd19422a2b04830649d1d12e9179 100644
  748. --- a/net/dns/dns_config_service_posix.cc
  749. +++ b/net/dns/dns_config_service_posix.cc
  750. @@ -135,8 +135,8 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  751. bool Watch() override {
  752. CheckOnCorrectSequence();
  753. -
  754. bool success = true;
  755. +#if !IS_MAS_BUILD()
  756. if (!config_watcher_.Watch(base::BindRepeating(&Watcher::OnConfigChanged,
  757. base::Unretained(this)))) {
  758. LOG(ERROR) << "DNS config watch failed to start.";
  759. @@ -153,6 +153,7 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  760. success = false;
  761. }
  762. #endif // !BUILDFLAG(IS_IOS)
  763. +#endif
  764. return success;
  765. }
  766. diff --git a/sandbox/mac/BUILD.gn b/sandbox/mac/BUILD.gn
  767. index 299a028f23314f479d2da8f914a5bdf34698d854..672dcb04dd3cf4e3cc71403f727a1dde91ad4402 100644
  768. --- a/sandbox/mac/BUILD.gn
  769. +++ b/sandbox/mac/BUILD.gn
  770. @@ -39,6 +39,7 @@ component("seatbelt") {
  771. ]
  772. public_deps = [ "//third_party/protobuf:protobuf_lite" ]
  773. defines = [ "SEATBELT_IMPLEMENTATION" ]
  774. + configs += ["//electron/build/config:mas_build"]
  775. }
  776. component("seatbelt_extension") {
  777. @@ -52,6 +53,7 @@ component("seatbelt_extension") {
  778. libs = [ "sandbox" ]
  779. public_deps = [ "//base" ]
  780. defines = [ "SEATBELT_IMPLEMENTATION" ]
  781. + configs += ["//electron/build/config:mas_build"]
  782. }
  783. component("system_services") {
  784. @@ -66,6 +68,7 @@ component("system_services") {
  785. deps = [ ":seatbelt_export" ]
  786. public_deps = [ "//base" ]
  787. defines = [ "SEATBELT_IMPLEMENTATION" ]
  788. + configs += ["//electron/build/config:mas_build"]
  789. }
  790. source_set("sandbox_unittests") {
  791. diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
  792. index f35d9ef2a2df3db8ecbf1d7b909c7b1cf33f3cd9..a710b8b4f851666fd65bb37f69ec2fa70259697b 100644
  793. --- a/sandbox/mac/sandbox_compiler.cc
  794. +++ b/sandbox/mac/sandbox_compiler.cc
  795. @@ -47,6 +47,7 @@ bool SandboxCompiler::SetParameter(const std::string& key,
  796. }
  797. bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  798. +#if !IS_MAS_BUILD()
  799. if (mode_ == Target::kSource) {
  800. std::vector<const char*> params;
  801. @@ -67,6 +68,9 @@ bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  802. }
  803. }
  804. return false;
  805. +#else
  806. + return true;
  807. +#endif
  808. }
  809. bool SandboxCompiler::CompilePolicyToProto(mac::SandboxPolicy& policy,
  810. diff --git a/sandbox/mac/sandbox_logging.cc b/sandbox/mac/sandbox_logging.cc
  811. index 095c639b9893e885d8937e29ed7d47a7c28bc6b6..cfa5e307de8326fbc335996feaf9595d1572cd3d 100644
  812. --- a/sandbox/mac/sandbox_logging.cc
  813. +++ b/sandbox/mac/sandbox_logging.cc
  814. @@ -33,9 +33,11 @@
  815. }
  816. #endif
  817. +#if !IS_MAS_BUILD()
  818. extern "C" {
  819. void abort_report_np(const char*, ...);
  820. }
  821. +#endif
  822. namespace sandbox::logging {
  823. @@ -76,9 +78,11 @@ void SendOsLog(Level level, const char* message) {
  824. sandbox::crash_message::SetCrashMessage(message);
  825. }
  826. +#if !IS_MAS_BUILD()
  827. if (level == Level::FATAL) {
  828. abort_report_np(message);
  829. }
  830. +#endif
  831. }
  832. // |error| is strerror(errno) when a P* logging function is called. Pass
  833. diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
  834. index 15c835e118456394c0a00ac98c11241c14ca75bd..83759e5fbc252fa57ca2fa122873dfac3d61d46d 100644
  835. --- a/sandbox/mac/seatbelt.cc
  836. +++ b/sandbox/mac/seatbelt.cc
  837. @@ -9,7 +9,7 @@
  838. extern "C" {
  839. #include <sandbox.h>
  840. -
  841. +#if !IS_MAS_BUILD()
  842. int sandbox_init_with_parameters(const char* profile,
  843. uint64_t flags,
  844. const char* const parameters[],
  845. @@ -40,13 +40,13 @@ sandbox_profile_t* sandbox_compile_string(const char* data,
  846. char** error);
  847. int sandbox_apply(sandbox_profile_t*);
  848. void sandbox_free_profile(sandbox_profile_t*);
  849. -
  850. +#endif
  851. } // extern "C"
  852. namespace sandbox {
  853. namespace {
  854. -
  855. +#if !IS_MAS_BUILD()
  856. bool HandleSandboxResult(int rv, char* errorbuf, std::string* error) {
  857. if (rv == 0) {
  858. if (error)
  859. @@ -74,36 +74,48 @@ bool HandleSandboxErrno(int rv, const char* message, std::string* error) {
  860. }
  861. return false;
  862. }
  863. -
  864. +#endif
  865. } // namespace
  866. // static
  867. Seatbelt::Parameters Seatbelt::Parameters::Create() {
  868. Parameters params;
  869. +#if !IS_MAS_BUILD()
  870. params.params_ = ::sandbox_create_params();
  871. +#endif
  872. return params;
  873. }
  874. Seatbelt::Parameters::Parameters() = default;
  875. Seatbelt::Parameters::Parameters(Seatbelt::Parameters&& other) {
  876. +#if !IS_MAS_BUILD()
  877. params_ = std::exchange(other.params_, nullptr);
  878. +#endif
  879. }
  880. Seatbelt::Parameters& Seatbelt::Parameters::operator=(
  881. Seatbelt::Parameters&& other) {
  882. +#if !IS_MAS_BUILD()
  883. params_ = std::exchange(other.params_, nullptr);
  884. +#endif
  885. return *this;
  886. }
  887. bool Seatbelt::Parameters::Set(const char* key, const char* value) {
  888. +#if !IS_MAS_BUILD()
  889. return ::sandbox_set_param(params_, key, value) == 0;
  890. +#else
  891. + return true;
  892. +#endif
  893. }
  894. Seatbelt::Parameters::~Parameters() {
  895. +#if !IS_MAS_BUILD()
  896. if (params_) {
  897. ::sandbox_free_params(params_);
  898. }
  899. +#endif
  900. }
  901. // Initialize the static member variables.
  902. @@ -114,6 +126,7 @@ const char* Seatbelt::kProfilePureComputation = kSBXProfilePureComputation;
  903. // static
  904. bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  905. +#if !IS_MAS_BUILD()
  906. // OS X deprecated these functions, but did not provide a suitable replacement,
  907. // so ignore the deprecation warning.
  908. #pragma clang diagnostic push
  909. @@ -122,6 +135,9 @@ bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  910. int rv = ::sandbox_init(profile, flags, &errorbuf);
  911. return HandleSandboxResult(rv, errorbuf, error);
  912. #pragma clang diagnostic pop
  913. +#else
  914. + return true;
  915. +#endif
  916. }
  917. // static
  918. @@ -129,10 +145,14 @@ bool Seatbelt::InitWithParams(const char* profile,
  919. uint64_t flags,
  920. const char* const parameters[],
  921. std::string* error) {
  922. +#if !IS_MAS_BUILD()
  923. char* errorbuf = nullptr;
  924. int rv =
  925. ::sandbox_init_with_parameters(profile, flags, parameters, &errorbuf);
  926. return HandleSandboxResult(rv, errorbuf, error);
  927. +#else
  928. + return true;
  929. +#endif
  930. }
  931. // static
  932. @@ -140,6 +160,7 @@ bool Seatbelt::Compile(const char* profile,
  933. const Seatbelt::Parameters& params,
  934. std::string& compiled_profile,
  935. std::string* error) {
  936. +#if !IS_MAS_BUILD()
  937. char* errorbuf = nullptr;
  938. sandbox_profile_t* sandbox_profile =
  939. ::sandbox_compile_string(profile, params.params(), &errorbuf);
  940. @@ -149,33 +170,44 @@ bool Seatbelt::Compile(const char* profile,
  941. compiled_profile.assign(reinterpret_cast<const char*>(sandbox_profile->data),
  942. sandbox_profile->size);
  943. ::sandbox_free_profile(sandbox_profile);
  944. +#endif
  945. return true;
  946. }
  947. // static
  948. bool Seatbelt::ApplyCompiledProfile(const std::string& profile,
  949. std::string* error) {
  950. +#if !IS_MAS_BUILD()
  951. sandbox_profile_t sbox_profile = {
  952. .builtin = nullptr,
  953. .data = reinterpret_cast<const uint8_t*>(profile.data()),
  954. .size = profile.size()};
  955. return HandleSandboxErrno(::sandbox_apply(&sbox_profile),
  956. "sandbox_apply: ", error);
  957. +#else
  958. + return true;
  959. +#endif
  960. }
  961. // static
  962. void Seatbelt::FreeError(char* errorbuf) {
  963. +#if !IS_MAS_BUILD()
  964. // OS X deprecated these functions, but did not provide a suitable replacement,
  965. // so ignore the deprecation warning.
  966. #pragma clang diagnostic push
  967. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  968. return ::sandbox_free_error(errorbuf);
  969. #pragma clang diagnostic pop
  970. +#endif
  971. }
  972. // static
  973. bool Seatbelt::IsSandboxed() {
  974. +#if !IS_MAS_BUILD()
  975. return ::sandbox_check(getpid(), NULL, 0);
  976. +#else
  977. + return true;
  978. +#endif
  979. }
  980. } // namespace sandbox
  981. diff --git a/sandbox/mac/seatbelt_extension.cc b/sandbox/mac/seatbelt_extension.cc
  982. index b3f017a8be25209a78ed6a1221abcdeeb7904752..506d520e41f321e02b227e07b7b41a4bbfec8d4d 100644
  983. --- a/sandbox/mac/seatbelt_extension.cc
  984. +++ b/sandbox/mac/seatbelt_extension.cc
  985. @@ -11,6 +11,7 @@
  986. #include "base/notreached.h"
  987. #include "sandbox/mac/seatbelt_extension_token.h"
  988. +#if !IS_MAS_BUILD()
  989. // libsandbox private API.
  990. extern "C" {
  991. extern const char* APP_SANDBOX_READ;
  992. @@ -22,6 +23,7 @@ char* sandbox_extension_issue_file(const char* type,
  993. const char* path,
  994. uint32_t flags);
  995. }
  996. +#endif
  997. namespace sandbox {
  998. @@ -50,7 +52,11 @@ std::unique_ptr<SeatbeltExtension> SeatbeltExtension::FromToken(
  999. bool SeatbeltExtension::Consume() {
  1000. DCHECK(!token_.empty());
  1001. +#if !IS_MAS_BUILD()
  1002. handle_ = sandbox_extension_consume(token_.c_str());
  1003. +#else
  1004. + handle_ = -1;
  1005. +#endif
  1006. return handle_ > 0;
  1007. }
  1008. @@ -62,7 +68,11 @@ bool SeatbeltExtension::ConsumePermanently() {
  1009. }
  1010. bool SeatbeltExtension::Revoke() {
  1011. +#if !IS_MAS_BUILD()
  1012. int rv = sandbox_extension_release(handle_);
  1013. +#else
  1014. + int rv = -1;
  1015. +#endif
  1016. handle_ = 0;
  1017. token_.clear();
  1018. return rv == 0;
  1019. @@ -80,12 +90,14 @@ SeatbeltExtension::SeatbeltExtension(const std::string& token)
  1020. char* SeatbeltExtension::IssueToken(SeatbeltExtension::Type type,
  1021. const std::string& resource) {
  1022. switch (type) {
  1023. +#if !IS_MAS_BUILD()
  1024. case FILE_READ:
  1025. return sandbox_extension_issue_file(APP_SANDBOX_READ, resource.c_str(),
  1026. 0);
  1027. case FILE_READ_WRITE:
  1028. return sandbox_extension_issue_file(APP_SANDBOX_READ_WRITE,
  1029. resource.c_str(), 0);
  1030. +#endif
  1031. default:
  1032. NOTREACHED_IN_MIGRATION();
  1033. return nullptr;
  1034. diff --git a/sandbox/mac/system_services.cc b/sandbox/mac/system_services.cc
  1035. index eb81a70e4d5d5cd3e6ae9b45f8cd1c795ea76c51..dc30306f2c5d20503399fc3a8860773aa0044352 100644
  1036. --- a/sandbox/mac/system_services.cc
  1037. +++ b/sandbox/mac/system_services.cc
  1038. @@ -9,6 +9,7 @@
  1039. #include "base/apple/osstatus_logging.h"
  1040. +#if !IS_MAS_BUILD()
  1041. extern "C" {
  1042. OSStatus SetApplicationIsDaemon(Boolean isDaemon);
  1043. void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1044. @@ -19,10 +20,12 @@ void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1045. // https://github.com/WebKit/WebKit/blob/24aaedc770d192d03a07ba4a71727274aaa8fc07/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm#L840
  1046. void _CSCheckFixDisable();
  1047. } // extern "C"
  1048. +#endif
  1049. namespace sandbox {
  1050. void DisableLaunchServices() {
  1051. + #if !IS_MAS_BUILD()
  1052. // Allow the process to continue without a LaunchServices ASN. The
  1053. // INIT_Process function in HIServices will abort if it cannot connect to
  1054. // launchservicesd to get an ASN. By setting this flag, HIServices skips
  1055. @@ -36,10 +39,13 @@ void DisableLaunchServices() {
  1056. 0, ^bool(CFDictionaryRef options) {
  1057. return false;
  1058. });
  1059. + #endif
  1060. }
  1061. void DisableCoreServicesCheckFix() {
  1062. +#if !IS_MAS_BUILD()
  1063. _CSCheckFixDisable();
  1064. +#endif
  1065. }
  1066. } // namespace sandbox
  1067. diff --git a/third_party/blink/renderer/core/BUILD.gn b/third_party/blink/renderer/core/BUILD.gn
  1068. index d6bdf90cc367cfd2dd8a6bea596593384bcde9d9..39d6bbda37fc62886712a38562ecedfd3904e2ae 100644
  1069. --- a/third_party/blink/renderer/core/BUILD.gn
  1070. +++ b/third_party/blink/renderer/core/BUILD.gn
  1071. @@ -332,6 +332,7 @@ component("core") {
  1072. configs -= core_config_remove
  1073. configs += core_config_add
  1074. configs += [ "//v8:external_startup_data" ]
  1075. + configs += ["//electron/build/config:mas_build"]
  1076. public_deps = [
  1077. ":buildflags",
  1078. diff --git a/third_party/blink/renderer/core/editing/build.gni b/third_party/blink/renderer/core/editing/build.gni
  1079. index 44e437c91135ec09c588a46e032bd6d3a12bab04..963e263a81b4eb9b3c53bebdcab1d1064b6113db 100644
  1080. --- a/third_party/blink/renderer/core/editing/build.gni
  1081. +++ b/third_party/blink/renderer/core/editing/build.gni
  1082. @@ -356,10 +356,14 @@ blink_core_sources_editing = [
  1083. if (is_mac) {
  1084. blink_core_sources_editing += [
  1085. "commands/smart_replace_cf.cc",
  1086. - "kill_ring_mac.mm",
  1087. "substring_util.h",
  1088. "substring_util.mm",
  1089. ]
  1090. + if (is_mas_build) {
  1091. + blink_core_sources_editing += [ "kill_ring_mac.mm" ]
  1092. + } else {
  1093. + blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1094. + }
  1095. } else {
  1096. blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1097. }
  1098. diff --git a/ui/accelerated_widget_mac/BUILD.gn b/ui/accelerated_widget_mac/BUILD.gn
  1099. index 3ead42e14ad9d41a30c5637678a3ac49296ce2a6..8dec61ee6a62e54ec3c8c5dd5e08601c28d04dfe 100644
  1100. --- a/ui/accelerated_widget_mac/BUILD.gn
  1101. +++ b/ui/accelerated_widget_mac/BUILD.gn
  1102. @@ -33,6 +33,8 @@ component("accelerated_widget_mac") {
  1103. "QuartzCore.framework",
  1104. ]
  1105. + configs += ["//electron/build/config:mas_build"]
  1106. +
  1107. if (is_ios) {
  1108. sources += [ "ca_layer_frame_sink_provider.h" ]
  1109. }
  1110. diff --git a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1111. index b11c365f42dd1ddc363de0d94c387b13ac65bef3..c274340cac7aaf22321b9cd35a8fad2c6eeae5ce 100644
  1112. --- a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1113. +++ b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1114. @@ -14,7 +14,9 @@
  1115. #include "ui/gl/gl_surface.h"
  1116. #include "ui/gl/presenter.h"
  1117. +#if !IS_MAS_BUILD()
  1118. @class CAContext;
  1119. +#endif
  1120. @class CALayer;
  1121. namespace ui {
  1122. @@ -110,7 +112,9 @@ class ACCELERATED_WIDGET_MAC_EXPORT CALayerTreeCoordinator {
  1123. // both the current tree and the pending trees.
  1124. size_t presented_ca_layer_trees_max_length_ = 2;
  1125. +#if !IS_MAS_BUILD()
  1126. CAContext* __strong ca_context_;
  1127. +#endif
  1128. // The root CALayer to display the current frame. This does not change
  1129. // over the lifetime of the object.
  1130. diff --git a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1131. index b99461d52e3a62b58330691e65f9956748cfbf02..09abf39af3e7115744778c7260a68f13a080b162 100644
  1132. --- a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1133. +++ b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1134. @@ -33,6 +33,7 @@
  1135. new_presentation_feedback_timestamps_(
  1136. new_presentation_feedback_timestamps),
  1137. buffer_presented_callback_(buffer_presented_callback) {
  1138. +#if !IS_MAS_BUILD()
  1139. if (allow_remote_layers_) {
  1140. root_ca_layer_ = [[CALayer alloc] init];
  1141. #if BUILDFLAG(IS_MAC)
  1142. @@ -61,6 +62,7 @@
  1143. #endif
  1144. ca_context_.layer = root_ca_layer_;
  1145. }
  1146. +#endif
  1147. }
  1148. CALayerTreeCoordinator::~CALayerTreeCoordinator() = default;
  1149. @@ -164,9 +166,13 @@
  1150. TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD,
  1151. "GLImpl", static_cast<int>(gl::GetGLImplementation()),
  1152. "width", pixel_size_.width());
  1153. +#if !IS_MAS_BUILD()
  1154. if (allow_remote_layers_) {
  1155. params.ca_context_id = [ca_context_ contextId];
  1156. } else {
  1157. +#else
  1158. + if (true) {
  1159. +#endif
  1160. IOSurfaceRef io_surface = frame->layer_tree->GetContentIOSurface();
  1161. if (io_surface) {
  1162. DCHECK(!allow_remote_layers_);
  1163. diff --git a/ui/accelerated_widget_mac/display_ca_layer_tree.mm b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1164. index dcf493d62990018040a3f84b6f875af737bd2214..6ffffe8b3946e0427aead8be19878c537c841294 100644
  1165. --- a/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1166. +++ b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1167. @@ -121,6 +121,7 @@ - (void)setContentsChanged;
  1168. }
  1169. void DisplayCALayerTree::GotCALayerFrame(uint32_t ca_context_id) {
  1170. +#if !IS_MAS_BUILD()
  1171. // Early-out if the remote layer has not changed.
  1172. if (remote_layer_.contextId == ca_context_id) {
  1173. return;
  1174. @@ -150,6 +151,9 @@ - (void)setContentsChanged;
  1175. [io_surface_layer_ removeFromSuperlayer];
  1176. io_surface_layer_ = nil;
  1177. }
  1178. +#else
  1179. + NOTREACHED() << "Remote layer is being used in MAS build";
  1180. +#endif
  1181. }
  1182. void DisplayCALayerTree::GotIOSurfaceFrame(
  1183. diff --git a/ui/accessibility/platform/BUILD.gn b/ui/accessibility/platform/BUILD.gn
  1184. index 2e24201fcdc1ec65688e2b08d28a74a218792af2..53b399c13c344b72992b9433add202ed6aa1c558 100644
  1185. --- a/ui/accessibility/platform/BUILD.gn
  1186. +++ b/ui/accessibility/platform/BUILD.gn
  1187. @@ -282,6 +282,7 @@ component("platform") {
  1188. "AppKit.framework",
  1189. "Foundation.framework",
  1190. ]
  1191. + configs += ["//electron/build/config:mas_build"]
  1192. }
  1193. if (is_ios) {
  1194. diff --git a/ui/accessibility/platform/browser_accessibility_manager_mac.mm b/ui/accessibility/platform/browser_accessibility_manager_mac.mm
  1195. index be442f6a2a67d07ec78fe00a3e864bf0088fe504..3a8c8a3900db26b10f2b7735b860d8935d2a6085 100644
  1196. --- a/ui/accessibility/platform/browser_accessibility_manager_mac.mm
  1197. +++ b/ui/accessibility/platform/browser_accessibility_manager_mac.mm
  1198. @@ -19,7 +19,9 @@
  1199. #include "ui/accessibility/platform/ax_private_webkit_constants_mac.h"
  1200. #import "ui/accessibility/platform/browser_accessibility_cocoa.h"
  1201. #import "ui/accessibility/platform/browser_accessibility_mac.h"
  1202. +#if !IS_MAS_BUILD()
  1203. #include "ui/base/cocoa/remote_accessibility_api.h"
  1204. +#endif
  1205. namespace {
  1206. @@ -227,6 +229,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1207. return;
  1208. }
  1209. +#if !IS_MAS_BUILD()
  1210. BrowserAccessibilityManager* root_manager = GetManagerForRootFrame();
  1211. if (root_manager) {
  1212. BrowserAccessibilityManagerMac* root_manager_mac =
  1213. @@ -249,6 +252,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1214. return;
  1215. }
  1216. }
  1217. +#endif
  1218. // Use native VoiceOver support for live regions.
  1219. BrowserAccessibilityCocoa* retained_node = native_node;
  1220. @@ -645,6 +649,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1221. return window == [NSApp accessibilityFocusedWindow];
  1222. }
  1223. +#if !IS_MAS_BUILD()
  1224. // TODO(accessibility): We need a solution to the problem described below.
  1225. // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
  1226. // 1. NSApp is the browser which spawned the PWA, and what it considers the
  1227. @@ -673,6 +678,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1228. if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]]) {
  1229. return true;
  1230. }
  1231. +#endif
  1232. return false;
  1233. }
  1234. diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.mm b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1235. index c8171f0527fe5194f0ea73b57c4444d4c630fbc4..7fa66598f2a541600602af47b3e1ed7b5d4463ee 100644
  1236. --- a/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1237. +++ b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1238. @@ -111,6 +111,7 @@
  1239. }
  1240. }
  1241. +#if !IS_MAS_BUILD()
  1242. // AXTextMarker
  1243. if (IsAXTextMarker(value)) {
  1244. return AXTextMarkerToBaseValue(value, indexer);
  1245. @@ -120,6 +121,7 @@
  1246. if (IsAXTextMarkerRange(value)) {
  1247. return AXTextMarkerRangeToBaseValue(value, indexer);
  1248. }
  1249. +#endif
  1250. // Accessible object
  1251. if (AXElementWrapper::IsValidElement(value)) {
  1252. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  1253. index 79937bebda1b3405a8acbf1559ebd994a3f7bf0b..e2838e81e56988c2c0b66556aa62b585c199618c 100644
  1254. --- a/ui/base/BUILD.gn
  1255. +++ b/ui/base/BUILD.gn
  1256. @@ -367,6 +367,7 @@ component("base") {
  1257. "interaction/element_tracker_mac.mm",
  1258. "resource/resource_bundle_mac.mm",
  1259. ]
  1260. + configs += ["//electron/build/config:mas_build"]
  1261. }
  1262. if (is_apple) {
  1263. @@ -384,6 +385,13 @@ component("base") {
  1264. sources += [ "resource/resource_bundle_lacros.cc" ]
  1265. }
  1266. + if (is_mas_build) {
  1267. + sources -= [
  1268. + "cocoa/remote_accessibility_api.h",
  1269. + "cocoa/remote_accessibility_api.mm",
  1270. + ]
  1271. + }
  1272. +
  1273. if (is_ios) {
  1274. sources += [
  1275. "device_form_factor_ios.mm",
  1276. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  1277. index 3182458838aa96d34911280ab4c6c3aa4aa22d6d..17b57f54492421743a0d69106eefce2c9beb8e87 100644
  1278. --- a/ui/base/cocoa/remote_accessibility_api.h
  1279. +++ b/ui/base/cocoa/remote_accessibility_api.h
  1280. @@ -13,6 +13,8 @@
  1281. // NSAccessibilityRemoteUIElement is a private class in AppKit.
  1282. +#if !IS_MAS_BUILD()
  1283. +
  1284. @interface NSAccessibilityRemoteUIElement : NSObject
  1285. + (void)setRemoteUIApp:(BOOL)flag;
  1286. + (BOOL)isRemoteUIApp;
  1287. @@ -38,4 +40,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  1288. } // namespace ui
  1289. +#endif // MAS_BUILD
  1290. +
  1291. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  1292. diff --git a/ui/base/cocoa/remote_layer_api.h b/ui/base/cocoa/remote_layer_api.h
  1293. index 59dc2f82214cfd883b6ebef3b0fb25af6387a9cd..d585ba14b34021a93c878d0d9f9d9ef70eed32ca 100644
  1294. --- a/ui/base/cocoa/remote_layer_api.h
  1295. +++ b/ui/base/cocoa/remote_layer_api.h
  1296. @@ -17,6 +17,7 @@
  1297. #if BUILDFLAG(IS_MAC)
  1298. +#if !IS_MAS_BUILD()
  1299. // The CGSConnectionID is used to create the CAContext in the process that is
  1300. // going to share the CALayers that it is rendering to another process to
  1301. // display.
  1302. @@ -68,6 +69,8 @@ extern NSString* const kCAContextIgnoresHitTest;
  1303. #endif // __OBJC__
  1304. +#endif // MAS_BUILD
  1305. +
  1306. namespace ui {
  1307. // This function will check if all of the interfaces listed above are supported
  1308. diff --git a/ui/base/cocoa/remote_layer_api.mm b/ui/base/cocoa/remote_layer_api.mm
  1309. index fc25ba79d2b0e1acdb7ba54b89e7d6e16f94771b..962df2d65d61ec0836cf465d847eb666033846f2 100644
  1310. --- a/ui/base/cocoa/remote_layer_api.mm
  1311. +++ b/ui/base/cocoa/remote_layer_api.mm
  1312. @@ -10,6 +10,7 @@
  1313. namespace ui {
  1314. +#if !IS_MAS_BUILD()
  1315. namespace {
  1316. // Control use of cross-process CALayers to display content directly from the
  1317. // GPU process on Mac.
  1318. @@ -17,8 +18,10 @@
  1319. "RemoteCoreAnimationAPI",
  1320. base::FEATURE_ENABLED_BY_DEFAULT);
  1321. } // namespace
  1322. +#endif
  1323. bool RemoteLayerAPISupported() {
  1324. +#if !IS_MAS_BUILD()
  1325. if (!base::FeatureList::IsEnabled(kRemoteCoreAnimationAPI))
  1326. return false;
  1327. @@ -55,6 +58,9 @@ bool RemoteLayerAPISupported() {
  1328. // If everything is there, we should be able to use the API.
  1329. return true;
  1330. +#else
  1331. + return false;
  1332. +#endif // MAS_BUILD
  1333. }
  1334. } // namespace
  1335. diff --git a/ui/display/BUILD.gn b/ui/display/BUILD.gn
  1336. index 84afacf999c4905fdbaba332e19058a6471c3436..1c5419258c92454e3637fc2d6f9e443edccf7c03 100644
  1337. --- a/ui/display/BUILD.gn
  1338. +++ b/ui/display/BUILD.gn
  1339. @@ -74,6 +74,10 @@ component("display") {
  1340. "mac/display_link_mac.mm",
  1341. "mac/screen_mac.mm",
  1342. ]
  1343. +
  1344. + configs += [
  1345. + "//electron/build/config:mas_build"
  1346. + ]
  1347. }
  1348. if (is_win) {
  1349. diff --git a/ui/display/mac/screen_mac.mm b/ui/display/mac/screen_mac.mm
  1350. index 35b71abc95f83bb01dba3f69e2d69a026840b7a2..f9d556e6b221d17035cd9e8d1f5620c52f3fb744 100644
  1351. --- a/ui/display/mac/screen_mac.mm
  1352. +++ b/ui/display/mac/screen_mac.mm
  1353. @@ -176,7 +176,17 @@ DisplayMac BuildDisplayForScreen(NSScreen* screen) {
  1354. display.set_color_depth(Display::kDefaultBitsPerPixel);
  1355. display.set_depth_per_component(Display::kDefaultBitsPerComponent);
  1356. }
  1357. +#if IS_MAS_BUILD()
  1358. + // This is equivalent to the CGDisplayUsesForceToGray() API as at 2018-08-06,
  1359. + // but avoids usage of the private API.
  1360. + CFStringRef app = CFSTR("com.apple.CoreGraphics");
  1361. + CFStringRef key = CFSTR("DisplayUseForcedGray");
  1362. + Boolean key_valid = false;
  1363. + display.set_is_monochrome(
  1364. + CFPreferencesGetAppBooleanValue(key, app, &key_valid));
  1365. +#else
  1366. display.set_is_monochrome(CGDisplayUsesForceToGray());
  1367. +#endif
  1368. // Query the display's refresh rate.
  1369. if (@available(macos 12.0, *)) {
  1370. diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
  1371. index c0a85b2cfc69a4f358ae03c65e774cdc45085bf6..05d6796e28093d5e970e3edb36fc02d5ceded0f8 100644
  1372. --- a/ui/gfx/BUILD.gn
  1373. +++ b/ui/gfx/BUILD.gn
  1374. @@ -204,6 +204,7 @@ component("gfx") {
  1375. "scoped_ns_graphics_context_save_gstate_mac.h",
  1376. "scoped_ns_graphics_context_save_gstate_mac.mm",
  1377. ]
  1378. + configs += ["//electron/build/config:mas_build"]
  1379. }
  1380. if (is_win) {
  1381. sources += [
  1382. diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm
  1383. index fe3f85073e31de487a08e57d7f9b07aa4eccf8f3..12d329eb172d4ab5108576460b1d3089249a88dd 100644
  1384. --- a/ui/gfx/platform_font_mac.mm
  1385. +++ b/ui/gfx/platform_font_mac.mm
  1386. @@ -28,9 +28,11 @@
  1387. using Weight = Font::Weight;
  1388. +#if !IS_MAS_BUILD()
  1389. extern "C" {
  1390. bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
  1391. }
  1392. +#endif
  1393. namespace {
  1394. @@ -250,7 +252,13 @@ CTFontRef SystemFontForConstructorOfType(
  1395. // TODO(avi, etienneb): Figure out this font stuff.
  1396. base::apple::ScopedCFTypeRef<CTFontDescriptorRef> descriptor(
  1397. CTFontCopyFontDescriptor(font));
  1398. +#if IS_MAS_BUILD()
  1399. + CFNumberRef priority = (CFNumberRef)CTFontDescriptorCopyAttribute(descriptor.get(), (CFStringRef)kCTFontPriorityAttribute);
  1400. + SInt64 v;
  1401. + if (CFNumberGetValue(priority, kCFNumberSInt64Type, &v) && v == kCTFontPrioritySystem) {
  1402. +#else
  1403. if (CTFontDescriptorIsSystemUIFont(descriptor.get())) {
  1404. +#endif
  1405. // Assume it's the standard system font. The fact that this much is known is
  1406. // enough.
  1407. return PlatformFontMac::SystemFontType::kGeneral;
  1408. diff --git a/ui/views/BUILD.gn b/ui/views/BUILD.gn
  1409. index b2b1a783ac0c243ef5cf573b2e73af82b432fbf9..1b43204b8ce15b9cc4cbf6c5a3d6853ab5da0858 100644
  1410. --- a/ui/views/BUILD.gn
  1411. +++ b/ui/views/BUILD.gn
  1412. @@ -722,6 +722,7 @@ component("views") {
  1413. "IOSurface.framework",
  1414. "QuartzCore.framework",
  1415. ]
  1416. + configs += ["//electron/build/config:mas_build"]
  1417. }
  1418. if (is_win) {
  1419. @@ -1154,6 +1155,8 @@ source_set("test_support") {
  1420. "//ui/base/mojom:mojom",
  1421. ]
  1422. + configs += ["//electron/build/config:mas_build"]
  1423. +
  1424. if (is_win) {
  1425. sources += [
  1426. "test/desktop_window_tree_host_win_test_api.cc",
  1427. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1428. index 81979cdb6c5dbad84ea67ef9014ce4027bcdc161..09fedd988397d0825a12b1e0b565d41e466c8e2e 100644
  1429. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1430. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1431. @@ -32,7 +32,9 @@
  1432. #include "ui/views/window/dialog_observer.h"
  1433. @class NativeWidgetMacNSWindow;
  1434. +#if !IS_MAS_BUILD()
  1435. @class NSAccessibilityRemoteUIElement;
  1436. +#endif
  1437. @class NSView;
  1438. namespace remote_cocoa {
  1439. @@ -483,10 +485,12 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  1440. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  1441. remote_ns_window_remote_;
  1442. +#if !IS_MAS_BUILD()
  1443. // Remote accessibility objects corresponding to the NSWindow and its root
  1444. // NSView.
  1445. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  1446. NSAccessibilityRemoteUIElement* __strong remote_view_accessible_;
  1447. +#endif
  1448. // Used to force the NSApplication's focused accessibility element to be the
  1449. // views::Views accessibility tree when the NSView for this is focused.
  1450. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1451. index 9a915cb0c36b224b8b95fa84bc1909de4283776f..5f84e8a68b8a5cdcebe272a79b96f7641aa8bd57 100644
  1452. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1453. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1454. @@ -349,7 +349,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1455. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  1456. if (in_process_ns_window_bridge_)
  1457. return in_process_ns_window_bridge_->ns_view();
  1458. +#if !IS_MAS_BUILD()
  1459. return remote_view_accessible_;
  1460. +#else
  1461. + return nullptr;
  1462. +#endif
  1463. }
  1464. gfx::NativeViewAccessible
  1465. @@ -364,7 +368,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1466. return [in_process_ns_window_bridge_->ns_view() window];
  1467. }
  1468. +#if !IS_MAS_BUILD()
  1469. return remote_window_accessible_;
  1470. +#else
  1471. + return nullptr;
  1472. +#endif
  1473. }
  1474. remote_cocoa::mojom::NativeWidgetNSWindow*
  1475. @@ -1333,9 +1341,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1476. // for PWAs. However this breaks accessibility on in-process windows,
  1477. // so set it back to NO when a local window gains focus. See
  1478. // https://crbug.com/41485830.
  1479. +#if !IS_MAS_BUILD()
  1480. if (is_key && features::IsAccessibilityRemoteUIAppEnabled()) {
  1481. [NSAccessibilityRemoteUIElement setRemoteUIApp:!!application_host_];
  1482. }
  1483. +#endif
  1484. // Explicitly set the keyboard accessibility state on regaining key
  1485. // window status.
  1486. if (is_key && is_content_first_responder)
  1487. @@ -1474,17 +1484,20 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1488. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  1489. const std::vector<uint8_t>& window_token,
  1490. const std::vector<uint8_t>& view_token) {
  1491. +#if !IS_MAS_BUILD()
  1492. remote_window_accessible_ =
  1493. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  1494. remote_view_accessible_ =
  1495. ui::RemoteAccessibility::GetRemoteElementFromToken(view_token);
  1496. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_];
  1497. [remote_view_accessible_ setTopLevelUIElement:remote_window_accessible_];
  1498. +#endif
  1499. }
  1500. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  1501. base::ProcessId* pid,
  1502. std::vector<uint8_t>* token) {
  1503. +#if !IS_MAS_BUILD()
  1504. *pid = getpid();
  1505. id element_id = GetNativeViewAccessible();
  1506. @@ -1497,6 +1510,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1507. }
  1508. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  1509. +#endif
  1510. return true;
  1511. }
  1512. diff --git a/ui/views/controls/webview/BUILD.gn b/ui/views/controls/webview/BUILD.gn
  1513. index 111d6432586f47833dde50678b908c76ad88d37a..45601d06f85ba618fe38c96ae28c47d306784e53 100644
  1514. --- a/ui/views/controls/webview/BUILD.gn
  1515. +++ b/ui/views/controls/webview/BUILD.gn
  1516. @@ -19,6 +19,9 @@ component("webview") {
  1517. if (is_mac) {
  1518. sources += [ "unhandled_keyboard_event_handler_mac.mm" ]
  1519. + configs += [
  1520. + "//electron/build/config:mas_build",
  1521. + ]
  1522. }
  1523. if (is_win) {