| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview The entry point for all ChromeVox2 related code for the | 6 * @fileoverview The entry point for all ChromeVox2 related code for the |
| 7 * background page. | 7 * background page. |
| 8 * | |
| 9 */ | 8 */ |
| 10 | 9 |
| 11 goog.provide('cvox2.Background'); | 10 goog.provide('cvox2.Background'); |
| 12 goog.provide('cvox2.global'); | 11 goog.provide('cvox2.global'); |
| 13 | 12 |
| 14 goog.require('cvox.TabsApiHandler'); | 13 goog.require('cvox.TabsApiHandler'); |
| 15 goog.require('cvox2.AutomationPredicates'); | 14 goog.require('cvox2.AutomationPredicates'); |
| 16 goog.require('cvox2.AutomationUtil'); | 15 goog.require('cvox2.AutomationUtil'); |
| 17 goog.require('cvox2.Dir'); | 16 goog.require('cvox2.Dir'); |
| 18 | 17 |
| 19 /** Classic Chrome accessibility API. */ | 18 /** Classic Chrome accessibility API. */ |
| 20 cvox2.global.accessibility = | 19 cvox2.global.accessibility = |
| 21 chrome.accessibilityPrivate || chrome.experimental.accessibility; | 20 chrome.accessibilityPrivate || chrome.experimental.accessibility; |
| 22 | 21 |
| 23 /** | 22 /** |
| 24 * ChromeVox2 background page. | 23 * ChromeVox2 background page. |
| 25 * @constructor | |
| 26 */ | 24 */ |
| 27 cvox2.Background = function() { | 25 cvox2.Background = function() { |
| 28 /** | 26 /** |
| 29 * A list of site substring patterns to use with ChromeVox next. Keep these | 27 * A list of site substring patterns to use with ChromeVox next. Keep these |
| 30 * strings relatively specific. | 28 * strings relatively specific. |
| 31 * @type {!Array.<string>} | 29 * @type {!Array.<string>} |
| 32 * @private | |
| 33 */ | 30 */ |
| 34 this.whitelist_ = ['http://www.chromevox.com/', 'chromevox_next_test']; | 31 this.whitelist_ = ['http://www.chromevox.com/', 'chromevox_next_test']; |
| 35 | 32 |
| 36 /** | 33 /** @type {cvox.TabsApiHandler} @private */ |
| 37 * @type {cvox.TabsApiHandler} | |
| 38 * @private | |
| 39 */ | |
| 40 this.tabsHandler_ = new cvox.TabsApiHandler(cvox.ChromeVox.tts, | 34 this.tabsHandler_ = new cvox.TabsApiHandler(cvox.ChromeVox.tts, |
| 41 cvox.ChromeVox.braille, | 35 cvox.ChromeVox.braille, |
| 42 cvox.ChromeVox.earcons); | 36 cvox.ChromeVox.earcons); |
| 43 | 37 |
| 44 /** | 38 /** @type {AutomationNode} @private */ |
| 45 * @type {chrome.automation.AutomationNode} | |
| 46 * @private | |
| 47 */ | |
| 48 this.currentNode_ = null; | 39 this.currentNode_ = null; |
| 49 | 40 |
| 41 /** @type {cvox.TabsApiHandler} @private */ |
| 42 this.tabsHandler_ = new cvox.TabsApiHandler(cvox.ChromeVox.tts, |
| 43 cvox.ChromeVox.braille, |
| 44 cvox.ChromeVox.earcons); |
| 45 |
| 50 // Only needed with unmerged ChromeVox classic loaded before. | 46 // Only needed with unmerged ChromeVox classic loaded before. |
| 51 cvox2.global.accessibility.setAccessibilityEnabled(false); | 47 cvox2.global.accessibility.setAccessibilityEnabled(false); |
| 52 | 48 |
| 53 // Manually bind all functions to |this|. | 49 // Manually bind all functions to |this|. |
| 54 for (var func in this) { | 50 for (var func in this) { |
| 55 if (typeof(this[func]) == 'function') | 51 if (typeof(this[func]) == 'function') |
| 56 this[func] = this[func].bind(this); | 52 this[func] = this[func].bind(this); |
| 57 } | 53 } |
| 58 | 54 |
| 59 // Register listeners for ... | 55 // Register listeners for ... |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 * @param {number} tabId | 66 * @param {number} tabId |
| 71 * @param {Object} changeInfo | 67 * @param {Object} changeInfo |
| 72 */ | 68 */ |
| 73 onTabUpdated: function(tabId, changeInfo) { | 69 onTabUpdated: function(tabId, changeInfo) { |
| 74 chrome.tabs.get(tabId, function(tab) { | 70 chrome.tabs.get(tabId, function(tab) { |
| 75 if (!tab.url) | 71 if (!tab.url) |
| 76 return; | 72 return; |
| 77 | 73 |
| 78 if (!this.isWhitelisted_(tab.url)) { | 74 if (!this.isWhitelisted_(tab.url)) { |
| 79 chrome.commands.onCommand.removeListener(this.onGotCommand); | 75 chrome.commands.onCommand.removeListener(this.onGotCommand); |
| 80 cvox.ChromeVox.injectChromeVoxIntoTabs([tab], true); | 76 cvox.ChromeVox.background.injectChromeVoxIntoTabs([tab], true); |
| 81 return; | 77 return; |
| 82 } | 78 } |
| 83 | 79 |
| 84 if (!chrome.commands.onCommand.hasListeners()) | 80 if (!chrome.commands.onCommand.hasListeners()) |
| 85 chrome.commands.onCommand.addListener(this.onGotCommand); | 81 chrome.commands.onCommand.addListener(this.onGotCommand); |
| 86 | 82 |
| 87 this.disableClassicChromeVox_(tab.id); | 83 this.disableClassicChromeVox_(tab.id); |
| 88 | 84 |
| 89 chrome.automation.getTree(this.onGotTree.bind(this)); | 85 chrome.automation.getTree(this.onGotTree.bind(this)); |
| 90 }.bind(this)); | 86 }.bind(this)); |
| 91 }, | 87 }, |
| 92 | 88 |
| 93 /** | 89 /** |
| 94 * Handles all setup once a new automation tree appears. | 90 * Handles all setup once a new automation tree appears. |
| 95 * @param {chrome.automation.AutomationNode} root | 91 * @param {AutomationTree} tree The new automation tree. |
| 96 */ | 92 */ |
| 97 onGotTree: function(root) { | 93 onGotTree: function(root) { |
| 98 // Register all automation event listeners. | 94 // Register all automation event listeners. |
| 99 root.addEventListener('focus', | 95 root.addEventListener(chrome.automation.EventType.focus, |
| 100 this.onFocus, | 96 this.onFocus, |
| 101 true); | 97 true); |
| 102 root.addEventListener('loadComplete', | 98 root.addEventListener(chrome.automation.EventType.loadComplete, |
| 103 this.onLoadComplete, | 99 this.onLoadComplete, |
| 104 true); | 100 true); |
| 105 | 101 |
| 106 if (root.attributes.docLoaded) | 102 if (root.attributes.docLoaded) |
| 107 this.onLoadComplete({target: root}); | 103 this.onLoadComplete({target: root}); |
| 108 }, | 104 }, |
| 109 | 105 |
| 110 /** | 106 /** |
| 111 * Handles chrome.commands.onCommand. | 107 * Handles chrome.commands.onCommand. |
| 112 * @param {string} command | 108 * @param {string} command |
| (...skipping 26 matching lines...) Expand all Loading... |
| 139 break; | 135 break; |
| 140 case 'nextLink': | 136 case 'nextLink': |
| 141 dir = cvox2.Dir.FORWARD; | 137 dir = cvox2.Dir.FORWARD; |
| 142 pred = cvox2.AutomationPredicates.link; | 138 pred = cvox2.AutomationPredicates.link; |
| 143 break; | 139 break; |
| 144 case 'previousLink': | 140 case 'previousLink': |
| 145 dir = cvox2.Dir.BACKWARD; | 141 dir = cvox2.Dir.BACKWARD; |
| 146 pred = cvox2.AutomationPredicates.link; | 142 pred = cvox2.AutomationPredicates.link; |
| 147 break; | 143 break; |
| 148 case 'nextElement': | 144 case 'nextElement': |
| 149 current = current.role == 'inlineTextBox' ? | 145 current = current.role == chrome.automation.RoleType.inlineTextBox ? |
| 150 current.parent() : current; | 146 current.parent() : current; |
| 151 current = cvox2.AutomationUtil.findNextNode(current, | 147 current = cvox2.AutomationUtil.findNextNode(current, |
| 152 cvox2.Dir.FORWARD, | 148 cvox2.Dir.FORWARD, |
| 153 cvox2.AutomationPredicates.inlineTextBox); | 149 cvox2.AutomationPredicates.inlineTextBox); |
| 154 current = current ? current.parent() : current; | 150 current = current ? current.parent() : current; |
| 155 break; | 151 break; |
| 156 case 'previousElement': | 152 case 'previousElement': |
| 157 current = current.role == 'inlineTextBox' ? | 153 current = current.role == chrome.automation.RoleType.inlineTextBox ? |
| 158 current.parent() : current; | 154 current.parent() : current; |
| 159 current = cvox2.AutomationUtil.findNextNode(current, | 155 current = cvox2.AutomationUtil.findNextNode(current, |
| 160 cvox2.Dir.BACKWARD, | 156 cvox2.Dir.BACKWARD, |
| 161 cvox2.AutomationPredicates.inlineTextBox); | 157 cvox2.AutomationPredicates.inlineTextBox); |
| 162 current = current ? current.parent() : current; | 158 current = current ? current.parent() : current; |
| 163 break; | 159 break; |
| 164 } | 160 } |
| 165 | 161 |
| 166 if (pred) | 162 if (pred) |
| 167 current = cvox2.AutomationUtil.findNextNode(current, dir, pred); | 163 current = cvox2.AutomationUtil.findNextNode(current, dir, pred); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 disableClassicChromeVox_: function(tabId) { | 221 disableClassicChromeVox_: function(tabId) { |
| 226 chrome.tabs.executeScript( | 222 chrome.tabs.executeScript( |
| 227 tabId, | 223 tabId, |
| 228 {'code': 'try { window.disableChromeVox(); } catch(e) { }\n', | 224 {'code': 'try { window.disableChromeVox(); } catch(e) { }\n', |
| 229 'allFrames': true}); | 225 'allFrames': true}); |
| 230 } | 226 } |
| 231 }; | 227 }; |
| 232 | 228 |
| 233 /** @type {cvox2.Background} */ | 229 /** @type {cvox2.Background} */ |
| 234 cvox2.global.backgroundObj = new cvox2.Background(); | 230 cvox2.global.backgroundObj = new cvox2.Background(); |
| OLD | NEW |