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

Side by Side Diff: src/FilterEngine.cpp

Issue 5598762307158016: Issue 1550 - Get rid of V8ValueHolder.h (Closed)
Patch Set: rebase Created May 20, 2016, 3:20 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 | « include/AdblockPlus/V8ValueHolder.h ('k') | src/JsContext.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 10 matching lines...) Expand all
21 #include <string> 21 #include <string>
22 22
23 #include <AdblockPlus.h> 23 #include <AdblockPlus.h>
24 #include "JsContext.h" 24 #include "JsContext.h"
25 #include "Thread.h" 25 #include "Thread.h"
26 26
27 using namespace AdblockPlus; 27 using namespace AdblockPlus;
28 28
29 extern std::string jsSources[]; 29 extern std::string jsSources[];
30 30
31 Filter::Filter(JsValuePtr value) 31 Filter::Filter(JsValue&& value)
32 : JsValue(value) 32 : JsValue(std::move(value))
33 { 33 {
34 if (!IsObject()) 34 if (!IsObject())
35 throw std::runtime_error("JavaScript value is not an object"); 35 throw std::runtime_error("JavaScript value is not an object");
36 } 36 }
37 37
38 Filter::Type Filter::GetType() 38 Filter::Type Filter::GetType()
39 { 39 {
40 std::string className = GetClass(); 40 std::string className = GetClass();
41 if (className == "BlockingFilter") 41 if (className == "BlockingFilter")
42 return TYPE_BLOCKING; 42 return TYPE_BLOCKING;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 JsValueList params; 74 JsValueList params;
75 params.push_back(shared_from_this()); 75 params.push_back(shared_from_this());
76 func->Call(params); 76 func->Call(params);
77 } 77 }
78 78
79 bool Filter::operator==(const Filter& filter) const 79 bool Filter::operator==(const Filter& filter) const
80 { 80 {
81 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString (); 81 return GetProperty("text")->AsString() == filter.GetProperty("text")->AsString ();
82 } 82 }
83 83
84 Subscription::Subscription(JsValuePtr value) 84 Subscription::Subscription(JsValue&& value)
85 : JsValue(value) 85 : JsValue(std::move(value))
86 { 86 {
87 if (!IsObject()) 87 if (!IsObject())
88 throw std::runtime_error("JavaScript value is not an object"); 88 throw std::runtime_error("JavaScript value is not an object");
89 } 89 }
90 90
91 bool Subscription::IsListed() 91 bool Subscription::IsListed()
92 { 92 {
93 JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription"); 93 JsValuePtr func = jsEngine->Evaluate("API.isListedSubscription");
94 JsValueList params; 94 JsValueList params;
95 params.push_back(shared_from_this()); 95 params.push_back(shared_from_this());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 bool FilterEngine::IsFirstRun() const 223 bool FilterEngine::IsFirstRun() const
224 { 224 {
225 return firstRun; 225 return firstRun;
226 } 226 }
227 227
228 FilterPtr FilterEngine::GetFilter(const std::string& text) 228 FilterPtr FilterEngine::GetFilter(const std::string& text)
229 { 229 {
230 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); 230 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText");
231 JsValueList params; 231 JsValueList params;
232 params.push_back(jsEngine->NewValue(text)); 232 params.push_back(jsEngine->NewValue(text));
233 return FilterPtr(new Filter(func->Call(params))); 233 return FilterPtr(new Filter(std::move(*func->Call(params))));
234 } 234 }
235 235
236 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) 236 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url)
237 { 237 {
238 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); 238 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl");
239 JsValueList params; 239 JsValueList params;
240 params.push_back(jsEngine->NewValue(url)); 240 params.push_back(jsEngine->NewValue(url));
241 return SubscriptionPtr(new Subscription(func->Call(params))); 241 return SubscriptionPtr(new Subscription(std::move(*func->Call(params))));
242 } 242 }
243 243
244 std::vector<FilterPtr> FilterEngine::GetListedFilters() const 244 std::vector<FilterPtr> FilterEngine::GetListedFilters() const
245 { 245 {
246 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); 246 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters");
247 JsValueList values = func->Call()->AsList(); 247 JsValueList values = func->Call()->AsList();
248 std::vector<FilterPtr> result; 248 std::vector<FilterPtr> result;
249 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 249 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
250 result.push_back(FilterPtr(new Filter(*it))); 250 result.push_back(FilterPtr(new Filter(std::move(**it))));
251 return result; 251 return result;
252 } 252 }
253 253
254 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const 254 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const
255 { 255 {
256 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); 256 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions");
257 JsValueList values = func->Call()->AsList(); 257 JsValueList values = func->Call()->AsList();
258 std::vector<SubscriptionPtr> result; 258 std::vector<SubscriptionPtr> result;
259 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 259 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
260 result.push_back(SubscriptionPtr(new Subscription(*it))); 260 result.push_back(SubscriptionPtr(new Subscription(std::move(**it))));
261 return result; 261 return result;
262 } 262 }
263 263
264 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const 264 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const
265 { 265 {
266 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); 266 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions");
267 JsValueList values = func->Call()->AsList(); 267 JsValueList values = func->Call()->AsList();
268 std::vector<SubscriptionPtr> result; 268 std::vector<SubscriptionPtr> result;
269 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 269 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
270 result.push_back(SubscriptionPtr(new Subscription(*it))); 270 result.push_back(SubscriptionPtr(new Subscription(std::move(**it))));
271 return result; 271 return result;
272 } 272 }
273 273
274 void FilterEngine::ShowNextNotification(const std::string& url) 274 void FilterEngine::ShowNextNotification(const std::string& url)
275 { 275 {
276 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); 276 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification");
277 JsValueList params; 277 JsValueList params;
278 if (!url.empty()) 278 if (!url.empty())
279 { 279 {
280 params.push_back(jsEngine->NewValue(url)); 280 params.push_back(jsEngine->NewValue(url));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 ContentTypeMask contentTypeMask, 344 ContentTypeMask contentTypeMask,
345 const std::string& documentUrl) const 345 const std::string& documentUrl) const
346 { 346 {
347 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); 347 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch");
348 JsValueList params; 348 JsValueList params;
349 params.push_back(jsEngine->NewValue(url)); 349 params.push_back(jsEngine->NewValue(url));
350 params.push_back(jsEngine->NewValue(contentTypeMask)); 350 params.push_back(jsEngine->NewValue(contentTypeMask));
351 params.push_back(jsEngine->NewValue(documentUrl)); 351 params.push_back(jsEngine->NewValue(documentUrl));
352 JsValuePtr result = func->Call(params); 352 JsValuePtr result = func->Call(params);
353 if (!result->IsNull()) 353 if (!result->IsNull())
354 return FilterPtr(new Filter(result)); 354 return FilterPtr(new Filter(std::move(*result)));
355 else 355 else
356 return FilterPtr(); 356 return FilterPtr();
357 } 357 }
358 358
359 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const 359 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const
360 { 360 {
361 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 361 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
362 JsValueList params; 362 JsValueList params;
363 params.push_back(jsEngine->NewValue(domain)); 363 params.push_back(jsEngine->NewValue(domain));
364 JsValueList result = func->Call(params)->AsList(); 364 JsValueList result = func->Call(params)->AsList();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback, 458 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback,
459 const JsValueList& params) 459 const JsValueList& params)
460 { 460 {
461 if (params.size() < 1) 461 if (params.size() < 1)
462 return; 462 return;
463 463
464 if (!params[0]->IsObject()) 464 if (!params[0]->IsObject())
465 { 465 {
466 return; 466 return;
467 } 467 }
468 callback(NotificationPtr(new Notification(params[0]))); 468 callback(NotificationPtr(new Notification(std::move(*params[0]))));
469 } 469 }
470 470
471 471
472 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 472 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
473 { 473 {
474 JsValueList params; 474 JsValueList params;
475 params.push_back(jsEngine->NewValue(v1)); 475 params.push_back(jsEngine->NewValue(v1));
476 params.push_back(jsEngine->NewValue(v2)); 476 params.push_back(jsEngine->NewValue(v2));
477 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 477 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
478 return func->Call(params)->AsInt(); 478 return func->Call(params)->AsInt();
(...skipping 27 matching lines...) Expand all
506 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 506 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
507 if (filter) 507 if (filter)
508 { 508 {
509 return filter; 509 return filter;
510 } 510 }
511 currentUrl = parentUrl; 511 currentUrl = parentUrl;
512 } 512 }
513 while (urlIterator != documentUrls.end()); 513 while (urlIterator != documentUrls.end());
514 return FilterPtr(); 514 return FilterPtr();
515 } 515 }
OLDNEW
« no previous file with comments | « include/AdblockPlus/V8ValueHolder.h ('k') | src/JsContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld