Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/bookmarks/bookmark_utils.h"

#include "base/strings/string_util.h"
#include "brave/browser/ui/bookmark/bookmark_helper.h"
#include "brave/components/constants/pref_names.h"
#include "build/build_config.h"
Expand All @@ -16,6 +18,7 @@
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/color_utils.h"
#include "url/gurl.h"

namespace chrome {

Expand All @@ -40,6 +43,8 @@ void BraveToggleBookmarkBarState(content::BrowserContext* browser_context) {
#define ShouldShowAppsShortcutInBookmarkBar \
ShouldShowAppsShortcutInBookmarkBar_Unused

#define FormatBookmarkURLForDisplay FormatBookmarkURLForDisplay_ChromiumImpl

#if defined(TOOLKIT_VIEWS)
#define GetBookmarkFolderIcon GetBookmarkFolderIcon_UnUsed
#endif
Expand All @@ -54,6 +59,7 @@ void BraveToggleBookmarkBarState(content::BrowserContext* browser_context) {
#undef ToggleBookmarkBarWhenVisible
#undef IsAppsShortcutEnabled
#undef ShouldShowAppsShortcutInBookmarkBar
#undef FormatBookmarkURLForDisplay

#if defined(TOOLKIT_VIEWS)
#undef GetBookmarkFolderIcon
Expand All @@ -69,6 +75,16 @@ bool ShouldShowAppsShortcutInBookmarkBar(Profile* profile) {
return false;
}

std::u16string FormatBookmarkURLForDisplay(const GURL& url) {
GURL replaced_url = url;
if (url.SchemeIs(content::kChromeUIScheme)) {
GURL::Replacements replacements;
replacements.SetSchemeStr(content::kBraveUIScheme);
replaced_url = url.ReplaceComponents(replacements);
}
return chrome::FormatBookmarkURLForDisplay_ChromiumImpl(replaced_url);
}

#if defined(TOOLKIT_VIEWS)
ui::ImageModel GetBookmarkFolderIcon(BookmarkFolderIconType icon_type,
absl::variant<int, SkColor> color) {
Expand Down
18 changes: 18 additions & 0 deletions chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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/.

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_H_

#include "chrome/browser/ui/bookmarks/bookmark_utils.h"

// This replace is for changing the chrome:// to brave:// scheme displayed in
// Bookmarks Add page
#define FormatBookmarkURLForDisplay \
FormatBookmarkURLForDisplay_ChromiumImpl(const GURL& url); \
std::u16string FormatBookmarkURLForDisplay
#include "../../../../../../chrome/browser/ui/bookmarks/bookmark_utils.h"
#undef FormatBookmarkURLForDisplay
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 "chrome/browser/ui/bookmarks/bookmark_utils.h"

#include "content/public/common/url_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace chrome {
TEST(BraveBookmarkUtilsTest, BraveSchemeIsReplaced) {
GURL url(content::kChromeUIScheme + std::string("://test"));
std::u16string new_url = chrome::FormatBookmarkURLForDisplay(url);
EXPECT_EQ(GURL(new_url).scheme(), content::kBraveUIScheme);
}
} // namespace chrome
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ test("brave_unit_tests") {
"//brave/chromium_src/chrome/browser/history/history_utils_unittest.cc",
"//brave/chromium_src/chrome/browser/lookalikes/lookalike_url_navigation_throttle_unittest.cc",
"//brave/chromium_src/chrome/browser/signin/account_consistency_disabled_unittest.cc",
"//brave/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils_unittest.cc",
"//brave/chromium_src/components/autofill/core/browser/autofill_experiments_unittest.cc",
"//brave/chromium_src/components/variations/service/field_trial_unittest.cc",
"//brave/chromium_src/net/cookies/brave_canonical_cookie_unittest.cc",
Expand Down