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
)) {
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 ' +
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
));
77 'severity': getDefaultSeverity(),
78 'type': getDefaultType(),
79 'simulate': getDefaultSimulate(),
80 'enable': getDefaultEnable()
86 //TODO(mustaq): Handle uninstall
88 document
.addEventListener('storage', function(evt
) {