| 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 10 matching lines...) Expand all Loading... |
| 21 #include <string> | 21 #include <string> |
| 22 | 22 |
| 23 #include <AdblockPlus.h> | 23 #include <AdblockPlus.h> |
| 24 #include "JsContext.h" | 24 #include "JsContext.h" |
| 25 #include "Thread.h" | 25 #include "Thread.h" |
| 26 | 26 |
| 27 using namespace AdblockPlus; | 27 using namespace AdblockPlus; |
| 28 | 28 |
| 29 extern std::string jsSources[]; | 29 extern std::string jsSources[]; |
| 30 | 30 |
| 31 Filter::Filter(JsValuePtr value) | 31 Filter::Filter(JsValue&& value) |
| 32 : JsValue(value) | 32 : JsValue(std::move(value)) |
| 33 { | 33 { |
| 34 if (!IsObject()) | 34 if (!IsObject()) |
| 35 throw std::runtime_error("JavaScript value is not an object"); | 35 throw std::runtime_error("JavaScript value is not an object"); |
| 36 } | 36 } |
| 37 | 37 |
| 38 Filter::Type Filter::GetType() | 38 Filter::Type Filter::GetType() |
| 39 { | 39 { |
| 40 std::string className = GetClass(); | 40 std::string className = GetClass(); |
| 41 if (className == "BlockingFilter") | 41 if (className == "BlockingFilter") |
| 42 return TYPE_BLOCKING; | 42 return TYPE_BLOCKING; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 JsValueList params; | 74 JsValueList params; |
| 75 params.push_back(shared_from_this()); | 75 params.push_back(shared_from_this()); |
| 76 func->Call(params); | 76 func->Call(params); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool Filter::operator==(const Filter& filter) const | 79 bool Filter::operator==(const Filter& filter) const |
| 80 { | 80 { |
| 81 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString
(); | 81 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString
(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 Subscription::Subscription(JsValuePtr value) | 84 Subscription::Subscription(JsValue&& value) |
| 85 : JsValue(value) | 85 : JsValue(std::move(value)) |
| 86 { | 86 { |
| 87 if (!IsObject()) | 87 if (!IsObject()) |
| 88 throw std::runtime_error("JavaScript value is not an object"); | 88 throw std::runtime_error("JavaScript value is not an object"); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool Subscription::IsListed() | 91 bool Subscription::IsListed() |
| 92 { | 92 { |
| 93 JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription"); | 93 JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription"); |
| 94 JsValueList params; | 94 JsValueList params; |
| 95 params.push_back(shared_from_this()); | 95 params.push_back(shared_from_this()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 bool FilterEngine::IsFirstRun() const | 209 bool FilterEngine::IsFirstRun() const |
| 210 { | 210 { |
| 211 return firstRun; | 211 return firstRun; |
| 212 } | 212 } |
| 213 | 213 |
| 214 FilterPtr FilterEngine::GetFilter(const std::string& text) | 214 FilterPtr FilterEngine::GetFilter(const std::string& text) |
| 215 { | 215 { |
| 216 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); | 216 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); |
| 217 JsValueList params; | 217 JsValueList params; |
| 218 params.push_back(jsEngine->NewValue(text)); | 218 params.push_back(jsEngine->NewValue(text)); |
| 219 return FilterPtr(new Filter(func->Call(params))); | 219 return FilterPtr(new Filter(std::move(*func->Call(params)))); |
| 220 } | 220 } |
| 221 | 221 |
| 222 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) | 222 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) |
| 223 { | 223 { |
| 224 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); | 224 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); |
| 225 JsValueList params; | 225 JsValueList params; |
| 226 params.push_back(jsEngine->NewValue(url)); | 226 params.push_back(jsEngine->NewValue(url)); |
| 227 return SubscriptionPtr(new Subscription(func->Call(params))); | 227 return SubscriptionPtr(new Subscription(std::move(*func->Call(params)))); |
| 228 } | 228 } |
| 229 | 229 |
| 230 std::vector<FilterPtr> FilterEngine::GetListedFilters() const | 230 std::vector<FilterPtr> FilterEngine::GetListedFilters() const |
| 231 { | 231 { |
| 232 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); | 232 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); |
| 233 JsValueList values = func->Call()->AsList(); | 233 JsValueList values = func->Call()->AsList(); |
| 234 std::vector<FilterPtr> result; | 234 std::vector<FilterPtr> result; |
| 235 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 235 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
| 236 result.push_back(FilterPtr(new Filter(*it))); | 236 result.push_back(FilterPtr(new Filter(std::move(**it)))); |
| 237 return result; | 237 return result; |
| 238 } | 238 } |
| 239 | 239 |
| 240 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const | 240 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const |
| 241 { | 241 { |
| 242 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); | 242 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); |
| 243 JsValueList values = func->Call()->AsList(); | 243 JsValueList values = func->Call()->AsList(); |
| 244 std::vector<SubscriptionPtr> result; | 244 std::vector<SubscriptionPtr> result; |
| 245 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 245 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
| 246 result.push_back(SubscriptionPtr(new Subscription(*it))); | 246 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); |
| 247 return result; | 247 return result; |
| 248 } | 248 } |
| 249 | 249 |
| 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(std::move(**it)))); |
| 257 return result; | 257 return result; |
| 258 } | 258 } |
| 259 | 259 |
| 260 NotificationPtr FilterEngine::GetNextNotificationToShow(const std::string& url) | 260 NotificationPtr FilterEngine::GetNextNotificationToShow(const std::string& url) |
| 261 { | 261 { |
| 262 JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow"); | 262 JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow"); |
| 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 return Notification::JsValueToNotification(std::move(*func->Call(params))); |
| 269 } | 269 } |
| 270 | 270 |
| 271 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 271 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
| 272 ContentType contentType, | 272 ContentType contentType, |
| 273 const std::string& documentUrl) const | 273 const std::string& documentUrl) const |
| 274 { | 274 { |
| 275 std::vector<std::string> documentUrls; | 275 std::vector<std::string> documentUrls; |
| 276 documentUrls.push_back(documentUrl); | 276 documentUrls.push_back(documentUrl); |
| 277 return Matches(url, contentType, documentUrls); | 277 return Matches(url, contentType, documentUrls); |
| 278 } | 278 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 303 ContentType contentType, | 303 ContentType contentType, |
| 304 const std::string& documentUrl) const | 304 const std::string& documentUrl) const |
| 305 { | 305 { |
| 306 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); | 306 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
| 307 JsValueList params; | 307 JsValueList params; |
| 308 params.push_back(jsEngine->NewValue(url)); | 308 params.push_back(jsEngine->NewValue(url)); |
| 309 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); | 309 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); |
| 310 params.push_back(jsEngine->NewValue(documentUrl)); | 310 params.push_back(jsEngine->NewValue(documentUrl)); |
| 311 JsValuePtr result = func->Call(params); | 311 JsValuePtr result = func->Call(params); |
| 312 if (!result->IsNull()) | 312 if (!result->IsNull()) |
| 313 return FilterPtr(new Filter(result)); | 313 return FilterPtr(new Filter(std::move(*result))); |
| 314 else | 314 else |
| 315 return FilterPtr(); | 315 return FilterPtr(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const | 318 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const |
| 319 { | 319 { |
| 320 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); | 320 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); |
| 321 JsValueList params; | 321 JsValueList params; |
| 322 params.push_back(jsEngine->NewValue(domain)); | 322 params.push_back(jsEngine->NewValue(domain)); |
| 323 JsValueList result = func->Call(params)->AsList(); | 323 JsValueList result = func->Call(params)->AsList(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 415 } |
| 416 | 416 |
| 417 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 417 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
| 418 { | 418 { |
| 419 JsValueList params; | 419 JsValueList params; |
| 420 params.push_back(jsEngine->NewValue(v1)); | 420 params.push_back(jsEngine->NewValue(v1)); |
| 421 params.push_back(jsEngine->NewValue(v2)); | 421 params.push_back(jsEngine->NewValue(v2)); |
| 422 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 422 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
| 423 return func->Call(params)->AsInt(); | 423 return func->Call(params)->AsInt(); |
| 424 } | 424 } |
| OLD | NEW |