mas_disable_remote_accessibility.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 9ddda9116e7284cbccde8a51e23ad7560dd06367..e846091ad99b0154636489e53491209ff3cbfaaa 100644
  12. --- a/components/remote_cocoa/app_shim/application_bridge.mm
  13. +++ b/components/remote_cocoa/app_shim/application_bridge.mm
  14. @@ -49,6 +49,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. @@ -59,6 +60,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. @@ -96,8 +100,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 89e8a69b2bbb28fb90314b19c062b47d618b7038..e3f6be21487823d1d96945f163a7865119ce5605 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. @@ -557,10 +557,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 c3a9fbf0f9d2b80c1de42a22ad094a286f0b559b..02493d4b62c98a3aebd3e460c459218a4dc4ea8e 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. @@ -70,8 +70,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. @@ -133,8 +135,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. DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostNSViewBridgeOwner);
  77. };
  78. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  79. index ffa437e300635290525658642cc83882fd08231a..7616391e80408ce11817c078c0ad280ecda4b4e7 100644
  80. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  81. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  82. @@ -47,7 +47,9 @@ class ScopedPasswordInputEnabler;
  83. @protocol RenderWidgetHostViewMacDelegate;
  84. +#ifndef MAS_BUILD
  85. @class NSAccessibilityRemoteUIElement;
  86. +#endif
  87. @class RenderWidgetHostViewCocoa;
  88. namespace content {
  89. @@ -651,10 +653,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  90. // EnsureSurfaceSynchronizedForWebTest().
  91. uint32_t latest_capture_sequence_number_ = 0u;
  92. +#ifndef MAS_BUILD
  93. // Remote accessibility objects corresponding to the NSWindow that this is
  94. // displayed to the user in.
  95. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  96. remote_window_accessible_;
  97. +#endif
  98. // Used to force the NSApplication's focused accessibility element to be the
  99. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  100. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  101. index cdbfdb7b904533c72721e7605ca801b5e79c51fb..23d00ebbd6563a2bee1c79819c3745f56ad6f53b 100644
  102. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  103. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  104. @@ -240,8 +240,10 @@
  105. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  106. remote_cocoa::mojom::Application* remote_cocoa_application,
  107. uint64_t parent_ns_view_id) {
  108. +#ifndef MAS_BUILD
  109. // Destroy the previous remote accessibility element.
  110. remote_window_accessible_.reset();
  111. +#endif
  112. // Disconnect from the previous bridge (this will have the effect of
  113. // destroying the associated bridge), and close the receiver (to allow it
  114. @@ -1438,8 +1440,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  115. gfx::NativeViewAccessible
  116. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  117. +#ifndef MAS_BUILD
  118. if (remote_window_accessible_)
  119. return remote_window_accessible_.get();
  120. +#endif
  121. return [GetInProcessNSView() window];
  122. }
  123. @@ -1483,9 +1487,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  124. }
  125. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  126. +#ifndef MAS_BUILD
  127. // When running in-process, just use the NSView's NSWindow as its own
  128. // accessibility element.
  129. remote_window_accessible_.reset();
  130. +#endif
  131. }
  132. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  133. @@ -1979,12 +1985,14 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  134. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  135. const std::vector<uint8_t>& window_token) {
  136. +#ifndef MAS_BUILD
  137. if (window_token.empty()) {
  138. remote_window_accessible_.reset();
  139. } else {
  140. remote_window_accessible_ =
  141. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  142. }
  143. +#endif
  144. }
  145. ///////////////////////////////////////////////////////////////////////////////
  146. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  147. index 898f3292fafc7b8fcb4e290c61f5b1395c94376d..47c8dbe3b11420f399cdacaf8390280ba163392f 100644
  148. --- a/ui/base/BUILD.gn
  149. +++ b/ui/base/BUILD.gn
  150. @@ -320,6 +320,13 @@ component("base") {
  151. ]
  152. }
  153. + if (is_mas_build) {
  154. + sources -= [
  155. + "cocoa/remote_accessibility_api.h",
  156. + "cocoa/remote_accessibility_api.mm",
  157. + ]
  158. + }
  159. +
  160. if (is_ios) {
  161. sources += [
  162. "device_form_factor_ios.mm",
  163. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  164. index e7adfee3210ec723c687adfcc4bee8827ef643e7..25a924a47eeb30d783ef83dbb4896c4bed139a27 100644
  165. --- a/ui/base/cocoa/remote_accessibility_api.h
  166. +++ b/ui/base/cocoa/remote_accessibility_api.h
  167. @@ -11,6 +11,8 @@
  168. #include "base/component_export.h"
  169. #include "base/mac/scoped_nsobject.h"
  170. +#ifndef MAS_BUILD
  171. +
  172. @interface NSAccessibilityRemoteUIElement : NSObject
  173. + (void)registerRemoteUIProcessIdentifier:(int)pid;
  174. + (NSData*)remoteTokenForLocalUIElement:(id)element;
  175. @@ -32,4 +34,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  176. } // namespace ui
  177. +#endif // MAS_BUILD
  178. +
  179. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  180. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  181. index 9f5543d22e7a72dc7ca031e04434279b5066215c..2eaaa54778f1f5d450389967ae77c5e4d578eb04 100644
  182. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  183. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  184. @@ -30,7 +30,9 @@
  185. #include "ui/views/window/dialog_observer.h"
  186. @class NativeWidgetMacNSWindow;
  187. +#ifndef MAS_BUILD
  188. @class NSAccessibilityRemoteUIElement;
  189. +#endif
  190. @class NSView;
  191. namespace remote_cocoa {
  192. @@ -420,11 +422,13 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  193. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  194. remote_ns_window_remote_;
  195. +#ifndef MAS_BUILD
  196. // Remote accessibility objects corresponding to the NSWindow and its root
  197. // NSView.
  198. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  199. remote_window_accessible_;
  200. base::scoped_nsobject<NSAccessibilityRemoteUIElement> remote_view_accessible_;
  201. +#endif
  202. // Used to force the NSApplication's focused accessibility element to be the
  203. // views::Views accessibility tree when the NSView for this is focused.
  204. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  205. index a756f7b856196606c1cd4fc26e8a907d9891d36c..2dce88094b9a697bd7f4d85a69294a098a2dd427 100644
  206. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  207. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  208. @@ -285,14 +285,22 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  209. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  210. if (in_process_ns_window_bridge_)
  211. return in_process_ns_window_bridge_->ns_view();
  212. +#ifndef MAS_BUILD
  213. return remote_view_accessible_.get();
  214. +#else
  215. + return nullptr;
  216. +#endif
  217. }
  218. gfx::NativeViewAccessible
  219. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const {
  220. if (in_process_ns_window_bridge_)
  221. return in_process_ns_window_bridge_->ns_window();
  222. +#ifndef MAS_BUILD
  223. return remote_window_accessible_.get();
  224. +#else
  225. + return nullptr;
  226. +#endif
  227. }
  228. remote_cocoa::mojom::NativeWidgetNSWindow*
  229. @@ -1197,6 +1205,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  230. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  231. const std::vector<uint8_t>& window_token,
  232. const std::vector<uint8_t>& view_token) {
  233. +#ifndef MAS_BUILD
  234. remote_window_accessible_ =
  235. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  236. remote_view_accessible_ =
  237. @@ -1204,14 +1213,17 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
  238. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_.get()];
  239. [remote_view_accessible_
  240. setTopLevelUIElement:remote_window_accessible_.get()];
  241. +#endif
  242. }
  243. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  244. int64_t* pid,
  245. std::vector<uint8_t>* token) {
  246. +#ifndef MAS_BUILD
  247. *pid = getpid();
  248. id element_id = GetNativeViewAccessible();
  249. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  250. +#endif
  251. return true;
  252. }