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: Created Nov. 10, 2014, 9:18 a.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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 bool FilterEngine::IsFirstRun() const 208 bool FilterEngine::IsFirstRun() const
209 { 209 {
210 return firstRun; 210 return firstRun;
211 } 211 }
212 212
213 FilterPtr FilterEngine::GetFilter(const std::string& text) 213 FilterPtr FilterEngine::GetFilter(const std::string& text)
214 { 214 {
215 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); 215 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText");
216 JsValueList params; 216 JsValueList params;
217 params.push_back(jsEngine->NewValue(text)); 217 params.push_back(jsEngine->NewValue(text));
218 return FilterPtr(new Filter(func->Call(params))); 218 return FilterPtr(new Filter(std::move(*func->Call(params))));
219 } 219 }
220 220
221 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url) 221 SubscriptionPtr FilterEngine::GetSubscription(const std::string& url)
222 { 222 {
223 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); 223 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl");
224 JsValueList params; 224 JsValueList params;
225 params.push_back(jsEngine->NewValue(url)); 225 params.push_back(jsEngine->NewValue(url));
226 return SubscriptionPtr(new Subscription(func->Call(params))); 226 return SubscriptionPtr(new Subscription(std::move(*func->Call(params))));
227 } 227 }
228 228
229 std::vector<FilterPtr> FilterEngine::GetListedFilters() const 229 std::vector<FilterPtr> FilterEngine::GetListedFilters() const
230 { 230 {
231 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); 231 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters");
232 JsValueList values = func->Call()->AsList(); 232 JsValueList values = func->Call()->AsList();
233 std::vector<FilterPtr> result; 233 std::vector<FilterPtr> result;
234 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 234 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
235 result.push_back(FilterPtr(new Filter(*it))); 235 result.push_back(FilterPtr(new Filter(std::move(**it))));
236 return result; 236 return result;
237 } 237 }
238 238
239 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const 239 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const
240 { 240 {
241 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); 241 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions");
242 JsValueList values = func->Call()->AsList(); 242 JsValueList values = func->Call()->AsList();
243 std::vector<SubscriptionPtr> result; 243 std::vector<SubscriptionPtr> result;
244 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 244 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
245 result.push_back(SubscriptionPtr(new Subscription(*it))); 245 result.push_back(SubscriptionPtr(new Subscription(std::move(**it))));
246 return result; 246 return result;
247 } 247 }
248 248
249 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const 249 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const
250 { 250 {
251 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions"); 251 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions");
252 JsValueList values = func->Call()->AsList(); 252 JsValueList values = func->Call()->AsList();
253 std::vector<SubscriptionPtr> result; 253 std::vector<SubscriptionPtr> result;
254 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 254 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
255 result.push_back(SubscriptionPtr(new Subscription(*it))); 255 result.push_back(SubscriptionPtr(new Subscription(std::move(**it))));
256 return result; 256 return result;
257 } 257 }
258 258
259 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 259 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
260 ContentType contentType, 260 ContentType contentType,
261 const std::string& documentUrl) const 261 const std::string& documentUrl) const
262 { 262 {
263 std::vector<std::string> documentUrls; 263 std::vector<std::string> documentUrls;
264 documentUrls.push_back(documentUrl); 264 documentUrls.push_back(documentUrl);
265 return Matches(url, contentType, documentUrls); 265 return Matches(url, contentType, documentUrls);
(...skipping 25 matching lines...) Expand all
291 ContentType contentType, 291 ContentType contentType,
292 const std::string& documentUrl) const 292 const std::string& documentUrl) const
293 { 293 {
294 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); 294 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch");
295 JsValueList params; 295 JsValueList params;
296 params.push_back(jsEngine->NewValue(url)); 296 params.push_back(jsEngine->NewValue(url));
297 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); 297 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType)));
298 params.push_back(jsEngine->NewValue(documentUrl)); 298 params.push_back(jsEngine->NewValue(documentUrl));
299 JsValuePtr result = func->Call(params); 299 JsValuePtr result = func->Call(params);
300 if (!result->IsNull()) 300 if (!result->IsNull())
301 return FilterPtr(new Filter(result)); 301 return FilterPtr(new Filter(std::move(*result)));
302 else 302 else
303 return FilterPtr(); 303 return FilterPtr();
304 } 304 }
305 305
306 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const 306 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri ng& domain) const
307 { 307 {
308 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 308 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
309 JsValueList params; 309 JsValueList params;
310 params.push_back(jsEngine->NewValue(domain)); 310 params.push_back(jsEngine->NewValue(domain));
311 JsValueList result = func->Call(params)->AsList(); 311 JsValueList result = func->Call(params)->AsList();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 403 }
404 404
405 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 405 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
406 { 406 {
407 JsValueList params; 407 JsValueList params;
408 params.push_back(jsEngine->NewValue(v1)); 408 params.push_back(jsEngine->NewValue(v1));
409 params.push_back(jsEngine->NewValue(v2)); 409 params.push_back(jsEngine->NewValue(v2));
410 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 410 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
411 return func->Call(params)->AsInt(); 411 return func->Call(params)->AsInt();
412 } 412 }
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