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

Side by Side Diff: libadblockplus-android/jni/JniWebRequest.cpp

Issue 29453616: Issue 5286 - Update to use libadblockplus rev. b88d098aeab5 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: Created June 1, 2017, 1:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 30 matching lines...) Expand all
41 { 41 {
42 delete serverResponseClass; 42 delete serverResponseClass;
43 serverResponseClass = NULL; 43 serverResponseClass = NULL;
44 } 44 }
45 } 45 }
46 46
47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) 47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject)
48 { 48 {
49 try 49 try
50 { 50 {
51 return JniPtrToLong(new AdblockPlus::WebRequestPtr(new JniWebRequest(env, ca llbackObject))); 51 return JniPtrToLong(new AdblockPlus::WebRequestSharedPtr(std::make_shared<Jn iWebRequest>(env, callbackObject)));
52 } 52 }
53 CATCH_THROW_AND_RETURN(env, 0) 53 CATCH_THROW_AND_RETURN(env, 0)
54 } 54 }
55 55
56 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 56 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
57 { 57 {
58 delete JniLongToTypePtr<AdblockPlus::WebRequestPtr>(ptr); 58 delete JniLongToTypePtr<AdblockPlus::WebRequestPtr>(ptr);
anton 2017/06/02 06:55:23 don't we have to cast it to WebRequestSharedPtr? (
sergei 2017/06/02 07:32:43 Good catch.
59 } 59 }
60 60
61 JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject) 61 JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject)
62 : JniCallbackBase(env, callbackObject), AdblockPlus::WebRequest() 62 : JniCallbackBase(env, callbackObject), AdblockPlus::WebRequest()
63 { 63 {
64 } 64 }
65 65
66 AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, 66 AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url,
67 const AdblockPlus::HeaderList& requestHeaders) const 67 const AdblockPlus::HeaderList& requestHeaders) const
68 { 68 {
69 JNIEnvAcquire env(GetJavaVM()); 69 JNIEnvAcquire env(GetJavaVM());
70 70
71 jmethodID method = env->GetMethodID( 71 jmethodID method = env->GetMethodID(
72 *JniLocalReference<jclass>(*env, 72 *JniLocalReference<jclass>(*env,
73 env->GetObjectClass(GetCallbackObject())), 73 env->GetObjectClass(GetCallbackObject())),
74 "httpGET", 74 "httpGET",
75 "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse")); 75 "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse"));
76 76
77 AdblockPlus::ServerResponse sResponse; 77 AdblockPlus::ServerResponse sResponse;
78 sResponse.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; 78 sResponse.status = AdblockPlus::IWebRequest::NS_ERROR_FAILURE;
79 79
80 if (method) 80 if (method)
81 { 81 {
82 JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env)); 82 JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env));
83 jmethodID addMethod = JniGetAddToListMethod(*env, *arrayList); 83 jmethodID addMethod = JniGetAddToListMethod(*env, *arrayList);
84 84
85 for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(), 85 for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(),
86 end = requestHeaders.end(); it != end; it++) 86 end = requestHeaders.end(); it != end; it++)
87 { 87 {
88 JniLocalReference<jobject> headerEntry(*env, NewTuple(*env, it->first, it- >second)); 88 JniLocalReference<jobject> headerEntry(*env, NewTuple(*env, it->first, it- >second));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 static JNINativeMethod methods[] = 151 static JNINativeMethod methods[] =
152 { 152 {
153 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 153 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
154 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 154 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
155 }; 155 };
156 156
157 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz) 157 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz)
158 { 158 {
159 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 159 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
160 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld