base/threading: remove ScopedTracker placed for experiments
[chromium-blink-merge.git] / ui / accessibility / extensions / highcontrast / background.js
blob24cba94322e9346760f325282e81706a749b9874
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function injectContentScripts() {
6 chrome.windows.getAll({'populate': true}, function(windows) {
7 for (var i = 0; i < windows.length; i++) {
8 var tabs = windows[i].tabs;
9 for (var j = 0; j < tabs.length; j++) {
10 var url = tabs[j].url;
11 if (url.indexOf('chrome') == 0 || url.indexOf('about') == 0) {
12 continue;
14 chrome.tabs.insertCSS(
15 tabs[j].id,
16 {file: 'highcontrast.css', allFrames: true});
17 chrome.tabs.executeScript(
18 tabs[j].id,
19 {file: 'highcontrast.js', allFrames: true});
22 });
25 function updateTabs() {
26 var msg = {
27 'enabled': getEnabled()
29 chrome.windows.getAll({'populate': true}, function(windows) {
30 for (var i = 0; i < windows.length; i++) {
31 var tabs = windows[i].tabs;
32 for (var j = 0; j < tabs.length; j++) {
33 var url = tabs[j].url;
34 if (isDisallowedUrl(url)) {
35 continue;
37 var msg = {
38 'enabled': getEnabled(),
39 'scheme': getSiteScheme(siteFromUrl(url))
41 chrome.tabs.sendRequest(tabs[j].id, msg);
44 });
47 function toggleEnabled() {
48 setEnabled(!getEnabled());
49 updateTabs();
52 function toggleSite(url) {
53 var site = siteFromUrl(url);
54 var scheme = getSiteScheme(site);
55 if (scheme > 0) {
56 scheme = 0;
57 } else if (getDefaultScheme() > 0) {
58 scheme = getDefaultScheme();
59 } else {
60 scheme = DEFAULT_SCHEME;
62 setSiteScheme(site, scheme);
63 updateTabs();
66 function init() {
67 injectContentScripts();
68 updateTabs();
70 chrome.extension.onRequest.addListener(
71 function(request, sender, sendResponse) {
72 if (request['toggle_global']) {
73 toggleEnabled();
75 if (request['toggle_site']) {
76 toggleSite(sender.tab ? sender.tab.url : 'www.example.com');
78 if (request['init']) {
79 var scheme = getDefaultScheme();
80 if (sender.tab) {
81 scheme = getSiteScheme(siteFromUrl(sender.tab.url));
83 var msg = {
84 'enabled': getEnabled(),
85 'scheme': scheme
87 sendResponse(msg);
89 });
91 document.addEventListener('storage', function(evt) {
92 updateTabs();
93 }, false);
95 if (navigator.appVersion.indexOf('Mac') != -1) {
96 chrome.browserAction.setTitle({'title': 'High Contrast (Cmd+Shift+F11)'});
100 init();