Bug 1519997 - Exclusively use cache for actions and events. r=geckoview-reviewers,snorp
authorEitan Isaacson <eitan@monotonous.org>
Thu, 17 Jan 2019 17:01:09 +0000
changeset 511397 779094a64ae178fe32a50798d0c1aafdad1aa68c
parent 511396 7949c9530cfe66194fa012b7b9b66d9e3f3d43e1
child 511398 32d337b78c8f7099fa0f741dc2f45a653a833a74
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp
bugs1519997
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519997 - Exclusively use cache for actions and events. r=geckoview-reviewers,snorp Differential Revision: https://phabricator.services.mozilla.com/D16499
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionAccessibility.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionAccessibility.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/SessionAccessibility.java
@@ -61,16 +61,17 @@ public class SessionAccessibility {
     @WrapForJNI static final int FLAG_LONG_CLICKABLE = 1 << 10;
     @WrapForJNI static final int FLAG_MULTI_LINE = 1 << 11;
     @WrapForJNI static final int FLAG_PASSWORD = 1 << 12;
     @WrapForJNI static final int FLAG_SCROLLABLE = 1 << 13;
     @WrapForJNI static final int FLAG_SELECTED = 1 << 14;
     @WrapForJNI static final int FLAG_VISIBLE_TO_USER = 1 << 15;
     @WrapForJNI static final int FLAG_SELECTABLE = 1 << 16;
 
+    static final int CLASSNAME_UNKNOWN = -1;
     @WrapForJNI static final int CLASSNAME_VIEW = 0;
     @WrapForJNI static final int CLASSNAME_BUTTON = 1;
     @WrapForJNI static final int CLASSNAME_CHECKBOX = 2;
     @WrapForJNI static final int CLASSNAME_DIALOG = 3;
     @WrapForJNI static final int CLASSNAME_EDITTEXT = 4;
     @WrapForJNI static final int CLASSNAME_GRIDVIEW = 5;
     @WrapForJNI static final int CLASSNAME_IMAGE = 6;
     @WrapForJNI static final int CLASSNAME_LISTVIEW = 7;
@@ -98,17 +99,17 @@ public class SessionAccessibility {
             "android.widget.SeekBar",
             "android.widget.Spinner",
             "android.widget.TabWidget",
             "android.widget.ToggleButton",
             "android.webkit.WebView"
     };
 
     static private String getClassName(final int index) {
-        if (index < CLASSNAMES.length) {
+        if (index >= 0 && index < CLASSNAMES.length) {
             return CLASSNAMES[index];
         }
 
         Log.e(LOGTAG, "Index " + index + " our of CLASSNAME bounds.");
         return "android.view.View"; // Fallback class is View
     }
 
     /* package */ final class NodeProvider extends AccessibilityNodeProvider {
@@ -135,39 +136,36 @@ public class SessionAccessibility {
         }
 
         @Override
         public boolean performAction(final int virtualViewId, int action, Bundle arguments) {
             final GeckoBundle data;
 
             switch (action) {
             case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
-                sendEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, virtualViewId, CLASSNAME_VIEW, null);
+                sendEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, virtualViewId, CLASSNAME_UNKNOWN, null);
                 return true;
             case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS:
                     if (virtualViewId == View.NO_ID) {
                         sendEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, View.NO_ID, CLASSNAME_WEBVIEW, null);
                     } else {
-                        final GeckoBundle nodeInfo = nativeProvider.getNodeInfo(virtualViewId);
-                        final int flags = nodeInfo != null ? nodeInfo.getInt("flags") : 0;
-                        if ((flags & FLAG_FOCUSED) != 0) {
+                        if (mFocusedNode == virtualViewId) {
                             mSession.getEventDispatcher().dispatch("GeckoView:AccessibilityCursorToFocused", null);
                         } else {
-                            final int className = nodeInfo != null ? nodeInfo.getInt("className") : CLASSNAME_VIEW;
-                            sendEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, virtualViewId, className, null);
+                            sendEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, virtualViewId, CLASSNAME_UNKNOWN, null);
                         }
                     }
                 return true;
             case AccessibilityNodeInfo.ACTION_CLICK:
                 nativeProvider.click(virtualViewId);
-                GeckoBundle nodeInfo = nativeProvider.getNodeInfo(virtualViewId);
-                final int flags = nodeInfo != null ? nodeInfo.getInt("flags") : 0;
-                if ((flags & (FLAG_SELECTABLE | FLAG_CHECKABLE)) == 0) {
-                    final int className = nodeInfo != null ? nodeInfo.getInt("className") : CLASSNAME_VIEW;
-                    sendEvent(AccessibilityEvent.TYPE_VIEW_CLICKED, virtualViewId, className, null);
+                GeckoBundle nodeInfo = getMostRecentBundle(virtualViewId);
+                if (nodeInfo != null) {
+                    if ((nodeInfo.getInt("flags") & (FLAG_SELECTABLE | FLAG_CHECKABLE)) == 0) {
+                        sendEvent(AccessibilityEvent.TYPE_VIEW_CLICKED, virtualViewId, nodeInfo.getInt("className"), null);
+                    }
                 }
                 return true;
             case AccessibilityNodeInfo.ACTION_LONG_CLICK:
                 mSession.getEventDispatcher().dispatch("GeckoView:AccessibilityLongPress", null);
                 return true;
             case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
                 mSession.getEventDispatcher().dispatch("GeckoView:AccessibilityScrollForward", null);
                 return true;
@@ -661,30 +659,31 @@ public class SessionAccessibility {
 
         if (!Settings.isPlatformEnabled() && (Build.VERSION.SDK_INT < 17 || mView.getDisplay() != null)) {
             // Accessibility could be activated in Gecko via xpcom, for example when using a11y
             // devtools. Here we assure that either Android a11y is *really* enabled, or no
             // display is attached and we must be in a junit test.
             return;
         }
 
-        GeckoBundle cachedBundle = null;
-        if (!mSession.getSettings().getFullAccessibilityTree()) {
-            cachedBundle = getMostRecentBundle(sourceId);
-            // Suppress events from non cached nodes if cache is enabled.
-            if (cachedBundle == null && sourceId != View.NO_ID) {
-                return;
-            }
+        GeckoBundle cachedBundle = getMostRecentBundle(sourceId);
+        if (cachedBundle == null && sourceId != View.NO_ID) {
+            // Suppress events from non cached nodes.
+            return;
         }
 
         final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
         event.setPackageName(GeckoAppShell.getApplicationContext().getPackageName());
         event.setSource(mView, sourceId);
-        event.setClassName(getClassName(className));
         event.setEnabled(true);
+        if (className == CLASSNAME_UNKNOWN && cachedBundle != null) {
+            event.setClassName(getClassName(cachedBundle.getInt("className")));
+        } else {
+            event.setClassName(getClassName(className));
+        }
 
         if (eventData != null) {
             if (eventData.containsKey("text")) {
                 event.getText().add(eventData.getString("text"));
             }
             event.setContentDescription(eventData.getString("description", ""));
             event.setAddedCount(eventData.getInt("addedCount", -1));
             event.setRemovedCount(eventData.getInt("removedCount", -1));