Beispiel #1
0
std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale)
{
  AdblockPlus::AppInfo appInfo;
  appInfo.version = ToUtf8String(IEPLUGIN_VERSION);
  appInfo.name = "adblockplusie";
#ifdef _WIN64
  appInfo.application = "msie64";
#else
  appInfo.application = "msie32";
#endif
  // TODO: Set applicationVersion parameter
  appInfo.locale = ToUtf8String(locale);
#ifdef ADBLOCK_PLUS_TEST_MODE
  appInfo.developmentBuild = true;
#else
  appInfo.developmentBuild = false;
#endif

  AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
  jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable);

  std::string dataPath = ToUtf8String(GetAppDataPath());
  dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())->SetBasePath(dataPath);
  std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterEngine(jsEngine));
  return filterEngine;
}
AdblockPlus::JsValuePtr AdblockPlus::ConsoleJsObject::Setup(
    AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj)
{
  obj->SetProperty("log", jsEngine->NewCallback(::LogCallback));
  obj->SetProperty("debug", jsEngine->NewCallback(::DebugCallback));
  obj->SetProperty("info", jsEngine->NewCallback(::InfoCallback));
  obj->SetProperty("warn", jsEngine->NewCallback(::WarnCallback));
  obj->SetProperty("error", jsEngine->NewCallback(::ErrorCallback));
  obj->SetProperty("trace", jsEngine->NewCallback(::TraceCallback));
  return obj;
}
JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_release(JNIEnv *pEnv, jobject)
{
    D(D_WARN, "nativeRelease()");
    try
    {
        AdblockPlus::JsEnginePtr jsEngine = filterEngine->GetJsEngine();
        jsEngine->RemoveEventCallback("updateAvailable");
        filterEngine->RemoveFilterChangeCallback();
        delete filterEngine;
        pEnv->DeleteGlobalRef(jniObject);
        jniObject = NULL;
        globalJvm = NULL;
    }
    catch (const std::exception& e)
    {
        ThrowJavaException(pEnv, e);
    }
    catch (...)
    {
        ThrowJavaException(pEnv);
    }
}
AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup(
    AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj)
{
  obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback));
  return obj;
}
AdblockPlus::JsValue::JsValue(AdblockPlus::JsEnginePtr jsEngine,
      v8::Handle<v8::Value> value)
    : jsEngine(jsEngine),
	value(new v8::UniquePersistent<v8::Value>(jsEngine->GetIsolate(), value))
{
}