Debian Codegraph @

src/js/contentscripts/clobbercookie.js

raw
1 /*
2 * This file is part of Privacy Badger <https://privacybadger.org/>
3 * Copyright (C) 2014 Electronic Frontier Foundation
4 *
5 * Privacy Badger is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Privacy Badger is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Privacy Badger. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 (function () {
19
20 // don't inject into non-HTML documents (such as XML documents)
21 // but do inject into XHTML documents
22 if (document instanceof HTMLDocument === false && (
23 document instanceof XMLDocument === false ||
24 document.createElement('div') instanceof HTMLDivElement === false
25 )) {
26 return;
27 }
28
29 // don't bother asking to run when trivially in first-party context
30 if (window.top == window) {
31 return;
32 }
33
34 // TODO race condition; fix waiting on https://crbug.com/478183
35 chrome.runtime.sendMessage({
36 type: "checkClobberingEnabled",
37 frameUrl: window.FRAME_URL
38 }, function (blocked) {
39 if (blocked) {
40 var code = '('+ function() {
41 document.__defineSetter__("cookie", function(/*value*/) { });
42 document.__defineGetter__("cookie", function() { return ""; });
43
44 // trim referrer down to origin
45 let referrer = document.referrer;
46 if (referrer) {
47 referrer = referrer.slice(
48 0,
49 referrer.indexOf('/', referrer.indexOf('://') + 3)
50 ) + '/';
51 }
52 document.__defineGetter__("referrer", function () { return referrer; });
53 } +')();';
54
55 window.injectScript(code);
56 }
57 return true;
58 });
59
60 }());