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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 23127017: Consider the frame structure in Matches() (Closed)
Left Patch Set: Created Oct. 29, 2013, 3:13 p.m.
Right Patch Set: Better test coverage Created Nov. 15, 2013, 8:15 a.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 | « include/AdblockPlus/FilterEngine.h ('k') | test/FilterEngine.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 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 std::vector<SubscriptionPtr> result; 208 std::vector<SubscriptionPtr> result;
209 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 209 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
210 result.push_back(SubscriptionPtr(new Subscription(*it))); 210 result.push_back(SubscriptionPtr(new Subscription(*it)));
211 return result; 211 return result;
212 } 212 }
213 213
214 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 214 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
215 const std::string& contentType, 215 const std::string& contentType,
216 const std::string& documentUrl) const 216 const std::string& documentUrl) const
217 { 217 {
218 std::vector<std::string> documentUrls;
219 documentUrls.push_back(documentUrl);
220 return Matches(url, contentType, documentUrls);
221 }
222
223 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
224 const std::string& contentType,
225 const std::vector<std::string>& documentUrls) const
226 {
227 if (documentUrls.empty())
228 return CheckFilterMatch(url, contentType, "");
229
230 std::string lastDocumentUrl = documentUrls.front();
231 for (std::vector<std::string>::const_iterator it = documentUrls.begin();
232 it != documentUrls.end(); it++) {
233 const std::string documentUrl = *it;
234 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, "DOCUMENT",
235 lastDocumentUrl);
236 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
237 return match;
238 lastDocumentUrl = documentUrl;
239 }
240
241 return CheckFilterMatch(url, contentType, lastDocumentUrl);
242 }
243
244 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url,
245 const std::string& contentType,
246 const std::string& documentUrl) const
247 {
218 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); 248 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch");
219 JsValueList params; 249 JsValueList params;
220 params.push_back(jsEngine->NewValue(url)); 250 params.push_back(jsEngine->NewValue(url));
221 params.push_back(jsEngine->NewValue(contentType)); 251 params.push_back(jsEngine->NewValue(contentType));
222 params.push_back(jsEngine->NewValue(documentUrl)); 252 params.push_back(jsEngine->NewValue(documentUrl));
223 JsValuePtr result = func->Call(params); 253 JsValuePtr result = func->Call(params);
224 if (!result->IsNull()) 254 if (!result->IsNull())
225 return FilterPtr(new Filter(result)); 255 return FilterPtr(new Filter(result));
226 else 256 else
227 return FilterPtr(); 257 return FilterPtr();
228 } 258 }
229 259
230 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
231 const std::string& contentType,
232 const std::vector<std::string>& documentUrls) const
233 {
234 AdblockPlus::FilterPtr match;
235 for (std::vector<std::string>::const_iterator it = documentUrls.begin();
236 it != documentUrls.end(); it++) {
237 match = Matches(url, contentType, *it);
238 if (!match || match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
239 return match;
240 }
Wladimir Palant 2013/10/30 07:39:56 No, this approach is wrong - and it seems that we
Felix Dahlke 2013/11/03 03:51:15 I was actually wondering about this after seeing p
241 return match;
242 }
243
244 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const 260 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const
245 { 261 {
246 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 262 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
247 JsValueList params; 263 JsValueList params;
248 params.push_back(jsEngine->NewValue(domain)); 264 params.push_back(jsEngine->NewValue(domain));
249 JsValueList result = func->Call(params)->AsList(); 265 JsValueList result = func->Call(params)->AsList();
250 std::vector<std::string> selectors; 266 std::vector<std::string> selectors;
251 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) 267 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it)
252 selectors.push_back((*it)->AsString()); 268 selectors.push_back((*it)->AsString());
253 return selectors; 269 return selectors;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 { 318 {
303 jsEngine->RemoveEventCallback("filterChange"); 319 jsEngine->RemoveEventCallback("filterChange");
304 } 320 }
305 321
306 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) 322 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params)
307 { 323 {
308 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : ""); 324 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : "");
309 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); 325 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
310 callback(action, item); 326 callback(action, item);
311 } 327 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld