OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 onCreated(filterEngine); | 245 onCreated(filterEngine); |
246 jsEngine->RemoveEventCallback("_init"); | 246 jsEngine->RemoveEventCallback("_init"); |
247 }); | 247 }); |
248 | 248 |
249 // Lock the JS engine while we are loading scripts, no timeouts should fire | 249 // Lock the JS engine while we are loading scripts, no timeouts should fire |
250 // until we are done. | 250 // until we are done. |
251 const JsContext context(*jsEngine); | 251 const JsContext context(*jsEngine); |
252 | 252 |
253 // Set the preconfigured prefs | 253 // Set the preconfigured prefs |
254 auto preconfiguredPrefsObject = jsEngine->NewObject(); | 254 auto preconfiguredPrefsObject = jsEngine->NewObject(); |
255 for (FilterEngine::Prefs::const_iterator it = params.preconfiguredPrefs.begin(
); | 255 for (const auto& pref : params.preconfiguredPrefs) |
256 it != params.preconfiguredPrefs.end(); it++) | |
257 { | 256 { |
258 preconfiguredPrefsObject.SetProperty(it->first, it->second); | 257 preconfiguredPrefsObject.SetProperty(pref.first, pref.second); |
259 } | 258 } |
260 jsEngine->SetGlobalProperty("_preconfiguredPrefs", preconfiguredPrefsObject); | 259 jsEngine->SetGlobalProperty("_preconfiguredPrefs", preconfiguredPrefsObject); |
261 // Load adblockplus scripts | 260 // Load adblockplus scripts |
262 for (int i = 0; !jsSources[i].empty(); i += 2) | 261 for (int i = 0; !jsSources[i].empty(); i += 2) |
263 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); | 262 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); |
264 } | 263 } |
265 | 264 |
266 FilterEnginePtr FilterEngine::Create(const JsEnginePtr& jsEngine, | 265 FilterEnginePtr FilterEngine::Create(const JsEnginePtr& jsEngine, |
267 const FilterEngine::CreationParameters& params) | 266 const FilterEngine::CreationParameters& params) |
268 { | 267 { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 { | 339 { |
341 JsValue func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); | 340 JsValue func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); |
342 return Subscription(func.Call(jsEngine->NewValue(url))); | 341 return Subscription(func.Call(jsEngine->NewValue(url))); |
343 } | 342 } |
344 | 343 |
345 std::vector<Filter> FilterEngine::GetListedFilters() const | 344 std::vector<Filter> FilterEngine::GetListedFilters() const |
346 { | 345 { |
347 JsValue func = jsEngine->Evaluate("API.getListedFilters"); | 346 JsValue func = jsEngine->Evaluate("API.getListedFilters"); |
348 JsValueList values = func.Call().AsList(); | 347 JsValueList values = func.Call().AsList(); |
349 std::vector<Filter> result; | 348 std::vector<Filter> result; |
350 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 349 for (auto& value : values) |
351 result.push_back(Filter(std::move(*it))); | 350 result.push_back(Filter(std::move(value))); |
352 return result; | 351 return result; |
353 } | 352 } |
354 | 353 |
355 std::vector<Subscription> FilterEngine::GetListedSubscriptions() const | 354 std::vector<Subscription> FilterEngine::GetListedSubscriptions() const |
356 { | 355 { |
357 JsValue func = jsEngine->Evaluate("API.getListedSubscriptions"); | 356 JsValue func = jsEngine->Evaluate("API.getListedSubscriptions"); |
358 JsValueList values = func.Call().AsList(); | 357 JsValueList values = func.Call().AsList(); |
359 std::vector<Subscription> result; | 358 std::vector<Subscription> result; |
360 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 359 for (auto& value : values) |
361 result.push_back(Subscription(std::move(*it))); | 360 result.push_back(Subscription(std::move(value))); |
362 return result; | 361 return result; |
363 } | 362 } |
364 | 363 |
365 std::vector<Subscription> FilterEngine::FetchAvailableSubscriptions() const | 364 std::vector<Subscription> FilterEngine::FetchAvailableSubscriptions() const |
366 { | 365 { |
367 JsValue func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); | 366 JsValue func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); |
368 JsValueList values = func.Call().AsList(); | 367 JsValueList values = func.Call().AsList(); |
369 std::vector<Subscription> result; | 368 std::vector<Subscription> result; |
370 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 369 for (auto& value : values) |
371 result.push_back(Subscription(std::move(*it))); | 370 result.push_back(Subscription(std::move(value))); |
372 return result; | 371 return result; |
373 } | 372 } |
374 | 373 |
375 void FilterEngine::SetAAEnabled(bool enabled) | 374 void FilterEngine::SetAAEnabled(bool enabled) |
376 { | 375 { |
377 jsEngine->Evaluate("API.setAASubscriptionEnabled").Call(jsEngine->NewValue(ena
bled)); | 376 jsEngine->Evaluate("API.setAASubscriptionEnabled").Call(jsEngine->NewValue(ena
bled)); |
378 } | 377 } |
379 | 378 |
380 bool FilterEngine::IsAAEnabled() const | 379 bool FilterEngine::IsAAEnabled() const |
381 { | 380 { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); | 608 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); |
610 if (filter) | 609 if (filter) |
611 { | 610 { |
612 return filter; | 611 return filter; |
613 } | 612 } |
614 currentUrl = parentUrl; | 613 currentUrl = parentUrl; |
615 } | 614 } |
616 while (urlIterator != documentUrls.end()); | 615 while (urlIterator != documentUrls.end()); |
617 return FilterPtr(); | 616 return FilterPtr(); |
618 } | 617 } |
OLD | NEW |