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..167a65314e685180b7a4c2dc8cef95bf4d0f560b 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. |
Peter Lundblad
2014/09/05 07:21:54
Define more precisely what the string should be.
David Tseng
2014/09/08 19:24:34
Done.
|
+ * @type {!Array.<string>} |
+ */ |
+ this.whitelist_ = ['http://www.chromevox.com/', 'chromevox_next']; |
Peter Lundblad
2014/09/05 07:21:54
What site is 'chromevox_next'?
David Tseng
2014/09/08 19:24:34
See new comments. Matches substrings now, so chrom
|
+ |
// Only needed with unmerged ChromeVox classic loaded before. |
+ // TODO(dtseng): Refactor all tabs handlers out of |
+ //accessibility_api_handler.js. |
Peter Lundblad
2014/09/05 07:21:54
nit: space after //
David Tseng
2014/09/08 19:24:34
Done.
|
cvox2.global.accessibility.setAccessibilityEnabled(false); |
// Register listeners for ... |
@@ -26,55 +34,36 @@ cvox2.Background = function() { |
chrome.automation.getDesktop(this.onGotTree.bind(this)); |
// Tabs. |
- chrome.tabs.onUpdated.addListener(this.onTabUpdated.bind(this)); |
- |
- // Keyboard events (currently Messages from content script). |
- chrome.extension.onConnect.addListener(this.onConnect.bind(this)); |
+ chrome.tabs.onActivated.addListener(this.onTabActivated.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)); |
- }, |
+/** |
Peter Lundblad
2014/09/05 07:21:54
nit: indent
David Tseng
2014/09/08 19:24:34
Done.
|
+ * Handles chrome.tabs.onActivated. |
+ * @param {number} tabId |
+ * @param {Object} activatedInfo |
+ */ |
+ onTabActivated: function(activatedInfo) { |
Peter Lundblad
2014/09/05 07:21:54
Does this logic work in web content that are not t
David Tseng
2014/09/08 19:24:34
Nope; but it should still fall back to classic Chr
|
+ chrome.tabs.get(activatedInfo.tabId, function(tab) { |
+ if (!tab.url) |
+ return; |
- /** |
- * Dispatches messages to specific handlers. |
- * @param {Object} message The message. |
- */ |
- onMessage: function(message) { |
- if (message.keyDown) |
- this.onKeyDown(message); |
- }, |
+ if (!tab.active || !this.isWhitelisted_(tab.url)) { |
+ chrome.commands.onCommand.removeListener(this.onGotCommand); |
+ return; |
+ } |
- /** |
- * Handles key down messages from the content script. |
- * @param {Object} message The key down message. |
- */ |
- onKeyDown: function(message) { |
- // TODO(dtseng): Implement. |
- }, |
+ if (!chrome.commands.onCommand.hasListener(this.onGotCommand)) |
+ chrome.commands.onCommand.addListener(this.onGotCommand.bind(this)); |
Peter Lundblad
2014/09/05 07:21:54
nit: indent
David Tseng
2014/09/08 19:24:34
Done.
|
- /** |
- * 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.executeScript( |
+ tab.id, |
+ {'code': 'try { window.disableChromeVox(); } catch(e) { }\n', |
+ 'allFrames': true}); |
+ |
+ chrome.automation.getTree(this.onGotTree.bind(this)); |
+ }.bind(this)); |
}, |
/** |
@@ -94,8 +83,26 @@ 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, cvox.AbstractTts.QUEUE_MODE_FLUSH); |
cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); |
+ }, |
+ |
+ /** |
+ * Handles chrome.commands.onCommand. |
+ * @param {string} command |
+ */ |
+ onGotCommand: function(command) { |
+ }, |
+ |
+ /** |
+ * @private |
+ * @param {string} url |
+ * @return {boolean} Whether the given |url| is whitelisted. |
Peter Lundblad
2014/09/05 07:21:54
nit: indent
David Tseng
2014/09/08 19:24:34
Done.
|
+ */ |
+ isWhitelisted_: function(url) { |
+ return this.whitelist_.some(function(item) { |
+ return url.indexOf(item) != -1; |
+ }); |
} |
}; |