| 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 Accesses Chrome's tabs extension API and gives | 6 * @fileoverview Accesses Chrome's tabs extension API and gives |
| 7 * feedback for events that happen in the "Chrome of Chrome". | 7 * feedback for events that happen in the "Chrome of Chrome". |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 goog.provide('cvox.TabsApiHandler'); | 10 goog.provide('cvox.TabsApiHandler'); |
| 11 | 11 |
| 12 goog.require('cvox.AbstractEarcons'); | 12 goog.require('cvox.AbstractEarcons'); |
| 13 goog.require('cvox.AbstractTts'); | 13 goog.require('cvox.AbstractTts'); |
| 14 goog.require('cvox.BrailleInterface'); | 14 goog.require('cvox.BrailleInterface'); |
| 15 goog.require('cvox.ChromeVox'); | 15 goog.require('cvox.ChromeVox'); |
| 16 goog.require('cvox.NavBraille'); | 16 goog.require('cvox.NavBraille'); |
| 17 | 17 |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Class that adds listeners and handles events from the tabs API. | 20 * Class that adds listeners and handles events from the tabs API. |
| 21 * @constructor | 21 * @constructor |
| 22 * @param {cvox.TtsInterface} tts The TTS to use for speaking. | |
| 23 * @param {cvox.BrailleInterface} braille The braille interface to use for | |
| 24 * brailling. | |
| 25 * @param {cvox.AbstractEarcons} earcons The earcons object to use for playing | |
| 26 * earcons. | |
| 27 */ | 22 */ |
| 28 cvox.TabsApiHandler = function(tts, braille, earcons) { | 23 cvox.TabsApiHandler = function() { |
| 29 /** @type {cvox.TtsInterface} @private */ | |
| 30 this.tts_ = tts; | |
| 31 /** @type {cvox.BrailleInterface} @private */ | |
| 32 this.braille_ = braille; | |
| 33 /** @type {cvox.AbstractEarcons} @private */ | |
| 34 this.earcons_ = earcons; | |
| 35 /** @type {function(string, Array<string>=)} @private */ | 24 /** @type {function(string, Array<string>=)} @private */ |
| 36 this.msg_ = Msgs.getMsg.bind(Msgs); | 25 this.msg_ = Msgs.getMsg.bind(Msgs); |
| 37 /** | 26 /** |
| 38 * Tracks whether the active tab has finished loading. | 27 * Tracks whether the active tab has finished loading. |
| 39 * @type {boolean} | 28 * @type {boolean} |
| 40 * @private | 29 * @private |
| 41 */ | 30 */ |
| 42 this.lastActiveTabLoaded_ = false; | 31 this.lastActiveTabLoaded_ = false; |
| 43 | 32 |
| 44 chrome.tabs.onCreated.addListener(this.onCreated.bind(this)); | 33 chrome.tabs.onCreated.addListener(this.onCreated.bind(this)); |
| 45 chrome.tabs.onRemoved.addListener(this.onRemoved.bind(this)); | 34 chrome.tabs.onRemoved.addListener(this.onRemoved.bind(this)); |
| 46 chrome.tabs.onActivated.addListener(this.onActivated.bind(this)); | 35 chrome.tabs.onActivated.addListener(this.onActivated.bind(this)); |
| 47 chrome.tabs.onUpdated.addListener(this.onUpdated.bind(this)); | 36 chrome.tabs.onUpdated.addListener(this.onUpdated.bind(this)); |
| 48 chrome.windows.onFocusChanged.addListener(this.onFocusChanged.bind(this)); | 37 chrome.windows.onFocusChanged.addListener(this.onFocusChanged.bind(this)); |
| 49 }; | 38 }; |
| 50 | 39 |
| 51 cvox.TabsApiHandler.prototype = { | 40 cvox.TabsApiHandler.prototype = { |
| 52 /** | 41 /** |
| 53 * Handles chrome.tabs.onCreated. | 42 * Handles chrome.tabs.onCreated. |
| 54 * @param {Object} tab | 43 * @param {Object} tab |
| 55 */ | 44 */ |
| 56 onCreated: function(tab) { | 45 onCreated: function(tab) { |
| 57 if (!cvox.ChromeVox.isActive) { | 46 if (!cvox.ChromeVox.isActive) { |
| 58 return; | 47 return; |
| 59 } | 48 } |
| 60 this.tts_.speak(this.msg_('chrome_tab_created'), | 49 cvox.ChromeVox.tts.speak(this.msg_('chrome_tab_created'), |
| 61 cvox.QueueMode.FLUSH, | 50 cvox.QueueMode.FLUSH, |
| 62 cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); | 51 cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); |
| 63 this.braille_.write( | 52 cvox.ChromeVox.braille.write( |
| 64 cvox.NavBraille.fromText(this.msg_('chrome_tab_created'))); | 53 cvox.NavBraille.fromText(this.msg_('chrome_tab_created'))); |
| 65 this.earcons_.playEarcon(cvox.Earcon.OBJECT_OPEN); | 54 cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.OBJECT_OPEN); |
| 66 }, | 55 }, |
| 67 | 56 |
| 68 /** | 57 /** |
| 69 * Handles chrome.tabs.onRemoved. | 58 * Handles chrome.tabs.onRemoved. |
| 70 * @param {Object} tab | 59 * @param {Object} tab |
| 71 */ | 60 */ |
| 72 onRemoved: function(tab) { | 61 onRemoved: function(tab) { |
| 73 if (!cvox.ChromeVox.isActive) { | 62 if (!cvox.ChromeVox.isActive) { |
| 74 return; | 63 return; |
| 75 } | 64 } |
| 76 this.earcons_.playEarcon(cvox.Earcon.OBJECT_CLOSE); | 65 cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.OBJECT_CLOSE); |
| 77 }, | 66 }, |
| 78 | 67 |
| 79 /** | 68 /** |
| 80 * Handles chrome.tabs.onActivated. | 69 * Handles chrome.tabs.onActivated. |
| 81 * @param {Object} activeInfo | 70 * @param {Object} activeInfo |
| 82 */ | 71 */ |
| 83 onActivated: function(activeInfo) { | 72 onActivated: function(activeInfo) { |
| 84 if (!cvox.ChromeVox.isActive) { | 73 if (!cvox.ChromeVox.isActive) { |
| 85 return; | 74 return; |
| 86 } | 75 } |
| 87 chrome.tabs.get(activeInfo.tabId, function(tab) { | 76 chrome.tabs.get(activeInfo.tabId, function(tab) { |
| 88 this.lastActiveTabLoaded_ = tab.status == 'complete'; | 77 this.lastActiveTabLoaded_ = tab.status == 'complete'; |
| 89 if (tab.status == 'loading') { | 78 if (tab.status == 'loading') { |
| 90 return; | 79 return; |
| 91 } | 80 } |
| 92 var title = tab.title ? tab.title : tab.url; | 81 var title = tab.title ? tab.title : tab.url; |
| 93 this.tts_.speak(this.msg_('chrome_tab_selected', | 82 cvox.ChromeVox.tts.speak(this.msg_('chrome_tab_selected', |
| 94 [title]), | 83 [title]), |
| 95 cvox.QueueMode.FLUSH, | 84 cvox.QueueMode.FLUSH, |
| 96 cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); | 85 cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); |
| 97 this.braille_.write( | 86 cvox.ChromeVox.braille.write( |
| 98 cvox.NavBraille.fromText(this.msg_('chrome_tab_selected', [title]))); | 87 cvox.NavBraille.fromText(this.msg_('chrome_tab_selected', [title]))); |
| 99 this.earcons_.playEarcon(cvox.Earcon.OBJECT_SELECT); | 88 cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.OBJECT_SELECT); |
| 100 }.bind(this)); | 89 }.bind(this)); |
| 101 }, | 90 }, |
| 102 | 91 |
| 103 /** | 92 /** |
| 104 * Handles chrome.tabs.onUpdated. | 93 * Handles chrome.tabs.onUpdated. |
| 105 * @param {number} tabId | 94 * @param {number} tabId |
| 106 * @param {Object} selectInfo | 95 * @param {Object} selectInfo |
| 107 */ | 96 */ |
| 108 onUpdated: function(tabId, selectInfo) { | 97 onUpdated: function(tabId, selectInfo) { |
| 109 if (!cvox.ChromeVox.isActive) { | 98 if (!cvox.ChromeVox.isActive) { |
| 110 return; | 99 return; |
| 111 } | 100 } |
| 112 chrome.tabs.get(tabId, function(tab) { | 101 chrome.tabs.get(tabId, function(tab) { |
| 113 if (!tab.active) { | 102 if (!tab.active) { |
| 114 return; | 103 return; |
| 115 } | 104 } |
| 116 if (tab.status == 'loading') { | 105 if (tab.status == 'loading') { |
| 117 this.lastActiveTabLoaded_ = false; | 106 this.lastActiveTabLoaded_ = false; |
| 118 this.earcons_.playEarcon(cvox.Earcon.PAGE_START_LOADING); | 107 cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.PAGE_START_LOADING); |
| 119 } else if (!this.lastActiveTabLoaded_) { | 108 } else if (!this.lastActiveTabLoaded_) { |
| 120 this.lastActiveTabLoaded_ = true; | 109 this.lastActiveTabLoaded_ = true; |
| 121 this.earcons_.playEarcon(cvox.Earcon.PAGE_FINISH_LOADING); | 110 cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.PAGE_FINISH_LOADING); |
| 122 } | 111 } |
| 123 }.bind(this)); | 112 }.bind(this)); |
| 124 }, | 113 }, |
| 125 | 114 |
| 126 /** | 115 /** |
| 127 * Handles chrome.windows.onFocusChanged. | 116 * Handles chrome.windows.onFocusChanged. |
| 128 * @param {number} windowId | 117 * @param {number} windowId |
| 129 */ | 118 */ |
| 130 onFocusChanged: function(windowId) { | 119 onFocusChanged: function(windowId) { |
| 131 if (!cvox.ChromeVox.isActive) { | 120 if (!cvox.ChromeVox.isActive) { |
| 132 return; | 121 return; |
| 133 } | 122 } |
| 134 if (windowId == chrome.windows.WINDOW_ID_NONE) { | 123 if (windowId == chrome.windows.WINDOW_ID_NONE) { |
| 135 return; | 124 return; |
| 136 } | 125 } |
| 137 chrome.windows.get(windowId, function(window) { | 126 chrome.windows.get(windowId, function(window) { |
| 138 chrome.tabs.query({active: true, windowId: windowId}, function(tabs) { | 127 chrome.tabs.query({active: true, windowId: windowId}, function(tabs) { |
| 139 var msgId = window.incognito ? 'chrome_incognito_window_selected' : | 128 var msgId = window.incognito ? 'chrome_incognito_window_selected' : |
| 140 'chrome_normal_window_selected'; | 129 'chrome_normal_window_selected'; |
| 141 var tab = tabs[0] || {}; | 130 var tab = tabs[0] || {}; |
| 142 var title = tab.title ? tab.title : tab.url; | 131 var title = tab.title ? tab.title : tab.url; |
| 143 this.tts_.speak(this.msg_(msgId, [title]), | 132 cvox.ChromeVox.tts.speak(this.msg_(msgId, [title]), |
| 144 cvox.QueueMode.FLUSH, | 133 cvox.QueueMode.FLUSH, |
| 145 cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); | 134 cvox.AbstractTts.PERSONALITY_ANNOUNCEMENT); |
| 146 this.braille_.write( | 135 cvox.ChromeVox.braille.write( |
| 147 cvox.NavBraille.fromText(this.msg_(msgId, [title]))); | 136 cvox.NavBraille.fromText(this.msg_(msgId, [title]))); |
| 148 this.earcons_.playEarcon(cvox.Earcon.OBJECT_SELECT); | 137 cvox.ChromeVox.earcons.playEarcon(cvox.Earcon.OBJECT_SELECT); |
| 149 }.bind(this)); | 138 }.bind(this)); |
| 150 }.bind(this)); | 139 }.bind(this)); |
| 151 } | 140 } |
| 152 }; | 141 }; |
| OLD | NEW |