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