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

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

Issue 908853004: Revert of Reland #2: Ensure WebView notifies desktop automation on creation, destruction, and change Original (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/background.js
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js
index 7659707e0e8df9f73408e8af4ae124b754fe9506..c33060899fe391dfc8a3de1b3118514e1d1a699b 100644
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js
@@ -16,6 +16,7 @@
goog.require('Output.EventType');
goog.require('cursors.Cursor');
goog.require('cvox.ChromeVoxEditableTextBase');
+goog.require('cvox.TabsApiHandler');
goog.scope(function() {
var AutomationNode = chrome.automation.AutomationNode;
@@ -34,6 +35,14 @@
* @private
*/
this.whitelist_ = ['chromevox_next_test'];
+
+ /**
+ * @type {cvox.TabsApiHandler}
+ * @private
+ */
+ this.tabsHandler_ = new cvox.TabsApiHandler(cvox.ChromeVox.tts,
+ cvox.ChromeVox.braille,
+ cvox.ChromeVox.earcons);
/**
* @type {cursors.Range}
@@ -73,29 +82,43 @@
// Register listeners for ...
// Desktop.
- chrome.automation.getDesktop(this.onGotDesktop);
+ chrome.automation.getDesktop(this.onGotTree);
+
+ // Tabs.
+ chrome.tabs.onUpdated.addListener(this.onTabUpdated);
};
Background.prototype = {
/**
+ * Handles chrome.tabs.onUpdated.
+ * @param {number} tabId
+ * @param {Object} changeInfo
+ */
+ onTabUpdated: function(tabId, changeInfo) {
+ if (changeInfo.status != 'complete')
+ return;
+ chrome.tabs.get(tabId, function(tab) {
+ if (!tab.url)
+ return;
+
+ var next = this.isWhitelisted_(tab.url);
+
+ this.toggleChromeVoxVersion({next: next, classic: !next});
+ }.bind(this));
+ },
+
+ /**
* Handles all setup once a new automation tree appears.
- * @param {chrome.automation.AutomationNode} desktop
- */
- onGotDesktop: function(desktop) {
+ * @param {chrome.automation.AutomationNode} root
+ */
+ onGotTree: function(root) {
// Register all automation event listeners.
for (var eventType in this.listeners_)
- desktop.addEventListener(eventType, this.listeners_[eventType], true);
-
- // The focused state gets set on the containing webView node.
- var webView = desktop.find({role: chrome.automation.RoleType.webView,
- state: {focused: true}});
- if (webView) {
- var root = webView.find({role: chrome.automation.RoleType.rootWebArea});
- if (root) {
- this.onLoadComplete(
- {target: root,
- type: chrome.automation.EventType.loadComplete});
- }
+ root.addEventListener(eventType, this.listeners_[eventType], true);
+
+ if (root.attributes.docLoaded) {
+ this.onLoadComplete(
+ {target: root, type: chrome.automation.EventType.loadComplete});
}
},
@@ -247,28 +270,14 @@
* @param {Object} evt
*/
onLoadComplete: function(evt) {
- var next = this.isWhitelisted_(evt.target.attributes.url);
- this.toggleChromeVoxVersion({next: next, classic: !next});
// Don't process nodes inside of web content if ChromeVox Next is inactive.
if (evt.target.root.role != chrome.automation.RoleType.desktop &&
!this.active_)
return;
- if (this.currentRange_)
- return;
-
- var root = evt.target;
- var webView = root;
- while (webView && webView.role != chrome.automation.RoleType.webView)
- webView = webView.parent;
-
- if (!webView || !webView.state.focused)
- return;
-
- var node = AutomationUtil.findNodePost(root,
+ var node = AutomationUtil.findNodePost(evt.target,
Dir.FORWARD,
AutomationPredicate.leaf);
-
if (node)
this.currentRange_ = cursors.Range.fromNode(node);
@@ -353,11 +362,21 @@
if (opt_options.next) {
if (!chrome.commands.onCommand.hasListener(this.onGotCommand))
- chrome.commands.onCommand.addListener(this.onGotCommand);
- this.active_ = true;
+ chrome.commands.onCommand.addListener(this.onGotCommand);
+
+ if (!this.active_)
+ chrome.automation.getTree(this.onGotTree);
+ this.active_ = true;
} else {
if (chrome.commands.onCommand.hasListener(this.onGotCommand))
chrome.commands.onCommand.removeListener(this.onGotCommand);
+
+ if (this.active_) {
+ for (var eventType in this.listeners_) {
+ this.currentRange_.getStart().getNode().root.removeEventListener(
+ eventType, this.listeners_[eventType], true);
+ }
+ }
this.active_ = false;
}

Powered by Google App Engine
This is Rietveld 408576698