#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include <ostream>
#include <vector>
#include "base/feature_list.h"
#include "base/time/time.h"
#include "components/attribution_reporting/features.h"
#include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/features_generated.h"
#include "third_party/blink/public/common/origin_trials/origin_trials.h"
#include "third_party/blink/public/common/origin_trials/trial_token.h"
#include "third_party/blink/public/common/origin_trials/trial_token_result.h"
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include "third_party/blink/public/mojom/origin_trial_feature/origin_trial_feature.mojom-shared.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/window_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/origin_trial_features.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/runtime_feature_state/runtime_feature_state_override_context.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "v8/include/v8.h"
namespace blink {
namespace {
constexpr char kDefaultTrialName[] = …;
bool IsWhitespace(UChar chr) { … }
bool SkipWhiteSpace(const String& str, unsigned& pos) { … }
String ExtractTokenOrQuotedString(const String& header_value, unsigned& pos) { … }
bool IsCrossNavigationFeature(mojom::blink::OriginTrialFeature feature) { … }
std::ostream& operator<<(std::ostream& stream, OriginTrialTokenStatus status) { … }
OriginTrialStatus MergeOriginTrialStatus(OriginTrialStatus s1,
OriginTrialStatus s2) { … }
}
OriginTrialTokenResult::OriginTrialTokenResult(
const String& raw_token,
OriginTrialTokenStatus status,
const std::optional<TrialToken>& parsed_token)
: … { … }
OriginTrialContext::OriginTrialContext(ExecutionContext* context)
: … { … }
void OriginTrialContext::SetTrialTokenValidatorForTesting(
std::unique_ptr<TrialTokenValidator> validator) { … }
std::unique_ptr<Vector<String>> OriginTrialContext::ParseHeaderValue(
const String& header_value) { … }
void OriginTrialContext::AddTokensFromHeader(ExecutionContext* context,
const String& header_value) { … }
void OriginTrialContext::AddTokens(ExecutionContext* context,
const Vector<String>* tokens) { … }
void OriginTrialContext::ActivateWorkerInheritedFeatures(
ExecutionContext* context,
const Vector<mojom::blink::OriginTrialFeature>* features) { … }
void OriginTrialContext::ActivateNavigationFeaturesFromInitiator(
ExecutionContext* context,
const Vector<mojom::blink::OriginTrialFeature>* features) { … }
std::unique_ptr<Vector<String>> OriginTrialContext::GetTokens(
ExecutionContext* execution_context) { … }
std::unique_ptr<Vector<mojom::blink::OriginTrialFeature>>
OriginTrialContext::GetInheritedTrialFeatures(
ExecutionContext* execution_context) { … }
std::unique_ptr<Vector<mojom::blink::OriginTrialFeature>>
OriginTrialContext::GetEnabledNavigationFeatures(
ExecutionContext* execution_context) { … }
std::unique_ptr<Vector<mojom::blink::OriginTrialFeature>>
OriginTrialContext::GetInheritedTrialFeatures() const { … }
std::unique_ptr<Vector<mojom::blink::OriginTrialFeature>>
OriginTrialContext::GetEnabledNavigationFeatures() const { … }
void OriginTrialContext::AddToken(const String& token) { … }
void OriginTrialContext::AddTokenFromExternalScript(
const String& token,
const Vector<scoped_refptr<SecurityOrigin>>& external_origins) { … }
void OriginTrialContext::AddTokenInternal(
const String& token,
const OriginInfo origin,
const Vector<OriginInfo>* script_origins) { … }
void OriginTrialContext::AddTokens(const Vector<String>& tokens) { … }
void OriginTrialContext::ActivateWorkerInheritedFeatures(
const Vector<mojom::blink::OriginTrialFeature>& features) { … }
void OriginTrialContext::ActivateNavigationFeaturesFromInitiator(
const Vector<mojom::blink::OriginTrialFeature>& features) { … }
void OriginTrialContext::InitializePendingFeatures() { … }
bool OriginTrialContext::InstallFeatures(
const HashSet<mojom::blink::OriginTrialFeature>& features,
Document& document,
ScriptState* script_state) { … }
bool OriginTrialContext::InstallSettingFeature(
Document& document,
mojom::blink::OriginTrialFeature enabled_feature) { … }
void OriginTrialContext::AddFeature(mojom::blink::OriginTrialFeature feature) { … }
bool OriginTrialContext::IsFeatureEnabled(
mojom::blink::OriginTrialFeature feature) const { … }
base::Time OriginTrialContext::GetFeatureExpiry(
mojom::blink::OriginTrialFeature feature) { … }
bool OriginTrialContext::IsNavigationFeatureActivated(
mojom::blink::OriginTrialFeature feature) const { … }
void OriginTrialContext::AddForceEnabledTrials(
const Vector<String>& trial_names) { … }
bool OriginTrialContext::CanEnableTrialFromName(const StringView& trial_name) { … }
OriginTrialFeaturesEnabled OriginTrialContext::EnableTrialFromName(
const String& trial_name,
base::Time expiry_time) { … }
bool OriginTrialContext::EnableTrialFromToken(const String& token,
const OriginInfo origin_info) { … }
bool OriginTrialContext::EnableTrialFromToken(
const String& token,
const OriginInfo origin_info,
const Vector<OriginInfo>* script_origins) { … }
void OriginTrialContext::CacheToken(const String& raw_token,
const TrialTokenResult& token_result,
OriginTrialStatus trial_status) { … }
void OriginTrialContext::Trace(Visitor* visitor) const { … }
const SecurityOrigin* OriginTrialContext::GetSecurityOrigin() { … }
bool OriginTrialContext::IsSecureContext() { … }
OriginTrialContext::OriginInfo OriginTrialContext::GetCurrentOriginInfo() { … }
void OriginTrialContext::SendTokenToBrowser(
const OriginInfo& origin_info,
const TrialToken& parsed_token,
const String& raw_token,
const Vector<OriginInfo>* script_origin_info) { … }
}