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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 5797488346791936: Issue 1107 - Support notifications (Closed)
Left Patch Set: Created Jan. 19, 2015, 12:50 p.m.
Right Patch Set: fix comment Created Jan. 23, 2015, 3:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « libadblockplus.gyp ('k') | src/Notification.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 260 NotificationPtr FilterEngine::GetNextNotificationToShow(const std::string& url)
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 { 261 {
267 JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow"); 262 JsValuePtr func = jsEngine->Evaluate("API.getNextNotificationToShow");
268 if (!func)
269 {
270 return std::tr1::shared_ptr<Notification>();
271 }
272 JsValueList params; 263 JsValueList params;
273 if (!url.empty()) 264 if (!url.empty())
274 { 265 {
275 params.push_back(jsEngine->NewValue(url)); 266 params.push_back(jsEngine->NewValue(url));
276 } 267 }
277 return Notification::JsValueToNotification(func->Call(params)); 268 return Notification::JsValueToNotification(func->Call(params));
278 }
279
280 NotificationTexts FilterEngine::GetNotificationTexts(const std::tr1::shared_ptr< Notification>& notification,
281 const std::string& locale ) const
282 {
283 JsValuePtr func = jsEngine->Evaluate("API.getNotificationTexts");
284 if (!func)
285 {
286 return NotificationTexts();
287 }
288 JsValueList params;
289 params.push_back(notification);
290 if (!locale.empty())
291 {
292 params.push_back(jsEngine->NewValue(locale));
293 }
294 auto jsTexts = func->Call(params);
295 if (!jsTexts)
296 {
297 return NotificationTexts();
298 }
299 return Notification::JsTextsToNotificationTexts(*jsTexts);
300 }
301
302 void FilterEngine::AddNotification(const std::tr1::shared_ptr<Notification>& val ue)
303 {
304 JsValuePtr func = jsEngine->Evaluate("API.addNotification");
305 if (!func)
306 {
307 return;
308 }
309 JsValueList params;
310 params.push_back(value);
311 func->Call(params);
312 }
313
314 void FilterEngine::RemoveNotification(const std::tr1::shared_ptr<Notification>& value)
315 {
316 JsValuePtr func = jsEngine->Evaluate("API.removeNotification");
317 if (!func)
318 {
319 return;
320 }
321 JsValueList params;
322 params.push_back(value);
323 func->Call(params);
324 }
325
326 void FilterEngine::MarkNotificationAsShown(const std::string& notificationId)
327 {
328 JsValuePtr func = jsEngine->Evaluate("API.markNotificationAsShown");
329 if (!func)
330 {
331 return;
332 }
333 JsValueList params;
334 params.push_back(jsEngine->NewValue(notificationId));
335 func->Call(params);
336 } 269 }
337 270
338 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 271 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
339 ContentType contentType, 272 ContentType contentType,
340 const std::string& documentUrl) const 273 const std::string& documentUrl) const
341 { 274 {
342 std::vector<std::string> documentUrls; 275 std::vector<std::string> documentUrls;
343 documentUrls.push_back(documentUrl); 276 documentUrls.push_back(documentUrl);
344 return Matches(url, contentType, documentUrls); 277 return Matches(url, contentType, documentUrls);
345 } 278 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 415 }
483 416
484 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 417 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
485 { 418 {
486 JsValueList params; 419 JsValueList params;
487 params.push_back(jsEngine->NewValue(v1)); 420 params.push_back(jsEngine->NewValue(v1));
488 params.push_back(jsEngine->NewValue(v2)); 421 params.push_back(jsEngine->NewValue(v2));
489 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 422 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
490 return func->Call(params)->AsInt(); 423 return func->Call(params)->AsInt();
491 } 424 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld