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

Delta Between Two Patch Sets: libadblockplus-android/jni/JniJsValue.cpp

Issue 29422558: Issue 5167 - Update to use libadblockplus revision dca8df9af1a7 (Closed)
Left Patch Set: suggestions by Serge Created April 26, 2017, 10:22 a.m.
Right Patch Set: updated dependencies (..-binaries) Created May 10, 2017, 6:54 a.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 | « libadblockplus-android/jni/JniJsValue.h ('k') | libadblockplus-android/jni/JniNotification.cpp » ('j') | 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 { 140 {
141 return JniGetJsValuePtr(ptr)->AsBool() ? JNI_TRUE : JNI_FALSE; 141 return JniGetJsValuePtr(ptr)->AsBool() ? JNI_TRUE : JNI_FALSE;
142 } 142 }
143 CATCH_THROW_AND_RETURN(env, JNI_FALSE) 143 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
144 } 144 }
145 145
146 static jobject JNICALL JniAsList(JNIEnv* env, jclass clazz, jlong ptr) 146 static jobject JNICALL JniAsList(JNIEnv* env, jclass clazz, jlong ptr)
147 { 147 {
148 try 148 try
149 { 149 {
150 AdblockPlus::JsValueList list = JniGetJsValuePtr(ptr)->AsList(); 150 return JniJsValueListToArrayList(env, JniGetJsValuePtr(ptr)->AsList());
151
152 return JniJsValueListToArrayList(env, list);
153 } 151 }
154 CATCH_THROW_AND_RETURN(env, 0) 152 CATCH_THROW_AND_RETURN(env, 0)
155 } 153 }
156 154
157 static jobject JNICALL JniGetProperty(JNIEnv* env, jclass clazz, jlong ptr, jstr ing name) 155 static jobject JNICALL JniGetProperty(JNIEnv* env, jclass clazz, jlong ptr, jstr ing name)
158 { 156 {
159 try 157 try
160 { 158 {
161 return NewJniJsValue(env, JniGetJsValuePtr(ptr)->GetProperty(JniJavaToStdStr ing(env, name))); 159 return NewJniJsValue(env, JniGetJsValuePtr(ptr)->GetProperty(JniJavaToStdStr ing(env, name)));
162 } 160 }
163 CATCH_THROW_AND_RETURN(env, 0) 161 CATCH_THROW_AND_RETURN(env, 0)
164 } 162 }
165 163
166 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 164 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
167 { 165 {
168 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 166 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
169 } 167 }
170 168
171 jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValue& jsValue, jclass j sValueClassArg) 169 jobject NewJniJsValue(JNIEnv* env, AdblockPlus::JsValue&& jsValue, jclass jsValu eClassArg)
172 { 170 {
173 return env->NewObject(jsValueClass->Get(), jsValueCtor, new AdblockPlus::JsVal ue(jsValue)); 171 return env->NewObject(jsValueClass->Get(), jsValueCtor, new AdblockPlus::JsVal ue(std::move(jsValue)));
174 } 172 }
175 173
176 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr) 174 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr)
177 { 175 {
178 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 176 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
179 } 177 }
180 178
181 AdblockPlus::JsValue& JniGetJsValue(jlong ptr) 179 AdblockPlus::JsValue& JniGetJsValue(jlong ptr)
182 { 180 {
183 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 181 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
184 } 182 }
185 183
186 jobject JniJsValueListToArrayList(JNIEnv* env, const AdblockPlus::JsValueList& l ist) 184 jobject JniJsValueListToArrayList(JNIEnv* env, AdblockPlus::JsValueList&& list)
187 { 185 {
188 jobject arrayList = NewJniArrayList(env); 186 jobject arrayList = NewJniArrayList(env);
189 187
190 for (AdblockPlus::JsValueList::const_iterator it = list.begin(), end = list.en d(); it != end; ++it) 188 for (AdblockPlus::JsValueList::iterator it = list.begin(), end = list.end(); i t != end; ++it)
191 { 189 {
192 JniAddObjectToList(env, arrayList, 190 JniAddObjectToList(env, arrayList, *JniLocalReference<jobject>(env, NewJniJs Value(env, std::move(*it))));
193 *JniLocalReference<jobject>(env, NewJniJsValue(env, *it)));
194 } 191 }
195 192
196 return arrayList; 193 return arrayList;
197 } 194 }
198 195
199 // TODO: List of functions that lack JNI bindings 196 // TODO: List of functions that lack JNI bindings
200 //std::vector<std::string> GetOwnPropertyNames() const; 197 //std::vector<std::string> GetOwnPropertyNames() const;
201 //void SetProperty(const std::string& name, const std::string& val); 198 //void SetProperty(const std::string& name, const std::string& val);
202 //void SetProperty(const std::string& name, int64_t val); 199 //void SetProperty(const std::string& name, int64_t val);
203 //void SetProperty(const std::string& name, bool val); 200 //void SetProperty(const std::string& name, bool val);
(...skipping 18 matching lines...) Expand all
222 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, 219 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean },
223 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, 220 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList },
224 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*) JniGetProperty }, 221 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*) JniGetProperty },
225 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 222 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
226 }; 223 };
227 224
228 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re gisterNatives(JNIEnv *env, jclass clazz) 225 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsValue_re gisterNatives(JNIEnv *env, jclass clazz)
229 { 226 {
230 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 227 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
231 } 228 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld