mas_disable_remote_accessibility.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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_disable_remote_accessibility.patch
  5. Disable remote accessibility APIs (NSAccessibilityRemoteUIElement) for MAS
  6. build.
  7. According to ccameron:
  8. NSAccessibilityRemoteUIElement is unnecessary for Electron's use-case. We use it
  9. for progressive web apps (where the AXTree is in the browser process, but macOS
  10. needs to think it's coming from the PWA process). I think it can just be chopped
  11. out -- if there are any side-effects, we should be able to work around them.
  12. diff --git a/components/remote_cocoa/app_shim/application_bridge.mm b/components/remote_cocoa/app_shim/application_bridge.mm
  13. index 9ddda9116e7284cbccde8a51e23ad7560dd06367..e846091ad99b0154636489e53491209ff3cbfaaa 100644
  14. --- a/components/remote_cocoa/app_shim/application_bridge.mm
  15. +++ b/components/remote_cocoa/app_shim/application_bridge.mm
  16. @@ -49,6 +49,7 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
  17. // NativeWidgetNSWindowHostHelper:
  18. id GetNativeViewAccessible() override {
  19. +#ifndef MAS_BUILD
  20. if (!remote_accessibility_element_) {
  21. int64_t browser_pid = 0;
  22. std::vector<uint8_t> element_token;
  23. @@ -59,6 +60,9 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
  24. ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
  25. }
  26. return remote_accessibility_element_.get();
  27. +#else
  28. + return nil;
  29. +#endif
  30. }
  31. void DispatchKeyEvent(ui::KeyEvent* event) override {
  32. bool event_handled = false;
  33. @@ -96,8 +100,10 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
  34. mojo::AssociatedRemote<mojom::TextInputHost> text_input_host_remote_;
  35. std::unique_ptr<NativeWidgetNSWindowBridge> bridge_;
  36. +#ifndef MAS_BUILD
  37. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  38. remote_accessibility_element_;
  39. +#endif
  40. };
  41. } // namespace
  42. 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
  43. index 2ee45cb069ec5d78d9c7a3f61fdd1d444a590f41..badc4323b910f8e3957583e05af303472cb204f6 100644
  44. --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  45. +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
  46. @@ -543,10 +543,12 @@ void NativeWidgetNSWindowBridge::CreateContentView(uint64_t ns_view_id,
  47. // this should be treated as an error and caught early.
  48. CHECK(bridged_view_);
  49. +#ifndef MAS_BUILD
  50. // Send the accessibility tokens for the NSView now that it exists.
  51. host_->SetRemoteAccessibilityTokens(
  52. ui::RemoteAccessibility::GetTokenForLocalElement(window_),
  53. ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
  54. +#endif
  55. // Beware: This view was briefly removed (in favor of a bare CALayer) in
  56. // crrev/c/1236675. The ordering of unassociated layers relative to NSView
  57. 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
  58. index c3a9fbf0f9d2b80c1de42a22ad094a286f0b559b..02493d4b62c98a3aebd3e460c459218a4dc4ea8e 100644
  59. --- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  60. +++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
  61. @@ -70,8 +70,10 @@ class RenderWidgetHostNSViewBridgeOwner
  62. return nil;
  63. }
  64. void SetAccessibilityWindow(NSWindow* window) override {
  65. +#ifndef MAS_BUILD
  66. host_->SetRemoteAccessibilityWindowToken(
  67. ui::RemoteAccessibility::GetTokenForLocalElement(window));
  68. +#endif
  69. }
  70. void ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& key_event,
  71. @@ -133,8 +135,10 @@ class RenderWidgetHostNSViewBridgeOwner
  72. mojo::AssociatedRemote<mojom::RenderWidgetHostNSViewHost> host_;
  73. std::unique_ptr<RenderWidgetHostNSViewBridge> bridge_;
  74. +#ifndef MAS_BUILD
  75. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  76. remote_accessibility_element_;
  77. +#endif
  78. DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostNSViewBridgeOwner);
  79. };
  80. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  81. index 51f91581aff32cd42b74c7086f51282cbc3629e8..8fa02de5ed90538923cd858a92f339daac686994 100644
  82. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  83. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  84. @@ -47,7 +47,9 @@ class ScopedPasswordInputEnabler;
  85. @protocol RenderWidgetHostViewMacDelegate;
  86. +#ifndef MAS_BUILD
  87. @class NSAccessibilityRemoteUIElement;
  88. +#endif
  89. @class RenderWidgetHostViewCocoa;
  90. namespace content {
  91. @@ -628,10 +630,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  92. // EnsureSurfaceSynchronizedForWebTest().
  93. uint32_t latest_capture_sequence_number_ = 0u;
  94. +#ifndef MAS_BUILD
  95. // Remote accessibility objects corresponding to the NSWindow that this is
  96. // displayed to the user in.
  97. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  98. remote_window_accessible_;
  99. +#endif
  100. // Used to force the NSApplication's focused accessibility element to be the
  101. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  102. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  103. index 026bb184e3ecf21185900d3102fbbdb4bc9e1100..aef2f3625465d5de36d0ce496f7133865a7ba18a 100644
  104. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  105. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  106. @@ -233,8 +233,10 @@ RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
  107. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  108. remote_cocoa::mojom::Application* remote_cocoa_application,
  109. uint64_t parent_ns_view_id) {
  110. +#ifndef MAS_BUILD
  111. // Destroy the previous remote accessibility element.
  112. remote_window_accessible_.reset();
  113. +#endif
  114. // Disconnect from the previous bridge (this will have the effect of
  115. // destroying the associated bridge), and close the receiver (to allow it
  116. @@ -1357,8 +1359,10 @@ RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessible() {
  117. gfx::NativeViewAccessible
  118. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  119. +#ifndef MAS_BUILD
  120. if (remote_window_accessible_)
  121. return remote_window_accessible_.get();
  122. +#endif
  123. return [GetInProcessNSView() window];
  124. }
  125. @@ -1390,9 +1394,11 @@ id RenderWidgetHostViewMac::GetFocusedBrowserAccessibilityElement() {
  126. }
  127. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  128. +#ifndef MAS_BUILD
  129. // When running in-process, just use the NSView's NSWindow as its own
  130. // accessibility element.
  131. remote_window_accessible_.reset();
  132. +#endif
  133. }
  134. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  135. @@ -1879,12 +1885,14 @@ void RenderWidgetHostViewMac::StopSpeaking() {
  136. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  137. const std::vector<uint8_t>& window_token) {
  138. +#ifndef MAS_BUILD
  139. if (window_token.empty()) {
  140. remote_window_accessible_.reset();
  141. } else {
  142. remote_window_accessible_ =
  143. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  144. }
  145. +#endif
  146. }
  147. ///////////////////////////////////////////////////////////////////////////////
  148. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  149. index 3241093ca37134435507b6cfb7d9663317563860..aace5b11a419cdbb0e257dd3ba2329e9ea013c6a 100644
  150. --- a/ui/base/BUILD.gn
  151. +++ b/ui/base/BUILD.gn
  152. @@ -311,6 +311,13 @@ jumbo_component("base") {
  153. ]
  154. }
  155. + if (is_mas_build) {
  156. + sources -= [
  157. + "cocoa/remote_accessibility_api.h",
  158. + "cocoa/remote_accessibility_api.mm",
  159. + ]
  160. + }
  161. +
  162. if (is_posix) {
  163. sources += [ "l10n/l10n_util_posix.cc" ]
  164. }
  165. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  166. index e7adfee3210ec723c687adfcc4bee8827ef643e7..25a924a47eeb30d783ef83dbb4896c4bed139a27 100644
  167. --- a/ui/base/cocoa/remote_accessibility_api.h
  168. +++ b/ui/base/cocoa/remote_accessibility_api.h
  169. @@ -11,6 +11,8 @@
  170. #include "base/component_export.h"
  171. #include "base/mac/scoped_nsobject.h"
  172. +#ifndef MAS_BUILD
  173. +
  174. @interface NSAccessibilityRemoteUIElement : NSObject
  175. + (void)registerRemoteUIProcessIdentifier:(int)pid;
  176. + (NSData*)remoteTokenForLocalUIElement:(id)element;
  177. @@ -32,4 +34,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  178. } // namespace ui
  179. +#endif // MAS_BUILD
  180. +
  181. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  182. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  183. index 06427b2009ceb2cecf39d783fd1c3477cd5e66f9..1a2cd7a0e52e6345472f29283dfe94be506a338a 100644
  184. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  185. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  186. @@ -29,7 +29,9 @@
  187. #include "ui/views/window/dialog_observer.h"
  188. @class NativeWidgetMacNSWindow;
  189. +#ifndef MAS_BUILD
  190. @class NSAccessibilityRemoteUIElement;
  191. +#endif
  192. @class NSView;
  193. namespace remote_cocoa {
  194. @@ -408,11 +410,13 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  195. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  196. remote_ns_window_remote_;
  197. +#ifndef MAS_BUILD
  198. // Remote accessibility objects corresponding to the NSWindow and its root
  199. // NSView.
  200. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  201. remote_window_accessible_;
  202. base::scoped_nsobject<NSAccessibilityRemoteUIElement> remote_view_accessible_;
  203. +#endif
  204. // Used to force the NSApplication's focused accessibility element to be the
  205. // views::Views accessibility tree when the NSView for this is focused.
  206. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  207. index 2256c365af5b1af79458fdcb0cb9d44c9ff641fd..f4949b071a177452b0074a2436669e9846558d1a 100644
  208. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  209. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  210. @@ -282,14 +282,22 @@ gfx::NativeViewAccessible
  211. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  212. if (in_process_ns_window_bridge_)
  213. return in_process_ns_window_bridge_->ns_view();
  214. +#ifndef MAS_BUILD
  215. return remote_view_accessible_.get();
  216. +#else
  217. + return nullptr;
  218. +#endif
  219. }
  220. gfx::NativeViewAccessible
  221. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const {
  222. if (in_process_ns_window_bridge_)
  223. return in_process_ns_window_bridge_->ns_window();
  224. +#ifndef MAS_BUILD
  225. return remote_window_accessible_.get();
  226. +#else
  227. + return nullptr;
  228. +#endif
  229. }
  230. remote_cocoa::mojom::NativeWidgetNSWindow*
  231. @@ -1118,6 +1126,7 @@ void NativeWidgetMacNSWindowHost::OnFocusWindowToolbar() {
  232. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  233. const std::vector<uint8_t>& window_token,
  234. const std::vector<uint8_t>& view_token) {
  235. +#ifndef MAS_BUILD
  236. remote_window_accessible_ =
  237. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  238. remote_view_accessible_ =
  239. @@ -1125,14 +1134,17 @@ void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  240. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_.get()];
  241. [remote_view_accessible_
  242. setTopLevelUIElement:remote_window_accessible_.get()];
  243. +#endif
  244. }
  245. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  246. int64_t* pid,
  247. std::vector<uint8_t>* token) {
  248. +#ifndef MAS_BUILD
  249. *pid = getpid();
  250. id element_id = GetNativeViewAccessible();
  251. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  252. +#endif
  253. return true;
  254. }