| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "android_webview/native/cookie_manager.h" | 5 #include "android_webview/native/cookie_manager.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_cookie_access_policy.h" | 7 #include "android_webview/browser/aw_cookie_access_policy.h" |
| 8 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | 8 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
| 9 #include "android_webview/native/aw_browser_dependency_factory.h" | 9 #include "android_webview/native/aw_browser_dependency_factory.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/message_loop_proxy.h" | 15 #include "base/message_loop_proxy.h" |
| 16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 21 #include "jni/AwCookieManager_jni.h" | 21 #include "jni/AwCookieManager_jni.h" |
| 22 #include "net/cookies/cookie_monster.h" | 22 #include "net/cookies/cookie_monster.h" |
| 23 #include "net/cookies/cookie_options.h" | 23 #include "net/cookies/cookie_options.h" |
| 24 #include "net/cookies/cookie_store.h" | |
| 25 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 26 | 25 |
| 27 using base::android::ConvertJavaStringToUTF8; | 26 using base::android::ConvertJavaStringToUTF8; |
| 28 using base::android::ConvertJavaStringToUTF16; | 27 using base::android::ConvertJavaStringToUTF16; |
| 29 using content::BrowserThread; | 28 using content::BrowserThread; |
| 30 using net::CookieList; | 29 using net::CookieList; |
| 31 using net::CookieMonster; | 30 using net::CookieMonster; |
| 32 | 31 |
| 33 // In the future, we may instead want to inject an explicit CookieStore | 32 // In the future, we may instead want to inject an explicit CookieStore |
| 34 // dependency into this object during process initialization to avoid | 33 // dependency into this object during process initialization to avoid |
| 35 // depending on the URLRequestContext. | 34 // depending on the URLRequestContext. |
| 36 // See issue http://crbug.com/157683 | 35 // See issue http://crbug.com/157683 |
| 37 | 36 |
| 38 // All functions on the CookieManager can be called from any thread, including | 37 // All functions on the CookieManager can be called from any thread, including |
| 39 // threads without a message loop. BrowserThread::FILE is used to call methods | 38 // threads without a message loop. BrowserThread::FILE is used to call methods |
| 40 // on CookieMonster that needs to be called, and called back, on a chrome | 39 // on CookieMonster that needs to be called, and called back, on a chrome |
| 41 // thread. | 40 // thread. |
| 42 | 41 |
| 43 namespace android_webview { | 42 namespace android_webview { |
| 44 | 43 |
| 45 namespace { | 44 namespace { |
| 46 | 45 |
| 47 class CookieManager { | 46 class CookieManager { |
| 48 public: | 47 public: |
| 49 static CookieManager* GetInstance(); | 48 static CookieManager* GetInstance(); |
| 50 | 49 |
| 51 void SetCookieMonster(net::URLRequestContext* request_context); | 50 void SetCookieMonster(net::CookieMonster* cookie_monster); |
| 52 | 51 |
| 53 void SetAcceptCookie(bool accept); | 52 void SetAcceptCookie(bool accept); |
| 54 bool AcceptCookie(); | 53 bool AcceptCookie(); |
| 55 void SetCookie(const GURL& host, const std::string& cookie_value); | 54 void SetCookie(const GURL& host, const std::string& cookie_value); |
| 56 std::string GetCookie(const GURL& host); | 55 std::string GetCookie(const GURL& host); |
| 57 void RemoveSessionCookie(); | 56 void RemoveSessionCookie(); |
| 58 void RemoveAllCookie(); | 57 void RemoveAllCookie(); |
| 59 void RemoveExpiredCookie(); | 58 void RemoveExpiredCookie(); |
| 60 void FlushCookieStore(); | 59 void FlushCookieStore(); |
| 61 bool HasCookies(); | 60 bool HasCookies(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 126 |
| 128 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 127 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 129 base::Bind(task, wait_for_completion ? &completion : NULL)); | 128 base::Bind(task, wait_for_completion ? &completion : NULL)); |
| 130 | 129 |
| 131 if (wait_for_completion) { | 130 if (wait_for_completion) { |
| 132 ScopedAllowWaitForLegacyWebViewApi wait; | 131 ScopedAllowWaitForLegacyWebViewApi wait; |
| 133 completion.Wait(); | 132 completion.Wait(); |
| 134 } | 133 } |
| 135 } | 134 } |
| 136 | 135 |
| 137 void CookieManager::SetCookieMonster(net::URLRequestContext* request_context) { | 136 void CookieManager::SetCookieMonster(net::CookieMonster* cookie_monster) { |
| 138 DCHECK(!cookie_monster_); | 137 DCHECK(!cookie_monster_); |
| 139 cookie_monster_ = request_context->cookie_store()->GetCookieMonster(); | 138 cookie_monster_ = cookie_monster; |
| 140 } | 139 } |
| 141 | 140 |
| 142 void CookieManager::SetAcceptCookie(bool accept) { | 141 void CookieManager::SetAcceptCookie(bool accept) { |
| 143 AwCookieAccessPolicy::GetInstance()->SetGlobalAllowAccess(accept); | 142 AwCookieAccessPolicy::GetInstance()->SetGlobalAllowAccess(accept); |
| 144 } | 143 } |
| 145 | 144 |
| 146 bool CookieManager::AcceptCookie() { | 145 bool CookieManager::AcceptCookie() { |
| 147 return AwCookieAccessPolicy::GetInstance()->GetGlobalAllowAccess(); | 146 return AwCookieAccessPolicy::GetInstance()->GetGlobalAllowAccess(); |
| 148 } | 147 } |
| 149 | 148 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 340 |
| 342 static jboolean AllowFileSchemeCookies(JNIEnv* env, jobject obj) { | 341 static jboolean AllowFileSchemeCookies(JNIEnv* env, jobject obj) { |
| 343 return CookieManager::GetInstance()->AllowFileSchemeCookies(); | 342 return CookieManager::GetInstance()->AllowFileSchemeCookies(); |
| 344 } | 343 } |
| 345 | 344 |
| 346 static void SetAcceptFileSchemeCookies(JNIEnv* env, jobject obj, | 345 static void SetAcceptFileSchemeCookies(JNIEnv* env, jobject obj, |
| 347 jboolean accept) { | 346 jboolean accept) { |
| 348 return CookieManager::GetInstance()->SetAcceptFileSchemeCookies(accept); | 347 return CookieManager::GetInstance()->SetAcceptFileSchemeCookies(accept); |
| 349 } | 348 } |
| 350 | 349 |
| 351 void SetCookieMonsterOnNetworkStackInit(net::URLRequestContext* context) { | 350 void SetCookieMonsterOnNetworkStackInit(net::CookieMonster* cookie_monster) { |
| 352 CookieManager::GetInstance()->SetCookieMonster(context); | 351 CookieManager::GetInstance()->SetCookieMonster(cookie_monster); |
| 353 } | 352 } |
| 354 | 353 |
| 355 bool RegisterCookieManager(JNIEnv* env) { | 354 bool RegisterCookieManager(JNIEnv* env) { |
| 356 return RegisterNativesImpl(env); | 355 return RegisterNativesImpl(env); |
| 357 } | 356 } |
| 358 | 357 |
| 359 } // android_webview namespace | 358 } // android_webview namespace |
| OLD | NEW |