Skip to content

Commit

Permalink
Merge pull request #3620 from brave/hide-other-bookmarks
Browse files Browse the repository at this point in the history
Hide other bookmarks
  • Loading branch information
darkdh authored Oct 16, 2019
2 parents f7a6b7d + 1cd5cb7 commit ccafc94
Show file tree
Hide file tree
Showing 30 changed files with 811 additions and 12 deletions.
48 changes: 48 additions & 0 deletions app/bookmark_bar_strings.grdp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--This file is created by l10nUtil.js. Do not edit manually.-->
<grit-part>
<if expr="not is_ios and not use_titlecase">
<message name="IDS_BOOKMARK_BAR_FOLDER_NAME" desc="Name shown in the tree for the Bookmarks Bar folder.">
Bookmarks
</message>
</if>
<if expr="not is_ios and use_titlecase">
<message name="IDS_BOOKMARK_BAR_FOLDER_NAME" desc="In Title Case: Name shown in the tree for the Bookmarks Bar folder.">
Bookmarks
</message>
</if>
<if expr="is_ios">
<message name="IDS_BOOKMARK_BAR_FOLDER_NAME" desc="Mobile: Name shown in the tree for the desktop bookmarks folder">
Desktop Bookmarks
</message>
</if>

<if expr="not use_titlecase">
<message name="IDS_BOOKMARK_BAR_MOBILE_FOLDER_NAME" desc="Name shown in the tree for the mobile bookmarks folder">
Mobile bookmarks
</message>
<message name="IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME" desc="Name shown in the tree for the other bookmarks folder">
Other bookmarks
</message>
<message name="IDS_BOOKMARK_BAR_MANAGED_FOLDER_DOMAIN_NAME" desc="Name shown in the tree for the managed bookmarks folder, when the managed bookmarks come from a domain">
<ph name="DOMAIN">$1<ex>google.com</ex></ph> bookmarks
</message>
<message name="IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME" desc="Name shown in the tree for the managed bookmarks folder, when the managed bookmarks don't come from a domain">
Managed bookmarks
</message>
</if>
<if expr="use_titlecase">
<message name="IDS_BOOKMARK_BAR_MOBILE_FOLDER_NAME" desc="In Title Case: Name shown in the tree for the mobile bookmarks folder">
Mobile Bookmarks
</message>
<message name="IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME" desc="In Title Case: Name shown in the tree for the other bookmarks folder">
Other Bookmarks
</message>
<message name="IDS_BOOKMARK_BAR_MANAGED_FOLDER_DOMAIN_NAME" desc="In Title Case: Name shown in the tree for the managed bookmarks folder, when the managed bookmarks come from a domain">
<ph name="DOMAIN">$1<ex>google.com</ex></ph> Bookmarks
</message>
<message name="IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME" desc="In Title Case: Name shown in the tree for the managed bookmarks folder, when the managed bookmarks don't come from a domain">
Managed Bookmarks
</message>
</if>
</grit-part>
4 changes: 2 additions & 2 deletions app/bookmarks_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</message>
<if expr="not is_android">
<message name="IDS_SHOW_BOOKMARK_BAR" desc="The toggle to show the bookmark bar">
&amp;Show bookmarks bar
&amp;Show bookmarks
</message>
</if>
</if>
Expand Down Expand Up @@ -155,7 +155,7 @@
</message>
<if expr="not is_android">
<message name="IDS_SHOW_BOOKMARK_BAR" desc="In Title Case: The toggle to show the bookmark bar">
&amp;Show Bookmarks Bar
&amp;Show Bookmarks
</message>
</if>
</if>
Expand Down
2 changes: 1 addition & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Hides the Brave Rewards button in the location bar when Brave Rewards is not enabled
</message>
<message name="IDS_SETTINGS_ALWAYS_SHOW_BOOKMARK_BAR_ON_NTP" desc="The label for settings switch controlling the visibility of bookmarks bar on NTP">
Always show bookmarks bar on New Tab page
Always show bookmarks on New Tab page
</message>
<!-- Tor -->
<message name="IDS_NEW_TOR_IDENTITY" desc="The text label of a menu item for requesting new Tor identity">
Expand Down
394 changes: 394 additions & 0 deletions app/components_strings.grd

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -7824,7 +7824,7 @@ Please help our engineers fix this problem. Tell us what happened right before y
</message>
<!-- View menu -->
<message name="IDS_BOOKMARK_BAR_ALWAYS_SHOW_MAC" desc="The Mac menu item for having bookmark bar always visible in the view menu.">
Always Show Bookmarks Bar
Always Show Bookmarks
</message>
<message name="IDS_STOP_MENU_MAC" desc="The Mac menu item stop in the view menu.">
Stop
Expand Down
2 changes: 1 addition & 1 deletion app/settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@
Show home button
</message>
<message name="IDS_SETTINGS_SHOW_BOOKMARKS_BAR" desc="Label for the checkbox which enables or disables showing the bookmarks bar in the toolbar.">
Show bookmarks bar
Show bookmarks
</message>
<message name="IDS_SETTINGS_HOME_PAGE_NTP" desc="Description of the New Tab Page when set as the home page.">
New Tab page
Expand Down
2 changes: 2 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ source_set("browser_process") {
"autocomplete/brave_autocomplete_provider_client.h",
"autocomplete/brave_autocomplete_scheme_classifier.cc",
"autocomplete/brave_autocomplete_scheme_classifier.h",
"bookmarks/brave_bookmark_client.cc",
"bookmarks/brave_bookmark_client.h",
"brave_shields/ad_block_pref_service_factory.cc",
"brave_shields/ad_block_pref_service_factory.h",
"brave_shields/cookie_pref_service_factory.cc",
Expand Down
23 changes: 23 additions & 0 deletions browser/bookmarks/brave_bookmark_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#include "brave/browser/bookmarks/brave_bookmark_client.h"

BraveBookmarkClient::BraveBookmarkClient(
Profile* profile,
bookmarks::ManagedBookmarkService* managed_bookmark_service,
sync_bookmarks::BookmarkSyncService* bookmark_sync_service) :
ChromeBookmarkClient(profile, managed_bookmark_service,
bookmark_sync_service) {
}

BraveBookmarkClient::~BraveBookmarkClient() {}

bool BraveBookmarkClient::IsPermanentNodeVisible(
const bookmarks::BookmarkPermanentNode* node) {
if (node->type() == bookmarks::BookmarkNode::OTHER_NODE)
return false;
return ChromeBookmarkClient::IsPermanentNodeVisible(node);
}
26 changes: 26 additions & 0 deletions browser/bookmarks/brave_bookmark_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_
#define BRAVE_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_

#include "chrome/browser/bookmarks/chrome_bookmark_client.h"

class BraveBookmarkClient : public ChromeBookmarkClient {
public:
BraveBookmarkClient(
Profile* profile,
bookmarks::ManagedBookmarkService* managed_bookmark_service,
sync_bookmarks::BookmarkSyncService* bookmark_sync_service);
~BraveBookmarkClient() override;

// bookmarks::BookmarkClient:
bool IsPermanentNodeVisible(
const bookmarks::BookmarkPermanentNode* node) override;
private:
DISALLOW_COPY_AND_ASSIGN(BraveBookmarkClient);
};

#endif // BRAVE_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_
28 changes: 28 additions & 0 deletions browser/bookmarks/brave_bookmark_client_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */

#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/bookmarks/browser/bookmark_model.h"

using BraveBookmarkClientTest = InProcessBrowserTest;

IN_PROC_BROWSER_TEST_F(BraveBookmarkClientTest, IsPermanentNodeVisible) {
bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(browser()->profile());
EXPECT_TRUE(bookmark_model->bookmark_bar_node()->IsVisible());
// Other node invisible by default
EXPECT_FALSE(bookmark_model->other_node()->IsVisible());
EXPECT_FALSE(bookmark_model->mobile_node()->IsVisible());

bookmark_model->AddURL(bookmark_model->other_node(), 0,
base::ASCIIToUTF16("A"), GURL("https://A.com"));
EXPECT_TRUE(bookmark_model->other_node()->IsVisible());
BraveMigrateOtherNode(bookmark_model);
EXPECT_FALSE(bookmark_model->other_node()->IsVisible());
}
2 changes: 2 additions & 0 deletions browser/profiles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import("//components/gcm_driver/config.gni")

source_set("profiles") {
sources = [
"brave_bookmark_model_loaded_observer.cc",
"brave_bookmark_model_loaded_observer.h",
"brave_profile_impl.cc",
"brave_profile_impl.h",
"brave_profile_manager.cc",
Expand Down
38 changes: 38 additions & 0 deletions browser/profiles/brave_bookmark_model_loaded_observer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#include "brave/browser/profiles/brave_bookmark_model_loaded_observer.h"

#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/bookmarks/browser/bookmark_model.h"

#include "brave/components/brave_sync/buildflags/buildflags.h"
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
#include "brave/components/brave_sync/brave_profile_sync_service_impl.h"
using brave_sync::BraveProfileSyncServiceImpl;
#endif

using bookmarks::BookmarkModel;

BraveBookmarkModelLoadedObserver::BraveBookmarkModelLoadedObserver(
Profile* profile)
: BookmarkModelLoadedObserver(profile) {}

void BraveBookmarkModelLoadedObserver::BookmarkModelLoaded(
BookmarkModel* model,
bool ids_reassigned) {
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
BraveProfileSyncServiceImpl* brave_profile_service =
static_cast<BraveProfileSyncServiceImpl*>(
ProfileSyncServiceFactory::GetForProfile(profile_));
// When sync is enabled, we need to send migration records to other devices so
// it is handled in BraveProfileSyncServiceImpl::OnSyncReady
if (!brave_profile_service->IsBraveSyncEnabled())
BraveMigrateOtherNode(model);
#else
BraveMigrateOtherNode(model);
#endif
BookmarkModelLoadedObserver::BookmarkModelLoaded(model, ids_reassigned);
}
23 changes: 23 additions & 0 deletions browser/profiles/brave_bookmark_model_loaded_observer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_PROFILES_BRAVE_BOOKMARK_MODEL_LOADED_OBSERVER_H_
#define BRAVE_BROWSER_PROFILES_BRAVE_BOOKMARK_MODEL_LOADED_OBSERVER_H_

#include "chrome/browser/profiles/bookmark_model_loaded_observer.h"

class BraveBookmarkModelLoadedObserver
: public BookmarkModelLoadedObserver {
public:
explicit BraveBookmarkModelLoadedObserver(Profile* profile);

private:
void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
bool ids_reassigned) override;

DISALLOW_COPY_AND_ASSIGN(BraveBookmarkModelLoadedObserver);
};

#endif // BRAVE_BROWSER_PROFILES_BRAVE_BOOKMARK_MODEL_LOADED_OBSERVER_H_
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ source_set("ui") {
"bookmark/bookmark_prefs_service.h",
"bookmark/bookmark_prefs_service_factory.cc",
"bookmark/bookmark_prefs_service_factory.h",
"bookmark/recently_used_folders_combo_model.cc",
"bookmark/recently_used_folders_combo_model.h",
"brave_browser_command_controller.cc",
"brave_browser_command_controller.h",
"brave_browser_content_setting_bubble_model_delegate.cc",
Expand Down
17 changes: 17 additions & 0 deletions browser/ui/bookmark/recently_used_folders_combo_model.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/bookmark/recently_used_folders_combo_model.h"

#include "components/bookmarks/browser/bookmark_model.h"

BraveRecentlyUsedFoldersComboModel::BraveRecentlyUsedFoldersComboModel(
bookmarks::BookmarkModel* model,
const bookmarks::BookmarkNode* node)
: RecentlyUsedFoldersComboModel(model, node) {
RecentlyUsedFoldersComboModel::RemoveNode(model->other_node());
}

BraveRecentlyUsedFoldersComboModel::~BraveRecentlyUsedFoldersComboModel() {}
22 changes: 22 additions & 0 deletions browser/ui/bookmark/recently_used_folders_combo_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_BOOKMARK_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
#define BRAVE_BROWSER_UI_BOOKMARK_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_

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

class BraveRecentlyUsedFoldersComboModel
: public RecentlyUsedFoldersComboModel {
public:
BraveRecentlyUsedFoldersComboModel(bookmarks::BookmarkModel* model,
const bookmarks::BookmarkNode* node);
~BraveRecentlyUsedFoldersComboModel() override;

private:
DISALLOW_COPY_AND_ASSIGN(BraveRecentlyUsedFoldersComboModel);
};

#endif // BRAVE_BROWSER_UI_BOOKMARK_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

#define GetBrowserContextRedirectedInIncognito \
GetBrowserContextRedirectedInIncognitoOverride
#define ChromeBookmarkClient BraveBookmarkClient
#include "../../../../../chrome/browser/bookmarks/bookmark_model_factory.cc"
#undef ChromeBookmarkClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_BOOKMARK_MODEL_LOADED_OBSERVER_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_BOOKMARK_MODEL_LOADED_OBSERVER_H_

#define BRAVE_BOOKMARK_MODEL_LOADED_OBSERVER_H_ \
private: \
friend class BraveBookmarkModelLoadedObserver; \
\
public:
#include "../../../../../chrome/browser/profiles/bookmark_model_loaded_observer.h"

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_BOOKMARK_MODEL_LOADED_OBSERVER_H_
4 changes: 4 additions & 0 deletions chromium_src/chrome/browser/profiles/profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/profiles/brave_bookmark_model_loaded_observer.h"
#include "brave/browser/profiles/brave_profile_impl.h"
#define BookmarkModelLoadedObserver BraveBookmarkModelLoadedObserver
#define PermissionManagerFactory BravePermissionManagerFactory
#include "../../../../../chrome/browser/profiles/profile_impl.cc"
#undef PermissionManagerFactory
#undef BookmarkModelLoadedObserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_

#define BRAVE_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_ \
private: \
friend class BraveRecentlyUsedFoldersComboModel; \
public:
#include "../../../../../../chrome/browser/ui/bookmarks/recently_used_folders_combo_model.h" // NOLINT
#undef BRAVE_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/bookmark/recently_used_folders_combo_model.h"

#define RecentlyUsedFoldersComboModel BraveRecentlyUsedFoldersComboModel
#include "../../../../../../../chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc"
#undef RecentlyUsedFoldersComboModel
27 changes: 27 additions & 0 deletions chromium_src/components/bookmarks/browser/bookmark_model.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#include "../../../../../components/bookmarks/browser/bookmark_model.cc"

namespace bookmarks {

// Move bookmarks under "Other Bookmarks" permanent node to a same name folder
// at the end of "Bookmark Bar" permanent node
void BraveMigrateOtherNode(BookmarkModel* model) {
DCHECK(model);
if (!model->other_node()->children().empty()) {
const bookmarks::BookmarkNode* new_other_node =
model->AddFolder(model->bookmark_bar_node(),
model->bookmark_bar_node()->children().size(),
model->other_node()->GetTitledUrlNodeTitle());
size_t children_size = model->other_node()->children().size();
for (size_t i = 0; i < children_size; ++i) {
model->Move(model->other_node()->children().front().get(), new_other_node,
i);
}
}
}

} // namespace bookmarks
Loading

0 comments on commit ccafc94

Please sign in to comment.