-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add always show bookmark bar on NTP option
Some user might want to show bookmark on NTP when they choose to hide bookmark bar.
- Loading branch information
Showing
19 changed files
with
336 additions
and
25 deletions.
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
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
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
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
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
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
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,32 @@ | ||
/* 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 "brave/browser/ui/bookmark/bookmark_prefs_service.h" | ||
|
||
#include "brave/common/pref_names.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_list.h" | ||
|
||
BookmarkPrefsService::BookmarkPrefsService(Profile* profile) | ||
: profile_(profile), | ||
prefs_(profile->GetPrefs()) { | ||
pref_change_registrar_.Init(prefs_); | ||
pref_change_registrar_.Add( | ||
kAlwaysShowBookmarkBarOnNTP, | ||
base::BindRepeating(&BookmarkPrefsService::OnPreferenceChanged, | ||
base::Unretained(this))); | ||
} | ||
|
||
BookmarkPrefsService::~BookmarkPrefsService() = default; | ||
|
||
void BookmarkPrefsService::OnPreferenceChanged() { | ||
for (Browser* browser : *BrowserList::GetInstance()) { | ||
if (profile_->IsSameProfile(browser->profile())) { | ||
browser->UpdateBookmarkBarState( | ||
Browser::BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); | ||
} | ||
} | ||
} |
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,31 @@ | ||
/* 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/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_PREFS_SERVICE_H_ | ||
#define BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_PREFS_SERVICE_H_ | ||
|
||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "components/prefs/pref_change_registrar.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
||
class PrefService; | ||
class Profile; | ||
|
||
class BookmarkPrefsService : public KeyedService { | ||
public: | ||
explicit BookmarkPrefsService(Profile* profile); | ||
~BookmarkPrefsService() override; | ||
|
||
private: | ||
void OnPreferenceChanged(); | ||
|
||
Profile* profile_; | ||
PrefService* prefs_; | ||
PrefChangeRegistrar pref_change_registrar_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BookmarkPrefsService); | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_PREFS_SERVICE_H_ |
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,51 @@ | ||
/* 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 "brave/browser/ui/bookmark/bookmark_prefs_service_factory.h" | ||
|
||
#include "brave/browser/ui/bookmark/bookmark_prefs_service.h" | ||
#include "brave/common/pref_names.h" | ||
#include "chrome/browser/profiles/incognito_helpers.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/pref_registry/pref_registry_syncable.h" | ||
|
||
// static | ||
BookmarkPrefsService* BookmarkPrefsServiceFactory::GetForBrowserContext( | ||
content::BrowserContext* context) { | ||
return static_cast<BookmarkPrefsService*>( | ||
GetInstance()->GetServiceForBrowserContext(context, true)); | ||
} | ||
|
||
// static | ||
BookmarkPrefsServiceFactory* BookmarkPrefsServiceFactory::GetInstance() { | ||
return base::Singleton<BookmarkPrefsServiceFactory>::get(); | ||
} | ||
|
||
BookmarkPrefsServiceFactory::BookmarkPrefsServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"BookmarkPrefsService", | ||
BrowserContextDependencyManager::GetInstance()) {} | ||
|
||
BookmarkPrefsServiceFactory::~BookmarkPrefsServiceFactory() {} | ||
|
||
KeyedService* BookmarkPrefsServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
return new BookmarkPrefsService(Profile::FromBrowserContext(context)); | ||
} | ||
|
||
content::BrowserContext* BookmarkPrefsServiceFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return chrome::GetBrowserContextRedirectedInIncognito(context); | ||
} | ||
|
||
bool BookmarkPrefsServiceFactory::ServiceIsCreatedWithBrowserContext() const { | ||
return true; | ||
} | ||
|
||
void BookmarkPrefsServiceFactory::RegisterProfilePrefs( | ||
user_prefs::PrefRegistrySyncable* registry) { | ||
registry->RegisterBooleanPref(kAlwaysShowBookmarkBarOnNTP, false); | ||
} |
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,39 @@ | ||
/* 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/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_PREFS_SERVICE_FACTORY_H_ | ||
#define BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_PREFS_SERVICE_FACTORY_H_ | ||
|
||
#include "base/memory/singleton.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
|
||
class BookmarkPrefsService; | ||
|
||
class BookmarkPrefsServiceFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
static BookmarkPrefsService* GetForBrowserContext( | ||
content::BrowserContext* context); | ||
|
||
static BookmarkPrefsServiceFactory* GetInstance(); | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<BookmarkPrefsServiceFactory>; | ||
|
||
BookmarkPrefsServiceFactory(); | ||
~BookmarkPrefsServiceFactory() override; | ||
|
||
// BrowserContextKeyedServiceFactory: | ||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* profile) const override; | ||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
bool ServiceIsCreatedWithBrowserContext() const override; | ||
void RegisterProfilePrefs( | ||
user_prefs::PrefRegistrySyncable* registry) override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BookmarkPrefsServiceFactory); | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_PREFS_SERVICE_FACTORY_H_ |
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
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,48 @@ | ||
/* 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 "brave/browser/ui/bookmark/brave_bookmark_tab_helper.h" | ||
|
||
#include "brave/common/pref_names.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
BraveBookmarkTabHelper::BraveBookmarkTabHelper( | ||
content::WebContents* web_contents) | ||
: web_contents_(web_contents) { | ||
} | ||
|
||
BraveBookmarkTabHelper::~BraveBookmarkTabHelper() { | ||
} | ||
|
||
void BraveBookmarkTabHelper::AddObserver(BookmarkTabHelperObserver* observer) { | ||
BookmarkTabHelper::FromWebContents(web_contents_)->AddObserver(observer); | ||
} | ||
|
||
void BraveBookmarkTabHelper::RemoveObserver( | ||
BookmarkTabHelperObserver* observer) { | ||
BookmarkTabHelper::FromWebContents(web_contents_)->RemoveObserver(observer); | ||
} | ||
|
||
bool BraveBookmarkTabHelper::ShouldShowBookmarkBar() { | ||
BookmarkTabHelper* helper = | ||
BookmarkTabHelper::FromWebContents(web_contents_); | ||
if (!helper) | ||
return false; | ||
|
||
// Originally, bookmark is visible for NTP when bookmarks are non empty. | ||
// In that case, we want to hide bookmark bar on NTP if user chooses to hide. | ||
// When bookmark should be hidden, we do not change it. | ||
bool should_show = helper->ShouldShowBookmarkBar(); | ||
if (should_show) { | ||
Profile* profile = | ||
Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | ||
should_show = profile->GetPrefs()->GetBoolean(kAlwaysShowBookmarkBarOnNTP); | ||
} | ||
|
||
return should_show; | ||
} | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_IMPL(BraveBookmarkTabHelper) |
Oops, something went wrong.