0

[WebEngine] Fix NavigationController not to report error on abort

Bug: 405446117
Change-Id: I55fdf1487c40f9d43bac1d5b32ebabdc5d1c3603
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6382277
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Commit-Queue: David Song <wintermelons@google.com>
Reviewed-by: David Song <wintermelons@google.com>
Cr-Commit-Position: refs/heads/main@{#1437769}
This commit is contained in:
Sergey Ulanov 2025-03-25 15:10:50 -07:00 committed by Chromium LUCI CQ
parent d23be1ba4d
commit d28f4c98f2
4 changed files with 24 additions and 3 deletions

@ -146,6 +146,9 @@ void DiffNavigationEntries(const fuchsia::web::NavigationState& old_entry,
} // namespace
const void* const NavigationControllerImpl::kAbortedRequestKey =
&NavigationControllerImpl::kAbortedRequestKey;
NavigationControllerImpl::NavigationControllerImpl(
content::WebContents* web_contents,
void* parent_for_trace_flow)
@ -468,8 +471,15 @@ void NavigationControllerImpl::DidFinishNavigation(
}
active_navigation_ = nullptr;
// Page load may be aborted by the `NavigationPolicyProvider`. It's not
// reported as an error.
bool cancelled_by_navigation_policy_handler =
!!navigation_handle->GetUserData(kAbortedRequestKey);
uncommitted_load_error_ = !navigation_handle->HasCommitted() &&
navigation_handle->GetNetErrorCode() != net::OK;
navigation_handle->GetNetErrorCode() != net::OK &&
!cancelled_by_navigation_policy_handler;
last_error_code_ = navigation_handle->GetNetErrorCode();
OnNavigationEntryChanged();

@ -27,6 +27,8 @@ class NavigationControllerImpl final
public content::WebContentsObserver,
public favicon::FaviconDriverObserver {
public:
static const void* const kAbortedRequestKey;
NavigationControllerImpl(content::WebContents* web_contents,
void* parent_for_trace_flow);

@ -106,6 +106,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPolicyTest, Deferred) {
auto* current_state = frame_.navigation_listener().current_state();
EXPECT_TRUE(current_state->has_is_main_document_loaded());
EXPECT_FALSE(current_state->is_main_document_loaded());
EXPECT_EQ(current_state->page_type(), fuchsia::web::PageType::NORMAL);
EXPECT_EQ(page_url.spec(), policy_provider_.requested_navigation()->url());
}

@ -5,6 +5,7 @@
#include "fuchsia_web/webengine/browser/navigation_policy_throttle.h"
#include "content/public/browser/navigation_handle.h"
#include "fuchsia_web/webengine/browser/navigation_controller_impl.h"
#include "fuchsia_web/webengine/browser/navigation_policy_handler.h"
namespace {
@ -41,8 +42,9 @@ NavigationPolicyThrottle::NavigationPolicyThrottle(
}
NavigationPolicyThrottle::~NavigationPolicyThrottle() {
if (policy_handler_)
if (policy_handler_) {
policy_handler_->RemoveNavigationThrottle(this);
}
}
void NavigationPolicyThrottle::OnNavigationPolicyProviderDisconnected(
@ -69,6 +71,11 @@ void NavigationPolicyThrottle::OnRequestedNavigationEvaluated(
// the NavigationHandle that owns this NavigationThrottle.
break;
case fuchsia::web::NavigationDecision::kAbort:
// Mark the request as aborted so it can be handled by the
// `NavigationControllerImpl` properly.
navigation_handle()->SetUserData(
NavigationControllerImpl::kAbortedRequestKey,
std::make_unique<base::SupportsUserData::Data>());
CancelDeferredNavigation(content::NavigationThrottle::CANCEL);
// DO NOT ADD CODE after this. The callback above will destroy the
// NavigationHandle that owns this NavigationThrottle.
@ -120,8 +127,9 @@ NavigationPolicyThrottle::HandleNavigationPhase(
policy_handler_->EvaluateRequestedNavigation(
ToRequestedNavigation(navigation_handle_, phase),
[weak_this = weak_factory_.GetWeakPtr()](auto decision) {
if (weak_this)
if (weak_this) {
weak_this->OnRequestedNavigationEvaluated(std::move(decision));
}
});
is_paused_ = true;