mas_avoid_private_macos_api_usage.patch.patch 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  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 0eb84c31ebbda5e7e842cd0f0df5ff2a15048178..c2fa88ac47c846ad94494660453891b0e38b33e3 100644
  36. --- a/base/BUILD.gn
  37. +++ b/base/BUILD.gn
  38. @@ -1040,6 +1040,7 @@ component("base") {
  39. "//build:ios_buildflags",
  40. "//build/config/compiler:compiler_buildflags",
  41. "//third_party/modp_b64",
  42. + "//electron/build/config:generate_mas_config",
  43. ]
  44. if (!is_nacl) {
  45. # Used by metrics/crc32, except on NaCl builds.
  46. diff --git a/base/enterprise_util_mac.mm b/base/enterprise_util_mac.mm
  47. index 4bf9a3c27e05c6635b2beb8e880b5b43dbed61b5..f328fbb49c45991f44a9c75325491d0873746b61 100644
  48. --- a/base/enterprise_util_mac.mm
  49. +++ b/base/enterprise_util_mac.mm
  50. @@ -16,6 +16,7 @@
  51. #include "base/strings/string_split.h"
  52. #include "base/strings/string_util.h"
  53. #include "base/strings/sys_string_conversions.h"
  54. +#include "electron/mas.h"
  55. namespace base {
  56. @@ -116,6 +117,14 @@ DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
  57. DeviceUserDomainJoinState state{.device_joined = false,
  58. .user_joined = false};
  59. +#if IS_MAS_BUILD()
  60. + return state;
  61. + }();
  62. +
  63. + return state;
  64. +}
  65. +#else
  66. +
  67. @autoreleasepool {
  68. ODSession* session = [ODSession defaultSession];
  69. if (session == nil) {
  70. @@ -219,5 +228,6 @@ DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
  71. return state;
  72. }
  73. +#endif
  74. } // namespace base
  75. diff --git a/base/process/launch_mac.cc b/base/process/launch_mac.cc
  76. index 697eff8aad0142ce0537feec816f9b31fd767061..504a3cba21622b8d79bf6563f3a009c47b093d50 100644
  77. --- a/base/process/launch_mac.cc
  78. +++ b/base/process/launch_mac.cc
  79. @@ -21,13 +21,19 @@
  80. #include "base/threading/scoped_blocking_call.h"
  81. #include "base/threading/thread_restrictions.h"
  82. #include "base/trace_event/base_tracing.h"
  83. +#include "electron/mas.h"
  84. +#if IS_MAS_BUILD()
  85. +#include <sys/syscall.h>
  86. +#endif
  87. extern "C" {
  88. // Changes the current thread's directory to a path or directory file
  89. // descriptor.
  90. +#if !IS_MAS_BUILD()
  91. int pthread_chdir_np(const char* dir);
  92. int pthread_fchdir_np(int fd);
  93. +#endif
  94. int responsibility_spawnattrs_setdisclaim(posix_spawnattr_t attrs,
  95. int disclaim);
  96. @@ -104,13 +110,27 @@ class PosixSpawnFileActions {
  97. #if !BUILDFLAG(IS_MAC)
  98. int ChangeCurrentThreadDirectory(const char* path) {
  99. +#if IS_MAS_BUILD()
  100. + #pragma clang diagnostic push
  101. + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  102. + return syscall(SYS___pthread_chdir, path);
  103. + #pragma clang diagnostic pop
  104. +#else
  105. return pthread_chdir_np(path);
  106. +#endif
  107. }
  108. // The recommended way to unset a per-thread cwd is to set a new value to an
  109. // invalid file descriptor, per libpthread-218.1.3/private/private.h.
  110. int ResetCurrentThreadDirectory() {
  111. +#if IS_MAS_BUILD()
  112. + #pragma clang diagnostic push
  113. + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  114. + return syscall(SYS___pthread_fchdir, -1);
  115. + #pragma clang diagnostic pop
  116. +#else
  117. return pthread_fchdir_np(-1);
  118. +#endif
  119. }
  120. #endif
  121. @@ -234,7 +254,7 @@ Process LaunchProcess(const std::vector<std::string>& argv,
  122. file_actions.Inherit(STDERR_FILENO);
  123. }
  124. -#if BUILDFLAG(IS_MAC)
  125. +#if 0
  126. if (options.disclaim_responsibility) {
  127. DPSXCHECK(responsibility_spawnattrs_setdisclaim(attr.get(), 1));
  128. }
  129. diff --git a/base/process/process_info_mac.cc b/base/process/process_info_mac.cc
  130. index 94a028be3c315edc0056408ab9ab41b6b001a1c1..abf9003bc71506d389ff77dc708c897113bba412 100644
  131. --- a/base/process/process_info_mac.cc
  132. +++ b/base/process/process_info_mac.cc
  133. @@ -4,19 +4,27 @@
  134. #include "base/process/process_info.h"
  135. +#include "electron/mas.h"
  136. +
  137. #include <stdio.h>
  138. #include <stdlib.h>
  139. #include <unistd.h>
  140. +#if !IS_MAS_BUILD()
  141. extern "C" {
  142. pid_t responsibility_get_pid_responsible_for_pid(pid_t);
  143. }
  144. +#endif
  145. namespace base {
  146. bool IsProcessSelfResponsible() {
  147. +#if !IS_MAS_BUILD()
  148. const pid_t pid = getpid();
  149. return responsibility_get_pid_responsible_for_pid(pid) == pid;
  150. +#else
  151. + return true;
  152. +#endif
  153. }
  154. } // namespace base
  155. diff --git a/components/os_crypt/sync/BUILD.gn b/components/os_crypt/sync/BUILD.gn
  156. index 3b81e00e1535ec729a521b83fe2471985d177e5c..094f52fd80bd91be4e705a457d12ea89271dc037 100644
  157. --- a/components/os_crypt/sync/BUILD.gn
  158. +++ b/components/os_crypt/sync/BUILD.gn
  159. @@ -46,6 +46,7 @@ component("os_crypt") {
  160. "os_crypt_mac.mm",
  161. ]
  162. deps += [ "//crypto:mock_apple_keychain" ]
  163. + deps += ["//electron/build/config:generate_mas_config"]
  164. }
  165. if (is_win) {
  166. diff --git a/components/os_crypt/sync/keychain_password_mac.mm b/components/os_crypt/sync/keychain_password_mac.mm
  167. index e7a65e97b51d93bff864889813317fb7c6ffc846..bb1fc0c99164ae4bdaaaa78e87c30e88932a928c 100644
  168. --- a/components/os_crypt/sync/keychain_password_mac.mm
  169. +++ b/components/os_crypt/sync/keychain_password_mac.mm
  170. @@ -13,6 +13,7 @@
  171. #include "base/rand_util.h"
  172. #include "build/branding_buildflags.h"
  173. #include "crypto/apple_keychain.h"
  174. +#include "electron/mas.h"
  175. using crypto::AppleKeychain;
  176. diff --git a/components/remote_cocoa/app_shim/BUILD.gn b/components/remote_cocoa/app_shim/BUILD.gn
  177. index da8b246916811fbee1e63d0aa95be9fa3ae12bfb..3bcd78507a15bb12ffe71a5f67e756000ca2633a 100644
  178. --- a/components/remote_cocoa/app_shim/BUILD.gn
  179. +++ b/components/remote_cocoa/app_shim/BUILD.gn
  180. @@ -75,6 +75,7 @@ component("app_shim") {
  181. "//components/crash/core/common",
  182. "//components/remote_cocoa/common:mojo",
  183. "//components/system_media_controls",
  184. + "//electron/build/config:generate_mas_config",
  185. "//mojo/public/cpp/bindings",
  186. "//net",
  187. "//ui/accelerated_widget_mac",
  188. diff --git a/components/remote_cocoa/app_shim/application_bridge.mm b/components/remote_cocoa/app_shim/application_bridge.mm
  189. index e9f4e5131238b9fb5f1b4b3e90a0cb84a7fc15b4..8b5f4cae3123ac5480ad73f0c873fca0d62f7c9f 100644
  190. --- a/components/remote_cocoa/app_shim/application_bridge.mm
  191. +++ b/components/remote_cocoa/app_shim/application_bridge.mm
  192. @@ -12,6 +12,7 @@
  193. #include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
  194. #include "components/remote_cocoa/app_shim/native_widget_ns_window_host_helper.h"
  195. #include "components/system_media_controls/mac/remote_cocoa/system_media_controls_bridge.h"
  196. +#include "electron/mas.h"
  197. #include "mojo/public/cpp/bindings/associated_remote.h"
  198. #include "mojo/public/cpp/bindings/self_owned_receiver.h"
  199. #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
  200. @@ -51,6 +52,7 @@
  201. // NativeWidgetNSWindowHostHelper:
  202. id GetNativeViewAccessible() override {
  203. +#if !IS_MAS_BUILD()
  204. if (!remote_accessibility_element_) {
  205. base::ProcessId browser_pid = base::kNullProcessId;
  206. std::vector<uint8_t> element_token;
  207. @@ -61,6 +63,9 @@ id GetNativeViewAccessible() override {
  208. ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
  209. }
  210. return remote_accessibility_element_;
  211. +#else
  212. + return nil;
  213. +#endif
  214. }
  215. void DispatchKeyEvent(ui::KeyEvent* event) override {
  216. bool event_handled = false;
  217. @@ -99,7 +104,9 @@ void GetWordAt(const gfx::Point& location_in_content,
  218. mojo::AssociatedRemote<mojom::TextInputHost> text_input_host_remote_;
  219. std::unique_ptr<NativeWidgetNSWindowBridge> bridge_;
  220. +#if !IS_MAS_BUILD()
  221. NSAccessibilityRemoteUIElement* __strong remote_accessibility_element_;
  222. +#endif
  223. };
  224. } // namespace
  225. 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
  226. index 1db1e7fc1d86bbca432a4226a24a312cf0b989f8..c4192c16299d291df259902ef8497a65776e3189 100644
  227. --- a/components/remote_cocoa/app_shim/browser_native_widget_window_mac.mm
  228. +++ b/components/remote_cocoa/app_shim/browser_native_widget_window_mac.mm
  229. @@ -8,7 +8,9 @@
  230. #include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
  231. #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
  232. +#include "electron/mas.h"
  233. +#if !IS_MAS_BUILD()
  234. @interface NSWindow (PrivateBrowserNativeWidgetAPI)
  235. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
  236. @end
  237. @@ -95,10 +97,13 @@ - (void)maybeShowTrafficLights {
  238. @end
  239. +#endif // MAS_BUILD
  240. +
  241. @implementation BrowserNativeWidgetWindow
  242. // NSWindow (PrivateAPI) overrides.
  243. +#if !IS_MAS_BUILD()
  244. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
  245. // - NSThemeFrame and its subclasses will be nil if it's missing at runtime.
  246. if ([BrowserWindowFrame class])
  247. @@ -145,6 +150,8 @@ - (BOOL)_usesCustomDrawing {
  248. return NO;
  249. }
  250. +#endif // MAS_BUILD
  251. +
  252. // Handle "Move focus to the window toolbar" configured in System Preferences ->
  253. // Keyboard -> Shortcuts -> Keyboard. Usually Ctrl+F5. The argument (|unknown|)
  254. // tends to just be nil.
  255. @@ -155,8 +162,8 @@ - (void)_handleFocusToolbarHotKey:(id)unknown {
  256. }
  257. - (void)setAlwaysShowTrafficLights:(BOOL)alwaysShow {
  258. - [base::apple::ObjCCastStrict<BrowserWindowFrame>(self.contentView.superview)
  259. - setAlwaysShowTrafficLights:alwaysShow];
  260. + // [base::apple::ObjCCastStrict<BrowserWindowFrame>(self.contentView.superview)
  261. + // setAlwaysShowTrafficLights:alwaysShow];
  262. }
  263. @end
  264. 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
  265. index 3a815ebf505bd95fa7f6b61ba433d98fbfe20225..149de0175c2ec0e41e3ba40caad7019ca87386d6 100644
  266. --- a/components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.mm
  267. +++ b/components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.mm
  268. @@ -4,6 +4,10 @@
  269. #import "components/remote_cocoa/app_shim/native_widget_mac_frameless_nswindow.h"
  270. +#include "electron/mas.h"
  271. +
  272. +#if !IS_MAS_BUILD()
  273. +
  274. @interface NSWindow (PrivateAPI)
  275. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
  276. @end
  277. @@ -18,8 +22,12 @@ - (CGFloat)_titlebarHeight {
  278. }
  279. @end
  280. +#endif // MAS_BUILD
  281. +
  282. @implementation NativeWidgetMacFramelessNSWindow
  283. +#if !IS_MAS_BUILD()
  284. +
  285. + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
  286. if ([NativeWidgetMacFramelessNSWindowFrame class]) {
  287. return [NativeWidgetMacFramelessNSWindowFrame class];
  288. @@ -27,4 +35,6 @@ + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
  289. return [super frameViewClassForStyleMask:windowStyle];
  290. }
  291. +#endif // MAS_BUILD
  292. +
  293. @end
  294. diff --git a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h
  295. index 945b01f2132547fa0f6a97ee4895994c500d1410..864f93f7c4159abc63e1535195fbf9d112558b91 100644
  296. --- a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h
  297. +++ b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.h
  298. @@ -9,6 +9,7 @@
  299. #include "base/apple/foundation_util.h"
  300. #include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h"
  301. +#include "electron/mas.h"
  302. #import "ui/base/cocoa/command_dispatcher.h"
  303. namespace remote_cocoa {
  304. @@ -17,6 +18,7 @@ class NativeWidgetNSWindowBridge;
  305. @protocol WindowTouchBarDelegate;
  306. +#if !IS_MAS_BUILD()
  307. // Weak lets Chrome launch even if a future macOS doesn't have the below classes
  308. WEAK_IMPORT_ATTRIBUTE
  309. @interface NSNextStepFrame : NSView
  310. @@ -33,6 +35,7 @@ REMOTE_COCOA_APP_SHIM_EXPORT
  311. REMOTE_COCOA_APP_SHIM_EXPORT
  312. @interface NativeWidgetMacNSWindowTitledFrame : NSThemeFrame
  313. @end
  314. +#endif
  315. // The NSWindow used by BridgedNativeWidget. Provides hooks into AppKit that
  316. // can only be accomplished by overriding methods.
  317. diff --git a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
  318. index 4f875587289f19b06041c5e8a7f76ab9cba169c9..952febab99656f59efee8c0d267d8f76f9943197 100644
  319. --- a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
  320. +++ b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
  321. @@ -26,6 +26,7 @@
  322. #import "components/remote_cocoa/app_shim/views_nswindow_delegate.h"
  323. #import "components/remote_cocoa/app_shim/window_touch_bar_delegate.h"
  324. #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
  325. +#include "electron/mas.h"
  326. #import "ui/base/cocoa/user_interface_item_command_handler.h"
  327. #import "ui/base/cocoa/window_size_constants.h"
  328. @@ -111,14 +112,18 @@ void OrderChildWindow(NSWindow* child_window,
  329. } // namespace
  330. +#if !IS_MAS_BUILD()
  331. @interface NSNextStepFrame (Private)
  332. - (instancetype)initWithFrame:(NSRect)frame
  333. styleMask:(NSUInteger)styleMask
  334. owner:(id)owner;
  335. @end
  336. +#endif
  337. @interface NSWindow (Private)
  338. +#if !IS_MAS_BUILD()
  339. + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle;
  340. +#endif
  341. - (BOOL)hasKeyAppearance;
  342. - (long long)_resizeDirectionForMouseLocation:(CGPoint)location;
  343. - (BOOL)_isConsideredOpenForPersistentState;
  344. @@ -157,6 +162,8 @@ - (void)cr_mouseDownOnFrameView:(NSEvent*)event {
  345. }
  346. @end
  347. +#if !IS_MAS_BUILD()
  348. +
  349. @implementation NativeWidgetMacNSWindowTitledFrame
  350. - (void)mouseDown:(NSEvent*)event {
  351. if (self.window.isMovable)
  352. @@ -184,6 +191,8 @@ - (BOOL)usesCustomDrawing {
  353. }
  354. @end
  355. +#endif // MAS_BUILD
  356. +
  357. @implementation NativeWidgetMacNSWindow {
  358. @private
  359. CommandDispatcher* __strong _commandDispatcher;
  360. @@ -380,6 +389,8 @@ - (NSAccessibilityRole)accessibilityRole {
  361. // NSWindow overrides.
  362. +#if !IS_MAS_BUILD()
  363. +
  364. + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
  365. if (windowStyle & NSWindowStyleMaskTitled) {
  366. if (Class customFrame = [NativeWidgetMacNSWindowTitledFrame class])
  367. @@ -391,6 +402,8 @@ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
  368. return [super frameViewClassForStyleMask:windowStyle];
  369. }
  370. +#endif
  371. +
  372. - (BOOL)_isTitleHidden {
  373. bool shouldShowWindowTitle = YES;
  374. if (_bridge)
  375. 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
  376. index f71ea08f64ab5cd36f6bd1e2d3d2908d4de80ba6..4b3450b3bd44a35964bd935453861101f999a53a 100644
  377. --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  378. +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  379. @@ -41,6 +41,7 @@
  380. #import "components/remote_cocoa/app_shim/views_nswindow_delegate.h"
  381. #import "components/remote_cocoa/app_shim/window_move_loop.h"
  382. #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
  383. +#include "electron/mas.h"
  384. #include "mojo/public/cpp/bindings/self_owned_receiver.h"
  385. #include "net/cert/x509_util_apple.h"
  386. #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
  387. @@ -643,10 +644,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
  388. // this should be treated as an error and caught early.
  389. CHECK(bridged_view_);
  390. +#if !IS_MAS_BUILD()
  391. // Send the accessibility tokens for the NSView now that it exists.
  392. host_->SetRemoteAccessibilityTokens(
  393. ui::RemoteAccessibility::GetTokenForLocalElement(window_),
  394. ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
  395. +#endif
  396. // Beware: This view was briefly removed (in favor of a bare CALayer) in
  397. // https://crrev.com/c/1236675. The ordering of unassociated layers relative
  398. diff --git a/components/viz/service/BUILD.gn b/components/viz/service/BUILD.gn
  399. index 4687c5e66f2176cc408b474e4d1e67f7dbf51669..dddf398085d2902b4b1e6e00cb90ccecc238a672 100644
  400. --- a/components/viz/service/BUILD.gn
  401. +++ b/components/viz/service/BUILD.gn
  402. @@ -378,6 +378,7 @@ viz_component("service") {
  403. "frame_sinks/external_begin_frame_source_mac.h",
  404. ]
  405. }
  406. + deps += ["//electron/build/config:generate_mas_config"]
  407. }
  408. if (is_android || use_ozone) {
  409. @@ -660,6 +661,7 @@ viz_source_set("unit_tests") {
  410. "display_embedder/software_output_device_mac_unittest.mm",
  411. ]
  412. frameworks = [ "IOSurface.framework" ]
  413. + deps += ["//electron/build/config:generate_mas_config"]
  414. }
  415. if (is_win) {
  416. 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
  417. index dbf334caa3a6d10017b69ad76802e389a011436b..da828823e8195cc9e497866363c9af93dcd4ec3f 100644
  418. --- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  419. +++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  420. @@ -15,6 +15,7 @@
  421. #include "content/common/web_contents_ns_view_bridge.mojom.h"
  422. #include "content/public/browser/remote_cocoa.h"
  423. #include "content/public/browser/render_widget_host_view_mac_delegate.h"
  424. +#include "electron/mas.h"
  425. #include "mojo/public/cpp/bindings/associated_receiver.h"
  426. #include "mojo/public/cpp/bindings/associated_remote.h"
  427. #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
  428. @@ -63,7 +64,9 @@ explicit RenderWidgetHostNSViewBridgeOwner(
  429. const RenderWidgetHostNSViewBridgeOwner&) = delete;
  430. private:
  431. +#if !IS_MAS_BUILD()
  432. NSAccessibilityRemoteUIElement* __strong remote_accessibility_element_;
  433. +#endif
  434. void OnMojoDisconnect() { delete this; }
  435. std::unique_ptr<blink::WebCoalescedInputEvent> TranslateEvent(
  436. @@ -75,6 +78,7 @@ explicit RenderWidgetHostNSViewBridgeOwner(
  437. }
  438. id GetAccessibilityElement() override {
  439. +#if !IS_MAS_BUILD()
  440. if (!remote_accessibility_element_) {
  441. base::ProcessId browser_pid = base::kNullProcessId;
  442. std::vector<uint8_t> element_token;
  443. @@ -85,6 +89,9 @@ id GetAccessibilityElement() override {
  444. ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
  445. }
  446. return remote_accessibility_element_;
  447. +#else
  448. + return nil;
  449. +#endif
  450. }
  451. // RenderWidgetHostNSViewHostHelper implementation.
  452. @@ -103,8 +110,10 @@ id GetFocusedBrowserAccessibilityElement() override {
  453. return [bridgedContentView accessibilityFocusedUIElement];
  454. }
  455. void SetAccessibilityWindow(NSWindow* window) override {
  456. +#if !IS_MAS_BUILD()
  457. host_->SetRemoteAccessibilityWindowToken(
  458. ui::RemoteAccessibility::GetTokenForLocalElement(window));
  459. +#endif
  460. }
  461. void ForwardKeyboardEvent(const input::NativeWebKeyboardEvent& key_event,
  462. 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
  463. index 13c3fe06c417a2565e6af4552930a56c44a01fb3..ef67191f5d010451cde2b084d6165c7dfe3bbee7 100644
  464. --- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  465. +++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  466. @@ -35,6 +35,7 @@
  467. #include "content/public/browser/browser_accessibility_state.h"
  468. #import "content/public/browser/render_widget_host_view_mac_delegate.h"
  469. #include "content/public/common/content_features.h"
  470. +#include "electron/mas.h"
  471. #include "skia/ext/skia_utils_mac.h"
  472. #include "third_party/blink/public/common/features.h"
  473. #include "third_party/blink/public/mojom/input/input_handler.mojom.h"
  474. @@ -2061,15 +2062,21 @@ - (NSAccessibilityRole)accessibilityRole {
  475. // Since this implementation doesn't have to wait any IPC calls, this doesn't
  476. // make any key-typing jank. --hbono 7/23/09
  477. //
  478. +#if !IS_MAS_BUILD()
  479. extern "C" {
  480. extern NSString* NSTextInputReplacementRangeAttributeName;
  481. }
  482. +#endif
  483. - (NSArray*)validAttributesForMarkedText {
  484. // This code is just copied from WebKit except renaming variables.
  485. static NSArray* const kAttributes = @[
  486. NSUnderlineStyleAttributeName, NSUnderlineColorAttributeName,
  487. +#if !IS_MAS_BUILD()
  488. NSMarkedClauseSegmentAttributeName, NSTextInputReplacementRangeAttributeName
  489. +#else
  490. + NSMarkedClauseSegmentAttributeName
  491. +#endif
  492. ];
  493. return kAttributes;
  494. }
  495. diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
  496. index 44579cb75f6757ff72279f0e5d8b7115322fa131..5b18a160870a0294a6eda807570ad847be546bf4 100644
  497. --- a/content/browser/BUILD.gn
  498. +++ b/content/browser/BUILD.gn
  499. @@ -323,6 +323,7 @@ source_set("browser") {
  500. "//ui/strings:ax_strings",
  501. "//ui/touch_selection",
  502. "//v8:v8_version",
  503. + "//electron/build/config:generate_mas_config",
  504. ]
  505. public_deps = [
  506. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  507. index 2285564db47ef15eb9a83affd1e481b5671c3940..cf5e79a5540d8208c34579d7e8b5a5715abb1beb 100644
  508. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  509. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  510. @@ -23,6 +23,7 @@
  511. #include "content/browser/renderer_host/text_input_manager.h"
  512. #include "content/common/content_export.h"
  513. #include "content/common/render_widget_host_ns_view.mojom.h"
  514. +#include "electron/mas.h"
  515. #include "mojo/public/cpp/bindings/associated_receiver.h"
  516. #include "mojo/public/cpp/bindings/associated_remote.h"
  517. #include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
  518. @@ -53,7 +54,9 @@ class CursorManager;
  519. @protocol RenderWidgetHostViewMacDelegate;
  520. +#if !IS_MAS_BUILD()
  521. @class NSAccessibilityRemoteUIElement;
  522. +#endif
  523. @class RenderWidgetHostViewCocoa;
  524. namespace content {
  525. @@ -684,9 +687,11 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  526. // EnsureSurfaceSynchronizedForWebTest().
  527. uint32_t latest_capture_sequence_number_ = 0u;
  528. +#if !IS_MAS_BUILD()
  529. // Remote accessibility objects corresponding to the NSWindow that this is
  530. // displayed to the user in.
  531. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  532. +#endif
  533. // Used to force the NSApplication's focused accessibility element to be the
  534. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  535. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  536. index 34fb29866785ef07c6dca4cfc85966df1c479b5f..e305d25a8f2a34ac90f4d503a9c74dcc6c553cdf 100644
  537. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  538. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  539. @@ -48,6 +48,7 @@
  540. #include "content/public/browser/render_widget_host.h"
  541. #include "content/public/browser/web_contents.h"
  542. #include "content/public/common/page_visibility_state.h"
  543. +#include "electron/mas.h"
  544. #include "media/base/media_switches.h"
  545. #include "skia/ext/platform_canvas.h"
  546. #include "skia/ext/skia_utils_mac.h"
  547. @@ -273,8 +274,10 @@
  548. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  549. remote_cocoa::mojom::Application* remote_cocoa_application,
  550. uint64_t parent_ns_view_id) {
  551. +#if !IS_MAS_BUILD()
  552. // Destroy the previous remote accessibility element.
  553. remote_window_accessible_ = nil;
  554. +#endif
  555. // Reset `ns_view_` before resetting `remote_ns_view_` to avoid dangling
  556. // pointers. `ns_view_` gets reinitialized later in this method.
  557. @@ -1636,8 +1639,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  558. gfx::NativeViewAccessible
  559. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  560. +#if !IS_MAS_BUILD()
  561. if (remote_window_accessible_)
  562. return remote_window_accessible_;
  563. +#endif
  564. return [GetInProcessNSView() window];
  565. }
  566. @@ -1686,9 +1691,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  567. }
  568. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  569. +#if !IS_MAS_BUILD()
  570. // When running in-process, just use the NSView's NSWindow as its own
  571. // accessibility element.
  572. remote_window_accessible_ = nil;
  573. +#endif
  574. }
  575. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  576. @@ -2212,20 +2219,26 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  577. void RenderWidgetHostViewMac::GetRenderWidgetAccessibilityToken(
  578. GetRenderWidgetAccessibilityTokenCallback callback) {
  579. base::ProcessId pid = getpid();
  580. +#if !IS_MAS_BUILD()
  581. id element_id = GetNativeViewAccessible();
  582. std::vector<uint8_t> token =
  583. ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  584. std::move(callback).Run(pid, token);
  585. +#else
  586. + std::move(callback).Run(pid, std::vector<uint8_t>());
  587. +#endif
  588. }
  589. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  590. const std::vector<uint8_t>& window_token) {
  591. +#if !IS_MAS_BUILD()
  592. if (window_token.empty()) {
  593. remote_window_accessible_ = nil;
  594. } else {
  595. remote_window_accessible_ =
  596. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  597. }
  598. +#endif
  599. }
  600. ///////////////////////////////////////////////////////////////////////////////
  601. diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn
  602. index f1a3573055d86e68e7089b06ea1bb3f97e36df27..e5b0194d583e0a0eb2441514abb65816f595dedc 100644
  603. --- a/content/common/BUILD.gn
  604. +++ b/content/common/BUILD.gn
  605. @@ -286,6 +286,7 @@ source_set("common") {
  606. "//ui/shell_dialogs",
  607. "//url",
  608. "//url/ipc:url_ipc",
  609. + "//electron/build/config:generate_mas_config",
  610. ]
  611. defines = []
  612. diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn
  613. index 55a3baeeec34e9e89b75e93cd17486baef6e550e..cdd5750c7a84e38501e4b6d24e6a2c365b9ce5f1 100644
  614. --- a/content/renderer/BUILD.gn
  615. +++ b/content/renderer/BUILD.gn
  616. @@ -334,6 +334,7 @@ target(link_target_type, "renderer") {
  617. "//ui/surface",
  618. "//url",
  619. "//v8",
  620. + "//electron/build/config:generate_mas_config",
  621. ]
  622. allow_circular_includes_from = []
  623. diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
  624. index d4db3b179725cb96bcbd0f73db7d52ef8b7522db..703b0f56a61abac51961bfd918b7349b943900de 100644
  625. --- a/content/renderer/renderer_main_platform_delegate_mac.mm
  626. +++ b/content/renderer/renderer_main_platform_delegate_mac.mm
  627. @@ -7,12 +7,15 @@
  628. #import <Cocoa/Cocoa.h>
  629. #include "base/check_op.h"
  630. +#include "electron/mas.h"
  631. #include "sandbox/mac/seatbelt.h"
  632. #include "sandbox/mac/system_services.h"
  633. +#if !IS_MAS_BUILD()
  634. extern "C" {
  635. CGError CGSSetDenyWindowServerConnections(bool);
  636. }
  637. +#endif
  638. namespace content {
  639. @@ -22,6 +25,7 @@
  640. // verifies there are no existing open connections), and then indicates that
  641. // Chrome should continue execution without access to launchservicesd.
  642. void DisableSystemServices() {
  643. +#if !IS_MAS_BUILD()
  644. // Tell the WindowServer that we don't want to make any future connections.
  645. // This will return Success as long as there are no open connections, which
  646. // is what we want.
  647. @@ -30,6 +34,7 @@ void DisableSystemServices() {
  648. sandbox::DisableLaunchServices();
  649. sandbox::DisableCoreServicesCheckFix();
  650. +#endif
  651. }
  652. } // namespace
  653. diff --git a/content/renderer/theme_helper_mac.mm b/content/renderer/theme_helper_mac.mm
  654. index a1068589ad844518038ee7bc15a3de9bc5cba525..1ff781c49f086ec8015c7d3c44567dbec3d00ff8 100644
  655. --- a/content/renderer/theme_helper_mac.mm
  656. +++ b/content/renderer/theme_helper_mac.mm
  657. @@ -7,16 +7,28 @@
  658. #include <Cocoa/Cocoa.h>
  659. #include "base/strings/sys_string_conversions.h"
  660. +#include "electron/mas.h"
  661. +#if !IS_MAS_BUILD()
  662. extern "C" {
  663. bool CGFontRenderingGetFontSmoothingDisabled(void);
  664. }
  665. -
  666. +#endif
  667. namespace content {
  668. bool IsSubpixelAntialiasingAvailable() {
  669. +#if !IS_MAS_BUILD()
  670. // See https://trac.webkit.org/changeset/239306/webkit for more info.
  671. return !CGFontRenderingGetFontSmoothingDisabled();
  672. +#else
  673. + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  674. + NSString *default_key = @"CGFontRenderingGetFontSmoothingDisabled";
  675. + // Check that key exists since boolForKey defaults to NO when the
  676. + // key is missing and this key in fact defaults to YES;
  677. + if ([defaults objectForKey:default_key] == nil)
  678. + return false;
  679. + return ![defaults boolForKey:default_key];
  680. +#endif
  681. }
  682. } // namespace content
  683. diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn
  684. index e9f8c56f5eaf281f62bf3841c2b000e90c07f4b2..85445aa251d92aff789d4a6d2f3c145e70816c9e 100644
  685. --- a/content/test/BUILD.gn
  686. +++ b/content/test/BUILD.gn
  687. @@ -643,6 +643,7 @@ static_library("test_support") {
  688. "//url",
  689. "//url/mojom:url_mojom_gurl",
  690. "//v8",
  691. + "//electron/build/config:generate_mas_config"
  692. ]
  693. data_deps = [
  694. @@ -1112,6 +1113,7 @@ static_library("browsertest_support") {
  695. }
  696. configs += [ "//v8:external_startup_data" ]
  697. + deps += ["//electron/build/config:generate_mas_config"]
  698. }
  699. mojom("content_test_mojo_bindings") {
  700. @@ -1936,6 +1938,7 @@ test("content_browsertests") {
  701. "//ui/shell_dialogs",
  702. "//ui/snapshot",
  703. "//ui/webui:test_support",
  704. + "//electron/build/config:generate_mas_config"
  705. ]
  706. if (!(is_chromeos_ash && target_cpu == "arm64" && current_cpu == "arm")) {
  707. @@ -3214,6 +3217,7 @@ test("content_unittests") {
  708. "//ui/latency:test_support",
  709. "//ui/shell_dialogs:shell_dialogs",
  710. "//ui/webui:test_support",
  711. + "//electron/build/config:generate_mas_config"
  712. ]
  713. if (enable_nocompile_tests) {
  714. diff --git a/content/web_test/BUILD.gn b/content/web_test/BUILD.gn
  715. index 99e612f705c5dff041454802033564085718260a..aa37555d9a9c0fda19d0096d035c245eca5ca0c6 100644
  716. --- a/content/web_test/BUILD.gn
  717. +++ b/content/web_test/BUILD.gn
  718. @@ -228,6 +228,7 @@ static_library("web_test_browser") {
  719. "//ui/gl",
  720. "//ui/shell_dialogs:shell_dialogs",
  721. "//url",
  722. + "//electron/build/config:generate_mas_config"
  723. ]
  724. # TODO(crbug.com/40139469): Blink test plugin must be migrated from PPAPI.
  725. diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn
  726. index 094318e67239ea34ccfe42949f417dece377673a..ba645e2aad56ac007eb6f41cf84cb1e05e4a6a1a 100644
  727. --- a/device/bluetooth/BUILD.gn
  728. +++ b/device/bluetooth/BUILD.gn
  729. @@ -258,6 +258,7 @@ component("bluetooth") {
  730. "IOKit.framework",
  731. "Foundation.framework",
  732. ]
  733. + deps += ["//electron/build/config:generate_mas_config"]
  734. }
  735. if (is_mac) {
  736. diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
  737. index fa86583a2d82c4076cfcf64cdc3f6bbb533b95d7..3e4bda0bc31431cb2cc0893d246be6bb54cfab83 100644
  738. --- a/device/bluetooth/bluetooth_adapter_mac.mm
  739. +++ b/device/bluetooth/bluetooth_adapter_mac.mm
  740. @@ -38,7 +38,9 @@
  741. #include "device/bluetooth/bluetooth_discovery_session_outcome.h"
  742. #include "device/bluetooth/bluetooth_socket_mac.h"
  743. #include "device/bluetooth/public/cpp/bluetooth_address.h"
  744. +#include "electron/mas.h"
  745. +#if !IS_MAS_BUILD()
  746. extern "C" {
  747. // Undocumented IOBluetooth Preference API [1]. Used by `blueutil` [2] and
  748. // `Karabiner` [3] to programmatically control the Bluetooth state. Calling the
  749. @@ -52,6 +54,7 @@
  750. // [4] https://support.apple.com/kb/PH25091
  751. void IOBluetoothPreferenceSetControllerPowerState(int state);
  752. }
  753. +#endif
  754. // A simple helper class that forwards any Bluetooth device connect notification
  755. // to its wrapped |_adapter|.
  756. @@ -161,8 +164,10 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  757. : controller_state_function_(
  758. base::BindRepeating(&BluetoothAdapterMac::GetHostControllerState,
  759. base::Unretained(this))),
  760. +#if !IS_MAS_BUILD()
  761. power_state_function_(
  762. base::BindRepeating(IOBluetoothPreferenceSetControllerPowerState)),
  763. +#endif
  764. device_paired_status_callback_(
  765. base::BindRepeating(&IsDeviceSystemPaired)) {
  766. }
  767. @@ -313,8 +318,12 @@ bool IsDeviceSystemPaired(const std::string& device_address) {
  768. }
  769. bool BluetoothAdapterMac::SetPoweredImpl(bool powered) {
  770. +#if !IS_MAS_BUILD()
  771. power_state_function_.Run(base::strict_cast<int>(powered));
  772. return true;
  773. +#else
  774. + return false;
  775. +#endif
  776. }
  777. base::WeakPtr<BluetoothLowEnergyAdapterApple>
  778. diff --git a/gpu/ipc/service/BUILD.gn b/gpu/ipc/service/BUILD.gn
  779. index 973cd337f2781271b4ca3e29db07939ec6917327..90658a336138e4e50f93c38f1c1f465c1c2bd4dc 100644
  780. --- a/gpu/ipc/service/BUILD.gn
  781. +++ b/gpu/ipc/service/BUILD.gn
  782. @@ -135,6 +135,7 @@ component("service") {
  783. "QuartzCore.framework",
  784. ]
  785. defines += [ "GL_SILENCE_DEPRECATION" ]
  786. + deps += ["//electron/build/config:generate_mas_config"]
  787. }
  788. if (is_ios) {
  789. sources += [ "image_transport_surface_ios.mm" ]
  790. diff --git a/gpu/ipc/service/image_transport_surface_overlay_mac.h b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  791. index 36322ddd3047f96569f35807541a37d3c6672b09..0121a780cf3b79fc1120c1b85cd5cd30c14968ef 100644
  792. --- a/gpu/ipc/service/image_transport_surface_overlay_mac.h
  793. +++ b/gpu/ipc/service/image_transport_surface_overlay_mac.h
  794. @@ -8,6 +8,7 @@
  795. #include <vector>
  796. #include "base/memory/weak_ptr.h"
  797. +#include "electron/mas.h"
  798. #include "gpu/ipc/service/command_buffer_stub.h"
  799. #include "gpu/ipc/service/image_transport_surface.h"
  800. #include "ui/gfx/ca_layer_result.h"
  801. @@ -23,7 +24,9 @@
  802. #include "ui/display/types/display_constants.h"
  803. #endif
  804. +#if !IS_MAS_BUILD()
  805. @class CAContext;
  806. +#endif
  807. @class CALayer;
  808. namespace ui {
  809. diff --git a/media/audio/BUILD.gn b/media/audio/BUILD.gn
  810. index 6f3b368103b05f07ae67da4c0307efe039b8dfce..c8b18509dc508fbb928b97830536d210b378bf73 100644
  811. --- a/media/audio/BUILD.gn
  812. +++ b/media/audio/BUILD.gn
  813. @@ -197,6 +197,7 @@ source_set("audio") {
  814. "CoreMedia.framework",
  815. ]
  816. weak_frameworks = [ "ScreenCaptureKit.framework" ] # macOS 13.0
  817. + deps += ["//electron/build/config:generate_mas_config"]
  818. }
  819. if (is_ios) {
  820. diff --git a/media/audio/apple/audio_low_latency_input.cc b/media/audio/apple/audio_low_latency_input.cc
  821. index 9b78f60304a0e487904fdb22c9e6d85a237ca96e..e639558d34edab3ba3b1bb4f502bd91405e58637 100644
  822. --- a/media/audio/apple/audio_low_latency_input.cc
  823. +++ b/media/audio/apple/audio_low_latency_input.cc
  824. @@ -28,6 +28,7 @@
  825. #include "base/strings/sys_string_conversions.h"
  826. #include "base/time/time.h"
  827. #include "base/trace_event/trace_event.h"
  828. +#include "electron/mas.h"
  829. #include "media/audio/apple/audio_manager_apple.h"
  830. #include "media/audio/apple/scoped_audio_unit.h"
  831. #include "media/base/audio_bus.h"
  832. @@ -39,19 +40,23 @@
  833. namespace {
  834. extern "C" {
  835. +#if !IS_MAS_BUILD()
  836. // See:
  837. // https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/PAL/pal/spi/cf/CoreAudioSPI.h?rev=228264
  838. OSStatus AudioDeviceDuck(AudioDeviceID inDevice,
  839. Float32 inDuckedLevel,
  840. const AudioTimeStamp* __nullable inStartTime,
  841. Float32 inRampDuration) __attribute__((weak_import));
  842. +#endif
  843. }
  844. void UndoDucking(AudioDeviceID output_device_id) {
  845. +#if !IS_MAS_BUILD()
  846. if (AudioDeviceDuck != nullptr) {
  847. // Ramp the volume back up over half a second.
  848. AudioDeviceDuck(output_device_id, 1.0, nullptr, 0.5);
  849. }
  850. +#endif
  851. }
  852. } // namespace
  853. #endif
  854. diff --git a/net/dns/BUILD.gn b/net/dns/BUILD.gn
  855. index 5f4ff9ff8172d4ad282cc9c781f85118b8ba7d1a..cc85f488884f48df94198b7e4d4823946e750716 100644
  856. --- a/net/dns/BUILD.gn
  857. +++ b/net/dns/BUILD.gn
  858. @@ -187,6 +187,8 @@ source_set("dns") {
  859. ":host_resolver_manager",
  860. ":mdns_client",
  861. ]
  862. +
  863. + deps += ["//electron/build/config:generate_mas_config"]
  864. }
  865. # The standard API of net/dns.
  866. diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
  867. index 70d5665ad7b9ef62370497636af919ede2508ad4..f4dc3e2b8053cdb3e8c439ab1a1d6369a8e6a7dc 100644
  868. --- a/net/dns/dns_config_service_posix.cc
  869. +++ b/net/dns/dns_config_service_posix.cc
  870. @@ -28,6 +28,7 @@
  871. #include "base/threading/scoped_blocking_call.h"
  872. #include "base/time/time.h"
  873. #include "build/build_config.h"
  874. +#include "electron/mas.h"
  875. #include "net/base/ip_endpoint.h"
  876. #include "net/dns/dns_config.h"
  877. #include "net/dns/dns_hosts.h"
  878. @@ -135,8 +136,8 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  879. bool Watch() override {
  880. CheckOnCorrectSequence();
  881. -
  882. bool success = true;
  883. +#if !IS_MAS_BUILD()
  884. if (!config_watcher_.Watch(base::BindRepeating(&Watcher::OnConfigChanged,
  885. base::Unretained(this)))) {
  886. LOG(ERROR) << "DNS config watch failed to start.";
  887. @@ -153,6 +154,7 @@ class DnsConfigServicePosix::Watcher : public DnsConfigService::Watcher {
  888. success = false;
  889. }
  890. #endif // !BUILDFLAG(IS_IOS)
  891. +#endif
  892. return success;
  893. }
  894. diff --git a/sandbox/mac/BUILD.gn b/sandbox/mac/BUILD.gn
  895. index 4e53d573ff67615bc7dcee7db6f855c67094f414..8b061d66b1a854b51a5a38b6a71eadab6a7dbbec 100644
  896. --- a/sandbox/mac/BUILD.gn
  897. +++ b/sandbox/mac/BUILD.gn
  898. @@ -39,6 +39,7 @@ component("seatbelt") {
  899. ]
  900. public_deps = [ "//third_party/protobuf:protobuf_lite" ]
  901. defines = [ "SEATBELT_IMPLEMENTATION" ]
  902. + deps += ["//electron/build/config:generate_mas_config"]
  903. }
  904. component("seatbelt_extension") {
  905. @@ -52,6 +53,7 @@ component("seatbelt_extension") {
  906. libs = [ "sandbox" ]
  907. public_deps = [ "//base" ]
  908. defines = [ "SEATBELT_IMPLEMENTATION" ]
  909. + deps += ["//electron/build/config:generate_mas_config"]
  910. }
  911. component("system_services") {
  912. @@ -66,6 +68,7 @@ component("system_services") {
  913. deps = [ ":seatbelt_export" ]
  914. public_deps = [ "//base" ]
  915. defines = [ "SEATBELT_IMPLEMENTATION" ]
  916. + deps += ["//electron/build/config:generate_mas_config"]
  917. }
  918. source_set("sandbox_unittests") {
  919. diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
  920. index f35d9ef2a2df3db8ecbf1d7b909c7b1cf33f3cd9..5d52330d1bd70cd7b97ee3360721f10c8447c717 100644
  921. --- a/sandbox/mac/sandbox_compiler.cc
  922. +++ b/sandbox/mac/sandbox_compiler.cc
  923. @@ -7,6 +7,7 @@
  924. #include <string>
  925. #include <vector>
  926. +#include "electron/mas.h"
  927. #include "sandbox/mac/seatbelt.h"
  928. namespace sandbox {
  929. @@ -47,6 +48,7 @@ bool SandboxCompiler::SetParameter(const std::string& key,
  930. }
  931. bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  932. +#if !IS_MAS_BUILD()
  933. if (mode_ == Target::kSource) {
  934. std::vector<const char*> params;
  935. @@ -67,6 +69,9 @@ bool SandboxCompiler::CompileAndApplyProfile(std::string& error) {
  936. }
  937. }
  938. return false;
  939. +#else
  940. + return true;
  941. +#endif
  942. }
  943. bool SandboxCompiler::CompilePolicyToProto(mac::SandboxPolicy& policy,
  944. diff --git a/sandbox/mac/sandbox_logging.cc b/sandbox/mac/sandbox_logging.cc
  945. index 095c639b9893e885d8937e29ed7d47a7c28bc6b6..7e0cf9b9f94b16741358bdb45122f8b2bd68c0f9 100644
  946. --- a/sandbox/mac/sandbox_logging.cc
  947. +++ b/sandbox/mac/sandbox_logging.cc
  948. @@ -16,6 +16,7 @@
  949. #include <string>
  950. #include "build/build_config.h"
  951. +#include "electron/mas.h"
  952. #include "sandbox/mac/sandbox_crash_message.h"
  953. #if defined(ARCH_CPU_X86_64)
  954. @@ -33,9 +34,11 @@
  955. }
  956. #endif
  957. +#if !IS_MAS_BUILD()
  958. extern "C" {
  959. void abort_report_np(const char*, ...);
  960. }
  961. +#endif
  962. namespace sandbox::logging {
  963. @@ -76,9 +79,11 @@ void SendOsLog(Level level, const char* message) {
  964. sandbox::crash_message::SetCrashMessage(message);
  965. }
  966. +#if !IS_MAS_BUILD()
  967. if (level == Level::FATAL) {
  968. abort_report_np(message);
  969. }
  970. +#endif
  971. }
  972. // |error| is strerror(errno) when a P* logging function is called. Pass
  973. diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
  974. index 15c835e118456394c0a00ac98c11241c14ca75bd..a16faabe2bd63a5e0fbe9082a3b4b7c8aa0ea064 100644
  975. --- a/sandbox/mac/seatbelt.cc
  976. +++ b/sandbox/mac/seatbelt.cc
  977. @@ -4,12 +4,14 @@
  978. #include "sandbox/mac/seatbelt.h"
  979. +#include "electron/mas.h"
  980. +
  981. #include <errno.h>
  982. #include <unistd.h>
  983. extern "C" {
  984. #include <sandbox.h>
  985. -
  986. +#if !IS_MAS_BUILD()
  987. int sandbox_init_with_parameters(const char* profile,
  988. uint64_t flags,
  989. const char* const parameters[],
  990. @@ -40,13 +42,13 @@ sandbox_profile_t* sandbox_compile_string(const char* data,
  991. char** error);
  992. int sandbox_apply(sandbox_profile_t*);
  993. void sandbox_free_profile(sandbox_profile_t*);
  994. -
  995. +#endif
  996. } // extern "C"
  997. namespace sandbox {
  998. namespace {
  999. -
  1000. +#if !IS_MAS_BUILD()
  1001. bool HandleSandboxResult(int rv, char* errorbuf, std::string* error) {
  1002. if (rv == 0) {
  1003. if (error)
  1004. @@ -74,36 +76,48 @@ bool HandleSandboxErrno(int rv, const char* message, std::string* error) {
  1005. }
  1006. return false;
  1007. }
  1008. -
  1009. +#endif
  1010. } // namespace
  1011. // static
  1012. Seatbelt::Parameters Seatbelt::Parameters::Create() {
  1013. Parameters params;
  1014. +#if !IS_MAS_BUILD()
  1015. params.params_ = ::sandbox_create_params();
  1016. +#endif
  1017. return params;
  1018. }
  1019. Seatbelt::Parameters::Parameters() = default;
  1020. Seatbelt::Parameters::Parameters(Seatbelt::Parameters&& other) {
  1021. +#if !IS_MAS_BUILD()
  1022. params_ = std::exchange(other.params_, nullptr);
  1023. +#endif
  1024. }
  1025. Seatbelt::Parameters& Seatbelt::Parameters::operator=(
  1026. Seatbelt::Parameters&& other) {
  1027. +#if !IS_MAS_BUILD()
  1028. params_ = std::exchange(other.params_, nullptr);
  1029. +#endif
  1030. return *this;
  1031. }
  1032. bool Seatbelt::Parameters::Set(const char* key, const char* value) {
  1033. +#if !IS_MAS_BUILD()
  1034. return ::sandbox_set_param(params_, key, value) == 0;
  1035. +#else
  1036. + return true;
  1037. +#endif
  1038. }
  1039. Seatbelt::Parameters::~Parameters() {
  1040. +#if !IS_MAS_BUILD()
  1041. if (params_) {
  1042. ::sandbox_free_params(params_);
  1043. }
  1044. +#endif
  1045. }
  1046. // Initialize the static member variables.
  1047. @@ -114,6 +128,7 @@ const char* Seatbelt::kProfilePureComputation = kSBXProfilePureComputation;
  1048. // static
  1049. bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  1050. +#if !IS_MAS_BUILD()
  1051. // OS X deprecated these functions, but did not provide a suitable replacement,
  1052. // so ignore the deprecation warning.
  1053. #pragma clang diagnostic push
  1054. @@ -122,6 +137,9 @@ bool Seatbelt::Init(const char* profile, uint64_t flags, std::string* error) {
  1055. int rv = ::sandbox_init(profile, flags, &errorbuf);
  1056. return HandleSandboxResult(rv, errorbuf, error);
  1057. #pragma clang diagnostic pop
  1058. +#else
  1059. + return true;
  1060. +#endif
  1061. }
  1062. // static
  1063. @@ -129,10 +147,14 @@ bool Seatbelt::InitWithParams(const char* profile,
  1064. uint64_t flags,
  1065. const char* const parameters[],
  1066. std::string* error) {
  1067. +#if !IS_MAS_BUILD()
  1068. char* errorbuf = nullptr;
  1069. int rv =
  1070. ::sandbox_init_with_parameters(profile, flags, parameters, &errorbuf);
  1071. return HandleSandboxResult(rv, errorbuf, error);
  1072. +#else
  1073. + return true;
  1074. +#endif
  1075. }
  1076. // static
  1077. @@ -140,6 +162,7 @@ bool Seatbelt::Compile(const char* profile,
  1078. const Seatbelt::Parameters& params,
  1079. std::string& compiled_profile,
  1080. std::string* error) {
  1081. +#if !IS_MAS_BUILD()
  1082. char* errorbuf = nullptr;
  1083. sandbox_profile_t* sandbox_profile =
  1084. ::sandbox_compile_string(profile, params.params(), &errorbuf);
  1085. @@ -149,33 +172,44 @@ bool Seatbelt::Compile(const char* profile,
  1086. compiled_profile.assign(reinterpret_cast<const char*>(sandbox_profile->data),
  1087. sandbox_profile->size);
  1088. ::sandbox_free_profile(sandbox_profile);
  1089. +#endif
  1090. return true;
  1091. }
  1092. // static
  1093. bool Seatbelt::ApplyCompiledProfile(const std::string& profile,
  1094. std::string* error) {
  1095. +#if !IS_MAS_BUILD()
  1096. sandbox_profile_t sbox_profile = {
  1097. .builtin = nullptr,
  1098. .data = reinterpret_cast<const uint8_t*>(profile.data()),
  1099. .size = profile.size()};
  1100. return HandleSandboxErrno(::sandbox_apply(&sbox_profile),
  1101. "sandbox_apply: ", error);
  1102. +#else
  1103. + return true;
  1104. +#endif
  1105. }
  1106. // static
  1107. void Seatbelt::FreeError(char* errorbuf) {
  1108. +#if !IS_MAS_BUILD()
  1109. // OS X deprecated these functions, but did not provide a suitable replacement,
  1110. // so ignore the deprecation warning.
  1111. #pragma clang diagnostic push
  1112. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  1113. return ::sandbox_free_error(errorbuf);
  1114. #pragma clang diagnostic pop
  1115. +#endif
  1116. }
  1117. // static
  1118. bool Seatbelt::IsSandboxed() {
  1119. +#if !IS_MAS_BUILD()
  1120. return ::sandbox_check(getpid(), NULL, 0);
  1121. +#else
  1122. + return true;
  1123. +#endif
  1124. }
  1125. } // namespace sandbox
  1126. diff --git a/sandbox/mac/seatbelt_extension.cc b/sandbox/mac/seatbelt_extension.cc
  1127. index 79edca9ca521d1bc2ff343967348eb98039b292a..23f9410ee66024e2c6b0b6b2b356a67b0ae2eba7 100644
  1128. --- a/sandbox/mac/seatbelt_extension.cc
  1129. +++ b/sandbox/mac/seatbelt_extension.cc
  1130. @@ -9,8 +9,10 @@
  1131. #include "base/check.h"
  1132. #include "base/memory/ptr_util.h"
  1133. #include "base/notreached.h"
  1134. +#include "electron/mas.h"
  1135. #include "sandbox/mac/seatbelt_extension_token.h"
  1136. +#if !IS_MAS_BUILD()
  1137. // libsandbox private API.
  1138. extern "C" {
  1139. extern const char* APP_SANDBOX_READ;
  1140. @@ -22,6 +24,7 @@ char* sandbox_extension_issue_file(const char* type,
  1141. const char* path,
  1142. uint32_t flags);
  1143. }
  1144. +#endif
  1145. namespace sandbox {
  1146. @@ -50,7 +53,11 @@ std::unique_ptr<SeatbeltExtension> SeatbeltExtension::FromToken(
  1147. bool SeatbeltExtension::Consume() {
  1148. DCHECK(!token_.empty());
  1149. +#if !IS_MAS_BUILD()
  1150. handle_ = sandbox_extension_consume(token_.c_str());
  1151. +#else
  1152. + handle_ = -1;
  1153. +#endif
  1154. return handle_ > 0;
  1155. }
  1156. @@ -62,7 +69,11 @@ bool SeatbeltExtension::ConsumePermanently() {
  1157. }
  1158. bool SeatbeltExtension::Revoke() {
  1159. +#if !IS_MAS_BUILD()
  1160. int rv = sandbox_extension_release(handle_);
  1161. +#else
  1162. + int rv = -1;
  1163. +#endif
  1164. handle_ = 0;
  1165. token_.clear();
  1166. return rv == 0;
  1167. @@ -80,12 +91,14 @@ SeatbeltExtension::SeatbeltExtension(const std::string& token)
  1168. char* SeatbeltExtension::IssueToken(SeatbeltExtension::Type type,
  1169. const std::string& resource) {
  1170. switch (type) {
  1171. +#if !IS_MAS_BUILD()
  1172. case FILE_READ:
  1173. return sandbox_extension_issue_file(APP_SANDBOX_READ, resource.c_str(),
  1174. 0);
  1175. case FILE_READ_WRITE:
  1176. return sandbox_extension_issue_file(APP_SANDBOX_READ_WRITE,
  1177. resource.c_str(), 0);
  1178. +#endif
  1179. default:
  1180. NOTREACHED();
  1181. }
  1182. diff --git a/sandbox/mac/system_services.cc b/sandbox/mac/system_services.cc
  1183. index eb81a70e4d5d5cd3e6ae9b45f8cd1c795ea76c51..9921ccb10d3455600eddd85f77f10228016389af 100644
  1184. --- a/sandbox/mac/system_services.cc
  1185. +++ b/sandbox/mac/system_services.cc
  1186. @@ -8,7 +8,9 @@
  1187. #include <CoreFoundation/CoreFoundation.h>
  1188. #include "base/apple/osstatus_logging.h"
  1189. +#include "electron/mas.h"
  1190. +#if !IS_MAS_BUILD()
  1191. extern "C" {
  1192. OSStatus SetApplicationIsDaemon(Boolean isDaemon);
  1193. void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1194. @@ -19,10 +21,12 @@ void _LSSetApplicationLaunchServicesServerConnectionStatus(
  1195. // https://github.com/WebKit/WebKit/blob/24aaedc770d192d03a07ba4a71727274aaa8fc07/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm#L840
  1196. void _CSCheckFixDisable();
  1197. } // extern "C"
  1198. +#endif
  1199. namespace sandbox {
  1200. void DisableLaunchServices() {
  1201. + #if !IS_MAS_BUILD()
  1202. // Allow the process to continue without a LaunchServices ASN. The
  1203. // INIT_Process function in HIServices will abort if it cannot connect to
  1204. // launchservicesd to get an ASN. By setting this flag, HIServices skips
  1205. @@ -36,10 +40,13 @@ void DisableLaunchServices() {
  1206. 0, ^bool(CFDictionaryRef options) {
  1207. return false;
  1208. });
  1209. + #endif
  1210. }
  1211. void DisableCoreServicesCheckFix() {
  1212. +#if !IS_MAS_BUILD()
  1213. _CSCheckFixDisable();
  1214. +#endif
  1215. }
  1216. } // namespace sandbox
  1217. diff --git a/third_party/blink/renderer/core/BUILD.gn b/third_party/blink/renderer/core/BUILD.gn
  1218. index 2041934dd6c8f5bb77c286871ff79c1fb56922a5..c6b5bb81023dd7b61b8d429e7cb46f4d37c4d9e1 100644
  1219. --- a/third_party/blink/renderer/core/BUILD.gn
  1220. +++ b/third_party/blink/renderer/core/BUILD.gn
  1221. @@ -408,6 +408,7 @@ component("core") {
  1222. "//ui/gfx/geometry",
  1223. "//ui/gfx/geometry:geometry_skia",
  1224. "//ui/strings",
  1225. + "//electron/build/config:generate_mas_config",
  1226. ]
  1227. if (is_mac) {
  1228. diff --git a/third_party/blink/renderer/core/editing/build.gni b/third_party/blink/renderer/core/editing/build.gni
  1229. index d38e951cdbf1ab9b367273ad0fb8f962155a7f3b..e39ee0414cb54004096dbfffc4f768e805f3310a 100644
  1230. --- a/third_party/blink/renderer/core/editing/build.gni
  1231. +++ b/third_party/blink/renderer/core/editing/build.gni
  1232. @@ -358,10 +358,14 @@ blink_core_sources_editing = [
  1233. if (is_mac) {
  1234. blink_core_sources_editing += [
  1235. "commands/smart_replace_cf.cc",
  1236. - "kill_ring_mac.mm",
  1237. "substring_util.h",
  1238. "substring_util.mm",
  1239. ]
  1240. + if (is_mas_build) {
  1241. + blink_core_sources_editing += [ "kill_ring_mac.mm" ]
  1242. + } else {
  1243. + blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1244. + }
  1245. } else {
  1246. blink_core_sources_editing += [ "kill_ring_none.cc" ]
  1247. }
  1248. diff --git a/ui/accelerated_widget_mac/BUILD.gn b/ui/accelerated_widget_mac/BUILD.gn
  1249. index 3ead42e14ad9d41a30c5637678a3ac49296ce2a6..07665bbefd34737bf6a8c3e79d70b066920788c9 100644
  1250. --- a/ui/accelerated_widget_mac/BUILD.gn
  1251. +++ b/ui/accelerated_widget_mac/BUILD.gn
  1252. @@ -64,6 +64,7 @@ component("accelerated_widget_mac") {
  1253. "//ui/gfx",
  1254. "//ui/gfx/geometry",
  1255. "//ui/gl",
  1256. + "//electron/build/config:generate_mas_config",
  1257. ]
  1258. }
  1259. diff --git a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1260. index b11c365f42dd1ddc363de0d94c387b13ac65bef3..5da42beb20b514396287cc6dc5cba608e1660b2e 100644
  1261. --- a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1262. +++ b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.h
  1263. @@ -7,6 +7,7 @@
  1264. #include <queue>
  1265. +#include "electron/mas.h"
  1266. #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h"
  1267. #include "ui/accelerated_widget_mac/ca_renderer_layer_tree.h"
  1268. #include "ui/gfx/ca_layer_result.h"
  1269. @@ -14,7 +15,9 @@
  1270. #include "ui/gl/gl_surface.h"
  1271. #include "ui/gl/presenter.h"
  1272. +#if !IS_MAS_BUILD()
  1273. @class CAContext;
  1274. +#endif
  1275. @class CALayer;
  1276. namespace ui {
  1277. @@ -110,7 +113,9 @@ class ACCELERATED_WIDGET_MAC_EXPORT CALayerTreeCoordinator {
  1278. // both the current tree and the pending trees.
  1279. size_t presented_ca_layer_trees_max_length_ = 2;
  1280. +#if !IS_MAS_BUILD()
  1281. CAContext* __strong ca_context_;
  1282. +#endif
  1283. // The root CALayer to display the current frame. This does not change
  1284. // over the lifetime of the object.
  1285. diff --git a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1286. index b99461d52e3a62b58330691e65f9956748cfbf02..f0c3bb1b809a29eee3d990b0a8bbffddb7500895 100644
  1287. --- a/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1288. +++ b/ui/accelerated_widget_mac/ca_layer_tree_coordinator.mm
  1289. @@ -10,6 +10,7 @@
  1290. #include "base/mac/mac_util.h"
  1291. #include "base/task/single_thread_task_runner.h"
  1292. #include "base/trace_event/trace_event.h"
  1293. +#include "electron/mas.h"
  1294. #include "ui/base/cocoa/animation_utils.h"
  1295. #include "ui/base/cocoa/remote_layer_api.h"
  1296. #include "ui/gfx/ca_layer_params.h"
  1297. @@ -33,6 +34,7 @@
  1298. new_presentation_feedback_timestamps_(
  1299. new_presentation_feedback_timestamps),
  1300. buffer_presented_callback_(buffer_presented_callback) {
  1301. +#if !IS_MAS_BUILD()
  1302. if (allow_remote_layers_) {
  1303. root_ca_layer_ = [[CALayer alloc] init];
  1304. #if BUILDFLAG(IS_MAC)
  1305. @@ -61,6 +63,7 @@
  1306. #endif
  1307. ca_context_.layer = root_ca_layer_;
  1308. }
  1309. +#endif
  1310. }
  1311. CALayerTreeCoordinator::~CALayerTreeCoordinator() = default;
  1312. @@ -164,9 +167,13 @@
  1313. TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", TRACE_EVENT_SCOPE_THREAD,
  1314. "GLImpl", static_cast<int>(gl::GetGLImplementation()),
  1315. "width", pixel_size_.width());
  1316. +#if !IS_MAS_BUILD()
  1317. if (allow_remote_layers_) {
  1318. params.ca_context_id = [ca_context_ contextId];
  1319. } else {
  1320. +#else
  1321. + if (true) {
  1322. +#endif
  1323. IOSurfaceRef io_surface = frame->layer_tree->GetContentIOSurface();
  1324. if (io_surface) {
  1325. DCHECK(!allow_remote_layers_);
  1326. diff --git a/ui/accelerated_widget_mac/display_ca_layer_tree.mm b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1327. index dcf493d62990018040a3f84b6f875af737bd2214..3d1c4dcc9ee0bbfdac15f40d9c74e9f342a59e39 100644
  1328. --- a/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1329. +++ b/ui/accelerated_widget_mac/display_ca_layer_tree.mm
  1330. @@ -12,6 +12,7 @@
  1331. #include "base/mac/mac_util.h"
  1332. #include "base/trace_event/trace_event.h"
  1333. #include "build/build_config.h"
  1334. +#include "electron/mas.h"
  1335. #include "ui/base/cocoa/animation_utils.h"
  1336. #include "ui/base/cocoa/remote_layer_api.h"
  1337. #include "ui/gfx/geometry/dip_util.h"
  1338. @@ -121,6 +122,7 @@ - (void)setContentsChanged;
  1339. }
  1340. void DisplayCALayerTree::GotCALayerFrame(uint32_t ca_context_id) {
  1341. +#if !IS_MAS_BUILD()
  1342. // Early-out if the remote layer has not changed.
  1343. if (remote_layer_.contextId == ca_context_id) {
  1344. return;
  1345. @@ -150,6 +152,9 @@ - (void)setContentsChanged;
  1346. [io_surface_layer_ removeFromSuperlayer];
  1347. io_surface_layer_ = nil;
  1348. }
  1349. +#else
  1350. + NOTREACHED() << "Remote layer is being used in MAS build";
  1351. +#endif
  1352. }
  1353. void DisplayCALayerTree::GotIOSurfaceFrame(
  1354. diff --git a/ui/accessibility/platform/BUILD.gn b/ui/accessibility/platform/BUILD.gn
  1355. index 2b3aad7a639c68c6a131e86352b40128ab6af411..840968e8117dd6657c240fa81f3a42b65a39b733 100644
  1356. --- a/ui/accessibility/platform/BUILD.gn
  1357. +++ b/ui/accessibility/platform/BUILD.gn
  1358. @@ -283,6 +283,7 @@ component("platform") {
  1359. "AppKit.framework",
  1360. "Foundation.framework",
  1361. ]
  1362. + deps += ["//electron/build/config:generate_mas_config"]
  1363. }
  1364. if (is_ios) {
  1365. diff --git a/ui/accessibility/platform/browser_accessibility_manager_mac.mm b/ui/accessibility/platform/browser_accessibility_manager_mac.mm
  1366. index be442f6a2a67d07ec78fe00a3e864bf0088fe504..2332199d02b98f53375b4e3e40e25018cb584228 100644
  1367. --- a/ui/accessibility/platform/browser_accessibility_manager_mac.mm
  1368. +++ b/ui/accessibility/platform/browser_accessibility_manager_mac.mm
  1369. @@ -13,13 +13,16 @@
  1370. #include "base/task/single_thread_task_runner.h"
  1371. #include "base/task/task_traits.h"
  1372. #include "base/time/time.h"
  1373. +#include "electron/mas.h"
  1374. #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
  1375. #include "ui/accessibility/ax_role_properties.h"
  1376. #include "ui/accessibility/platform/ax_platform_tree_manager_delegate.h"
  1377. #include "ui/accessibility/platform/ax_private_webkit_constants_mac.h"
  1378. #import "ui/accessibility/platform/browser_accessibility_cocoa.h"
  1379. #import "ui/accessibility/platform/browser_accessibility_mac.h"
  1380. +#if !IS_MAS_BUILD()
  1381. #include "ui/base/cocoa/remote_accessibility_api.h"
  1382. +#endif
  1383. namespace {
  1384. @@ -227,6 +230,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1385. return;
  1386. }
  1387. +#if !IS_MAS_BUILD()
  1388. BrowserAccessibilityManager* root_manager = GetManagerForRootFrame();
  1389. if (root_manager) {
  1390. BrowserAccessibilityManagerMac* root_manager_mac =
  1391. @@ -249,6 +253,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1392. return;
  1393. }
  1394. }
  1395. +#endif
  1396. // Use native VoiceOver support for live regions.
  1397. BrowserAccessibilityCocoa* retained_node = native_node;
  1398. @@ -645,6 +650,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1399. return window == [NSApp accessibilityFocusedWindow];
  1400. }
  1401. +#if !IS_MAS_BUILD()
  1402. // TODO(accessibility): We need a solution to the problem described below.
  1403. // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
  1404. // 1. NSApp is the browser which spawned the PWA, and what it considers the
  1405. @@ -673,6 +679,7 @@ void PostAnnouncementNotification(NSString* announcement,
  1406. if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]]) {
  1407. return true;
  1408. }
  1409. +#endif
  1410. return false;
  1411. }
  1412. diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.mm b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1413. index c8171f0527fe5194f0ea73b57c4444d4c630fbc4..c2ac4da580e3e7f749a0a4de1e859af62de11672 100644
  1414. --- a/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1415. +++ b/ui/accessibility/platform/inspect/ax_transform_mac.mm
  1416. @@ -11,6 +11,7 @@
  1417. #include "base/apple/foundation_util.h"
  1418. #include "base/strings/sys_string_conversions.h"
  1419. +#include "electron/mas.h"
  1420. #include "ui/accessibility/ax_range.h"
  1421. #include "ui/accessibility/platform/ax_platform_node.h"
  1422. #include "ui/accessibility/platform/ax_platform_node_cocoa.h"
  1423. @@ -111,6 +112,7 @@
  1424. }
  1425. }
  1426. +#if !IS_MAS_BUILD()
  1427. // AXTextMarker
  1428. if (IsAXTextMarker(value)) {
  1429. return AXTextMarkerToBaseValue(value, indexer);
  1430. @@ -120,6 +122,7 @@
  1431. if (IsAXTextMarkerRange(value)) {
  1432. return AXTextMarkerRangeToBaseValue(value, indexer);
  1433. }
  1434. +#endif
  1435. // Accessible object
  1436. if (AXElementWrapper::IsValidElement(value)) {
  1437. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  1438. index d6e2f90269e179f02a5ff972cca6963e86c3e211..c88e9d2f83f427c2763a307a21b81359245086d6 100644
  1439. --- a/ui/base/BUILD.gn
  1440. +++ b/ui/base/BUILD.gn
  1441. @@ -358,6 +358,13 @@ component("base") {
  1442. ]
  1443. }
  1444. + if (is_mas_build) {
  1445. + sources -= [
  1446. + "cocoa/remote_accessibility_api.h",
  1447. + "cocoa/remote_accessibility_api.mm",
  1448. + ]
  1449. + }
  1450. +
  1451. if (is_ios) {
  1452. sources += [
  1453. "device_form_factor_ios.mm",
  1454. @@ -508,6 +515,12 @@ component("base") {
  1455. "//url",
  1456. ]
  1457. + if (is_mac) {
  1458. + deps += [
  1459. + "//electron/build/config:generate_mas_config"
  1460. + ]
  1461. + }
  1462. +
  1463. if (is_debug || dcheck_always_on) {
  1464. deps += [ "//third_party/re2" ]
  1465. }
  1466. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  1467. index 3182458838aa96d34911280ab4c6c3aa4aa22d6d..6dc85c366b7e61c8bd0302e501c3223a19223313 100644
  1468. --- a/ui/base/cocoa/remote_accessibility_api.h
  1469. +++ b/ui/base/cocoa/remote_accessibility_api.h
  1470. @@ -10,9 +10,12 @@
  1471. #include <vector>
  1472. #include "base/component_export.h"
  1473. +#include "electron/mas.h"
  1474. // NSAccessibilityRemoteUIElement is a private class in AppKit.
  1475. +#if !IS_MAS_BUILD()
  1476. +
  1477. @interface NSAccessibilityRemoteUIElement : NSObject
  1478. + (void)setRemoteUIApp:(BOOL)flag;
  1479. + (BOOL)isRemoteUIApp;
  1480. @@ -38,4 +41,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  1481. } // namespace ui
  1482. +#endif // MAS_BUILD
  1483. +
  1484. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  1485. diff --git a/ui/base/cocoa/remote_layer_api.h b/ui/base/cocoa/remote_layer_api.h
  1486. index 59dc2f82214cfd883b6ebef3b0fb25af6387a9cd..912c5252d1b30d943a1552739b9eef9a8eae2d7a 100644
  1487. --- a/ui/base/cocoa/remote_layer_api.h
  1488. +++ b/ui/base/cocoa/remote_layer_api.h
  1489. @@ -9,6 +9,7 @@
  1490. #include "base/component_export.h"
  1491. #include "build/build_config.h"
  1492. +#include "electron/mas.h"
  1493. #if defined(__OBJC__)
  1494. #import <Foundation/Foundation.h>
  1495. @@ -17,6 +18,7 @@
  1496. #if BUILDFLAG(IS_MAC)
  1497. +#if !IS_MAS_BUILD()
  1498. // The CGSConnectionID is used to create the CAContext in the process that is
  1499. // going to share the CALayers that it is rendering to another process to
  1500. // display.
  1501. @@ -68,6 +70,8 @@ extern NSString* const kCAContextIgnoresHitTest;
  1502. #endif // __OBJC__
  1503. +#endif // MAS_BUILD
  1504. +
  1505. namespace ui {
  1506. // This function will check if all of the interfaces listed above are supported
  1507. diff --git a/ui/base/cocoa/remote_layer_api.mm b/ui/base/cocoa/remote_layer_api.mm
  1508. index fc25ba79d2b0e1acdb7ba54b89e7d6e16f94771b..de771ef414b9a69e331261524f08e9a12145ec60 100644
  1509. --- a/ui/base/cocoa/remote_layer_api.mm
  1510. +++ b/ui/base/cocoa/remote_layer_api.mm
  1511. @@ -5,11 +5,13 @@
  1512. #include "ui/base/cocoa/remote_layer_api.h"
  1513. #include "base/feature_list.h"
  1514. +#include "electron/mas.h"
  1515. #include <objc/runtime.h>
  1516. namespace ui {
  1517. +#if !IS_MAS_BUILD()
  1518. namespace {
  1519. // Control use of cross-process CALayers to display content directly from the
  1520. // GPU process on Mac.
  1521. @@ -17,8 +19,10 @@
  1522. "RemoteCoreAnimationAPI",
  1523. base::FEATURE_ENABLED_BY_DEFAULT);
  1524. } // namespace
  1525. +#endif
  1526. bool RemoteLayerAPISupported() {
  1527. +#if !IS_MAS_BUILD()
  1528. if (!base::FeatureList::IsEnabled(kRemoteCoreAnimationAPI))
  1529. return false;
  1530. @@ -55,6 +59,9 @@ bool RemoteLayerAPISupported() {
  1531. // If everything is there, we should be able to use the API.
  1532. return true;
  1533. +#else
  1534. + return false;
  1535. +#endif // MAS_BUILD
  1536. }
  1537. } // namespace
  1538. diff --git a/ui/display/BUILD.gn b/ui/display/BUILD.gn
  1539. index 84afacf999c4905fdbaba332e19058a6471c3436..bbab402c8c11e62dad7fa946d9550efa3637dbda 100644
  1540. --- a/ui/display/BUILD.gn
  1541. +++ b/ui/display/BUILD.gn
  1542. @@ -130,6 +130,12 @@ component("display") {
  1543. "//ui/gfx/geometry",
  1544. ]
  1545. + if (is_mac) {
  1546. + deps += [
  1547. + "//electron/build/config:generate_mas_config"
  1548. + ]
  1549. + }
  1550. +
  1551. if (is_ios) {
  1552. deps += [ "//build:ios_buildflags" ]
  1553. }
  1554. diff --git a/ui/display/mac/screen_mac.mm b/ui/display/mac/screen_mac.mm
  1555. index 29ae2da6a8a2c2a612dfb92f7f9c03ca5fa306b1..440c139a32a0c205e77b657d4aab64684661a01d 100644
  1556. --- a/ui/display/mac/screen_mac.mm
  1557. +++ b/ui/display/mac/screen_mac.mm
  1558. @@ -30,6 +30,7 @@
  1559. #include "base/trace_event/trace_event.h"
  1560. #include "build/build_config.h"
  1561. #include "components/device_event_log/device_event_log.h"
  1562. +#include "electron/mas.h"
  1563. #include "ui/display/display.h"
  1564. #include "ui/display/display_change_notifier.h"
  1565. #include "ui/display/util/display_util.h"
  1566. @@ -176,7 +177,17 @@ DisplayMac BuildDisplayForScreen(NSScreen* screen) {
  1567. display.set_color_depth(Display::kDefaultBitsPerPixel);
  1568. display.set_depth_per_component(Display::kDefaultBitsPerComponent);
  1569. }
  1570. +#if IS_MAS_BUILD()
  1571. + // This is equivalent to the CGDisplayUsesForceToGray() API as at 2018-08-06,
  1572. + // but avoids usage of the private API.
  1573. + CFStringRef app = CFSTR("com.apple.CoreGraphics");
  1574. + CFStringRef key = CFSTR("DisplayUseForcedGray");
  1575. + Boolean key_valid = false;
  1576. + display.set_is_monochrome(
  1577. + CFPreferencesGetAppBooleanValue(key, app, &key_valid));
  1578. +#else
  1579. display.set_is_monochrome(CGDisplayUsesForceToGray());
  1580. +#endif
  1581. // Query the display's refresh rate.
  1582. if (@available(macos 12.0, *)) {
  1583. diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
  1584. index 762ffff0e4a7ffc40e85dc82f5f0f243a447a85d..db4fbc65fded3beb58e6c336e1d4c4d33d3b2c25 100644
  1585. --- a/ui/gfx/BUILD.gn
  1586. +++ b/ui/gfx/BUILD.gn
  1587. @@ -335,6 +335,12 @@ component("gfx") {
  1588. "//ui/base:ui_data_pack",
  1589. ]
  1590. + if (is_mac) {
  1591. + deps += [
  1592. + "//electron/build/config:generate_mas_config"
  1593. + ]
  1594. + }
  1595. +
  1596. if (!is_apple) {
  1597. sources += [
  1598. "platform_font_skia.cc",
  1599. diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm
  1600. index fe3f85073e31de487a08e57d7f9b07aa4eccf8f3..cf5b07203c8bd559a404600cc98cc8eccdefd4d7 100644
  1601. --- a/ui/gfx/platform_font_mac.mm
  1602. +++ b/ui/gfx/platform_font_mac.mm
  1603. @@ -19,6 +19,7 @@
  1604. #include "base/numerics/safe_conversions.h"
  1605. #include "base/strings/sys_string_conversions.h"
  1606. #include "base/strings/utf_string_conversions.h"
  1607. +#include "electron/mas.h"
  1608. #include "third_party/skia/include/ports/SkTypeface_mac.h"
  1609. #include "ui/gfx/canvas.h"
  1610. #include "ui/gfx/font.h"
  1611. @@ -28,9 +29,11 @@
  1612. using Weight = Font::Weight;
  1613. +#if !IS_MAS_BUILD()
  1614. extern "C" {
  1615. bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
  1616. }
  1617. +#endif
  1618. namespace {
  1619. @@ -250,7 +253,13 @@ CTFontRef SystemFontForConstructorOfType(
  1620. // TODO(avi, etienneb): Figure out this font stuff.
  1621. base::apple::ScopedCFTypeRef<CTFontDescriptorRef> descriptor(
  1622. CTFontCopyFontDescriptor(font));
  1623. +#if IS_MAS_BUILD()
  1624. + CFNumberRef priority = (CFNumberRef)CTFontDescriptorCopyAttribute(descriptor.get(), (CFStringRef)kCTFontPriorityAttribute);
  1625. + SInt64 v;
  1626. + if (CFNumberGetValue(priority, kCFNumberSInt64Type, &v) && v == kCTFontPrioritySystem) {
  1627. +#else
  1628. if (CTFontDescriptorIsSystemUIFont(descriptor.get())) {
  1629. +#endif
  1630. // Assume it's the standard system font. The fact that this much is known is
  1631. // enough.
  1632. return PlatformFontMac::SystemFontType::kGeneral;
  1633. diff --git a/ui/views/BUILD.gn b/ui/views/BUILD.gn
  1634. index 02473f891423617ae9b386d8d8628a4c418ebb2a..8dc033eb0d8cf11cc1d63f050da599454c391b7a 100644
  1635. --- a/ui/views/BUILD.gn
  1636. +++ b/ui/views/BUILD.gn
  1637. @@ -723,6 +723,8 @@ component("views") {
  1638. "IOSurface.framework",
  1639. "QuartzCore.framework",
  1640. ]
  1641. +
  1642. + deps += ["//electron/build/config:generate_mas_config"]
  1643. }
  1644. if (is_win) {
  1645. @@ -1153,6 +1155,8 @@ source_set("test_support") {
  1646. "//ui/base/mojom:ui_base_types",
  1647. ]
  1648. + deps += ["//electron/build/config:generate_mas_config"]
  1649. +
  1650. if (is_win) {
  1651. sources += [
  1652. "test/desktop_window_tree_host_win_test_api.cc",
  1653. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1654. index 81979cdb6c5dbad84ea67ef9014ce4027bcdc161..daeda64747dcbcd05f34e77079be701c5b281e7d 100644
  1655. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1656. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  1657. @@ -18,6 +18,7 @@
  1658. #include "components/remote_cocoa/browser/scoped_cg_window_id.h"
  1659. #include "components/remote_cocoa/common/native_widget_ns_window.mojom.h"
  1660. #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
  1661. +#include "electron/mas.h"
  1662. #include "mojo/public/cpp/bindings/associated_receiver.h"
  1663. #include "mojo/public/cpp/bindings/associated_remote.h"
  1664. #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
  1665. @@ -32,7 +33,9 @@
  1666. #include "ui/views/window/dialog_observer.h"
  1667. @class NativeWidgetMacNSWindow;
  1668. +#if !IS_MAS_BUILD()
  1669. @class NSAccessibilityRemoteUIElement;
  1670. +#endif
  1671. @class NSView;
  1672. namespace remote_cocoa {
  1673. @@ -483,10 +486,12 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  1674. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  1675. remote_ns_window_remote_;
  1676. +#if !IS_MAS_BUILD()
  1677. // Remote accessibility objects corresponding to the NSWindow and its root
  1678. // NSView.
  1679. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  1680. NSAccessibilityRemoteUIElement* __strong remote_view_accessible_;
  1681. +#endif
  1682. // Used to force the NSApplication's focused accessibility element to be the
  1683. // views::Views accessibility tree when the NSView for this is focused.
  1684. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1685. index 9a915cb0c36b224b8b95fa84bc1909de4283776f..e402df17b4e7273c850d0bd822019ee9d0f669a9 100644
  1686. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1687. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  1688. @@ -21,6 +21,7 @@
  1689. #include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
  1690. #include "components/remote_cocoa/browser/ns_view_ids.h"
  1691. #include "components/remote_cocoa/browser/window.h"
  1692. +#include "electron/mas.h"
  1693. #include "mojo/public/cpp/bindings/self_owned_associated_receiver.h"
  1694. #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
  1695. #include "ui/accessibility/accessibility_features.h"
  1696. @@ -349,7 +350,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1697. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  1698. if (in_process_ns_window_bridge_)
  1699. return in_process_ns_window_bridge_->ns_view();
  1700. +#if !IS_MAS_BUILD()
  1701. return remote_view_accessible_;
  1702. +#else
  1703. + return nullptr;
  1704. +#endif
  1705. }
  1706. gfx::NativeViewAccessible
  1707. @@ -364,7 +369,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1708. return [in_process_ns_window_bridge_->ns_view() window];
  1709. }
  1710. +#if !IS_MAS_BUILD()
  1711. return remote_window_accessible_;
  1712. +#else
  1713. + return nullptr;
  1714. +#endif
  1715. }
  1716. remote_cocoa::mojom::NativeWidgetNSWindow*
  1717. @@ -1333,9 +1342,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1718. // for PWAs. However this breaks accessibility on in-process windows,
  1719. // so set it back to NO when a local window gains focus. See
  1720. // https://crbug.com/41485830.
  1721. +#if !IS_MAS_BUILD()
  1722. if (is_key && features::IsAccessibilityRemoteUIAppEnabled()) {
  1723. [NSAccessibilityRemoteUIElement setRemoteUIApp:!!application_host_];
  1724. }
  1725. +#endif
  1726. // Explicitly set the keyboard accessibility state on regaining key
  1727. // window status.
  1728. if (is_key && is_content_first_responder)
  1729. @@ -1474,17 +1485,20 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1730. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  1731. const std::vector<uint8_t>& window_token,
  1732. const std::vector<uint8_t>& view_token) {
  1733. +#if !IS_MAS_BUILD()
  1734. remote_window_accessible_ =
  1735. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  1736. remote_view_accessible_ =
  1737. ui::RemoteAccessibility::GetRemoteElementFromToken(view_token);
  1738. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_];
  1739. [remote_view_accessible_ setTopLevelUIElement:remote_window_accessible_];
  1740. +#endif
  1741. }
  1742. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  1743. base::ProcessId* pid,
  1744. std::vector<uint8_t>* token) {
  1745. +#if !IS_MAS_BUILD()
  1746. *pid = getpid();
  1747. id element_id = GetNativeViewAccessible();
  1748. @@ -1497,6 +1511,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  1749. }
  1750. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  1751. +#endif
  1752. return true;
  1753. }
  1754. diff --git a/ui/views/controls/webview/BUILD.gn b/ui/views/controls/webview/BUILD.gn
  1755. index 111d6432586f47833dde50678b908c76ad88d37a..429ca4402652a2d89ead228d92971f0cb3b6222c 100644
  1756. --- a/ui/views/controls/webview/BUILD.gn
  1757. +++ b/ui/views/controls/webview/BUILD.gn
  1758. @@ -46,6 +46,12 @@ component("webview") {
  1759. "//url",
  1760. ]
  1761. + if (is_mac) {
  1762. + deps += [
  1763. + "//electron/build/config:generate_mas_config",
  1764. + ]
  1765. + }
  1766. +
  1767. public_deps = [
  1768. "//base",
  1769. "//content/public/browser",