Commit d62ac714 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: implement remove*Cookie APIs for the network service

No change to the legacy code path.

This implements #removeSessionCookies and #removeAllCookies for the
network service code path. This implements both APIs on top of
CookieManager::DeleteCookies().

This removes 3 tests from the filter (the remaining related test is
blocked on fixing #hasCookies).

Bug: 931641, 933629, 902641, 933462
Test: run_webview_instrumentation_test_apk \
Test: --enable-features=NetworkService,NetworkServiceInProcess \
Test: -f CookieManagerTest#testRemove*
Cq-Include-Trybots: master.tryserver.chromium.android:android_mojo
Change-Id: Idb8f1bb5c464993fd142f29681395598c2f65cf6
Reviewed-on: https://chromium-review.googlesource.com/c/1478459
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634512}
parent 285cc227
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "services/network/network_service.h" #include "services/network/network_service.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/cookie_manager.mojom-forward.h" #include "services/network/public/mojom/cookie_manager.mojom-forward.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "url/url_constants.h" #include "url/url_constants.h"
using base::FilePath; using base::FilePath;
...@@ -460,9 +461,19 @@ void CookieManager::RemoveSessionCookiesSync() { ...@@ -460,9 +461,19 @@ void CookieManager::RemoveSessionCookiesSync() {
void CookieManager::RemoveSessionCookiesHelper( void CookieManager::RemoveSessionCookiesHelper(
base::RepeatingCallback<void(bool)> callback) { base::RepeatingCallback<void(bool)> callback) {
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
auto match_session_cookies = network::mojom::CookieDeletionFilter::New();
match_session_cookies->session_control =
network::mojom::CookieDeletionSessionControl::SESSION_COOKIES;
GetCookieManagerWrapper()->DeleteCookies(
std::move(match_session_cookies),
base::BindOnce(&CookieManager::RemoveCookiesCompleted,
base::Unretained(this), callback));
} else {
GetCookieStore()->DeleteSessionCookiesAsync( GetCookieStore()->DeleteSessionCookiesAsync(
base::BindOnce(&CookieManager::RemoveCookiesCompleted, base::BindOnce(&CookieManager::RemoveCookiesCompleted,
base::Unretained(this), callback)); base::Unretained(this), callback));
}
} }
void CookieManager::RemoveCookiesCompleted( void CookieManager::RemoveCookiesCompleted(
...@@ -486,9 +497,18 @@ void CookieManager::RemoveAllCookiesSync() { ...@@ -486,9 +497,18 @@ void CookieManager::RemoveAllCookiesSync() {
void CookieManager::RemoveAllCookiesHelper( void CookieManager::RemoveAllCookiesHelper(
const base::RepeatingCallback<void(bool)> callback) { const base::RepeatingCallback<void(bool)> callback) {
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
// An empty filter matches all cookies.
auto match_all_cookies = network::mojom::CookieDeletionFilter::New();
GetCookieManagerWrapper()->DeleteCookies(
std::move(match_all_cookies),
base::BindOnce(&CookieManager::RemoveCookiesCompleted,
base::Unretained(this), callback));
} else {
GetCookieStore()->DeleteAllAsync( GetCookieStore()->DeleteAllAsync(
base::BindOnce(&CookieManager::RemoveCookiesCompleted, base::BindOnce(&CookieManager::RemoveCookiesCompleted,
base::Unretained(this), callback)); base::Unretained(this), callback));
}
} }
void CookieManager::RemoveExpiredCookies() { void CookieManager::RemoveExpiredCookies() {
......
...@@ -41,4 +41,12 @@ void AwCookieManagerWrapper::SetCanonicalCookie( ...@@ -41,4 +41,12 @@ void AwCookieManagerWrapper::SetCanonicalCookie(
std::move(callback)); std::move(callback));
} }
void AwCookieManagerWrapper::DeleteCookies(
network::mojom::CookieDeletionFilterPtr filter,
DeleteCookiesCallback callback) {
// TODO(ntfschr): handle the case where content layer isn't initialized yet
// (http://crbug.com/933461).
cookie_manager_->DeleteCookies(std::move(filter), std::move(callback));
}
} // namespace android_webview } // namespace android_webview
...@@ -28,6 +28,8 @@ class AwCookieManagerWrapper { ...@@ -28,6 +28,8 @@ class AwCookieManagerWrapper {
network::mojom::CookieManager::GetCookieListCallback; network::mojom::CookieManager::GetCookieListCallback;
using SetCanonicalCookieCallback = using SetCanonicalCookieCallback =
network::mojom::CookieManager::SetCanonicalCookieCallback; network::mojom::CookieManager::SetCanonicalCookieCallback;
using DeleteCookiesCallback =
network::mojom::CookieManager::DeleteCookiesCallback;
// Called when content layer starts up, to pass in a NetworkContextPtr for us // Called when content layer starts up, to pass in a NetworkContextPtr for us
// to use for Cookies APIs. // to use for Cookies APIs.
...@@ -45,6 +47,9 @@ class AwCookieManagerWrapper { ...@@ -45,6 +47,9 @@ class AwCookieManagerWrapper {
bool modify_http_only, bool modify_http_only,
SetCanonicalCookieCallback); SetCanonicalCookieCallback);
void DeleteCookies(network::mojom::CookieDeletionFilterPtr filter,
DeleteCookiesCallback callback);
private: private:
// A CookieManagerPtr which is cloned from the NetworkContext's // A CookieManagerPtr which is cloned from the NetworkContext's
// CookieManagerPtr (but, lives on this thread). // CookieManagerPtr (but, lives on this thread).
......
...@@ -26,19 +26,15 @@ ...@@ -26,19 +26,15 @@
-org.chromium.android_webview.test.CookieManagerTest.testAcceptCookie_falseWontSetCookies -org.chromium.android_webview.test.CookieManagerTest.testAcceptCookie_falseWontSetCookies
-org.chromium.android_webview.test.CookieManagerTest.testAcceptFileSchemeCookies -org.chromium.android_webview.test.CookieManagerTest.testAcceptFileSchemeCookies
-org.chromium.android_webview.test.CookieManagerTest.testThirdPartyCookie -org.chromium.android_webview.test.CookieManagerTest.testThirdPartyCookie
-org.chromium.android_webview.test.CookieManagerTest.testThirdPartyCookiesArePerWebview
# https://crbug.com/931641 # https://crbug.com/931641
-org.chromium.android_webview.test.CookieManagerTest.testRemoveSessionCookiesNullCallback -org.chromium.android_webview.test.CookieManagerTest.testRemoveSessionCookiesNullCallback
-org.chromium.android_webview.test.CookieManagerTest.testThirdPartyCookieForWebSocketDisabledCase -org.chromium.android_webview.test.CookieManagerTest.testThirdPartyCookieForWebSocketDisabledCase
-org.chromium.android_webview.test.CookieManagerTest.testRemoveSessionCookies
-org.chromium.android_webview.test.CookieManagerTest.testRemoveSessionCookiesCallback
# https://crbug.com/933629 # https://crbug.com/933629
-org.chromium.android_webview.test.CookieManagerTest.testCookiesExpire -org.chromium.android_webview.test.CookieManagerTest.testCookiesExpire
-org.chromium.android_webview.test.CookieManagerTest.testHasCookie -org.chromium.android_webview.test.CookieManagerTest.testHasCookie
-org.chromium.android_webview.test.CookieManagerTest.testRemoveAllCookies -org.chromium.android_webview.test.CookieManagerTest.testRemoveAllCookies
-org.chromium.android_webview.test.CookieManagerTest.testRemoveAllCookiesCallback
-org.chromium.android_webview.test.CookieManagerTest.testSetCookieNullCallback -org.chromium.android_webview.test.CookieManagerTest.testSetCookieNullCallback
# https://crbug.com/893580 # https://crbug.com/893580
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment