chromium/third_party/blink/renderer/core/speculation_rules/document_speculation_rules.cc

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

#include "third_party/blink/renderer/core/speculation_rules/document_speculation_rules.h"

#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/state_transitions.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-shared.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/css/style_rule.h"
#include "third_party/blink/renderer/core/display_lock/display_lock_utilities.h"
#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/shadow_including_tree_order_traversal.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/event_handler_registry.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/html_anchor_element.h"
#include "third_party/blink/renderer/core/html/html_area_element.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/lcp_critical_path_predictor/lcp_critical_path_predictor.h"
#include "third_party/blink/renderer/core/loader/speculation_rule_loader.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/speculation_rules/document_rule_predicate.h"
#include "third_party/blink/renderer/core/speculation_rules/speculation_candidate.h"
#include "third_party/blink/renderer/core/speculation_rules/speculation_rules_metrics.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/weborigin/referrer.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/weborigin/security_policy.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

namespace {

// https://wicg.github.io/nav-speculation/prefetch.html#list-of-sufficiently-strict-speculative-navigation-referrer-policies
bool AcceptableReferrerPolicy(const Referrer& referrer,
                              bool is_initially_same_site) {}

String SpeculationActionAsString(mojom::blink::SpeculationAction action) {}

String MakeReferrerWarning(mojom::blink::SpeculationAction action,
                           const KURL& url,
                           const Referrer& referrer,
                           bool has_link) {}

// Computes a referrer based on a Speculation Rule, and its URL or the link it
// is matched against. Return std::nullopt if the computed referrer policy is
// not acceptable (see AcceptableReferrerPolicy above).
std::optional<Referrer> GetReferrer(const SpeculationRule* rule,
                                    const SpeculationRuleSet& rule_set,
                                    Document& document,
                                    mojom::blink::SpeculationAction action,
                                    HTMLAnchorElement* link,
                                    std::optional<KURL> opt_url) {}

// The reason for calling |UpdateSpeculationCandidates| for metrics.
// Currently, this is designed to measure the impact of the project of
// retriggering preloading on BFCache restoration (crbug.com/1449163), so
// other update reasons (such as ruleset insertion/removal etc...) will be
// tentatively classified as |kOther|.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class UpdateSpeculationCandidatesReason {};

}  // namespace

std::ostream& operator<<(
    std::ostream& o,
    const DocumentSpeculationRules::PendingUpdateState& s) {}

// static
const char DocumentSpeculationRules::kSupplementName[] =;

// static
DocumentSpeculationRules& DocumentSpeculationRules::From(Document& document) {}

// static
DocumentSpeculationRules* DocumentSpeculationRules::FromIfExists(
    Document& document) {}

DocumentSpeculationRules::DocumentSpeculationRules(Document& document)
    :{}

void DocumentSpeculationRules::OnLCPPredicted(const Element*) {}

void DocumentSpeculationRules::AddRuleSet(SpeculationRuleSet* rule_set) {}

void DocumentSpeculationRules::RemoveRuleSet(SpeculationRuleSet* rule_set) {}

void DocumentSpeculationRules::AddSpeculationRuleLoader(
    SpeculationRuleLoader* speculation_rule_loader) {}

void DocumentSpeculationRules::RemoveSpeculationRuleLoader(
    SpeculationRuleLoader* speculation_rule_loader) {}

void DocumentSpeculationRules::LinkInserted(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::LinkRemoved(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::HrefAttributeChanged(
    HTMLAnchorElement* link,
    const AtomicString& old_value,
    const AtomicString& new_value) {}

void DocumentSpeculationRules::ReferrerPolicyAttributeChanged(
    HTMLAnchorElement* link) {}

void DocumentSpeculationRules::RelAttributeChanged(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::TargetAttributeChanged(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::DocumentReferrerPolicyChanged() {}

void DocumentSpeculationRules::DocumentBaseURLChanged() {}

void DocumentSpeculationRules::DocumentBaseTargetChanged() {}

void DocumentSpeculationRules::LinkMatchedSelectorsUpdated(
    HTMLAnchorElement* link) {}

void DocumentSpeculationRules::LinkGainedOrLostComputedStyle(
    HTMLAnchorElement* link) {}

void DocumentSpeculationRules::DocumentStyleUpdated() {}

void DocumentSpeculationRules::ChildStyleRecalcBlocked(Element* root) {}

void DocumentSpeculationRules::DidStyleChildren(Element* root) {}

void DocumentSpeculationRules::DisplayLockedElementDisconnected(Element* root) {}

void DocumentSpeculationRules::DocumentRestoredFromBFCache() {}

void DocumentSpeculationRules::InitiatePreview(const KURL& url) {}

void DocumentSpeculationRules::QueueUpdateSpeculationCandidates(
    bool force_style_update) {}

void DocumentSpeculationRules::Trace(Visitor* visitor) const {}

mojom::blink::SpeculationHost* DocumentSpeculationRules::GetHost() {}

void DocumentSpeculationRules::UpdateSpeculationCandidatesMicrotask() {}

void DocumentSpeculationRules::UpdateSpeculationCandidates() {}

void DocumentSpeculationRules::AddLinkBasedSpeculationCandidates(
    HeapVector<Member<SpeculationCandidate>>& candidates) {}

void DocumentSpeculationRules::InitializeIfNecessary() {}

void DocumentSpeculationRules::LinkAttributeChanged(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::DocumentPropertyChanged() {}

void DocumentSpeculationRules::AddLink(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::RemoveLink(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::InvalidateLink(HTMLAnchorElement* link) {}

void DocumentSpeculationRules::InvalidateAllLinks() {}

void DocumentSpeculationRules::UpdateSelectors() {}

void DocumentSpeculationRules::SetPendingUpdateState(
    PendingUpdateState new_state) {}

}  // namespace blink