#include "content/browser/browsing_data/clear_site_data_handler.h"
#include <optional>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "content/browser/buckets/bucket_utils.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition_config.h"
#include "content/public/browser/web_contents.h"
#include "net/base/load_flags.h"
#include "net/url_request/clear_site_data.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "third_party/blink/public/common/features_generated.h"
namespace content {
namespace {
const char kConsoleMessageTemplate[] = …;
const char kConsoleMessageCleared[] = …;
const char kConsoleMessageDatatypeSeparator[] = …;
enum LoggableEventMask { … };
void LogEvent(int event) { … }
int ParametersMask(const ClearSiteDataTypeSet clear_site_data_types,
bool has_buckets) { … }
void OutputFormattedMessage(WebContents* web_contents,
blink::mojom::ConsoleMessageLevel level,
const std::string& formatted_text) { … }
}
ClearSiteDataHandler::ConsoleMessagesDelegate::ConsoleMessagesDelegate()
: … { … }
ClearSiteDataHandler::ConsoleMessagesDelegate::~ConsoleMessagesDelegate() { … }
void ClearSiteDataHandler::ConsoleMessagesDelegate::AddMessage(
const GURL& url,
const std::string& text,
blink::mojom::ConsoleMessageLevel level) { … }
void ClearSiteDataHandler::ConsoleMessagesDelegate::OutputMessages(
base::WeakPtr<WebContents> web_contents) { … }
void ClearSiteDataHandler::ConsoleMessagesDelegate::
SetOutputFormattedMessageFunctionForTesting(
const OutputFormattedMessageFunction& function) { … }
void ClearSiteDataHandler::HandleHeader(
base::WeakPtr<BrowserContext> browser_context,
base::WeakPtr<WebContents> web_contents,
const StoragePartitionConfig& storage_partition_config,
const GURL& url,
const std::string& header_value,
int load_flags,
const std::optional<net::CookiePartitionKey> cookie_partition_key,
const std::optional<blink::StorageKey> storage_key,
bool partitioned_state_allowed_only,
base::OnceClosure callback) { … }
bool ClearSiteDataHandler::ParseHeaderForTesting(
const std::string& header,
ClearSiteDataTypeSet* clear_site_data_types,
std::set<std::string>* storage_buckets_to_remove,
ConsoleMessagesDelegate* delegate,
const GURL& current_url) { … }
ClearSiteDataHandler::ClearSiteDataHandler(
base::WeakPtr<BrowserContext> browser_context,
base::WeakPtr<WebContents> web_contents,
const StoragePartitionConfig& storage_partition_config,
const GURL& url,
const std::string& header_value,
int load_flags,
const std::optional<net::CookiePartitionKey> cookie_partition_key,
const std::optional<blink::StorageKey> storage_key,
bool partitioned_state_allowed_only,
base::OnceClosure callback,
std::unique_ptr<ConsoleMessagesDelegate> delegate)
: … { … }
ClearSiteDataHandler::~ClearSiteDataHandler() = default;
bool ClearSiteDataHandler::HandleHeaderAndOutputConsoleMessages() { … }
bool ClearSiteDataHandler::Run() { … }
bool ClearSiteDataHandler::ParseHeader(
const std::string& header,
ClearSiteDataTypeSet* clear_site_data_types,
std::set<std::string>* storage_buckets_to_remove,
ConsoleMessagesDelegate* delegate,
const GURL& current_url) { … }
void ClearSiteDataHandler::ExecuteClearingTask(
const url::Origin& origin,
const ClearSiteDataTypeSet clear_site_data_types,
const std::set<std::string>& storage_buckets_to_remove,
base::OnceClosure callback) { … }
void ClearSiteDataHandler::TaskFinished(
base::TimeTicks clearing_started,
std::unique_ptr<ConsoleMessagesDelegate> delegate,
base::WeakPtr<WebContents> web_contents,
base::OnceClosure callback) { … }
void ClearSiteDataHandler::OutputConsoleMessages() { … }
void ClearSiteDataHandler::RunCallbackNotDeferred() { … }
}