Index: src/FilterEngine.cpp |
=================================================================== |
--- a/src/FilterEngine.cpp |
+++ b/src/FilterEngine.cpp |
@@ -16,16 +16,17 @@ |
*/ |
#include <algorithm> |
#include <cctype> |
#include <functional> |
#include <string> |
#include <AdblockPlus.h> |
+#include "Thread.h" |
using namespace AdblockPlus; |
extern std::string jsSources[]; |
Filter::Filter(JsValuePtr value) |
: JsValue(value) |
{ |
@@ -127,25 +128,31 @@ bool Subscription::IsUpdating() |
return result->AsBool(); |
} |
bool Subscription::operator==(const Subscription& subscription) const |
{ |
return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsString(); |
} |
-FilterEngine::FilterEngine(JsEnginePtr jsEngine) : jsEngine(jsEngine) |
+FilterEngine::FilterEngine(JsEnginePtr jsEngine) |
+ : jsEngine(jsEngine), initialized(false) |
{ |
+ jsEngine->SetInitCallback(std::tr1::bind(&FilterEngine::InitDone, this)); |
for (int i = 0; !jsSources[i].empty(); i += 2) |
jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); |
+ |
+ // TODO: This should really be implemented via a conditional variable |
+ while (!initialized) |
+ ::Sleep(10); |
} |
-bool FilterEngine::IsInitialized() const |
+void FilterEngine::InitDone() |
{ |
- return jsEngine->Evaluate("_abpInitialized")->AsBool(); |
+ initialized = true; |
} |
FilterPtr FilterEngine::GetFilter(const std::string& text) |
{ |
JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); |
JsValueList params; |
params.push_back(jsEngine->NewValue(text)); |
return FilterPtr(new Filter(func->Call(params))); |