| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 chrome.tabs.query({active: true}, function(tabs) { | 162 chrome.tabs.query({active: true}, function(tabs) { |
| 163 if (mode === ChromeVoxMode.CLASSIC) { | 163 if (mode === ChromeVoxMode.CLASSIC) { |
| 164 // Generally, we don't want to inject classic content scripts as it is | 164 // Generally, we don't want to inject classic content scripts as it is |
| 165 // done by the extension system at document load. The exception is when | 165 // done by the extension system at document load. The exception is when |
| 166 // we toggle classic on manually as part of a user command. | 166 // we toggle classic on manually as part of a user command. |
| 167 if (opt_injectClassic) | 167 if (opt_injectClassic) |
| 168 cvox.ChromeVox.injectChromeVoxIntoTabs(tabs); | 168 cvox.ChromeVox.injectChromeVoxIntoTabs(tabs); |
| 169 } else { | 169 } else { |
| 170 // When in compat mode, if the focus is within the desktop tree proper, | 170 // When in compat mode, if the focus is within the desktop tree proper, |
| 171 // then do not disable content scripts. | 171 // then do not disable content scripts. |
| 172 if (this.currentRange_ && | 172 if (this.currentRange_ && !this.currentRange_.isWebRange()) |
| 173 this.currentRange_.start.node.root.role == RoleType.desktop) | |
| 174 return; | 173 return; |
| 175 | 174 |
| 176 this.disableClassicChromeVox_(); | 175 this.disableClassicChromeVox_(); |
| 177 } | 176 } |
| 178 }.bind(this)); | 177 }.bind(this)); |
| 179 | 178 |
| 180 // If switching out of a ChromeVox Next mode, make sure we cancel | 179 // If switching out of a ChromeVox Next mode, make sure we cancel |
| 181 // the progress loading sound just in case. | 180 // the progress loading sound just in case. |
| 182 if ((this.mode_ === ChromeVoxMode.NEXT || | 181 if ((this.mode_ === ChromeVoxMode.NEXT || |
| 183 this.mode_ === ChromeVoxMode.FORCE_NEXT) && | 182 this.mode_ === ChromeVoxMode.FORCE_NEXT) && |
| 184 this.mode_ != mode) { | 183 this.mode_ != mode) { |
| 185 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); | 184 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); |
| 186 } | 185 } |
| 187 | 186 |
| 188 this.mode_ = mode; | 187 this.mode_ = mode; |
| 189 }, | 188 }, |
| 190 | 189 |
| 191 /** | 190 /** |
| 191 * Mode refreshes takes into account both |url| and the current ChromeVox |
| 192 * range. The latter gets used to decide if the user is or isn't in web |
| 193 * content. The focused state also needs to be set for this info to be |
| 194 * reliable. |
| 192 * @override | 195 * @override |
| 193 */ | 196 */ |
| 194 refreshMode: function(url) { | 197 refreshMode: function(url) { |
| 195 var mode = this.mode_; | 198 var mode = this.mode_; |
| 196 if (mode != ChromeVoxMode.FORCE_NEXT) { | 199 if (mode != ChromeVoxMode.FORCE_NEXT) { |
| 197 if (this.isWhitelistedForNext_(url)) | 200 if (this.isWhitelistedForNext_(url)) { |
| 198 mode = ChromeVoxMode.NEXT; | 201 mode = ChromeVoxMode.NEXT; |
| 199 else if (this.isBlacklistedForClassic_(url)) | 202 } else if (this.isBlacklistedForClassic_(url) || (this.currentRange_ && |
| 203 !this.currentRange_.isWebRange() && |
| 204 this.currentRange_.start.node.state.focused)) { |
| 200 mode = ChromeVoxMode.COMPAT; | 205 mode = ChromeVoxMode.COMPAT; |
| 201 else | 206 } else { |
| 202 mode = ChromeVoxMode.CLASSIC; | 207 mode = ChromeVoxMode.CLASSIC; |
| 208 } |
| 203 } | 209 } |
| 204 | 210 |
| 205 this.setMode(mode); | 211 this.setMode(mode); |
| 206 }, | 212 }, |
| 207 | 213 |
| 208 /** | 214 /** |
| 209 * @override | 215 * @override |
| 210 */ | 216 */ |
| 211 getCurrentRange: function() { | 217 getCurrentRange: function() { |
| 212 return this.currentRange_; | 218 return this.currentRange_; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 cvox.ChromeVox.isActive = !cvox.ChromeVox.isActive; | 439 cvox.ChromeVox.isActive = !cvox.ChromeVox.isActive; |
| 434 if (!cvox.ChromeVox.isActive) { | 440 if (!cvox.ChromeVox.isActive) { |
| 435 var msg = Msgs.getMsg('chromevox_inactive'); | 441 var msg = Msgs.getMsg('chromevox_inactive'); |
| 436 cvox.ChromeVox.tts.speak(msg, cvox.QueueMode.FLUSH); | 442 cvox.ChromeVox.tts.speak(msg, cvox.QueueMode.FLUSH); |
| 437 return false; | 443 return false; |
| 438 } | 444 } |
| 439 break; | 445 break; |
| 440 case 'toggleChromeVoxVersion': | 446 case 'toggleChromeVoxVersion': |
| 441 var newMode; | 447 var newMode; |
| 442 if (this.mode_ == ChromeVoxMode.FORCE_NEXT) { | 448 if (this.mode_ == ChromeVoxMode.FORCE_NEXT) { |
| 443 var inViews = | 449 var inWeb = current.isWebRange(); |
| 444 this.currentRange_.start.node.root.role == RoleType.desktop; | 450 newMode = inWeb ? ChromeVoxMode.CLASSIC : ChromeVoxMode.COMPAT; |
| 445 newMode = inViews ? ChromeVoxMode.COMPAT : ChromeVoxMode.CLASSIC; | |
| 446 } else { | 451 } else { |
| 447 newMode = ChromeVoxMode.FORCE_NEXT; | 452 newMode = ChromeVoxMode.FORCE_NEXT; |
| 448 } | 453 } |
| 449 this.setMode(newMode, true); | 454 this.setMode(newMode, true); |
| 450 | 455 |
| 451 var isClassic = | 456 var isClassic = |
| 452 newMode == ChromeVoxMode.CLASSIC || newMode == ChromeVoxMode.COMPAT; | 457 newMode == ChromeVoxMode.CLASSIC || newMode == ChromeVoxMode.COMPAT; |
| 453 | 458 |
| 454 // Leaving unlocalized as 'next' isn't an official name. | 459 // Leaving unlocalized as 'next' isn't an official name. |
| 455 cvox.ChromeVox.tts.speak(isClassic ? | 460 cvox.ChromeVox.tts.speak(isClassic ? |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 !this.isBlacklistedForClassic_(url) && | 571 !this.isBlacklistedForClassic_(url) && |
| 567 !this.isWhitelistedForNext_(url); | 572 !this.isWhitelistedForNext_(url); |
| 568 }, | 573 }, |
| 569 | 574 |
| 570 /** | 575 /** |
| 571 * @param {string} url | 576 * @param {string} url |
| 572 * @return {boolean} | 577 * @return {boolean} |
| 573 * @private | 578 * @private |
| 574 */ | 579 */ |
| 575 isBlacklistedForClassic_: function(url) { | 580 isBlacklistedForClassic_: function(url) { |
| 576 return url === '' || this.classicBlacklistRegExp_.test(url); | 581 return this.classicBlacklistRegExp_.test(url); |
| 577 }, | 582 }, |
| 578 | 583 |
| 579 /** | 584 /** |
| 580 * @param {string} url | 585 * @param {string} url |
| 581 * @return {boolean} Whether the given |url| is whitelisted. | 586 * @return {boolean} Whether the given |url| is whitelisted. |
| 582 * @private | 587 * @private |
| 583 */ | 588 */ |
| 584 isWhitelistedForNext_: function(url) { | 589 isWhitelistedForNext_: function(url) { |
| 585 return this.whitelist_.some(function(item) { | 590 return this.whitelist_.some(function(item) { |
| 586 return url.indexOf(item) != -1; | 591 return url.indexOf(item) != -1; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 668 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 664 .replace(/\*/g, '.*') | 669 .replace(/\*/g, '.*') |
| 665 .replace(/\?/g, '.'); | 670 .replace(/\?/g, '.'); |
| 666 }).join('|') + ')$'); | 671 }).join('|') + ')$'); |
| 667 }; | 672 }; |
| 668 | 673 |
| 669 /** @type {Background} */ | 674 /** @type {Background} */ |
| 670 global.backgroundObj = new Background(); | 675 global.backgroundObj = new Background(); |
| 671 | 676 |
| 672 }); // goog.scope | 677 }); // goog.scope |
| OLD | NEW |