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

Side by Side Diff: src/FilterEngine.cpp

Issue 5797488346791936: Issue 1107 - Support notifications (Closed)
Patch Set: move GetNotificationTexts into Notification class Created Jan. 21, 2015, 3:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libadblockplus.gyp ('k') | src/JsEngine.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(*it)));
257 return result; 257 return result;
258 } 258 }
259 259
260 std::tr1::shared_ptr<Notification> FilterEngine::CreateNotification(Notification Type type, const std::string& id) const
261 {
262 return std::tr1::make_shared<Notification>(type, id, jsEngine->NewObject(), No tification::PrivateCtrArg());
263 }
264
265 std::tr1::shared_ptr<Notification> FilterEngine::GetNextNotificationToShow(const std::string& url /*= std::string()*/)
266 {
267 JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow");
268 if (!func)
269 {
270 return std::tr1::shared_ptr<Notification>();
271 }
272 JsValueList params;
273 if (!url.empty())
274 {
275 params.push_back(jsEngine->NewValue(url));
276 }
277 return Notification::JsValueToNotification(func->Call(params));
278 }
279
280 void FilterEngine::AddNotification(const std::tr1::shared_ptr<Notification>& val ue)
281 {
282 JsValuePtr func = jsEngine->Evaluate("API.addNotification");
283 if (!func)
284 {
285 return;
286 }
287 JsValueList params;
288 params.push_back(value);
289 func->Call(params);
290 }
291
292 void FilterEngine::RemoveNotification(const std::tr1::shared_ptr<Notification>& value)
293 {
294 JsValuePtr func = jsEngine->Evaluate("API.removeNotification");
295 if (!func)
296 {
297 return;
298 }
299 JsValueList params;
300 params.push_back(value);
301 func->Call(params);
302 }
303
304 void FilterEngine::MarkNotificationAsShown(const std::string& notificationId)
305 {
306 JsValuePtr func = jsEngine->Evaluate("API.markNotificationAsShown");
307 if (!func)
308 {
309 return;
310 }
311 JsValueList params;
312 params.push_back(jsEngine->NewValue(notificationId));
313 func->Call(params);
314 }
315
260 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 316 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
261 ContentType contentType, 317 ContentType contentType,
262 const std::string& documentUrl) const 318 const std::string& documentUrl) const
263 { 319 {
264 std::vector<std::string> documentUrls; 320 std::vector<std::string> documentUrls;
265 documentUrls.push_back(documentUrl); 321 documentUrls.push_back(documentUrl);
266 return Matches(url, contentType, documentUrls); 322 return Matches(url, contentType, documentUrls);
267 } 323 }
268 324
269 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 325 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 460 }
405 461
406 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 462 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
407 { 463 {
408 JsValueList params; 464 JsValueList params;
409 params.push_back(jsEngine->NewValue(v1)); 465 params.push_back(jsEngine->NewValue(v1));
410 params.push_back(jsEngine->NewValue(v2)); 466 params.push_back(jsEngine->NewValue(v2));
411 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 467 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
412 return func->Call(params)->AsInt(); 468 return func->Call(params)->AsInt();
413 } 469 }
OLDNEW
« no previous file with comments | « libadblockplus.gyp ('k') | src/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld