Left: | ||
Right: |
OLD | NEW |
---|---|
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 Loading... | |
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, documentUrls.back()); | |
Wladimir Palant
2013/11/04 07:17:28
Nit: use lastDocumentUrl instead of documentUrls.b
Felix Dahlke
2013/11/15 08:18:19
Done.
| |
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(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 { | 318 { |
289 jsEngine->RemoveEventCallback("filterChange"); | 319 jsEngine->RemoveEventCallback("filterChange"); |
290 } | 320 } |
291 | 321 |
292 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) | 322 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) |
293 { | 323 { |
294 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() : ""); |
295 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); | 325 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); |
296 callback(action, item); | 326 callback(action, item); |
297 } | 327 } |
OLD | NEW |