Commit 31524c7c authored by dtseng's avatar dtseng Committed by Commit bot

Refactor tabs API handlers out of AccessibilityApiHandler.

Review URL: https://codereview.chromium.org/572373002

Cr-Commit-Position: refs/heads/master@{#296013}
parent 6f29d319
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
/** /**
* @fileoverview Accesses Chrome's accessibility extension API and gives * @fileoverview Accesses Chrome's accessibility extension API and gives
* spoken feedback for events that happen in the "Chrome of Chrome". * spoken feedback for events that happen in the "Chrome of Chrome".
*
*/ */
goog.provide('cvox.AccessibilityApiHandler'); goog.provide('cvox.AccessibilityApiHandler');
...@@ -175,24 +174,6 @@ cvox.AccessibilityApiHandler.prototype.addEventListeners_ = function() { ...@@ -175,24 +174,6 @@ cvox.AccessibilityApiHandler.prototype.addEventListeners_ = function() {
var accessibility = chrome.accessibilityPrivate; var accessibility = chrome.accessibilityPrivate;
chrome.tabs.onCreated.addListener(goog.bind(function(tab) {
if (!cvox.ChromeVox.isActive) {
return;
}
this.tts.speak(msg('chrome_tab_created'),
0,
cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT);
this.braille.write(cvox.NavBraille.fromText(msg('chrome_tab_created')));
this.earcons.playEarcon(cvox.AbstractEarcons.OBJECT_OPEN);
}, this));
chrome.tabs.onRemoved.addListener(goog.bind(function(tab) {
if (!cvox.ChromeVox.isActive) {
return;
}
this.earcons.playEarcon(cvox.AbstractEarcons.OBJECT_CLOSE);
}, this));
chrome.tabs.onActivated.addListener(goog.bind(function(activeInfo) { chrome.tabs.onActivated.addListener(goog.bind(function(activeInfo) {
if (!cvox.ChromeVox.isActive) { if (!cvox.ChromeVox.isActive) {
return; return;
...@@ -201,55 +182,10 @@ cvox.AccessibilityApiHandler.prototype.addEventListeners_ = function() { ...@@ -201,55 +182,10 @@ cvox.AccessibilityApiHandler.prototype.addEventListeners_ = function() {
if (tab.status == 'loading') { if (tab.status == 'loading') {
return; return;
} }
var title = tab.title ? tab.title : tab.url;
this.tts.speak(msg('chrome_tab_selected',
[title]),
cvox.AbstractTts.QUEUE_MODE_FLUSH,
cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT);
this.braille.write(
cvox.NavBraille.fromText(msg('chrome_tab_selected', [title])));
this.earcons.playEarcon(cvox.AbstractEarcons.OBJECT_SELECT);
this.queueAlertsForActiveTab(); this.queueAlertsForActiveTab();
}, this)); }, this));
}, this)); }, this));
chrome.tabs.onUpdated.addListener(goog.bind(function(tabId, selectInfo) {
if (!cvox.ChromeVox.isActive) {
return;
}
chrome.tabs.get(tabId, goog.bind(function(tab) {
if (!tab.active) {
return;
}
if (tab.status == 'loading') {
this.earcons.playEarcon(cvox.AbstractEarcons.BUSY_PROGRESS_LOOP);
} else {
this.earcons.playEarcon(cvox.AbstractEarcons.TASK_SUCCESS);
}
}, this));
}, this));
chrome.windows.onFocusChanged.addListener(goog.bind(function(windowId) {
if (!cvox.ChromeVox.isActive) {
return;
}
if (windowId == chrome.windows.WINDOW_ID_NONE) {
return;
}
chrome.windows.get(windowId, goog.bind(function(window) {
chrome.tabs.getSelected(windowId, goog.bind(function(tab) {
var msgId = window.incognito ? 'chrome_incognito_window_selected' :
'chrome_normal_window_selected';
var title = tab.title ? tab.title : tab.url;
this.tts.speak(msg(msgId, [title]),
cvox.AbstractTts.QUEUE_MODE_FLUSH,
cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT);
this.braille.write(cvox.NavBraille.fromText(msg(msgId, [title])));
this.earcons.playEarcon(cvox.AbstractEarcons.OBJECT_SELECT);
}, this));
}, this));
}, this));
chrome.accessibilityPrivate.onWindowOpened.addListener( chrome.accessibilityPrivate.onWindowOpened.addListener(
goog.bind(function(win) { goog.bind(function(win) {
if (!cvox.ChromeVox.isActive) { if (!cvox.ChromeVox.isActive) {
......
...@@ -29,6 +29,7 @@ goog.require('cvox.NavBraille'); ...@@ -29,6 +29,7 @@ goog.require('cvox.NavBraille');
goog.require('cvox.OptionsPage'); goog.require('cvox.OptionsPage');
goog.require('cvox.PlatformFilter'); goog.require('cvox.PlatformFilter');
goog.require('cvox.PlatformUtil'); goog.require('cvox.PlatformUtil');
goog.require('cvox.TabsApiHandler');
goog.require('cvox.TtsBackground'); goog.require('cvox.TtsBackground');
...@@ -88,6 +89,8 @@ cvox.ChromeVoxBackground.prototype.init = function() { ...@@ -88,6 +89,8 @@ cvox.ChromeVoxBackground.prototype.init = function() {
this.accessibilityApiHandler_ = new cvox.AccessibilityApiHandler( this.accessibilityApiHandler_ = new cvox.AccessibilityApiHandler(
this.tts, this.backgroundBraille_, this.earcons); this.tts, this.backgroundBraille_, this.earcons);
this.tabsApiHandler_ = new cvox.TabsApiHandler(
this.tts, this.backgroundBraille_, this.earcons);
// Export globals on cvox.ChromeVox. // Export globals on cvox.ChromeVox.
cvox.ChromeVox.tts = this.tts; cvox.ChromeVox.tts = this.tts;
......
// Copyright 2014 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 Accesses Chrome's tabs extension API and gives
* feedback for events that happen in the "Chrome of Chrome".
*/
goog.provide('cvox.TabsApiHandler');
goog.require('cvox.AbstractEarcons');
goog.require('cvox.AbstractTts');
goog.require('cvox.BrailleInterface');
goog.require('cvox.BrailleUtil');
goog.require('cvox.NavBraille');
/**
* Class that adds listeners and handles events from the tabs API.
* @constructor
* @param {cvox.TtsInterface} tts The TTS to use for speaking.
* @param {cvox.BrailleInterface} braille The braille interface to use for
* brailling.
* @param {cvox.AbstractEarcons} earcons The earcons object to use for playing
* earcons.
*/
cvox.TabsApiHandler = function(tts, braille, earcons) {
/** @type {cvox.TtsInterface} @private */
this.tts_ = tts;
/** @type {cvox.BrailleInterface} @private */
this.braille_ = braille;
/** @type {cvox.AbstractEarcons} @private */
this.earcons_ = earcons;
/** @type {function(string)} @private */
this.msg_ = cvox.ChromeVox.msgs.getMsg.bind(cvox.ChromeVox.msgs);
chrome.tabs.onCreated.addListener(this.onCreated.bind(this));
chrome.tabs.onRemoved.addListener(this.onRemoved.bind(this));
chrome.tabs.onActivated.addListener(this.onActivated.bind(this));
chrome.tabs.onUpdated.addListener(this.onUpdated.bind(this));
chrome.windows.onFocusChanged.addListener(this.onFocusChanged.bind(this));
};
cvox.TabsApiHandler.prototype = {
/**
* Handles chrome.tabs.onCreated.
* @param {Object} tab
*/
onCreated: function(tab) {
if (!cvox.ChromeVox.isActive) {
return;
}
this.tts_.speak(this.msg_('chrome_tab_created'),
cvox.AbstractTts.QUEUE_MODE_FLUSH,
cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT);
this.braille_.write(
cvox.NavBraille.fromText(this.msg_('chrome_tab_created')));
this.earcons_.playEarcon(cvox.AbstractEarcons.OBJECT_OPEN);
},
/**
* Handles chrome.tabs.onRemoved.
* @param {Object} tab
*/
onRemoved: function(tab) {
if (!cvox.ChromeVox.isActive) {
return;
}
this.earcons_.playEarcon(cvox.AbstractEarcons.OBJECT_CLOSE);
},
/**
* Handles chrome.tabs.onActivated.
* @param {Object} activeInfo
*/
onActivated: function(activeInfo) {
if (!cvox.ChromeVox.isActive) {
return;
}
chrome.tabs.get(activeInfo.tabId, function(tab) {
if (tab.status == 'loading') {
return;
}
var title = tab.title ? tab.title : tab.url;
this.tts_.speak(this.msg_('chrome_tab_selected',
[title]),
cvox.AbstractTts.QUEUE_MODE_FLUSH,
cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT);
this.braille_.write(
cvox.NavBraille.fromText(this.msg_('chrome_tab_selected', [title])));
this.earcons_.playEarcon(cvox.AbstractEarcons.OBJECT_SELECT);
}.bind(this));
},
/**
* Handles chrome.tabs.onUpdated.
* @param {number} tabId
* @param {Object} selectInfo
*/
onUpdated: function(tabId, selectInfo) {
if (!cvox.ChromeVox.isActive) {
return;
}
chrome.tabs.get(tabId, function(tab) {
if (!tab.active) {
return;
}
if (tab.status == 'loading') {
this.earcons_.playEarcon(cvox.AbstractEarcons.BUSY_PROGRESS_LOOP);
} else {
this.earcons_.playEarcon(cvox.AbstractEarcons.TASK_SUCCESS);
}
}.bind(this));
},
/**
* Handles chrome.windows.onFocusChanged.
* @param {number} windowId
*/
onFocusChanged: function(windowId) {
if (!cvox.ChromeVox.isActive) {
return;
}
if (windowId == chrome.windows.WINDOW_ID_NONE) {
return;
}
chrome.windows.get(windowId, function(window) {
chrome.tabs.getSelected(windowId, function(tab) {
var msgId = window.incognito ? 'chrome_incognito_window_selected' :
'chrome_normal_window_selected';
var title = tab.title ? tab.title : tab.url;
this.tts_.speak(this.msg_(msgId, [title]),
cvox.AbstractTts.QUEUE_MODE_FLUSH,
cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT);
this.braille_.write(
cvox.NavBraille.fromText(this.msg_(msgId, [title])));
this.earcons_.playEarcon(cvox.AbstractEarcons.OBJECT_SELECT);
}.bind(this));
}.bind(this));
}
};
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
{ {
'variables': { 'variables': {
'chromevox_dir': '.',
'chromevox_third_party_dir': '<(DEPTH)/chrome/third_party/chromevox', 'chromevox_third_party_dir': '<(DEPTH)/chrome/third_party/chromevox',
'closure_goog_dir': '<(chromevox_third_party_dir)/third_party/closure-library/closure/goog', 'closure_goog_dir': '<(chromevox_third_party_dir)/third_party/closure-library/closure/goog',
'chromevox_dest_dir': '<(PRODUCT_DIR)/resources/chromeos/chromevox', 'chromevox_dest_dir': '<(PRODUCT_DIR)/resources/chromeos/chromevox',
'js_root_flags': [ 'js_root_flags': [
'-r', '.', '-r', '.',
'-r', '<(chromevox_dir)',
'-r', '<(closure_goog_dir)', '-r', '<(closure_goog_dir)',
'-x', 'testing', '-x', 'testing',
'-x', '_test.js', '-x', '_test.js',
......
...@@ -24,10 +24,6 @@ ...@@ -24,10 +24,6 @@
'type': 'none', 'type': 'none',
'variables': { 'variables': {
'dest_dir': '<(chromevox_dest_dir)', 'dest_dir': '<(chromevox_dest_dir)',
'js_root_flags': [
'-r', '.',
'-r', '<(closure_goog_dir)',
],
}, },
'sources': [ 'sources': [
'cvox2/background/loader.js', 'cvox2/background/loader.js',
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
goog.provide('cvox2.Background'); goog.provide('cvox2.Background');
goog.provide('cvox2.global'); goog.provide('cvox2.global');
goog.require('cvox.TabsApiHandler');
/** Classic Chrome accessibility API. */ /** Classic Chrome accessibility API. */
cvox2.global.accessibility = cvox2.global.accessibility =
chrome.accessibilityPrivate || chrome.experimental.accessibility; chrome.accessibilityPrivate || chrome.experimental.accessibility;
...@@ -25,9 +27,12 @@ cvox2.Background = function() { ...@@ -25,9 +27,12 @@ cvox2.Background = function() {
*/ */
this.whitelist_ = ['http://www.chromevox.com/', 'chromevox_next_test']; this.whitelist_ = ['http://www.chromevox.com/', 'chromevox_next_test'];
/** @type {cvox.TabsApiHandler} @private */
this.tabsHandler_ = new cvox.TabsApiHandler(cvox.ChromeVox.tts,
cvox.ChromeVox.braille,
cvox.ChromeVox.earcons);
// Only needed with unmerged ChromeVox classic loaded before. // Only needed with unmerged ChromeVox classic loaded before.
// TODO(dtseng): Refactor all tabs handlers out of
// accessibility_api_handler.js.
cvox2.global.accessibility.setAccessibilityEnabled(false); cvox2.global.accessibility.setAccessibilityEnabled(false);
// Manually bind all functions to |this|. // Manually bind all functions to |this|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment