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

Delta Between Two Patch Sets: src/plugin/PluginFilter.cpp

Issue 5516878722105344: Issue #276 - replace TCHAR etc. with wide-character versions (Closed)
Left Patch Set: Created July 26, 2014, 2:20 p.m.
Right Patch Set: Created Aug. 5, 2014, 3:17 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
« no previous file with change/comment | « src/plugin/PluginClass.cpp ('k') | src/plugin/PluginSystem.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginFilter.h" 3 #include "PluginFilter.h"
4 4
5 #include "COM_Value.h"
6 #if (defined PRODUCT_ADBLOCKPLUS) 5 #if (defined PRODUCT_ADBLOCKPLUS)
7 #include "PluginSettings.h" 6 #include "PluginSettings.h"
8 #include "PluginClient.h" 7 #include "PluginClient.h"
9 #include "PluginClientFactory.h" 8 #include "PluginClientFactory.h"
10 #endif 9 #endif
11 10
12 #include "PluginMutex.h" 11 #include "PluginMutex.h"
13 #include "PluginSettings.h" 12 #include "PluginSettings.h"
14 #include "PluginSystem.h" 13 #include "PluginSystem.h"
15 #include "PluginClass.h" 14 #include "PluginClass.h"
16 #include "mlang.h" 15 #include "mlang.h"
17 16
18 #include "..\shared\CriticalSection.h" 17 #include "..\shared\CriticalSection.h"
19 18
19
20 // The filters are described at http://adblockplus.org/en/filters 20 // The filters are described at http://adblockplus.org/en/filters
21 21
22 static CriticalSection s_criticalSectionFilterMap; 22 static CriticalSection s_criticalSectionFilterMap;
23 23
24 // ============================================================================ 24 // ============================================================================
25 // CFilterElementHideAttrSelector 25 // CFilterElementHideAttrSelector
26 // ============================================================================ 26 // ============================================================================
27 27
28 CFilterElementHideAttrSelector::CFilterElementHideAttrSelector() : m_type(TYPE_N ONE), m_pos(POS_NONE), m_attr(L"") 28 CFilterElementHideAttrSelector::CFilterElementHideAttrSelector() : m_type(TYPE_N ONE), m_pos(POS_NONE), m_bstrAttr(NULL)
29 { 29 {
30 } 30 }
31 31
32 CFilterElementHideAttrSelector::CFilterElementHideAttrSelector(const CFilterElem entHideAttrSelector& filter) 32 CFilterElementHideAttrSelector::CFilterElementHideAttrSelector(const CFilterElem entHideAttrSelector& filter)
33 { 33 {
34 m_type = filter.m_type; 34 m_type = filter.m_type;
35 m_pos = filter.m_pos; 35 m_pos = filter.m_pos;
36 m_attr = filter.m_attr; 36 m_bstrAttr = filter.m_bstrAttr;
37 37
38 m_value = filter.m_value; 38 m_value = filter.m_value;
39 } 39 }
40 40
41 CFilterElementHideAttrSelector::~CFilterElementHideAttrSelector() 41 CFilterElementHideAttrSelector::~CFilterElementHideAttrSelector()
42 { 42 {
43 } 43 }
44 44
45 45
46 // ============================================================================ 46 // ============================================================================
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (delimiterPos > 0) 143 if (delimiterPos > 0)
144 { 144 {
145 attrSelector.m_value = arg.Mid(delimiterPos + 1); 145 attrSelector.m_value = arg.Mid(delimiterPos + 1);
146 if (attrSelector.m_value.GetLength() >= 2 && attrSelector.m_value.GetAt(0) == '\"' && attrSelector.m_value.GetAt(attrSelector.m_value.GetLength() - 1) == '\"') 146 if (attrSelector.m_value.GetLength() >= 2 && attrSelector.m_value.GetAt(0) == '\"' && attrSelector.m_value.GetAt(attrSelector.m_value.GetLength() - 1) == '\"')
147 { 147 {
148 attrSelector.m_value = attrSelector.m_value.Mid(1, attrSelector.m_value. GetLength() - 2); 148 attrSelector.m_value = attrSelector.m_value.Mid(1, attrSelector.m_value. GetLength() - 2);
149 } 149 }
150 150
151 if (arg.GetAt(delimiterPos - 1) == '^') 151 if (arg.GetAt(delimiterPos - 1) == '^')
152 { 152 {
153 attrSelector.m_attr = arg.Left(delimiterPos - 1); 153 attrSelector.m_bstrAttr = arg.Left(delimiterPos - 1);
154 attrSelector.m_pos = CFilterElementHideAttrPos::STARTING; 154 attrSelector.m_pos = CFilterElementHideAttrPos::STARTING;
155 } 155 }
156 else if (arg.GetAt(delimiterPos - 1) == '*') 156 else if (arg.GetAt(delimiterPos - 1) == '*')
157 { 157 {
158 attrSelector.m_attr = arg.Left(delimiterPos - 1); 158 attrSelector.m_bstrAttr = arg.Left(delimiterPos - 1);
159 attrSelector.m_pos = CFilterElementHideAttrPos::ANYWHERE; 159 attrSelector.m_pos = CFilterElementHideAttrPos::ANYWHERE;
160 } 160 }
161 else if (arg.GetAt(delimiterPos - 1) == '$') 161 else if (arg.GetAt(delimiterPos - 1) == '$')
162 { 162 {
163 attrSelector.m_attr = arg.Left(delimiterPos - 1); 163 attrSelector.m_bstrAttr = arg.Left(delimiterPos - 1);
164 attrSelector.m_pos = CFilterElementHideAttrPos::ENDING; 164 attrSelector.m_pos = CFilterElementHideAttrPos::ENDING;
165 } 165 }
166 else 166 else
167 { 167 {
168 attrSelector.m_attr = arg.Left(delimiterPos); 168 attrSelector.m_bstrAttr = arg.Left(delimiterPos);
169 attrSelector.m_pos = CFilterElementHideAttrPos::EXACT; 169 attrSelector.m_pos = CFilterElementHideAttrPos::EXACT;
170 } 170 }
171 } 171 }
172 CString tag = attrSelector.m_attr; 172 CString tag = attrSelector.m_bstrAttr;
173 if (tag == "style") 173 if (tag == "style")
174 { 174 {
175 attrSelector.m_type = CFilterElementHideAttrType::STYLE; 175 attrSelector.m_type = CFilterElementHideAttrType::STYLE;
176 attrSelector.m_value.MakeLower(); 176 attrSelector.m_value.MakeLower();
177 } 177 }
178 else if (tag == "id") 178 else if (tag == "id")
179 { 179 {
180 attrSelector.m_type = CFilterElementHideAttrType::ID; 180 attrSelector.m_type = CFilterElementHideAttrType::ID;
181 } 181 }
182 else if (tag == "class") 182 else if (tag == "class")
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 { 235 {
236 } 236 }
237 237
238 238
239 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const 239 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const
240 { 240 {
241 HRESULT hr; 241 HRESULT hr;
242 242
243 if (!m_tagId.IsEmpty()) 243 if (!m_tagId.IsEmpty())
244 { 244 {
245 AdblockPlus::COM::BSTR_Argument id; 245 CComBSTR id;
246 hr = pEl->get_id(&id); 246 hr = pEl->get_id(&id);
247 if ((hr != S_OK) || (to_CString(id) != m_tagId)) 247 if ((hr != S_OK) || (id != CComBSTR(m_tagId)))
248 { 248 {
249 return false; 249 return false;
250 } 250 }
251 } 251 }
252 if (!m_tagClassName.IsEmpty()) 252 if (!m_tagClassName.IsEmpty())
253 { 253 {
254 AdblockPlus::COM::BSTR_Argument result; 254 CComBSTR classNameBSTR;
255 hr = pEl->get_className(&result); 255 hr = pEl->get_className(&classNameBSTR);
256 if (hr == S_OK) 256 if (hr == S_OK)
257 { 257 {
258 CString className = to_CString(result); 258 CString className = classNameBSTR;
259 int start = 0; 259 int start = 0;
260 CString specificClass; 260 CString specificClass;
261 bool foundMatch = false; 261 bool foundMatch = false;
262 while ((specificClass = className.Tokenize(L" ", start)) != L"") 262 while ((specificClass = className.Tokenize(L" ", start)) != L"")
263 { 263 {
264 // TODO: Consider case of multiple classes. (m_tagClassName can be somet hing like "foo.bar") 264 // TODO: Consider case of multiple classes. (m_tagClassName can be somet hing like "foo.bar")
265 if (specificClass == m_tagClassName) 265 if (specificClass == m_tagClassName)
266 { 266 {
267 foundMatch = true; 267 foundMatch = true;
268 } 268 }
269 } 269 }
270 if (!foundMatch) 270 if (!foundMatch)
271 { 271 {
272 return false; 272 return false;
273 } 273 }
274 } 274 }
275 } 275 }
276 if (!m_tag.IsEmpty()) 276 if (!m_tag.IsEmpty())
277 { 277 {
278 AdblockPlus::COM::BSTR_Argument result; 278 CComBSTR tagName;
279 hr = pEl->get_tagName(&result); 279 tagName.ToLower();
280 CString tagName = to_CString(result); 280 hr = pEl->get_tagName(&tagName);
281 tagName.MakeLower(); 281 if ((hr != S_OK) || (tagName != CComBSTR(m_tag)))
282 if ((hr != S_OK) || tagName != m_tag)
283 { 282 {
284 return false; 283 return false;
285 } 284 }
286 } 285 }
287 286
288 // Check attributes 287 // Check attributes
289 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin(); 288 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin();
290 attrIt != m_attributeSelectors.end(); ++ attrIt) 289 attrIt != m_attributeSelectors.end(); ++ attrIt)
291 { 290 {
292 CString value; 291 CString value;
293 bool attrFound = false; 292 bool attrFound = false;
294 if (attrIt->m_type == CFilterElementHideAttrType::STYLE) 293 if (attrIt->m_type == CFilterElementHideAttrType::STYLE)
295 { 294 {
296 CComPtr<IHTMLStyle> pStyle; 295 CComPtr<IHTMLStyle> pStyle;
297 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) 296 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
298 { 297 {
299 AdblockPlus::COM::BSTR_Argument cssText; 298 CComBSTR bstrStyle;
300 if (SUCCEEDED(pStyle->get_cssText(&cssText))) 299
301 { 300 if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle)
302 value = to_CString(cssText); 301 {
303 if (!value.IsEmpty()) 302 value = bstrStyle;
304 { 303 value.MakeLower();
305 value.MakeLower(); 304 attrFound = true;
306 attrFound = true;
307 }
308 } 305 }
309 } 306 }
310 } 307 }
311 else if (attrIt->m_type == CFilterElementHideAttrType::CLASS) 308 else if (attrIt->m_type == CFilterElementHideAttrType::CLASS)
312 { 309 {
313 AdblockPlus::COM::BSTR_Argument classNames; 310 CComBSTR bstrClassNames;
314 if (SUCCEEDED(pEl->get_className(&classNames))) 311 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames)
315 { 312 {
316 value = to_CString(classNames); 313 value = bstrClassNames;
317 if (!value.IsEmpty()) 314 attrFound = true;
318 {
319 attrFound = true;
320 }
321 } 315 }
322 } 316 }
323 else if (attrIt->m_type == CFilterElementHideAttrType::ID) 317 else if (attrIt->m_type == CFilterElementHideAttrType::ID)
324 { 318 {
325 AdblockPlus::COM::BSTR_Argument id; 319 CComBSTR bstrId;
326 if (SUCCEEDED(pEl->get_id(&id))) 320 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
327 { 321 {
328 value = to_CString(id); 322 value = bstrId;
329 if (!value.IsEmpty()) 323 attrFound = true;
330 {
331 attrFound = true;
332 }
333 } 324 }
334 } 325 }
335 else 326 else
336 { 327 {
337 CComVariant vAttr; 328 CComVariant vAttr;
338 AdblockPlus::COM::BSTR_Argument attribute_name(to_wstring(attrIt->m_attr)) ; 329 if (SUCCEEDED(pEl->getAttribute(attrIt->m_bstrAttr, 0, &vAttr)))
339 if (SUCCEEDED(pEl->getAttribute(attribute_name, 0, &vAttr)))
340 { 330 {
341 attrFound = true; 331 attrFound = true;
342 if (vAttr.vt == VT_BSTR) 332 if (vAttr.vt == VT_BSTR)
343 { 333 {
344 value = vAttr.bstrVal; 334 value = vAttr.bstrVal;
345 } 335 }
346 else if (vAttr.vt == VT_I4) 336 else if (vAttr.vt == VT_I4)
347 { 337 {
348 value.Format(L"%u", vAttr.iVal); 338 value.Format(L"%u", vAttr.iVal);
349 } 339 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 500 }
511 } while (separatorChar != '\0'); 501 } while (separatorChar != '\0');
512 } 502 }
513 503
514 return true; 504 return true;
515 } 505 }
516 506
517 bool CPluginFilter::IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& domain, const CString& indent) const 507 bool CPluginFilter::IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& domain, const CString& indent) const
518 { 508 {
519 CString id; 509 CString id;
520 AdblockPlus::COM::BSTR_Argument result; 510 CComBSTR bstrId;
521 if (SUCCEEDED(pEl->get_id(&result))) 511 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
522 { 512 {
523 id = to_CString(result); 513 id = bstrId;
524 } 514 }
525 515
526 CString classNames; 516 CString classNames;
527 // reuse of 'result' is not an error, since address-of operator permits it 517 CComBSTR bstrClassNames;
528 if (SUCCEEDED(pEl->get_className(&result))) 518 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames)
529 { 519 {
530 classNames = to_CString(result); 520 classNames = bstrClassNames;
531 } 521 }
532 522
533 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); 523 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
534 { 524 {
535 CString domainTest = domain; 525 CString domainTest = domain;
536 526
537 // Search tag/id filters 527 // Search tag/id filters
538 if (!id.IsEmpty()) 528 if (!id.IsEmpty())
539 { 529 {
540 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum = 530 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum =
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") 710 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES")
721 711
722 #ifdef ENABLE_DEBUG_RESULT 712 #ifdef ENABLE_DEBUG_RESULT
723 CPluginDebug::DebugResultBlocking(type, src, domain); 713 CPluginDebug::DebugResultBlocking(type, src, domain);
724 #endif 714 #endif
725 } 715 }
726 return true; 716 return true;
727 } 717 }
728 return false; 718 return false;
729 } 719 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld