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

Delta Between Two Patch Sets: jni/abpEngine.cpp

Issue 6693736058716160: Catch all exceptions from libadblockplus and rethrow them as Java exceptions (Closed)
Left Patch Set: Created Nov. 16, 2013, 4:15 p.m.
Right Patch Set: Rebased on branch libadblockplus Created Nov. 18, 2013, 3:58 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 11 matching lines...) Expand all
22 #include "Utils.h" 22 #include "Utils.h"
23 #include "debug.h" 23 #include "debug.h"
24 24
25 JavaVM* globalJvm; 25 JavaVM* globalJvm;
26 AdblockPlus::FilterEngine* filterEngine; 26 AdblockPlus::FilterEngine* filterEngine;
27 jobject jniObject; 27 jobject jniObject;
28 bool manualUpdate = false; 28 bool manualUpdate = false;
29 29
30 extern "C" 30 extern "C"
31 { 31 {
32 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_initialize(JNIEn v *pEnv, jobject, jstring basepath); 32 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_initialize(
33 JNIEnv *pEnv, jobject object, jstring basePath, jstring version,
34 jstring sdkVersion, jstring locale, jboolean developmentBuild);
33 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_release(JNIEnv * pEnv, jobject); 35 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_release(JNIEnv * pEnv, jobject);
34 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_isFirstRun(J NIEnv *pEnv, jobject); 36 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_isFirstRun(J NIEnv *pEnv, jobject);
35 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getListe dSubscriptions(JNIEnv *pEnv, jobject); 37 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getListe dSubscriptions(JNIEnv *pEnv, jobject);
36 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getRecom mendedSubscriptions(JNIEnv *pEnv, jobject); 38 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getRecom mendedSubscriptions(JNIEnv *pEnv, jobject);
37 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_addSubscription( JNIEnv *pEnv, jobject, jstring url); 39 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_addSubscription( JNIEnv *pEnv, jobject, jstring url);
38 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_removeSubscripti on(JNIEnv *pEnv, jobject, jstring url); 40 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_removeSubscripti on(JNIEnv *pEnv, jobject, jstring url);
39 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_refreshSubscript ion(JNIEnv *pEnv, jobject, jstring url); 41 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_refreshSubscript ion(JNIEnv *pEnv, jobject, jstring url);
40 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_actualizeSubscri ptionStatus(JNIEnv *pEnv, jobject, jstring url); 42 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_actualizeSubscri ptionStatus(JNIEnv *pEnv, jobject, jstring url);
41 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_matches(JNIE nv *pEnv, jobject, jstring url, jstring contentType, jstring documentUrl); 43 JNIEXPORT jboolean JNICALL Java_org_adblockplus_android_ABPEngine_matches(JNIE nv *pEnv, jobject, jstring url, jstring contentType, jstring documentUrl);
42 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getSelec torsForDomain(JNIEnv *pEnv, jobject, jstring domain); 44 JNIEXPORT jobjectArray JNICALL Java_org_adblockplus_android_ABPEngine_getSelec torsForDomain(JNIEnv *pEnv, jobject, jstring domain);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 203
202 jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) 204 jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
203 { 205 {
204 return JNI_VERSION_1_6; 206 return JNI_VERSION_1_6;
205 } 207 }
206 208
207 void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) 209 void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
208 { 210 {
209 } 211 }
210 212
211 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_initialize(JNIEnv *pEnv, jobject pObject, jstring basepath) 213 JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_initialize(
214 JNIEnv *pEnv, jobject pObject, jstring basePath, jstring version,
215 jstring sdkVersion, jstring locale, jboolean developmentBuild)
212 { 216 {
213 D(D_WARN, "nativeInitialize()"); 217 D(D_WARN, "nativeInitialize()");
214 try 218 try
215 { 219 {
216 int status = pEnv->GetJavaVM(&globalJvm); 220 int status = pEnv->GetJavaVM(&globalJvm);
217 221
218 jniObject = pEnv->NewGlobalRef(pObject); 222 jniObject = pEnv->NewGlobalRef(pObject);
219 223
220 const std::string path = GetString(pEnv, basepath);
221
222 AdblockPlus::AppInfo appInfo; 224 AdblockPlus::AppInfo appInfo;
223 // TODO Should be extracted from the manifest
224 appInfo.version = "1.1.2";
225 appInfo.name = "adblockplusandroid"; 225 appInfo.name = "adblockplusandroid";
226 appInfo.version = GetString(pEnv, version);
226 appInfo.application = "android"; 227 appInfo.application = "android";
228 appInfo.applicationVersion = GetString(pEnv, sdkVersion);
229 appInfo.locale = GetString(pEnv, locale);
230 appInfo.developmentBuild = developmentBuild;
231
232 D(D_INFO, "AppInfo: name=%s, version=%s, application=%s, applicationVersion= %s , locale=%s, developmentBuild=%s",
233 appInfo.name.c_str(), appInfo.version.c_str(), appInfo.application.c_str() ,
234 appInfo.applicationVersion.c_str(), appInfo.locale.c_str(),
235 appInfo.developmentBuild ? "true" : "false");
227 236
228 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New(appInfo)); 237 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New(appInfo));
229 238
230 AdblockPlus::DefaultFileSystem* defaultFileSystem = new AdblockPlus::Default FileSystem(); 239 AdblockPlus::DefaultFileSystem* defaultFileSystem = new AdblockPlus::Default FileSystem();
231 AndroidLogSystem* androidLogSystem = new AndroidLogSystem(); 240 AndroidLogSystem* androidLogSystem = new AndroidLogSystem();
232 AndroidWebRequest* androidWebRequest = new AndroidWebRequest(globalJvm); 241 AndroidWebRequest* androidWebRequest = new AndroidWebRequest(globalJvm);
233 242
234 defaultFileSystem->SetBasePath(path); 243 defaultFileSystem->SetBasePath(GetString(pEnv, basePath));
235 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(androidLogSystem)); 244 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(androidLogSystem));
236 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(defaultFileSystem)); 245 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(defaultFileSystem));
237 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(androidWebRequest)); 246 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(androidWebRequest));
238 jsEngine->SetEventCallback("updateAvailable", std::tr1::bind(&UpdateAvailabl eCallback, std::tr1::placeholders::_1)); 247 jsEngine->SetEventCallback("updateAvailable", std::tr1::bind(&UpdateAvailabl eCallback, std::tr1::placeholders::_1));
239 248
240 filterEngine = new AdblockPlus::FilterEngine(jsEngine); 249 filterEngine = new AdblockPlus::FilterEngine(jsEngine);
241 filterEngine->SetFilterChangeCallback(&FilterChangedCallback); 250 filterEngine->SetFilterChangeCallback(&FilterChangedCallback);
242 } 251 }
243 catch (const std::exception& e) 252 catch (const std::exception& e)
244 { 253 {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 492 }
484 catch (const std::exception& e) 493 catch (const std::exception& e)
485 { 494 {
486 ThrowJavaException(pEnv, e); 495 ThrowJavaException(pEnv, e);
487 } 496 }
488 catch (...) 497 catch (...)
489 { 498 {
490 ThrowJavaException(pEnv); 499 ThrowJavaException(pEnv);
491 } 500 }
492 } 501 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld