Chromium Code Reviews| Index: ui/accessibility/platform/ax_platform_node_mac.mm |
| diff --git a/ui/accessibility/platform/ax_platform_node_mac.mm b/ui/accessibility/platform/ax_platform_node_mac.mm |
| index 2ae6c78132ee1ff34f62c2de0896c8775ba2f2ee..bf9813298bf8bbf562628d538eb3adf1dbaa754b 100644 |
| --- a/ui/accessibility/platform/ax_platform_node_mac.mm |
| +++ b/ui/accessibility/platform/ax_platform_node_mac.mm |
| @@ -280,6 +280,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { |
| + if (!node_) |
|
dmazzoni
2017/06/20 17:47:16
Isn't this an internal helper method? It seems lik
tapted
2017/06/20 23:30:52
Removed - I think this was just left over from ear
|
| + return nil; |
| + |
| std::string attributeValue; |
| if (node_->GetStringAttribute(attribute, &attributeValue)) |
| return base::SysUTF8ToNSString(attributeValue); |
| @@ -294,6 +297,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| // NSAccessibility informal protocol implementation. |
| - (BOOL)accessibilityIsIgnored { |
| + if (!node_) |
| + return YES; |
| + |
| return [[self AXRole] isEqualToString:NSAccessibilityUnknownRole] || |
| node_->GetData().HasState(ui::AX_STATE_INVISIBLE); |
| } |
| @@ -313,10 +319,13 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (id)accessibilityFocusedUIElement { |
| - return node_->GetDelegate()->GetFocus(); |
| + return node_ ? node_->GetDelegate()->GetFocus() : nil; |
| } |
| - (NSArray*)accessibilityActionNames { |
| + if (!node_) |
| + return @[]; |
| + |
| base::scoped_nsobject<NSMutableArray> axActions( |
| [[NSMutableArray alloc] init]); |
| @@ -340,7 +349,11 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (void)accessibilityPerformAction:(NSString*)action { |
| - DCHECK([[self accessibilityActionNames] containsObject:action]); |
| + // Actions are performed asynchronously, so it's always possible for an object |
| + // to change its mind after previously reporting an action as available. |
| + if (![[self accessibilityActionNames] containsObject:action]) |
| + return; |
| + |
| ui::AXActionData data; |
| for (const ActionMap::value_type& entry : GetActionMap()) { |
| if ([action isEqualToString:entry.second]) { |
| @@ -358,6 +371,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (NSArray*)accessibilityAttributeNames { |
| + if (!node_) |
| + return @[]; |
| + |
| // These attributes are required on all accessibility objects. |
| NSArray* const kAllRoleAttributes = @[ |
| NSAccessibilityChildrenAttribute, |
| @@ -426,6 +442,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (BOOL)accessibilityIsAttributeSettable:(NSString*)attributeName { |
| + if (!node_) |
| + return NO; |
| + |
| if (node_->GetData().HasState(ui::AX_STATE_DISABLED)) |
| return NO; |
| @@ -463,6 +482,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute { |
| + if (!node_) |
| + return; |
| + |
| ui::AXActionData data; |
| // Check for attributes first. Only the |data.action| should be set here - any |
| @@ -501,6 +523,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (id)accessibilityAttributeValue:(NSString*)attribute { |
| + if (!node_) |
| + return nil; // Return nil when detached. Even for AXRole. |
| + |
| SEL selector = NSSelectorFromString(attribute); |
| if ([self respondsToSelector:selector]) |
| return [self performSelector:selector]; |
| @@ -513,6 +538,7 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| - (NSString*)AXRole { |
| if (!node_) |
| return nil; |
| + |
| return [[self class] nativeRoleFromAXRole:node_->GetData().role]; |
| } |
| @@ -577,7 +603,8 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| - (NSArray*)AXChildren { |
| if (!node_) |
| - return nil; |
| + return @[]; |
| + |
| int count = node_->GetChildCount(); |
| NSMutableArray* children = [NSMutableArray arrayWithCapacity:count]; |
| for (int i = 0; i < count; ++i) |