| 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_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
| 8 #include "android_webview/browser/aw_cookie_access_policy.h" | 8 #include "android_webview/browser/aw_cookie_access_policy.h" |
| 9 #include "android_webview/browser/net/init_native_callback.h" | 9 #include "android_webview/browser/net/init_native_callback.h" |
| 10 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | 10 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 void GetUserDataDir(FilePath* user_data_dir) { | 138 void GetUserDataDir(FilePath* user_data_dir) { |
| 139 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, user_data_dir)) { | 139 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, user_data_dir)) { |
| 140 NOTREACHED() << "Failed to get app data directory for Android WebView"; | 140 NOTREACHED() << "Failed to get app data directory for Android WebView"; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 class CookieManager { | 144 class CookieManager { |
| 145 public: | 145 public: |
| 146 static CookieManager* GetInstance(); | 146 static CookieManager* GetInstance(); |
| 147 | 147 |
| 148 scoped_refptr<net::CookieStore> CreateBrowserThreadCookieStore( | 148 scoped_refptr<net::CookieStore> GetCookieStore(); |
| 149 AwBrowserContext* browser_context); | |
| 150 | 149 |
| 151 void SetAcceptCookie(bool accept); | 150 void SetAcceptCookie(bool accept); |
| 152 bool AcceptCookie(); | 151 bool AcceptCookie(); |
| 153 void SetAcceptThirdPartyCookie(bool accept); | 152 void SetAcceptThirdPartyCookie(bool accept); |
| 154 bool AcceptThirdPartyCookie(); | 153 bool AcceptThirdPartyCookie(); |
| 155 void SetCookie(const GURL& host, | 154 void SetCookie(const GURL& host, |
| 156 const std::string& cookie_value, | 155 const std::string& cookie_value, |
| 157 scoped_ptr<BoolCookieCallbackHolder> callback); | 156 scoped_ptr<BoolCookieCallbackHolder> callback); |
| 158 void SetCookieSync(const GURL& host, | 157 void SetCookieSync(const GURL& host, |
| 159 const std::string& cookie_value); | 158 const std::string& cookie_value); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner, | 206 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner, |
| 208 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); | 207 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); |
| 209 void EnsureCookieMonsterExistsLocked(); | 208 void EnsureCookieMonsterExistsLocked(); |
| 210 bool AllowFileSchemeCookiesLocked(); | 209 bool AllowFileSchemeCookiesLocked(); |
| 211 void SetAcceptFileSchemeCookiesLocked(bool accept); | 210 void SetAcceptFileSchemeCookiesLocked(bool accept); |
| 212 | 211 |
| 213 scoped_refptr<net::CookieMonster> cookie_monster_; | 212 scoped_refptr<net::CookieMonster> cookie_monster_; |
| 214 scoped_refptr<base::MessageLoopProxy> cookie_monster_proxy_; | 213 scoped_refptr<base::MessageLoopProxy> cookie_monster_proxy_; |
| 215 base::Lock cookie_monster_lock_; | 214 base::Lock cookie_monster_lock_; |
| 216 | 215 |
| 217 // Both these threads are normally NULL. They only exist if CookieManager was | |
| 218 // accessed before Chromium was started. | |
| 219 scoped_ptr<base::Thread> cookie_monster_client_thread_; | 216 scoped_ptr<base::Thread> cookie_monster_client_thread_; |
| 220 scoped_ptr<base::Thread> cookie_monster_backend_thread_; | 217 scoped_ptr<base::Thread> cookie_monster_backend_thread_; |
| 221 | 218 |
| 222 DISALLOW_COPY_AND_ASSIGN(CookieManager); | 219 DISALLOW_COPY_AND_ASSIGN(CookieManager); |
| 223 }; | 220 }; |
| 224 | 221 |
| 225 base::LazyInstance<CookieManager>::Leaky g_lazy_instance; | 222 base::LazyInstance<CookieManager>::Leaky g_lazy_instance; |
| 226 | 223 |
| 227 // static | 224 // static |
| 228 CookieManager* CookieManager::GetInstance() { | 225 CookieManager* CookieManager::GetInstance() { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 completion.Wait(); | 317 completion.Wait(); |
| 321 } | 318 } |
| 322 | 319 |
| 323 // Executes the |task| on the |cookie_monster_proxy_| message loop. | 320 // Executes the |task| on the |cookie_monster_proxy_| message loop. |
| 324 void CookieManager::ExecCookieTask(const base::Closure& task) { | 321 void CookieManager::ExecCookieTask(const base::Closure& task) { |
| 325 base::AutoLock lock(cookie_monster_lock_); | 322 base::AutoLock lock(cookie_monster_lock_); |
| 326 EnsureCookieMonsterExistsLocked(); | 323 EnsureCookieMonsterExistsLocked(); |
| 327 cookie_monster_proxy_->PostTask(FROM_HERE, task); | 324 cookie_monster_proxy_->PostTask(FROM_HERE, task); |
| 328 } | 325 } |
| 329 | 326 |
| 330 scoped_refptr<net::CookieStore> CookieManager::CreateBrowserThreadCookieStore( | 327 scoped_refptr<net::CookieStore> CookieManager::GetCookieStore() { |
| 331 AwBrowserContext* browser_context) { | |
| 332 base::AutoLock lock(cookie_monster_lock_); | 328 base::AutoLock lock(cookie_monster_lock_); |
| 333 | 329 EnsureCookieMonsterExistsLocked(); |
| 334 if (cookie_monster_client_thread_) { | |
| 335 // We created a cookie monster already on its own threads; we'll just keep | |
| 336 // using it rather than creating one on the normal Chromium threads. | |
| 337 // CookieMonster is threadsafe, so this is fine. | |
| 338 return cookie_monster_; | |
| 339 } | |
| 340 | |
| 341 // Go ahead and create the cookie monster using the normal Chromium threads. | |
| 342 DCHECK(!cookie_monster_.get()); | |
| 343 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); | |
| 344 | |
| 345 FilePath user_data_dir; | |
| 346 GetUserDataDir(&user_data_dir); | |
| 347 DCHECK(browser_context->GetPath() == user_data_dir); | |
| 348 | |
| 349 cookie_monster_proxy_ = | |
| 350 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | |
| 351 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | |
| 352 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | |
| 353 BrowserThread::GetBlockingPool()->GetSequenceToken()); | |
| 354 CreateCookieMonster(user_data_dir, | |
| 355 cookie_monster_proxy_, | |
| 356 background_task_runner); | |
| 357 return cookie_monster_; | 330 return cookie_monster_; |
| 358 } | 331 } |
| 359 | 332 |
| 360 void CookieManager::SetAcceptCookie(bool accept) { | 333 void CookieManager::SetAcceptCookie(bool accept) { |
| 361 AwCookieAccessPolicy::GetInstance()->SetGlobalAllowAccess(accept); | 334 AwCookieAccessPolicy::GetInstance()->SetGlobalAllowAccess(accept); |
| 362 } | 335 } |
| 363 | 336 |
| 364 bool CookieManager::AcceptCookie() { | 337 bool CookieManager::AcceptCookie() { |
| 365 return AwCookieAccessPolicy::GetInstance()->GetGlobalAllowAccess(); | 338 return AwCookieAccessPolicy::GetInstance()->GetGlobalAllowAccess(); |
| 366 } | 339 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 return CookieManager::GetInstance()->AllowFileSchemeCookies(); | 615 return CookieManager::GetInstance()->AllowFileSchemeCookies(); |
| 643 } | 616 } |
| 644 | 617 |
| 645 static void SetAcceptFileSchemeCookies(JNIEnv* env, jobject obj, | 618 static void SetAcceptFileSchemeCookies(JNIEnv* env, jobject obj, |
| 646 jboolean accept) { | 619 jboolean accept) { |
| 647 return CookieManager::GetInstance()->SetAcceptFileSchemeCookies(accept); | 620 return CookieManager::GetInstance()->SetAcceptFileSchemeCookies(accept); |
| 648 } | 621 } |
| 649 | 622 |
| 650 scoped_refptr<net::CookieStore> CreateCookieStore( | 623 scoped_refptr<net::CookieStore> CreateCookieStore( |
| 651 AwBrowserContext* browser_context) { | 624 AwBrowserContext* browser_context) { |
| 652 return CookieManager::GetInstance()->CreateBrowserThreadCookieStore( | 625 return CookieManager::GetInstance()->GetCookieStore(); |
| 653 browser_context); | |
| 654 } | 626 } |
| 655 | 627 |
| 656 bool RegisterCookieManager(JNIEnv* env) { | 628 bool RegisterCookieManager(JNIEnv* env) { |
| 657 return RegisterNativesImpl(env); | 629 return RegisterNativesImpl(env); |
| 658 } | 630 } |
| 659 | 631 |
| 660 } // android_webview namespace | 632 } // android_webview namespace |
| OLD | NEW |