| 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 <utility> |
| 8 |
| 7 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
| 8 #include "android_webview/browser/aw_cookie_access_policy.h" | 10 #include "android_webview/browser/aw_cookie_access_policy.h" |
| 9 #include "android_webview/browser/net/init_native_callback.h" | 11 #include "android_webview/browser/net/init_native_callback.h" |
| 10 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | 12 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
| 11 #include "android_webview/native/aw_browser_dependency_factory.h" | 13 #include "android_webview/native/aw_browser_dependency_factory.h" |
| 12 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 13 #include "base/android/path_utils.h" | 15 #include "base/android/path_utils.h" |
| 14 #include "base/bind.h" | 16 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 16 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 335 |
| 334 bool CookieManager::GetShouldAcceptCookies() { | 336 bool CookieManager::GetShouldAcceptCookies() { |
| 335 return AwCookieAccessPolicy::GetInstance()->GetShouldAcceptCookies(); | 337 return AwCookieAccessPolicy::GetInstance()->GetShouldAcceptCookies(); |
| 336 } | 338 } |
| 337 | 339 |
| 338 void CookieManager::SetCookie( | 340 void CookieManager::SetCookie( |
| 339 const GURL& host, | 341 const GURL& host, |
| 340 const std::string& cookie_value, | 342 const std::string& cookie_value, |
| 341 scoped_ptr<BoolCookieCallbackHolder> callback_holder) { | 343 scoped_ptr<BoolCookieCallbackHolder> callback_holder) { |
| 342 BoolCallback callback = | 344 BoolCallback callback = |
| 343 BoolCookieCallbackHolder::ConvertToCallback(callback_holder.Pass()); | 345 BoolCookieCallbackHolder::ConvertToCallback(std::move(callback_holder)); |
| 344 ExecCookieTask(base::Bind(&CookieManager::SetCookieHelper, | 346 ExecCookieTask(base::Bind(&CookieManager::SetCookieHelper, |
| 345 base::Unretained(this), | 347 base::Unretained(this), |
| 346 host, | 348 host, |
| 347 cookie_value, | 349 cookie_value, |
| 348 callback)); | 350 callback)); |
| 349 } | 351 } |
| 350 | 352 |
| 351 void CookieManager::SetCookieSync(const GURL& host, | 353 void CookieManager::SetCookieSync(const GURL& host, |
| 352 const std::string& cookie_value) { | 354 const std::string& cookie_value) { |
| 353 ExecCookieTaskSync(base::Bind(&CookieManager::SetCookieHelper, | 355 ExecCookieTaskSync(base::Bind(&CookieManager::SetCookieHelper, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 void CookieManager::GetCookieValueCompleted(base::Closure complete, | 397 void CookieManager::GetCookieValueCompleted(base::Closure complete, |
| 396 std::string* result, | 398 std::string* result, |
| 397 const std::string& value) { | 399 const std::string& value) { |
| 398 *result = value; | 400 *result = value; |
| 399 complete.Run(); | 401 complete.Run(); |
| 400 } | 402 } |
| 401 | 403 |
| 402 void CookieManager::RemoveSessionCookies( | 404 void CookieManager::RemoveSessionCookies( |
| 403 scoped_ptr<BoolCookieCallbackHolder> callback_holder) { | 405 scoped_ptr<BoolCookieCallbackHolder> callback_holder) { |
| 404 BoolCallback callback = | 406 BoolCallback callback = |
| 405 BoolCookieCallbackHolder::ConvertToCallback(callback_holder.Pass()); | 407 BoolCookieCallbackHolder::ConvertToCallback(std::move(callback_holder)); |
| 406 ExecCookieTask(base::Bind(&CookieManager::RemoveSessionCookiesHelper, | 408 ExecCookieTask(base::Bind(&CookieManager::RemoveSessionCookiesHelper, |
| 407 base::Unretained(this), | 409 base::Unretained(this), |
| 408 callback)); | 410 callback)); |
| 409 } | 411 } |
| 410 | 412 |
| 411 void CookieManager::RemoveSessionCookiesSync() { | 413 void CookieManager::RemoveSessionCookiesSync() { |
| 412 ExecCookieTaskSync(base::Bind(&CookieManager::RemoveSessionCookiesHelper, | 414 ExecCookieTaskSync(base::Bind(&CookieManager::RemoveSessionCookiesHelper, |
| 413 base::Unretained(this))); | 415 base::Unretained(this))); |
| 414 } | 416 } |
| 415 | 417 |
| 416 void CookieManager::RemoveSessionCookiesHelper( | 418 void CookieManager::RemoveSessionCookiesHelper( |
| 417 BoolCallback callback) { | 419 BoolCallback callback) { |
| 418 cookie_monster_->DeleteSessionCookiesAsync( | 420 cookie_monster_->DeleteSessionCookiesAsync( |
| 419 base::Bind(&CookieManager::RemoveCookiesCompleted, | 421 base::Bind(&CookieManager::RemoveCookiesCompleted, |
| 420 base::Unretained(this), | 422 base::Unretained(this), |
| 421 callback)); | 423 callback)); |
| 422 } | 424 } |
| 423 | 425 |
| 424 void CookieManager::RemoveCookiesCompleted( | 426 void CookieManager::RemoveCookiesCompleted( |
| 425 BoolCallback callback, | 427 BoolCallback callback, |
| 426 int num_deleted) { | 428 int num_deleted) { |
| 427 callback.Run(num_deleted > 0); | 429 callback.Run(num_deleted > 0); |
| 428 } | 430 } |
| 429 | 431 |
| 430 void CookieManager::RemoveAllCookies( | 432 void CookieManager::RemoveAllCookies( |
| 431 scoped_ptr<BoolCookieCallbackHolder> callback_holder) { | 433 scoped_ptr<BoolCookieCallbackHolder> callback_holder) { |
| 432 BoolCallback callback = | 434 BoolCallback callback = |
| 433 BoolCookieCallbackHolder::ConvertToCallback(callback_holder.Pass()); | 435 BoolCookieCallbackHolder::ConvertToCallback(std::move(callback_holder)); |
| 434 ExecCookieTask(base::Bind(&CookieManager::RemoveAllCookiesHelper, | 436 ExecCookieTask(base::Bind(&CookieManager::RemoveAllCookiesHelper, |
| 435 base::Unretained(this), | 437 base::Unretained(this), |
| 436 callback)); | 438 callback)); |
| 437 } | 439 } |
| 438 | 440 |
| 439 void CookieManager::RemoveAllCookiesSync() { | 441 void CookieManager::RemoveAllCookiesSync() { |
| 440 ExecCookieTaskSync(base::Bind(&CookieManager::RemoveAllCookiesHelper, | 442 ExecCookieTaskSync(base::Bind(&CookieManager::RemoveAllCookiesHelper, |
| 441 base::Unretained(this))); | 443 base::Unretained(this))); |
| 442 } | 444 } |
| 443 | 445 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 527 |
| 526 static void SetCookie(JNIEnv* env, | 528 static void SetCookie(JNIEnv* env, |
| 527 const JavaParamRef<jobject>& obj, | 529 const JavaParamRef<jobject>& obj, |
| 528 const JavaParamRef<jstring>& url, | 530 const JavaParamRef<jstring>& url, |
| 529 const JavaParamRef<jstring>& value, | 531 const JavaParamRef<jstring>& value, |
| 530 const JavaParamRef<jobject>& java_callback) { | 532 const JavaParamRef<jobject>& java_callback) { |
| 531 GURL host(ConvertJavaStringToUTF16(env, url)); | 533 GURL host(ConvertJavaStringToUTF16(env, url)); |
| 532 std::string cookie_value(ConvertJavaStringToUTF8(env, value)); | 534 std::string cookie_value(ConvertJavaStringToUTF8(env, value)); |
| 533 scoped_ptr<BoolCookieCallbackHolder> callback( | 535 scoped_ptr<BoolCookieCallbackHolder> callback( |
| 534 new BoolCookieCallbackHolder(env, java_callback)); | 536 new BoolCookieCallbackHolder(env, java_callback)); |
| 535 CookieManager::GetInstance()->SetCookie(host, cookie_value, callback.Pass()); | 537 CookieManager::GetInstance()->SetCookie(host, cookie_value, |
| 538 std::move(callback)); |
| 536 } | 539 } |
| 537 | 540 |
| 538 static void SetCookieSync(JNIEnv* env, | 541 static void SetCookieSync(JNIEnv* env, |
| 539 const JavaParamRef<jobject>& obj, | 542 const JavaParamRef<jobject>& obj, |
| 540 const JavaParamRef<jstring>& url, | 543 const JavaParamRef<jstring>& url, |
| 541 const JavaParamRef<jstring>& value) { | 544 const JavaParamRef<jstring>& value) { |
| 542 GURL host(ConvertJavaStringToUTF16(env, url)); | 545 GURL host(ConvertJavaStringToUTF16(env, url)); |
| 543 std::string cookie_value(ConvertJavaStringToUTF8(env, value)); | 546 std::string cookie_value(ConvertJavaStringToUTF8(env, value)); |
| 544 | 547 |
| 545 CookieManager::GetInstance()->SetCookieSync(host, cookie_value); | 548 CookieManager::GetInstance()->SetCookieSync(host, cookie_value); |
| 546 } | 549 } |
| 547 | 550 |
| 548 static ScopedJavaLocalRef<jstring> GetCookie(JNIEnv* env, | 551 static ScopedJavaLocalRef<jstring> GetCookie(JNIEnv* env, |
| 549 const JavaParamRef<jobject>& obj, | 552 const JavaParamRef<jobject>& obj, |
| 550 const JavaParamRef<jstring>& url) { | 553 const JavaParamRef<jstring>& url) { |
| 551 GURL host(ConvertJavaStringToUTF16(env, url)); | 554 GURL host(ConvertJavaStringToUTF16(env, url)); |
| 552 | 555 |
| 553 return base::android::ConvertUTF8ToJavaString( | 556 return base::android::ConvertUTF8ToJavaString( |
| 554 env, CookieManager::GetInstance()->GetCookie(host)); | 557 env, CookieManager::GetInstance()->GetCookie(host)); |
| 555 } | 558 } |
| 556 | 559 |
| 557 static void RemoveSessionCookies(JNIEnv* env, | 560 static void RemoveSessionCookies(JNIEnv* env, |
| 558 const JavaParamRef<jobject>& obj, | 561 const JavaParamRef<jobject>& obj, |
| 559 const JavaParamRef<jobject>& java_callback) { | 562 const JavaParamRef<jobject>& java_callback) { |
| 560 scoped_ptr<BoolCookieCallbackHolder> callback( | 563 scoped_ptr<BoolCookieCallbackHolder> callback( |
| 561 new BoolCookieCallbackHolder(env, java_callback)); | 564 new BoolCookieCallbackHolder(env, java_callback)); |
| 562 CookieManager::GetInstance()->RemoveSessionCookies(callback.Pass()); | 565 CookieManager::GetInstance()->RemoveSessionCookies(std::move(callback)); |
| 563 } | 566 } |
| 564 | 567 |
| 565 static void RemoveSessionCookiesSync(JNIEnv* env, | 568 static void RemoveSessionCookiesSync(JNIEnv* env, |
| 566 const JavaParamRef<jobject>& obj) { | 569 const JavaParamRef<jobject>& obj) { |
| 567 CookieManager::GetInstance()->RemoveSessionCookiesSync(); | 570 CookieManager::GetInstance()->RemoveSessionCookiesSync(); |
| 568 } | 571 } |
| 569 | 572 |
| 570 static void RemoveAllCookies(JNIEnv* env, | 573 static void RemoveAllCookies(JNIEnv* env, |
| 571 const JavaParamRef<jobject>& obj, | 574 const JavaParamRef<jobject>& obj, |
| 572 const JavaParamRef<jobject>& java_callback) { | 575 const JavaParamRef<jobject>& java_callback) { |
| 573 scoped_ptr<BoolCookieCallbackHolder> callback( | 576 scoped_ptr<BoolCookieCallbackHolder> callback( |
| 574 new BoolCookieCallbackHolder(env, java_callback)); | 577 new BoolCookieCallbackHolder(env, java_callback)); |
| 575 CookieManager::GetInstance()->RemoveAllCookies(callback.Pass()); | 578 CookieManager::GetInstance()->RemoveAllCookies(std::move(callback)); |
| 576 } | 579 } |
| 577 | 580 |
| 578 static void RemoveAllCookiesSync(JNIEnv* env, | 581 static void RemoveAllCookiesSync(JNIEnv* env, |
| 579 const JavaParamRef<jobject>& obj) { | 582 const JavaParamRef<jobject>& obj) { |
| 580 CookieManager::GetInstance()->RemoveAllCookiesSync(); | 583 CookieManager::GetInstance()->RemoveAllCookiesSync(); |
| 581 } | 584 } |
| 582 | 585 |
| 583 static void RemoveExpiredCookies(JNIEnv* env, | 586 static void RemoveExpiredCookies(JNIEnv* env, |
| 584 const JavaParamRef<jobject>& obj) { | 587 const JavaParamRef<jobject>& obj) { |
| 585 CookieManager::GetInstance()->RemoveExpiredCookies(); | 588 CookieManager::GetInstance()->RemoveExpiredCookies(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 607 scoped_refptr<net::CookieStore> CreateCookieStore( | 610 scoped_refptr<net::CookieStore> CreateCookieStore( |
| 608 AwBrowserContext* browser_context) { | 611 AwBrowserContext* browser_context) { |
| 609 return CookieManager::GetInstance()->GetCookieStore(); | 612 return CookieManager::GetInstance()->GetCookieStore(); |
| 610 } | 613 } |
| 611 | 614 |
| 612 bool RegisterCookieManager(JNIEnv* env) { | 615 bool RegisterCookieManager(JNIEnv* env) { |
| 613 return RegisterNativesImpl(env); | 616 return RegisterNativesImpl(env); |
| 614 } | 617 } |
| 615 | 618 |
| 616 } // android_webview namespace | 619 } // android_webview namespace |
| OLD | NEW |