OLD | NEW |
1 #include <AdblockPlus.h> | 1 #include <AdblockPlus.h> |
2 #include <functional> | 2 #include <functional> |
3 #include <vector> | 3 #include <vector> |
4 #include <thread> | 4 #include <thread> |
5 #include <Windows.h> | 5 #include <Windows.h> |
6 | 6 |
7 #include "../shared/AutoHandle.h" | 7 #include "../shared/AutoHandle.h" |
8 #include "../shared/Communication.h" | 8 #include "../shared/Communication.h" |
9 #include "../shared/Dictionary.h" | 9 #include "../shared/Dictionary.h" |
10 #include "../shared/Utils.h" | 10 #include "../shared/Utils.h" |
11 #include "../shared/Version.h" | 11 #include "../shared/Version.h" |
12 #include "../shared/CriticalSection.h" | 12 #include "../shared/CriticalSection.h" |
13 #include "../shared/IE_version.h" | 13 #include "../shared/IE_version.h" |
14 #include "AdblockPlus.h" | 14 #include "AdblockPlus.h" |
15 #include "Debug.h" | 15 #include "Debug.h" |
16 #include "Updater.h" | 16 #include "Updater.h" |
17 | 17 |
18 namespace | 18 namespace |
19 { | 19 { |
20 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 20 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; |
21 std::auto_ptr<Updater> updater; | 21 std::auto_ptr<Updater> updater; |
22 int activeConnections = 0; | 22 int activeConnections = 0; |
23 CriticalSection activeConnectionsLock; | 23 CriticalSection activeConnectionsLock; |
24 HWND callbackWindow; | 24 HWND callbackWindow; |
25 | 25 |
26 void WriteStrings(Communication::OutputBuffer& response, | |
27 const std::vector<std::string>& strings) | |
28 { | |
29 int32_t count = static_cast<int32_t>(strings.size()); | |
30 response << count; | |
31 for (int32_t i = 0; i < count; i++) | |
32 response << strings[i]; | |
33 } | |
34 | |
35 void WriteSubscriptions(Communication::OutputBuffer& response, | 26 void WriteSubscriptions(Communication::OutputBuffer& response, |
36 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) | 27 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) |
37 { | 28 { |
38 int32_t count = static_cast<int32_t>(subscriptions.size()); | 29 int32_t count = static_cast<int32_t>(subscriptions.size()); |
39 response << count; | 30 response << count; |
40 for (int32_t i = 0; i < count; i++) | 31 for (int32_t i = 0; i < count; i++) |
41 { | 32 { |
42 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; | 33 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; |
43 response << subscription->GetProperty("url")->AsString() | 34 response << subscription->GetProperty("url")->AsString() |
44 << subscription->GetProperty("title")->AsString() | 35 << subscription->GetProperty("title")->AsString() |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 request >> url >> type >> documentUrl; | 85 request >> url >> type >> documentUrl; |
95 referrerMapping.Add(url, documentUrl); | 86 referrerMapping.Add(url, documentUrl); |
96 AdblockPlus::FilterPtr filter = filterEngine->Matches(url, type, referre
rMapping.BuildReferrerChain(documentUrl)); | 87 AdblockPlus::FilterPtr filter = filterEngine->Matches(url, type, referre
rMapping.BuildReferrerChain(documentUrl)); |
97 response << (filter && filter->GetType() != AdblockPlus::Filter::TYPE_EX
CEPTION); | 88 response << (filter && filter->GetType() != AdblockPlus::Filter::TYPE_EX
CEPTION); |
98 break; | 89 break; |
99 } | 90 } |
100 case Communication::PROC_GET_ELEMHIDE_SELECTORS: | 91 case Communication::PROC_GET_ELEMHIDE_SELECTORS: |
101 { | 92 { |
102 std::string domain; | 93 std::string domain; |
103 request >> domain; | 94 request >> domain; |
104 WriteStrings(response, filterEngine->GetElementHidingSelectors(domain)); | 95 response << filterEngine->GetElementHidingSelectors(domain); |
105 break; | 96 break; |
106 } | 97 } |
107 case Communication::PROC_AVAILABLE_SUBSCRIPTIONS: | 98 case Communication::PROC_AVAILABLE_SUBSCRIPTIONS: |
108 { | 99 { |
109 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions()
); | 100 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions()
); |
110 break; | 101 break; |
111 } | 102 } |
112 case Communication::PROC_LISTED_SUBSCRIPTIONS: | 103 case Communication::PROC_LISTED_SUBSCRIPTIONS: |
113 { | 104 { |
114 WriteSubscriptions(response, filterEngine->GetListedSubscriptions()); | 105 WriteSubscriptions(response, filterEngine->GetListedSubscriptions()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 const size_t prefixLen = strlen(prefix); | 170 const size_t prefixLen = strlen(prefix); |
180 const size_t suffixLen = strlen(suffix); | 171 const size_t suffixLen = strlen(suffix); |
181 if (!text.compare(0, prefixLen, prefix) && | 172 if (!text.compare(0, prefixLen, prefix) && |
182 !text.compare(text.size() - suffixLen, suffixLen, suffix)) | 173 !text.compare(text.size() - suffixLen, suffixLen, suffix)) |
183 { | 174 { |
184 domains.push_back(text.substr(prefixLen, text.size() - prefixLen -
suffixLen)); | 175 domains.push_back(text.substr(prefixLen, text.size() - prefixLen -
suffixLen)); |
185 } | 176 } |
186 } | 177 } |
187 } | 178 } |
188 | 179 |
189 WriteStrings(response, domains); | 180 response << domains; |
190 break; | 181 break; |
191 } | 182 } |
192 case Communication::PROC_IS_WHITELISTED_URL: | 183 case Communication::PROC_IS_WHITELISTED_URL: |
193 { | 184 { |
194 std::string url; | 185 std::string url; |
195 request >> url; | 186 request >> url; |
196 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "DOCUMENT", ur
l); | 187 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "DOCUMENT", ur
l); |
197 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE
PTION); | 188 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE
PTION); |
198 break; | 189 break; |
199 } | 190 } |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 } | 476 } |
486 catch (const std::runtime_error& e) | 477 catch (const std::runtime_error& e) |
487 { | 478 { |
488 DebugException(e); | 479 DebugException(e); |
489 return 1; | 480 return 1; |
490 } | 481 } |
491 } | 482 } |
492 | 483 |
493 return 0; | 484 return 0; |
494 } | 485 } |
OLD | NEW |