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

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_ui.cc

Issue 8135001: Fixed behavior of the bookmark bar visibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DCHECK_EQ instead of DCHECK Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
8 8
9 #include <set>
10
11 #include "base/bind.h" 9 #include "base/bind.h"
12 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 11 #include "base/command_line.h"
14 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
15 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
16 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
17 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
18 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
19 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/defaults.h" 18 #include "chrome/browser/defaults.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } // namespace 65 } // namespace
68 66
69 /////////////////////////////////////////////////////////////////////////////// 67 ///////////////////////////////////////////////////////////////////////////////
70 // NewTabUI 68 // NewTabUI
71 69
72 NewTabUI::NewTabUI(TabContents* contents) 70 NewTabUI::NewTabUI(TabContents* contents)
73 : ChromeWebUI(contents) { 71 : ChromeWebUI(contents) {
74 // Override some options on the Web UI. 72 // Override some options on the Web UI.
75 hide_favicon_ = true; 73 hide_favicon_ = true;
76 74
77 if (!NTP4BookmarkFeaturesEnabled() &&
78 GetProfile()->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar) &&
79 browser_defaults::bookmarks_enabled) {
80 set_force_bookmark_bar_visible(true);
81 }
82
83 focus_location_bar_by_default_ = true; 75 focus_location_bar_by_default_ = true;
84 should_hide_url_ = true; 76 should_hide_url_ = true;
85 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); 77 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
86 78
87 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more 79 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more
88 // highly. Note this means we're including clicks on not only most visited 80 // highly. Note this means we're including clicks on not only most visited
89 // thumbnails, but also clicks on recently bookmarked. 81 // thumbnails, but also clicks on recently bookmarked.
90 link_transition_type_ = PageTransition::AUTO_BOOKMARK; 82 link_transition_type_ = PageTransition::AUTO_BOOKMARK;
91 83
92 if (!GetProfile()->IsOffTheRecord()) { 84 if (!GetProfile()->IsOffTheRecord()) {
(...skipping 29 matching lines...) Expand all
122 NewTabHTMLSource* html_source = 114 NewTabHTMLSource* html_source =
123 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); 115 new NewTabHTMLSource(GetProfile()->GetOriginalProfile());
124 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 116 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
125 profile->GetChromeURLDataManager()->AddDataSource(html_source); 117 profile->GetChromeURLDataManager()->AddDataSource(html_source);
126 118
127 // Listen for theme installation. 119 // Listen for theme installation.
128 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 120 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
129 Source<ThemeService>( 121 Source<ThemeService>(
130 ThemeServiceFactory::GetForProfile(GetProfile()))); 122 ThemeServiceFactory::GetForProfile(GetProfile())));
131 // Listen for bookmark bar visibility changes. 123 // Listen for bookmark bar visibility changes.
132 registrar_.Add(this, 124 pref_change_registrar_.Init(GetProfile()->GetPrefs());
133 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 125 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
134 NotificationService::AllSources());
135 } 126 }
136 127
137 NewTabUI::~NewTabUI() { 128 NewTabUI::~NewTabUI() {
138 } 129 }
139 130
140 // The timer callback. If enough time has elapsed since the last paint 131 // The timer callback. If enough time has elapsed since the last paint
141 // message, we say we're done painting; otherwise, we keep waiting. 132 // message, we say we're done painting; otherwise, we keep waiting.
142 void NewTabUI::PaintTimeout() { 133 void NewTabUI::PaintTimeout() {
143 // The amount of time there must be no painting for us to consider painting 134 // The amount of time there must be no painting for us to consider painting
144 // finished. Observed times are in the ~1200ms range on Windows. 135 // finished. Observed times are in the ~1200ms range on Windows.
(...skipping 26 matching lines...) Expand all
171 162
172 } 163 }
173 void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) { 164 void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) {
174 StartTimingPaint(render_view_host); 165 StartTimingPaint(render_view_host);
175 } 166 }
176 167
177 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { 168 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) {
178 StartTimingPaint(render_view_host); 169 StartTimingPaint(render_view_host);
179 } 170 }
180 171
172 bool NewTabUI::CanShowBookmarkBar() const {
173 PrefService* prefs = GetProfile()->GetPrefs();
174 bool disabled_by_policy =
175 prefs->IsManagedPreference(prefs::kShowBookmarkBar) &&
176 !prefs->GetBoolean(prefs::kShowBookmarkBar);
177 return
178 browser_defaults::bookmarks_enabled &&
179 !disabled_by_policy &&
180 !NTP4BookmarkFeaturesEnabled();
181 }
182
181 void NewTabUI::Observe(int type, 183 void NewTabUI::Observe(int type,
182 const NotificationSource& source, 184 const NotificationSource& source,
183 const NotificationDetails& details) { 185 const NotificationDetails& details) {
184 switch (type) { 186 switch (type) {
185 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { 187 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
186 InitializeCSSCaches(); 188 InitializeCSSCaches();
187 ListValue args; 189 ListValue args;
188 args.Append(Value::CreateStringValue( 190 args.Append(Value::CreateStringValue(
189 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( 191 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage(
190 IDR_THEME_NTP_ATTRIBUTION) ? 192 IDR_THEME_NTP_ATTRIBUTION) ?
191 "true" : "false")); 193 "true" : "false"));
192 CallJavascriptFunction("themeChanged", args); 194 CallJavascriptFunction("themeChanged", args);
193 break; 195 break;
194 } 196 }
195 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: { 197 case chrome::NOTIFICATION_PREF_CHANGED: {
196 if (GetProfile()->GetPrefs()->IsManagedPreference( 198 const std::string& pref_name = *Details<std::string>(details).ptr();
197 prefs::kEnableBookmarkBar)) { 199 if (pref_name == prefs::kShowBookmarkBar) {
198 break; 200 if (!NTP4Enabled() && CanShowBookmarkBar()) {
199 } 201 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar))
200 if (!NTP4Enabled()) { 202 CallJavascriptFunction("bookmarkBarAttached");
201 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) 203 else
202 CallJavascriptFunction("bookmarkBarAttached"); 204 CallJavascriptFunction("bookmarkBarDetached");
203 else 205 }
204 CallJavascriptFunction("bookmarkBarDetached"); 206 } else {
207 NOTREACHED();
205 } 208 }
206 break; 209 break;
207 } 210 }
208 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { 211 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: {
209 last_paint_ = base::TimeTicks::Now(); 212 last_paint_ = base::TimeTicks::Now();
210 break; 213 break;
211 } 214 }
212 default: 215 default:
213 CHECK(false) << "Unexpected notification: " << type; 216 CHECK(false) << "Unexpected notification: " << type;
214 } 217 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 SendResponse(request_id, html_bytes); 337 SendResponse(request_id, html_bytes);
335 } 338 }
336 339
337 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { 340 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const {
338 return "text/html"; 341 return "text/html";
339 } 342 }
340 343
341 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { 344 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const {
342 return false; 345 return false;
343 } 346 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_ui.h ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698