Bug 1498235 - lazy load accessibility highlighter in accessibility walker actor. r=gl
☠☠ backed out by 4ef080fed9d2 ☠ ☠
authorYura Zenevich <yura.zenevich@gmail.com>
Wed, 24 Oct 2018 04:16:43 +0000
changeset 491264 8399e5224d6935e06c37eb600b34967ba06b4487
parent 491263 134717494734f146e380f26128f4a892b16a30ff
child 491265 980d3b8e603b3cdebf7cc647b39b01576f0178b0
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersgl
bugs1498235
milestone65.0a1
Bug 1498235 - lazy load accessibility highlighter in accessibility walker actor. r=gl MozReview-Commit-ID: 7xFlSocDPVG Depends on D9580 Differential Revision: https://phabricator.services.mozilla.com/D9581
devtools/server/actors/accessibility/walker.js
--- a/devtools/server/actors/accessibility/walker.js
+++ b/devtools/server/actors/accessibility/walker.js
@@ -3,25 +3,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { Cc, Ci } = require("chrome");
 const Services = require("Services");
 const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
 const { accessibleWalkerSpec } = require("devtools/shared/specs/accessibility");
-const { isXUL } = require("devtools/server/actors/highlighters/utils/markup");
-const { CustomHighlighterActor, register } =
-  require("devtools/server/actors/highlighters");
 
 loader.lazyRequireGetter(this, "AccessibleActor", "devtools/server/actors/accessibility/accessible", true);
+loader.lazyRequireGetter(this, "CustomHighlighterActor", "devtools/server/actors/highlighters", true);
 loader.lazyRequireGetter(this, "DevToolsUtils", "devtools/shared/DevToolsUtils");
 loader.lazyRequireGetter(this, "events", "devtools/shared/event-emitter");
 loader.lazyRequireGetter(this, "isDefunct", "devtools/server/actors/utils/accessibility", true);
+loader.lazyRequireGetter(this, "isTypeRegistered", "devtools/server/actors/highlighters", true);
 loader.lazyRequireGetter(this, "isWindowIncluded", "devtools/shared/layout/utils", true);
+loader.lazyRequireGetter(this, "isXUL", "devtools/server/actors/highlighters/utils/markup", true);
+loader.lazyRequireGetter(this, "register", "devtools/server/actors/highlighters", true);
 
 const nsIAccessibleEvent = Ci.nsIAccessibleEvent;
 const nsIAccessibleStateChangeEvent = Ci.nsIAccessibleStateChangeEvent;
 const nsIAccessibleRole = Ci.nsIAccessibleRole;
 
 const {
   EVENT_TEXT_CHANGED,
   EVENT_TEXT_INSERTED,
@@ -87,19 +88,16 @@ const NAME_FROM_SUBTREE_RULE_ROLES = new
   nsIAccessibleRole.ROLE_TEAR_OFF_MENU_ITEM,
   nsIAccessibleRole.ROLE_TERM,
   nsIAccessibleRole.ROLE_TOGGLE_BUTTON,
   nsIAccessibleRole.ROLE_TOOLTIP,
 ]);
 
 const IS_OSX = Services.appinfo.OS === "Darwin";
 
-register("AccessibleHighlighter", "accessible");
-register("XULWindowAccessibleHighlighter", "xul-accessible");
-
 /**
  * Helper function that determines if nsIAccessible object is in stale state. When an
  * object is stale it means its subtree is not up to date.
  *
  * @param  {nsIAccessible}  accessible
  *         object to be tested.
  * @return {Boolean}
  *         True if accessible object is stale, false otherwise.
@@ -126,21 +124,36 @@ const AccessibleWalkerActor = ActorClass
     this.targetActor = targetActor;
     this.refMap = new Map();
     this.setA11yServiceGetter();
     this.onPick = this.onPick.bind(this);
     this.onHovered = this.onHovered.bind(this);
     this.onKey = this.onKey.bind(this);
     this.onHighlighterEvent = this.onHighlighterEvent.bind(this);
 
-    this.highlighter = CustomHighlighterActor(this, isXUL(this.rootWin) ?
-      "XULWindowAccessibleHighlighter" : "AccessibleHighlighter");
+    DevToolsUtils.defineLazyGetter(this, "highlighter", () => {
+      let highlighter;
+      if (isXUL(this.rootWin)) {
+        if (!isTypeRegistered("XULWindowAccessibleHighlighter")) {
+          register("XULWindowAccessibleHighlighter", "xul-accessible");
+        }
 
-    this.manage(this.highlighter);
-    this.highlighter.on("highlighter-event", this.onHighlighterEvent);
+        highlighter = CustomHighlighterActor(this, "XULWindowAccessibleHighlighter");
+      } else {
+        if (!isTypeRegistered("AccessibleHighlighter")) {
+          register("AccessibleHighlighter", "accessible");
+        }
+
+        highlighter = CustomHighlighterActor(this, "AccessibleHighlighter");
+      }
+
+      this.manage(highlighter);
+      highlighter.on("highlighter-event", this.onHighlighterEvent);
+      return highlighter;
+    });
   },
 
   setA11yServiceGetter() {
     DevToolsUtils.defineLazyGetter(this, "a11yService", () => {
       Services.obs.addObserver(this, "accessible-event");
       return Cc["@mozilla.org/accessibilityService;1"].getService(
         Ci.nsIAccessibilityService);
     });