mas_avoid_private_macos_api_usage.patch.patch 60 KB

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