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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 bool FilterEngine::IsFirstRun() const | 220 bool FilterEngine::IsFirstRun() const |
221 { | 221 { |
222 return firstRun; | 222 return firstRun; |
223 } | 223 } |
224 | 224 |
225 FilterPtr FilterEngine::GetFilter(const std::string& text) | 225 FilterPtr FilterEngine::GetFilter(const std::string& text) |
226 { | 226 { |
227 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); | 227 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); |
228 JsValueList params; | 228 JsValueList params; |
229 params.push_back(jsEngine->NewValue(text)); | 229 params.push_back(jsEngine->NewValue(text)); |
230 return FilterPtr(new Filter(func->Call(params))); | 230 return FilterPtr(new Filter(std::move(*func->Call(params)))); |
231 } | 231 } |
232 | 232 |
233 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) | 233 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) |
234 { | 234 { |
235 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); | 235 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); |
236 JsValueList params; | 236 JsValueList params; |
237 params.push_back(jsEngine->NewValue(url)); | 237 params.push_back(jsEngine->NewValue(url)); |
238 return SubscriptionPtr(new Subscription(func->Call(params))); | 238 return SubscriptionPtr(new Subscription(std::move(*func->Call(params)))); |
239 } | 239 } |
240 | 240 |
241 std::vector<FilterPtr> FilterEngine::GetListedFilters() const | 241 std::vector<FilterPtr> FilterEngine::GetListedFilters() const |
242 { | 242 { |
243 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); | 243 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); |
244 JsValueList values = func->Call()->AsList(); | 244 JsValueList values = func->Call()->AsList(); |
245 std::vector<FilterPtr> result; | 245 std::vector<FilterPtr> result; |
246 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 246 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
247 result.push_back(FilterPtr(new Filter(*it))); | 247 result.push_back(FilterPtr(new Filter(std::move(**it)))); |
248 return result; | 248 return result; |
249 } | 249 } |
250 | 250 |
251 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const | 251 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const |
252 { | 252 { |
253 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); | 253 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); |
254 JsValueList values = func->Call()->AsList(); | 254 JsValueList values = func->Call()->AsList(); |
255 std::vector<SubscriptionPtr> result; | 255 std::vector<SubscriptionPtr> result; |
256 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 256 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
257 result.push_back(SubscriptionPtr(new Subscription(*it))); | 257 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); |
258 return result; | 258 return result; |
259 } | 259 } |
260 | 260 |
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(std::move(**it)))); |
268 return result; | 268 return result; |
269 } | 269 } |
270 | 270 |
271 void FilterEngine::ShowNextNotification(const std::string& url) | 271 void FilterEngine::ShowNextNotification(const std::string& url) |
272 { | 272 { |
273 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); | 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)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 ContentType contentType, | 329 ContentType contentType, |
330 const std::string& documentUrl) const | 330 const std::string& documentUrl) const |
331 { | 331 { |
332 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); | 332 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
333 JsValueList params; | 333 JsValueList params; |
334 params.push_back(jsEngine->NewValue(url)); | 334 params.push_back(jsEngine->NewValue(url)); |
335 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); | 335 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); |
336 params.push_back(jsEngine->NewValue(documentUrl)); | 336 params.push_back(jsEngine->NewValue(documentUrl)); |
337 JsValuePtr result = func->Call(params); | 337 JsValuePtr result = func->Call(params); |
338 if (!result->IsNull()) | 338 if (!result->IsNull()) |
339 return FilterPtr(new Filter(result)); | 339 return FilterPtr(new Filter(std::move(*result))); |
340 else | 340 else |
341 return FilterPtr(); | 341 return FilterPtr(); |
342 } | 342 } |
343 | 343 |
344 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const | 344 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const |
345 { | 345 { |
346 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); | 346 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); |
347 JsValueList params; | 347 JsValueList params; |
348 params.push_back(jsEngine->NewValue(domain)); | 348 params.push_back(jsEngine->NewValue(domain)); |
349 JsValueList result = func->Call(params)->AsList(); | 349 JsValueList result = func->Call(params)->AsList(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback, | 443 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback, |
444 const JsValueList& params) | 444 const JsValueList& params) |
445 { | 445 { |
446 if (params.size() < 1) | 446 if (params.size() < 1) |
447 return; | 447 return; |
448 | 448 |
449 if (!params[0]->IsObject()) | 449 if (!params[0]->IsObject()) |
450 { | 450 { |
451 return; | 451 return; |
452 } | 452 } |
453 callback(NotificationPtr(new Notification(params[0]))); | 453 callback(NotificationPtr(new Notification(std::move(*params[0])))); |
454 } | 454 } |
455 | 455 |
456 | 456 |
457 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 457 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
458 { | 458 { |
459 JsValueList params; | 459 JsValueList params; |
460 params.push_back(jsEngine->NewValue(v1)); | 460 params.push_back(jsEngine->NewValue(v1)); |
461 params.push_back(jsEngine->NewValue(v2)); | 461 params.push_back(jsEngine->NewValue(v2)); |
462 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 462 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
463 return func->Call(params)->AsInt(); | 463 return func->Call(params)->AsInt(); |
464 } | 464 } |
OLD | NEW |