| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
| 6 #include "base/android/jni_string.h" | 6 #include "base/android/jni_string.h" |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/android/cookies/cookies_fetcher.h" | 10 #include "chrome/browser/android/cookies/cookies_fetcher.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 | 68 |
| 69 store->GetAllCookiesAsync(base::Bind( | 69 store->GetAllCookiesAsync(base::Bind( |
| 70 &CookiesFetcher::OnCookiesFetchFinished, base::Unretained(this))); | 70 &CookiesFetcher::OnCookiesFetchFinished, base::Unretained(this))); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void CookiesFetcher::OnCookiesFetchFinished(const net::CookieList& cookies) { | 73 void CookiesFetcher::OnCookiesFetchFinished(const net::CookieList& cookies) { |
| 74 JNIEnv* env = base::android::AttachCurrentThread(); | 74 JNIEnv* env = base::android::AttachCurrentThread(); |
| 75 | 75 |
| 76 ScopedJavaLocalRef<jobjectArray> joa = | 76 ScopedJavaLocalRef<jobjectArray> joa = |
| 77 Java_CookiesFetcher_createCookiesArray( | 77 Java_CookiesFetcher_createCookiesArray(env, jobject_, cookies.size()); |
| 78 env, jobject_.obj(), cookies.size()); | |
| 79 | 78 |
| 80 int index = 0; | 79 int index = 0; |
| 81 for (net::CookieList::const_iterator i = cookies.begin(); | 80 for (net::CookieList::const_iterator i = cookies.begin(); |
| 82 i != cookies.end(); ++i) { | 81 i != cookies.end(); ++i) { |
| 83 std::string domain = i->Domain(); | 82 std::string domain = i->Domain(); |
| 84 if (domain.length() > 1 && domain[0] == '.') | 83 if (domain.length() > 1 && domain[0] == '.') |
| 85 domain = domain.substr(1); | 84 domain = domain.substr(1); |
| 86 ScopedJavaLocalRef<jobject> java_cookie = Java_CookiesFetcher_createCookie( | 85 ScopedJavaLocalRef<jobject> java_cookie = Java_CookiesFetcher_createCookie( |
| 87 env, jobject_.obj(), | 86 env, jobject_, base::android::ConvertUTF8ToJavaString(env, i->Name()), |
| 88 base::android::ConvertUTF8ToJavaString(env, i->Name()).obj(), | 87 base::android::ConvertUTF8ToJavaString(env, i->Value()), |
| 89 base::android::ConvertUTF8ToJavaString(env, i->Value()).obj(), | 88 base::android::ConvertUTF8ToJavaString(env, i->Domain()), |
| 90 base::android::ConvertUTF8ToJavaString(env, i->Domain()).obj(), | 89 base::android::ConvertUTF8ToJavaString(env, i->Path()), |
| 91 base::android::ConvertUTF8ToJavaString(env, i->Path()).obj(), | |
| 92 i->CreationDate().ToInternalValue(), i->ExpiryDate().ToInternalValue(), | 90 i->CreationDate().ToInternalValue(), i->ExpiryDate().ToInternalValue(), |
| 93 i->LastAccessDate().ToInternalValue(), i->IsSecure(), i->IsHttpOnly(), | 91 i->LastAccessDate().ToInternalValue(), i->IsSecure(), i->IsHttpOnly(), |
| 94 static_cast<int>(i->SameSite()), i->Priority()); | 92 static_cast<int>(i->SameSite()), i->Priority()); |
| 95 env->SetObjectArrayElement(joa.obj(), index++, java_cookie.obj()); | 93 env->SetObjectArrayElement(joa.obj(), index++, java_cookie.obj()); |
| 96 } | 94 } |
| 97 | 95 |
| 98 Java_CookiesFetcher_onCookieFetchFinished(env, jobject_.obj(), joa.obj()); | 96 Java_CookiesFetcher_onCookieFetchFinished(env, jobject_, joa); |
| 99 | 97 |
| 100 // Give up the reference. | 98 // Give up the reference. |
| 101 jobject_.Reset(); | 99 jobject_.Reset(); |
| 102 } | 100 } |
| 103 | 101 |
| 104 static void RestoreToCookieJarInternal(net::URLRequestContextGetter* getter, | 102 static void RestoreToCookieJarInternal(net::URLRequestContextGetter* getter, |
| 105 const net::CanonicalCookie& cookie) { | 103 const net::CanonicalCookie& cookie) { |
| 106 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 107 | 105 |
| 108 net::CookieStore* store = getter->GetURLRequestContext()->cookie_store(); | 106 net::CookieStore* store = getter->GetURLRequestContext()->cookie_store(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 179 |
| 182 // JNI functions | 180 // JNI functions |
| 183 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 181 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 184 return reinterpret_cast<intptr_t>(new CookiesFetcher(env, obj, 0)); | 182 return reinterpret_cast<intptr_t>(new CookiesFetcher(env, obj, 0)); |
| 185 } | 183 } |
| 186 | 184 |
| 187 // Register native methods | 185 // Register native methods |
| 188 bool RegisterCookiesFetcher(JNIEnv* env) { | 186 bool RegisterCookiesFetcher(JNIEnv* env) { |
| 189 return RegisterNativesImpl(env); | 187 return RegisterNativesImpl(env); |
| 190 } | 188 } |
| OLD | NEW |