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

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: Only kill Classic in current tab 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);
240 } else { 249 } else {
241 // When in compat mode, if the focus is within the desktop tree proper, 250 // When in compat mode, if the focus is within the desktop tree proper,
242 // then do not disable content scripts. 251 // then do not disable content scripts.
243 if (cur && !cur.isWebRange()) 252 if (cur && !cur.isWebRange())
244 return; 253 return;
245 254
246 this.disableClassicChromeVox_(); 255 this.disableClassicChromeVox_(tabs);
David Tseng 2016/06/16 21:36:33 If setting force next mode, we do want to disable
dmazzoni 2016/06/17 22:20:38 Good catch. Take a look.
247 } 256 }
248 }.bind(this)); 257 }.bind(this));
249 258
250 // If switching out of a ChromeVox Next mode, make sure we cancel 259 // If switching out of a ChromeVox Next mode, make sure we cancel
251 // the progress loading sound just in case. 260 // the progress loading sound just in case.
252 if ((this.mode_ === ChromeVoxMode.NEXT || 261 if ((this.mode_ === ChromeVoxMode.NEXT ||
253 this.mode_ === ChromeVoxMode.FORCE_NEXT) && 262 this.mode_ === ChromeVoxMode.FORCE_NEXT) &&
254 this.mode_ != mode) { 263 this.mode_ != mode) {
255 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING); 264 cvox.ChromeVox.earcons.cancelEarcon(cvox.Earcon.PAGE_START_LOADING);
256 } 265 }
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 !this.isBlacklistedForClassic_(url) && 1004 !this.isBlacklistedForClassic_(url) &&
996 !this.isWhitelistedForNext_(url); 1005 !this.isWhitelistedForNext_(url);
997 }, 1006 },
998 1007
999 /** 1008 /**
1000 * @param {string} url 1009 * @param {string} url
1001 * @return {boolean} 1010 * @return {boolean}
1002 * @private 1011 * @private
1003 */ 1012 */
1004 isBlacklistedForClassic_: function(url) { 1013 isBlacklistedForClassic_: function(url) {
1005 return this.classicBlacklistRegExp_.test(url); 1014 if (this.classicBlacklistRegExp_.test(url))
1015 return true;
1016 url = url.substring(0, url.indexOf('#')) || url;
1017 return this.classicBlacklist_.has(url);
1006 }, 1018 },
1007 1019
1008 /** 1020 /**
1009 * @param {string} url 1021 * @param {string} url
1010 * @return {boolean} Whether the given |url| is whitelisted. 1022 * @return {boolean} Whether the given |url| is whitelisted.
1011 * @private 1023 * @private
1012 */ 1024 */
1013 isWhitelistedForNext_: function(url) { 1025 isWhitelistedForNext_: function(url) {
1014 return this.whitelist_.some(function(item) { 1026 return this.whitelist_.some(function(item) {
1015 return url.indexOf(item) != -1; 1027 return url.indexOf(item) != -1;
1016 }); 1028 });
1017 }, 1029 },
1018 1030
1019 /** 1031 /**
1020 * Disables classic ChromeVox in current web content. 1032 * Disables classic ChromeVox in current web content.
1033 * @param {Array<Tab>} tabs The tabs where ChromeVox scripts should
1034 * be disabled.
1021 */ 1035 */
1022 disableClassicChromeVox_: function() { 1036 disableClassicChromeVox_: function(tabs) {
1023 cvox.ExtensionBridge.send({ 1037 for (var i = 0, tab; tab = tabs[i]; i++) {
1038 chrome.tabs.sendMessage(tab.id, {
1024 message: 'SYSTEM_COMMAND', 1039 message: 'SYSTEM_COMMAND',
1025 command: 'killChromeVox' 1040 command: 'killChromeVox'
1026 }); 1041 });
1042 }
1027 }, 1043 },
1028 1044
1029 /** 1045 /**
1030 * @param {!Spannable} text 1046 * @param {!Spannable} text
1031 * @param {number} position 1047 * @param {number} position
1032 * @private 1048 * @private
1033 */ 1049 */
1034 brailleRoutingCommand_: function(text, position) { 1050 brailleRoutingCommand_: function(text, position) {
1035 var actionNodeSpan = null; 1051 var actionNodeSpan = null;
1036 var selectionSpan = null; 1052 var selectionSpan = null;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1084
1069 switch (target) { 1085 switch (target) {
1070 case 'next': 1086 case 'next':
1071 if (action == 'getIsClassicEnabled') { 1087 if (action == 'getIsClassicEnabled') {
1072 var url = msg['url']; 1088 var url = msg['url'];
1073 var isClassicEnabled = this.shouldEnableClassicForUrl_(url); 1089 var isClassicEnabled = this.shouldEnableClassicForUrl_(url);
1074 port.postMessage({ 1090 port.postMessage({
1075 target: 'next', 1091 target: 'next',
1076 isClassicEnabled: isClassicEnabled 1092 isClassicEnabled: isClassicEnabled
1077 }); 1093 });
1094 } else if (action == 'enableCompatForUrl') {
1095 var url = msg['url'];
1096 this.classicBlacklist_.add(url);
1097 if (this.currentRange_ && this.currentRange_.start.node)
1098 this.refreshMode(this.currentRange_.start.node);
1078 } else if (action == 'onCommand') { 1099 } else if (action == 'onCommand') {
1079 this.onGotCommand(msg['command']); 1100 this.onGotCommand(msg['command']);
1080 } else if (action == 'flushNextUtterance') { 1101 } else if (action == 'flushNextUtterance') {
1081 Output.flushNextSpeechUtterance(); 1102 Output.flushNextSpeechUtterance();
1082 } 1103 }
1083 break; 1104 break;
1084 } 1105 }
1085 }, 1106 },
1086 1107
1087 /** 1108 /**
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&') 1215 return glob.replace(/[.+^$(){}|[\]\\]/g, '\\$&')
1195 .replace(/\*/g, '.*') 1216 .replace(/\*/g, '.*')
1196 .replace(/\?/g, '.'); 1217 .replace(/\?/g, '.');
1197 }).join('|') + ')$'); 1218 }).join('|') + ')$');
1198 }; 1219 };
1199 1220
1200 /** @type {Background} */ 1221 /** @type {Background} */
1201 global.backgroundObj = new Background(); 1222 global.backgroundObj = new Background();
1202 1223
1203 }); // goog.scope 1224 }); // 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