Chromium Code Reviews| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 i != cookies.end(); ++i) { | 81 i != cookies.end(); ++i) { |
| 82 ScopedJavaLocalRef<jobject> java_cookie = Java_CookiesFetcher_createCookie( | 82 ScopedJavaLocalRef<jobject> java_cookie = Java_CookiesFetcher_createCookie( |
| 83 env, jobject_.obj(), | 83 env, jobject_.obj(), |
| 84 base::android::ConvertUTF8ToJavaString(env, i->Source().spec()).obj(), | 84 base::android::ConvertUTF8ToJavaString(env, i->Source().spec()).obj(), |
| 85 base::android::ConvertUTF8ToJavaString(env, i->Name()).obj(), | 85 base::android::ConvertUTF8ToJavaString(env, i->Name()).obj(), |
| 86 base::android::ConvertUTF8ToJavaString(env, i->Value()).obj(), | 86 base::android::ConvertUTF8ToJavaString(env, i->Value()).obj(), |
| 87 base::android::ConvertUTF8ToJavaString(env, i->Domain()).obj(), | 87 base::android::ConvertUTF8ToJavaString(env, i->Domain()).obj(), |
| 88 base::android::ConvertUTF8ToJavaString(env, i->Path()).obj(), | 88 base::android::ConvertUTF8ToJavaString(env, i->Path()).obj(), |
| 89 i->CreationDate().ToInternalValue(), i->ExpiryDate().ToInternalValue(), | 89 i->CreationDate().ToInternalValue(), i->ExpiryDate().ToInternalValue(), |
| 90 i->LastAccessDate().ToInternalValue(), i->IsSecure(), i->IsHttpOnly(), | 90 i->LastAccessDate().ToInternalValue(), i->IsSecure(), i->IsHttpOnly(), |
| 91 i->IsFirstPartyOnly(), i->Priority()); | 91 i->IsSameSite(), i->Priority()); |
| 92 env->SetObjectArrayElement(joa.obj(), index++, java_cookie.obj()); | 92 env->SetObjectArrayElement(joa.obj(), index++, java_cookie.obj()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 Java_CookiesFetcher_onCookieFetchFinished(env, jobject_.obj(), joa.obj()); | 95 Java_CookiesFetcher_onCookieFetchFinished(env, jobject_.obj(), joa.obj()); |
| 96 | 96 |
| 97 // Give up the reference. | 97 // Give up the reference. |
| 98 jobject_.Reset(); | 98 jobject_.Reset(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void CookiesFetcher::RestoreCookies(JNIEnv* env, | 101 void CookiesFetcher::RestoreCookies(JNIEnv* env, |
| 102 const JavaParamRef<jobject>& obj, | 102 const JavaParamRef<jobject>& obj, |
| 103 const JavaParamRef<jstring>& url, | 103 const JavaParamRef<jstring>& url, |
| 104 const JavaParamRef<jstring>& name, | 104 const JavaParamRef<jstring>& name, |
| 105 const JavaParamRef<jstring>& value, | 105 const JavaParamRef<jstring>& value, |
| 106 const JavaParamRef<jstring>& domain, | 106 const JavaParamRef<jstring>& domain, |
| 107 const JavaParamRef<jstring>& path, | 107 const JavaParamRef<jstring>& path, |
| 108 int64_t creation, | 108 int64_t creation, |
| 109 int64_t expiration, | 109 int64_t expiration, |
| 110 int64_t last_access, | 110 int64_t last_access, |
| 111 bool secure, | 111 bool secure, |
| 112 bool httponly, | 112 bool httponly, |
| 113 bool firstpartyonly, | 113 bool samesite, |
|
mmenke
2016/01/25 18:47:10
same_site (x2)
Mike West
2016/01/26 11:05:45
Done (x2)
| |
| 114 int priority) { | 114 int priority) { |
| 115 Profile* profile = ProfileManager::GetPrimaryUserProfile(); | 115 Profile* profile = ProfileManager::GetPrimaryUserProfile(); |
| 116 if (!profile->HasOffTheRecordProfile()) { | 116 if (!profile->HasOffTheRecordProfile()) { |
| 117 return; // Don't create it. There is nothing to do. | 117 return; // Don't create it. There is nothing to do. |
| 118 } | 118 } |
| 119 profile = profile->GetOffTheRecordProfile(); | 119 profile = profile->GetOffTheRecordProfile(); |
| 120 | 120 |
| 121 scoped_refptr<net::URLRequestContextGetter> getter( | 121 scoped_refptr<net::URLRequestContextGetter> getter( |
| 122 profile->GetRequestContext()); | 122 profile->GetRequestContext()); |
| 123 | 123 |
| 124 net::CanonicalCookie cookie( | 124 net::CanonicalCookie cookie( |
| 125 GURL(base::android::ConvertJavaStringToUTF8(env, url)), | 125 GURL(base::android::ConvertJavaStringToUTF8(env, url)), |
| 126 base::android::ConvertJavaStringToUTF8(env, name), | 126 base::android::ConvertJavaStringToUTF8(env, name), |
| 127 base::android::ConvertJavaStringToUTF8(env, value), | 127 base::android::ConvertJavaStringToUTF8(env, value), |
| 128 base::android::ConvertJavaStringToUTF8(env, domain), | 128 base::android::ConvertJavaStringToUTF8(env, domain), |
| 129 base::android::ConvertJavaStringToUTF8(env, path), | 129 base::android::ConvertJavaStringToUTF8(env, path), |
| 130 base::Time::FromInternalValue(creation), | 130 base::Time::FromInternalValue(creation), |
| 131 base::Time::FromInternalValue(expiration), | 131 base::Time::FromInternalValue(expiration), |
| 132 base::Time::FromInternalValue(last_access), secure, httponly, | 132 base::Time::FromInternalValue(last_access), secure, httponly, |
| 133 firstpartyonly, static_cast<net::CookiePriority>(priority)); | 133 samesite, static_cast<net::CookiePriority>(priority)); |
| 134 | 134 |
| 135 // The rest must be done from the IO thread. | 135 // The rest must be done from the IO thread. |
| 136 content::BrowserThread::PostTask( | 136 content::BrowserThread::PostTask( |
| 137 content::BrowserThread::IO, | 137 content::BrowserThread::IO, |
| 138 FROM_HERE, | 138 FROM_HERE, |
| 139 base::Bind(&CookiesFetcher::RestoreToCookieJarInternal, | 139 base::Bind(&CookiesFetcher::RestoreToCookieJarInternal, |
| 140 base::Unretained(this), | 140 base::Unretained(this), |
| 141 getter, | 141 getter, |
| 142 cookie)); | 142 cookie)); |
| 143 } | 143 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 159 | 159 |
| 160 // TODO(estark): Remove kEnableExperimentalWebPlatformFeatures check | 160 // TODO(estark): Remove kEnableExperimentalWebPlatformFeatures check |
| 161 // when we decide whether to ship cookie | 161 // when we decide whether to ship cookie |
| 162 // prefixes. https://crbug.com/541511 | 162 // prefixes. https://crbug.com/541511 |
| 163 bool experimental_features_enabled = | 163 bool experimental_features_enabled = |
| 164 base::CommandLine::ForCurrentProcess()->HasSwitch( | 164 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 165 switches::kEnableExperimentalWebPlatformFeatures); | 165 switches::kEnableExperimentalWebPlatformFeatures); |
| 166 monster->SetCookieWithDetailsAsync( | 166 monster->SetCookieWithDetailsAsync( |
| 167 cookie.Source(), cookie.Name(), cookie.Value(), cookie.Domain(), | 167 cookie.Source(), cookie.Name(), cookie.Value(), cookie.Domain(), |
| 168 cookie.Path(), cookie.ExpiryDate(), cookie.IsSecure(), | 168 cookie.Path(), cookie.ExpiryDate(), cookie.IsSecure(), |
| 169 cookie.IsHttpOnly(), cookie.IsFirstPartyOnly(), | 169 cookie.IsHttpOnly(), cookie.IsSameSite(), |
| 170 experimental_features_enabled, experimental_features_enabled, | 170 experimental_features_enabled, experimental_features_enabled, |
| 171 cookie.Priority(), cb); | 171 cookie.Priority(), cb); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // JNI functions | 174 // JNI functions |
| 175 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 175 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 176 return reinterpret_cast<intptr_t>(new CookiesFetcher(env, obj, 0)); | 176 return reinterpret_cast<intptr_t>(new CookiesFetcher(env, obj, 0)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Register native methods | 179 // Register native methods |
| 180 bool RegisterCookiesFetcher(JNIEnv* env) { | 180 bool RegisterCookiesFetcher(JNIEnv* env) { |
| 181 return RegisterNativesImpl(env); | 181 return RegisterNativesImpl(env); |
| 182 } | 182 } |
| OLD | NEW |