#include "content/browser/devtools/protocol/storage_handler.h"
#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/barrier_closure.h"
#include "base/functional/bind.h"
#include "base/notreached.h"
#include "base/scoped_observation.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/attribution_reporting/aggregatable_debug_reporting_config.h"
#include "components/attribution_reporting/aggregatable_dedup_key.h"
#include "components/attribution_reporting/aggregatable_trigger_data.h"
#include "components/attribution_reporting/aggregatable_values.h"
#include "components/attribution_reporting/aggregation_keys.h"
#include "components/attribution_reporting/attribution_scopes_data.h"
#include "components/attribution_reporting/attribution_scopes_set.h"
#include "components/attribution_reporting/debug_types.h"
#include "components/attribution_reporting/destination_set.h"
#include "components/attribution_reporting/event_trigger_data.h"
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/source_registration.h"
#include "components/attribution_reporting/source_type.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/trigger_config.h"
#include "components/attribution_reporting/trigger_data_matching.mojom.h"
#include "components/services/storage/privileged/mojom/indexed_db_control.mojom.h"
#include "components/services/storage/public/cpp/buckets/bucket_locator.h"
#include "components/services/storage/public/mojom/cache_storage_control.mojom.h"
#include "content/browser/attribution_reporting/aggregatable_result.mojom.h"
#include "content/browser/attribution_reporting/attribution_manager.h"
#include "content/browser/attribution_reporting/attribution_observer.h"
#include "content/browser/attribution_reporting/attribution_report.h"
#include "content/browser/attribution_reporting/attribution_trigger.h"
#include "content/browser/attribution_reporting/common_source_info.h"
#include "content/browser/attribution_reporting/create_report_result.h"
#include "content/browser/attribution_reporting/event_level_result.mojom.h"
#include "content/browser/attribution_reporting/storable_source.h"
#include "content/browser/attribution_reporting/store_source_result.mojom.h"
#include "content/browser/devtools/protocol/browser_handler.h"
#include "content/browser/devtools/protocol/handler_helpers.h"
#include "content/browser/devtools/protocol/network.h"
#include "content/browser/devtools/protocol/network_handler.h"
#include "content/browser/devtools/protocol/storage.h"
#include "content/browser/interest_group/interest_group_manager_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "services/network/public/mojom/trust_tokens.mojom.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/browser/quota/quota_manager_impl.h"
#include "storage/browser/quota/quota_manager_observer.mojom-forward.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/quota/quota_override_handle.h"
#include "third_party/blink/public/common/interest_group/devtools_serialization.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/buckets/bucket_manager_host.mojom-shared.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace protocol {
ClearCookiesCallback;
GetCookiesCallback;
SetCookiesCallback;
struct UsageListInitializer { … };
UsageListInitializer initializers[] = …;
namespace {
void ReportUsageAndQuotaDataOnUIThread(
std::unique_ptr<StorageHandler::GetUsageAndQuotaCallback> callback,
blink::mojom::QuotaStatusCode code,
int64_t usage,
int64_t quota,
bool is_override_enabled,
blink::mojom::UsageBreakdownPtr usage_breakdown) { … }
void GotUsageAndQuotaDataCallback(
std::unique_ptr<StorageHandler::GetUsageAndQuotaCallback> callback,
blink::mojom::QuotaStatusCode code,
int64_t usage,
int64_t quota,
bool is_override_enabled,
blink::mojom::UsageBreakdownPtr usage_breakdown) { … }
void GetUsageAndQuotaOnIOThread(
storage::QuotaManager* manager,
const blink::StorageKey& storage_key,
std::unique_ptr<StorageHandler::GetUsageAndQuotaCallback> callback) { … }
std::unique_ptr<protocol::Storage::StorageBucketInfo> BuildBucketInfo(
const storage::BucketInfo& bucket) { … }
}
class StorageHandler::CacheStorageObserver
: storage::mojom::CacheStorageObserver { … };
class StorageHandler::IndexedDBObserver
: public storage::mojom::IndexedDBObserver { … };
class StorageHandler::SharedStorageObserver
: content::SharedStorageWorkletHostManager::SharedStorageObserverInterface { … };
class StorageHandler::QuotaManagerObserver
: storage::mojom::QuotaManagerObserver { … };
StorageHandler::StorageHandler(DevToolsAgentHostClient* client)
: … { … }
StorageHandler::~StorageHandler() { … }
std::vector<StorageHandler*> StorageHandler::ForAgentHost(
DevToolsAgentHostImpl* host) { … }
void StorageHandler::Wire(UberDispatcher* dispatcher) { … }
void StorageHandler::SetRenderer(int process_host_id,
RenderFrameHostImpl* frame_host) { … }
Response StorageHandler::Disable() { … }
void StorageHandler::GetCookies(Maybe<std::string> browser_context_id,
std::unique_ptr<GetCookiesCallback> callback) { … }
void StorageHandler::GotAllCookies(
std::unique_ptr<GetCookiesCallback> callback,
const std::vector<net::CanonicalCookie>& cookies) { … }
void StorageHandler::SetCookies(
std::unique_ptr<protocol::Array<Network::CookieParam>> cookies,
Maybe<std::string> browser_context_id,
std::unique_ptr<SetCookiesCallback> callback) { … }
void StorageHandler::ClearCookies(
Maybe<std::string> browser_context_id,
std::unique_ptr<ClearCookiesCallback> callback) { … }
Response StorageHandler::GetStorageKeyForFrame(
const std::string& frame_id,
std::string* serialized_storage_key) { … }
namespace {
uint32_t GetRemoveDataMask(const std::string& storage_types) { … }
}
void StorageHandler::ClearDataForOrigin(
const std::string& origin,
const std::string& storage_types,
std::unique_ptr<ClearDataForOriginCallback> callback) { … }
void StorageHandler::ClearDataForStorageKey(
const std::string& storage_key,
const std::string& storage_types,
std::unique_ptr<ClearDataForStorageKeyCallback> callback) { … }
void StorageHandler::GetUsageAndQuota(
const String& origin_string,
std::unique_ptr<GetUsageAndQuotaCallback> callback) { … }
void StorageHandler::OverrideQuotaForOrigin(
const String& origin_string,
Maybe<double> quota_size,
std::unique_ptr<OverrideQuotaForOriginCallback> callback) { … }
Response StorageHandler::TrackCacheStorageForOrigin(
const std::string& origin_string) { … }
Response StorageHandler::TrackCacheStorageForStorageKey(
const std::string& storage_key) { … }
Response StorageHandler::UntrackCacheStorageForOrigin(
const std::string& origin_string) { … }
Response StorageHandler::UntrackCacheStorageForStorageKey(
const std::string& storage_key) { … }
Response StorageHandler::TrackIndexedDBForOrigin(
const std::string& origin_string) { … }
Response StorageHandler::TrackIndexedDBForStorageKey(
const std::string& storage_key) { … }
Response StorageHandler::UntrackIndexedDBForOrigin(
const std::string& origin_string) { … }
Response StorageHandler::UntrackIndexedDBForStorageKey(
const std::string& storage_key) { … }
StorageHandler::CacheStorageObserver*
StorageHandler::GetCacheStorageObserver() { … }
StorageHandler::IndexedDBObserver* StorageHandler::GetIndexedDBObserver() { … }
SharedStorageWorkletHostManager*
StorageHandler::GetSharedStorageWorkletHostManager() { … }
absl::variant<protocol::Response, storage::SharedStorageManager*>
StorageHandler::GetSharedStorageManager() { … }
storage::QuotaManagerProxy* StorageHandler::GetQuotaManagerProxy() { … }
void StorageHandler::NotifyCacheStorageListChanged(
const storage::BucketLocator& bucket_locator) { … }
void StorageHandler::NotifyCacheStorageContentChanged(
const storage::BucketLocator& bucket_locator,
const std::string& name) { … }
void StorageHandler::NotifyIndexedDBListChanged(
storage::BucketLocator bucket_locator) { … }
void StorageHandler::NotifyIndexedDBContentChanged(
storage::BucketLocator bucket_locator,
const std::u16string& database_name,
const std::u16string& object_store_name) { … }
Response StorageHandler::FindStoragePartition(
const Maybe<std::string>& browser_context_id,
StoragePartition** storage_partition) { … }
namespace {
void SendTrustTokens(
std::unique_ptr<StorageHandler::GetTrustTokensCallback> callback,
std::vector<::network::mojom::StoredTrustTokensForIssuerPtr> tokens) { … }
}
void StorageHandler::GetTrustTokens(
std::unique_ptr<GetTrustTokensCallback> callback) { … }
namespace {
void SendClearTrustTokensStatus(
std::unique_ptr<StorageHandler::ClearTrustTokensCallback> callback,
network::mojom::DeleteStoredTrustTokensStatus status) { … }
}
void StorageHandler::ClearTrustTokens(
const std::string& issuerOrigin,
std::unique_ptr<ClearTrustTokensCallback> callback) { … }
void StorageHandler::OnInterestGroupAccessed(
base::optional_ref<const std::string> auction_id,
base::Time access_time,
InterestGroupManagerImpl::InterestGroupObserver::AccessType type,
const url::Origin& owner_origin,
const std::string& name,
base::optional_ref<const url::Origin> component_seller_origin,
std::optional<double> bid,
base::optional_ref<const std::string> bid_currency) { … }
namespace {
void SendGetInterestGroup(
std::unique_ptr<StorageHandler::GetInterestGroupDetailsCallback> callback,
std::optional<SingleStorageInterestGroup> storage_group) { … }
}
void StorageHandler::GetInterestGroupDetails(
const std::string& owner_origin_string,
const std::string& name,
std::unique_ptr<GetInterestGroupDetailsCallback> callback) { … }
Response StorageHandler::SetInterestGroupTracking(bool enable) { … }
Response StorageHandler::SetInterestGroupTrackingInternal(
StoragePartition* storage_partition,
bool enable) { … }
Response StorageHandler::SetInterestGroupAuctionTracking(bool enable) { … }
namespace {
void SendSharedStorageMetadata(
std::unique_ptr<StorageHandler::GetSharedStorageMetadataCallback> callback,
storage::SharedStorageManager::MetadataResult metadata) { … }
}
void StorageHandler::GetSharedStorageMetadata(
const std::string& owner_origin_string,
std::unique_ptr<GetSharedStorageMetadataCallback> callback) { … }
namespace {
void RetrieveSharedStorageEntries(
std::unique_ptr<StorageHandler::GetSharedStorageEntriesCallback> callback,
storage::SharedStorageManager::EntriesResult entries_result) { … }
}
void StorageHandler::GetSharedStorageEntries(
const std::string& owner_origin_string,
std::unique_ptr<GetSharedStorageEntriesCallback> callback) { … }
namespace {
void DispatchSharedStorageSetCallback(
std::unique_ptr<Storage::Backend::SetSharedStorageEntryCallback> callback,
storage::SharedStorageManager::OperationResult result) { … }
}
void StorageHandler::SetSharedStorageEntry(
const std::string& owner_origin_string,
const std::string& key,
const std::string& value,
Maybe<bool> ignore_if_present,
std::unique_ptr<SetSharedStorageEntryCallback> callback) { … }
namespace {
template <typename CallbackType>
void DispatchSharedStorageCallback(
std::unique_ptr<CallbackType> callback,
storage::SharedStorageManager::OperationResult result) { … }
}
void StorageHandler::DeleteSharedStorageEntry(
const std::string& owner_origin_string,
const std::string& key,
std::unique_ptr<DeleteSharedStorageEntryCallback> callback) { … }
void StorageHandler::ClearSharedStorageEntries(
const std::string& owner_origin_string,
std::unique_ptr<ClearSharedStorageEntriesCallback> callback) { … }
Response StorageHandler::SetSharedStorageTracking(bool enable) { … }
void StorageHandler::ResetSharedStorageBudget(
const std::string& owner_origin_string,
std::unique_ptr<ResetSharedStorageBudgetCallback> callback) { … }
namespace {
std::string GetFrameTokenFromFrameTreeNodeId(int frame_id) { … }
}
void StorageHandler::NotifySharedStorageAccessed(
const base::Time& access_time,
SharedStorageWorkletHostManager::SharedStorageObserverInterface::AccessType
type,
int main_frame_id,
const std::string& owner_origin,
const SharedStorageEventParams& params) { … }
DispatchResponse StorageHandler::SetStorageBucketTracking(
const std::string& serialized_storage_key,
bool enable) { … }
DispatchResponse StorageHandler::DeleteStorageBucket(
std::unique_ptr<protocol::Storage::StorageBucket> bucket) { … }
void StorageHandler::NotifyCreateOrUpdateBucket(
const storage::BucketInfo& bucket_info) { … }
void StorageHandler::NotifyDeleteBucket(
const storage::BucketLocator& bucket_locator) { … }
AttributionManager* StorageHandler::GetAttributionManager() { … }
void StorageHandler::SetAttributionReportingLocalTestingMode(
bool enabled,
std::unique_ptr<SetAttributionReportingLocalTestingModeCallback> callback) { … }
void StorageHandler::SendPendingAttributionReports(
std::unique_ptr<SendPendingAttributionReportsCallback> callback) { … }
void StorageHandler::ResetAttributionReporting() { … }
namespace {
AggregatableResult;
EventLevelResult;
StoreSourceResult;
Storage::AttributionReportingSourceRegistrationResult
ToSourceRegistrationResult(StoreSourceResult result) { … }
Storage::AttributionReportingEventLevelResult ToEventLevelResult(
EventLevelResult result) { … }
Storage::AttributionReportingAggregatableResult ToAggregatableResult(
AggregatableResult result) { … }
std::unique_ptr<Array<Storage::AttributionReportingFilterDataEntry>>
ToFilterDataEntries(const attribution_reporting::FilterData& filter_data) { … }
std::unique_ptr<Array<Storage::AttributionReportingFilterConfig>>
ToFilterConfigs(
const std::vector<attribution_reporting::FilterConfig>& filter_configs) { … }
std::unique_ptr<Storage::AttributionReportingFilterPair> ToFilterPair(
const attribution_reporting::FilterPair& filters) { … }
std::unique_ptr<Array<Storage::AttributionReportingAggregationKeysEntry>>
ToAggregationKeysEntries(const attribution_reporting::AggregationKeys& keys) { … }
std::unique_ptr<Storage::AttributionReportingEventReportWindows>
ToEventReportWindows(const attribution_reporting::EventReportWindows& windows) { … }
std::unique_ptr<Array<Storage::AttributionReportingTriggerSpec>> ToTriggerSpecs(
const attribution_reporting::TriggerSpecs& specs) { … }
Storage::AttributionReportingTriggerDataMatching ToTriggerDataMatching(
attribution_reporting::mojom::TriggerDataMatching value) { … }
std::unique_ptr<Array<Storage::AttributionReportingAggregatableDedupKey>>
ToAggregatableDedupKeys(
const std::vector<attribution_reporting::AggregatableDedupKey>&
dedup_keys) { … }
std::unique_ptr<Array<Storage::AttributionReportingEventTriggerData>>
ToEventTriggerData(const std::vector<attribution_reporting::EventTriggerData>&
event_triggers) { … }
std::unique_ptr<Array<Storage::AttributionReportingAggregatableTriggerData>>
ToAggregatableTriggerData(
const std::vector<attribution_reporting::AggregatableTriggerData>&
aggregatable_triggers) { … }
std::unique_ptr<Array<Storage::AttributionReportingAggregatableValueDictEntry>>
ToAggregatableValueDictEntries(
const attribution_reporting::AggregatableValues::Values&
aggregatable_value) { … }
std::unique_ptr<Array<Storage::AttributionReportingAggregatableValueEntry>>
ToAggregatableValueEntries(
const std::vector<attribution_reporting::AggregatableValues>&
aggregatable_values) { … }
Storage::AttributionReportingSourceRegistrationTimeConfig
ToSourceRegistrationTimeConfig(
attribution_reporting::mojom::SourceRegistrationTimeConfig
source_registration_time_config) { … }
std::unique_ptr<
Array<Storage::AttributionReportingAggregatableDebugReportingData>>
ToAggregatableDebugReportingDataArray(
const attribution_reporting::AggregatableDebugReportingConfig::DebugData&
data) { … }
std::unique_ptr<Storage::AttributionReportingAggregatableDebugReportingConfig>
ToAggregatableDebugReportingConfig(
std::optional<double> budget,
const attribution_reporting::AggregatableDebugReportingConfig& config) { … }
}
void StorageHandler::OnSourceHandled(
const StorableSource& source,
base::Time source_time,
std::optional<uint64_t> cleared_debug_key,
attribution_reporting::mojom::StoreSourceResult result) { … }
void StorageHandler::OnTriggerHandled(std::optional<uint64_t> cleared_debug_key,
const CreateReportResult& result) { … }
Response StorageHandler::SetAttributionReportingTracking(bool enable) { … }
void StorageHandler::NotifyInterestGroupAuctionEventOccurred(
base::Time event_time,
content::InterestGroupAuctionEventType type,
const std::string& unique_auction_id,
base::optional_ref<const std::string> parent_auction_id,
const base::Value::Dict& auction_config) { … }
void StorageHandler::NotifyInterestGroupAuctionNetworkRequestCreated(
content::InterestGroupAuctionFetchType type,
const std::string& request_id,
const std::vector<std::string>& devtools_auction_ids) { … }
}
}