Bug 1627765 - Remove mac heirarchy cache. r=morgan

Differential Revision: https://phabricator.services.mozilla.com/D69880

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2020-04-10 17:52:58 +00:00
Родитель 8f333badf3
Коммит ca37dab5ab
5 изменённых файлов: 28 добавлений и 128 удалений

Просмотреть файл

@ -47,9 +47,6 @@ class AccessibleWrap : public Accessible {
virtual void Shutdown() override; virtual void Shutdown() override;
virtual bool InsertChildAt(uint32_t aIdx, Accessible* aChild) override;
virtual bool RemoveChild(Accessible* aAccessible) override;
virtual nsresult HandleAccEvent(AccEvent* aEvent) override; virtual nsresult HandleAccEvent(AccEvent* aEvent) override;
protected: protected:

Просмотреть файл

@ -154,21 +154,6 @@ nsresult AccessibleWrap::HandleAccEvent(AccEvent* aEvent) {
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
} }
bool AccessibleWrap::InsertChildAt(uint32_t aIdx, Accessible* aAccessible) {
bool inserted = Accessible::InsertChildAt(aIdx, aAccessible);
if (inserted && mNativeObject) [mNativeObject appendChild:aAccessible];
return inserted;
}
bool AccessibleWrap::RemoveChild(Accessible* aAccessible) {
bool removed = Accessible::RemoveChild(aAccessible);
if (removed && mNativeObject) [mNativeObject invalidateChildren];
return removed;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// AccessibleWrap protected // AccessibleWrap protected

Просмотреть файл

@ -46,76 +46,16 @@ void ProxyCreated(ProxyAccessible* aProxy, uint32_t) {
uintptr_t accWrap = reinterpret_cast<uintptr_t>(aProxy) | IS_PROXY; uintptr_t accWrap = reinterpret_cast<uintptr_t>(aProxy) | IS_PROXY;
mozAccessible* mozWrapper = [[type alloc] initWithAccessible:accWrap]; mozAccessible* mozWrapper = [[type alloc] initWithAccessible:accWrap];
aProxy->SetWrapper(reinterpret_cast<uintptr_t>(mozWrapper)); aProxy->SetWrapper(reinterpret_cast<uintptr_t>(mozWrapper));
mozAccessible* nativeParent = nullptr;
if (aProxy->IsDoc() && aProxy->AsDoc()->IsTopLevel()) {
// If proxy is top level, the parent we need to invalidate the children of
// will be a non-remote accessible.
Accessible* outerDoc = aProxy->OuterDocOfRemoteBrowser();
if (outerDoc) {
nativeParent = GetNativeFromGeckoAccessible(outerDoc);
}
} else {
// Non-top level proxies need proxy parents' children invalidated.
ProxyAccessible* parent = aProxy->Parent();
MOZ_ASSERT(parent ||
// It's expected that an OOP iframe might not have a parent yet.
(aProxy->IsDoc() && aProxy->AsDoc()->IsTopLevelInContentProcess()),
"a non-top-level proxy is missing a parent?");
nativeParent = parent ? GetNativeFromProxy(parent) : nullptr;
}
if (nativeParent) {
[nativeParent invalidateChildren];
}
} }
void ProxyDestroyed(ProxyAccessible* aProxy) { void ProxyDestroyed(ProxyAccessible* aProxy) {
mozAccessible* nativeParent = nil;
if (aProxy->IsDoc() && aProxy->AsDoc()->IsTopLevel()) {
// Invalidate native parent in parent process's children on proxy destruction
Accessible* outerDoc = aProxy->OuterDocOfRemoteBrowser();
if (outerDoc) {
nativeParent = GetNativeFromGeckoAccessible(outerDoc);
}
} else {
if (!aProxy->Document()->IsShutdown()) {
// Only do if the document has not been shut down, else parent will return
// garbage since we don't shut down children from top down.
ProxyAccessible* parent = aProxy->Parent();
// Invalidate proxy parent's children.
if (parent) {
nativeParent = GetNativeFromProxy(parent);
}
}
}
mozAccessible* wrapper = GetNativeFromProxy(aProxy); mozAccessible* wrapper = GetNativeFromProxy(aProxy);
[wrapper expire]; [wrapper expire];
[wrapper release]; [wrapper release];
aProxy->SetWrapper(0); aProxy->SetWrapper(0);
if (nativeParent) {
[nativeParent invalidateChildren];
}
} }
void ProxyEvent(ProxyAccessible* aProxy, uint32_t aEventType) { void ProxyEvent(ProxyAccessible* aProxy, uint32_t aEventType) {
if (aEventType == nsIAccessibleEvent::EVENT_REORDER && aProxy->ChildrenCount() == 1 &&
aProxy->ChildAt(0)->IsDoc()) {
// This is a remote OuterDocAccessible. The reorder event indicates that Its
// embedded document has been added or changed. If the document itself is
// an existing Accessible, ProxyCreated won't have been called, so we won't
// have invalidated native children. This can happen for in-process iframes
// if the OuterDocAccessible is re-created (e.g. due to layout reflow).
// It always happens for out-of-process iframes, as we must always call
// ProxyCreated before DocAccessibleParent::AddChildDoc for those.
mozAccessible* wrapper = GetNativeFromProxy(aProxy);
if (wrapper) {
[wrapper invalidateChildren];
}
}
// ignore everything but focus-changed, value-changed, caret and selection // ignore everything but focus-changed, value-changed, caret and selection
// events for now. // events for now.
if (aEventType != nsIAccessibleEvent::EVENT_FOCUS && if (aEventType != nsIAccessibleEvent::EVENT_FOCUS &&

Просмотреть файл

@ -48,16 +48,6 @@ static const uintptr_t IS_PROXY = 1;
*/ */
uintptr_t mGeckoAccessible; uintptr_t mGeckoAccessible;
/**
* Strong ref to array of children
*/
NSMutableArray* mChildren;
/**
* Weak reference to the parent
*/
mozAccessible* mParent;
/** /**
* The role of our gecko accessible. * The role of our gecko accessible.
*/ */
@ -148,14 +138,6 @@ static const uintptr_t IS_PROXY = 1;
#pragma mark - #pragma mark -
// invalidates and removes all our children from our cached array.
- (void)invalidateChildren;
/**
* Append a child if they are already cached.
*/
- (void)appendChild:(mozilla::a11y::Accessible*)aAccessible;
// makes ourselves "expired". after this point, we might be around if someone // makes ourselves "expired". after this point, we might be around if someone
// has retained us (e.g., a third-party), but we really contain no information. // has retained us (e.g., a third-party), but we really contain no information.
- (void)expire; - (void)expire;
@ -188,6 +170,11 @@ static const uintptr_t IS_PROXY = 1;
// value for the specified attribute // value for the specified attribute
- (id)accessibilityAttributeValue:(NSString*)attribute; - (id)accessibilityAttributeValue:(NSString*)attribute;
// gets the array length of specified attribute values. Added
// here to have a lighter way to get the child count instead
// of constructing a full array.
- (NSUInteger)accessibilityArrayAttributeCount:(NSString*)attribute;
- (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute; - (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute;
- (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute; - (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute;

Просмотреть файл

@ -108,7 +108,6 @@ static inline NSMutableArray* ConvertToNSArray(nsTArray<ProxyAccessible*>& aArra
- (void)dealloc { - (void)dealloc {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK; NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[mChildren release];
[super dealloc]; [super dealloc];
NS_OBJC_END_TRY_ABORT_BLOCK; NS_OBJC_END_TRY_ABORT_BLOCK;
@ -297,6 +296,24 @@ static const uint64_t kCacheInitialized = ((uint64_t)0x1) << 63;
mCachedState = 0; mCachedState = 0;
} }
- (NSUInteger)accessibilityArrayAttributeCount:(NSString*)attribute {
AccessibleWrap* accWrap = [self getGeckoAccessible];
ProxyAccessible* proxy = [self getProxyAccessible];
if (!accWrap && !proxy) return 0;
// By default this calls -[[mozAccessible children] count].
// Since we don't cache mChildren. This is faster.
if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
if (accWrap) return accWrap->ChildCount();
return proxy->ChildrenCount();
}
id array = [self accessibilityAttributeValue:attribute];
return [array isKindOfClass:[NSArray class]] ? [array count] : 0;
}
- (id)accessibilityAttributeValue:(NSString*)attribute { - (id)accessibilityAttributeValue:(NSString*)attribute {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
@ -745,21 +762,17 @@ static const uint64_t kCacheInitialized = ((uint64_t)0x1) << 63;
} }
// gets our native children lazily. // gets our native children lazily.
// returns nil when there are no children.
- (NSArray*)children { - (NSArray*)children {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mChildren) return mChildren; NSMutableArray* children = [NSMutableArray new];
// get the array of children.
mChildren = [[NSMutableArray alloc] init];
AccessibleWrap* accWrap = [self getGeckoAccessible]; AccessibleWrap* accWrap = [self getGeckoAccessible];
if (accWrap) { if (accWrap) {
uint32_t childCount = accWrap->ChildCount(); uint32_t childCount = accWrap->ChildCount();
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) { for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
mozAccessible* nativeChild = GetNativeFromGeckoAccessible(accWrap->GetChildAt(childIdx)); mozAccessible* nativeChild = GetNativeFromGeckoAccessible(accWrap->GetChildAt(childIdx));
if (nativeChild) [mChildren addObject:nativeChild]; if (nativeChild) [children addObject:nativeChild];
} }
// children from child if this is an outerdoc // children from child if this is an outerdoc
@ -767,7 +780,7 @@ static const uint64_t kCacheInitialized = ((uint64_t)0x1) << 63;
if (docOwner) { if (docOwner) {
if (ProxyAccessible* proxyDoc = docOwner->RemoteChildDoc()) { if (ProxyAccessible* proxyDoc = docOwner->RemoteChildDoc()) {
mozAccessible* nativeRemoteChild = GetNativeFromProxy(proxyDoc); mozAccessible* nativeRemoteChild = GetNativeFromProxy(proxyDoc);
[mChildren insertObject:nativeRemoteChild atIndex:0]; [children insertObject:nativeRemoteChild atIndex:0];
NSAssert1(nativeRemoteChild, @"%@ found a child remote doc missing a native\n", self); NSAssert1(nativeRemoteChild, @"%@ found a child remote doc missing a native\n", self);
} }
} }
@ -775,11 +788,11 @@ static const uint64_t kCacheInitialized = ((uint64_t)0x1) << 63;
uint32_t childCount = proxy->ChildrenCount(); uint32_t childCount = proxy->ChildrenCount();
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) { for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
mozAccessible* nativeChild = GetNativeFromProxy(proxy->ChildAt(childIdx)); mozAccessible* nativeChild = GetNativeFromProxy(proxy->ChildAt(childIdx));
if (nativeChild) [mChildren addObject:nativeChild]; if (nativeChild) [children addObject:nativeChild];
} }
} }
return mChildren; return children;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL; NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
} }
@ -1267,26 +1280,6 @@ struct RoleDescrComparator {
NS_OBJC_END_TRY_ABORT_BLOCK_NIL; NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
} }
- (void)invalidateChildren {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// make room for new children
if (mChildren) {
[mChildren release];
mChildren = nil;
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)appendChild:(Accessible*)aAccessible {
// if mChildren is nil, then we don't even need to bother
if (!mChildren) return;
mozAccessible* curNative = GetNativeFromGeckoAccessible(aAccessible);
if (curNative) [mChildren addObject:curNative];
}
- (BOOL)accessibilityNotifiesWhenDestroyed { - (BOOL)accessibilityNotifiesWhenDestroyed {
return YES; return YES;
} }
@ -1294,8 +1287,6 @@ struct RoleDescrComparator {
- (void)expire { - (void)expire {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK; NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[self invalidateChildren];
[self invalidateState]; [self invalidateState];
mGeckoAccessible = 0; mGeckoAccessible = 0;