| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 * @private | 67 * @private |
| 68 */ | 68 */ |
| 69 this.classicBlacklistRegExp_ = Background.globsToRegExp_( | 69 this.classicBlacklistRegExp_ = Background.globsToRegExp_( |
| 70 chrome.runtime.getManifest()['content_scripts'][0]['exclude_globs']); | 70 chrome.runtime.getManifest()['content_scripts'][0]['exclude_globs']); |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Regular expression for whitelisting Next compat. | 73 * Regular expression for whitelisting Next compat. |
| 74 * @type {RegExp} | 74 * @type {RegExp} |
| 75 * @private | 75 * @private |
| 76 */ | 76 */ |
| 77 this.NextCompatRegExp_ = Background.globsToRegExp_([ | 77 this.nextCompatRegExp_ = Background.globsToRegExp_([ |
| 78 '*docs.google.com*' | 78 '*docs.google.com*' |
| 79 ]); | 79 ]); |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * @type {cursors.Range} | 82 * @type {cursors.Range} |
| 83 * @private | 83 * @private |
| 84 */ | 84 */ |
| 85 this.currentRange_ = null; | 85 this.currentRange_ = null; |
| 86 | 86 |
| 87 /** | 87 /** |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return useNext ? ChromeVoxMode.FORCE_NEXT : ChromeVoxMode.CLASSIC; | 243 return useNext ? ChromeVoxMode.FORCE_NEXT : ChromeVoxMode.CLASSIC; |
| 244 | 244 |
| 245 // Closure complains, but clearly, |target| is not null. | 245 // Closure complains, but clearly, |target| is not null. |
| 246 var topLevelRoot = | 246 var topLevelRoot = |
| 247 AutomationUtil.getTopLevelRoot(/** @type {!AutomationNode} */(target)); | 247 AutomationUtil.getTopLevelRoot(/** @type {!AutomationNode} */(target)); |
| 248 if (!topLevelRoot) | 248 if (!topLevelRoot) |
| 249 return useNext ? ChromeVoxMode.FORCE_NEXT : | 249 return useNext ? ChromeVoxMode.FORCE_NEXT : |
| 250 ChromeVoxMode.CLASSIC_COMPAT; | 250 ChromeVoxMode.CLASSIC_COMPAT; |
| 251 | 251 |
| 252 var nextSite = this.isWhitelistedForNext_(topLevelRoot.docUrl); | 252 var nextSite = this.isWhitelistedForNext_(topLevelRoot.docUrl); |
| 253 var nextCompat = this.NextCompatRegExp_.test(topLevelRoot.docUrl); | 253 var nextCompat = this.nextCompatRegExp_.test(topLevelRoot.docUrl); |
| 254 var classicCompat = | 254 var classicCompat = |
| 255 this.isWhitelistedForClassicCompat_(topLevelRoot.docUrl); | 255 this.isWhitelistedForClassicCompat_(topLevelRoot.docUrl); |
| 256 if (nextCompat && useNext) | 256 if (nextCompat && useNext) |
| 257 return ChromeVoxMode.NEXT_COMPAT; | 257 return ChromeVoxMode.NEXT_COMPAT; |
| 258 else if (classicCompat && !useNext) | 258 else if (classicCompat && !useNext) |
| 259 return ChromeVoxMode.CLASSIC_COMPAT; | 259 return ChromeVoxMode.CLASSIC_COMPAT; |
| 260 else if (nextSite) | 260 else if (nextSite) |
| 261 return ChromeVoxMode.NEXT; | 261 return ChromeVoxMode.NEXT; |
| 262 else if (!useNext) | 262 else if (!useNext) |
| 263 return ChromeVoxMode.CLASSIC; | 263 return ChromeVoxMode.CLASSIC; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 553 } |
| 554 return true; | 554 return true; |
| 555 }, | 555 }, |
| 556 | 556 |
| 557 /** | 557 /** |
| 558 * Returns true if the url should have Classic running. | 558 * Returns true if the url should have Classic running. |
| 559 * @return {boolean} | 559 * @return {boolean} |
| 560 * @private | 560 * @private |
| 561 */ | 561 */ |
| 562 shouldEnableClassicForUrl_: function(url) { | 562 shouldEnableClassicForUrl_: function(url) { |
| 563 return this.mode != ChromeVoxMode.FORCE_NEXT && | 563 return this.nextCompatRegExp_.test(url) || |
| 564 !this.isBlacklistedForClassic_(url) && | 564 (this.mode != ChromeVoxMode.FORCE_NEXT && |
| 565 !this.isWhitelistedForNext_(url); | 565 !this.isBlacklistedForClassic_(url) && |
| 566 !this.isWhitelistedForNext_(url)); |
| 566 }, | 567 }, |
| 567 | 568 |
| 568 /** | 569 /** |
| 569 * Compat mode is on if any of the following are true: | 570 * Compat mode is on if any of the following are true: |
| 570 * 1. a url is blacklisted for Classic. | 571 * 1. a url is blacklisted for Classic. |
| 571 * 2. the current range is not within web content. | 572 * 2. the current range is not within web content. |
| 572 * @param {string} url | 573 * @param {string} url |
| 573 * @return {boolean} | 574 * @return {boolean} |
| 574 */ | 575 */ |
| 575 isWhitelistedForClassicCompat_: function(url) { | 576 isWhitelistedForClassicCompat_: function(url) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 * forNextCompat: filters out tabs that have been listed for next compat (i.e. | 611 * forNextCompat: filters out tabs that have been listed for next compat (i.e. |
| 611 * should retain content script). | 612 * should retain content script). |
| 612 */ | 613 */ |
| 613 disableClassicChromeVox_: function(params) { | 614 disableClassicChromeVox_: function(params) { |
| 614 var disableChromeVoxCommand = { | 615 var disableChromeVoxCommand = { |
| 615 message: 'SYSTEM_COMMAND', | 616 message: 'SYSTEM_COMMAND', |
| 616 command: 'killChromeVox' | 617 command: 'killChromeVox' |
| 617 }; | 618 }; |
| 618 | 619 |
| 619 if (params.forNextCompat) { | 620 if (params.forNextCompat) { |
| 620 var reStr = this.NextCompatRegExp_.toString(); | 621 var reStr = this.nextCompatRegExp_.toString(); |
| 621 disableChromeVoxCommand['excludeUrlRegExp'] = | 622 disableChromeVoxCommand['excludeUrlRegExp'] = |
| 622 reStr.substring(1, reStr.length - 1); | 623 reStr.substring(1, reStr.length - 1); |
| 623 } | 624 } |
| 624 | 625 |
| 625 if (params.tabs) { | 626 if (params.tabs) { |
| 626 for (var i = 0, tab; tab = params.tabs[i]; i++) | 627 for (var i = 0, tab; tab = params.tabs[i]; i++) |
| 627 chrome.tabs.sendMessage(tab.id, disableChromeVoxCommand); | 628 chrome.tabs.sendMessage(tab.id, disableChromeVoxCommand); |
| 628 } else { | 629 } else { |
| 629 // Send to all ChromeVox clients. | 630 // Send to all ChromeVox clients. |
| 630 cvox.ExtensionBridge.send(disableChromeVoxCommand); | 631 cvox.ExtensionBridge.send(disableChromeVoxCommand); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 return new RegExp('^(' + globs.map(function(glob) { | 770 return new RegExp('^(' + globs.map(function(glob) { |
| 770 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 771 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 771 .replace(/\*/g, '.*') | 772 .replace(/\*/g, '.*') |
| 772 .replace(/\?/g, '.'); | 773 .replace(/\?/g, '.'); |
| 773 }).join('|') + ')$'); | 774 }).join('|') + ')$'); |
| 774 }; | 775 }; |
| 775 | 776 |
| 776 new Background(); | 777 new Background(); |
| 777 | 778 |
| 778 }); // goog.scope | 779 }); // goog.scope |
| OLD | NEW |