1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_STORAGE_HANDLER_H_
#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_STORAGE_HANDLER_H_
#include <memory>
#include <string>
#include <variant>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/types/optional_ref.h"
#include "components/services/storage/shared_storage/shared_storage_manager.h"
#include "content/browser/attribution_reporting/attribution_observer.h"
#include "content/browser/devtools/protocol/devtools_domain_handler.h"
#include "content/browser/devtools/protocol/storage.h"
#include "content/browser/interest_group/devtools_enums.h"
#include "content/browser/interest_group/interest_group_manager_impl.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/shared_storage/shared_storage_runtime_manager.h"
#include "content/public/browser/global_routing_id.h"
#include "storage/browser/quota/quota_manager.h"
#include "third_party/blink/public/common/shared_storage/shared_storage_utils.h"
namespace storage {
class QuotaOverrideHandle;
}
namespace content {
class AttributionManager;
class RenderFrameHostImpl;
class StoragePartition;
namespace protocol {
class StorageHandler
: public DevToolsDomainHandler,
public Storage::Backend,
public content::InterestGroupManagerImpl::InterestGroupObserver,
public AttributionObserver,
public content::SharedStorageRuntimeManager::
SharedStorageObserverInterface {
public:
explicit StorageHandler(DevToolsAgentHostClient* client);
StorageHandler(const StorageHandler&) = delete;
StorageHandler& operator=(const StorageHandler&) = delete;
~StorageHandler() override;
static std::vector<StorageHandler*> ForAgentHost(DevToolsAgentHostImpl* host);
// content::protocol::DevToolsDomainHandler
void Wire(UberDispatcher* dispatcher) override;
void SetRenderer(int process_host_id,
RenderFrameHostImpl* frame_host) override;
Response Disable() override;
bool interest_group_auction_tracking_enabled() const {
return interest_group_auction_tracking_enabled_;
}
// content::protocol::storage::Backend
Response GetStorageKeyForFrame(const std::string& frame_id,
std::string* serialized_storage_key) override;
void ClearDataForOrigin(
const std::string& origin,
const std::string& storage_types,
std::unique_ptr<ClearDataForOriginCallback> callback) override;
void ClearDataForStorageKey(
const std::string& storage_key,
const std::string& storage_types,
std::unique_ptr<ClearDataForStorageKeyCallback> callback) override;
void GetUsageAndQuota(
const String& origin,
std::unique_ptr<GetUsageAndQuotaCallback> callback) override;
// Storage Quota Override
void GetQuotaOverrideHandle();
void OverrideQuotaForOrigin(
const String& origin,
std::optional<double> quota_size,
std::unique_ptr<OverrideQuotaForOriginCallback> callback) override;
// Cookies management
void GetCookies(
std::optional<std::string> browser_context_id,
std::unique_ptr<Storage::Backend::GetCookiesCallback> callback) override;
void SetCookies(
std::unique_ptr<protocol::Array<Network::CookieParam>> cookies,
std::optional<std::string> browser_context_id,
std::unique_ptr<Storage::Backend::SetCookiesCallback> callback) override;
void ClearCookies(std::optional<std::string> browser_context_id,
std::unique_ptr<Storage::Backend::ClearCookiesCallback>
callback) override;
// Ignores all double calls to track an origin.
Response TrackCacheStorageForOrigin(const std::string& origin) override;
Response TrackCacheStorageForStorageKey(
const std::string& storage_key) override;
Response UntrackCacheStorageForOrigin(const std::string& origin) override;
Response UntrackCacheStorageForStorageKey(
const std::string& storage_key) override;
Response TrackIndexedDBForOrigin(const std::string& origin) override;
Response TrackIndexedDBForStorageKey(const std::string& storage_key) override;
Response UntrackIndexedDBForOrigin(const std::string& origin) override;
Response UntrackIndexedDBForStorageKey(
const std::string& storage_key) override;
void GetTrustTokens(
std::unique_ptr<GetTrustTokensCallback> callback) override;
void ClearTrustTokens(
const std::string& issuerOrigin,
std::unique_ptr<ClearTrustTokensCallback> callback) override;
void GetInterestGroupDetails(
const std::string& owner_origin_string,
const std::string& name,
std::unique_ptr<GetInterestGroupDetailsCallback> callback) override;
Response SetInterestGroupTracking(bool enable) override;
Response SetInterestGroupAuctionTracking(bool enable) override;
void GetSharedStorageMetadata(
const std::string& owner_origin_string,
std::unique_ptr<GetSharedStorageMetadataCallback> callback) override;
void GetSharedStorageEntries(
const std::string& owner_origin_string,
std::unique_ptr<GetSharedStorageEntriesCallback> callback) override;
void SetSharedStorageEntry(
const std::string& owner_origin_string,
const std::string& key,
const std::string& value,
std::optional<bool> ignore_if_present,
std::unique_ptr<SetSharedStorageEntryCallback> callback) override;
void DeleteSharedStorageEntry(
const std::string& owner_origin_string,
const std::string& key,
std::unique_ptr<DeleteSharedStorageEntryCallback> callback) override;
void ClearSharedStorageEntries(
const std::string& owner_origin_string,
std::unique_ptr<ClearSharedStorageEntriesCallback> callback) override;
Response SetSharedStorageTracking(bool enable) override;
void ResetSharedStorageBudget(
const std::string& owner_origin_string,
std::unique_ptr<ResetSharedStorageBudgetCallback> callback) override;
DispatchResponse SetStorageBucketTracking(
const std::string& serialized_storage_key,
bool enable) override;
DispatchResponse DeleteStorageBucket(
std::unique_ptr<protocol::Storage::StorageBucket> bucket) override;
void SetAttributionReportingLocalTestingMode(
bool enabled,
std::unique_ptr<SetAttributionReportingLocalTestingModeCallback>)
override;
Response SetAttributionReportingTracking(bool enable) override;
void SendPendingAttributionReports(
std::unique_ptr<SendPendingAttributionReportsCallback>) override;
void 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 NotifyInterestGroupAuctionNetworkRequestCreated(
content::InterestGroupAuctionFetchType type,
const std::string& request_id,
const std::vector<std::string>& devtools_auction_ids);
Response SetProtectedAudienceKAnonymity(
const std::string& in_owner_origin,
const std::string& in_group_name,
std::unique_ptr<std::vector<Binary>> in_hashes) override;
private:
// See definition for lifetime information.
class CacheStorageObserver;
class IndexedDBObserver;
class InterestGroupObserver;
class SharedStorageObserver;
class QuotaManagerObserver;
// Not thread safe.
CacheStorageObserver* GetCacheStorageObserver();
IndexedDBObserver* GetIndexedDBObserver();
SharedStorageRuntimeManager* GetSharedStorageRuntimeManager();
std::variant<protocol::Response, storage::SharedStorageManager*>
GetSharedStorageManager();
storage::QuotaManagerProxy* GetQuotaManagerProxy();
AttributionManager* GetAttributionManager();
// content::InterestGroupManagerImpl::InterestGroupObserver
void 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) override;
// AttributionObserver
void OnSourceHandled(
const StorableSource&,
base::Time source_time,
std::optional<uint64_t> cleared_debug_key,
attribution_reporting::mojom::StoreSourceResult) override;
void OnTriggerHandled(std::optional<uint64_t> cleared_debug_key,
const CreateReportResult&) override;
void OnReportSent(const AttributionReport&,
bool is_debug_report,
const SendResult&) override;
// content::SharedStorageRuntimeManager::SharedStorageObserverInterface
GlobalRenderFrameHostId AssociatedFrameHostId() const override;
bool ShouldReceiveAllSharedStorageReports() const override;
void OnSharedStorageAccessed(
base::Time access_time,
blink::SharedStorageAccessScope scope,
SharedStorageRuntimeManager::SharedStorageObserverInterface::AccessMethod
method,
GlobalRenderFrameHostId main_frame_id,
const std::string& owner_origin,
const SharedStorageEventParams& params) override;
void OnSharedStorageSelectUrlUrnUuidGenerated(const GURL& urn_uuid) override;
void OnSharedStorageSelectUrlConfigPopulated(
const std::optional<FencedFrameConfig>& config) override;
void OnSharedStorageWorkletOperationExecutionFinished(
base::Time finished_time,
base::TimeDelta execution_time,
SharedStorageRuntimeManager::SharedStorageObserverInterface::AccessMethod
method,
int operation_id,
int worklet_ordinal_id,
const base::UnguessableToken& worklet_devtools_token,
GlobalRenderFrameHostId main_frame_id,
const std::string& owner_origin) override;
void NotifyCacheStorageListChanged(
const storage::BucketLocator& bucket_locator);
void NotifyCacheStorageContentChanged(
const storage::BucketLocator& bucket_locator,
const std::string& name);
void NotifyIndexedDBListChanged(storage::BucketLocator bucket_locator);
void NotifyIndexedDBContentChanged(storage::BucketLocator bucket_locator,
const std::u16string& database_name,
const std::u16string& object_store_name);
void NotifyCreateOrUpdateBucket(const storage::BucketInfo& bucket_info);
void NotifyDeleteBucket(const storage::BucketLocator& bucket_locator);
Response FindStoragePartition(
const std::optional<std::string>& browser_context_id,
StoragePartition** storage_partition);
void ResetAttributionReporting();
// This doesn't update `interest_group_auction_tracking_enabled_` and does not
// have to work on `storage_partition_`, unlike the public version.
Response SetInterestGroupTrackingInternal(StoragePartition* storage_partition,
bool enable);
void GotAllCookies(
std::unique_ptr<Storage::Backend::GetCookiesCallback> callback,
const std::vector<net::CanonicalCookie>& cookies);
std::unique_ptr<Storage::Frontend> frontend_;
raw_ptr<StoragePartition> storage_partition_{nullptr};
raw_ptr<RenderFrameHostImpl> frame_host_ = nullptr;
std::unique_ptr<CacheStorageObserver> cache_storage_observer_;
std::unique_ptr<IndexedDBObserver> indexed_db_observer_;
std::unique_ptr<QuotaManagerObserver> quota_manager_observer_;
// Exposes the API for managing storage quota overrides.
std::unique_ptr<storage::QuotaOverrideHandle> quota_override_handle_;
raw_ptr<DevToolsAgentHostClient> client_;
bool interest_group_tracking_enabled_ = false;
bool interest_group_auction_tracking_enabled_ = false;
base::ScopedObservation<AttributionManager, AttributionObserver>
attribution_observation_{this};
base::ScopedObservation<
content::SharedStorageRuntimeManager,
content::SharedStorageRuntimeManager::SharedStorageObserverInterface>
shared_storage_observation_{this};
base::WeakPtrFactory<StorageHandler> weak_ptr_factory_{this};
};
} // namespace protocol
} // namespace content
#endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_STORAGE_HANDLER_H_
|