Left: | ||
Right: |
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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 const FilterEngine::Prefs& preconfiguredPrefs) |
139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) | 139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) |
140 { | 140 { |
141 jsEngine->SetEventCallback("_init", std::tr1::bind(&FilterEngine::InitDone, | 141 jsEngine->SetEventCallback("_init", std::bind(&FilterEngine::InitDone, |
142 this, std::tr1::placeholders::_1)); | 142 this, std::placeholders::_1)); |
143 | 143 |
144 { | 144 { |
145 // 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 |
146 // until we are done. | 146 // until we are done. |
147 const JsContext context(jsEngine); | 147 const JsContext context(jsEngine); |
148 | 148 |
149 // Set the preconfigured prefs | 149 // Set the preconfigured prefs |
150 JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject(); | 150 JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject(); |
151 for (FilterEngine::Prefs::const_iterator it = preconfiguredPrefs.begin(); | 151 for (FilterEngine::Prefs::const_iterator it = preconfiguredPrefs.begin(); |
152 it != preconfiguredPrefs.end(); it++) | 152 it != preconfiguredPrefs.end(); it++) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 } | 278 } |
279 func->Call(params); | 279 func->Call(params); |
280 } | 280 } |
281 | 281 |
282 void FilterEngine::SetShowNotificationCallback(const ShowNotificationCallback& v alue) | 282 void FilterEngine::SetShowNotificationCallback(const ShowNotificationCallback& v alue) |
283 { | 283 { |
284 if (!value) | 284 if (!value) |
285 return; | 285 return; |
286 | 286 |
287 jsEngine->SetEventCallback("_showNotification", | 287 jsEngine->SetEventCallback("_showNotification", |
288 std::tr1::bind(&FilterEngine::ShowNotification, this, value, | 288 std::bind(&FilterEngine::ShowNotification, this, value, |
289 std::tr1::placeholders::_1)); | 289 std::placeholders::_1)); |
Felix Dahlke
2015/08/05 21:28:05
Nit: This was previously indented on column (i.e.
| |
290 } | 290 } |
291 | 291 |
292 void FilterEngine::RemoveShowNotificationCallback() | 292 void FilterEngine::RemoveShowNotificationCallback() |
293 { | 293 { |
294 jsEngine->RemoveEventCallback("_showNotification"); | 294 jsEngine->RemoveEventCallback("_showNotification"); |
295 } | 295 } |
296 | 296 |
297 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 297 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
298 ContentType contentType, | 298 ContentType contentType, |
299 const std::string& documentUrl) const | 299 const std::string& documentUrl) const |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); | 375 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); |
376 JsValueList params; | 376 JsValueList params; |
377 params.push_back(jsEngine->NewValue(url)); | 377 params.push_back(jsEngine->NewValue(url)); |
378 return func->Call(params)->AsString(); | 378 return func->Call(params)->AsString(); |
379 } | 379 } |
380 | 380 |
381 void FilterEngine::SetUpdateAvailableCallback( | 381 void FilterEngine::SetUpdateAvailableCallback( |
382 FilterEngine::UpdateAvailableCallback callback) | 382 FilterEngine::UpdateAvailableCallback callback) |
383 { | 383 { |
384 jsEngine->SetEventCallback("updateAvailable", | 384 jsEngine->SetEventCallback("updateAvailable", |
385 std::tr1::bind(&FilterEngine::UpdateAvailable, this, callback, | 385 std::bind(&FilterEngine::UpdateAvailable, this, callback, |
386 std::tr1::placeholders::_1)); | 386 std::placeholders::_1)); |
Felix Dahlke
2015/08/05 21:28:05
Nit: This was previously indented on column (i.e.
| |
387 } | 387 } |
388 | 388 |
389 void FilterEngine::RemoveUpdateAvailableCallback() | 389 void FilterEngine::RemoveUpdateAvailableCallback() |
390 { | 390 { |
391 jsEngine->RemoveEventCallback("updateAvailable"); | 391 jsEngine->RemoveEventCallback("updateAvailable"); |
392 } | 392 } |
393 | 393 |
394 void FilterEngine::UpdateAvailable( | 394 void FilterEngine::UpdateAvailable( |
395 FilterEngine::UpdateAvailableCallback callback, JsValueList& params) | 395 FilterEngine::UpdateAvailableCallback callback, JsValueList& params) |
396 { | 396 { |
397 if (params.size() >= 1 && !params[0]->IsNull()) | 397 if (params.size() >= 1 && !params[0]->IsNull()) |
398 callback(params[0]->AsString()); | 398 callback(params[0]->AsString()); |
399 } | 399 } |
400 | 400 |
401 void FilterEngine::ForceUpdateCheck( | 401 void FilterEngine::ForceUpdateCheck( |
402 FilterEngine::UpdateCheckDoneCallback callback) | 402 FilterEngine::UpdateCheckDoneCallback callback) |
403 { | 403 { |
404 std::string eventName = "_updateCheckDone"; | 404 std::string eventName = "_updateCheckDone"; |
405 eventName += ++updateCheckId; | 405 eventName += ++updateCheckId; |
406 | 406 |
407 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone, | 407 jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDone , |
408 this, eventName, callback, std::tr1::placeholders::_1)); | 408 this, eventName, callback, std::placeholders::_1)); |
409 | 409 |
410 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); | 410 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); |
411 JsValueList params; | 411 JsValueList params; |
412 params.push_back(jsEngine->NewValue(eventName)); | 412 params.push_back(jsEngine->NewValue(eventName)); |
413 func->Call(params); | 413 func->Call(params); |
414 } | 414 } |
415 | 415 |
416 void FilterEngine::UpdateCheckDone(const std::string& eventName, | 416 void FilterEngine::UpdateCheckDone(const std::string& eventName, |
417 FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params) | 417 FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params) |
418 { | 418 { |
419 jsEngine->RemoveEventCallback(eventName); | 419 jsEngine->RemoveEventCallback(eventName); |
420 | 420 |
421 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : ""); | 421 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : ""); |
422 callback(error); | 422 callback(error); |
423 } | 423 } |
424 | 424 |
425 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback) | 425 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback) |
426 { | 426 { |
427 jsEngine->SetEventCallback("filterChange", std::tr1::bind(&FilterEngine::Filte rChanged, | 427 jsEngine->SetEventCallback("filterChange", std::bind(&FilterEngine::FilterChan ged, |
428 this, callback, std::tr1::placeholders::_1)); | 428 this, callback, std::placeholders::_1)); |
429 } | 429 } |
430 | 430 |
431 void FilterEngine::RemoveFilterChangeCallback() | 431 void FilterEngine::RemoveFilterChangeCallback() |
432 { | 432 { |
433 jsEngine->RemoveEventCallback("filterChange"); | 433 jsEngine->RemoveEventCallback("filterChange"); |
434 } | 434 } |
435 | 435 |
436 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) | 436 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) |
437 { | 437 { |
438 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : ""); | 438 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : ""); |
(...skipping 12 matching lines...) Expand all Loading... | |
451 | 451 |
452 | 452 |
453 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 453 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
454 { | 454 { |
455 JsValueList params; | 455 JsValueList params; |
456 params.push_back(jsEngine->NewValue(v1)); | 456 params.push_back(jsEngine->NewValue(v1)); |
457 params.push_back(jsEngine->NewValue(v2)); | 457 params.push_back(jsEngine->NewValue(v2)); |
458 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 458 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
459 return func->Call(params)->AsInt(); | 459 return func->Call(params)->AsInt(); |
460 } | 460 } |
OLD | NEW |