| Index: chrome/browser/resources/access_chromevox/chromevox/background/background.js
|
| ===================================================================
|
| --- chrome/browser/resources/access_chromevox/chromevox/background/background.js (revision 0)
|
| +++ chrome/browser/resources/access_chromevox/chromevox/background/background.js (revision 0)
|
| @@ -0,0 +1,221 @@
|
| +// Copyright (c) 2011 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 Script that runs on the background page.
|
| + */
|
| +
|
| +goog.provide('cvox.ChromeVoxBackground');
|
| +
|
| +goog.require('cvox.BuildConfig');
|
| +
|
| +goog.require('cvox.ChromeVoxAccessibilityApiHandler');
|
| +goog.require('cvox.ChromeVoxChromeOsTtsEngine');
|
| +goog.require('cvox.ChromeVoxEarcons');
|
| +goog.require('cvox.ChromeVoxEmacspeakTtsServerEngine');
|
| +goog.require('cvox.ChromeVoxExtensionTtsEngine');
|
| +goog.require('cvox.ChromeVoxFlashGoossEngine');
|
| +goog.require('cvox.ChromeVoxGoossEngine');
|
| +goog.require('cvox.ChromeVoxLocalTtsServerEngine');
|
| +goog.require('cvox.ExtensionBridge');
|
| +goog.require('cvox.LocalEarconsManager');
|
| +goog.require('cvox.LocalTtsManager');
|
| +
|
| +/**
|
| + * This object manages the global and persistent state for ChromeVox.
|
| + * It listens for messages from the content scripts on pages and
|
| + * interprets them.
|
| + * @constructor
|
| + */
|
| +cvox.ChromeVoxBackground = function() {
|
| +};
|
| +
|
| +/**
|
| + * Initialize the background page: set up TTS and bridge listeners.
|
| + */
|
| +cvox.ChromeVoxBackground.prototype.init = function() {
|
| + // TODO (clchen): Implement the options page - but make sure the default
|
| + // is set on the background page, because the options page doesn't actually
|
| + // load unless the user opens it.
|
| + localStorage['keyBindings'] = JSON.stringify({
|
| + // Stop TTS
|
| + '#17' : 'stopSpeech', // Ctrl
|
| +
|
| + // TAB/Shift+TAB
|
| + '#9' : 'handleTab', // Tab
|
| + 'Shift+#9' : 'handleTab',
|
| +
|
| + // Basic navigation
|
| + 'Ctrl+Alt+#38' : 'backward',
|
| + 'Ctrl+Alt+#40' : 'forward',
|
| + 'Ctrl+Alt+#37' : 'previousGranularity',
|
| + 'Ctrl+Alt+#39' : 'nextGranularity',
|
| + '#13' : 'actOnCurrentItem', // ENTER
|
| +
|
| + // General commands
|
| + 'Ctrl+Alt+#191' : 'toggleSearchWidget', // '/'
|
| + 'Ctrl+Alt+B' : 'showBookmarkManager',
|
| + 'Ctrl+Alt+A' : 'nextTtsEngine',
|
| + 'Ctrl+Alt+#189' : 'decreaseTtsRate', // '-'
|
| + 'Ctrl+Alt+#187' : 'increaseTtsRate', // '='
|
| + 'Ctrl+Alt+Shift+#189' : 'decreaseTtsPitch', // '-'
|
| + 'Ctrl+Alt+Shift+#187' : 'increaseTtsPitch', // '='
|
| + 'Ctrl+Alt+#219' : 'decreaseTtsVolume', // '['
|
| + 'Ctrl+Alt+#221' : 'increaseTtsVolume', // ']'
|
| +
|
| + // Jump commands
|
| + 'Ctrl+Alt+1' : 'nextHeading1',
|
| + 'Ctrl+Alt+Shift+1' : 'previousHeading1',
|
| + 'Ctrl+Alt+2' : 'nextHeading2',
|
| + 'Ctrl+Alt+Shift+2' : 'previousHeading2',
|
| + 'Ctrl+Alt+3' : 'nextHeading3',
|
| + 'Ctrl+Alt+Shift+3' : 'previousHeading3',
|
| + 'Ctrl+Alt+4' : 'nextHeading4',
|
| + 'Ctrl+Alt+Shift+4' : 'previousHeading4',
|
| + 'Ctrl+Alt+5' : 'nextHeading5',
|
| + 'Ctrl+Alt+Shift+5' : 'previousHeading5',
|
| + 'Ctrl+Alt+6' : 'nextHeading6',
|
| + 'Ctrl+Alt+Shift+6' : 'previousHeading6',
|
| + 'Ctrl+Alt+C' : 'nextComboBox',
|
| + 'Ctrl+Alt+Shift+C' : 'previousComboBox',
|
| + 'Ctrl+Alt+E' : 'nextEditText',
|
| + 'Ctrl+Alt+Shift+E' : 'previousEditText',
|
| + 'Ctrl+Alt+F' : 'nextFormField',
|
| + 'Ctrl+Alt+Shift+F' : 'previousFormField',
|
| + 'Ctrl+Alt+G' : 'nextGraphic',
|
| + 'Ctrl+Alt+Shift+G' : 'previousGraphic',
|
| + 'Ctrl+Alt+H' : 'nextHeading',
|
| + 'Ctrl+Alt+Shift+H' : 'previousHeading',
|
| + 'Ctrl+Alt+I' : 'nextListItem',
|
| + 'Ctrl+Alt+Shift+I' : 'previousListItem',
|
| + 'Ctrl+Alt+L' : 'nextLink',
|
| + 'Ctrl+Alt+Shift+L' : 'previousLink',
|
| + 'Ctrl+Alt+N' : 'nextNotLink',
|
| + 'Ctrl+Alt+Shift+N' : 'previousNotLink',
|
| + 'Ctrl+Alt+O' : 'nextList',
|
| + 'Ctrl+Alt+Shift+O' : 'previousList',
|
| + 'Ctrl+Alt+Q' : 'nextBlockquote',
|
| + 'Ctrl+Alt+Shift+Q' : 'previousBlockquote',
|
| + 'Ctrl+Alt+R' : 'nextRadio',
|
| + 'Ctrl+Alt+Shift+R' : 'previousRadio',
|
| + 'Ctrl+Alt+S' : 'nextSlider',
|
| + 'Ctrl+Alt+Shift+S' : 'previousSlider',
|
| + 'Ctrl+Alt+T' : 'nextTable',
|
| + 'Ctrl+Alt+Shift+T' : 'previousTable',
|
| + 'Ctrl+Alt+U' : 'nextButton',
|
| + 'Ctrl+Alt+Shift+U' : 'previousButton',
|
| + 'Ctrl+Alt+X' : 'nextCheckbox',
|
| + 'Ctrl+Alt+Shift+X' : 'previousCheckbox'
|
| + });
|
| +
|
| + this.ttsManager = this.createTtsManager();
|
| + this.earconsManager = this.createEarconsManager(this.ttsManager);
|
| + this.addBridgeListener();
|
| +
|
| + cvox.ChromeVoxAccessibilityApiHandler.init(this.ttsManager,
|
| + this.earconsManager);
|
| +};
|
| +
|
| +/**
|
| + * @return {cvox.AbstractTtsManager} New initialized TTS manager.
|
| + */
|
| +cvox.ChromeVoxBackground.prototype.createTtsManager = function() {
|
| + var ttsEngines = [cvox.ChromeVoxFlashGoossEngine,
|
| + cvox.ChromeVoxChromeOsTtsEngine,
|
| + cvox.ChromeVoxGoossEngine,
|
| + cvox.ChromeVoxEmacspeakTtsServerEngine];
|
| + return new cvox.LocalTtsManager(ttsEngines, null);
|
| +};
|
| +
|
| +/**
|
| + * @param {cvox.AbstractTtsManager} ttsManager A TTS Manager.
|
| + * @return {Object} New initialized earcons manager.
|
| + */
|
| +cvox.ChromeVoxBackground.prototype.createEarconsManager = function(ttsManager) {
|
| + return new cvox.LocalEarconsManager([cvox.ChromeVoxEarcons], ttsManager);
|
| +};
|
| +
|
| +/**
|
| + * Send all of the settings to all active tabs.
|
| + */
|
| +cvox.ChromeVoxBackground.prototype.sendSettingsToActiveTab = function() {
|
| + cvox.ExtensionBridge.send({'keyBindings':
|
| + JSON.parse(localStorage['keyBindings'])});
|
| +};
|
| +
|
| +/**
|
| + * Called when a TTS message is received from a page content script.
|
| + * @param {Object} msg The TTS message.
|
| + */
|
| +cvox.ChromeVoxBackground.prototype.onTtsMessage = function(msg) {
|
| + if (msg.action == 'speak') {
|
| + this.ttsManager.speak(msg.text, msg.queueMode, msg.properties);
|
| + } else if (msg.action == 'stop') {
|
| + this.ttsManager.stop();
|
| + } else if (msg.action == 'nextEngine') {
|
| + this.ttsManager.nextTtsEngine(true);
|
| + } else if (msg.action == 'increaseRate') {
|
| + this.ttsManager.increaseProperty(
|
| + cvox.AbstractTtsManager.TTS_PROPERTY_RATE);
|
| + } else if (msg.action == 'decreaseRate') {
|
| + this.ttsManager.decreaseProperty(
|
| + cvox.AbstractTtsManager.TTS_PROPERTY_RATE);
|
| + } else if (msg.action == 'increasePitch') {
|
| + this.ttsManager.increaseProperty(
|
| + cvox.AbstractTtsManager.TTS_PROPERTY_PITCH);
|
| + } else if (msg.action == 'decreasePitch') {
|
| + this.ttsManager.decreaseProperty(
|
| + cvox.AbstractTtsManager.TTS_PROPERTY_PITCH);
|
| + } else if (msg.action == 'increaseVolume') {
|
| + this.ttsManager.increaseProperty(
|
| + cvox.AbstractTtsManager.TTS_PROPERTY_VOLUME);
|
| + } else if (msg.action == 'decreaseVolume') {
|
| + this.ttsManager.decreaseProperty(
|
| + cvox.AbstractTtsManager.TTS_PROPERTY_VOLUME);
|
| + }
|
| +};
|
| +
|
| +/**
|
| + * Called when an earcon message is received from a page content script.
|
| + * @param {Object} msg The earcon message.
|
| + */
|
| +cvox.ChromeVoxBackground.prototype.onEarconMessage = function(msg) {
|
| + if (msg.action == 'play') {
|
| + this.earconsManager.playEarcon(msg.earcon);
|
| + } else if (msg.action == 'nextEacons') {
|
| + this.earconsManager.nextEarcons();
|
| + }
|
| +};
|
| +
|
| +/**
|
| + * Listen for connections from our content script bridges, and dispatch the
|
| + * messages to the proper destination.
|
| + */
|
| +cvox.ChromeVoxBackground.prototype.addBridgeListener = function() {
|
| + var context = this;
|
| + cvox.ExtensionBridge.addMessageListener(function(msg) {
|
| + if (msg.target == 'BookmarkManager') {
|
| + var createDataObj = new Object();
|
| + createDataObj.url =
|
| + 'chromevox/background/bookmark_manager.html';
|
| + chrome.windows.create(createDataObj);
|
| + } else if (msg.target == 'Options') {
|
| + if (msg.action == 'getSettings') {
|
| + context.sendSettingsToActiveTab();
|
| + } else if (msg.action == 'open') {
|
| + console.log('Options open called');
|
| + var optionsPage = new Object();
|
| + optionsPage.url = 'options.html';
|
| + chrome.windows.create(optionsPage);
|
| + }
|
| + } else if (msg.target == 'TTS') {
|
| + context.onTtsMessage(msg);
|
| + } else if (msg.target == 'EARCON') {
|
| + context.onEarconMessage(msg);
|
| + }
|
| + });
|
| +};
|
| +
|
| +var background = new cvox.ChromeVoxBackground();
|
| +background.init();
|
|
|
| Property changes on: chrome/browser/resources/access_chromevox/chromevox/background/background.js
|
| ___________________________________________________________________
|
| Added: svn:executable
|
| + *
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|