#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include <memory>
#include <string_view>
#include "base/check.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/no_destructor.h"
#include "base/time/time.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "third_party/blink/public/common/origin_trials/origin_trial_policy.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/mojom/origin_trial_feature/origin_trial_feature.mojom-shared.h"
namespace blink {
namespace {
static base::RepeatingCallback<OriginTrialPolicy*()>& PolicyGetter() { … }
bool IsDeprecationTrialPossible() { … }
OriginTrialTokenStatus IsTokenValid(
const TrialToken& trial_token,
const url::Origin& origin,
base::span<const url::Origin> third_party_origins,
base::Time current_time) { … }
bool IsTokenExpired(const std::string_view trial_name,
const base::Time token_expiry_time,
const base::Time current_time) { … }
OriginTrialTokenStatus ValidateTokenEnabled(
const OriginTrialPolicy& policy,
const std::string_view trial_name,
const base::Time token_expiry_time,
const TrialToken::UsageRestriction usage_restriction,
const std::string_view token_signature,
const base::Time current_time) { … }
}
TrialTokenValidator::OriginInfo::OriginInfo(const url::Origin& wrapped_origin)
: … { … }
TrialTokenValidator::OriginInfo::OriginInfo(const url::Origin& wrapped_origin,
bool origin_is_secure)
: … { … }
TrialTokenValidator::TrialTokenValidator() = default;
TrialTokenValidator::~TrialTokenValidator() = default;
void TrialTokenValidator::SetOriginTrialPolicyGetter(
base::RepeatingCallback<OriginTrialPolicy*()> policy_getter) { … }
void TrialTokenValidator::ResetOriginTrialPolicyGetter() { … }
TrialTokenResult TrialTokenValidator::ValidateTokenAndTrial(
std::string_view token,
const url::Origin& origin,
base::Time current_time) const { … }
TrialTokenResult TrialTokenValidator::ValidateTokenAndTrial(
std::string_view token,
const url::Origin& origin,
base::span<const url::Origin> third_party_origins,
base::Time current_time) const { … }
TrialTokenResult TrialTokenValidator::ValidateTokenAndTrialWithOriginInfo(
std::string_view token,
const OriginInfo& origin,
base::span<const OriginInfo> third_party_origin_info,
base::Time current_time) const { … }
TrialTokenResult TrialTokenValidator::ValidateToken(
std::string_view token,
const url::Origin& origin,
base::Time current_time) const { … }
TrialTokenResult TrialTokenValidator::ValidateToken(
std::string_view token,
const url::Origin& origin,
base::span<const url::Origin> third_party_origins,
base::Time current_time) const { … }
bool TrialTokenValidator::RevalidateTokenAndTrial(
const std::string_view trial_name,
const base::Time token_expiry_time,
const TrialToken::UsageRestriction usage_restriction,
const std::string_view token_signature,
const base::Time current_time) const { … }
std::vector<mojom::OriginTrialFeature>
TrialTokenValidator::FeaturesEnabledByTrial(std::string_view trial_name) { … }
bool TrialTokenValidator::TrialEnablesFeaturesForOS(
std::string_view trial_name) { … }
bool TrialTokenValidator::RequestEnablesFeature(const net::URLRequest* request,
std::string_view feature_name,
base::Time current_time) const { … }
bool TrialTokenValidator::RequestEnablesFeature(
const GURL& request_url,
const net::HttpResponseHeaders* response_headers,
std::string_view feature_name,
base::Time current_time) const { … }
bool TrialTokenValidator::RequestEnablesDeprecatedFeature(
const GURL& request_url,
const net::HttpResponseHeaders* response_headers,
std::string_view feature_name,
base::Time current_time) const { … }
bool TrialTokenValidator::ResponseBearsValidTokenForFeature(
const GURL& request_url,
const net::HttpResponseHeaders& response_headers,
std::string_view feature_name,
base::Time current_time) const { … }
std::unique_ptr<TrialTokenValidator::FeatureToTokensMap>
TrialTokenValidator::GetValidTokensFromHeaders(
const url::Origin& origin,
const net::HttpResponseHeaders* headers,
base::Time current_time) const { … }
std::unique_ptr<TrialTokenValidator::FeatureToTokensMap>
TrialTokenValidator::GetValidTokens(const url::Origin& origin,
const FeatureToTokensMap& tokens,
base::Time current_time) const { … }
bool TrialTokenValidator::IsTrialPossibleOnOrigin(const GURL& url) { … }
}