| LEFT | RIGHT |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 1 #include <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
| 2 #include <functional> | 19 #include <functional> |
| 3 #include <vector> | 20 #include <vector> |
| 4 #include <thread> | 21 #include <thread> |
| 5 #include <Windows.h> | 22 #include <Windows.h> |
| 6 | 23 |
| 7 #include "../shared/AutoHandle.h" | 24 #include "../shared/AutoHandle.h" |
| 8 #include "../shared/Communication.h" | 25 #include "../shared/Communication.h" |
| 9 #include "../shared/Dictionary.h" | 26 #include "../shared/Dictionary.h" |
| 10 #include "../shared/Utils.h" | 27 #include "../shared/Utils.h" |
| 11 #include "../shared/Version.h" | 28 #include "../shared/Version.h" |
| 12 #include "../shared/CriticalSection.h" | 29 #include "../shared/CriticalSection.h" |
| 13 #include "IE_Version.h" | 30 #include "IeVersion.h" |
| 14 #include "AdblockPlus.h" | 31 #include "AdblockPlus.h" |
| 15 #include "Debug.h" | 32 #include "Debug.h" |
| 16 #include "Updater.h" | 33 #include "Updater.h" |
| 17 | 34 |
| 18 namespace | 35 namespace |
| 19 { | 36 { |
| 20 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 37 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; |
| 21 std::auto_ptr<Updater> updater; | 38 std::auto_ptr<Updater> updater; |
| 22 int activeConnections = 0; | 39 int activeConnections = 0; |
| 23 CriticalSection activeConnectionsLock; | 40 CriticalSection activeConnectionsLock; |
| 24 HWND callbackWindow; | 41 HWND callbackWindow; |
| 25 | 42 |
| 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, | 43 void WriteSubscriptions(Communication::OutputBuffer& response, |
| 36 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) | 44 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) |
| 37 { | 45 { |
| 38 int32_t count = static_cast<int32_t>(subscriptions.size()); | 46 int32_t count = static_cast<int32_t>(subscriptions.size()); |
| 39 response << count; | 47 response << count; |
| 40 for (int32_t i = 0; i < count; i++) | 48 for (int32_t i = 0; i < count; i++) |
| 41 { | 49 { |
| 42 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; | 50 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; |
| 43 response << subscription->GetProperty("url")->AsString() | 51 response << subscription->GetProperty("url")->AsString() |
| 44 << subscription->GetProperty("title")->AsString() | 52 << subscription->GetProperty("title")->AsString() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 { | 90 { |
| 83 Communication::OutputBuffer response; | 91 Communication::OutputBuffer response; |
| 84 | 92 |
| 85 Communication::ProcType procedure; | 93 Communication::ProcType procedure; |
| 86 request >> procedure; | 94 request >> procedure; |
| 87 switch (procedure) | 95 switch (procedure) |
| 88 { | 96 { |
| 89 case Communication::PROC_MATCHES: | 97 case Communication::PROC_MATCHES: |
| 90 { | 98 { |
| 91 std::string url; | 99 std::string url; |
| 92 std::string type; | 100 using namespace AdblockPlus; |
| 93 std::string documentUrl; | 101 std::string documentUrl; |
| 102 int32_t type; |
| 94 request >> url >> type >> documentUrl; | 103 request >> url >> type >> documentUrl; |
| 95 referrerMapping.Add(url, documentUrl); | 104 referrerMapping.Add(url, documentUrl); |
| 96 AdblockPlus::FilterPtr filter = filterEngine->Matches(url, type, referre
rMapping.BuildReferrerChain(documentUrl)); | 105 auto contentType = static_cast<FilterEngine::ContentType>(type); |
| 97 response << (filter && filter->GetType() != AdblockPlus::Filter::TYPE_EX
CEPTION); | 106 FilterPtr filter = filterEngine->Matches(url, contentType, referrerMappi
ng.BuildReferrerChain(documentUrl)); |
| 107 response << (filter && filter->GetType() != Filter::TYPE_EXCEPTION); |
| 98 break; | 108 break; |
| 99 } | 109 } |
| 100 case Communication::PROC_GET_ELEMHIDE_SELECTORS: | 110 case Communication::PROC_GET_ELEMHIDE_SELECTORS: |
| 101 { | 111 { |
| 102 std::string domain; | 112 std::string domain; |
| 103 request >> domain; | 113 request >> domain; |
| 104 WriteStrings(response, filterEngine->GetElementHidingSelectors(domain)); | 114 response << filterEngine->GetElementHidingSelectors(domain); |
| 105 break; | 115 break; |
| 106 } | 116 } |
| 107 case Communication::PROC_AVAILABLE_SUBSCRIPTIONS: | 117 case Communication::PROC_AVAILABLE_SUBSCRIPTIONS: |
| 108 { | 118 { |
| 109 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions()
); | 119 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions()
); |
| 110 break; | 120 break; |
| 111 } | 121 } |
| 112 case Communication::PROC_LISTED_SUBSCRIPTIONS: | 122 case Communication::PROC_LISTED_SUBSCRIPTIONS: |
| 113 { | 123 { |
| 114 WriteSubscriptions(response, filterEngine->GetListedSubscriptions()); | 124 WriteSubscriptions(response, filterEngine->GetListedSubscriptions()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const size_t prefixLen = strlen(prefix); | 189 const size_t prefixLen = strlen(prefix); |
| 180 const size_t suffixLen = strlen(suffix); | 190 const size_t suffixLen = strlen(suffix); |
| 181 if (!text.compare(0, prefixLen, prefix) && | 191 if (!text.compare(0, prefixLen, prefix) && |
| 182 !text.compare(text.size() - suffixLen, suffixLen, suffix)) | 192 !text.compare(text.size() - suffixLen, suffixLen, suffix)) |
| 183 { | 193 { |
| 184 domains.push_back(text.substr(prefixLen, text.size() - prefixLen -
suffixLen)); | 194 domains.push_back(text.substr(prefixLen, text.size() - prefixLen -
suffixLen)); |
| 185 } | 195 } |
| 186 } | 196 } |
| 187 } | 197 } |
| 188 | 198 |
| 189 WriteStrings(response, domains); | 199 response << domains; |
| 190 break; | 200 break; |
| 191 } | 201 } |
| 192 case Communication::PROC_IS_WHITELISTED_URL: | 202 case Communication::PROC_GET_WHITELISTING_FITER: |
| 193 { | 203 { |
| 194 std::string url; | 204 std::string url; |
| 195 request >> url; | 205 request >> url; |
| 196 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "DOCUMENT", ur
l); | 206 AdblockPlus::FilterPtr match = filterEngine->Matches(url, |
| 197 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE
PTION); | 207 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_DOCUMENT, url); |
| 208 std::string filterText; |
| 209 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
| 210 { |
| 211 filterText = match->GetProperty("text")->AsString(); |
| 212 } |
| 213 response << filterText; |
| 198 break; | 214 break; |
| 199 } | 215 } |
| 200 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: | 216 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL: |
| 201 { | 217 { |
| 202 std::string url; | 218 std::string url; |
| 203 request >> url; | 219 request >> url; |
| 204 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "ELEMHIDE", ur
l); | 220 AdblockPlus::FilterPtr match = filterEngine->Matches(url, |
| 221 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_ELEMHIDE, url); |
| 205 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE
PTION); | 222 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE
PTION); |
| 206 break; | 223 break; |
| 207 } | 224 } |
| 208 case Communication::PROC_ADD_FILTER: | 225 case Communication::PROC_ADD_FILTER: |
| 209 { | 226 { |
| 210 std::string text; | 227 std::string text; |
| 211 request >> text; | 228 request >> text; |
| 212 | 229 |
| 213 filterEngine->GetFilter(text)->AddToList(); | 230 filterEngine->GetFilter(text)->AddToList(); |
| 214 break; | 231 break; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 case Communication::PROC_COMPARE_VERSIONS: | 335 case Communication::PROC_COMPARE_VERSIONS: |
| 319 { | 336 { |
| 320 std::string v1, v2; | 337 std::string v1, v2; |
| 321 request >> v1 >> v2; | 338 request >> v1 >> v2; |
| 322 | 339 |
| 323 response << filterEngine->CompareVersions(v1, v2); | 340 response << filterEngine->CompareVersions(v1, v2); |
| 324 break; | 341 break; |
| 325 } | 342 } |
| 326 case Communication::PROC_GET_DOCUMENTATION_LINK: | 343 case Communication::PROC_GET_DOCUMENTATION_LINK: |
| 327 { | 344 { |
| 328 response << ToUtf16String(filterEngine->GetPref("documentation_link")->A
sString()); | 345 response << filterEngine->GetPref("documentation_link")->AsString(); |
| 329 break; | 346 break; |
| 330 } | 347 } |
| 331 case Communication::PROC_TOGGLE_PLUGIN_ENABLED: | 348 case Communication::PROC_TOGGLE_PLUGIN_ENABLED: |
| 332 { | 349 { |
| 333 filterEngine->SetPref("enabled", filterEngine->GetJsEngine()->NewValue(!
filterEngine->GetPref("enabled")->AsBool())); | 350 filterEngine->SetPref("enabled", filterEngine->GetJsEngine()->NewValue(!
filterEngine->GetPref("enabled")->AsBool())); |
| 334 response << filterEngine->GetPref("enabled")->AsBool(); | 351 response << filterEngine->GetPref("enabled")->AsBool(); |
| 335 break; | 352 break; |
| 336 } | 353 } |
| 337 case Communication::PROC_GET_HOST: | 354 case Communication::PROC_GET_HOST: |
| 338 { | 355 { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 502 } |
| 486 catch (const std::runtime_error& e) | 503 catch (const std::runtime_error& e) |
| 487 { | 504 { |
| 488 DebugException(e); | 505 DebugException(e); |
| 489 return 1; | 506 return 1; |
| 490 } | 507 } |
| 491 } | 508 } |
| 492 | 509 |
| 493 return 0; | 510 return 0; |
| 494 } | 511 } |
| LEFT | RIGHT |