 Issue 5653480979038208:
  Issue 2325 - Add a way to set settings in libadblockplus for FRP and automatic updates  (Closed)
    
  
    Issue 5653480979038208:
  Issue 2325 - Add a way to set settings in libadblockplus for FRP and automatic updates  (Closed) 
  | Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 params.push_back(shared_from_this()); | 127 params.push_back(shared_from_this()); | 
| 128 JsValuePtr result = func->Call(params); | 128 JsValuePtr 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, std::map<std::string, std::stri ng> preconfiguredPrefs) | 
| 138 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) | 138 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) | 
| 139 { | 139 { | 
| 140 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, | 140 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, | 
| 141 this, std::tr1::placeholders::_1)); | 141 this, std::tr1::placeholders::_1)); | 
| 142 | 142 | 
| 143 { | 143 { | 
| 144 // Lock the JS engine while we are loading scripts, no timeouts should fire | 144 // Lock the JS engine while we are loading scripts, no timeouts should fire | 
| 145 // until we are done. | 145 // until we are done. | 
| 146 const JsContext context(jsEngine); | 146 const JsContext context(jsEngine); | 
| 147 | |
| 148 // Set the precongiured prefs | |
| 149 jsEngine->Evaluate(std::string("var Preconfig = {};")); | |
| 
Felix Dahlke
2015/06/09 19:40:51
1. _preconfiguredPrefs would be a better name. We
 
Oleksandr
2015/06/10 08:40:30
I agree it was hacky, but it had it's advantages.
 | |
| 150 for (auto it = preconfiguredPrefs.begin(); it != preconfiguredPrefs.end(); i t++) | |
| 
Felix Dahlke
2015/06/09 19:40:51
It's still C++03 here.
 | |
| 151 { | |
| 152 jsEngine->Evaluate(std::string("Preconfig.") + it->first + std::string(" = ") + it->second); | |
| 153 } | |
| 154 | |
| 147 for (int i = 0; !jsSources[i].empty(); i += 2) | 155 for (int i = 0; !jsSources[i].empty(); i += 2) | 
| 148 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); | 156 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); | 
| 149 } | 157 } | 
| 150 | 158 | 
| 151 // TODO: This should really be implemented via a conditional variable | 159 // TODO: This should really be implemented via a conditional variable | 
| 152 while (!initialized) | 160 while (!initialized) | 
| 153 ::Sleep(10); | 161 ::Sleep(10); | 
| 154 } | 162 } | 
| 155 | 163 | 
| 156 namespace | 164 namespace | 
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 } | 423 } | 
| 416 | 424 | 
| 417 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 425 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 
| 418 { | 426 { | 
| 419 JsValueList params; | 427 JsValueList params; | 
| 420 params.push_back(jsEngine->NewValue(v1)); | 428 params.push_back(jsEngine->NewValue(v1)); | 
| 421 params.push_back(jsEngine->NewValue(v2)); | 429 params.push_back(jsEngine->NewValue(v2)); | 
| 422 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 430 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 
| 423 return func->Call(params)->AsInt(); | 431 return func->Call(params)->AsInt(); | 
| 424 } | 432 } | 
| OLD | NEW |