Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js

Issue 608853006: Reland fix ChromeVox Next compile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Address nits. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 173
171 /** 174 /**
172 * Provides all feedback once ChromeVox's focus changes. 175 * Provides all feedback once ChromeVox's focus changes.
173 * @param {Object} evt 176 * @param {Object} evt
174 */ 177 */
175 onFocus: function(evt) { 178 onFocus: function(evt) {
176 var node = evt.target; 179 var node = evt.target;
177 if (!node) 180 if (!node)
178 return; 181 return;
179 var container = node; 182 var container = node;
180 while (container && (container.role == 'inlineTextBox' || 183 while (container &&
181 container.role == 'staticText')) 184 (container.role == chrome.automation.RoleType.inlineTextBox ||
185 container.role == chrome.automation.RoleType.staticText))
182 container = container.parent(); 186 container = container.parent();
183 187
184 var role = container ? container.role : node.role; 188 var role = container ? container.role : node.role;
185 189
186 var output = 190 var output =
187 [node.attributes.name, node.attributes.value, role].join(', '); 191 [node.attributes.name, node.attributes.value, role].join(', ');
188 cvox.ChromeVox.tts.speak(output, cvox.AbstractTts.QUEUE_MODE_FLUSH); 192 cvox.ChromeVox.tts.speak(output, cvox.AbstractTts.QUEUE_MODE_FLUSH);
189 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); 193 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output));
190 chrome.accessibilityPrivate.setFocusRing([evt.target.location]); 194 chrome.accessibilityPrivate.setFocusRing([evt.target.location]);
191 195
(...skipping 29 matching lines...) Expand all
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();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698