Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / accessibility / extensions / colorenhancer / src / background.js
bloba3321714d39bf0ab626b6097e9896847d8510926
1 // Copyright 2015 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 /**
6 * Adds filter script and css to all existing tabs.
8 * TODO(wnwen): Verify content scripts are not being injected multiple times.
9 */
10 function injectContentScripts() {
11 chrome.windows.getAll({'populate': true}, function(windows) {
12 for (var i = 0; i < windows.length; i++) {
13 var tabs = windows[i].tabs;
14 for (var j = 0; j < tabs.length; j++) {
15 var url = tabs[j].url;
16 if (isDisallowedUrl(url)) {
17 continue;
19 chrome.tabs.insertCSS(
20 tabs[j].id,
21 {file: 'res/cvd.css'});
22 chrome.tabs.executeScript(
23 tabs[j].id,
24 {file: 'src/common.js'});
25 chrome.tabs.executeScript(
26 tabs[j].id,
27 {file: 'src/cvd.js'});
30 });
33 /**
34 * Updates all existing tabs with config values.
36 function updateTabs() {
37 chrome.windows.getAll({'populate': true}, function(windows) {
38 for (var i = 0; i < windows.length; i++) {
39 var tabs = windows[i].tabs;
40 for (var j = 0; j < tabs.length; j++) {
41 var url = tabs[j].url;
42 if (isDisallowedUrl(url)) {
43 continue;
45 var msg = {
46 'delta': getSiteDelta(siteFromUrl(url)),
47 'severity': getDefaultSeverity(),
48 'type': getDefaultType(),
49 'simulate': getDefaultSimulate(),
50 'enable': getDefaultEnable()
52 debugPrint('updateTabs: sending ' + JSON.stringify(msg) + ' to ' +
53 siteFromUrl(url));
54 chrome.tabs.sendRequest(tabs[j].id, msg);
57 });
60 /**
61 * Initial extension loading.
63 (function initialize() {
64 injectContentScripts();
65 updateTabs();
67 chrome.extension.onRequest.addListener(
68 function(request, sender, sendResponse) {
69 if (request['init']) {
70 var delta = getDefaultDelta();
71 if (sender.tab) {
72 delta = getSiteDelta(siteFromUrl(sender.tab.url));
75 var msg = {
76 'delta': delta,
77 'severity': getDefaultSeverity(),
78 'type': getDefaultType(),
79 'simulate': getDefaultSimulate(),
80 'enable': getDefaultEnable()
82 sendResponse(msg);
84 });
86 //TODO(mustaq): Handle uninstall
88 document.addEventListener('storage', function(evt) {
89 updateTabs();
90 }, false);
91 })();