Restore old brave:// schemes as chrome:// and revert verbatim_match.cc removal from (#34913)

This fixes several bugs introduced by #34913. Previously saved sessions with `brave://` virtual urls were not properly restored and brave:// urls were sometimes treated as searches on android
This commit is contained in:
Brian Johnson
2026-03-24 02:05:50 +01:00
committed by GitHub
parent 4f58e0cdfa
commit 2ac3a19ee1
3 changed files with 40 additions and 0 deletions
@@ -0,0 +1,16 @@
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#include "components/omnibox/browser/verbatim_match.h"
#include "content/public/common/url_constants.h"
#if BUILDFLAG(IS_ANDROID)
#define kChromeUIScheme kChromeUIScheme, content::kBraveUIScheme
#endif // BUILDFLAG(IS_ANDROID)
#include <components/omnibox/browser/verbatim_match.cc>
#if BUILDFLAG(IS_ANDROID)
#undef kChromeUIScheme
#endif // BUILDFLAG(IS_ANDROID)
@@ -11,6 +11,7 @@
#include "brave/components/containers/buildflags/buildflags.h"
#include "components/sessions/core/serialized_navigation_entry.h"
#include "content/public/common/url_constants.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_CONTAINERS)
#include "brave/components/containers/content/browser/session_utils.h"
@@ -78,6 +79,14 @@ void ContentSerializedNavigationDriver::Sanitize(
SerializedNavigationEntry* navigation) const {
Sanitize_ChromiumImpl(navigation);
// Restore previous saved urls with brave:// scheme as chrome://
const auto& virtual_url = navigation->virtual_url();
if (virtual_url.SchemeIs(content::kBraveUIScheme)) {
GURL::Replacements replacements;
replacements.SetSchemeStr(content::kChromeUIScheme);
navigation->set_virtual_url(virtual_url.ReplaceComponents(replacements));
}
#if BUILDFLAG(ENABLE_CONTAINERS)
// This method is called when loading a SerializedNavigationEntry from
// disk/sync, BEFORE it's converted to a NavigationEntry. It's our opportunity
@@ -61,4 +61,19 @@ TEST(BraveContentSerializedNavigationDriverTest,
EXPECT_EQ(std::string(), driver->GetSanitizedPageStateForPickle(&navigation));
}
// Tests that restored brave:// pages are converted to chrome://
TEST(BraveContentSerializedNavigationDriverTest,
SanitizeConvertsBraveVirtualUrlToChrome) {
ContentSerializedNavigationDriver* driver =
ContentSerializedNavigationDriver::GetInstance();
SerializedNavigationEntry navigation =
SerializedNavigationEntryTestHelper::CreateNavigationForTest();
// Check encoded data is not empty but clean state only with url info for
// chrome overridable url by extension.
navigation.set_virtual_url(GURL("brave://flags"));
driver->Sanitize(&navigation);
EXPECT_EQ(GURL("chrome://flags"), navigation.virtual_url());
}
} // namespace sessions