0

Revert "macOS a11y: Implement accessibilityHitTest for remote app shims (PWAs)"

This reverts commit f080d6deb1,
which can cause hangs and OOMs.

The original cl landed many months ago, but chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm is the only change that didn't revert cleanly.

Bug: 1400682

Change-Id: I2e3ad54f9056429c3143144b93de22d43e2d66f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4225718
Reviewed-by: Avi Drissman <avi@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Chris Bookholt <bookholt@chromium.org>
Commit-Queue: Jayson Adams <shrike@chromium.org>
Reviewed-by: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1102257}
This commit is contained in:
Jayson Adams
2023-02-07 18:29:59 +00:00
committed by Chromium LUCI CQ
parent cc86b2c935
commit a5af91924b
13 changed files with 7 additions and 82 deletions

@ -348,20 +348,7 @@ void BrowserNonClientFrameViewMac::OnThemeChanged() {
// BrowserNonClientFrameViewMac, views::NonClientFrameView implementation:
gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForClientView() const {
// Because of the z-ordering of our child views (the client view is positioned
// over the non-client frame view), if the client view ever overlaps the frame
// view visually (as it does for the browser window), then NSAccessibility
// accessibilityHitTest will not be able to find the window controls, such as
// WebAppFrameToolbarView.
// TODO(crbug/1361945): Make accessibilityHitTest support the window controls
// overlay mode.
gfx::Rect client_view_bounds = bounds();
int top_inset = (browser_view()->IsWindowControlsOverlayEnabled() ||
browser_view()->IsImmersiveModeEnabled())
? 0
: GetTopInset(false);
client_view_bounds.Inset(gfx::Insets::TLBR(top_inset, 0, 0, 0));
return client_view_bounds;
return bounds();
}
gfx::Rect BrowserNonClientFrameViewMac::GetWindowBoundsForClientBounds(

@ -52,7 +52,7 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
// NativeWidgetNSWindowHostHelper:
id GetNativeViewAccessible() override {
if (!remote_accessibility_element_) {
base::ProcessId browser_pid = base::kNullProcessId;
int64_t browser_pid = 0;
std::vector<uint8_t> element_token;
host_remote_->GetRootViewAccessibilityToken(&browser_pid, &element_token);
[NSAccessibilityRemoteUIElement

@ -14,7 +14,6 @@
#import "components/remote_cocoa/app_shim/views_nswindow_delegate.h"
#import "components/remote_cocoa/app_shim/window_touch_bar_delegate.h"
#include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
#include "ui/base/cocoa/remote_accessibility_api.h"
#import "ui/base/cocoa/user_interface_item_command_handler.h"
#import "ui/base/cocoa/window_size_constants.h"
@ -144,21 +143,6 @@ void OrderChildWindow(NSWindow* child_window,
return [[self window] windowTitlebarLayoutDirection] ==
NSUserInterfaceLayoutDirectionRightToLeft;
}
// The base implementation skips NSAccessibilityRemoteUIElement.
- (id)accessibilityHitTest:(NSPoint)point {
for (id child in [[self accessibilityChildren] reverseObjectEnumerator]) {
if ([child isKindOfClass:[NSAccessibilityRemoteUIElement class]])
return [child accessibilityHitTest:point];
if (!NSPointInRect(point, [child accessibilityFrame]))
continue;
if (id foundChild = [child accessibilityHitTest:point])
return foundChild;
}
// Hit self, but not any child.
return NSAccessibilityUnignoredAncestor(self);
}
@end
@implementation NativeWidgetMacNSWindowBorderlessFrame

@ -4,7 +4,6 @@
module remote_cocoa.mojom;
import "mojo/public/mojom/base/process_id.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "ui/base/accelerators/mojom/accelerator.mojom";
import "ui/base/mojom/ui_base_types.mojom";
@ -221,7 +220,7 @@ interface NativeWidgetNSWindowHost {
// view and in |host_pid| the pid for the host process.
[Sync]
GetRootViewAccessibilityToken() =>
(mojo_base.mojom.ProcessId host_pid, array<uint8> element_token);
(int64 host_pid, array<uint8> element_token);
// Return the result for -[NSUserInterfaceValidations
// validateUserInterfaceItem] for a given command, along with any state for

@ -76,19 +76,6 @@ class RenderWidgetHostNSViewBridgeOwner
}
// RenderWidgetHostNSViewHostHelper implementation.
id GetAccessibilityElement() override {
if (!remote_accessibility_element_) {
base::ProcessId browser_pid = base::kNullProcessId;
std::vector<uint8_t> element_token;
host_->GetRenderWidgetAccessibilityToken(&browser_pid, &element_token);
[NSAccessibilityRemoteUIElement
registerRemoteUIProcessIdentifier:browser_pid];
remote_accessibility_element_ =
ui::RemoteAccessibility::GetRemoteElementFromToken(element_token);
}
return remote_accessibility_element_.get();
}
id GetRootBrowserAccessibilityElement() override {
// The RenderWidgetHostViewCocoa in the app shim process does not
// participate in the accessibility tree. Only the instance in the browser

@ -47,9 +47,6 @@ class RenderWidgetHostNSViewHostHelper {
virtual ~RenderWidgetHostNSViewHostHelper() {}
// Return the RenderWidget's accessibility node.
virtual id GetAccessibilityElement() = 0;
// Return the RenderWidget's BrowserAccessibilityManager's root accessibility
// node.
virtual id GetRootBrowserAccessibilityElement() = 0;

@ -83,7 +83,6 @@ class DummyHostHelper : public RenderWidgetHostNSViewHostHelper {
private:
// RenderWidgetHostNSViewHostHelper implementation.
id GetAccessibilityElement() override { return nil; }
id GetRootBrowserAccessibilityElement() override { return nil; }
id GetFocusedBrowserAccessibilityElement() override { return nil; }
void SetAccessibilityWindow(NSWindow* window) override {}
@ -1698,9 +1697,6 @@ void ExtractUnderlines(NSAttributedString* string,
- (id)accessibilityHitTest:(NSPoint)point {
id root_element = _hostHelper->GetRootBrowserAccessibilityElement();
if (!root_element) {
id rwhv_element = _hostHelper->GetAccessibilityElement();
if (rwhv_element && rwhv_element != self)
return [rwhv_element accessibilityHitTest:point];
return self;
}

@ -312,7 +312,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
}
// RenderWidgetHostNSViewHostHelper implementation.
id GetAccessibilityElement() override;
id GetRootBrowserAccessibilityElement() override;
id GetFocusedBrowserAccessibilityElement() override;
void SetAccessibilityWindow(NSWindow* window) override;
@ -408,8 +407,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
void StopSpeaking() override;
bool SyncIsSpeaking(bool* is_speaking) override;
void SyncIsSpeaking(SyncIsSpeakingCallback callback) override;
void GetRenderWidgetAccessibilityToken(
GetRenderWidgetAccessibilityTokenCallback callback) override;
void SetRemoteAccessibilityWindowToken(
const std::vector<uint8_t>& window_token) override;

@ -1618,10 +1618,6 @@ void RenderWidgetHostViewMac::ShowSharePicker(
// RenderWidgetHostNSViewHostHelper and mojom::RenderWidgetHostNSViewHost
// implementation:
id RenderWidgetHostViewMac::GetAccessibilityElement() {
return GetNativeViewAccessible();
}
id RenderWidgetHostViewMac::GetRootBrowserAccessibilityElement() {
if (auto* manager = host()->GetRootBrowserAccessibilityManager())
return manager->GetBrowserAccessibilityRoot()->GetNativeViewAccessible();
@ -2128,15 +2124,6 @@ void RenderWidgetHostViewMac::StopSpeaking() {
ui::TextServicesContextMenu::StopSpeaking();
}
void RenderWidgetHostViewMac::GetRenderWidgetAccessibilityToken(
GetRenderWidgetAccessibilityTokenCallback callback) {
base::ProcessId pid = getpid();
id element_id = GetNativeViewAccessible();
std::vector<uint8_t> token =
ui::RemoteAccessibility::GetTokenForLocalElement(element_id);
std::move(callback).Run(pid, token);
}
void RenderWidgetHostViewMac::SetRemoteAccessibilityWindowToken(
const std::vector<uint8_t>& window_token) {
if (window_token.empty()) {

@ -4,7 +4,6 @@
module remote_cocoa.mojom;
import "mojo/public/mojom/base/process_id.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "third_party/blink/public/mojom/input/input_handler.mojom";
import "third_party/blink/public/mojom/webshare/share_error.mojom";
@ -253,12 +252,6 @@ interface RenderWidgetHostNSViewHost {
[Sync]
SyncIsSpeaking() => (bool is_speaking);
// Return in |element_token| the token for the root content AX node for this
// view and in |host_pid| the pid for the host process.
[Sync]
GetRenderWidgetAccessibilityToken() =>
(mojo_base.mojom.ProcessId host_pid, array<uint8> element_token);
// Send the token for the NSWindow in which this NSView is being displayed.
SetRemoteAccessibilityWindowToken(array<uint8> window_token);
};

@ -12,7 +12,6 @@
#include "base/mac/scoped_nsobject.h"
@interface NSAccessibilityRemoteUIElement : NSObject
+ (void)setRemoteUIApp:(BOOL)flag;
+ (void)registerRemoteUIProcessIdentifier:(int)pid;
+ (NSData*)remoteTokenForLocalUIElement:(id)element;
- (id)initWithRemoteToken:(NSData*)token;

@ -339,7 +339,7 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
void SetRemoteAccessibilityTokens(
const std::vector<uint8_t>& window_token,
const std::vector<uint8_t>& view_token) override;
bool GetRootViewAccessibilityToken(base::ProcessId* pid,
bool GetRootViewAccessibilityToken(int64_t* pid,
std::vector<uint8_t>* token) override;
bool ValidateUserInterfaceItem(
int32_t command,

@ -187,7 +187,7 @@ class BridgedNativeWidgetHostDummy
void GetRootViewAccessibilityToken(
GetRootViewAccessibilityTokenCallback callback) override {
std::vector<uint8_t> token;
base::ProcessId pid = base::kNullProcessId;
int64_t pid = 0;
std::move(callback).Run(pid, token);
}
void ValidateUserInterfaceItem(
@ -1341,11 +1341,10 @@ void NativeWidgetMacNSWindowHost::SetRemoteAccessibilityTokens(
[remote_view_accessible_ setWindowUIElement:remote_window_accessible_.get()];
[remote_view_accessible_
setTopLevelUIElement:remote_window_accessible_.get()];
[NSAccessibilityRemoteUIElement setRemoteUIApp:YES];
}
bool NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
base::ProcessId* pid,
int64_t* pid,
std::vector<uint8_t>* token) {
*pid = getpid();
id element_id = GetNativeViewAccessible();
@ -1525,7 +1524,7 @@ void NativeWidgetMacNSWindowHost::GetWindowFrameTitlebarHeight(
void NativeWidgetMacNSWindowHost::GetRootViewAccessibilityToken(
GetRootViewAccessibilityTokenCallback callback) {
std::vector<uint8_t> token;
base::ProcessId pid;
int64_t pid;
GetRootViewAccessibilityToken(&pid, &token);
std::move(callback).Run(pid, token);
}