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

Side by Side Diff: src/engine/Main.cpp

Issue 5081266177179648: Issue 1104 - Cannot uncheck Disable on website option in tool bar (Closed)
Patch Set: Created Feb. 23, 2015, 12:40 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 | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/PluginClass.cpp » ('J')
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 22 matching lines...) Expand all
33 #include "Updater.h" 33 #include "Updater.h"
34 34
35 namespace 35 namespace
36 { 36 {
37 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 37 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
38 std::auto_ptr<Updater> updater; 38 std::auto_ptr<Updater> updater;
39 int activeConnections = 0; 39 int activeConnections = 0;
40 CriticalSection activeConnectionsLock; 40 CriticalSection activeConnectionsLock;
41 HWND callbackWindow; 41 HWND callbackWindow;
42 42
43 std::string CreateDomainWhitelistingFilterText(const std::string& domain)
44 {
45 return "@@||" + domain + "^$document";
46 }
47
48 void AddWhitelistedUrl(const std::string& url)
49 {
50 std::string host = ASCIIStringToLower(url);
51 if (BeginsWith<std::string>(host, "https://") || BeginsWith<std::string>(hos t, "http://"))
Eric 2015/02/26 16:14:10 Explicit type specification for template function.
sergei 2015/03/02 13:01:04 Actually, I guess, we don't need this test at all
52 {
53 host = filterEngine->GetHostFromURL(host);
54 }
55
56 ReplaceString<std::string>(host, "www.", "");
Eric 2015/02/26 16:14:10 Explicit type for template function.
Eric 2015/02/26 18:16:01 More importantly, this algorithm is not correct. I
sergei 2015/03/02 13:01:04 Right, it's incorrect, we need to replace only the
57 if (!host.empty())
58 {
59 filterEngine->GetFilter(CreateDomainWhitelistingFilterText(host))->AddToLi st();
60 }
61 }
62
43 void WriteSubscriptions(Communication::OutputBuffer& response, 63 void WriteSubscriptions(Communication::OutputBuffer& response,
44 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) 64 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
45 { 65 {
46 int32_t count = static_cast<int32_t>(subscriptions.size()); 66 int32_t count = static_cast<int32_t>(subscriptions.size());
47 response << count; 67 response << count;
48 for (int32_t i = 0; i < count; i++) 68 for (int32_t i = 0; i < count; i++)
49 { 69 {
50 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; 70 AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
51 response << subscription->GetProperty("url")->AsString() 71 response << subscription->GetProperty("url")->AsString()
52 << subscription->GetProperty("title")->AsString() 72 << subscription->GetProperty("title")->AsString()
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 230 }
211 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: 231 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL:
212 { 232 {
213 std::string url; 233 std::string url;
214 request >> url; 234 request >> url;
215 AdblockPlus::FilterPtr match = filterEngine->Matches(url, 235 AdblockPlus::FilterPtr match = filterEngine->Matches(url,
216 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url); 236 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url);
217 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 237 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION);
218 break; 238 break;
219 } 239 }
220 case Communication::PROC_ADD_FILTER: 240 case Communication::PROC_ADD_WHITELSITED_DOMAIN:
221 { 241 {
222 std::string text; 242 std::string url;
223 request >> text; 243 request >> url;
224 244 AddWhitelistedUrl(url);
225 filterEngine->GetFilter(text)->AddToList();
226 break; 245 break;
227 } 246 }
228 case Communication::PROC_REMOVE_FILTER: 247 case Communication::PROC_REMOVE_WHITELSITED_DOMAIN:
229 { 248 {
Eric 2015/02/26 18:16:01 As a point of code clarity, if we have a function
sergei 2015/03/02 13:01:04 I cannot say that their implementations are opposi
Eric 2015/03/02 19:24:31 I doesn't matter if their implementations are exac
230 std::string text; 249 std::string domain;
231 request >> text; 250 request >> domain;
232 filterEngine->GetFilter(text)->RemoveFromList(); 251 AdblockPlus::FilterPtr filter
252 = filterEngine->GetFilter(CreateDomainWhitelistingFilterText(domain));
253 if (filter && filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
254 {
255 filter->RemoveFromList();
256 }
257 break;
258 }
259 case Communication::PROC_TOGGLE_WHITELISTING:
260 {
261 std::string url;
262 request >> url;
263 auto filter = filterEngine->Matches(url,
264 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, "");
265 bool isWhitelisted = filter && filter->GetType() == AdblockPlus::Filter: :TYPE_EXCEPTION;
266 if (isWhitelisted)
267 {
268 filter->RemoveFromList();
269 }
270 else
271 {
272 AddWhitelistedUrl(url);
273 }
233 break; 274 break;
234 } 275 }
235 case Communication::PROC_SET_PREF: 276 case Communication::PROC_SET_PREF:
236 { 277 {
237 std::string prefName; 278 std::string prefName;
238 request >> prefName; 279 request >> prefName;
239 280
240 Communication::ValueType valueType = request.GetType(); 281 Communication::ValueType valueType = request.GetType();
241 switch (valueType) 282 switch (valueType)
242 { 283 {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 538 }
498 catch (const std::runtime_error& e) 539 catch (const std::runtime_error& e)
499 { 540 {
500 DebugException(e); 541 DebugException(e);
501 return 1; 542 return 1;
502 } 543 }
503 } 544 }
504 545
505 return 0; 546 return 0;
506 } 547 }
OLDNEW
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/PluginClass.cpp » ('J')

Powered by Google App Engine
This is Rietveld