0

NavigationThrottleRunner2: NavigationThrottle ctor migration for fuchsia

Bug: 412524375
Change-Id: I0606927ef879a8ee14cb225c45bb6866f81da53c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6575480
Reviewed-by: Zijie He <zijiehe@google.com>
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1463449}
This commit is contained in:
Takashi Toyoshima
2025-05-21 08:15:49 -07:00
committed by Chromium LUCI CQ
parent b8ba2d9590
commit 16a7de155a
4 changed files with 34 additions and 15 deletions

@ -5,6 +5,7 @@
#include "fuchsia_web/webengine/browser/navigation_policy_throttle.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_throttle_registry.h"
#include "fuchsia_web/webengine/browser/navigation_controller_impl.h"
#include "fuchsia_web/webengine/browser/navigation_policy_handler.h"
@ -29,11 +30,9 @@ fuchsia::web::RequestedNavigation ToRequestedNavigation(
} // namespace
NavigationPolicyThrottle::NavigationPolicyThrottle(
content::NavigationHandle* handle,
content::NavigationThrottleRegistry& registry,
NavigationPolicyHandler* policy_handler)
: NavigationThrottle(handle),
policy_handler_(policy_handler),
navigation_handle_(handle) {
: NavigationThrottle(registry), policy_handler_(policy_handler) {
if (policy_handler->is_provider_connected()) {
policy_handler_->RegisterNavigationThrottle(this);
} else {
@ -119,13 +118,13 @@ NavigationPolicyThrottle::HandleNavigationPhase(
content::NavigationThrottle::CANCEL);
}
if (!policy_handler_->ShouldEvaluateNavigation(navigation_handle_, phase)) {
if (!policy_handler_->ShouldEvaluateNavigation(navigation_handle(), phase)) {
return content::NavigationThrottle::ThrottleCheckResult(
content::NavigationThrottle::PROCEED);
}
policy_handler_->EvaluateRequestedNavigation(
ToRequestedNavigation(navigation_handle_, phase),
ToRequestedNavigation(navigation_handle(), phase),
[weak_this = weak_factory_.GetWeakPtr()](auto decision) {
if (weak_this) {
weak_this->OnRequestedNavigationEvaluated(std::move(decision));

@ -11,13 +11,18 @@
#include "content/public/browser/navigation_throttle.h"
#include "fuchsia_web/webengine/web_engine_export.h"
namespace content {
class NavigationThrottleRegistry;
} // namespace content
class NavigationPolicyHandler;
class WEB_ENGINE_EXPORT NavigationPolicyThrottle
: public content::NavigationThrottle {
public:
explicit NavigationPolicyThrottle(content::NavigationHandle* handle,
NavigationPolicyHandler* policy_handler);
explicit NavigationPolicyThrottle(
content::NavigationThrottleRegistry& registry,
NavigationPolicyHandler* policy_handler);
~NavigationPolicyThrottle() override;
NavigationPolicyThrottle(const NavigationPolicyThrottle&) = delete;
@ -40,7 +45,6 @@ class WEB_ENGINE_EXPORT NavigationPolicyThrottle
fuchsia::web::NavigationPhase phase);
raw_ptr<NavigationPolicyHandler> policy_handler_;
raw_ptr<content::NavigationHandle> navigation_handle_;
// Indicates if the navigation is currently paused.
bool is_paused_ = false;

@ -9,6 +9,7 @@
#include "base/test/task_environment.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/mock_navigation_throttle_registry.h"
#include "fuchsia_web/webengine/browser/fake_navigation_policy_provider.h"
#include "fuchsia_web/webengine/browser/navigation_policy_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -89,7 +90,10 @@ TEST_F(NavigationPolicyThrottleTest, WillStartRequest_MainFrame) {
navigation_handle.set_is_same_document(true);
policy_provider()->set_should_abort_navigation(true);
NavigationPolicyThrottle throttle(&navigation_handle, policy_handler_.get());
content::MockNavigationThrottleRegistry registry(
&navigation_handle,
content::MockNavigationThrottleRegistry::RegistrationMode::kHold);
NavigationPolicyThrottle throttle(registry, policy_handler_.get());
auto result = throttle.WillStartRequest();
EXPECT_EQ(content::NavigationThrottle::DEFER, result);
@ -119,7 +123,10 @@ TEST_F(NavigationPolicyThrottleTest, WillStartRequest_SubFrame) {
navigation_handle.set_is_same_document(false);
policy_provider()->set_should_abort_navigation(true);
NavigationPolicyThrottle throttle(&navigation_handle, policy_handler_.get());
content::MockNavigationThrottleRegistry registry(
&navigation_handle,
content::MockNavigationThrottleRegistry::RegistrationMode::kHold);
NavigationPolicyThrottle throttle(registry,policy_handler_.get());
auto result = throttle.WillStartRequest();
EXPECT_EQ(content::NavigationThrottle::PROCEED, result);
@ -132,7 +139,10 @@ TEST_F(NavigationPolicyThrottleTest, WillRedirectRequest) {
navigation_handle.set_is_same_document(false);
policy_provider()->set_should_abort_navigation(true);
NavigationPolicyThrottle throttle(&navigation_handle, policy_handler_.get());
content::MockNavigationThrottleRegistry registry(
&navigation_handle,
content::MockNavigationThrottleRegistry::RegistrationMode::kHold);
NavigationPolicyThrottle throttle(registry, policy_handler_.get());
auto result = throttle.WillRedirectRequest();
EXPECT_EQ(content::NavigationThrottle::PROCEED, result);
@ -146,7 +156,10 @@ TEST_F(NavigationPolicyThrottleTest, WillFailRequest) {
navigation_handle.set_is_same_document(true);
policy_provider()->set_should_abort_navigation(false);
NavigationPolicyThrottle throttle(&navigation_handle, policy_handler_.get());
content::MockNavigationThrottleRegistry registry(
&navigation_handle,
content::MockNavigationThrottleRegistry::RegistrationMode::kHold);
NavigationPolicyThrottle throttle(registry, policy_handler_.get());
auto result = throttle.WillFailRequest();
EXPECT_EQ(content::NavigationThrottle::DEFER, result);
@ -165,7 +178,10 @@ TEST_F(NavigationPolicyThrottleTest, WillProcessResponse) {
navigation_handle.set_is_same_document(true);
policy_provider()->set_should_abort_navigation(false);
NavigationPolicyThrottle throttle(&navigation_handle, policy_handler_.get());
content::MockNavigationThrottleRegistry registry(
&navigation_handle,
content::MockNavigationThrottleRegistry::RegistrationMode::kHold);
NavigationPolicyThrottle throttle(registry, policy_handler_.get());
auto result = throttle.WillProcessResponse();
EXPECT_EQ(content::NavigationThrottle::DEFER, result);

@ -318,7 +318,7 @@ void WebEngineContentBrowserClient::CreateThrottlesForNavigation(
// indicating an interest in navigations.
if (frame_impl->navigation_policy_handler()) {
registry.AddThrottle(std::make_unique<NavigationPolicyThrottle>(
&navigation_handle, frame_impl->navigation_policy_handler()));
registry, frame_impl->navigation_policy_handler()));
}
const std::optional<std::string>& explicit_sites_filter_error_page =