123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: Cheng Zhao <[email protected]>
- Date: Thu, 20 Sep 2018 17:48:49 -0700
- Subject: mas: avoid usage of NSAccessibilityRemoteUIElement
- According to ccameron:
- NSAccessibilityRemoteUIElement is unnecessary for Electron's use-case. We use it
- for progressive web apps (where the AXTree is in the browser process, but macOS
- needs to think it's coming from the PWA process). I think it can just be chopped
- out -- if there are any side-effects, we should be able to work around them.
- diff --git a/components/remote_cocoa/app_shim/application_bridge.mm b/components/remote_cocoa/app_shim/application_bridge.mm
- index 306db835fe203f663b1d84dd3490b619eb3f60b2..7a41d7afe6197e0a78934206782b1063f77f707a 100644
- --- a/components/remote_cocoa/app_shim/application_bridge.mm
- +++ b/components/remote_cocoa/app_shim/application_bridge.mm
- @@ -51,6 +51,7 @@
-
- // NativeWidgetNSWindowHostHelper:
- id GetNativeViewAccessible() override {
- +#ifndef MAS_BUILD
- if (!remote_accessibility_element_) {
- int64_t browser_pid = 0;
- std::vector<uint8_t> element_token;
- @@ -61,6 +62,9 @@ id GetNativeViewAccessible() override {
- ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
- }
- return remote_accessibility_element_.get();
- +#else
- + return nil;
- +#endif
- }
- void DispatchKeyEvent(ui::KeyEvent* event) override {
- bool event_handled = false;
- @@ -99,8 +103,10 @@ void GetWordAt(const gfx::Point& location_in_content,
- mojo::AssociatedRemote<mojom::TextInputHost> text_input_host_remote_;
-
- std::unique_ptr<NativeWidgetNSWindowBridge> bridge_;
- +#ifndef MAS_BUILD
- base::scoped_nsobject<NSAccessibilityRemoteUIElement>
- remote_accessibility_element_;
- +#endif
- };
-
- } // namespace
- 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
- index 4719512943b8c3930bca35a226fc3e635021c109..55292d12f486cd9b954398fcf407c9b88ca5fd47 100644
- --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
- +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
- @@ -565,10 +565,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
- // this should be treated as an error and caught early.
- CHECK(bridged_view_);
-
- +#ifndef MAS_BUILD
- // Send the accessibility tokens for the NSView now that it exists.
- host_->SetRemoteAccessibilityTokens(
- ui::RemoteAccessibility::GetTokenForLocalElement(window_),
- ui::RemoteAccessibility::GetTokenForLocalElement(bridged_view_));
- +#endif
-
- // Beware: This view was briefly removed (in favor of a bare CALayer) in
- // crrev/c/1236675. The ordering of unassociated layers relative to NSView
- 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
- index be7b05ee4f779ccc44e6eea7ff7fb3e8bd504d6f..3b3336913cf91c3b7f22cefb4139f82b882c97c9 100644
- --- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
- +++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
- @@ -77,8 +77,10 @@ id GetFocusedBrowserAccessibilityElement() override {
- return nil;
- }
- void SetAccessibilityWindow(NSWindow* window) override {
- +#ifndef MAS_BUILD
- host_->SetRemoteAccessibilityWindowToken(
- ui::RemoteAccessibility::GetTokenForLocalElement(window));
- +#endif
- }
-
- void ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& key_event,
- @@ -140,8 +142,10 @@ void SmartMagnify(const blink::WebGestureEvent& web_event) override {
-
- mojo::AssociatedRemote<mojom::RenderWidgetHostNSViewHost> host_;
- std::unique_ptr<RenderWidgetHostNSViewBridge> bridge_;
- +#ifndef MAS_BUILD
- base::scoped_nsobject<NSAccessibilityRemoteUIElement>
- remote_accessibility_element_;
- +#endif
- };
- }
-
- diff --git a/content/browser/accessibility/browser_accessibility_manager_mac.mm b/content/browser/accessibility/browser_accessibility_manager_mac.mm
- index c107750255b441061d03f8a38df5b28173c05f31..7093e185839095c21f6ea7cf4e88692407fd8cf5 100644
- --- a/content/browser/accessibility/browser_accessibility_manager_mac.mm
- +++ b/content/browser/accessibility/browser_accessibility_manager_mac.mm
- @@ -21,7 +21,9 @@
- #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
- #include "ui/accessibility/ax_role_properties.h"
- #include "ui/accessibility/platform/ax_private_webkit_constants_mac.h"
- +#ifndef MAS_BUILD
- #include "ui/base/cocoa/remote_accessibility_api.h"
- +#endif
-
- namespace {
-
- @@ -614,6 +616,7 @@ void PostAnnouncementNotification(NSString* announcement) {
- if ([NSApp isActive])
- return window == [NSApp accessibilityFocusedWindow];
-
- +#ifndef MAS_BUILD
- // TODO(accessibility): We need a solution to the problem described below.
- // If the window is NSAccessibilityRemoteUIElement, there are some challenges:
- // 1. NSApp is the browser which spawned the PWA, and what it considers the
- @@ -641,6 +644,7 @@ void PostAnnouncementNotification(NSString* announcement) {
- // from within the app shim content.
- if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]])
- return true;
- +#endif
-
- return false;
- }
- diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
- index 0549e3b400cb42e1a3491a2de9739c275ae006df..ab59ea7211b425e36d3d0fa673d8c09b99140716 100644
- --- a/content/browser/renderer_host/render_widget_host_view_mac.h
- +++ b/content/browser/renderer_host/render_widget_host_view_mac.h
- @@ -52,7 +52,9 @@ class ScopedPasswordInputEnabler;
-
- @protocol RenderWidgetHostViewMacDelegate;
-
- +#ifndef MAS_BUILD
- @class NSAccessibilityRemoteUIElement;
- +#endif
- @class RenderWidgetHostViewCocoa;
-
- namespace content {
- @@ -668,10 +670,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
- // EnsureSurfaceSynchronizedForWebTest().
- uint32_t latest_capture_sequence_number_ = 0u;
-
- +#ifndef MAS_BUILD
- // Remote accessibility objects corresponding to the NSWindow that this is
- // displayed to the user in.
- base::scoped_nsobject<NSAccessibilityRemoteUIElement>
- remote_window_accessible_;
- +#endif
-
- // Used to force the NSApplication's focused accessibility element to be the
- // content::BrowserAccessibilityCocoa accessibility tree when the NSView for
- diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
- index 2d106cbcfd6fd63b95c0f322dda3dc926ebcc118..e0168e7cf64a783a96aa4e43fa3a80bfbbe1fbac 100644
- --- a/content/browser/renderer_host/render_widget_host_view_mac.mm
- +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
- @@ -259,8 +259,10 @@
- void RenderWidgetHostViewMac::MigrateNSViewBridge(
- remote_cocoa::mojom::Application* remote_cocoa_application,
- uint64_t parent_ns_view_id) {
- +#ifndef MAS_BUILD
- // Destroy the previous remote accessibility element.
- remote_window_accessible_.reset();
- +#endif
-
- // Disconnect from the previous bridge (this will have the effect of
- // destroying the associated bridge), and close the receiver (to allow it
- @@ -1566,8 +1568,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
-
- gfx::NativeViewAccessible
- RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
- +#ifndef MAS_BUILD
- if (remote_window_accessible_)
- return remote_window_accessible_.get();
- +#endif
- return [GetInProcessNSView() window];
- }
-
- @@ -1611,9 +1615,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
- }
-
- void RenderWidgetHostViewMac::SetAccessibilityWindow(NSWindow* window) {
- +#ifndef MAS_BUILD
- // When running in-process, just use the NSView's NSWindow as its own
- // accessibility element.
- remote_window_accessible_.reset();
- +#endif
- }
-
- bool RenderWidgetHostViewMac::SyncIsWidgetForMainFrame(
- @@ -2108,12 +2114,14 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
-
- void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
- const std::vector<uint8_t>& window_token) {
- +#ifndef MAS_BUILD
- if (window_token.empty()) {
- remote_window_accessible_.reset();
- } else {
- remote_window_accessible_ =
- ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
- }
- +#endif
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn
- index 2c4a0c7dde08353221b5e2747b00c72cf4818137..64375989d127bd4b2990c9ee8fc10c24de9de30e 100644
- --- a/ui/base/BUILD.gn
- +++ b/ui/base/BUILD.gn
- @@ -341,6 +341,13 @@ component("base") {
- sources += [ "resource/resource_bundle_lacros.cc" ]
- }
-
- + if (is_mas_build) {
- + sources -= [
- + "cocoa/remote_accessibility_api.h",
- + "cocoa/remote_accessibility_api.mm",
- + ]
- + }
- +
- if (is_ios) {
- sources += [
- "device_form_factor_ios.mm",
- diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
- index e7adfee3210ec723c687adfcc4bee8827ef643e7..25a924a47eeb30d783ef83dbb4896c4bed139a27 100644
- --- a/ui/base/cocoa/remote_accessibility_api.h
- +++ b/ui/base/cocoa/remote_accessibility_api.h
- @@ -11,6 +11,8 @@
- #include "base/component_export.h"
- #include "base/mac/scoped_nsobject.h"
-
- +#ifndef MAS_BUILD
- +
- @interface NSAccessibilityRemoteUIElement : NSObject
- + (void)registerRemoteUIProcessIdentifier:(int)pid;
- + (NSData*)remoteTokenForLocalUIElement:(id)element;
- @@ -32,4 +34,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
-
- } // namespace ui
-
- +#endif // MAS_BUILD
- +
- #endif // UI_BASE_COCOA_REMOTE_ACCESSIBILITY_API_H_
- diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.h b/ui/views/cocoa/native_widget_mac_ns_window_host.h
- index 5a09100094d0371a3e58db6c7626e06bdcdd17c3..1aa7bde93efdf198998ba4e6a97dcf2aadd9f4e9 100644
- --- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
- +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
- @@ -32,7 +32,9 @@
- #include "ui/views/window/dialog_observer.h"
-
- @class NativeWidgetMacNSWindow;
- +#ifndef MAS_BUILD
- @class NSAccessibilityRemoteUIElement;
- +#endif
- @class NSView;
-
- namespace remote_cocoa {
- @@ -449,11 +451,13 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
- mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
- remote_ns_window_remote_;
-
- +#ifndef MAS_BUILD
- // Remote accessibility objects corresponding to the NSWindow and its root
- // NSView.
- base::scoped_nsobject<NSAccessibilityRemoteUIElement>
- remote_window_accessible_;
- base::scoped_nsobject<NSAccessibilityRemoteUIElement> remote_view_accessible_;
- +#endif
-
- // Used to force the NSApplication's focused accessibility element to be the
- // views::Views accessibility tree when the NSView for this is focused.
- diff --git a/ui/views/cocoa/native_widget_mac_ns_window_host.mm b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
- index 1a4a33a111da65c7541c5b7bab430f58acb29e77..8f1b227bc7d1fcb5c30e6c0bdf4ee8677552ba57 100644
- --- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
- +++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
- @@ -327,14 +327,22 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
- NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSView() const {
- if (in_process_ns_window_bridge_)
- return in_process_ns_window_bridge_->ns_view();
- +#ifndef MAS_BUILD
- return remote_view_accessible_.get();
- +#else
- + return nullptr;
- +#endif
- }
-
- gfx::NativeViewAccessible
- NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const {
- if (in_process_ns_window_bridge_)
- return in_process_ns_window_bridge_->ns_window();
- +#ifndef MAS_BUILD
- return remote_window_accessible_.get();
- +#else
- + return nullptr;
- +#endif
- }
-
- remote_cocoa::mojom::NativeWidgetNSWindow*
- @@ -1306,6 +1314,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
- void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
- const std::vector<uint8_t>& window_token,
- const std::vector<uint8_t>& view_token) {
- +#ifndef MAS_BUILD
- remote_window_accessible_ =
- ui::RemoteAccessibility::GetRemoteElementFromToken(window_token);
- remote_view_accessible_ =
- @@ -1313,14 +1322,17 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
- [remote_view_accessible_ setWindowUIElement:remote_window_accessible_.get()];
- [remote_view_accessible_
- setTopLevelUIElement:remote_window_accessible_.get()];
- +#endif
- }
-
- bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
- int64_t* pid,
- std::vector<uint8_t>* token) {
- +#ifndef MAS_BUILD
- *pid = getpid();
- id element_id = GetNativeViewAccessible();
- *token = ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
- +#endif
- return true;
- }
-
|