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: Created April 26, 2017, 6:48 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 AdblockPlus::JsValue* jsValue = JniGetJsValuePtr(ptr); 159 return NewJniJsValue(env, JniGetJsValuePtr(ptr)->GetProperty(JniJavaToStdStr ing(env, name)));
162 return NewJniJsValue(env, jsValue->GetProperty(JniJavaToStdString(env, name) ));
163 } 160 }
164 CATCH_THROW_AND_RETURN(env, 0) 161 CATCH_THROW_AND_RETURN(env, 0)
165 } 162 }
166 163
167 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 164 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
168 { 165 {
169 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 166 delete JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
170 } 167 }
171 168
172 jobject NewJniJsValue(JNIEnv* env, const AdblockPlus::JsValue& jsValue, jclass j sValueClassArg) 169 jobject NewJniJsValue(JNIEnv* env, AdblockPlus::JsValue&& jsValue, jclass jsValu eClassArg)
173 { 170 {
174 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)));
175 } 172 }
176 173
177 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr) 174 AdblockPlus::JsValue* JniGetJsValuePtr(jlong ptr)
178 { 175 {
179 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 176 return JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
180 } 177 }
181 178
182 AdblockPlus::JsValue& JniGetJsValue(jlong ptr) 179 AdblockPlus::JsValue& JniGetJsValue(jlong ptr)
183 { 180 {
184 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr); 181 return *JniLongToTypePtr<AdblockPlus::JsValue>(ptr);
185 } 182 }
186 183
187 jobject JniJsValueListToArrayList(JNIEnv* env, const AdblockPlus::JsValueList& l ist) 184 jobject JniJsValueListToArrayList(JNIEnv* env, AdblockPlus::JsValueList&& list)
188 { 185 {
189 jobject arrayList = NewJniArrayList(env); 186 jobject arrayList = NewJniArrayList(env);
190 187
191 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)
192 { 189 {
193 JniAddObjectToList(env, arrayList, 190 JniAddObjectToList(env, arrayList, *JniLocalReference<jobject>(env, NewJniJs Value(env, std::move(*it))));
194 *JniLocalReference<jobject>(env, NewJniJsValue(env, *it)));
195 } 191 }
196 192
197 return arrayList; 193 return arrayList;
198 } 194 }
199 195
200 // TODO: List of functions that lack JNI bindings 196 // TODO: List of functions that lack JNI bindings
201 //std::vector<std::string> GetOwnPropertyNames() const; 197 //std::vector<std::string> GetOwnPropertyNames() const;
202 //void SetProperty(const std::string& name, const std::string& val); 198 //void SetProperty(const std::string& name, const std::string& val);
203 //void SetProperty(const std::string& name, int64_t val); 199 //void SetProperty(const std::string& name, int64_t val);
204 //void SetProperty(const std::string& name, bool val); 200 //void SetProperty(const std::string& name, bool val);
(...skipping 18 matching lines...) Expand all
223 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean }, 219 { (char*)"asBoolean", (char*)"(J)Z", (void*)JniAsBoolean },
224 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList }, 220 { (char*)"asList", (char*)"(J)Ljava/util/List;", (void*)JniAsList },
225 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*) JniGetProperty }, 221 { (char*)"getProperty", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*) JniGetProperty },
226 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 222 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
227 }; 223 };
228 224
229 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)
230 { 226 {
231 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 227 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
232 } 228 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld