2020-01-13 14:04:38 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Cheng Zhao <zcbenz@gmail.com>
|
|
|
|
Date: Thu, 20 Sep 2018 17:48:49 -0700
|
2021-05-19 18:20:12 +00:00
|
|
|
Subject: mas: avoid usage of NSAccessibilityRemoteUIElement
|
2020-01-13 14:04:38 +00:00
|
|
|
|
|
|
|
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
|
2022-05-17 16:48:40 +00:00
|
|
|
index 306db835fe203f663b1d84dd3490b619eb3f60b2..7a41d7afe6197e0a78934206782b1063f77f707a 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/components/remote_cocoa/app_shim/application_bridge.mm
|
|
|
|
+++ b/components/remote_cocoa/app_shim/application_bridge.mm
|
2022-02-10 02:58:52 +00:00
|
|
|
@@ -51,6 +51,7 @@
|
2020-01-13 14:04:38 +00:00
|
|
|
|
|
|
|
// NativeWidgetNSWindowHostHelper:
|
|
|
|
id GetNativeViewAccessible() override {
|
|
|
|
+#ifndef MAS_BUILD
|
|
|
|
if (!remote_accessibility_element_) {
|
|
|
|
int64_t browser_pid = 0;
|
|
|
|
std::vector<uint8_t> element_token;
|
2022-02-10 02:58:52 +00:00
|
|
|
@@ -61,6 +62,9 @@ id GetNativeViewAccessible() override {
|
2020-01-13 14:04:38 +00:00
|
|
|
ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
|
|
|
|
}
|
|
|
|
return remote_accessibility_element_.get();
|
|
|
|
+#else
|
|
|
|
+ return nil;
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
void DispatchKeyEvent(ui::KeyEvent* event) override {
|
|
|
|
bool event_handled = false;
|
2022-02-10 02:58:52 +00:00
|
|
|
@@ -99,8 +103,10 @@ void GetWordAt(const gfx::Point& location_in_content,
|
2020-01-13 14:04:38 +00:00
|
|
|
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
|
2022-08-17 18:35:53 +00:00
|
|
|
index c8a108cd8d39bf5185db438092579f67d31938f1..7ceaca262d71b1738d1dc92421db5e94494d5a97 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
|
|
|
|
+++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -583,10 +583,12 @@ NSUInteger CountBridgedWindows(NSArray* child_windows) {
|
2020-01-13 14:04:38 +00:00
|
|
|
// 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
|
2022-08-17 18:35:53 +00:00
|
|
|
index d6d48ab183ee32edc8c9c984673e050a2557950d..0022095c7ae81197ef5cdeddc62d8550fb973e03 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
|
|
|
|
+++ b/content/app_shim_remote_cocoa/ns_view_bridge_factory_impl.mm
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -76,8 +76,10 @@ id GetFocusedBrowserAccessibilityElement() override {
|
2020-01-13 14:04:38 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
void SetAccessibilityWindow(NSWindow* window) override {
|
|
|
|
+#ifndef MAS_BUILD
|
|
|
|
host_->SetRemoteAccessibilityWindowToken(
|
|
|
|
ui::RemoteAccessibility::GetTokenForLocalElement(window));
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForwardKeyboardEvent(const content::NativeWebKeyboardEvent& key_event,
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -139,8 +141,10 @@ void SmartMagnify(const blink::WebGestureEvent& web_event) override {
|
2020-01-13 14:04:38 +00:00
|
|
|
|
|
|
|
mojo::AssociatedRemote<mojom::RenderWidgetHostNSViewHost> host_;
|
|
|
|
std::unique_ptr<RenderWidgetHostNSViewBridge> bridge_;
|
|
|
|
+#ifndef MAS_BUILD
|
|
|
|
base::scoped_nsobject<NSAccessibilityRemoteUIElement>
|
|
|
|
remote_accessibility_element_;
|
|
|
|
+#endif
|
|
|
|
};
|
2021-11-24 08:45:59 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 21:26:16 +00:00
|
|
|
diff --git a/content/browser/accessibility/browser_accessibility_manager_mac.mm b/content/browser/accessibility/browser_accessibility_manager_mac.mm
|
2022-08-17 18:35:53 +00:00
|
|
|
index 6c0700b182e9765afd60d8deec501d13432e1b0a..c85c024a5a5711471e24698f14dda21b49817424 100644
|
2022-07-13 21:26:16 +00:00
|
|
|
--- 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 {
|
|
|
|
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -613,6 +615,7 @@ void PostAnnouncementNotification(NSString* announcement) {
|
2022-07-13 21:26:16 +00:00
|
|
|
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
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -640,6 +643,7 @@ void PostAnnouncementNotification(NSString* announcement) {
|
2022-07-13 21:26:16 +00:00
|
|
|
// from within the app shim content.
|
|
|
|
if ([window isKindOfClass:[NSAccessibilityRemoteUIElement class]])
|
|
|
|
return true;
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-13 14:04:38 +00:00
|
|
|
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
|
2022-07-13 21:26:16 +00:00
|
|
|
index a27ce05f20a8d645688c5bb920d36e76901e2b37..cb4238fe7d5f2d182c742532cf467880db7b309e 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/content/browser/renderer_host/render_widget_host_view_mac.h
|
|
|
|
+++ b/content/browser/renderer_host/render_widget_host_view_mac.h
|
2022-07-13 21:26:16 +00:00
|
|
|
@@ -51,7 +51,9 @@ class ScopedPasswordInputEnabler;
|
2020-01-13 14:04:38 +00:00
|
|
|
|
|
|
|
@protocol RenderWidgetHostViewMacDelegate;
|
|
|
|
|
|
|
|
+#ifndef MAS_BUILD
|
|
|
|
@class NSAccessibilityRemoteUIElement;
|
|
|
|
+#endif
|
|
|
|
@class RenderWidgetHostViewCocoa;
|
|
|
|
|
|
|
|
namespace content {
|
2022-07-13 21:26:16 +00:00
|
|
|
@@ -665,10 +667,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
|
2020-01-13 14:04:38 +00:00
|
|
|
// 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
|
2022-08-17 18:35:53 +00:00
|
|
|
index 9c42f305d30b1f1cafd72fd7326894819fa57ee7..54681d4aaaa52ee07fba0055a8411b8e19b4cc8c 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
|
|
|
|
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
|
2022-06-27 20:50:08 +00:00
|
|
|
@@ -258,8 +258,10 @@
|
2020-01-13 14:04:38 +00:00
|
|
|
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
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -1559,8 +1561,10 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
|
2020-01-13 14:04:38 +00:00
|
|
|
|
|
|
|
gfx::NativeViewAccessible
|
|
|
|
RenderWidgetHostViewMac::AccessibilityGetNativeViewAccessibleForWindow() {
|
|
|
|
+#ifndef MAS_BUILD
|
|
|
|
if (remote_window_accessible_)
|
|
|
|
return remote_window_accessible_.get();
|
|
|
|
+#endif
|
|
|
|
return [GetInProcessNSView() window];
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -1604,9 +1608,11 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
|
2020-01-13 14:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -2101,12 +2107,14 @@ void CombineTextNodesAndMakeCallback(SpeechCallback callback,
|
2020-01-13 14:04:38 +00:00
|
|
|
|
|
|
|
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
|
2022-08-17 18:35:53 +00:00
|
|
|
index 012ab83bb9f4887646decb030b4a18f6b21e0d01..0d8b56cc387b24833ec7950a8049e038f650020c 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/ui/base/BUILD.gn
|
|
|
|
+++ b/ui/base/BUILD.gn
|
2022-07-13 21:26:16 +00:00
|
|
|
@@ -341,6 +341,13 @@ component("base") {
|
2022-05-17 16:48:40 +00:00
|
|
|
sources += [ "resource/resource_bundle_lacros.cc" ]
|
2020-01-13 14:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ if (is_mas_build) {
|
|
|
|
+ sources -= [
|
|
|
|
+ "cocoa/remote_accessibility_api.h",
|
|
|
|
+ "cocoa/remote_accessibility_api.mm",
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+
|
2020-10-28 00:33:04 +00:00
|
|
|
if (is_ios) {
|
|
|
|
sources += [
|
|
|
|
"device_form_factor_ios.mm",
|
2020-01-13 14:04:38 +00:00
|
|
|
diff --git a/ui/base/cocoa/remote_accessibility_api.h b/ui/base/cocoa/remote_accessibility_api.h
|
2020-05-26 20:06:26 +00:00
|
|
|
index e7adfee3210ec723c687adfcc4bee8827ef643e7..25a924a47eeb30d783ef83dbb4896c4bed139a27 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/ui/base/cocoa/remote_accessibility_api.h
|
|
|
|
+++ b/ui/base/cocoa/remote_accessibility_api.h
|
|
|
|
@@ -11,6 +11,8 @@
|
2020-05-26 20:06:26 +00:00
|
|
|
#include "base/component_export.h"
|
2020-01-13 14:04:38 +00:00
|
|
|
#include "base/mac/scoped_nsobject.h"
|
|
|
|
|
|
|
|
+#ifndef MAS_BUILD
|
|
|
|
+
|
|
|
|
@interface NSAccessibilityRemoteUIElement : NSObject
|
|
|
|
+ (void)registerRemoteUIProcessIdentifier:(int)pid;
|
|
|
|
+ (NSData*)remoteTokenForLocalUIElement:(id)element;
|
2020-05-26 20:06:26 +00:00
|
|
|
@@ -32,4 +34,6 @@ class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility {
|
2020-01-13 14:04:38 +00:00
|
|
|
|
|
|
|
} // 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
|
2022-07-13 21:26:16 +00:00
|
|
|
index fc847f1ae010e4e0d69836f16d83515b8a92073a..a4bebe5078ace6c49cb34912813bbaf76b43b00c 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/ui/views/cocoa/native_widget_mac_ns_window_host.h
|
|
|
|
+++ b/ui/views/cocoa/native_widget_mac_ns_window_host.h
|
2022-07-13 21:26:16 +00:00
|
|
|
@@ -32,7 +32,9 @@
|
2020-01-13 14:04:38 +00:00
|
|
|
#include "ui/views/window/dialog_observer.h"
|
|
|
|
|
|
|
|
@class NativeWidgetMacNSWindow;
|
|
|
|
+#ifndef MAS_BUILD
|
|
|
|
@class NSAccessibilityRemoteUIElement;
|
|
|
|
+#endif
|
|
|
|
@class NSView;
|
|
|
|
|
|
|
|
namespace remote_cocoa {
|
2022-07-13 21:26:16 +00:00
|
|
|
@@ -447,11 +449,13 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
|
2020-01-13 14:04:38 +00:00
|
|
|
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
|
2022-08-17 18:35:53 +00:00
|
|
|
index eaca66e6c854cf7c2ba57a988080d2dee03d08e7..88e75e76cc4accacfbe4e8a2a1934372424d0eb8 100644
|
2020-01-13 14:04:38 +00:00
|
|
|
--- a/ui/views/cocoa/native_widget_mac_ns_window_host.mm
|
|
|
|
+++ b/ui/views/cocoa/native_widget_mac_ns_window_host.mm
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -325,14 +325,22 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
|
2020-01-13 14:04:38 +00:00
|
|
|
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*
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -1289,6 +1297,7 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
|
2020-01-13 14:04:38 +00:00
|
|
|
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_ =
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -1296,14 +1305,17 @@ void HandleAccelerator(const ui::Accelerator& accelerator,
|
2020-01-13 14:04:38 +00:00
|
|
|
[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;
|
|
|
|
}
|
|
|
|
|