| 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 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('Background'); | 10 goog.provide('Background'); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 * @override | 146 * @override |
| 147 */ | 147 */ |
| 148 getMode: function() { | 148 getMode: function() { |
| 149 return this.mode_; | 149 return this.mode_; |
| 150 }, | 150 }, |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * @override | 153 * @override |
| 154 */ | 154 */ |
| 155 setMode: function(mode, opt_injectClassic) { | 155 setMode: function(mode, opt_injectClassic) { |
| 156 console.log('setMode ' + mode + ', inject=' + opt_injectClassic); |
| 157 |
| 156 // Switching key maps potentially affects the key codes that involve | 158 // Switching key maps potentially affects the key codes that involve |
| 157 // sequencing. Without resetting this list, potentially stale key codes | 159 // sequencing. Without resetting this list, potentially stale key codes |
| 158 // remain. The key codes themselves get pushed in | 160 // remain. The key codes themselves get pushed in |
| 159 // cvox.KeySequence.deserialize which gets called by cvox.KeyMap. | 161 // cvox.KeySequence.deserialize which gets called by cvox.KeyMap. |
| 160 cvox.ChromeVox.sequenceSwitchKeyCodes = []; | 162 cvox.ChromeVox.sequenceSwitchKeyCodes = []; |
| 161 if (mode === ChromeVoxMode.CLASSIC || mode === ChromeVoxMode.COMPAT) | 163 if (mode === ChromeVoxMode.CLASSIC || mode === ChromeVoxMode.COMPAT) |
| 162 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromDefaults(); | 164 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromDefaults(); |
| 163 else | 165 else |
| 164 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromNext(); | 166 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromNext(); |
| 165 | 167 |
| 168 console.log('setMode b'); |
| 169 |
| 166 if (mode == ChromeVoxMode.CLASSIC) { | 170 if (mode == ChromeVoxMode.CLASSIC) { |
| 167 if (chrome.commands && | 171 if (chrome.commands && |
| 168 chrome.commands.onCommand.hasListener(this.onGotCommand)) | 172 chrome.commands.onCommand.hasListener(this.onGotCommand)) |
| 169 chrome.commands.onCommand.removeListener(this.onGotCommand); | 173 chrome.commands.onCommand.removeListener(this.onGotCommand); |
| 170 chrome.accessibilityPrivate.setKeyboardListener(false, false); | 174 chrome.accessibilityPrivate.setKeyboardListener(false, false); |
| 171 } else { | 175 } else { |
| 172 if (chrome.commands && | 176 if (chrome.commands && |
| 173 !chrome.commands.onCommand.hasListener(this.onGotCommand)) | 177 !chrome.commands.onCommand.hasListener(this.onGotCommand)) |
| 174 chrome.commands.onCommand.addListener(this.onGotCommand); | 178 chrome.commands.onCommand.addListener(this.onGotCommand); |
| 175 chrome.accessibilityPrivate.setKeyboardListener( | 179 chrome.accessibilityPrivate.setKeyboardListener( |
| 176 true, cvox.ChromeVox.isStickyPrefOn); | 180 true, cvox.ChromeVox.isStickyPrefOn); |
| 177 } | 181 } |
| 178 | 182 |
| 183 console.log('setMode c'); |
| 184 |
| 179 chrome.tabs.query({active: true}, function(tabs) { | 185 chrome.tabs.query({active: true}, function(tabs) { |
| 180 if (mode === ChromeVoxMode.CLASSIC) { | 186 if (mode === ChromeVoxMode.CLASSIC) { |
| 181 // Generally, we don't want to inject classic content scripts as it is | 187 // Generally, we don't want to inject classic content scripts as it is |
| 182 // done by the extension system at document load. The exception is when | 188 // done by the extension system at document load. The exception is when |
| 183 // we toggle classic on manually as part of a user command. | 189 // we toggle classic on manually as part of a user command. |
| 184 if (opt_injectClassic) | 190 if (opt_injectClassic) |
| 185 cvox.ChromeVox.injectChromeVoxIntoTabs(tabs); | 191 cvox.ChromeVox.injectChromeVoxIntoTabs(tabs); |
| 186 } else { | 192 } else { |
| 187 // When in compat mode, if the focus is within the desktop tree proper, | 193 // When in compat mode, if the focus is within the desktop tree proper, |
| 188 // then do not disable content scripts. | 194 // then do not disable content scripts. |
| 189 if (this.currentRange_ && !this.currentRange_.isWebRange()) | 195 if (this.currentRange_ && !this.currentRange_.isWebRange()) |
| 190 return; | 196 return; |
| 191 | 197 |
| 192 this.disableClassicChromeVox_(); | 198 this.disableClassicChromeVox_(); |
| 193 } | 199 } |
| 194 }.bind(this)); | 200 }.bind(this)); |
| 195 | 201 |
| 202 console.log('setMode d'); |
| 203 |
| 196 // If switching out of a ChromeVox Next mode, make sure we cancel | 204 // If switching out of a ChromeVox Next mode, make sure we cancel |
| 197 // the progress loading sound just in case. | 205 // the progress loading sound just in case. |
| 198 if ((this.mode_ === ChromeVoxMode.NEXT || | 206 if ((this.mode_ === ChromeVoxMode.NEXT || |
| 199 this.mode_ === ChromeVoxMode.FORCE_NEXT) && | 207 this.mode_ === ChromeVoxMode.FORCE_NEXT) && |
| 200 this.mode_ != mode) { | 208 this.mode_ != mode) { |
| 201 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); | 209 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); |
| 202 } | 210 } |
| 203 | 211 |
| 212 console.log('setMode e'); |
| 213 |
| 204 if (mode === ChromeVoxMode.NEXT || | 214 if (mode === ChromeVoxMode.NEXT || |
| 205 mode === ChromeVoxMode.FORCE_NEXT) { | 215 mode === ChromeVoxMode.FORCE_NEXT) { |
| 206 (new PanelCommand(PanelCommandType.ENABLE_MENUS)).send(); | 216 (new PanelCommand(PanelCommandType.ENABLE_MENUS)).send(); |
| 207 } else { | 217 } else { |
| 208 (new PanelCommand(PanelCommandType.DISABLE_MENUS)).send(); | 218 (new PanelCommand(PanelCommandType.DISABLE_MENUS)).send(); |
| 209 } | 219 } |
| 210 | 220 |
| 221 console.log('setMode f'); |
| 222 |
| 223 // If switching to Classic from any automation-API-based mode, |
| 224 // clear the focus ring. |
| 225 if (mode === ChromeVoxMode.CLASSIC && mode != this.mode_) { |
| 226 if (cvox.ChromeVox.isChromeOS) |
| 227 chrome.accessibilityPrivate.setFocusRing([]); |
| 228 } |
| 229 |
| 230 console.log('setMode g'); |
| 231 |
| 232 // If switching away from Classic to any automation-API-based mode, |
| 233 // update the range based on what's focused. |
| 234 if (this.mode_ === ChromeVoxMode.CLASSIC && mode != this.mode_) { |
| 235 var focus = chrome.automation.getFocus(); |
| 236 if (focus) { |
| 237 console.log('setMode h calling setCurrentRange'); |
| 238 this.setCurrentRange(cursors.Range.fromNode(focus)); |
| 239 } |
| 240 } |
| 241 |
| 242 console.log('setMode h'); |
| 243 |
| 211 this.mode_ = mode; | 244 this.mode_ = mode; |
| 212 }, | 245 }, |
| 213 | 246 |
| 214 /** | 247 /** |
| 215 * Mode refreshes takes into account both |url| and the current ChromeVox | 248 * Mode refreshes takes into account both |url| and the current ChromeVox |
| 216 * range. The latter gets used to decide if the user is or isn't in web | 249 * range. The latter gets used to decide if the user is or isn't in web |
| 217 * content. The focused state also needs to be set for this info to be | 250 * content. The focused state also needs to be set for this info to be |
| 218 * reliable. | 251 * reliable. |
| 219 * @override | 252 * @override |
| 220 */ | 253 */ |
| 221 refreshMode: function(url) { | 254 refreshMode: function(url) { |
| 255 console.log('refreshMode ' + url); |
| 256 |
| 222 var mode = this.mode_; | 257 var mode = this.mode_; |
| 223 if (mode != ChromeVoxMode.FORCE_NEXT) { | 258 if (mode != ChromeVoxMode.FORCE_NEXT) { |
| 224 if (this.isWhitelistedForNext_(url)) { | 259 if (this.isWhitelistedForNext_(url)) { |
| 225 mode = ChromeVoxMode.NEXT; | 260 mode = ChromeVoxMode.NEXT; |
| 226 } else if (this.isBlacklistedForClassic_(url) || (this.currentRange_ && | 261 } else if (this.isBlacklistedForClassic_(url) || (this.currentRange_ && |
| 227 !this.currentRange_.isWebRange() && | 262 !this.currentRange_.isWebRange() && |
| 228 this.currentRange_.start.node.state.focused)) { | 263 this.currentRange_.start.node.state.focused)) { |
| 229 mode = ChromeVoxMode.COMPAT; | 264 mode = ChromeVoxMode.COMPAT; |
| 230 } else { | 265 } else { |
| 231 mode = ChromeVoxMode.CLASSIC; | 266 mode = ChromeVoxMode.CLASSIC; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 newMode = ChromeVoxMode.FORCE_NEXT; | 527 newMode = ChromeVoxMode.FORCE_NEXT; |
| 493 } | 528 } |
| 494 this.setMode(newMode, true); | 529 this.setMode(newMode, true); |
| 495 | 530 |
| 496 var isClassic = | 531 var isClassic = |
| 497 newMode == ChromeVoxMode.CLASSIC || newMode == ChromeVoxMode.COMPAT; | 532 newMode == ChromeVoxMode.CLASSIC || newMode == ChromeVoxMode.COMPAT; |
| 498 | 533 |
| 499 // Leaving unlocalized as 'next' isn't an official name. | 534 // Leaving unlocalized as 'next' isn't an official name. |
| 500 cvox.ChromeVox.tts.speak(isClassic ? | 535 cvox.ChromeVox.tts.speak(isClassic ? |
| 501 'classic' : 'next', cvox.QueueMode.FLUSH, {doNotInterrupt: true}); | 536 'classic' : 'next', cvox.QueueMode.FLUSH, {doNotInterrupt: true}); |
| 537 |
| 538 // If the new mode is Classic, return now so we don't announce |
| 539 // anything more. |
| 540 if (newMode == ChromeVoxMode.CLASSIC) |
| 541 return false; |
| 502 break; | 542 break; |
| 503 case 'toggleStickyMode': | 543 case 'toggleStickyMode': |
| 504 cvox.ChromeVoxBackground.setPref('sticky', | 544 cvox.ChromeVoxBackground.setPref('sticky', |
| 505 !cvox.ChromeVox.isStickyPrefOn, | 545 !cvox.ChromeVox.isStickyPrefOn, |
| 506 true); | 546 true); |
| 507 | 547 |
| 508 if (cvox.ChromeVox.isStickyPrefOn) | 548 if (cvox.ChromeVox.isStickyPrefOn) |
| 509 chrome.accessibilityPrivate.setKeyboardListener(true, true); | 549 chrome.accessibilityPrivate.setKeyboardListener(true, true); |
| 510 else | 550 else |
| 511 chrome.accessibilityPrivate.setKeyboardListener(true, false); | 551 chrome.accessibilityPrivate.setKeyboardListener(true, false); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 880 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 841 .replace(/\*/g, '.*') | 881 .replace(/\*/g, '.*') |
| 842 .replace(/\?/g, '.'); | 882 .replace(/\?/g, '.'); |
| 843 }).join('|') + ')$'); | 883 }).join('|') + ')$'); |
| 844 }; | 884 }; |
| 845 | 885 |
| 846 /** @type {Background} */ | 886 /** @type {Background} */ |
| 847 global.backgroundObj = new Background(); | 887 global.backgroundObj = new Background(); |
| 848 | 888 |
| 849 }); // goog.scope | 889 }); // goog.scope |
| OLD | NEW |