mas_disable_remote_accessibility.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 3600a7ce7b3e6540767f64c631f352aa62240459..3147961f3d1c2c1690b5adf16a9a58f71456c5d0 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_.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. +#if !IS_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 4befb8cc94966c4c6ea21dd2d4f9c40152486387..5f17cc7422f5627d20186fe674cc2c6bcb1decaa 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. @@ -572,10 +572,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
  45. // this should be treated as an error and caught early.
  46. CHECK(bridged_view_);
  47. +#if !IS_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 f553d52bcc00acc9f1e2d87ee618efb7b24b389d..672aa22e5d1eeecfca3c780822024037e04ae4e2 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. @@ -87,8 +87,10 @@ id GetFocusedBrowserAccessibilityElement() override {
  60. return nil;
  61. }
  62. void SetAccessibilityWindow(NSWindow* window) override {
  63. +#if !IS_MAS_BUILD()
  64. host_->SetRemoteAccessibilityWindowToken(
  65. ui::RemoteAccessibility::GetTokenForLocalElement(window));
  66. +#endif
  67. }
  68. void ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& key_event,
  69. @@ -150,8 +152,10 @@ void SmartMagnify(const blink::WebGestureEvent& web_event) override {
  70. mojo::AssociatedRemote<mojom::RenderWidgetHostNSViewHost> host_;
  71. std::unique_ptr<RenderWidgetHostNSViewBridge> bridge_;
  72. +#if !IS_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 3a81bbe5542f39c82f6ccf6643f491cb73ecb2aa..6b156ac4c514855f73fedc85fb9b0080e8e61463 100644
  80. --- a/content/browser/accessibility/browser_accessibility_manager_mac.mm
  81. +++ b/content/browser/accessibility/browser_accessibility_manager_mac.mm
  82. @@ -22,7 +22,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. +#if !IS_MAS_BUILD()
  87. #include "ui/base/cocoa/remote_accessibility_api.h"
  88. +#endif
  89. namespace {
  90. @@ -225,6 +227,7 @@ void PostAnnouncementNotification(NSString* announcement,
  91. return;
  92. }
  93. +#if !IS_MAS_BUILD()
  94. BrowserAccessibilityManager* root_manager = GetManagerForRootFrame();
  95. if (root_manager) {
  96. BrowserAccessibilityManagerMac* root_manager_mac =
  97. @@ -247,6 +250,7 @@ void PostAnnouncementNotification(NSString* announcement,
  98. return;
  99. }
  100. }
  101. +#endif
  102. if (base::mac::IsOS10_13()) {
  103. // Use the announcement API to get around OS <= 10.13 VoiceOver bug
  104. @@ -643,6 +647,7 @@ void PostAnnouncementNotification(NSString* announcement,
  105. if ([NSApp isActive])
  106. return window == [NSApp accessibilityFocusedWindow];
  107. +#if !IS_MAS_BUILD()
  108. // TODO(accessibility): We need a solution to the problem described below.
  109. // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
  110. // 1. NSApp is the browser which spawned the PWA, and what it considers the
  111. @@ -670,6 +675,7 @@ void PostAnnouncementNotification(NSString* announcement,
  112. // from within the app shim content.
  113. if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]])
  114. return true;
  115. +#endif
  116. return false;
  117. }
  118. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
  119. index efca18c2a229b5d5afdcf5ac9c3057e0294bedd3..7a589e826f5c221259ac82ddfeba5985feb39d00 100644
  120. --- a/content/browser/renderer_host/render_widget_host_view_mac.h
  121. +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
  122. @@ -51,7 +51,9 @@ class ScopedPasswordInputEnabler;
  123. @protocol RenderWidgetHostViewMacDelegate;
  124. +#if !IS_MAS_BUILD()
  125. @class NSAccessibilityRemoteUIElement;
  126. +#endif
  127. @class RenderWidgetHostViewCocoa;
  128. namespace content {
  129. @@ -664,10 +666,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
  130. // EnsureSurfaceSynchronizedForWebTest().
  131. uint32_t latest_capture_sequence_number_ = 0u;
  132. +#if !IS_MAS_BUILD()
  133. // Remote accessibility objects corresponding to the NSWindow that this is
  134. // displayed to the user in.
  135. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  136. remote_window_accessible_;
  137. +#endif
  138. // Used to force the NSApplication's focused accessibility element to be the
  139. // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
  140. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
  141. index a7cbd153f799d8e6da61fb255c3d1d70c18fa514..2e3a87b7694f105a684ac2500ae5fb6861eee668 100644
  142. --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
  143. +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
  144. @@ -254,8 +254,10 @@
  145. void RenderWidgetHostViewMac::MigrateNSViewBridge(
  146. remote_cocoa::mojom::Application* remote_cocoa_application,
  147. uint64_t parent_ns_view_id) {
  148. +#if !IS_MAS_BUILD()
  149. // Destroy the previous remote accessibility element.
  150. remote_window_accessible_.reset();
  151. +#endif
  152. // Reset `ns_view_` before resetting `remote_ns_view_` to avoid dangling
  153. // pointers. `ns_view_` gets reinitialized later in this method.
  154. @@ -1567,8 +1569,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  155. gfx::NativeViewAccessible
  156. RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
  157. +#if !IS_MAS_BUILD()
  158. if (remote_window_accessible_)
  159. return remote_window_accessible_.get();
  160. +#endif
  161. return [GetInProcessNSView() window];
  162. }
  163. @@ -1612,9 +1616,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  164. }
  165. void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
  166. +#if !IS_MAS_BUILD()
  167. // When running in-process, just use the NSView's NSWindow as its own
  168. // accessibility element.
  169. remote_window_accessible_.reset();
  170. +#endif
  171. }
  172. bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
  173. @@ -2116,12 +2122,14 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
  174. void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
  175. const std::vector<uint8_t>& window_token) {
  176. +#if !IS_MAS_BUILD()
  177. if (window_token.empty()) {
  178. remote_window_accessible_.reset();
  179. } else {
  180. remote_window_accessible_ =
  181. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  182. }
  183. +#endif
  184. }
  185. ///////////////////////////////////////////////////////////////////////////////
  186. diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
  187. index b7abc4befd026de5721ac03a3469f2df8fc355cb..4f41808bcabe9c1f4277d877d597b4f0c43030f9 100644
  188. --- a/ui/base/BUILD.gn
  189. +++ b/ui/base/BUILD.gn
  190. @@ -358,6 +358,13 @@ component("base") {
  191. sources += [ "resource/resource_bundle_lacros.cc" ]
  192. }
  193. + if (is_mas_build) {
  194. + sources -= [
  195. + "cocoa/remote_accessibility_api.h",
  196. + "cocoa/remote_accessibility_api.mm",
  197. + ]
  198. + }
  199. +
  200. if (is_ios) {
  201. sources += [
  202. "device_form_factor_ios.mm",
  203. diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
  204. index aa09619a3137d1878c9f5c111a348703965dd16f..6553de29e861c15028564ffe4a4b9b01f2b42c5b 100644
  205. --- a/ui/base/cocoa/remote_accessibility_api.h
  206. +++ b/ui/base/cocoa/remote_accessibility_api.h
  207. @@ -11,6 +11,8 @@
  208. #include "base/component_export.h"
  209. #include "base/mac/scoped_nsobject.h"
  210. +#if !IS_MAS_BUILD()
  211. +
  212. @interface NSAccessibilityRemoteUIElement : NSObject
  213. + (void)registerRemoteUIProcessIdentifier:(int)pid;
  214. + (NSData*)remoteTokenForLocalUIElement:(id)element;
  215. @@ -32,4 +34,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
  216. } // namespace ui
  217. +#endif // MAS_BUILD
  218. +
  219. #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
  220. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  221. index 1f7fef969cf78606110e4a848c00ed6546a626f2..01b031219c9d96eb9b1850ccfd5b86bc5abadbf7 100644
  222. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
  223. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
  224. @@ -32,7 +32,9 @@
  225. #include "ui/views/window/dialog_observer.h"
  226. @class NativeWidgetMacNSWindow;
  227. +#if !IS_MAS_BUILD()
  228. @class NSAccessibilityRemoteUIElement;
  229. +#endif
  230. @class NSView;
  231. namespace remote_cocoa {
  232. @@ -463,11 +465,13 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
  233. mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
  234. remote_ns_window_remote_;
  235. +#if !IS_MAS_BUILD()
  236. // Remote accessibility objects corresponding to the NSWindow and its root
  237. // NSView.
  238. base::scoped_nsobject<NSAccessibilityRemoteUIElement>
  239. remote_window_accessible_;
  240. base::scoped_nsobject<NSAccessibilityRemoteUIElement> remote_view_accessible_;
  241. +#endif
  242. // Used to force the NSApplication's focused accessibility element to be the
  243. // views::Views accessibility tree when the NSView for this is focused.
  244. diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  245. index 06af43645067a32088c4874724175379c8d366c8..76c803688baf2093417143ee0a621cbdf88566a1 100644
  246. --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  247. +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
  248. @@ -345,14 +345,22 @@ void BubbleAnchorViewContainedInWidget(
  249. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
  250. if (in_process_ns_window_bridge_)
  251. return in_process_ns_window_bridge_->ns_view();
  252. +#if !IS_MAS_BUILD()
  253. return remote_view_accessible_.get();
  254. +#else
  255. + return nullptr;
  256. +#endif
  257. }
  258. gfx::NativeViewAccessible
  259. NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const {
  260. if (in_process_ns_window_bridge_)
  261. return in_process_ns_window_bridge_->ns_window();
  262. +#if !IS_MAS_BUILD()
  263. return remote_window_accessible_.get();
  264. +#else
  265. + return nullptr;
  266. +#endif
  267. }
  268. remote_cocoa::mojom::NativeWidgetNSWindow*
  269. @@ -1339,6 +1347,7 @@ void BubbleAnchorViewContainedInWidget(
  270. void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
  271. const std::vector<uint8_t>& window_token,
  272. const std::vector<uint8_t>& view_token) {
  273. +#if !IS_MAS_BUILD()
  274. remote_window_accessible_ =
  275. ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
  276. remote_view_accessible_ =
  277. @@ -1346,14 +1355,17 @@ void BubbleAnchorViewContainedInWidget(
  278. [remote_view_accessible_ setWindowUIElement:remote_window_accessible_.get()];
  279. [remote_view_accessible_
  280. setTopLevelUIElement:remote_window_accessible_.get()];
  281. +#endif
  282. }
  283. bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
  284. int64_t* pid,
  285. std::vector<uint8_t>* token) {
  286. +#if !IS_MAS_BUILD()
  287. *pid = getpid();
  288. id element_id = GetNativeViewAccessible();
  289. *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
  290. +#endif
  291. return true;
  292. }