mas_avoid_private_macos_api_usage.patch.patch 71 KB

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