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