Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: background.js

Issue 29338761: Issue 3841 - Remove workaround stripping [style] selectors on certain websites (Closed)
Patch Set: Created March 19, 2016, 8:16 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 25 matching lines...) Expand all
36 var FilterNotifier = require("filterNotifier").FilterNotifier; 36 var FilterNotifier = require("filterNotifier").FilterNotifier;
37 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; 37 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
38 var ElemHide = require("elemHide").ElemHide; 38 var ElemHide = require("elemHide").ElemHide;
39 var defaultMatcher = require("matcher").defaultMatcher; 39 var defaultMatcher = require("matcher").defaultMatcher;
40 var Prefs = require("prefs").Prefs; 40 var Prefs = require("prefs").Prefs;
41 var updateIcon = require("icon").updateIcon; 41 var updateIcon = require("icon").updateIcon;
42 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl; 42 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl;
43 var port = require("messaging").port; 43 var port = require("messaging").port;
44 var devtools = require("devtools"); 44 var devtools = require("devtools");
45 45
46 // Special-case domains for which we cannot use style-based hiding rules.
47 // See http://crbug.com/68705.
48 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
49
50 var htmlPages = new ext.PageMap(); 46 var htmlPages = new ext.PageMap();
51 47
52 var contextMenuItem = { 48 var contextMenuItem = {
53 title: ext.i18n.getMessage("block_element"), 49 title: ext.i18n.getMessage("block_element"),
54 contexts: ["image", "video", "audio"], 50 contexts: ["image", "video", "audio"],
55 onclick: function(page) 51 onclick: function(page)
56 { 52 {
57 page.sendMessage({type: "composer.content.contextMenuClicked"}); 53 page.sendMessage({type: "composer.content.contextMenuClicked"});
58 } 54 }
59 }; 55 };
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 else 105 else
110 filters.push(filter.text); 106 filters.push(filter.text);
111 } 107 }
112 } 108 }
113 109
114 return {filters: filters, exceptions: exceptions}; 110 return {filters: filters, exceptions: exceptions};
115 } 111 }
116 112
117 port.on("get-selectors", function(msg, sender) 113 port.on("get-selectors", function(msg, sender)
118 { 114 {
119 var selectors = []; 115 var selectors;
120 var trace = devtools && devtools.hasPanel(sender.page); 116 var trace = devtools && devtools.hasPanel(sender.page);
121 117
122 if (!checkWhitelisted(sender.page, sender.frame, 118 if (!checkWhitelisted(sender.page, sender.frame,
123 RegExpFilter.typeMap.DOCUMENT | 119 RegExpFilter.typeMap.DOCUMENT |
124 RegExpFilter.typeMap.ELEMHIDE)) 120 RegExpFilter.typeMap.ELEMHIDE))
125 { 121 selectors = ElemHide.getSelectorsForDomain(
126 var noStyleRules = false; 122 extractHostFromFrame(sender.frame),
127 var specificOnly = checkWhitelisted(sender.page, sender.frame, 123 checkWhitelisted(sender.page, sender.frame,
128 RegExpFilter.typeMap.GENERICHIDE); 124 RegExpFilter.typeMap.GENERICHIDE)
129 var host = extractHostFromFrame(sender.frame); 125 );
130 126 else
131 for (var i = 0; i < noStyleRulesHosts.length; i++) 127 selectors = [];
132 {
133 var noStyleHost = noStyleRulesHosts[i];
134 if (host == noStyleHost || (host.length > noStyleHost.length &&
135 host.substr(host.length - noStyleHost.length - 1) == "." + noStyleHost))
136 {
137 noStyleRules = true;
138 }
139 }
140 selectors = ElemHide.getSelectorsForDomain(host, specificOnly);
141 if (noStyleRules)
142 {
143 selectors = selectors.filter(function(s)
144 {
145 return !/\[style[\^\$]?=/.test(s);
146 });
147 }
148 }
149 128
150 return {selectors: selectors, trace: trace}; 129 return {selectors: selectors, trace: trace};
151 }); 130 });
152 131
153 port.on("should-collapse", function(msg, sender) 132 port.on("should-collapse", function(msg, sender)
154 { 133 {
155 if (checkWhitelisted(sender.page, sender.frame)) 134 if (checkWhitelisted(sender.page, sender.frame))
156 return false; 135 return false;
157 136
158 var typeMask = RegExpFilter.typeMap[msg.mediatype]; 137 var typeMask = RegExpFilter.typeMap[msg.mediatype];
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 187 }
209 }); 188 });
210 189
211 // update icon when page changes location 190 // update icon when page changes location
212 ext.pages.onLoading.addListener(function(page) 191 ext.pages.onLoading.addListener(function(page)
213 { 192 {
214 page.sendMessage({type: "composer.content.finished"}); 193 page.sendMessage({type: "composer.content.finished"});
215 refreshIconAndContextMenu(page); 194 refreshIconAndContextMenu(page);
216 showNextNotificationForUrl(page.url); 195 showNextNotificationForUrl(page.url);
217 }); 196 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld