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: fix JsValue destructor Created Jan. 22, 2016, 1:16 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
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 bool FilterEngine::IsFirstRun() const 220 bool FilterEngine::IsFirstRun() const
221 { 221 {
222 return firstRun; 222 return firstRun;
223 } 223 }
224 224
225 FilterPtr FilterEngine::GetFilter(const std::string& text) 225 FilterPtr FilterEngine::GetFilter(const std::string& text)
226 { 226 {
227 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); 227 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText");
228 JsValueList params; 228 JsValueList params;
229 params.push_back(jsEngine->NewValue(text)); 229 params.push_back(jsEngine->NewValue(text));
230 return FilterPtr(new Filter(func->Call(params))); 230 return FilterPtr(new Filter(std::move(*func->Call(params))));
231 } 231 }
232 232
233 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) 233 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url)
234 { 234 {
235 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); 235 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl");
236 JsValueList params; 236 JsValueList params;
237 params.push_back(jsEngine->NewValue(url)); 237 params.push_back(jsEngine->NewValue(url));
238 return SubscriptionPtr(new Subscription(func->Call(params))); 238 return SubscriptionPtr(new Subscription(std::move(*func->Call(params))));
239 } 239 }
240 240
241 std::vector<FilterPtr> FilterEngine::GetListedFilters() const 241 std::vector<FilterPtr> FilterEngine::GetListedFilters() const
242 { 242 {
243 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); 243 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters");
244 JsValueList values = func->Call()->AsList(); 244 JsValueList values = func->Call()->AsList();
245 std::vector<FilterPtr> result; 245 std::vector<FilterPtr> result;
246 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 246 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
247 result.push_back(FilterPtr(new Filter(*it))); 247 result.push_back(FilterPtr(new Filter(std::move(**it))));
248 return result; 248 return result;
249 } 249 }
250 250
251 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const 251 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const
252 { 252 {
253 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); 253 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions");
254 JsValueList values = func->Call()->AsList(); 254 JsValueList values = func->Call()->AsList();
255 std::vector<SubscriptionPtr> result; 255 std::vector<SubscriptionPtr> result;
256 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 256 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
257 result.push_back(SubscriptionPtr(new Subscription(*it))); 257 result.push_back(SubscriptionPtr(new Subscription(std::move(**it))));
258 return result; 258 return result;
259 } 259 }
260 260
261 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const 261 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const
262 { 262 {
263 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); 263 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions");
264 JsValueList values = func->Call()->AsList(); 264 JsValueList values = func->Call()->AsList();
265 std::vector<SubscriptionPtr> result; 265 std::vector<SubscriptionPtr> result;
266 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 266 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
267 result.push_back(SubscriptionPtr(new Subscription(*it))); 267 result.push_back(SubscriptionPtr(new Subscription(std::move(**it))));
268 return result; 268 return result;
269 } 269 }
270 270
271 void FilterEngine::ShowNextNotification(const std::string& url) 271 void FilterEngine::ShowNextNotification(const std::string& url)
272 { 272 {
273 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); 273 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification");
274 JsValueList params; 274 JsValueList params;
275 if (!url.empty()) 275 if (!url.empty())
276 { 276 {
277 params.push_back(jsEngine->NewValue(url)); 277 params.push_back(jsEngine->NewValue(url));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 ContentType contentType, 341 ContentType contentType,
342 const std::string& documentUrl) const 342 const std::string& documentUrl) const
343 { 343 {
344 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); 344 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch");
345 JsValueList params; 345 JsValueList params;
346 params.push_back(jsEngine->NewValue(url)); 346 params.push_back(jsEngine->NewValue(url));
347 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); 347 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType)));
348 params.push_back(jsEngine->NewValue(documentUrl)); 348 params.push_back(jsEngine->NewValue(documentUrl));
349 JsValuePtr result = func->Call(params); 349 JsValuePtr result = func->Call(params);
350 if (!result->IsNull()) 350 if (!result->IsNull())
351 return FilterPtr(new Filter(result)); 351 return FilterPtr(new Filter(std::move(*result)));
352 else 352 else
353 return FilterPtr(); 353 return FilterPtr();
354 } 354 }
355 355
356 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const 356 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const
357 { 357 {
358 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 358 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
359 JsValueList params; 359 JsValueList params;
360 params.push_back(jsEngine->NewValue(domain)); 360 params.push_back(jsEngine->NewValue(domain));
361 JsValueList result = func->Call(params)->AsList(); 361 JsValueList result = func->Call(params)->AsList();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback, 455 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback,
456 const JsValueList& params) 456 const JsValueList& params)
457 { 457 {
458 if (params.size() < 1) 458 if (params.size() < 1)
459 return; 459 return;
460 460
461 if (!params[0]->IsObject()) 461 if (!params[0]->IsObject())
462 { 462 {
463 return; 463 return;
464 } 464 }
465 callback(NotificationPtr(new Notification(params[0]))); 465 callback(NotificationPtr(new Notification(std::move(*params[0]))));
466 } 466 }
467 467
468 468
469 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 469 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
470 { 470 {
471 JsValueList params; 471 JsValueList params;
472 params.push_back(jsEngine->NewValue(v1)); 472 params.push_back(jsEngine->NewValue(v1));
473 params.push_back(jsEngine->NewValue(v2)); 473 params.push_back(jsEngine->NewValue(v2));
474 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 474 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
475 return func->Call(params)->AsInt(); 475 return func->Call(params)->AsInt();
(...skipping 28 matching lines...) Expand all
504 currentUrl, contentType, parentUrl); 504 currentUrl, contentType, parentUrl);
505 if (filter) 505 if (filter)
506 { 506 {
507 return filter; 507 return filter;
508 } 508 }
509 currentUrl = parentUrl; 509 currentUrl = parentUrl;
510 } 510 }
511 while (urlIterator != documentUrls.end()); 511 while (urlIterator != documentUrls.end());
512 return FilterPtr(); 512 return FilterPtr();
513 } 513 }
OLDNEW

Powered by Google App Engine
This is Rietveld