mas_disable_remote_accessibility.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 20 Sep 2018 17:48:49 -0700
  4. Subject: mas: avoid usage of NSAccessibilityRemoteUIElement
  5. According to ccameron:
  6. NSAccessibilityRemoteUIElement is unnecessary for Electron's use-case. We use it
  7. for progressive web apps (where the AXTree is in the browser process, but macOS
  8. needs to think it's coming from the PWA process). I think it can just be chopped
  9. out -- if there are any side-effects, we should be able to work around them.
  10. diff --git a/components/remote_cocoa/app_shim/application_bridge.mm b/components/remote_cocoa/app_shim/application_bridge.mm
  11. index 5a096477c123a782341115f964c4975301ccaf9a..ecfbb3b405425af346a6ba6788fc1d8ff89760cd 100644
  12. --- a/components/remote_cocoa/app_shim/application_bridge.mm
  13. +++ b/components/remote_cocoa/app_shim/application_bridge.mm
  14. @@ -51,6 +51,7 @@
  15. // NativeWidgetNSWindowHostHelper:
  16. id GetNativeViewAccessible() override {
  17. +#if !IS_MAS_BUILD()
  18. if (!remote_accessibility_element_) {
  19. int64_t browser_pid = 0;
  20. std::vector<uint8_t> element_token;
  21. @@ -61,6 +62,9 @@ id GetNativeViewAccessible() override {
  22. ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
  23. }
  24. return remote_accessibility_element_;
  25. +#else
  26. + return nil;
  27. +#endif
  28. }
  29. void DispatchKeyEvent(ui::KeyEvent* event) override {
  30. bool event_handled = false;
  31. @@ -99,7 +103,9 @@ void GetWordAt(const gfx::Point& location_in_content,
  32. mojo::AssociatedRemote<mojom::TextInputHost> text_input_host_remote_;
  33. std::unique_ptr<NativeWidgetNSWindowBridge> bridge_;
  34. +#if !IS_MAS_BUILD()
  35. NSAccessibilityRemoteUIElement* __strong remote_accessibility_element_;
  36. +#endif
  37. };
  38. } // namespace
  39. 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
  40. index c4285bf227abf1536213835ebdb8ca16d2638263..73c27518cab1efbbd2e4ec334b8685bd25d6d693 100644
  41. --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  42. +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  43. @@ -587,10 +587,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
  44. // this should be treated as an error and caught early.
  45. CHECK(bridged_view_);
  46. +#if !IS_MAS_BUILD()
  47. // Send the accessibility tokens for the NSView now that it exists.
  48. host_->SetRemoteAccessibilityTokens(
  49. ui::RemoteAccessibility::GetTokenForLocalElement(window_),
  50. ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
  51. +#endif
  52. // Beware: This view was briefly removed (in favor of a bare CALayer) in
  53. // https://crrev.com/c/1236675. The ordering of unassociated layers relative
  54. 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
  55. index 8fe41069ae9578a75469b40413b8e796792527cf..c5da46f4cc173eeb28c58bc464acd55ec9e4fc9e 100644
  56. --- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  57. +++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  58. @@ -86,8 +86,10 @@ id GetFocusedBrowserAccessibilityElement() override {
  59. return nil;
  60. }
  61. void SetAccessibilityWindow(NSWindow* window) override {
  62. +#if !IS_MAS_BUILD()
  63. host_->SetRemoteAccessibilityWindowToken(
  64. ui::RemoteAccessibility::GetTokenForLocalElement(window));
  65. +#endif
  66. }
  67. void ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& key_event,
  68. diff --git a/content/browser/accessibility/browser_accessibility_manager_mac.mm b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  69. index 45aeb6838a859f57287bec51f79a4eb77d69b619..6f5c28de251d4f6db9b07b37d0b513c2cc2826b3 100644
  70. --- a/content/browser/accessibility/browser_accessibility_manager_mac.mm
  71. +++ b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  72. @@ -21,7 +21,9 @@
  73. #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
  74. #include "ui/accessibility/ax_role_properties.h"
  75. #include "ui/accessibility/platform/ax_private_webkit_constants_mac.h"
  76. +#if !IS_MAS_BUILD()
  77. #include "ui/base/cocoa/remote_accessibility_api.h"
  78. +#endif
  79. namespace {
  80. @@ -224,6 +226,7 @@ void PostAnnouncementNotification(NSString* announcement,
  81. return;
  82. }
  83. +#if !IS_MAS_BUILD()
  84. BrowserAccessibilityManager* root_manager = GetManagerForRootFrame();
  85. if (root_manager) {
  86. BrowserAccessibilityManagerMac* root_manager_mac =
  87. @@ -246,6 +249,7 @@ void PostAnnouncementNotification(NSString* announcement,
  88. return;
  89. }
  90. }
  91. +#endif
  92. // Use native VoiceOver support for live regions.
  93. BrowserAccessibilityCocoa* retained_node = native_node;
  94. @@ -627,6 +631,7 @@ void PostAnnouncementNotification(NSString* announcement,
  95. if ([NSApp isActive])
  96. return window == [NSApp accessibilityFocusedWindow];
  97. +#if !IS_MAS_BUILD()
  98. // TODO(accessibility): We need a solution to the problem described below.
  99. // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
  100. // 1. NSApp is the browser which spawned the PWA, and what it considers the
  101. @@ -654,6 +659,7 @@ void PostAnnouncementNotification(NSString* announcement,
  102. // from within the app shim content.
  103. if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]])
  104. return true;
  105. +#endif
  106. return false;
  107. }
  108. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  109. index fd35d3a94113f1337b097cfa4bf40d8330504e5a..04bd16db3b8a23b9e5d90ced459c440a34ffa375 100644
  110. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  111. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  112. @@ -49,7 +49,9 @@ class ScopedPasswordInputEnabler;
  113. @protocol RenderWidgetHostViewMacDelegate;
  114. +#if !IS_MAS_BUILD()
  115. @class NSAccessibilityRemoteUIElement;
  116. +#endif
  117. @class RenderWidgetHostViewCocoa;
  118. namespace content {
  119. @@ -667,9 +669,11 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  120. // EnsureSurfaceSynchronizedForWebTest().
  121. uint32_t latest_capture_sequence_number_ = 0u;
  122. +#if !IS_MAS_BUILD()
  123. // Remote accessibility objects corresponding to the NSWindow that this is
  124. // displayed to the user in.
  125. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  126. +#endif
  127. // Used to force the NSApplication's focused accessibility element to be the
  128. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  129. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  130. index b8d1f98c9c7c5831677d4c200aa085a4a168273c..7f2b627031f65ad45a8ad182d3b7421005893ff4 100644
  131. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  132. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  133. @@ -263,8 +263,10 @@
  134. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  135. remote_cocoa::mojom::Application* remote_cocoa_application,
  136. uint64_t parent_ns_view_id) {
  137. +#if !IS_MAS_BUILD()
  138. // Destroy the previous remote accessibility element.
  139. remote_window_accessible_ = nil;
  140. +#endif
  141. // Reset `ns_view_` before resetting `remote_ns_view_` to avoid dangling
  142. // pointers. `ns_view_` gets reinitialized later in this method.
  143. @@ -1614,8 +1616,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  144. gfx::NativeViewAccessible
  145. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  146. +#if !IS_MAS_BUILD()
  147. if (remote_window_accessible_)
  148. return remote_window_accessible_;
  149. +#endif
  150. return [GetInProcessNSView() window];
  151. }
  152. @@ -1659,9 +1663,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  153. }
  154. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  155. +#if !IS_MAS_BUILD()
  156. // When running in-process, just use the NSView's NSWindow as its own
  157. // accessibility element.
  158. remote_window_accessible_ = nil;
  159. +#endif
  160. }
  161. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  162. @@ -2163,12 +2169,14 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  163. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  164. const std::vector<uint8_t>& window_token) {
  165. +#if !IS_MAS_BUILD()
  166. if (window_token.empty()) {
  167. remote_window_accessible_ = nil;
  168. } else {
  169. remote_window_accessible_ =
  170. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  171. }
  172. +#endif
  173. }
  174. ///////////////////////////////////////////////////////////////////////////////
  175. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  176. index 121d8798571233799624a1e187b0f0edfdb9ca98..9233e89712a12e27d85232fb51f113f41375a08a 100644
  177. --- a/ui/base/BUILD.gn
  178. +++ b/ui/base/BUILD.gn
  179. @@ -373,6 +373,13 @@ component("base") {
  180. sources += [ "resource/resource_bundle_lacros.cc" ]
  181. }
  182. + if (is_mas_build) {
  183. + sources -= [
  184. + "cocoa/remote_accessibility_api.h",
  185. + "cocoa/remote_accessibility_api.mm",
  186. + ]
  187. + }
  188. +
  189. if (is_ios) {
  190. sources += [
  191. "device_form_factor_ios.mm",
  192. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  193. index 835cce73b7ab8b38c37d3e2650e12303d9d918e3..4460a00497dfaee0ba90cd5d14888055ed8a2830 100644
  194. --- a/ui/base/cocoa/remote_accessibility_api.h
  195. +++ b/ui/base/cocoa/remote_accessibility_api.h
  196. @@ -13,6 +13,8 @@
  197. // NSAccessibilityRemoteUIElement is a private class in AppKit.
  198. +#if !IS_MAS_BUILD()
  199. +
  200. @interface NSAccessibilityRemoteUIElement : NSObject
  201. + (void)registerRemoteUIProcessIdentifier:(int)pid;
  202. + (NSData*)remoteTokenForLocalUIElement:(id)element;
  203. @@ -34,4 +36,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  204. } // namespace ui
  205. +#endif // MAS_BUILD
  206. +
  207. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  208. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  209. index 58f1b79111a0be5102976c3e257375c409c1c4be..be0306b98feb451fefeec70becbcf51612d22283 100644
  210. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  211. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  212. @@ -30,7 +30,9 @@
  213. #include "ui/views/window/dialog_observer.h"
  214. @class NativeWidgetMacNSWindow;
  215. +#if !IS_MAS_BUILD()
  216. @class NSAccessibilityRemoteUIElement;
  217. +#endif
  218. @class NSView;
  219. namespace remote_cocoa {
  220. @@ -450,10 +452,12 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  221. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  222. remote_ns_window_remote_;
  223. +#if !IS_MAS_BUILD()
  224. // Remote accessibility objects corresponding to the NSWindow and its root
  225. // NSView.
  226. NSAccessibilityRemoteUIElement* __strong remote_window_accessible_;
  227. NSAccessibilityRemoteUIElement* __strong remote_view_accessible_;
  228. +#endif
  229. // Used to force the NSApplication's focused accessibility element to be the
  230. // views::Views accessibility tree when the NSView for this is focused.
  231. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  232. index 42b7016e880b26e2cc8b9da14917907d4826440c..f6b588c059d6706155144f3b0a9a8861d8f1146d 100644
  233. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  234. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  235. @@ -339,7 +339,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  236. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  237. if (in_process_ns_window_bridge_)
  238. return in_process_ns_window_bridge_->ns_view();
  239. +#if !IS_MAS_BUILD()
  240. return remote_view_accessible_;
  241. +#else
  242. + return nullptr;
  243. +#endif
  244. }
  245. gfx::NativeViewAccessible
  246. @@ -354,7 +358,11 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  247. return [in_process_ns_window_bridge_->ns_view() window];
  248. }
  249. +#if !IS_MAS_BUILD()
  250. return remote_window_accessible_;
  251. +#else
  252. + return nullptr;
  253. +#endif
  254. }
  255. remote_cocoa::mojom::NativeWidgetNSWindow*
  256. @@ -1326,20 +1334,24 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  257. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  258. const std::vector<uint8_t>& window_token,
  259. const std::vector<uint8_t>& view_token) {
  260. +#if !IS_MAS_BUILD()
  261. remote_window_accessible_ =
  262. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  263. remote_view_accessible_ =
  264. ui::RemoteAccessibility::GetRemoteElementFromToken(view_token);
  265. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_];
  266. [remote_view_accessible_ setTopLevelUIElement:remote_window_accessible_];
  267. +#endif
  268. }
  269. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  270. int64_t* pid,
  271. std::vector<uint8_t>* token) {
  272. +#if !IS_MAS_BUILD()
  273. *pid = getpid();
  274. id element_id = GetNativeViewAccessible();
  275. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  276. +#endif
  277. return true;
  278. }