| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | |
| 4 * | |
| 5 * Adblock Plus 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 * Adblock Plus 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 Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 16 */ | |
| 17 | |
| 18 let {defaultMatcher} = require("matcher"); | |
| 19 let {WhitelistFilter} = require("filterClasses"); | |
| 20 | |
| 21 let tabsWithKeyException = new TabMap(true); | |
| 22 | |
| 23 let isWhitelisted = exports.isWhitelisted = function(url, parentUrl, type) | |
| 24 { | |
| 25 let filter = defaultMatcher.matchesAny( | |
| 26 stripFragmentFromURL(url), | |
| 27 type || "DOCUMENT", | |
| 28 extractHostFromURL(parentUrl || url), | |
| 29 false | |
| 30 ); | |
| 31 | |
| 32 return (filter instanceof WhitelistFilter ? filter : null); | |
| 33 }; | |
| 34 | |
| 35 let isFrameWhitelisted = exports.isFrameWhitelisted = function(tab, frame, type) | |
| 36 { | |
| 37 let urlsWithKeyException = tabsWithKeyException.get(tab); | |
| 38 | |
| 39 for (; frame != null; frame = frame.parent) | |
| 40 { | |
| 41 if (urlsWithKeyException && stripFragmentFromURL(frame.url) in urlsWithKeyEx ception) | |
| 42 return true; | |
| 43 if (isWhitelisted(frame.url, (frame.parent || {}).url, type)) | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 return false; | |
| 48 }; | |
| 49 | |
| 50 let verifyKeyException = function(token, url, docDomain) | |
| 51 { | |
| 52 let match = token.match(/((.*?)=*)_(.*)/); | |
| 53 if (!match) | |
| 54 return false; // invalid format | |
| 55 | |
| 56 if (!defaultMatcher.matchesByKey(url, match[2], docDomain)) | |
|
Felix Dahlke
2014/01/18 13:39:19
I think this would be easier to follow if you'd as
Sebastian Noack
2014/01/19 10:19:40
Done.
| |
| 57 return false; // unknown key | |
| 58 | |
| 59 let uri = new URI(url); | |
| 60 let params = [ | |
| 61 uri.path, // REQUEST_URI | |
| 62 uri.asciiHost + (uri.port != -1 ? ":" + uri.port : ""), // HTTP_HOST | |
| 63 window.navigator.userAgent // HTTP_USER_AGENT | |
| 64 ]; | |
| 65 | |
| 66 return verifySignature(match[1], match[3], params.join("\0")); | |
| 67 }; | |
| 68 | |
| 69 let recordKeyException = function(tab, url) | |
| 70 { | |
| 71 let urlsWithKeyException = tabsWithKeyException.get(tab); | |
| 72 | |
| 73 if (!urlsWithKeyException) | |
| 74 { | |
| 75 urlsWithKeyException = {__proto__: null}; | |
| 76 tabsWithKeyException.set(tab, urlsWithKeyException); | |
| 77 } | |
| 78 | |
| 79 urlsWithKeyException[url] = null; | |
| 80 }; | |
| 81 | |
| 82 let processKeyException = exports.processKeyException = function(token, tab, fra me) | |
| 83 { | |
| 84 let url = stripFragmentFromURL(frame.url); | |
| 85 let docDomain = extractHostFromURL((frame.parent || frame).url); | |
| 86 | |
| 87 if (verifyKeyException(token, url, docDomain)) | |
| 88 recordKeyException(tab, url); | |
| 89 }; | |
| OLD | NEW |