Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/FilterEngine.cpp

Issue 5797488346791936: Issue 1107 - Support notifications (Closed)
Patch Set: Created Jan. 19, 2015, 12:50 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/FilterEngine.cpp
diff --git a/src/FilterEngine.cpp b/src/FilterEngine.cpp
index 3d4770dfe98ca93df67a5bbdcd97d3cf551996e0..0640d42b330dc08ad1ba3bb2a1cd91b6971252b8 100644
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -257,6 +257,84 @@ std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const
return result;
}
+std::tr1::shared_ptr<Notification> FilterEngine::CreateNotification(NotificationType type, const std::string& id) const
+{
+ return std::tr1::make_shared<Notification>(type, id, jsEngine->NewObject(), Notification::PrivateCtrArg());
+}
+
+std::tr1::shared_ptr<Notification> FilterEngine::GetNextNotificationToShow(const std::string& url /*= std::string()*/)
+{
+ JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow");
+ if (!func)
+ {
+ return std::tr1::shared_ptr<Notification>();
+ }
+ JsValueList params;
+ if (!url.empty())
+ {
+ params.push_back(jsEngine->NewValue(url));
+ }
+ return Notification::JsValueToNotification(func->Call(params));
+}
+
+NotificationTexts FilterEngine::GetNotificationTexts(const std::tr1::shared_ptr<Notification>& notification,
+ const std::string& locale) const
+{
+ JsValuePtr func = jsEngine->Evaluate("API.getNotificationTexts");
+ if (!func)
+ {
+ return NotificationTexts();
+ }
+ JsValueList params;
+ params.push_back(notification);
+ if (!locale.empty())
+ {
+ params.push_back(jsEngine->NewValue(locale));
+ }
+ auto jsTexts = func->Call(params);
+ if (!jsTexts)
+ {
+ return NotificationTexts();
+ }
+ return Notification::JsTextsToNotificationTexts(*jsTexts);
+}
+
+void FilterEngine::AddNotification(const std::tr1::shared_ptr<Notification>& value)
+{
+ JsValuePtr func = jsEngine->Evaluate("API.addNotification");
+ if (!func)
+ {
+ return;
+ }
+ JsValueList params;
+ params.push_back(value);
+ func->Call(params);
+}
+
+void FilterEngine::RemoveNotification(const std::tr1::shared_ptr<Notification>& value)
+{
+ JsValuePtr func = jsEngine->Evaluate("API.removeNotification");
+ if (!func)
+ {
+ return;
+ }
+ JsValueList params;
+ params.push_back(value);
+ func->Call(params);
+}
+
+void FilterEngine::MarkNotificationAsShown(const std::string& notificationId)
+{
+ JsValuePtr func = jsEngine->Evaluate("API.markNotificationAsShown");
+ if (!func)
+ {
+ return;
+ }
+ JsValueList params;
+ params.push_back(jsEngine->NewValue(notificationId));
+ func->Call(params);
+}
+
AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
ContentType contentType,
const std::string& documentUrl) const
« include/AdblockPlus/FilterEngine.h ('K') | « libadblockplus.gyp ('k') | src/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld