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

Unified Diff: libadblockplus-android/jni/JniWebRequest.cpp

Issue 29678581: Issue 6000 - Rename "libadblockplus-android" (Closed)
Patch Set: addressed comments Created Jan. 29, 2018, 11:04 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « libadblockplus-android/jni/JniWebRequest.h ('k') | libadblockplus-android/jni/Utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libadblockplus-android/jni/JniWebRequest.cpp
diff --git a/libadblockplus-android/jni/JniWebRequest.cpp b/libadblockplus-android/jni/JniWebRequest.cpp
deleted file mode 100644
index 2e309007b61d0e218c9ac7a5c30cca67ee3248cd..0000000000000000000000000000000000000000
--- a/libadblockplus-android/jni/JniWebRequest.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * This file is part of Adblock Plus <https://adblockplus.org/>,
- * Copyright (C) 2006-present eyeo GmbH
- *
- * Adblock Plus is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * Adblock Plus is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "JniCallbacks.h"
-#include "JniWebRequest.h"
-
-// precached in JNI_OnLoad and released in JNI_OnUnload
-JniGlobalReference<jclass>* headerEntryClass;
-JniGlobalReference<jclass>* serverResponseClass;
-
-void JniWebRequest_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved)
-{
- headerEntryClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("HeaderEntry")));
- serverResponseClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("ServerResponse")));
-}
-
-void JniWebRequest_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved)
-{
- if (headerEntryClass)
- {
- delete headerEntryClass;
- headerEntryClass = NULL;
- }
-
- if (serverResponseClass)
- {
- delete serverResponseClass;
- serverResponseClass = NULL;
- }
-}
-
-JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject)
- : JniCallbackBase(env, callbackObject)
-{
-}
-
-AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url,
- const AdblockPlus::HeaderList& requestHeaders) const
-{
- JNIEnvAcquire env(GetJavaVM());
-
- jmethodID method = env->GetMethodID(
- *JniLocalReference<jclass>(*env,
- env->GetObjectClass(GetCallbackObject())),
- "httpGET",
- "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse"));
-
- AdblockPlus::ServerResponse sResponse;
- sResponse.status = AdblockPlus::IWebRequest::NS_ERROR_FAILURE;
-
- if (method)
- {
- JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env));
- jmethodID addMethod = JniGetAddToListMethod(*env, *arrayList);
-
- for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(),
- end = requestHeaders.end(); it != end; it++)
- {
- JniLocalReference<jobject> headerEntry(*env, NewTuple(*env, it->first, it->second));
- JniAddObjectToList(*env, *arrayList, addMethod, *headerEntry);
- }
-
- JniLocalReference<jobject> response(*env,
- env->CallObjectMethod(GetCallbackObject(), method,
- *JniLocalReference<jstring>(*env, env->NewStringUTF(url.c_str())),
- *arrayList));
-
- if (!env->ExceptionCheck())
- {
- sResponse.status = JniGetLongField(*env, serverResponseClass->Get(),
- *response, "status");
- sResponse.responseStatus = JniGetIntField(*env,
- serverResponseClass->Get(),
- *response,
- "responseStatus");
- sResponse.responseText = JniGetStringField(*env,
- serverResponseClass->Get(),
- *response,
- "response");
-
- // map headers
- jobjectArray responseHeadersArray = JniGetStringArrayField(*env,
- serverResponseClass->Get(),
- *response,
- "headers");
-
- if (responseHeadersArray)
- {
- int itemsCount = env->GetArrayLength(responseHeadersArray) / 2;
- for (int i = 0; i < itemsCount; i++)
- {
- jstring jKey = (jstring)env->GetObjectArrayElement(responseHeadersArray, i * 2);
- std::string stdKey = JniJavaToStdString(*env, jKey);
-
- jstring jValue = (jstring)env->GetObjectArrayElement(responseHeadersArray, i * 2 + 1);
- std::string stdValue = JniJavaToStdString(*env, jValue);
-
- std::pair<std::string,std::string> keyValue(stdKey, stdValue);
- sResponse.responseHeaders.push_back(keyValue);
- }
- }
- }
- }
-
- CheckAndLogJavaException(*env);
-
- return sResponse;
-}
-
-jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a,
- const std::string& b) const
-{
- jmethodID factory = env->GetMethodID(headerEntryClass->Get(), "<init>",
- "(Ljava/lang/String;Ljava/lang/String;)V");
-
- JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str()));
- JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str()));
-
- return env->NewObject(headerEntryClass->Get(), factory, *strA, *strB);
-}
« no previous file with comments | « libadblockplus-android/jni/JniWebRequest.h ('k') | libadblockplus-android/jni/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld