Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js |
| diff --git a/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js b/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js |
| index 26d6f7040105a0af528e31ca7f60e349aa0b8552..e8fca61df502d654eeb24ca7146a2ea9c7da91bc 100644 |
| --- a/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js |
| +++ b/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js |
| @@ -18,7 +18,15 @@ cvox2.global.accessibility = |
| * ChromeVox2 background page. |
| */ |
| cvox2.Background = function() { |
| + /** |
| + * A list of sites to use with ChromeVox next. |
| + * @type {!Array.<string>} |
| + */ |
| + this.whitelist_ = ['http://www.chromevox.com/']; |
| + |
| // Only needed with unmerged ChromeVox classic loaded before. |
| + // TODO(dtseng): Refactor all tabs handlers out of |
| + //accessibility_api_handler.js. |
| cvox2.global.accessibility.setAccessibilityEnabled(false); |
| // Register listeners for ... |
| @@ -27,54 +35,36 @@ cvox2.Background = function() { |
| // Tabs. |
| chrome.tabs.onUpdated.addListener(this.onTabUpdated.bind(this)); |
| - |
| - // Keyboard events (currently Messages from content script). |
| - chrome.extension.onConnect.addListener(this.onConnect.bind(this)); |
| }; |
| cvox2.Background.prototype = { |
| /** |
| - * ID of the port used to communicate between content script and background |
| - * page. |
| - * @const {string} |
| - */ |
| - PORT_ID: 'chromevox2', |
| - |
| - /** |
| - * Handles chrome.extension.onConnect. |
| - * @param {Object} port The port. |
| - */ |
| - onConnect: function(port) { |
| - if (port.name != this.PORT_ID) |
| - return; |
| - port.onMessage.addListener(this.onMessage.bind(this)); |
| - }, |
| - |
| - /** |
| - * Dispatches messages to specific handlers. |
| - * @param {Object} message The message. |
| - */ |
| - onMessage: function(message) { |
| - if (message.keyDown) |
| - this.onKeyDown(message); |
| - }, |
| - |
| - /** |
| - * Handles key down messages from the content script. |
| - * @param {Object} message The key down message. |
| - */ |
| - onKeyDown: function(message) { |
| - // TODO(dtseng): Implement. |
| - }, |
| - |
| - /** |
| * Handles chrome.tabs.onUpdate. |
| * @param {number} tabId The tab id. |
| * @param {Object.<string, (string|boolean)>} changeInfo Information about |
| * the updated tab. |
| */ |
| onTabUpdated: function(tabId, changeInfo) { |
| - chrome.automation.getTree(this.onGotTree.bind(this)); |
| + chrome.tabs.get(tabId, function(tab) { |
| + var isWhitelisted = this.whitelist_.some(function(item) { |
| + return tab.url.indexOf(item) == 0; |
| + }); |
| + |
| + if (!tab.active || !isWhitelisted) { |
| + 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
|
| + return; |
| + } |
| + |
| + if (!chrome.commands.onCommand.hasListener(this.onGotCommand)) |
| + chrome.commands.onCommand.addListener(this.onGotCommand.bind(this)); |
| + |
| + chrome.tabs.executeScript( |
| + tab.id, |
| + {'code': 'try { window.disableChromeVox(); } catch(e) { }\n', |
| + 'allFrames': true}); |
| + |
| + chrome.automation.getTree(this.onGotTree.bind(this)); |
| + }.bind(this)); |
| }, |
| /** |
| @@ -94,8 +84,11 @@ cvox2.Background.prototype = { |
| */ |
| onAutomationEvent: function(evt) { |
| var output = evt.target.attributes.name + ' ' + evt.target.role; |
| - cvox.ChromeVox.tts.speak(output); |
| + 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.
|
| cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); |
| + }, |
| + |
| + onGotCommand: function(command) { |
| } |
| }; |