Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Unified Diff: chrome/browser/ui/bookmarks/bookmark_tab_helper.cc

Issue 12217127: Alternate NTP: Show detached bookmark bar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android build Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/bookmarks/bookmark_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « no previous file | chrome/browser/ui/bookmarks/bookmark_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698