Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js

Issue 2074513002: Parse meta tag that disables ChromeVox content script and forces compat mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address last feedback Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/chromevox/injected/init_document.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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) {
1023 cvox.ExtensionBridge.send({ 1041 var disableChromeVoxCommand = {
1024 message: 'SYSTEM_COMMAND', 1042 message: 'SYSTEM_COMMAND',
1025 command: 'killChromeVox' 1043 command: 'killChromeVox'
1026 }); 1044 };
1045
1046 if (opt_tabs) {
1047 for (var i = 0, tab; tab = opt_tabs[i]; i++)
1048 chrome.tabs.sendMessage(tab.id, disableChromeVoxCommand);
1049 } else {
1050 // Send to all ChromeVox clients.
1051 cvox.ExtensionBridge.send(disableChromeVoxCommand);
1052 }
1027 }, 1053 },
1028 1054
1029 /** 1055 /**
1030 * @param {!Spannable} text 1056 * @param {!Spannable} text
1031 * @param {number} position 1057 * @param {number} position
1032 * @private 1058 * @private
1033 */ 1059 */
1034 brailleRoutingCommand_: function(text, position) { 1060 brailleRoutingCommand_: function(text, position) {
1035 var actionNodeSpan = null; 1061 var actionNodeSpan = null;
1036 var selectionSpan = null; 1062 var selectionSpan = null;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1094
1069 switch (target) { 1095 switch (target) {
1070 case 'next': 1096 case 'next':
1071 if (action == 'getIsClassicEnabled') { 1097 if (action == 'getIsClassicEnabled') {
1072 var url = msg['url']; 1098 var url = msg['url'];
1073 var isClassicEnabled = this.shouldEnableClassicForUrl_(url); 1099 var isClassicEnabled = this.shouldEnableClassicForUrl_(url);
1074 port.postMessage({ 1100 port.postMessage({
1075 target: 'next', 1101 target: 'next',
1076 isClassicEnabled: isClassicEnabled 1102 isClassicEnabled: isClassicEnabled
1077 }); 1103 });
1104 } else if (action == 'enableCompatForUrl') {
1105 var url = msg['url'];
1106 this.classicBlacklist_.add(url);
1107 if (this.currentRange_ && this.currentRange_.start.node)
1108 this.refreshMode(this.currentRange_.start.node);
1078 } else if (action == 'onCommand') { 1109 } else if (action == 'onCommand') {
1079 this.onGotCommand(msg['command']); 1110 this.onGotCommand(msg['command']);
1080 } else if (action == 'flushNextUtterance') { 1111 } else if (action == 'flushNextUtterance') {
1081 Output.flushNextSpeechUtterance(); 1112 Output.flushNextSpeechUtterance();
1082 } 1113 }
1083 break; 1114 break;
1084 } 1115 }
1085 }, 1116 },
1086 1117
1087 /** 1118 /**
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') 1225 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&')
1195 .replace(/\*/g, '.*') 1226 .replace(/\*/g, '.*')
1196 .replace(/\?/g, '.'); 1227 .replace(/\?/g, '.');
1197 }).join('|') + ')$'); 1228 }).join('|') + ')$');
1198 }; 1229 };
1199 1230
1200 /** @type {Background} */ 1231 /** @type {Background} */
1201 global.backgroundObj = new Background(); 1232 global.backgroundObj = new Background();
1202 1233
1203 }); // goog.scope 1234 }); // goog.scope
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/chromevox/injected/init_document.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698