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

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

Issue 536233002: Begin introducing some of the initial pieces for ChromeVox next commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chromeos_conversions
Patch Set: Created 6 years, 3 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 /** Classic Chrome accessibility API. */ 13 /** Classic Chrome accessibility API. */
14 cvox2.global.accessibility = 14 cvox2.global.accessibility =
15 chrome.accessibilityPrivate || chrome.experimental.accessibility; 15 chrome.accessibilityPrivate || chrome.experimental.accessibility;
16 16
17 /** 17 /**
18 * ChromeVox2 background page. 18 * ChromeVox2 background page.
19 */ 19 */
20 cvox2.Background = function() { 20 cvox2.Background = function() {
21 /**
22 * A list of sites to use with ChromeVox next.
23 * @type {!Array.<string>}
24 */
25 this.whitelist_ = ['http://www.chromevox.com/'];
26
21 // Only needed with unmerged ChromeVox classic loaded before. 27 // Only needed with unmerged ChromeVox classic loaded before.
28 // TODO(dtseng): Refactor all tabs handlers out of
29 //accessibility_api_handler.js.
22 cvox2.global.accessibility.setAccessibilityEnabled(false); 30 cvox2.global.accessibility.setAccessibilityEnabled(false);
23 31
24 // Register listeners for ... 32 // Register listeners for ...
25 // Desktop. 33 // Desktop.
26 chrome.automation.getDesktop(this.onGotTree.bind(this)); 34 chrome.automation.getDesktop(this.onGotTree.bind(this));
27 35
28 // Tabs. 36 // Tabs.
29 chrome.tabs.onUpdated.addListener(this.onTabUpdated.bind(this)); 37 chrome.tabs.onUpdated.addListener(this.onTabUpdated.bind(this));
30
31 // Keyboard events (currently Messages from content script).
32 chrome.extension.onConnect.addListener(this.onConnect.bind(this));
33 }; 38 };
34 39
35 cvox2.Background.prototype = { 40 cvox2.Background.prototype = {
36 /** 41 /**
37 * ID of the port used to communicate between content script and background
38 * page.
39 * @const {string}
40 */
41 PORT_ID: 'chromevox2',
42
43 /**
44 * Handles chrome.extension.onConnect.
45 * @param {Object} port The port.
46 */
47 onConnect: function(port) {
48 if (port.name != this.PORT_ID)
49 return;
50 port.onMessage.addListener(this.onMessage.bind(this));
51 },
52
53 /**
54 * Dispatches messages to specific handlers.
55 * @param {Object} message The message.
56 */
57 onMessage: function(message) {
58 if (message.keyDown)
59 this.onKeyDown(message);
60 },
61
62 /**
63 * Handles key down messages from the content script.
64 * @param {Object} message The key down message.
65 */
66 onKeyDown: function(message) {
67 // TODO(dtseng): Implement.
68 },
69
70 /**
71 * Handles chrome.tabs.onUpdate. 42 * Handles chrome.tabs.onUpdate.
72 * @param {number} tabId The tab id. 43 * @param {number} tabId The tab id.
73 * @param {Object.<string, (string|boolean)>} changeInfo Information about 44 * @param {Object.<string, (string|boolean)>} changeInfo Information about
74 * the updated tab. 45 * the updated tab.
75 */ 46 */
76 onTabUpdated: function(tabId, changeInfo) { 47 onTabUpdated: function(tabId, changeInfo) {
77 chrome.automation.getTree(this.onGotTree.bind(this)); 48 chrome.tabs.get(tabId, function(tab) {
49 var isWhitelisted = this.whitelist_.some(function(item) {
50 return tab.url.indexOf(item) == 0;
51 });
52
53 if (!tab.active || !isWhitelisted) {
54 chrome.commands.onCommand.removeListener(this.onGotCommand);
dmazzoni 2014/09/04 15:55:42 Unless I'm misunderstanding, I don't think you wan
David Tseng 2014/09/04 18:37:43 Done. Disabling only occurs if the tab is whiteli
55 return;
56 }
57
58 if (!chrome.commands.onCommand.hasListener(this.onGotCommand))
59 chrome.commands.onCommand.addListener(this.onGotCommand.bind(this));
60
61 chrome.tabs.executeScript(
62 tab.id,
63 {'code': 'try { window.disableChromeVox(); } catch(e) { }\n',
64 'allFrames': true});
65
66 chrome.automation.getTree(this.onGotTree.bind(this));
67 }.bind(this));
78 }, 68 },
79 69
80 /** 70 /**
81 * Handles all setup once a new automation tree appears. 71 * Handles all setup once a new automation tree appears.
82 * @param {AutomationTree} tree The new automation tree. 72 * @param {AutomationTree} tree The new automation tree.
83 */ 73 */
84 onGotTree: function(root) { 74 onGotTree: function(root) {
85 // Register all automation event listeners. 75 // Register all automation event listeners.
86 root.addEventListener(chrome.automation.EventType.focus, 76 root.addEventListener(chrome.automation.EventType.focus,
87 this.onAutomationEvent.bind(this), 77 this.onAutomationEvent.bind(this),
88 true); 78 true);
89 }, 79 },
90 80
91 /** 81 /**
92 * A generic handler for all desktop automation events. 82 * A generic handler for all desktop automation events.
93 * @param {AutomationEvent} evt The event. 83 * @param {AutomationEvent} evt The event.
94 */ 84 */
95 onAutomationEvent: function(evt) { 85 onAutomationEvent: function(evt) {
96 var output = evt.target.attributes.name + ' ' + evt.target.role; 86 var output = evt.target.attributes.name + ' ' + evt.target.role;
97 cvox.ChromeVox.tts.speak(output); 87 cvox.ChromeVox.tts.speak(output, 0);
dmazzoni 2014/09/04 15:55:42 please use QUEUE_MODE_FLUSH instead of 0
David Tseng 2014/09/04 18:37:43 Done.
98 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); 88 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output));
89 },
90
91 onGotCommand: function(command) {
99 } 92 }
100 }; 93 };
101 94
102 /** @type {cvox2.Background} */ 95 /** @type {cvox2.Background} */
103 cvox2.global.backgroundObj = new cvox2.Background(); 96 cvox2.global.backgroundObj = new cvox2.Background();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698