-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make bookmark toggle on NTP whether bookmark is empty or not #2563
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* 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 <vector> | ||
|
||
#include "chrome/browser/bookmarks/bookmark_model_factory.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/search/search.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_commands.h" | ||
#include "chrome/browser/ui/tabs/tab_strip_model.h" | ||
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | ||
#include "chrome/common/url_constants.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "components/bookmarks/browser/bookmark_model.h" | ||
#include "components/bookmarks/browser/bookmark_utils.h" | ||
#include "content/public/browser/navigation_entry.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
#include "url/gurl.h" | ||
|
||
using BookmarkTabHelperBrowserTest = InProcessBrowserTest; | ||
|
||
namespace { | ||
|
||
bool IsNTP(content::WebContents* web_contents) { | ||
// Use the committed entry so the bookmarks bar disappears at the same time | ||
// the page does. | ||
content::NavigationEntry* entry = | ||
web_contents->GetController().GetLastCommittedEntry(); | ||
if (!entry) | ||
entry = web_contents->GetController().GetVisibleEntry(); | ||
return (entry && NewTabUI::IsNewTab(entry->GetURL())) || | ||
search::NavEntryIsInstantNTP(web_contents, entry); | ||
} | ||
|
||
} // namespace | ||
|
||
IN_PROC_BROWSER_TEST_F(BookmarkTabHelperBrowserTest, | ||
BookmarkBarOnNTPToggleTest) { | ||
auto* contents = browser()->tab_strip_model()->GetActiveWebContents(); | ||
EXPECT_TRUE(content::NavigateToURL(contents, | ||
GURL(chrome::kChromeUINewTabURL))); | ||
EXPECT_TRUE(IsNTP(contents)); | ||
chrome::ToggleBookmarkBar(browser()); | ||
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | ||
|
||
const GURL url = GURL("https://www.brave.com"); | ||
bookmarks::BookmarkModel* bookmark_model = | ||
BookmarkModelFactory::GetForBrowserContext(browser()->profile()); | ||
|
||
std::vector<const bookmarks::BookmarkNode*> nodes; | ||
bookmark_model->GetNodesByURL(url, &nodes); | ||
EXPECT_EQ(0UL, nodes.size()); | ||
|
||
bookmarks::AddIfNotBookmarked(bookmark_model, url, base::string16()); | ||
bookmark_model->GetNodesByURL(url, &nodes); | ||
EXPECT_EQ(1UL, nodes.size()); | ||
|
||
chrome::ToggleBookmarkBar(browser()); | ||
EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); | ||
} |
12 changes: 12 additions & 0 deletions
12
patches/chrome-browser-ui-bookmarks-bookmark_tab_helper.cc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc | ||
index f6ef61a0ac86ae55e8f9e80ece0758253af48520..888d656cf7080ebc32e90fc492e70a9b394d7026 100644 | ||
--- a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc | ||
+++ b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc | ||
@@ -67,6 +67,7 @@ bool BookmarkTabHelper::ShouldShowBookmarkBar() const { | ||
!prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)) | ||
return false; | ||
|
||
+ return false; | ||
// The bookmark bar is only shown on the NTP if the user | ||
// has added something to it. | ||
return IsNTP(web_contents()) && bookmark_model_ && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was expecting to see something like
return !IsNTP(web_contents())
here. Is it safe to just return false here without further checks?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emerick I think this method is used for preventing bookmark bar visible or hidden opposite to the
kShowBookmarkBar
prefs value.When
kShowBookmarkBar
is set to hidden, this method only returns true when active tab is NTP and bookmark bar isn't empty if all above conditions aren't met. So, we can hide bookmark bar on NTP by returning false here in this case.When
kShowBookmarkBar
is set to visible, this method isn't called except fullscreen condition.According to the comment of
Browser::ShouldHideUIForFullscreen()
, browser controls UI can be visible on MacOS fullscreen mode by sliding down. WhenBrowser::ShouldHideUIForFullscreen()
returns true, this method will be called and we should also return false to hide bookmark bar.So, I think returning false in here is safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emerick Thanks for quick review!