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

Side by Side Diff: src/plugin/AdblockPlusClient.cpp

Issue 10955040: Fix domain whitelisting and remove unused code (Closed)
Patch Set: Addressed all issues Created June 25, 2013, 2:19 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginSettings.h" 3 #include "PluginSettings.h"
4 #include "PluginSystem.h" 4 #include "PluginSystem.h"
5 #include "PluginFilter.h" 5 #include "PluginFilter.h"
6 #include "PluginClientFactory.h" 6 #include "PluginClientFactory.h"
7 #include "PluginHttpRequest.h" 7 #include "PluginHttpRequest.h"
8 #include "PluginMutex.h" 8 #include "PluginMutex.h"
9 #include "PluginClass.h" 9 #include "PluginClass.h"
10 10
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 std::vector<SubscriptionDescription> result; 89 std::vector<SubscriptionDescription> result;
90 for (int32_t i = 0; i < count; i++) 90 for (int32_t i = 0; i < count; i++)
91 { 91 {
92 SubscriptionDescription description; 92 SubscriptionDescription description;
93 message >> description.url >> description.title 93 message >> description.url >> description.title
94 >> description.specialization >> description.listed; 94 >> description.specialization >> description.listed;
95 result.push_back(description); 95 result.push_back(description);
96 } 96 }
97 return result; 97 return result;
98 } 98 }
99
100 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::Outpu tBuffer& message)
101 {
102 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe();
103 pipe->WriteMessage(message);
104 return pipe->ReadMessage();
105 }
106
107 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::ProcT ype proc)
108 {
109 Communication::OutputBuffer message;
110 message << proc;
111 return CallAdblockPlusEngineProcedure(message);
112 }
99 } 113 }
100 114
101 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; 115 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL;
102 116
103 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() 117 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase()
104 { 118 {
105 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); 119 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
106 } 120 }
107 121
108 CAdblockPlusClient::~CAdblockPlusClient() 122 CAdblockPlusClient::~CAdblockPlusClient()
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 { 194 {
181 bool isHidden; 195 bool isHidden;
182 m_criticalSectionFilter.Lock(); 196 m_criticalSectionFilter.Lock();
183 { 197 {
184 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); 198 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent);
185 } 199 }
186 m_criticalSectionFilter.Unlock(); 200 m_criticalSectionFilter.Unlock();
187 return isHidden; 201 return isHidden;
188 } 202 }
189 203
190 bool CAdblockPlusClient::IsUrlWhiteListed(const CString& url) 204 bool CAdblockPlusClient::IsWhitelistedUrl(const std::string& url)
Wladimir Palant 2013/06/25 18:03:58 I would actually expect to see std::wstring here -
Felix Dahlke 2013/06/26 09:32:55 Yes, that seems to make more sense, since the plug
Wladimir Palant 2013/06/27 05:55:02 Yes, the other methods seem wrong as well. I'm fin
191 { 205 {
192 bool isWhitelisted = CPluginClientBase::IsUrlWhiteListed(url); 206 Communication::OutputBuffer request;
193 if (isWhitelisted == false && !url.IsEmpty()) 207 request << Communication::PROC_IS_WHITELISTED_URL << url;
208
209 try
194 { 210 {
195 m_criticalSectionFilter.Lock(); 211 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
196 { 212
197 isWhitelisted = m_filter.get() && m_filter->ShouldWhiteList(url); 213 bool isWhitelisted;
198 } 214 response >> isWhitelisted;
199 m_criticalSectionFilter.Unlock(); 215 return isWhitelisted;
200 } 216 }
201 217 catch (const std::exception& e)
202 return isWhitelisted; 218 {
219 DEBUG_GENERAL(e.what());
220 return false;
221 }
203 } 222 }
204 223
205 int CAdblockPlusClient::GetIEVersion() 224 int CAdblockPlusClient::GetIEVersion()
206 { 225 {
207 //HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer 226 //HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer
208 HKEY hKey; 227 HKEY hKey;
209 LSTATUS status = RegOpenKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Interne t Explorer", &hKey); 228 LSTATUS status = RegOpenKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Interne t Explorer", &hKey);
210 if (status != 0) 229 if (status != 0)
211 { 230 {
212 return 0; 231 return 0;
213 } 232 }
214 DWORD type, cbData; 233 DWORD type, cbData;
215 BYTE version[50]; 234 BYTE version[50];
216 cbData = 50; 235 cbData = 50;
217 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a); 236 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a);
218 if (status != 0) 237 if (status != 0)
219 { 238 {
220 return 0; 239 return 0;
221 } 240 }
222 RegCloseKey(hKey); 241 RegCloseKey(hKey);
223 return (int)(version[0] - 48); 242 return (int)(version[0] - 48);
224 } 243 }
225 244
226 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::OutputB uffer& message)
227 {
228 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe();
229 pipe->WriteMessage(message);
230 return pipe->ReadMessage();
231 }
232
233 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::ProcTyp e proc)
234 {
235 Communication::OutputBuffer message;
236 message << proc;
237 return CallAdblockPlusEngineProcedure(message);
238 }
239
240 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont entType, const std::string& domain) 245 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont entType, const std::string& domain)
241 { 246 {
242 Communication::OutputBuffer request; 247 Communication::OutputBuffer request;
243 request << Communication::PROC_MATCHES << url << contentType << domain; 248 request << Communication::PROC_MATCHES << url << contentType << domain;
244 249
245 try 250 try
246 { 251 {
247 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request ); 252 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
248 253
249 bool match; 254 bool match;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 370
366 try 371 try
367 { 372 {
368 CallAdblockPlusEngineProcedure(request); 373 CallAdblockPlusEngineProcedure(request);
369 } 374 }
370 catch (const std::exception& e) 375 catch (const std::exception& e)
371 { 376 {
372 DEBUG_GENERAL(e.what()); 377 DEBUG_GENERAL(e.what());
373 } 378 }
374 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld