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, |
138 std::map<std::string, AdblockPlus::JsValuePtr> preconfiguredPrefs) | |
138 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) | 139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) |
139 { | 140 { |
140 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, | 141 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, |
141 this, std::tr1::placeholders::_1)); | 142 this, std::tr1::placeholders::_1)); |
142 | 143 |
143 { | 144 { |
144 // Lock the JS engine while we are loading scripts, no timeouts should fire | 145 // Lock the JS engine while we are loading scripts, no timeouts should fire |
145 // until we are done. | 146 // until we are done. |
146 const JsContext context(jsEngine); | 147 const JsContext context(jsEngine); |
148 | |
149 // Set the preconfigured prefs | |
150 JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject(); | |
151 for (std::map<std::string, AdblockPlus::JsValuePtr>::iterator it = | |
152 preconfiguredPrefs.begin(); | |
153 it != preconfiguredPrefs.end(); it++) | |
154 { | |
155 preconfiguredPrefsObject->SetProperty(it->first, it->second); | |
156 } | |
157 JsValuePtr globalJsObject = jsEngine->GetGlobalJsObject(); | |
158 globalJsObject->SetProperty("_preconfiguredPrefs", preconfiguredPrefsObject) ; | |
Eric
2015/06/10 17:48:16
Apart from initialization (where 'GetGlobalJsObjec
Felix Dahlke
2015/06/11 20:21:13
For the record: I asked for it this way. But Eric'
Oleksandr
2015/06/12 10:47:57
Done.
| |
159 | |
160 // Load adblockplus scripts | |
147 for (int i = 0; !jsSources[i].empty(); i += 2) | 161 for (int i = 0; !jsSources[i].empty(); i += 2) |
148 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); | 162 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); |
149 } | 163 } |
150 | 164 |
151 // TODO: This should really be implemented via a conditional variable | 165 // TODO: This should really be implemented via a conditional variable |
152 while (!initialized) | 166 while (!initialized) |
153 ::Sleep(10); | 167 ::Sleep(10); |
154 } | 168 } |
155 | 169 |
156 namespace | 170 namespace |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 } | 429 } |
416 | 430 |
417 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 431 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
418 { | 432 { |
419 JsValueList params; | 433 JsValueList params; |
420 params.push_back(jsEngine->NewValue(v1)); | 434 params.push_back(jsEngine->NewValue(v1)); |
421 params.push_back(jsEngine->NewValue(v2)); | 435 params.push_back(jsEngine->NewValue(v2)); |
422 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 436 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
423 return func->Call(params)->AsInt(); | 437 return func->Call(params)->AsInt(); |
424 } | 438 } |
OLD | NEW |