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.
6 * Adds filter script and css to all existing tabs.
8 * TODO(wnwen): Verify content scripts are not being injected multiple times.
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)) {
19 chrome.tabs.insertCSS(
21 {file: 'res/cvd.css'});
22 chrome.tabs.executeScript(
24 {file: 'src/common.js'});
25 chrome.tabs.executeScript(
27 {file: 'src/cvd.js'});
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)) {
45 debugPrint('sending to ' + siteFromUrl(url) + ' ' +
46 getSiteDelta(siteFromUrl(url)) + ',' +
47 getSiteSeverity(siteFromUrl(url)));
49 'delta': getSiteDelta(siteFromUrl(url)),
50 'severity': getSiteSeverity(siteFromUrl(url)),
51 'type': getDefaultType(),
52 'simulate': getDefaultSimulate()
54 chrome.tabs.sendRequest(tabs[j].id, msg);
61 * Initial extension loading.
63 (function initialize() {
64 injectContentScripts();
67 chrome.extension.onRequest.addListener(
68 function(request, sender, sendResponse) {
69 if (request['init']) {
70 var delta = getDefaultDelta();
72 delta = getSiteDelta(siteFromUrl(sender.tab.url));
75 var severity = getDefaultSeverity();
77 severity = getSiteSeverity(siteFromUrl(sender.tab.url));
80 var type = getDefaultType();
81 var simulate = getDefaultSimulate();
86 'type': getDefaultType(),
87 'simulate': getDefaultSimulate()
93 document.addEventListener('storage', function(evt) {