| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const | 261 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const |
| 262 { | 262 { |
| 263 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); | 263 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); |
| 264 JsValueList values = func->Call()->AsList(); | 264 JsValueList values = func->Call()->AsList(); |
| 265 std::vector<SubscriptionPtr> result; | 265 std::vector<SubscriptionPtr> result; |
| 266 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 266 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
| 267 result.push_back(SubscriptionPtr(new Subscription(*it))); | 267 result.push_back(SubscriptionPtr(new Subscription(*it))); |
| 268 return result; | 268 return result; |
| 269 } | 269 } |
| 270 | 270 |
| 271 NotificationPtr FilterEngine::GetNextNotificationToShow(const std::string& url) | 271 void FilterEngine::ShowNextNotification(const std::string& url) |
| 272 { | 272 { |
| 273 JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow"); | 273 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); |
| 274 JsValueList params; | 274 JsValueList params; |
| 275 if (!url.empty()) | 275 if (!url.empty()) |
| 276 { | 276 { |
| 277 params.push_back(jsEngine->NewValue(url)); | 277 params.push_back(jsEngine->NewValue(url)); |
| 278 } | 278 } |
| 279 return Notification::JsValueToNotification(func->Call(params)); | 279 func->Call(params); |
| 280 } |
| 281 |
| 282 void FilterEngine::SetShowNotificationCallback(const ShowNotificationCallback& v
alue) |
| 283 { |
| 284 if (!value) |
| 285 return; |
| 286 |
| 287 jsEngine->SetEventCallback("_showNotification", |
| 288 std::tr1::bind(&FilterEngine::ShowNotification, this, value, |
| 289 std::tr1::placeholders::_1)); |
| 290 } |
| 291 |
| 292 void FilterEngine::RemoveShowNotificationCallback() |
| 293 { |
| 294 jsEngine->RemoveEventCallback("_showNotification"); |
| 280 } | 295 } |
| 281 | 296 |
| 282 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 297 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
| 283 ContentType contentType, | 298 ContentType contentType, |
| 284 const std::string& documentUrl) const | 299 const std::string& documentUrl) const |
| 285 { | 300 { |
| 286 std::vector<std::string> documentUrls; | 301 std::vector<std::string> documentUrls; |
| 287 documentUrls.push_back(documentUrl); | 302 documentUrls.push_back(documentUrl); |
| 288 return Matches(url, contentType, documentUrls); | 303 return Matches(url, contentType, documentUrls); |
| 289 } | 304 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 jsEngine->RemoveEventCallback("filterChange"); | 433 jsEngine->RemoveEventCallback("filterChange"); |
| 419 } | 434 } |
| 420 | 435 |
| 421 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js
ValueList& params) | 436 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js
ValueList& params) |
| 422 { | 437 { |
| 423 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() : ""); |
| 424 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); | 439 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); |
| 425 callback(action, item); | 440 callback(action, item); |
| 426 } | 441 } |
| 427 | 442 |
| 443 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback, |
| 444 const JsValueList& params) |
| 445 { |
| 446 if (params.size() < 1) |
| 447 return; |
| 448 |
| 449 callback(Notification::JsValueToNotification(params[0])); |
| 450 } |
| 451 |
| 452 |
| 428 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 453 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
| 429 { | 454 { |
| 430 JsValueList params; | 455 JsValueList params; |
| 431 params.push_back(jsEngine->NewValue(v1)); | 456 params.push_back(jsEngine->NewValue(v1)); |
| 432 params.push_back(jsEngine->NewValue(v2)); | 457 params.push_back(jsEngine->NewValue(v2)); |
| 433 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 458 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
| 434 return func->Call(params)->AsInt(); | 459 return func->Call(params)->AsInt(); |
| 435 } | 460 } |
| OLD | NEW |