| Index: chrome/browser/ui/bookmarks/bookmark_tab_helper.cc
|
| diff --git a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc
|
| index 78ab9a120d4de7289fa2aea249fdbb1eb4cc5cb3..c6c6d5646fd5385c9318f6d95b95c55362dd96e0 100644
|
| --- a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc
|
| +++ b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc
|
| @@ -6,24 +6,18 @@
|
|
|
| #include "chrome/browser/bookmarks/bookmark_model.h"
|
| #include "chrome/browser/bookmarks/bookmark_model_factory.h"
|
| +#include "chrome/browser/defaults.h"
|
| +#include "chrome/browser/prefs/pref_service_syncable.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h"
|
| #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/common/url_constants.h"
|
| +#include "content/public/browser/navigation_entry.h"
|
| #include "content/public/browser/web_contents.h"
|
|
|
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(BookmarkTabHelper);
|
|
|
| -namespace {
|
| -
|
| -bool CanShowBookmarkBar(content::WebUI* ui) {
|
| - if (!ui)
|
| - return false;
|
| - NewTabUI* new_tab = NewTabUI::FromWebUIController(ui->GetController());
|
| - return new_tab && new_tab->CanShowBookmarkBar();
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| BookmarkTabHelper::~BookmarkTabHelper() {
|
| if (bookmark_model_)
|
| bookmark_model_->RemoveObserver(this);
|
| @@ -33,19 +27,28 @@ bool BookmarkTabHelper::ShouldShowBookmarkBar() const {
|
| if (web_contents()->ShowingInterstitialPage())
|
| return false;
|
|
|
| - // See WebContents::GetWebUIForCurrentState() comment for more info. This case
|
| - // is very similar, but for non-first loads, we want to use the committed
|
| - // entry. This is so the bookmarks bar disappears at the same time the page
|
| - // does.
|
| - if (web_contents()->GetController().GetLastCommittedEntry()) {
|
| - // Not the first load, always use the committed Web UI.
|
| - return CanShowBookmarkBar(web_contents()->GetCommittedWebUI());
|
| + // For non-first loads, we want to use the committed entry. This is 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();
|
| + if (!entry)
|
| + return false;
|
| +
|
| + GURL url = entry->GetVirtualURL();
|
| + if (url != GURL(chrome::kChromeUINewTabURL) ||
|
| + url.SchemeIs(chrome::kViewSourceScheme)) {
|
| + return false;
|
| }
|
|
|
| - // When it's the first load, we know either the pending one or the committed
|
| - // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
|
| - // of them will be valid, so we can just check both.
|
| - return CanShowBookmarkBar(web_contents()->GetWebUI());
|
| + Profile* profile =
|
| + Profile::FromBrowserContext(web_contents()->GetBrowserContext());
|
| + PrefService* prefs = profile->GetPrefs();
|
| + bool disabled_by_policy =
|
| + prefs->IsManagedPreference(prefs::kShowBookmarkBar) &&
|
| + !prefs->GetBoolean(prefs::kShowBookmarkBar);
|
| + return browser_defaults::bookmarks_enabled && !disabled_by_policy;
|
| }
|
|
|
| BookmarkTabHelper::BookmarkTabHelper(content::WebContents* web_contents)
|
|
|