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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.h » ('j') | src/plugin/PluginClass.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/engine/Main.cpp
diff --git a/src/engine/Main.cpp b/src/engine/Main.cpp
index 01ddcb6ca49a5ca2dc8dbc692d364abaae0ef70e..759931d9cca638102b0d3a2dc7f95631ac3434bd 100644
--- a/src/engine/Main.cpp
+++ b/src/engine/Main.cpp
@@ -40,6 +40,26 @@ namespace
CriticalSection activeConnectionsLock;
HWND callbackWindow;
+ std::string CreateDomainWhitelistingFilterText(const std::string& domain)
+ {
+ return "@@||" + domain + "^$document";
+ }
+
+ void AddWhitelistedUrl(const std::string& url)
+ {
+ std::string host = ASCIIStringToLower(url);
+ if (BeginsWith<std::string>(host, "https://") || BeginsWith<std::string>(host, "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
+ {
+ host = filterEngine->GetHostFromURL(host);
+ }
+
+ 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
+ if (!host.empty())
+ {
+ filterEngine->GetFilter(CreateDomainWhitelistingFilterText(host))->AddToList();
+ }
+ }
+
void WriteSubscriptions(Communication::OutputBuffer& response,
const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions)
{
@@ -217,19 +237,40 @@ namespace
response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION);
break;
}
- case Communication::PROC_ADD_FILTER:
+ case Communication::PROC_ADD_WHITELSITED_DOMAIN:
{
- std::string text;
- request >> text;
-
- filterEngine->GetFilter(text)->AddToList();
+ std::string url;
+ request >> url;
+ AddWhitelistedUrl(url);
break;
}
- case Communication::PROC_REMOVE_FILTER:
+ case Communication::PROC_REMOVE_WHITELSITED_DOMAIN:
{
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
- std::string text;
- request >> text;
- filterEngine->GetFilter(text)->RemoveFromList();
+ std::string domain;
+ request >> domain;
+ AdblockPlus::FilterPtr filter
+ = filterEngine->GetFilter(CreateDomainWhitelistingFilterText(domain));
+ if (filter && filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
+ {
+ filter->RemoveFromList();
+ }
+ break;
+ }
+ case Communication::PROC_TOGGLE_WHITELISTING:
+ {
+ std::string url;
+ request >> url;
+ auto filter = filterEngine->Matches(url,
+ AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, "");
+ bool isWhitelisted = filter && filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION;
+ if (isWhitelisted)
+ {
+ filter->RemoveFromList();
+ }
+ else
+ {
+ AddWhitelistedUrl(url);
+ }
break;
}
case Communication::PROC_SET_PREF:
« 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