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

Unified Diff: src/engine/main.cpp

Issue 10845030: Marshal all libadblockplus calls to the engine process (Closed)
Patch Set: Created May 31, 2013, 2:20 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 | « AdblockPlusPlugin.vcxproj ('k') | src/plugin/AdblockPlusClient.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/engine/main.cpp
===================================================================
--- a/src/engine/main.cpp
+++ b/src/engine/main.cpp
@@ -35,41 +35,117 @@ namespace
if (utf8StringLength == 0)
throw std::runtime_error("Failed to determine the required buffer size");
std::string utf8String(utf8StringLength, '\0');
WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, &utf8String[0], utf8StringLength, 0, 0);
return utf8String;
}
+ void WriteStrings(Communication::OutputBuffer& response,
+ const std::vector<std::string> strings)
Felix Dahlke 2013/06/04 11:53:17 Shouldn't the strings be passed by reference? This
+ {
+ int32_t count = strings.size();
+ response << count;
+ for (int32_t i = 0; i < count; i++)
+ response << strings[i];
+ }
+
+ void WriteSubscriptions(Communication::OutputBuffer& response,
+ const std::vector<AdblockPlus::SubscriptionPtr> subscriptions)
Felix Dahlke 2013/06/04 11:53:17 Same as above, probably better to pass by referenc
+ {
+ int32_t count = subscriptions.size();
+ response << count;
+ for (int32_t i = 0; i < count; i++)
+ {
+ AdblockPlus::SubscriptionPtr subscription = subscriptions[i];
+ response << subscription->GetProperty("url")->AsString()
+ << subscription->GetProperty("title")->AsString()
+ << subscription->GetProperty("specialization")->AsString()
+ << subscription->IsListed();
+ }
+ }
+
Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request)
{
Communication::OutputBuffer response;
std::string procedureName;
request >> procedureName;
if (procedureName == "Matches")
{
std::string url;
std::string type;
std::string documentUrl;
request >> url >> type >> documentUrl;
response << filterEngine->Matches(url, type, documentUrl);
}
- if (procedureName == "GetElementHidingSelectors")
+ else if (procedureName == "GetElementHidingSelectors")
{
std::string domain;
request >> domain;
+ WriteStrings(response, filterEngine->GetElementHidingSelectors(domain));
+ }
+ else if (procedureName == "FetchAvailableSubscriptions")
+ {
+ WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions());
+ }
+ else if (procedureName == "GetListedSubscriptions")
+ {
+ WriteSubscriptions(response, filterEngine->GetListedSubscriptions());
+ }
+ else if (procedureName == "SetSubscription")
+ {
+ std::string url;
+ request >> url;
- std::vector<std::string> selectors = filterEngine->GetElementHidingSelectors(domain);
+ std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetListedSubscriptions();
+ for (size_t i = 0, count = subscriptions.size(); i < count; i++)
+ subscriptions[i]->RemoveFromList();
- int32_t length = selectors.size();
- response << length;
- for (int32_t i = 0; i < length; i++)
- response << selectors[i];
+ filterEngine->GetSubscription(url)->AddToList();
+ }
+ else if (procedureName == "UpdateAllSubscriptions")
+ {
+ std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetListedSubscriptions();
+ for (size_t i = 0, count = subscriptions.size(); i < count; i++)
+ subscriptions[i]->UpdateFilters();
+ }
+ else if (procedureName == "GetExceptionDomains")
+ {
+ std::vector<AdblockPlus::FilterPtr> filters = filterEngine->GetListedFilters();
+ std::vector<std::string> domains;
+ for (size_t i = 0, count = filters.size(); i < count; i++)
+ {
+ AdblockPlus::FilterPtr filter = filters[i];
+ if (filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
+ {
+ std::string text = filter->GetProperty("text")->AsString();
+
+ //@@||example.com^$document
+ const char prefix[] = "@@||";
+ const char suffix[] = "^$document";
+ const int prefixLen = strlen(prefix);
+ const int suffixLen = strlen(suffix);
+ if (!text.compare(0, prefixLen, prefix) &&
+ !text.compare(text.size() - suffixLen, suffixLen, suffix))
+ {
+ domains.push_back(text.substr(prefixLen, text.size() - prefixLen - suffixLen));
+ }
+ }
+ }
+
+ WriteStrings(response, domains);
+ }
+ else if (procedureName == "AddFilter")
+ {
+ std::string text;
+ request >> text;
+
+ filterEngine->GetFilter(text)->AddToList();
}
return response;
}
DWORD WINAPI ClientThread(LPVOID param)
{
std::auto_ptr<Communication::Pipe> pipe(static_cast<Communication::Pipe*>(param));
« no previous file with comments | « AdblockPlusPlugin.vcxproj ('k') | src/plugin/AdblockPlusClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld