Commit bf6c8577 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

Prevent multiple copies of a11y component extensions from opening

AX-Relnotes: n/a.
Bug: None.
Change-Id: I9c1145a4589aa7bbf761c51585055cdb363313d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380931Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#812441}
parent 7c828057
...@@ -87,6 +87,7 @@ js_library("accessibility_common") { ...@@ -87,6 +87,7 @@ js_library("accessibility_common") {
deps = [ deps = [
":autoclick", ":autoclick",
":magnifier", ":magnifier",
"../common:instance_checker",
] ]
externs_list = [ externs_list = [
"$externs_path/chrome_extensions.js", "$externs_path/chrome_extensions.js",
......
...@@ -76,5 +76,6 @@ class AccessibilityCommon { ...@@ -76,5 +76,6 @@ class AccessibilityCommon {
} }
} }
InstanceChecker.closeExtraInstances();
// Initialize the AccessibilityCommon extension. // Initialize the AccessibilityCommon extension.
var accessibilityCommon = new AccessibilityCommon(); var accessibilityCommon = new AccessibilityCommon();
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
{% endif %} {% endif %}
"background": { "background": {
"scripts": [ "scripts": [
"common/closure_shim.js",
"common/instance_checker.js",
"accessibility_common/autoclick/autoclick.js", "accessibility_common/autoclick/autoclick.js",
"accessibility_common/magnifier/magnifier.js", "accessibility_common/magnifier/magnifier.js",
"accessibility_common/accessibility_common_loader.js", "accessibility_common/accessibility_common_loader.js",
......
...@@ -27,6 +27,7 @@ chromevox_modules = [ ...@@ -27,6 +27,7 @@ chromevox_modules = [
"../common/constants.js", "../common/constants.js",
"../common/event_generator.js", "../common/event_generator.js",
"../common/key_code.js", "../common/key_code.js",
"../common/instance_checker.js",
"../common/tree_walker.js", "../common/tree_walker.js",
"background/annotation/node_identifier.js", "background/annotation/node_identifier.js",
"background/annotation/user_annotation_handler.js", "background/annotation/user_annotation_handler.js",
......
...@@ -25,6 +25,7 @@ goog.require('ExtensionBridge'); ...@@ -25,6 +25,7 @@ goog.require('ExtensionBridge');
goog.require('FindHandler'); goog.require('FindHandler');
goog.require('FocusAutomationHandler'); goog.require('FocusAutomationHandler');
goog.require('GestureCommandHandler'); goog.require('GestureCommandHandler');
goog.require('InstanceChecker');
goog.require('LiveRegions'); goog.require('LiveRegions');
goog.require('LocaleOutputHelper'); goog.require('LocaleOutputHelper');
goog.require('MathHandler'); goog.require('MathHandler');
...@@ -555,17 +556,7 @@ Background = class extends ChromeVoxState { ...@@ -555,17 +556,7 @@ Background = class extends ChromeVoxState {
} }
}; };
InstanceChecker.closeExtraInstances();
// In 'split' manifest mode, the extension system runs two copies of the
// extension. One in an incognito context; the other not. In guest mode, the
// extension system runs only the extension in an incognito context. To prevent
// doubling of this extension, only continue for one context.
const manifest =
/** @type {{incognito: (string|undefined)}} */ (
chrome.runtime.getManifest());
if (manifest.incognito == 'split' && !chrome.extension.inIncognitoContext) {
window.close();
}
new Background(); new Background();
}); // goog.scope }); // goog.scope
...@@ -31,6 +31,7 @@ run_jsbundler("accessibility_common_copied_files") { ...@@ -31,6 +31,7 @@ run_jsbundler("accessibility_common_copied_files") {
"constants.js", "constants.js",
"event_generator.js", "event_generator.js",
"event_handler.js", "event_handler.js",
"instance_checker.js",
"key_code.js", "key_code.js",
"rect_util.js", "rect_util.js",
"repeated_event_handler.js", "repeated_event_handler.js",
...@@ -96,6 +97,10 @@ js_library("event_handler") { ...@@ -96,6 +97,10 @@ js_library("event_handler") {
js_library("key_code") { js_library("key_code") {
} }
js_library("instance_checker") {
deps = [ ":closure_shim" ]
}
js_library("rect_util") { js_library("rect_util") {
externs_list = [ "$externs_path/accessibility_private.js" ] externs_list = [ "$externs_path/accessibility_private.js" ]
} }
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
goog.provide('InstanceChecker');
/**
* Used to prevent multiple instances of the extension from running
* simultaneously.
*/
const InstanceChecker = class {
static closeExtraInstances() {
// In 'split' manifest mode, the extension system runs two copies of the
// extension. One in an incognito context; the other not. In guest mode, the
// extension system runs only the extension in an incognito context. To
// prevent doubling of this extension, only continue for one context.
const manifest =
/** @type {{incognito: (string|undefined)}} */ (
chrome.runtime.getManifest());
if (manifest.incognito == 'split' && !chrome.extension.inIncognitoContext) {
window.close();
}
}
};
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
InstanceChecker.closeExtraInstances();
const selectToSpeak = new SelectToSpeak(); const selectToSpeak = new SelectToSpeak();
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"common/constants.js", "common/constants.js",
"common/key_code.js", "common/key_code.js",
"common/automation_predicate.js", "common/automation_predicate.js",
"common/instance_checker.js",
"common/rect_util.js", "common/rect_util.js",
"common/tree_walker.js", "common/tree_walker.js",
"common/automation_util.js", "common/automation_util.js",
......
...@@ -173,7 +173,10 @@ js_library("auto_scan_manager") { ...@@ -173,7 +173,10 @@ js_library("auto_scan_manager") {
} }
js_library("background") { js_library("background") {
deps = [ ":switch_access" ] deps = [
":switch_access",
"../common:instance_checker",
]
externs_list = [ "$externs_path/chrome_extensions.js" ] externs_list = [ "$externs_path/chrome_extensions.js" ]
} }
......
...@@ -2,14 +2,5 @@ ...@@ -2,14 +2,5 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// In 'split' manifest mode, the extension system runs two copies of the InstanceChecker.closeExtraInstances();
// extension. One in an incognito context; the other not. In guest mode, the
// extension system runs only the extension in an incognito context. To prevent
// doubling of this extension, only continue for one context.
const manifest =
/** @type {{incognito: (string|undefined)}} */ (
chrome.runtime.getManifest());
if (manifest.incognito == 'split' && !chrome.extension.inIncognitoContext) {
window.close();
}
SwitchAccess.initialize(); SwitchAccess.initialize();
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"common/event_generator.js", "common/event_generator.js",
"common/event_handler.js", "common/event_handler.js",
"common/key_code.js", "common/key_code.js",
"common/instance_checker.js",
"common/rect_util.js", "common/rect_util.js",
"common/repeated_event_handler.js", "common/repeated_event_handler.js",
"common/repeated_tree_change_handler.js", "common/repeated_tree_change_handler.js",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment