mas_disable_remote_accessibility.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 306db835fe203f663b1d84dd3490b619eb3f60b2..7a41d7afe6197e0a78934206782b1063f77f707a 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. +#ifndef 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_.get();
  25. +#else
  26. + return nil;
  27. +#endif
  28. }
  29. void DispatchKeyEvent(ui::KeyEvent* event) override {
  30. bool event_handled = false;
  31. @@ -99,8 +103,10 @@ void GetWordAt(const gfx::Point& location_in_content,
  32. mojo::AssociatedRemote<mojom::TextInputHost> text_input_host_remote_;
  33. std::unique_ptr<NativeWidgetNSWindowBridge> bridge_;
  34. +#ifndef MAS_BUILD
  35. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  36. remote_accessibility_element_;
  37. +#endif
  38. };
  39. } // namespace
  40. 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
  41. index 4719512943b8c3930bca35a226fc3e635021c109..55292d12f486cd9b954398fcf407c9b88ca5fd47 100644
  42. --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  43. +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  44. @@ -565,10 +565,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
  45. // this should be treated as an error and caught early.
  46. CHECK(bridged_view_);
  47. +#ifndef MAS_BUILD
  48. // Send the accessibility tokens for the NSView now that it exists.
  49. host_->SetRemoteAccessibilityTokens(
  50. ui::RemoteAccessibility::GetTokenForLocalElement(window_),
  51. ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
  52. +#endif
  53. // Beware: This view was briefly removed (in favor of a bare CALayer) in
  54. // crrev/c/1236675. The ordering of unassociated layers relative to NSView
  55. 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
  56. index be7b05ee4f779ccc44e6eea7ff7fb3e8bd504d6f..3b3336913cf91c3b7f22cefb4139f82b882c97c9 100644
  57. --- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  58. +++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  59. @@ -77,8 +77,10 @@ id GetFocusedBrowserAccessibilityElement() override {
  60. return nil;
  61. }
  62. void SetAccessibilityWindow(NSWindow* window) override {
  63. +#ifndef MAS_BUILD
  64. host_->SetRemoteAccessibilityWindowToken(
  65. ui::RemoteAccessibility::GetTokenForLocalElement(window));
  66. +#endif
  67. }
  68. void ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& key_event,
  69. @@ -140,8 +142,10 @@ void SmartMagnify(const blink::WebGestureEvent& web_event) override {
  70. mojo::AssociatedRemote<mojom::RenderWidgetHostNSViewHost> host_;
  71. std::unique_ptr<RenderWidgetHostNSViewBridge> bridge_;
  72. +#ifndef MAS_BUILD
  73. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  74. remote_accessibility_element_;
  75. +#endif
  76. };
  77. }
  78. diff --git a/content/browser/accessibility/browser_accessibility_manager_mac.mm b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  79. index c107750255b441061d03f8a38df5b28173c05f31..7093e185839095c21f6ea7cf4e88692407fd8cf5 100644
  80. --- a/content/browser/accessibility/browser_accessibility_manager_mac.mm
  81. +++ b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  82. @@ -21,7 +21,9 @@
  83. #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
  84. #include "ui/accessibility/ax_role_properties.h"
  85. #include "ui/accessibility/platform/ax_private_webkit_constants_mac.h"
  86. +#ifndef MAS_BUILD
  87. #include "ui/base/cocoa/remote_accessibility_api.h"
  88. +#endif
  89. namespace {
  90. @@ -614,6 +616,7 @@ void PostAnnouncementNotification(NSString* announcement) {
  91. if ([NSApp isActive])
  92. return window == [NSApp accessibilityFocusedWindow];
  93. +#ifndef MAS_BUILD
  94. // TODO(accessibility): We need a solution to the problem described below.
  95. // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
  96. // 1. NSApp is the browser which spawned the PWA, and what it considers the
  97. @@ -641,6 +644,7 @@ void PostAnnouncementNotification(NSString* announcement) {
  98. // from within the app shim content.
  99. if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]])
  100. return true;
  101. +#endif
  102. return false;
  103. }
  104. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  105. index 0549e3b400cb42e1a3491a2de9739c275ae006df..ab59ea7211b425e36d3d0fa673d8c09b99140716 100644
  106. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  107. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  108. @@ -52,7 +52,9 @@ class ScopedPasswordInputEnabler;
  109. @protocol RenderWidgetHostViewMacDelegate;
  110. +#ifndef MAS_BUILD
  111. @class NSAccessibilityRemoteUIElement;
  112. +#endif
  113. @class RenderWidgetHostViewCocoa;
  114. namespace content {
  115. @@ -668,10 +670,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  116. // EnsureSurfaceSynchronizedForWebTest().
  117. uint32_t latest_capture_sequence_number_ = 0u;
  118. +#ifndef MAS_BUILD
  119. // Remote accessibility objects corresponding to the NSWindow that this is
  120. // displayed to the user in.
  121. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  122. remote_window_accessible_;
  123. +#endif
  124. // Used to force the NSApplication's focused accessibility element to be the
  125. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  126. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  127. index 2d106cbcfd6fd63b95c0f322dda3dc926ebcc118..e0168e7cf64a783a96aa4e43fa3a80bfbbe1fbac 100644
  128. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  129. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  130. @@ -259,8 +259,10 @@
  131. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  132. remote_cocoa::mojom::Application* remote_cocoa_application,
  133. uint64_t parent_ns_view_id) {
  134. +#ifndef MAS_BUILD
  135. // Destroy the previous remote accessibility element.
  136. remote_window_accessible_.reset();
  137. +#endif
  138. // Disconnect from the previous bridge (this will have the effect of
  139. // destroying the associated bridge), and close the receiver (to allow it
  140. @@ -1566,8 +1568,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  141. gfx::NativeViewAccessible
  142. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  143. +#ifndef MAS_BUILD
  144. if (remote_window_accessible_)
  145. return remote_window_accessible_.get();
  146. +#endif
  147. return [GetInProcessNSView() window];
  148. }
  149. @@ -1611,9 +1615,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  150. }
  151. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  152. +#ifndef MAS_BUILD
  153. // When running in-process, just use the NSView's NSWindow as its own
  154. // accessibility element.
  155. remote_window_accessible_.reset();
  156. +#endif
  157. }
  158. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  159. @@ -2108,12 +2114,14 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  160. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  161. const std::vector<uint8_t>& window_token) {
  162. +#ifndef MAS_BUILD
  163. if (window_token.empty()) {
  164. remote_window_accessible_.reset();
  165. } else {
  166. remote_window_accessible_ =
  167. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  168. }
  169. +#endif
  170. }
  171. ///////////////////////////////////////////////////////////////////////////////
  172. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  173. index 2c4a0c7dde08353221b5e2747b00c72cf4818137..64375989d127bd4b2990c9ee8fc10c24de9de30e 100644
  174. --- a/ui/base/BUILD.gn
  175. +++ b/ui/base/BUILD.gn
  176. @@ -341,6 +341,13 @@ component("base") {
  177. sources += [ "resource/resource_bundle_lacros.cc" ]
  178. }
  179. + if (is_mas_build) {
  180. + sources -= [
  181. + "cocoa/remote_accessibility_api.h",
  182. + "cocoa/remote_accessibility_api.mm",
  183. + ]
  184. + }
  185. +
  186. if (is_ios) {
  187. sources += [
  188. "device_form_factor_ios.mm",
  189. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  190. index e7adfee3210ec723c687adfcc4bee8827ef643e7..25a924a47eeb30d783ef83dbb4896c4bed139a27 100644
  191. --- a/ui/base/cocoa/remote_accessibility_api.h
  192. +++ b/ui/base/cocoa/remote_accessibility_api.h
  193. @@ -11,6 +11,8 @@
  194. #include "base/component_export.h"
  195. #include "base/mac/scoped_nsobject.h"
  196. +#ifndef MAS_BUILD
  197. +
  198. @interface NSAccessibilityRemoteUIElement : NSObject
  199. + (void)registerRemoteUIProcessIdentifier:(int)pid;
  200. + (NSData*)remoteTokenForLocalUIElement:(id)element;
  201. @@ -32,4 +34,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  202. } // namespace ui
  203. +#endif // MAS_BUILD
  204. +
  205. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  206. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  207. index 5a09100094d0371a3e58db6c7626e06bdcdd17c3..1aa7bde93efdf198998ba4e6a97dcf2aadd9f4e9 100644
  208. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  209. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  210. @@ -32,7 +32,9 @@
  211. #include "ui/views/window/dialog_observer.h"
  212. @class NativeWidgetMacNSWindow;
  213. +#ifndef MAS_BUILD
  214. @class NSAccessibilityRemoteUIElement;
  215. +#endif
  216. @class NSView;
  217. namespace remote_cocoa {
  218. @@ -449,11 +451,13 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  219. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  220. remote_ns_window_remote_;
  221. +#ifndef MAS_BUILD
  222. // Remote accessibility objects corresponding to the NSWindow and its root
  223. // NSView.
  224. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  225. remote_window_accessible_;
  226. base::scoped_nsobject<NSAccessibilityRemoteUIElement> remote_view_accessible_;
  227. +#endif
  228. // Used to force the NSApplication's focused accessibility element to be the
  229. // views::Views accessibility tree when the NSView for this is focused.
  230. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  231. index 1a4a33a111da65c7541c5b7bab430f58acb29e77..8f1b227bc7d1fcb5c30e6c0bdf4ee8677552ba57 100644
  232. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  233. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  234. @@ -327,14 +327,22 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  235. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  236. if (in_process_ns_window_bridge_)
  237. return in_process_ns_window_bridge_->ns_view();
  238. +#ifndef MAS_BUILD
  239. return remote_view_accessible_.get();
  240. +#else
  241. + return nullptr;
  242. +#endif
  243. }
  244. gfx::NativeViewAccessible
  245. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const {
  246. if (in_process_ns_window_bridge_)
  247. return in_process_ns_window_bridge_->ns_window();
  248. +#ifndef MAS_BUILD
  249. return remote_window_accessible_.get();
  250. +#else
  251. + return nullptr;
  252. +#endif
  253. }
  254. remote_cocoa::mojom::NativeWidgetNSWindow*
  255. @@ -1306,6 +1314,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  256. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  257. const std::vector<uint8_t>& window_token,
  258. const std::vector<uint8_t>& view_token) {
  259. +#ifndef MAS_BUILD
  260. remote_window_accessible_ =
  261. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  262. remote_view_accessible_ =
  263. @@ -1313,14 +1322,17 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  264. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_.get()];
  265. [remote_view_accessible_
  266. setTopLevelUIElement:remote_window_accessible_.get()];
  267. +#endif
  268. }
  269. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  270. int64_t* pid,
  271. std::vector<uint8_t>* token) {
  272. +#ifndef MAS_BUILD
  273. *pid = getpid();
  274. id element_id = GetNativeViewAccessible();
  275. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  276. +#endif
  277. return true;
  278. }