LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 params.push_back(shared_from_this()); | 127 params.push_back(shared_from_this()); |
128 JsValuePtr result = func->Call(params); | 128 JsValuePtr result = func->Call(params); |
129 return result->AsBool(); | 129 return result->AsBool(); |
130 } | 130 } |
131 | 131 |
132 bool Subscription::operator==(const Subscription& subscription) const | 132 bool Subscription::operator==(const Subscription& subscription) const |
133 { | 133 { |
134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt
ring(); | 134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt
ring(); |
135 } | 135 } |
136 | 136 |
137 FilterEngine::FilterEngine(JsEnginePtr jsEngine) | 137 FilterEngine::FilterEngine(JsEnginePtr jsEngine, |
| 138 const FilterEngine::Prefs& preconfiguredPrefs) |
138 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) | 139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) |
139 { | 140 { |
140 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, | 141 jsEngine->SetEventCallback("_init", std::bind(&FilterEngine::InitDone, |
141 this, std::tr1::placeholders::_1)); | 142 this, std::placeholders::_1)); |
142 | 143 |
143 { | 144 { |
144 // Lock the JS engine while we are loading scripts, no timeouts should fire | 145 // Lock the JS engine while we are loading scripts, no timeouts should fire |
145 // until we are done. | 146 // until we are done. |
146 const JsContext context(jsEngine); | 147 const JsContext context(jsEngine); |
| 148 |
| 149 // Set the preconfigured prefs |
| 150 JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject(); |
| 151 for (FilterEngine::Prefs::const_iterator it = preconfiguredPrefs.begin(); |
| 152 it != preconfiguredPrefs.end(); it++) |
| 153 { |
| 154 preconfiguredPrefsObject->SetProperty(it->first, it->second); |
| 155 } |
| 156 jsEngine->SetGlobalProperty("_preconfiguredPrefs", preconfiguredPrefsObject)
; |
| 157 // Load adblockplus scripts |
147 for (int i = 0; !jsSources[i].empty(); i += 2) | 158 for (int i = 0; !jsSources[i].empty(); i += 2) |
148 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); | 159 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); |
149 } | 160 } |
150 | 161 |
151 // TODO: This should really be implemented via a conditional variable | 162 // TODO: This should really be implemented via a conditional variable |
152 while (!initialized) | 163 while (!initialized) |
153 ::Sleep(10); | 164 ::Sleep(10); |
154 } | 165 } |
155 | 166 |
156 namespace | 167 namespace |
157 { | 168 { |
158 typedef std::map<FilterEngine::ContentType, std::string> ContentTypeMap; | 169 typedef std::map<FilterEngine::ContentType, std::string> ContentTypeMap; |
159 | 170 |
160 ContentTypeMap CreateContentTypeMap() | 171 ContentTypeMap CreateContentTypeMap() |
161 { | 172 { |
162 ContentTypeMap contentTypes; | 173 ContentTypeMap contentTypes; |
163 contentTypes[FilterEngine::CONTENT_TYPE_OTHER] = "OTHER"; | 174 contentTypes[FilterEngine::CONTENT_TYPE_OTHER] = "OTHER"; |
164 contentTypes[FilterEngine::CONTENT_TYPE_SCRIPT] = "SCRIPT"; | 175 contentTypes[FilterEngine::CONTENT_TYPE_SCRIPT] = "SCRIPT"; |
165 contentTypes[FilterEngine::CONTENT_TYPE_IMAGE] = "IMAGE"; | 176 contentTypes[FilterEngine::CONTENT_TYPE_IMAGE] = "IMAGE"; |
166 contentTypes[FilterEngine::CONTENT_TYPE_STYLESHEET] = "STYLESHEET"; | 177 contentTypes[FilterEngine::CONTENT_TYPE_STYLESHEET] = "STYLESHEET"; |
167 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT] = "OBJECT"; | 178 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT] = "OBJECT"; |
168 contentTypes[FilterEngine::CONTENT_TYPE_SUBDOCUMENT] = "SUBDOCUMENT"; | 179 contentTypes[FilterEngine::CONTENT_TYPE_SUBDOCUMENT] = "SUBDOCUMENT"; |
169 contentTypes[FilterEngine::CONTENT_TYPE_DOCUMENT] = "DOCUMENT"; | 180 contentTypes[FilterEngine::CONTENT_TYPE_DOCUMENT] = "DOCUMENT"; |
| 181 contentTypes[FilterEngine::CONTENT_TYPE_PING] = "PING"; |
170 contentTypes[FilterEngine::CONTENT_TYPE_XMLHTTPREQUEST] = "XMLHTTPREQUEST"; | 182 contentTypes[FilterEngine::CONTENT_TYPE_XMLHTTPREQUEST] = "XMLHTTPREQUEST"; |
171 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT_SUBREQUEST] = "OBJECT_SUBREQU
EST"; | 183 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT_SUBREQUEST] = "OBJECT_SUBREQU
EST"; |
172 contentTypes[FilterEngine::CONTENT_TYPE_FONT] = "FONT"; | 184 contentTypes[FilterEngine::CONTENT_TYPE_FONT] = "FONT"; |
173 contentTypes[FilterEngine::CONTENT_TYPE_MEDIA] = "MEDIA"; | 185 contentTypes[FilterEngine::CONTENT_TYPE_MEDIA] = "MEDIA"; |
| 186 contentTypes[FilterEngine::CONTENT_TYPE_ELEMHIDE] = "ELEMHIDE"; |
| 187 contentTypes[FilterEngine::CONTENT_TYPE_GENERICBLOCK] = "GENERICBLOCK"; |
| 188 contentTypes[FilterEngine::CONTENT_TYPE_GENERICHIDE] = "GENERICHIDE"; |
174 return contentTypes; | 189 return contentTypes; |
175 } | 190 } |
176 } | 191 } |
177 | 192 |
178 const ContentTypeMap FilterEngine::contentTypes = CreateContentTypeMap(); | 193 const ContentTypeMap FilterEngine::contentTypes = CreateContentTypeMap(); |
179 | 194 |
180 std::string FilterEngine::ContentTypeToString(ContentType contentType) | 195 std::string FilterEngine::ContentTypeToString(ContentType contentType) |
181 { | 196 { |
182 ContentTypeMap::const_iterator it = contentTypes.find(contentType); | 197 ContentTypeMap::const_iterator it = contentTypes.find(contentType); |
183 if (it != contentTypes.end()) | 198 if (it != contentTypes.end()) |
184 return it->second; | 199 return it->second; |
185 throw std::invalid_argument("Argument is not a valid ContentType"); | 200 throw std::invalid_argument("Argument is not a valid ContentType"); |
186 } | 201 } |
187 | 202 |
188 FilterEngine::ContentType FilterEngine::StringToContentType(const std::string& c
ontentType) | 203 FilterEngine::ContentType FilterEngine::StringToContentType(const std::string& c
ontentType) |
189 { | 204 { |
190 std::string contentTypeUpper = contentType; | 205 std::string contentTypeUpper = contentType; |
191 std::transform(contentType.begin(), contentType.end(), contentTypeUpper.begin(
), ::toupper); | 206 std::transform(contentType.begin(), contentType.end(), contentTypeUpper.begin(
), ::toupper); |
192 for (ContentTypeMap::const_iterator it = contentTypes.begin(); | 207 for (ContentTypeMap::const_iterator it = contentTypes.begin(); |
193 it != contentTypes.end(); it++) | 208 it != contentTypes.end(); it++) |
194 { | 209 { |
195 if (it->second == contentTypeUpper) | 210 if (it->second == contentTypeUpper) |
196 return it->first; | 211 return it->first; |
197 } | 212 } |
198 throw std::invalid_argument("Cannot convert argument to ContentType"); | 213 throw std::invalid_argument("Cannot convert argument to ContentType"); |
199 } | 214 } |
200 | 215 |
201 void FilterEngine::InitDone(JsValueList& params) | 216 void FilterEngine::InitDone(JsValueList& params) |
202 { | 217 { |
203 jsEngine->RemoveEventCallback("init"); | 218 jsEngine->RemoveEventCallback("_init"); |
204 initialized = true; | 219 initialized = true; |
205 firstRun = params.size() && params[0]->AsBool(); | 220 firstRun = params.size() && params[0]->AsBool(); |
206 } | 221 } |
207 | 222 |
208 bool FilterEngine::IsFirstRun() const | 223 bool FilterEngine::IsFirstRun() const |
209 { | 224 { |
210 return firstRun; | 225 return firstRun; |
211 } | 226 } |
212 | 227 |
213 FilterPtr FilterEngine::GetFilter(const std::string& text) | 228 FilterPtr FilterEngine::GetFilter(const std::string& text) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const | 264 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const |
250 { | 265 { |
251 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); | 266 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); |
252 JsValueList values = func->Call()->AsList(); | 267 JsValueList values = func->Call()->AsList(); |
253 std::vector<SubscriptionPtr> result; | 268 std::vector<SubscriptionPtr> result; |
254 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 269 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
255 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); | 270 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); |
256 return result; | 271 return result; |
257 } | 272 } |
258 | 273 |
| 274 void FilterEngine::ShowNextNotification(const std::string& url) |
| 275 { |
| 276 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); |
| 277 JsValueList params; |
| 278 if (!url.empty()) |
| 279 { |
| 280 params.push_back(jsEngine->NewValue(url)); |
| 281 } |
| 282 func->Call(params); |
| 283 } |
| 284 |
| 285 void FilterEngine::SetShowNotificationCallback(const ShowNotificationCallback& v
alue) |
| 286 { |
| 287 if (!value) |
| 288 return; |
| 289 |
| 290 jsEngine->SetEventCallback("_showNotification", |
| 291 std::bind(&FilterEngine::ShowNotification, this, value, |
| 292 std::placeholders::_1)); |
| 293 } |
| 294 |
| 295 void FilterEngine::RemoveShowNotificationCallback() |
| 296 { |
| 297 jsEngine->RemoveEventCallback("_showNotification"); |
| 298 } |
| 299 |
259 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 300 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
260 ContentType contentType, | 301 ContentTypeMask contentTypeMask, |
261 const std::string& documentUrl) const | 302 const std::string& documentUrl) const |
262 { | 303 { |
263 std::vector<std::string> documentUrls; | 304 std::vector<std::string> documentUrls; |
264 documentUrls.push_back(documentUrl); | 305 documentUrls.push_back(documentUrl); |
265 return Matches(url, contentType, documentUrls); | 306 return Matches(url, contentTypeMask, documentUrls); |
266 } | 307 } |
267 | 308 |
268 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 309 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
269 ContentType contentType, | 310 ContentTypeMask contentTypeMask, |
270 const std::vector<std::string>& documentUrls) const | 311 const std::vector<std::string>& documentUrls) const |
271 { | 312 { |
272 if (documentUrls.empty()) | 313 if (documentUrls.empty()) |
273 return CheckFilterMatch(url, contentType, ""); | 314 return CheckFilterMatch(url, contentTypeMask, ""); |
274 | 315 |
275 std::string lastDocumentUrl = documentUrls.front(); | 316 std::string lastDocumentUrl = documentUrls.front(); |
276 for (std::vector<std::string>::const_iterator it = documentUrls.begin(); | 317 for (std::vector<std::string>::const_iterator it = documentUrls.begin(); |
277 it != documentUrls.end(); it++) { | 318 it != documentUrls.end(); it++) { |
278 const std::string documentUrl = *it; | 319 const std::string documentUrl = *it; |
279 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, | 320 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, |
280 CONTENT_TYPE_DOCUMENT, | 321 CONTENT_TYPE_DOCUMENT, |
281 lastDocumentUrl); | 322 lastDocumentUrl); |
282 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) | 323 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
283 return match; | 324 return match; |
284 lastDocumentUrl = documentUrl; | 325 lastDocumentUrl = documentUrl; |
285 } | 326 } |
286 | 327 |
287 return CheckFilterMatch(url, contentType, lastDocumentUrl); | 328 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); |
| 329 } |
| 330 |
| 331 bool FilterEngine::IsDocumentWhitelisted(const std::string& url, |
| 332 const std::vector<std::string>& documentUrls) const |
| 333 { |
| 334 return !!GetWhitelistingFilter(url, CONTENT_TYPE_DOCUMENT, documentUrls); |
| 335 } |
| 336 |
| 337 bool FilterEngine::IsElemhideWhitelisted(const std::string& url, |
| 338 const std::vector<std::string>& documentUrls) const |
| 339 { |
| 340 return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls); |
288 } | 341 } |
289 | 342 |
290 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, | 343 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, |
291 ContentType contentType, | 344 ContentTypeMask contentTypeMask, |
292 const std::string& documentUrl) const | 345 const std::string& documentUrl) const |
293 { | 346 { |
294 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); | 347 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
295 JsValueList params; | 348 JsValueList params; |
296 params.push_back(jsEngine->NewValue(url)); | 349 params.push_back(jsEngine->NewValue(url)); |
297 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); | 350 params.push_back(jsEngine->NewValue(contentTypeMask)); |
298 params.push_back(jsEngine->NewValue(documentUrl)); | 351 params.push_back(jsEngine->NewValue(documentUrl)); |
299 JsValuePtr result = func->Call(params); | 352 JsValuePtr result = func->Call(params); |
300 if (!result->IsNull()) | 353 if (!result->IsNull()) |
301 return FilterPtr(new Filter(std::move(*result))); | 354 return FilterPtr(new Filter(std::move(*result))); |
302 else | 355 else |
303 return FilterPtr(); | 356 return FilterPtr(); |
304 } | 357 } |
305 | 358 |
306 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const | 359 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const |
307 { | 360 { |
(...skipping 29 matching lines...) Expand all Loading... |
337 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); | 390 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); |
338 JsValueList params; | 391 JsValueList params; |
339 params.push_back(jsEngine->NewValue(url)); | 392 params.push_back(jsEngine->NewValue(url)); |
340 return func->Call(params)->AsString(); | 393 return func->Call(params)->AsString(); |
341 } | 394 } |
342 | 395 |
343 void FilterEngine::SetUpdateAvailableCallback( | 396 void FilterEngine::SetUpdateAvailableCallback( |
344 FilterEngine::UpdateAvailableCallback callback) | 397 FilterEngine::UpdateAvailableCallback callback) |
345 { | 398 { |
346 jsEngine->SetEventCallback("updateAvailable", | 399 jsEngine->SetEventCallback("updateAvailable", |
347 std::tr1::bind(&FilterEngine::UpdateAvailable, this, callback, | 400 std::bind(&FilterEngine::UpdateAvailable, this, callback, |
348 std::tr1::placeholders::_1)); | 401 std::placeholders::_1)); |
349 } | 402 } |
350 | 403 |
351 void FilterEngine::RemoveUpdateAvailableCallback() | 404 void FilterEngine::RemoveUpdateAvailableCallback() |
352 { | 405 { |
353 jsEngine->RemoveEventCallback("updateAvailable"); | 406 jsEngine->RemoveEventCallback("updateAvailable"); |
354 } | 407 } |
355 | 408 |
356 void FilterEngine::UpdateAvailable( | 409 void FilterEngine::UpdateAvailable( |
357 FilterEngine::UpdateAvailableCallback callback, JsValueList& params) | 410 FilterEngine::UpdateAvailableCallback callback, JsValueList& params) |
358 { | 411 { |
359 if (params.size() >= 1 && !params[0]->IsNull()) | 412 if (params.size() >= 1 && !params[0]->IsNull()) |
360 callback(params[0]->AsString()); | 413 callback(params[0]->AsString()); |
361 } | 414 } |
362 | 415 |
363 void FilterEngine::ForceUpdateCheck( | 416 void FilterEngine::ForceUpdateCheck( |
364 FilterEngine::UpdateCheckDoneCallback callback) | 417 FilterEngine::UpdateCheckDoneCallback callback) |
365 { | 418 { |
366 std::string eventName = "updateCheckDone"; | 419 std::string eventName = "_updateCheckDone"; |
367 eventName += ++updateCheckId; | 420 eventName += ++updateCheckId; |
368 | 421 |
369 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec
kDone, | 422 jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDone
, |
370 this, eventName, callback, std::tr1::placeholders::_1)); | 423 this, eventName, callback, std::placeholders::_1)); |
371 | 424 |
372 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); | 425 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); |
373 JsValueList params; | 426 JsValueList params; |
374 params.push_back(jsEngine->NewValue(eventName)); | 427 params.push_back(jsEngine->NewValue(eventName)); |
375 func->Call(params); | 428 func->Call(params); |
376 } | 429 } |
377 | 430 |
378 void FilterEngine::UpdateCheckDone(const std::string& eventName, | 431 void FilterEngine::UpdateCheckDone(const std::string& eventName, |
379 FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params) | 432 FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params) |
380 { | 433 { |
381 jsEngine->RemoveEventCallback(eventName); | 434 jsEngine->RemoveEventCallback(eventName); |
382 | 435 |
383 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt
ring() : ""); | 436 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt
ring() : ""); |
384 callback(error); | 437 callback(error); |
385 } | 438 } |
386 | 439 |
387 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca
llback) | 440 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca
llback) |
388 { | 441 { |
389 jsEngine->SetEventCallback("filterChange", std::tr1::bind(&FilterEngine::Filte
rChanged, | 442 jsEngine->SetEventCallback("filterChange", std::bind(&FilterEngine::FilterChan
ged, |
390 this, callback, std::tr1::placeholders::_1)); | 443 this, callback, std::placeholders::_1)); |
391 } | 444 } |
392 | 445 |
393 void FilterEngine::RemoveFilterChangeCallback() | 446 void FilterEngine::RemoveFilterChangeCallback() |
394 { | 447 { |
395 jsEngine->RemoveEventCallback("filterChange"); | 448 jsEngine->RemoveEventCallback("filterChange"); |
396 } | 449 } |
397 | 450 |
398 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js
ValueList& params) | 451 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js
ValueList& params) |
399 { | 452 { |
400 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS
tring() : ""); | 453 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS
tring() : ""); |
401 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); | 454 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); |
402 callback(action, item); | 455 callback(action, item); |
403 } | 456 } |
| 457 |
| 458 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback, |
| 459 const JsValueList& params) |
| 460 { |
| 461 if (params.size() < 1) |
| 462 return; |
| 463 |
| 464 if (!params[0]->IsObject()) |
| 465 { |
| 466 return; |
| 467 } |
| 468 callback(NotificationPtr(new Notification(std::move(*params[0])))); |
| 469 } |
| 470 |
404 | 471 |
405 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 472 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
406 { | 473 { |
407 JsValueList params; | 474 JsValueList params; |
408 params.push_back(jsEngine->NewValue(v1)); | 475 params.push_back(jsEngine->NewValue(v1)); |
409 params.push_back(jsEngine->NewValue(v2)); | 476 params.push_back(jsEngine->NewValue(v2)); |
410 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 477 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
411 return func->Call(params)->AsInt(); | 478 return func->Call(params)->AsInt(); |
412 } | 479 } |
| 480 |
| 481 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, |
| 482 ContentTypeMask contentTypeMask, const std::string& documentUrl) const |
| 483 { |
| 484 FilterPtr match = Matches(url, contentTypeMask, documentUrl); |
| 485 if (match && match->GetType() == Filter::TYPE_EXCEPTION) |
| 486 { |
| 487 return match; |
| 488 } |
| 489 return FilterPtr(); |
| 490 } |
| 491 |
| 492 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, |
| 493 ContentTypeMask contentTypeMask, |
| 494 const std::vector<std::string>& documentUrls) const |
| 495 { |
| 496 if (documentUrls.empty()) |
| 497 { |
| 498 return GetWhitelistingFilter(url, contentTypeMask, ""); |
| 499 } |
| 500 |
| 501 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin(); |
| 502 std::string currentUrl = url; |
| 503 do |
| 504 { |
| 505 std::string parentUrl = *urlIterator++; |
| 506 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); |
| 507 if (filter) |
| 508 { |
| 509 return filter; |
| 510 } |
| 511 currentUrl = parentUrl; |
| 512 } |
| 513 while (urlIterator != documentUrls.end()); |
| 514 return FilterPtr(); |
| 515 } |
LEFT | RIGHT |