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

Side by Side Diff: src/FilterEngine.cpp

Issue 29334678: Issue 3589 - Change return type of AdblockPlus::JsValue::Call from pointer to r-value object. (Closed)
Patch Set: Created Jan. 27, 2016, 11:17 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/JsValue.h ('k') | src/JsValue.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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return TYPE_COMMENT; 50 return TYPE_COMMENT;
51 else 51 else
52 return TYPE_INVALID; 52 return TYPE_INVALID;
53 } 53 }
54 54
55 bool Filter::IsListed() 55 bool Filter::IsListed()
56 { 56 {
57 JsValuePtr func = jsEngine->Evaluate("API.isListedFilter"); 57 JsValuePtr func = jsEngine->Evaluate("API.isListedFilter");
58 JsValueList params; 58 JsValueList params;
59 params.push_back(shared_from_this()); 59 params.push_back(shared_from_this());
60 return func->Call(params)->AsBool(); 60 return func->Call(params).AsBool();
61 } 61 }
62 62
63 void Filter::AddToList() 63 void Filter::AddToList()
64 { 64 {
65 JsValuePtr func = jsEngine->Evaluate("API.addFilterToList"); 65 JsValuePtr func = jsEngine->Evaluate("API.addFilterToList");
66 JsValueList params; 66 JsValueList params;
67 params.push_back(shared_from_this()); 67 params.push_back(shared_from_this());
68 func->Call(params); 68 func->Call(params);
69 } 69 }
70 70
(...skipping 15 matching lines...) Expand all
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());
96 return func->Call(params)->AsBool(); 96 return func->Call(params).AsBool();
97 } 97 }
98 98
99 void Subscription::AddToList() 99 void Subscription::AddToList()
100 { 100 {
101 JsValuePtr func = jsEngine->Evaluate("API.addSubscriptionToList"); 101 JsValuePtr func = jsEngine->Evaluate("API.addSubscriptionToList");
102 JsValueList params; 102 JsValueList params;
103 params.push_back(shared_from_this()); 103 params.push_back(shared_from_this());
104 func->Call(params); 104 func->Call(params);
105 } 105 }
106 106
(...skipping 11 matching lines...) Expand all
118 JsValueList params; 118 JsValueList params;
119 params.push_back(shared_from_this()); 119 params.push_back(shared_from_this());
120 func->Call(params); 120 func->Call(params);
121 } 121 }
122 122
123 bool Subscription::IsUpdating() 123 bool Subscription::IsUpdating()
124 { 124 {
125 JsValuePtr func = jsEngine->Evaluate("API.isSubscriptionUpdating"); 125 JsValuePtr func = jsEngine->Evaluate("API.isSubscriptionUpdating");
126 JsValueList params; 126 JsValueList params;
127 params.push_back(shared_from_this()); 127 params.push_back(shared_from_this());
128 JsValuePtr result = func->Call(params); 128 JsValue result = func->Call(params);
129 return result->AsBool(); 129 return result.AsBool();
130 } 130 }
131 131
132 bool Subscription::operator==(const Subscription& subscription) const 132 bool Subscription::operator==(const Subscription& subscription) const
133 { 133 {
134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring(); 134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring();
135 } 135 }
136 136
137 FilterEngine::FilterEngine(JsEnginePtr jsEngine, 137 FilterEngine::FilterEngine(JsEnginePtr jsEngine,
138 const FilterEngine::Prefs& preconfiguredPrefs) 138 const FilterEngine::Prefs& preconfiguredPrefs)
139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) 139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0)
(...skipping 80 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(std::move(*func->Call(params)))); 230 return FilterPtr(new Filter(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(std::move(*func->Call(params)))); 238 return SubscriptionPtr(new Subscription(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(std::move(**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(std::move(**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(std::move(**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;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 339
340 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, 340 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url,
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 JsValue result = func->Call(params);
350 if (!result->IsNull()) 350 if (!result.IsNull())
351 return FilterPtr(new Filter(std::move(*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();
362 std::vector<std::string> selectors; 362 std::vector<std::string> selectors;
363 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) 363 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it)
364 selectors.push_back((*it)->AsString()); 364 selectors.push_back((*it)->AsString());
365 return selectors; 365 return selectors;
366 } 366 }
367 367
368 JsValuePtr FilterEngine::GetPref(const std::string& pref) const 368 JsValuePtr FilterEngine::GetPref(const std::string& pref) const
369 { 369 {
370 JsValuePtr func = jsEngine->Evaluate("API.getPref"); 370 JsValuePtr func = jsEngine->Evaluate("API.getPref");
371 JsValueList params; 371 JsValueList params;
372 params.push_back(jsEngine->NewValue(pref)); 372 params.push_back(jsEngine->NewValue(pref));
373 return func->Call(params); 373 return std::make_shared<JsValue>(func->Call(params));
Oleksandr 2016/01/31 21:23:24 Nit: This reminds me - isn't it time to drop use o
Eric 2016/02/08 19:54:50 It's already been done in the libadblockplus repos
374 } 374 }
375 375
376 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) 376 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value)
377 { 377 {
378 JsValuePtr func = jsEngine->Evaluate("API.setPref"); 378 JsValuePtr func = jsEngine->Evaluate("API.setPref");
379 JsValueList params; 379 JsValueList params;
380 params.push_back(jsEngine->NewValue(pref)); 380 params.push_back(jsEngine->NewValue(pref));
381 params.push_back(value); 381 params.push_back(value);
382 func->Call(params); 382 func->Call(params);
383 } 383 }
384 384
385 std::string FilterEngine::GetHostFromURL(const std::string& url) 385 std::string FilterEngine::GetHostFromURL(const std::string& url)
386 { 386 {
387 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); 387 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl");
388 JsValueList params; 388 JsValueList params;
389 params.push_back(jsEngine->NewValue(url)); 389 params.push_back(jsEngine->NewValue(url));
390 return func->Call(params)->AsString(); 390 return func->Call(params).AsString();
391 } 391 }
392 392
393 void FilterEngine::SetUpdateAvailableCallback( 393 void FilterEngine::SetUpdateAvailableCallback(
394 FilterEngine::UpdateAvailableCallback callback) 394 FilterEngine::UpdateAvailableCallback callback)
395 { 395 {
396 jsEngine->SetEventCallback("updateAvailable", 396 jsEngine->SetEventCallback("updateAvailable",
397 std::bind(&FilterEngine::UpdateAvailable, this, callback, 397 std::bind(&FilterEngine::UpdateAvailable, this, callback,
398 std::placeholders::_1)); 398 std::placeholders::_1));
399 } 399 }
400 400
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 callback(NotificationPtr(new Notification(std::move(*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();
476 } 476 }
477 477
478 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, 478 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url,
479 ContentType contentType, const std::string& documentUrl) const 479 ContentType contentType, const std::string& documentUrl) const
480 { 480 {
481 FilterPtr match = Matches(url, contentType, documentUrl); 481 FilterPtr match = Matches(url, contentType, documentUrl);
482 if (match && match->GetType() == Filter::TYPE_EXCEPTION) 482 if (match && match->GetType() == Filter::TYPE_EXCEPTION)
483 { 483 {
484 return match; 484 return match;
485 } 485 }
(...skipping 18 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
« no previous file with comments | « include/AdblockPlus/JsValue.h ('k') | src/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld