Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3897)

Unified Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/automation_object_constructor_installer.js

Issue 1942683005: Refactor event handler classes to make it easier to add new event type listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/automation_object_constructor_installer.js
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/automation_object_constructor_installer.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/automation_object_constructor_installer.js
new file mode 100644
index 0000000000000000000000000000000000000000..cdb5e93ec187fee0a9f273fb3740da6a3672e90a
--- /dev/null
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/automation_object_constructor_installer.js
@@ -0,0 +1,37 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview Provides bindings to instantiate objects in the automation API.
+ *
+ * Due to restrictions in the extension system, it is not ordinarily possible to
+ * construct an object defined by the extension API. However, given an instance
+ * of that object, we can save its constructor for future use.
+ */
+
+goog.provide('AutomationObjectConstructorInstaller');
+
+/**
+ * Installs the AutomationNode and AutomationEvent classes based on an
+ * AutomationNode instance.
+ * @param {chrome.automation.AutomationNode} node
+ * @param {function()} callback Called when installation finishes.
+ */
+AutomationObjectConstructorInstaller.init = function(node, callback) {
+ chrome.automation.AutomationNode =
+ /** @type {function (new:chrome.automation.AutomationNode)} */(
+ node.constructor);
+ node.addEventListener(chrome.automation.EventType.childrenChanged,
+ function installAutomationEvent(e) {
+ chrome.automation.AutomationEvent =
+ /** @type {function (new:chrome.automation.AutomationEvent)} */(
+ e.constructor);
+ node.removeEventListener(
+ chrome.automation.EventType.childrenChanged,
+ installAutomationEvent,
+ true);
+ callback();
+ },
+ true);
+};

Powered by Google App Engine
This is Rietveld 408576698