Index: src/FilterEngine.cpp |
=================================================================== |
--- a/src/FilterEngine.cpp |
+++ b/src/FilterEngine.cpp |
@@ -32,107 +32,91 @@ extern std::string jsSources[]; |
Filter::Filter(JsValue&& value) |
: JsValue(std::move(value)) |
{ |
if (!IsObject()) |
throw std::runtime_error("JavaScript value is not an object"); |
} |
-Filter::Type Filter::GetType() |
+Filter::Type Filter::GetType() const |
{ |
std::string className = GetClass(); |
if (className == "BlockingFilter") |
return TYPE_BLOCKING; |
else if (className == "WhitelistFilter") |
return TYPE_EXCEPTION; |
else if (className == "ElemHideFilter") |
return TYPE_ELEMHIDE; |
else if (className == "ElemHideException") |
return TYPE_ELEMHIDE_EXCEPTION; |
else if (className == "CommentFilter") |
return TYPE_COMMENT; |
else |
return TYPE_INVALID; |
} |
-bool Filter::IsListed() |
+bool Filter::IsListed() const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.isListedFilter"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- return func->Call(params)->AsBool(); |
+ return func->Call(shared_from_this())->AsBool(); |
} |
void Filter::AddToList() |
{ |
JsValuePtr func = jsEngine->Evaluate("API.addFilterToList"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- func->Call(params); |
+ func->Call(shared_from_this()); |
} |
void Filter::RemoveFromList() |
{ |
JsValuePtr func = jsEngine->Evaluate("API.removeFilterFromList"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- func->Call(params); |
+ func->Call(shared_from_this()); |
} |
bool Filter::operator==(const Filter& filter) const |
{ |
return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString(); |
} |
Subscription::Subscription(JsValue&& value) |
: JsValue(std::move(value)) |
{ |
if (!IsObject()) |
throw std::runtime_error("JavaScript value is not an object"); |
} |
-bool Subscription::IsListed() |
+bool Subscription::IsListed() const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- return func->Call(params)->AsBool(); |
+ return func->Call(shared_from_this())->AsBool(); |
} |
void Subscription::AddToList() |
{ |
JsValuePtr func = jsEngine->Evaluate("API.addSubscriptionToList"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- func->Call(params); |
+ func->Call(shared_from_this()); |
} |
void Subscription::RemoveFromList() |
{ |
JsValuePtr func = jsEngine->Evaluate("API.removeSubscriptionFromList"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- func->Call(params); |
+ func->Call(shared_from_this()); |
} |
void Subscription::UpdateFilters() |
{ |
JsValuePtr func = jsEngine->Evaluate("API.updateSubscription"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- func->Call(params); |
+ func->Call(shared_from_this()); |
} |
-bool Subscription::IsUpdating() |
+bool Subscription::IsUpdating() const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.isSubscriptionUpdating"); |
- JsValueList params; |
- params.push_back(shared_from_this()); |
- JsValuePtr result = func->Call(params); |
+ JsValuePtr result = func->Call(shared_from_this()); |
return result->AsBool(); |
} |
bool Subscription::operator==(const Subscription& subscription) const |
{ |
return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsString(); |
} |
@@ -284,30 +268,26 @@ FilterEngine::ContentType FilterEngine:: |
throw std::invalid_argument("Cannot convert argument to ContentType"); |
} |
bool FilterEngine::IsFirstRun() const |
{ |
return firstRun; |
} |
-FilterPtr FilterEngine::GetFilter(const std::string& text) |
+FilterPtr FilterEngine::GetFilter(const std::string& text) const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); |
- JsValueList params; |
- params.push_back(jsEngine->NewValue(text)); |
- return FilterPtr(new Filter(std::move(*func->Call(params)))); |
+ return FilterPtr(new Filter(std::move(*func->Call(jsEngine->NewValue(text))))); |
} |
-SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) |
+SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); |
- JsValueList params; |
- params.push_back(jsEngine->NewValue(url)); |
- return SubscriptionPtr(new Subscription(std::move(*func->Call(params)))); |
+ return SubscriptionPtr(new Subscription(std::move(*func->Call(jsEngine->NewValue(url))))); |
} |
std::vector<FilterPtr> FilterEngine::GetListedFilters() const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); |
JsValueList values = func->Call()->AsList(); |
std::vector<FilterPtr> result; |
for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
@@ -333,17 +313,17 @@ std::vector<SubscriptionPtr> FilterEngin |
for (JsValueList::iterator it = values.begin(); it != values.end(); it++) |
result.push_back(SubscriptionPtr(new Subscription(std::move(**it)))); |
return result; |
} |
void FilterEngine::ShowNextNotification(const std::string& url) |
{ |
JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); |
- JsValueList params; |
+ JsConstValueList params; |
if (!url.empty()) |
{ |
params.push_back(jsEngine->NewValue(url)); |
} |
func->Call(params); |
} |
void FilterEngine::SetShowNotificationCallback(const ShowNotificationCallback& value) |
@@ -404,63 +384,57 @@ bool FilterEngine::IsElemhideWhitelisted |
return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls); |
} |
AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, |
ContentTypeMask contentTypeMask, |
const std::string& documentUrl) const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
- JsValueList params; |
+ JsConstValueList params; |
params.push_back(jsEngine->NewValue(url)); |
params.push_back(jsEngine->NewValue(contentTypeMask)); |
params.push_back(jsEngine->NewValue(documentUrl)); |
JsValuePtr result = func->Call(params); |
if (!result->IsNull()) |
return FilterPtr(new Filter(std::move(*result))); |
else |
return FilterPtr(); |
} |
std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::string& domain) const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); |
- JsValueList params; |
- params.push_back(jsEngine->NewValue(domain)); |
- JsValueList result = func->Call(params)->AsList(); |
+ JsValueList result = func->Call(jsEngine->NewValue(domain))->AsList(); |
std::vector<std::string> selectors; |
for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) |
selectors.push_back((*it)->AsString()); |
return selectors; |
} |
JsValuePtr FilterEngine::GetPref(const std::string& pref) const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.getPref"); |
- JsValueList params; |
- params.push_back(jsEngine->NewValue(pref)); |
- return func->Call(params); |
+ return func->Call(jsEngine->NewValue(pref)); |
} |
void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) |
{ |
JsValuePtr func = jsEngine->Evaluate("API.setPref"); |
- JsValueList params; |
+ JsConstValueList params; |
params.push_back(jsEngine->NewValue(pref)); |
if (value) |
params.push_back(value); |
func->Call(params); |
} |
-std::string FilterEngine::GetHostFromURL(const std::string& url) |
+std::string FilterEngine::GetHostFromURL(const std::string& url) const |
{ |
JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); |
- JsValueList params; |
- params.push_back(jsEngine->NewValue(url)); |
- return func->Call(params)->AsString(); |
+ return func->Call(jsEngine->NewValue(url))->AsString(); |
} |
void FilterEngine::SetUpdateAvailableCallback( |
FilterEngine::UpdateAvailableCallback callback) |
{ |
jsEngine->SetEventCallback("updateAvailable", |
std::bind(&FilterEngine::UpdateAvailable, this, callback, |
std::placeholders::_1)); |
@@ -477,17 +451,17 @@ void FilterEngine::UpdateAvailable( |
if (params.size() >= 1 && !params[0]->IsNull()) |
callback(params[0]->AsString()); |
} |
void FilterEngine::ForceUpdateCheck( |
const FilterEngine::UpdateCheckDoneCallback& callback) |
{ |
JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); |
- JsValueList params; |
+ JsConstValueList params; |
if (callback) |
{ |
std::string eventName = "_updateCheckDone" + std::to_string(++updateCheckId); |
jsEngine->SetEventCallback(eventName, std::bind(&FilterEngine::UpdateCheckDone, |
this, eventName, callback, std::placeholders::_1)); |
params.push_back(jsEngine->NewValue(eventName)); |
} |
func->Call(params); |
@@ -513,17 +487,17 @@ void FilterEngine::RemoveFilterChangeCal |
jsEngine->RemoveEventCallback("filterChange"); |
} |
void FilterEngine::SetAllowedConnectionType(const std::string* value) |
{ |
SetPref("allowed_connection_type", value ? jsEngine->NewValue(*value) : nullptr); |
} |
-std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() |
+std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() const |
{ |
auto prefValue = GetPref("allowed_connection_type"); |
if (prefValue->IsUndefined()) |
return nullptr; |
return std::unique_ptr<std::string>(new std::string(prefValue->AsString())); |
} |
void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, JsValueList& params) |
@@ -542,19 +516,19 @@ void FilterEngine::ShowNotification(cons |
if (!params[0]->IsObject()) |
{ |
return; |
} |
callback(NotificationPtr(new Notification(std::move(*params[0])))); |
} |
-int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
+int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) const |
{ |
- JsValueList params; |
+ JsConstValueList params; |
params.push_back(jsEngine->NewValue(v1)); |
params.push_back(jsEngine->NewValue(v2)); |
JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
return func->Call(params)->AsInt(); |
} |
FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, |
ContentTypeMask contentTypeMask, const std::string& documentUrl) const |