Bug 1498235 - only initialize accessibility actor when the toolbox opens or when a11y panel opens as a default panel. r=gl
authorYura Zenevich <yura.zenevich@gmail.com>
Tue, 30 Oct 2018 17:52:09 +0000
changeset 499969 d56a4f994d89e2331eb440b72d2cd32d9db62ef2
parent 499968 e46f007f2744512df791f0553e260e4aaa479397
child 499970 73b9703078a1f1055ce515d1fcce6b93f8e5d7f3
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1498235
milestone65.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 1498235 - only initialize accessibility actor when the toolbox opens or when a11y panel opens as a default panel. r=gl MozReview-Commit-ID: CzOTdDDU8fv Differential Revision: https://phabricator.services.mozilla.com/D9578
devtools/client/accessibility/accessibility-startup.js
--- a/devtools/client/accessibility/accessibility-startup.js
+++ b/devtools/client/accessibility/accessibility-startup.js
@@ -29,38 +29,67 @@ class AccessibilityStartup {
     return this._accessibility;
   }
 
   get walker() {
     return this._walker;
   }
 
   /**
+   * Determine which features are supported based on the version of the server. Also, sync
+   * the state of the accessibility front/actor.
+   * @return {Promise}
+   *         A promise that returns true when accessibility front is fully in sync with
+   *         the actor.
+   */
+  async prepareAccessibility() {
+    // We must call a method on an accessibility front here (such as getWalker), in
+    // oreder to be able to check actor's backward compatibility via actorHasMethod.
+    // See targe.js@getActorDescription for more information.
+    this._walker = await this._accessibility.getWalker();
+
+    this._supports = {};
+    // Only works with FF61+ targets
+    this._supports.enableDisable =
+      await this.target.actorHasMethod("accessibility", "enable");
+
+    if (this._supports.enableDisable) {
+      this._supports.relations =
+        await this.target.actorHasMethod("accessible", "getRelations");
+      await this._accessibility.bootstrap();
+    }
+
+    return true;
+  }
+
+  /**
    * Fully initialize accessibility front. Also add listeners for accessibility
    * service lifecycle events that affect the state of the tool tab highlight.
    * @return {Promise}
    *         A promise for when accessibility front is fully initialized.
    */
   initAccessibility() {
     if (!this._initAccessibility) {
       this._initAccessibility = (async function() {
+        await Promise.race([
+          this.toolbox.isOpen,
+          this.toolbox.once("accessibility-init"),
+        ]);
+
         this._accessibility = this.target.getFront("accessibility");
-        // We must call a method on an accessibility front here (such as getWalker), in
-        // oreder to be able to check actor's backward compatibility via actorHasMethod.
-        // See targe.js@getActorDescription for more information.
-        this._walker = await this._accessibility.getWalker();
-        this._supports = {};
-        // Only works with FF61+ targets
-        this._supports.enableDisable =
-          await this.target.actorHasMethod("accessibility", "enable");
-
-        if (this._supports.enableDisable) {
-          this._supports.relations =
-            await this.target.actorHasMethod("accessible", "getRelations");
-          await this._accessibility.bootstrap();
+        // When target is being destroyed (for example on remoteness change), it
+        // destroy accessibility front. In case when a11y is not fully initialized, that
+        // may result in unresolved promises.
+        const prepared = await Promise.race([
+          this.prepareAccessibility(),
+          this.target.once("close"), // does not have a value.
+        ]);
+        // If the target is being destroyed, no need to continue.
+        if (!prepared) {
+          return;
         }
 
         this._updateToolHighlight();
 
         this._accessibility.on("init", this._updateToolHighlight);
         this._accessibility.on("shutdown", this._updateToolHighlight);
       }.bind(this))();
     }