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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 return TYPE_ELEMHIDE_EXCEPTION; | 50 return TYPE_ELEMHIDE_EXCEPTION; |
51 else if (className == "CommentFilter") | 51 else if (className == "CommentFilter") |
52 return TYPE_COMMENT; | 52 return TYPE_COMMENT; |
53 else | 53 else |
54 return TYPE_INVALID; | 54 return TYPE_INVALID; |
55 } | 55 } |
56 | 56 |
57 bool Filter::IsListed() const | 57 bool Filter::IsListed() const |
58 { | 58 { |
59 JsValuePtr func = jsEngine->Evaluate("API.isListedFilter"); | 59 JsValuePtr func = jsEngine->Evaluate("API.isListedFilter"); |
60 return func->Call(shared_from_this())->AsBool(); | 60 return func->Call(*this).AsBool(); |
61 } | 61 } |
62 | 62 |
63 void Filter::AddToList() | 63 void Filter::AddToList() |
64 { | 64 { |
65 JsValuePtr func = jsEngine->Evaluate("API.addFilterToList"); | 65 JsValuePtr func = jsEngine->Evaluate("API.addFilterToList"); |
66 func->Call(shared_from_this()); | 66 func->Call(*this); |
67 } | 67 } |
68 | 68 |
69 void Filter::RemoveFromList() | 69 void Filter::RemoveFromList() |
70 { | 70 { |
71 JsValuePtr func = jsEngine->Evaluate("API.removeFilterFromList"); | 71 JsValuePtr func = jsEngine->Evaluate("API.removeFilterFromList"); |
72 func->Call(shared_from_this()); | 72 func->Call(*this); |
73 } | 73 } |
74 | 74 |
75 bool Filter::operator==(const Filter& filter) const | 75 bool Filter::operator==(const Filter& filter) const |
76 { | 76 { |
77 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString
(); | 77 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString
(); |
78 } | 78 } |
79 | 79 |
80 Subscription::Subscription(JsValue&& value) | 80 Subscription::Subscription(JsValue&& value) |
81 : JsValue(std::move(value)) | 81 : JsValue(std::move(value)) |
82 { | 82 { |
83 if (!IsObject()) | 83 if (!IsObject()) |
84 throw std::runtime_error("JavaScript value is not an object"); | 84 throw std::runtime_error("JavaScript value is not an object"); |
85 } | 85 } |
86 | 86 |
87 bool Subscription::IsListed() const | 87 bool Subscription::IsListed() const |
88 { | 88 { |
89 JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription"); | 89 JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription"); |
90 return func->Call(shared_from_this())->AsBool(); | 90 return func->Call(*this).AsBool(); |
91 } | 91 } |
92 | 92 |
93 void Subscription::AddToList() | 93 void Subscription::AddToList() |
94 { | 94 { |
95 JsValuePtr func = jsEngine->Evaluate("API.addSubscriptionToList"); | 95 JsValuePtr func = jsEngine->Evaluate("API.addSubscriptionToList"); |
96 func->Call(shared_from_this()); | 96 func->Call(*this); |
97 } | 97 } |
98 | 98 |
99 void Subscription::RemoveFromList() | 99 void Subscription::RemoveFromList() |
100 { | 100 { |
101 JsValuePtr func = jsEngine->Evaluate("API.removeSubscriptionFromList"); | 101 JsValuePtr func = jsEngine->Evaluate("API.removeSubscriptionFromList"); |
102 func->Call(shared_from_this()); | 102 func->Call(*this); |
103 } | 103 } |
104 | 104 |
105 void Subscription::UpdateFilters() | 105 void Subscription::UpdateFilters() |
106 { | 106 { |
107 JsValuePtr func = jsEngine->Evaluate("API.updateSubscription"); | 107 JsValuePtr func = jsEngine->Evaluate("API.updateSubscription"); |
108 func->Call(shared_from_this()); | 108 func->Call(*this); |
109 } | 109 } |
110 | 110 |
111 bool Subscription::IsUpdating() const | 111 bool Subscription::IsUpdating() const |
112 { | 112 { |
113 JsValuePtr func = jsEngine->Evaluate("API.isSubscriptionUpdating"); | 113 JsValuePtr func = jsEngine->Evaluate("API.isSubscriptionUpdating"); |
114 JsValuePtr result = func->Call(shared_from_this()); | 114 return func->Call(*this).AsBool(); |
115 return result->AsBool(); | |
116 } | 115 } |
117 | 116 |
118 bool Subscription::operator==(const Subscription& subscription) const | 117 bool Subscription::operator==(const Subscription& subscription) const |
119 { | 118 { |
120 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt
ring(); | 119 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt
ring(); |
121 } | 120 } |
122 | 121 |
123 namespace | 122 namespace |
124 { | 123 { |
125 class Sync | 124 class Sync |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 267 } |
269 | 268 |
270 bool FilterEngine::IsFirstRun() const | 269 bool FilterEngine::IsFirstRun() const |
271 { | 270 { |
272 return firstRun; | 271 return firstRun; |
273 } | 272 } |
274 | 273 |
275 FilterPtr FilterEngine::GetFilter(const std::string& text) const | 274 FilterPtr FilterEngine::GetFilter(const std::string& text) const |
276 { | 275 { |
277 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); | 276 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); |
278 return FilterPtr(new Filter(std::move(*func->Call(jsEngine->NewValue(text)))))
; | 277 return FilterPtr(new Filter(func->Call(*jsEngine->NewValue(text)))); |
279 } | 278 } |
280 | 279 |
281 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) const | 280 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) const |
282 { | 281 { |
283 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); | 282 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); |
284 return SubscriptionPtr(new Subscription(std::move(*func->Call(jsEngine->NewVal
ue(url))))); | 283 return SubscriptionPtr(new Subscription(func->Call(*jsEngine->NewValue(url))))
; |
285 } | 284 } |
286 | 285 |
287 std::vector<FilterPtr> FilterEngine::GetListedFilters() const | 286 std::vector<FilterPtr> FilterEngine::GetListedFilters() const |
288 { | 287 { |
289 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); | 288 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); |
290 JsValueList values = func->Call()->AsList(); | 289 JsValueList values = func->Call().AsList(); |
291 std::vector<FilterPtr> result; | 290 std::vector<FilterPtr> result; |
292 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 291 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
293 result.push_back(FilterPtr(new Filter(std::move(**it)))); | 292 result.push_back(FilterPtr(new Filter(std::move(**it)))); |
294 return result; | 293 return result; |
295 } | 294 } |
296 | 295 |
297 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const | 296 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const |
298 { | 297 { |
299 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); | 298 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); |
300 JsValueList values = func->Call()->AsList(); | 299 JsValueList values = func->Call().AsList(); |
301 std::vector<SubscriptionPtr> result; | 300 std::vector<SubscriptionPtr> result; |
302 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 301 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
303 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); | 302 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); |
304 return result; | 303 return result; |
305 } | 304 } |
306 | 305 |
307 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const | 306 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const |
308 { | 307 { |
309 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); | 308 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); |
310 JsValueList values = func->Call()->AsList(); | 309 JsValueList values = func->Call().AsList(); |
311 std::vector<SubscriptionPtr> result; | 310 std::vector<SubscriptionPtr> result; |
312 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) | 311 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
313 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); | 312 result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); |
314 return result; | 313 return result; |
315 } | 314 } |
316 | 315 |
317 void FilterEngine::ShowNextNotification(const std::string& url) | 316 void FilterEngine::ShowNextNotification(const std::string& url) |
318 { | 317 { |
319 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); | 318 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); |
320 JsConstValueList params; | 319 JsConstValueList params; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 382 |
384 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, | 383 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, |
385 ContentTypeMask contentTypeMask, | 384 ContentTypeMask contentTypeMask, |
386 const std::string& documentUrl) const | 385 const std::string& documentUrl) const |
387 { | 386 { |
388 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); | 387 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
389 JsConstValueList params; | 388 JsConstValueList params; |
390 params.push_back(jsEngine->NewValue(url)); | 389 params.push_back(jsEngine->NewValue(url)); |
391 params.push_back(jsEngine->NewValue(contentTypeMask)); | 390 params.push_back(jsEngine->NewValue(contentTypeMask)); |
392 params.push_back(jsEngine->NewValue(documentUrl)); | 391 params.push_back(jsEngine->NewValue(documentUrl)); |
393 JsValuePtr result = func->Call(params); | 392 JsValue result = func->Call(params); |
394 if (!result->IsNull()) | 393 if (!result.IsNull()) |
395 return FilterPtr(new Filter(std::move(*result))); | 394 return FilterPtr(new Filter(std::move(result))); |
396 else | 395 else |
397 return FilterPtr(); | 396 return FilterPtr(); |
398 } | 397 } |
399 | 398 |
400 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const | 399 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const |
401 { | 400 { |
402 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); | 401 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); |
403 JsValueList result = func->Call(jsEngine->NewValue(domain))->AsList(); | 402 JsValueList result = func->Call(*jsEngine->NewValue(domain)).AsList(); |
404 std::vector<std::string> selectors; | 403 std::vector<std::string> selectors; |
405 for (const auto& r: result) | 404 for (const auto& r: result) |
406 selectors.push_back(r->AsString()); | 405 selectors.push_back(r->AsString()); |
407 return selectors; | 406 return selectors; |
408 } | 407 } |
409 | 408 |
410 JsValuePtr FilterEngine::GetPref(const std::string& pref) const | 409 JsValuePtr FilterEngine::GetPref(const std::string& pref) const |
411 { | 410 { |
412 JsValuePtr func = jsEngine->Evaluate("API.getPref"); | 411 JsValuePtr func = jsEngine->Evaluate("API.getPref"); |
413 return func->Call(jsEngine->NewValue(pref)); | 412 return std::make_shared<JsValue>(func->Call(*jsEngine->NewValue(pref))); |
414 } | 413 } |
415 | 414 |
416 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) | 415 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) |
417 { | 416 { |
418 JsValuePtr func = jsEngine->Evaluate("API.setPref"); | 417 JsValuePtr func = jsEngine->Evaluate("API.setPref"); |
419 JsConstValueList params; | 418 JsConstValueList params; |
420 params.push_back(jsEngine->NewValue(pref)); | 419 params.push_back(jsEngine->NewValue(pref)); |
421 if (value) | 420 if (value) |
422 params.push_back(value); | 421 params.push_back(value); |
423 func->Call(params); | 422 func->Call(params); |
424 } | 423 } |
425 | 424 |
426 std::string FilterEngine::GetHostFromURL(const std::string& url) const | 425 std::string FilterEngine::GetHostFromURL(const std::string& url) const |
427 { | 426 { |
428 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); | 427 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); |
429 return func->Call(jsEngine->NewValue(url))->AsString(); | 428 return func->Call(*jsEngine->NewValue(url)).AsString(); |
430 } | 429 } |
431 | 430 |
432 void FilterEngine::SetUpdateAvailableCallback( | 431 void FilterEngine::SetUpdateAvailableCallback( |
433 FilterEngine::UpdateAvailableCallback callback) | 432 FilterEngine::UpdateAvailableCallback callback) |
434 { | 433 { |
435 jsEngine->SetEventCallback("updateAvailable", | 434 jsEngine->SetEventCallback("updateAvailable", |
436 std::bind(&FilterEngine::UpdateAvailable, this, callback, | 435 std::bind(&FilterEngine::UpdateAvailable, this, callback, |
437 std::placeholders::_1)); | 436 std::placeholders::_1)); |
438 } | 437 } |
439 | 438 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 callback(NotificationPtr(new Notification(std::move(*params[0])))); | 516 callback(NotificationPtr(new Notification(std::move(*params[0])))); |
518 } | 517 } |
519 | 518 |
520 | 519 |
521 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
const | 520 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
const |
522 { | 521 { |
523 JsConstValueList params; | 522 JsConstValueList params; |
524 params.push_back(jsEngine->NewValue(v1)); | 523 params.push_back(jsEngine->NewValue(v1)); |
525 params.push_back(jsEngine->NewValue(v2)); | 524 params.push_back(jsEngine->NewValue(v2)); |
526 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 525 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
527 return func->Call(params)->AsInt(); | 526 return func->Call(params).AsInt(); |
528 } | 527 } |
529 | 528 |
530 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, | 529 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, |
531 ContentTypeMask contentTypeMask, const std::string& documentUrl) const | 530 ContentTypeMask contentTypeMask, const std::string& documentUrl) const |
532 { | 531 { |
533 FilterPtr match = Matches(url, contentTypeMask, documentUrl); | 532 FilterPtr match = Matches(url, contentTypeMask, documentUrl); |
534 if (match && match->GetType() == Filter::TYPE_EXCEPTION) | 533 if (match && match->GetType() == Filter::TYPE_EXCEPTION) |
535 { | 534 { |
536 return match; | 535 return match; |
537 } | 536 } |
(...skipping 17 matching lines...) Expand all Loading... |
555 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); | 554 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); |
556 if (filter) | 555 if (filter) |
557 { | 556 { |
558 return filter; | 557 return filter; |
559 } | 558 } |
560 currentUrl = parentUrl; | 559 currentUrl = parentUrl; |
561 } | 560 } |
562 while (urlIterator != documentUrls.end()); | 561 while (urlIterator != documentUrls.end()); |
563 return FilterPtr(); | 562 return FilterPtr(); |
564 } | 563 } |
OLD | NEW |