chromium/third_party/blink/public/common/fenced_frame/fenced_frame_utils.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FENCED_FRAME_FENCED_FRAME_UTILS_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FENCED_FRAME_FENCED_FRAME_UTILS_H_

#include <optional>

#include "services/network/public/cpp/web_sandbox_flags.h"
#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
#include "third_party/blink/public/common/common_export.h"

class GURL;

namespace blink {

// To prevent overloading the RAM, limit the maximum automatic beacon length
// to 64KB.
const size_t kFencedFrameMaxBeaconLength =;

// The maximum length of `blink::FencedFrameConfig::shared_storage_context_`.
// When setting, longer strings are truncated to this length.
const size_t kFencedFrameConfigSharedStorageContextMaxLength =;

// Histogram names for fenced frame.
inline constexpr char kFencedFrameCreationOrNavigationOutcomeHistogram[] =;

inline constexpr char kIsOpaqueFencedFrameSizeCoercedHistogram[] =;

inline constexpr char kIsFencedFrameResizedAfterSizeFrozen[] =;

inline constexpr char kFencedFrameMandatoryUnsandboxedFlagsSandboxed[] =;

inline constexpr char kFencedFrameFailedSandboxLoadInTopLevelFrame[] =;

inline constexpr char kFencedFrameTopNavigationHistogram[] =;

inline constexpr char kAutomaticBeaconOutcomeHistogram[] =;

inline constexpr char kAutomaticBeaconEventTypeHistogram[] =;

inline constexpr char kFencedFrameBeaconReportingHttpResultUMA[] =;

inline constexpr char kFencedFrameBeaconReportingCountUMA[] =;

inline constexpr char kFencedFrameBeaconReportingCountCrossOriginUMA[] =;

// Corresponds to the "FencedFrameCreationOutcome" histogram enumeration type in
// tools/metrics/histograms/enums.xml.
//
// PLEASE DO NOT REORDER, REMOVE, OR CHANGE THE MEANING OF THESE VALUES.
enum class FencedFrameCreationOutcome {};

// Corresponds to the "AutomaticBeaconOutcome" histogram enumeration type in
// tools/metrics/histograms/enums.xml.
//
// PLEASE DO NOT REORDER, REMOVE, OR CHANGE THE MEANING OF THESE VALUES.
enum class AutomaticBeaconOutcome {};

// Corresponds to the "FencedFrameNavigationState" histogram enumeration type in
// tools/metrics/histograms/enums.xml.
//
// PLEASE DO NOT REORDER, REMOVE, OR CHANGE THE MEANING OF THESE VALUES.
enum class FencedFrameNavigationState {};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class FencedFrameBeaconReportingResult {};

// Whether or not a fenced frame is allowed to be navigated to `url`. For now
// this is described by
// https://github.com/WICG/fenced-frame/blob/master/explainer/modes.md.
BLINK_COMMON_EXPORT bool IsValidFencedFrameURL(const GURL& url);

// Whether or not a URL is a valid "urn uuid URL" depends not only on just the
// scheme being "urn", but that the URL's prefix is "urn:uuid".
BLINK_COMMON_EXPORT bool IsValidUrnUuidURL(const GURL& url);

// Record fenced frame related UMAs.
BLINK_COMMON_EXPORT void RecordFencedFrameCreationOutcome(
    const FencedFrameCreationOutcome outcome);
BLINK_COMMON_EXPORT void RecordOpaqueFencedFrameSizeCoercion(bool did_coerce);
BLINK_COMMON_EXPORT void RecordFencedFrameResizedAfterSizeFrozen();
BLINK_COMMON_EXPORT void RecordFencedFrameUnsandboxedFlags(
    network::mojom::WebSandboxFlags flags);
BLINK_COMMON_EXPORT void RecordFencedFrameFailedSandboxLoadInTopLevelFrame(
    bool is_main_frame);

// Returns true if the DOM event type name `event_type` is allowed to be
// propagated from a fenced frame to its embedder. Returns false otherwise.
BLINK_COMMON_EXPORT bool CanNotifyEventTypeAcrossFence(
    const std::string& event_type);

// Automatic beacon type definitions
inline constexpr char kDeprecatedFencedFrameTopNavigationBeaconType[] =;
inline constexpr char kFencedFrameTopNavigationStartBeaconType[] =;
inline constexpr char kFencedFrameTopNavigationCommitBeaconType[] =;

inline constexpr const char* kFencedFrameAutomaticBeaconTypes[] =;

// Prefix of reserved event types for private aggregation API
inline constexpr char kFencedFrameReservedPAEventPrefix[] =;

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_PUBLIC_COMMON_FENCED_FRAME_FENCED_FRAME_UTILS_H_