[orca] Web: When dumping cache due to children-changed preserve context by default



commit 5ad5e62d03c00b8858b4f7ff9ee1fb32d3771767
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Dec 15 13:51:50 2020 +0100

    Web: When dumping cache due to children-changed preserve context by default
    
    We now dump all of our cache when children-changed events are emitted.
    This ensures we are not working with a stale tree (which can cause us
    to get stuck and/or skip over content). Unfortunately, clearing the
    context has exposed bugs in browsers. It should be safe to preserve
    the context by default so we do not have to search for the current
    location after a children-changed event that hasn't destroyed the
    current location's accessible object.

 src/orca/scripts/web/script.py           | 12 ++----------
 src/orca/scripts/web/script_utilities.py | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index 14310fd55..8f8459f0f 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -1697,11 +1697,7 @@ class Script(default.Script):
         isLiveRegion = self.utilities.isLiveRegion(event.source)
         document = self.utilities.getDocumentForObject(event.source)
         if document and not isLiveRegion:
-            msg = "WEB: Clearing all cached info for %s" % document
-            debug.println(debug.LEVEL_INFO, msg, True)
-            self.structuralNavigation.clearCache(document)
-            self.utilities.clearCaretContext(document)
-            self.utilities.clearCachedObjects()
+            self.utilities.dumpCache(document)
         else:
             msg = "WEB: Could not get document for event source"
             debug.println(debug.LEVEL_INFO, msg, True)
@@ -1799,11 +1795,7 @@ class Script(default.Script):
 
         document = self.utilities.getDocumentForObject(event.source)
         if document:
-            msg = "WEB: Clearing all cached info for %s" % document
-            debug.println(debug.LEVEL_INFO, msg, True)
-            self.structuralNavigation.clearCache(document)
-            self.utilities.clearCaretContext(document)
-            self.utilities.clearCachedObjects()
+            self.utilities.dumpCache(document)
 
         if self.utilities.handleEventForRemovedChild(event):
             msg = "WEB: Event handled for removed child."
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 2bd298796..7a275e170 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -127,6 +127,24 @@ class Utilities(script_utilities.Utilities):
         for key in toRemove:
             self._caretContexts.pop(key, None)
 
+    def dumpCache(self, documentFrame, preserveContext=True):
+        if not documentFrame or self.isZombie(documentFrame):
+            documentFrame = self.documentFrame()
+
+        context = self._caretContexts.get(hash(documentFrame.parent))
+
+        msg = "WEB: Clearing all cached info for %s" % documentFrame
+        debug.println(debug.LEVEL_INFO, msg, True)
+
+        self._script.structuralNavigation.clearCache(documentFrame)
+        self.clearCaretContext(documentFrame)
+        self.clearCachedObjects()
+
+        if preserveContext and context:
+            msg = "WEB: Preserving context of %s, %i" % (context[0], context[1])
+            debug.println(debug.LEVEL_INFO, msg, True)
+            self._caretContexts[documentFrame.parent] = context
+
     def clearCachedObjects(self):
         debug.println(debug.LEVEL_INFO, "WEB: cleaning up cached objects", True)
         self._objectAttributes = {}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]