Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * A list of site substring patterns to use with ChromeVox next. Keep these | 46 * A list of site substring patterns to use with ChromeVox next. Keep these |
| 47 * strings relatively specific. | 47 * strings relatively specific. |
| 48 * @type {!Array<string>} | 48 * @type {!Array<string>} |
| 49 * @private | 49 * @private |
| 50 */ | 50 */ |
| 51 this.whitelist_ = ['chromevox_next_test']; | 51 this.whitelist_ = ['chromevox_next_test']; |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * A list of site substring patterns to blacklist ChromeVox Classic, | |
| 55 * putting ChromeVox into Compat mode. | |
| 56 * @type {!Set<string>} | |
| 57 * @private | |
| 58 */ | |
| 59 this.classicBlacklist_ = new Set(); | |
| 60 | |
| 61 /** | |
| 54 * Regular expression for blacklisting classic. | 62 * Regular expression for blacklisting classic. |
| 55 * @type {RegExp} | 63 * @type {RegExp} |
| 56 * @private | 64 * @private |
| 57 */ | 65 */ |
| 58 this.classicBlacklistRegExp_ = Background.globsToRegExp_( | 66 this.classicBlacklistRegExp_ = Background.globsToRegExp_( |
| 59 chrome.runtime.getManifest()['content_scripts'][0]['exclude_globs']); | 67 chrome.runtime.getManifest()['content_scripts'][0]['exclude_globs']); |
| 60 | 68 |
| 61 /** | 69 /** |
| 62 * @type {cursors.Range} | 70 * @type {cursors.Range} |
| 63 * @private | 71 * @private |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 !chrome.commands.onCommand.hasListener(this.onGotCommand)) | 231 !chrome.commands.onCommand.hasListener(this.onGotCommand)) |
| 224 chrome.commands.onCommand.addListener(this.onGotCommand); | 232 chrome.commands.onCommand.addListener(this.onGotCommand); |
| 225 chrome.accessibilityPrivate.setKeyboardListener( | 233 chrome.accessibilityPrivate.setKeyboardListener( |
| 226 true, cvox.ChromeVox.isStickyPrefOn); | 234 true, cvox.ChromeVox.isStickyPrefOn); |
| 227 } | 235 } |
| 228 | 236 |
| 229 // note that |this.currentRange_| can *change* because the request is | 237 // note that |this.currentRange_| can *change* because the request is |
| 230 // async. Save it to ensure we're looking at the currentRange at this moment | 238 // async. Save it to ensure we're looking at the currentRange at this moment |
| 231 // in time. | 239 // in time. |
| 232 var cur = this.currentRange_; | 240 var cur = this.currentRange_; |
| 233 chrome.tabs.query({active: true}, function(tabs) { | 241 chrome.tabs.query({active: true, |
| 242 lastFocusedWindow: true}, function(tabs) { | |
| 234 if (mode === ChromeVoxMode.CLASSIC) { | 243 if (mode === ChromeVoxMode.CLASSIC) { |
| 235 // Generally, we don't want to inject classic content scripts as it is | 244 // Generally, we don't want to inject classic content scripts as it is |
| 236 // done by the extension system at document load. The exception is when | 245 // done by the extension system at document load. The exception is when |
| 237 // we toggle classic on manually as part of a user command. | 246 // we toggle classic on manually as part of a user command. |
| 238 if (opt_injectClassic) | 247 if (opt_injectClassic) |
| 239 cvox.ChromeVox.injectChromeVoxIntoTabs(tabs); | 248 cvox.ChromeVox.injectChromeVoxIntoTabs(tabs); |
| 249 } else if (mode === ChromeVoxMode.FORCE_NEXT) { | |
| 250 // Disable ChromeVox everywhere. | |
| 251 this.disableClassicChromeVox_(); | |
| 240 } else { | 252 } else { |
| 241 // When in compat mode, if the focus is within the desktop tree proper, | 253 // If we're focused in the desktop tree, do nothing. |
| 242 // then do not disable content scripts. | |
| 243 if (cur && !cur.isWebRange()) | 254 if (cur && !cur.isWebRange()) |
| 244 return; | 255 return; |
| 245 | 256 |
| 246 this.disableClassicChromeVox_(); | 257 // If we're entering compat mode or next mode for just one tab, |
| 258 // disable Classic for that tab only. | |
| 259 this.disableClassicChromeVox_(tabs); | |
| 247 } | 260 } |
| 248 }.bind(this)); | 261 }.bind(this)); |
| 249 | 262 |
| 250 // If switching out of a ChromeVox Next mode, make sure we cancel | 263 // If switching out of a ChromeVox Next mode, make sure we cancel |
| 251 // the progress loading sound just in case. | 264 // the progress loading sound just in case. |
| 252 if ((this.mode_ === ChromeVoxMode.NEXT || | 265 if ((this.mode_ === ChromeVoxMode.NEXT || |
| 253 this.mode_ === ChromeVoxMode.FORCE_NEXT) && | 266 this.mode_ === ChromeVoxMode.FORCE_NEXT) && |
| 254 this.mode_ != mode) { | 267 this.mode_ != mode) { |
| 255 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); | 268 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); |
| 256 } | 269 } |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 995 !this.isBlacklistedForClassic_(url) && | 1008 !this.isBlacklistedForClassic_(url) && |
| 996 !this.isWhitelistedForNext_(url); | 1009 !this.isWhitelistedForNext_(url); |
| 997 }, | 1010 }, |
| 998 | 1011 |
| 999 /** | 1012 /** |
| 1000 * @param {string} url | 1013 * @param {string} url |
| 1001 * @return {boolean} | 1014 * @return {boolean} |
| 1002 * @private | 1015 * @private |
| 1003 */ | 1016 */ |
| 1004 isBlacklistedForClassic_: function(url) { | 1017 isBlacklistedForClassic_: function(url) { |
| 1005 return this.classicBlacklistRegExp_.test(url); | 1018 if (this.classicBlacklistRegExp_.test(url)) |
| 1019 return true; | |
| 1020 url = url.substring(0, url.indexOf('#')) || url; | |
| 1021 return this.classicBlacklist_.has(url); | |
| 1006 }, | 1022 }, |
| 1007 | 1023 |
| 1008 /** | 1024 /** |
| 1009 * @param {string} url | 1025 * @param {string} url |
| 1010 * @return {boolean} Whether the given |url| is whitelisted. | 1026 * @return {boolean} Whether the given |url| is whitelisted. |
| 1011 * @private | 1027 * @private |
| 1012 */ | 1028 */ |
| 1013 isWhitelistedForNext_: function(url) { | 1029 isWhitelistedForNext_: function(url) { |
| 1014 return this.whitelist_.some(function(item) { | 1030 return this.whitelist_.some(function(item) { |
| 1015 return url.indexOf(item) != -1; | 1031 return url.indexOf(item) != -1; |
| 1016 }); | 1032 }); |
| 1017 }, | 1033 }, |
| 1018 | 1034 |
| 1019 /** | 1035 /** |
| 1020 * Disables classic ChromeVox in current web content. | 1036 * Disables classic ChromeVox in current web content. |
| 1037 * @param {Array<Tab>=} opt_tabs The tabs where ChromeVox scripts should | |
| 1038 * be disabled. If null, will disable ChromeVox everywhere. | |
| 1021 */ | 1039 */ |
| 1022 disableClassicChromeVox_: function() { | 1040 disableClassicChromeVox_: function(opt_tabs) { |
|
David Tseng
2016/06/20 16:26:08
Note for possibly a future refactoring cl: backgro
dmazzoni
2016/06/20 20:06:24
Acknowledged.
| |
| 1023 cvox.ExtensionBridge.send({ | 1041 if (opt_tabs) { |
| 1042 for (var i = 0, tab; tab = opt_tabs[i]; i++) { | |
| 1043 chrome.tabs.sendMessage(tab.id, { | |
| 1044 message: 'SYSTEM_COMMAND', | |
| 1045 command: 'killChromeVox' | |
| 1046 }); | |
| 1047 } | |
| 1048 } else { | |
| 1049 // Send to all ChromeVox clients. | |
| 1050 cvox.ExtensionBridge.send({ | |
| 1024 message: 'SYSTEM_COMMAND', | 1051 message: 'SYSTEM_COMMAND', |
| 1025 command: 'killChromeVox' | 1052 command: 'killChromeVox' |
|
David Tseng
2016/06/20 16:26:08
Same object; write it once at the top and in both
dmazzoni
2016/06/20 20:06:23
Done.
| |
| 1026 }); | 1053 }); |
| 1054 } | |
| 1027 }, | 1055 }, |
| 1028 | 1056 |
| 1029 /** | 1057 /** |
| 1030 * @param {!Spannable} text | 1058 * @param {!Spannable} text |
| 1031 * @param {number} position | 1059 * @param {number} position |
| 1032 * @private | 1060 * @private |
| 1033 */ | 1061 */ |
| 1034 brailleRoutingCommand_: function(text, position) { | 1062 brailleRoutingCommand_: function(text, position) { |
| 1035 var actionNodeSpan = null; | 1063 var actionNodeSpan = null; |
| 1036 var selectionSpan = null; | 1064 var selectionSpan = null; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1068 | 1096 |
| 1069 switch (target) { | 1097 switch (target) { |
| 1070 case 'next': | 1098 case 'next': |
| 1071 if (action == 'getIsClassicEnabled') { | 1099 if (action == 'getIsClassicEnabled') { |
| 1072 var url = msg['url']; | 1100 var url = msg['url']; |
| 1073 var isClassicEnabled = this.shouldEnableClassicForUrl_(url); | 1101 var isClassicEnabled = this.shouldEnableClassicForUrl_(url); |
| 1074 port.postMessage({ | 1102 port.postMessage({ |
| 1075 target: 'next', | 1103 target: 'next', |
| 1076 isClassicEnabled: isClassicEnabled | 1104 isClassicEnabled: isClassicEnabled |
| 1077 }); | 1105 }); |
| 1106 } else if (action == 'enableCompatForUrl') { | |
| 1107 var url = msg['url']; | |
| 1108 this.classicBlacklist_.add(url); | |
| 1109 if (this.currentRange_ && this.currentRange_.start.node) | |
| 1110 this.refreshMode(this.currentRange_.start.node); | |
| 1078 } else if (action == 'onCommand') { | 1111 } else if (action == 'onCommand') { |
| 1079 this.onGotCommand(msg['command']); | 1112 this.onGotCommand(msg['command']); |
| 1080 } else if (action == 'flushNextUtterance') { | 1113 } else if (action == 'flushNextUtterance') { |
| 1081 Output.flushNextSpeechUtterance(); | 1114 Output.flushNextSpeechUtterance(); |
| 1082 } | 1115 } |
| 1083 break; | 1116 break; |
| 1084 } | 1117 } |
| 1085 }, | 1118 }, |
| 1086 | 1119 |
| 1087 /** | 1120 /** |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') | 1227 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') |
| 1195 .replace(/\*/g, '.*') | 1228 .replace(/\*/g, '.*') |
| 1196 .replace(/\?/g, '.'); | 1229 .replace(/\?/g, '.'); |
| 1197 }).join('|') + ')$'); | 1230 }).join('|') + ')$'); |
| 1198 }; | 1231 }; |
| 1199 | 1232 |
| 1200 /** @type {Background} */ | 1233 /** @type {Background} */ |
| 1201 global.backgroundObj = new Background(); | 1234 global.backgroundObj = new Background(); |
| 1202 | 1235 |
| 1203 }); // goog.scope | 1236 }); // goog.scope |
| OLD | NEW |