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

Delta Between Two Patch Sets: src/engine/Main.cpp

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Left Patch Set: Created June 21, 2014, 8:25 p.m.
Right Patch Set: Final (?) 2 Created Jan. 5, 2015, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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"
14 #include "AdblockPlus.h"
13 #include "Debug.h" 15 #include "Debug.h"
14 #include "Updater.h" 16 #include "Updater.h"
15 17
16 namespace 18 namespace
17 { 19 {
18 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 20 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
19 std::auto_ptr<Updater> updater; 21 std::auto_ptr<Updater> updater;
20 int activeConnections = 0; 22 int activeConnections = 0;
21 CriticalSection activeConnectionsLock; 23 CriticalSection activeConnectionsLock;
22 HWND callbackWindow; 24 HWND callbackWindow;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 checkingForUpdate = false; 70 checkingForUpdate = false;
69 callbackWindow = 0; 71 callbackWindow = 0;
70 } 72 }
71 return; 73 return;
72 } 74 }
73 75
74 76
75 CriticalSection firstRunLock; 77 CriticalSection firstRunLock;
76 CriticalSection updateCheckLock; 78 CriticalSection updateCheckLock;
77 bool firstRunActionExecuted = false; 79 bool firstRunActionExecuted = false;
80 AdblockPlus::ReferrerMapping referrerMapping;
78 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) 81 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request)
79 { 82 {
80 Communication::OutputBuffer response; 83 Communication::OutputBuffer response;
81 84
82 Communication::ProcType procedure; 85 Communication::ProcType procedure;
83 request >> procedure; 86 request >> procedure;
84 switch (procedure) 87 switch (procedure)
85 { 88 {
86 case Communication::PROC_MATCHES: 89 case Communication::PROC_MATCHES:
87 { 90 {
88 std::string url; 91 std::string url;
89 std::string type; 92 std::string type;
90 std::string documentUrl; 93 std::string documentUrl;
91 request >> url >> type >> documentUrl; 94 request >> url >> type >> documentUrl;
92 AdblockPlus::FilterPtr filter = filterEngine->Matches(url, type, documen tUrl); 95 referrerMapping.Add(url, documentUrl);
96 AdblockPlus::FilterPtr filter = filterEngine->Matches(url, type, referre rMapping.BuildReferrerChain(documentUrl));
93 response << (filter && filter->GetType() != AdblockPlus::Filter::TYPE_EX CEPTION); 97 response << (filter && filter->GetType() != AdblockPlus::Filter::TYPE_EX CEPTION);
94 break; 98 break;
95 } 99 }
96 case Communication::PROC_GET_ELEMHIDE_SELECTORS: 100 case Communication::PROC_GET_ELEMHIDE_SELECTORS:
97 { 101 {
98 std::string domain; 102 std::string domain;
99 request >> domain; 103 request >> domain;
100 WriteStrings(response, filterEngine->GetElementHidingSelectors(domain)); 104 WriteStrings(response, filterEngine->GetElementHidingSelectors(domain));
101 break; 105 break;
102 } 106 }
103 case Communication::PROC_AVAILABLE_SUBSCRIPTIONS: 107 case Communication::PROC_AVAILABLE_SUBSCRIPTIONS:
104 { 108 {
105 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions() ); 109 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions() );
106 break; 110 break;
107 } 111 }
108 case Communication::PROC_LISTED_SUBSCRIPTIONS: 112 case Communication::PROC_LISTED_SUBSCRIPTIONS:
109 { 113 {
110 WriteSubscriptions(response, filterEngine->GetListedSubscriptions()); 114 WriteSubscriptions(response, filterEngine->GetListedSubscriptions());
111 break; 115 break;
112 } 116 }
113 case Communication::PROC_SET_SUBSCRIPTION: 117 case Communication::PROC_SET_SUBSCRIPTION:
114 { 118 {
115 std::string url; 119 std::string url;
116 request >> url; 120 request >> url;
117 121
122 AdblockPlus::JsValuePtr valuePtr = filterEngine->GetPref("subscriptions_ exceptionsurl");
123 std::string aaUrl = "";
124 if (!valuePtr->IsNull())
125 {
126 aaUrl = valuePtr->AsString();
127 }
118 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine-> GetListedSubscriptions(); 128 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine-> GetListedSubscriptions();
129
130 // Remove all subscriptions, besides the Acceptable Ads
119 for (size_t i = 0, count = subscriptions.size(); i < count; i++) 131 for (size_t i = 0, count = subscriptions.size(); i < count; i++)
120 subscriptions[i]->RemoveFromList(); 132 {
133 if (subscriptions[i]->GetProperty("url")->AsString() != aaUrl)
134 {
135 subscriptions[i]->RemoveFromList();
136 }
137 }
121 138
122 filterEngine->GetSubscription(url)->AddToList(); 139 filterEngine->GetSubscription(url)->AddToList();
140 break;
141 }
142 case Communication::PROC_ADD_SUBSCRIPTION:
143 {
144 std::string url;
145 request >> url;
146
147 filterEngine->GetSubscription(url)->AddToList();
148 break;
149 }
150 case Communication::PROC_REMOVE_SUBSCRIPTION:
151 {
152 std::string url;
153 request >> url;
154
155 filterEngine->GetSubscription(url)->RemoveFromList();
123 break; 156 break;
124 } 157 }
125 case Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS: 158 case Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS:
126 { 159 {
127 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine-> GetListedSubscriptions(); 160 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine-> GetListedSubscriptions();
128 for (size_t i = 0, count = subscriptions.size(); i < count; i++) 161 for (size_t i = 0, count = subscriptions.size(); i < count; i++)
129 subscriptions[i]->UpdateFilters(); 162 subscriptions[i]->UpdateFilters();
130 break; 163 break;
131 } 164 }
132 case Communication::PROC_GET_EXCEPTION_DOMAINS: 165 case Communication::PROC_GET_EXCEPTION_DOMAINS:
(...skipping 24 matching lines...) Expand all
157 break; 190 break;
158 } 191 }
159 case Communication::PROC_IS_WHITELISTED_URL: 192 case Communication::PROC_IS_WHITELISTED_URL:
160 { 193 {
161 std::string url; 194 std::string url;
162 request >> url; 195 request >> url;
163 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "DOCUMENT", ur l); 196 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "DOCUMENT", ur l);
164 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION); 197 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION);
165 break; 198 break;
166 } 199 }
200 case Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL:
201 {
202 std::string url;
203 request >> url;
204 AdblockPlus::FilterPtr match = filterEngine->Matches(url, "ELEMHIDE", ur l);
205 response << (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCE PTION);
206 break;
207 }
167 case Communication::PROC_ADD_FILTER: 208 case Communication::PROC_ADD_FILTER:
168 { 209 {
169 std::string text; 210 std::string text;
170 request >> text; 211 request >> text;
171 212
172 filterEngine->GetFilter(text)->AddToList(); 213 filterEngine->GetFilter(text)->AddToList();
173 break; 214 break;
174 } 215 }
175 case Communication::PROC_REMOVE_FILTER: 216 case Communication::PROC_REMOVE_FILTER:
176 { 217 {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 CriticalSection::Lock lock(firstRunLock); 306 CriticalSection::Lock lock(firstRunLock);
266 if (!firstRunActionExecuted && filterEngine->IsFirstRun()) 307 if (!firstRunActionExecuted && filterEngine->IsFirstRun())
267 { 308 {
268 response << true; 309 response << true;
269 firstRunActionExecuted = true; 310 firstRunActionExecuted = true;
270 } 311 }
271 else 312 else
272 { 313 {
273 response << false; 314 response << false;
274 } 315 }
316 break;
317 }
318 case Communication::PROC_COMPARE_VERSIONS:
319 {
320 std::string v1, v2;
321 request >> v1 >> v2;
322
323 response << filterEngine->CompareVersions(v1, v2);
275 break; 324 break;
276 } 325 }
277 case Communication::PROC_GET_DOCUMENTATION_LINK: 326 case Communication::PROC_GET_DOCUMENTATION_LINK:
278 { 327 {
279 response << ToUtf16String(filterEngine->GetPref("documentation_link")->A sString()); 328 response << ToUtf16String(filterEngine->GetPref("documentation_link")->A sString());
280 break; 329 break;
281 } 330 }
282 case Communication::PROC_TOGGLE_PLUGIN_ENABLED: 331 case Communication::PROC_TOGGLE_PLUGIN_ENABLED:
283 { 332 {
284 filterEngine->SetPref("enabled", filterEngine->GetJsEngine()->NewValue(! filterEngine->GetPref("enabled")->AsBool())); 333 filterEngine->SetPref("enabled", filterEngine->GetJsEngine()->NewValue(! filterEngine->GetPref("enabled")->AsBool()));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale) 416 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale)
368 { 417 {
369 AdblockPlus::AppInfo appInfo; 418 AdblockPlus::AppInfo appInfo;
370 appInfo.version = ToUtf8String(IEPLUGIN_VERSION); 419 appInfo.version = ToUtf8String(IEPLUGIN_VERSION);
371 appInfo.name = "adblockplusie"; 420 appInfo.name = "adblockplusie";
372 #ifdef _WIN64 421 #ifdef _WIN64
373 appInfo.application = "msie64"; 422 appInfo.application = "msie64";
374 #else 423 #else
375 appInfo.application = "msie32"; 424 appInfo.application = "msie32";
376 #endif 425 #endif
377 appInfo.applicationVersion = ToUtf8String( ABP::IE::installed_version_string() ); 426 appInfo.applicationVersion = ToUtf8String(AdblockPlus::IE::InstalledVersionStr ing());
378 appInfo.locale = ToUtf8String(locale); 427 appInfo.locale = ToUtf8String(locale);
379 #ifdef ADBLOCK_PLUS_TEST_MODE 428 #ifdef ADBLOCK_PLUS_TEST_MODE
380 appInfo.developmentBuild = true; 429 appInfo.developmentBuild = true;
381 #else 430 #else
382 appInfo.developmentBuild = false; 431 appInfo.developmentBuild = false;
383 #endif 432 #endif
384 433
385 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); 434 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
386 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable); 435 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable);
387 436
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 485 }
437 catch (const std::runtime_error& e) 486 catch (const std::runtime_error& e)
438 { 487 {
439 DebugException(e); 488 DebugException(e);
440 return 1; 489 return 1;
441 } 490 }
442 } 491 }
443 492
444 return 0; 493 return 0;
445 } 494 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld