Commit c9872679 authored by Dylan Cutler's avatar Dylan Cutler Committed by Chromium LUCI CQ

Add method to BrowsingDataBridge to clear SameSite=None cookies.

This CL also introduces a new UMA metric,
ClearBrowsingData_SameSiteNoneData, which is used in
BrowsingDataBridgeTest.java and will also be used to track usage
of the feature once it is released.

Bug: 1166674
Change-Id: I00aebaf4b5192e187fb42e7947b52ea046bf4276
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627766
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846214}
parent a87b6168
......@@ -121,6 +121,16 @@ public final class BrowsingDataBridge {
ignoredDomainReasons);
}
/**
* Clear SameSite=None cookies and related storage asynchronously.
* @param callback Invoked when the clearing is done.
* @param clearStorage If true, clears any storage associated with SameSite=None cookies.
*/
public void clearSameSiteNoneData(Runnable callback, boolean clearStorage) {
BrowsingDataBridgeJni.get().clearSameSiteNoneData(
BrowsingDataBridge.this, getProfile(), callback, clearStorage);
}
/**
* This method tests clearing of specified types of browsing data for primary Incognito profile.
* @param dataTypes An array of browsing data types to delete, represented as values from
......@@ -253,6 +263,8 @@ public final class BrowsingDataBridge {
void clearBrowsingData(BrowsingDataBridge caller, Profile profile, int[] dataTypes,
int timePeriod, String[] excludedDomains, int[] excludedDomainReasons,
String[] ignoredDomains, int[] ignoredDomainReasons);
void clearSameSiteNoneData(BrowsingDataBridge caller, Profile profile, Runnable callback,
boolean clearStorage);
void requestInfoAboutOtherFormsOfBrowsingHistory(BrowsingDataBridge caller, Profile profile,
OtherFormsOfBrowsingHistoryListener listener);
void fetchImportantSites(Profile profile, ImportantSitesCallback callback);
......
......@@ -117,6 +117,21 @@ public class BrowsingDataBridgeTest {
"ClearBrowsingData_SiteUsageData", "ClearBrowsingData_ContentLicenses"));
}
/**
* Test deleting SameSite=None cookies.
*/
@Test
@SmallTest
public void testSameSiteNoneCookiesDeleted() throws Exception {
TestThreadUtils.runOnUiThreadBlocking(() -> {
BrowsingDataBridge.getInstance().clearSameSiteNoneData(
() -> { mCallbackHelper.notifyCalled(); }, false);
});
mCallbackHelper.waitForCallback(0);
assertThat(mActionTester.toString(), getActions(),
Matchers.contains("ClearBrowsingData_SameSiteNoneData"));
}
/**
* Get ClearBrowsingData related actions, filter all other actions to avoid flakes.
*/
......
......@@ -10,6 +10,7 @@
#include <string>
#include <vector>
#include "base/android/callback_android.h"
#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
......@@ -37,6 +38,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/same_site_data_remover.h"
using base::android::AttachCurrentThread;
using base::android::JavaParamRef;
......@@ -168,6 +170,20 @@ static void JNI_BrowsingDataBridge_ClearBrowsingData(
std::move(filter_builder), browsing_data_remover, std::move(callback));
}
static void JNI_BrowsingDataBridge_ClearSameSiteNoneData(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jobject>& jprofile,
const JavaParamRef<jobject>& jcallback,
jboolean jclear_storage) {
TRACE_EVENT0("browsing_data", "BrowsingDataBridge_ClearSameSiteNoneData");
Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
content::ClearSameSiteNoneData(
base::BindOnce(&base::android::RunRunnableAndroid,
ScopedJavaGlobalRef<jobject>(jcallback)),
profile, jclear_storage);
}
static void EnableDialogAboutOtherFormsOfBrowsingHistory(
const JavaRef<jobject>& listener,
bool enabled) {
......
......@@ -13,6 +13,7 @@
#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/metrics/user_metrics.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/same_site_data_remover.h"
#include "content/public/browser/storage_partition.h"
......@@ -124,6 +125,8 @@ void SameSiteDataRemoverImpl::ClearStoragePartitionData(
void ClearSameSiteNoneData(base::OnceClosure closure,
BrowserContext* context,
bool clear_storage) {
base::RecordAction(
base::UserMetricsAction("ClearBrowsingData_SameSiteNoneData"));
auto same_site_remover = std::make_unique<SameSiteDataRemoverImpl>(context);
SameSiteDataRemoverImpl* remover = same_site_remover.get();
......
......@@ -4639,6 +4639,11 @@ should be able to be added at any place in this file.
<description>Please enter the description of this user action.</description>
</action>
<action name="ClearBrowsingData_SameSiteNoneData" not_user_triggered="true">
<owner>dylancutler@google.com</owner>
<description>SameSite=None cookies were deleted.</description>
</action>
<action name="ClearBrowsingData_ServerBoundCerts">
<obsolete>This has been renamed ClearBrowsingData_ChannelIDs.</obsolete>
<owner>Please list the metric's owners. Add more owner tags as needed.</owner>
......
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