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
|
// Copyright 2025 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_RENDERER_HOST_NAVIGATION_THROTTLE_REGISTRY_IMPL_H_
#define CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_THROTTLE_REGISTRY_IMPL_H_
#include <memory>
#include <vector>
#include "base/memory/raw_ref.h"
#include "base/memory/safety_checks.h"
#include "content/common/content_export.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/navigation_throttle_registry.h"
namespace content {
class NavigationHandle;
class NavigationRequest;
// The different event types that can be processed by NavigationThrottles.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// This type is also used in the UKM as set in the RecordDeferTimeUKM().
//
// LINT.IfChange(NavigationThrottleEvent)
enum class NavigationThrottleEvent {
kNoEvent = 0,
kWillStartRequest = 1,
kWillRedirectRequest = 2,
kWillFailRequest = 3,
kWillProcessResponse = 4,
kWillCommitWithoutUrlLoader = 5,
kMaxValue = kWillCommitWithoutUrlLoader,
};
// LINT.ThenChange(//tools/metrics/histograms/metadata/navigation/enums.xml:NavigationThrottleEvent)
class CONTENT_EXPORT NavigationThrottleRegistryBase
: public NavigationThrottleRegistry {
public:
~NavigationThrottleRegistryBase() override;
// Called when the NavigationThrottleRunner is done processing the navigation
// event of type `event`. `result` is the final
// NavigationThrottle::ThrottleCheckResult for this event.
virtual void OnEventProcessed(
NavigationThrottleEvent event,
NavigationThrottle::ThrottleCheckResult result) = 0;
// Returns the list of NavigationThrottles registered for this navigation.
virtual std::vector<std::unique_ptr<NavigationThrottle>>& GetThrottles() = 0;
// Returns the NavigationThrottle at the given `index`. The `index` should
// be in a valid range.
virtual NavigationThrottle& GetThrottleAtIndex(size_t index) = 0;
};
class NavigationThrottleRegistryImpl : public NavigationThrottleRegistryBase {
// Do not remove this macro!
// The macro is maintained by the memory safety team.
ADVANCED_MEMORY_SAFETY_CHECKS();
public:
explicit NavigationThrottleRegistryImpl(
NavigationRequest* navigation_request);
NavigationThrottleRegistryImpl(const NavigationThrottleRegistryImpl&) =
delete;
NavigationThrottleRegistryImpl& operator=(
const NavigationThrottleRegistryImpl&) = delete;
~NavigationThrottleRegistryImpl() override;
// Registers the appropriate NavigationThrottles for a "standard" navigation
// (i.e., one with a URLLoader that goes through the
// WillSendRequest/WillProcessResponse callback sequence).
void RegisterNavigationThrottles();
// Registers the appropriate NavigationThrottles for a navigation that can
// immediately commit because no URLLoader is required (about:blank,
// about:srcdoc, and most same-document navigations).
void RegisterNavigationThrottlesForCommitWithoutUrlLoader();
// Implements NavigationThrottleRegistry:
NavigationHandle& GetNavigationHandle() override;
void AddThrottle(
std::unique_ptr<NavigationThrottle> navigation_throttle) override;
bool HasThrottle(const std::string& name) override;
bool EraseThrottleForTesting(const std::string& name) override;
// Implements NavigationThrottleRegistryBase:
void OnEventProcessed(
NavigationThrottleEvent event,
NavigationThrottle::ThrottleCheckResult result) override;
std::vector<std::unique_ptr<NavigationThrottle>>& GetThrottles() override;
NavigationThrottle& GetThrottleAtIndex(size_t index) override;
private:
// Holds a reference to the NavigationRequest that owns this instance.
const raw_ref<NavigationRequest> navigation_request_;
// A list of Throttles registered for this navigation.
std::vector<std::unique_ptr<NavigationThrottle>> throttles_;
};
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_THROTTLE_REGISTRY_IMPL_H_
|