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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const | 250 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const |
251 { | 251 { |
252 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); | 252 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); |
253 JsValueList values = func->Call()->AsList(); | 253 JsValueList values = func->Call()->AsList(); |
254 std::vector<SubscriptionPtr> result; | 254 std::vector<SubscriptionPtr> result; |
255 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 255 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
256 result.push_back(SubscriptionPtr(new Subscription(*it))); | 256 result.push_back(SubscriptionPtr(new Subscription(*it))); |
257 return result; | 257 return result; |
258 } | 258 } |
259 | 259 |
260 NotificationPtr FilterEngine::GetNextNotificationToShow(const std::string& url) | 260 void FilterEngine::ShowNextNotification(const std::string& url) |
261 { | 261 { |
262 JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow"); | 262 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); |
263 JsValueList params; | 263 JsValueList params; |
264 if (!url.empty()) | 264 if (!url.empty()) |
265 { | 265 { |
266 params.push_back(jsEngine->NewValue(url)); | 266 params.push_back(jsEngine->NewValue(url)); |
267 } | 267 } |
268 return Notification::JsValueToNotification(func->Call(params)); | 268 func->Call(params); |
| 269 } |
| 270 |
| 271 void FilterEngine::SetNotificationAvailableCallback(const NotificationAvailableC
allback& value) |
| 272 { |
| 273 if (!value) |
| 274 return; |
| 275 |
| 276 jsEngine->SetEventCallback("notificationAvailable", |
| 277 std::tr1::bind(&FilterEngine::NotificationAvailable, this, value, |
| 278 std::tr1::placeholders::_1)); |
| 279 } |
| 280 |
| 281 void FilterEngine::RemoveNotificationAvailableCallback() |
| 282 { |
| 283 jsEngine->RemoveEventCallback("notificationAvailable"); |
269 } | 284 } |
270 | 285 |
271 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 286 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
272 ContentType contentType, | 287 ContentType contentType, |
273 const std::string& documentUrl) const | 288 const std::string& documentUrl) const |
274 { | 289 { |
275 std::vector<std::string> documentUrls; | 290 std::vector<std::string> documentUrls; |
276 documentUrls.push_back(documentUrl); | 291 documentUrls.push_back(documentUrl); |
277 return Matches(url, contentType, documentUrls); | 292 return Matches(url, contentType, documentUrls); |
278 } | 293 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 jsEngine->RemoveEventCallback("filterChange"); | 422 jsEngine->RemoveEventCallback("filterChange"); |
408 } | 423 } |
409 | 424 |
410 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js
ValueList& params) | 425 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js
ValueList& params) |
411 { | 426 { |
412 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS
tring() : ""); | 427 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS
tring() : ""); |
413 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); | 428 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); |
414 callback(action, item); | 429 callback(action, item); |
415 } | 430 } |
416 | 431 |
| 432 void FilterEngine::NotificationAvailable(const NotificationAvailableCallback& ca
llback, |
| 433 const JsValueList& params) |
| 434 { |
| 435 if (params.size() < 1) |
| 436 return; |
| 437 |
| 438 callback(Notification::JsValueToNotification(params[0])); |
| 439 } |
| 440 |
| 441 |
417 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 442 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
418 { | 443 { |
419 JsValueList params; | 444 JsValueList params; |
420 params.push_back(jsEngine->NewValue(v1)); | 445 params.push_back(jsEngine->NewValue(v1)); |
421 params.push_back(jsEngine->NewValue(v2)); | 446 params.push_back(jsEngine->NewValue(v2)); |
422 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 447 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
423 return func->Call(params)->AsInt(); | 448 return func->Call(params)->AsInt(); |
424 } | 449 } |
OLD | NEW |