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

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 8135001: Fixed behavior of the bookmark bar visibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac build 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 "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 #include "content/browser/host_zoom_map.h" 137 #include "content/browser/host_zoom_map.h"
138 #include "content/browser/renderer_host/render_view_host.h" 138 #include "content/browser/renderer_host/render_view_host.h"
139 #include "content/browser/site_instance.h" 139 #include "content/browser/site_instance.h"
140 #include "content/browser/tab_contents/interstitial_page.h" 140 #include "content/browser/tab_contents/interstitial_page.h"
141 #include "content/browser/tab_contents/navigation_controller.h" 141 #include "content/browser/tab_contents/navigation_controller.h"
142 #include "content/browser/tab_contents/navigation_entry.h" 142 #include "content/browser/tab_contents/navigation_entry.h"
143 #include "content/browser/tab_contents/tab_contents_view.h" 143 #include "content/browser/tab_contents/tab_contents_view.h"
144 #include "content/browser/user_metrics.h" 144 #include "content/browser/user_metrics.h"
145 #include "content/common/content_restriction.h" 145 #include "content/common/content_restriction.h"
146 #include "content/common/content_switches.h" 146 #include "content/common/content_switches.h"
147 #include "content/common/notification_details.h"
147 #include "content/common/notification_service.h" 148 #include "content/common/notification_service.h"
148 #include "content/common/page_transition_types.h" 149 #include "content/common/page_transition_types.h"
149 #include "content/common/page_zoom.h" 150 #include "content/common/page_zoom.h"
150 #include "grit/chromium_strings.h" 151 #include "grit/chromium_strings.h"
151 #include "grit/generated_resources.h" 152 #include "grit/generated_resources.h"
152 #include "grit/locale_settings.h" 153 #include "grit/locale_settings.h"
153 #include "grit/theme_resources_standard.h" 154 #include "grit/theme_resources_standard.h"
154 #include "net/base/cookie_monster.h" 155 #include "net/base/cookie_monster.h"
155 #include "net/base/net_util.h" 156 #include "net/base/net_util.h"
156 #include "net/base/registry_controlled_domain.h" 157 #include "net/base/registry_controlled_domain.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 Source<Profile>(profile_)); 298 Source<Profile>(profile_));
298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 299 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
299 Source<Profile>(profile_)); 300 Source<Profile>(profile_));
300 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 301 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
301 NotificationService::AllSources()); 302 NotificationService::AllSources());
302 registrar_.Add( 303 registrar_.Add(
303 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 304 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
304 Source<ThemeService>(ThemeServiceFactory::GetForProfile(profile_))); 305 Source<ThemeService>(ThemeServiceFactory::GetForProfile(profile_)));
305 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, 306 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED,
306 NotificationService::AllSources()); 307 NotificationService::AllSources());
307 // We listen to all notification sources because the bookmark bar
308 // state needs to stay in sync between the incognito and normal profiles.
309 registrar_.Add(this,
310 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
311 NotificationService::AllBrowserContextsAndSources());
312 308
313 // Need to know when to alert the user of theme install delay. 309 // Need to know when to alert the user of theme install delay.
314 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_READY_FOR_INSTALL, 310 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_READY_FOR_INSTALL,
315 NotificationService::AllSources()); 311 NotificationService::AllSources());
316 312
317 PrefService* local_state = g_browser_process->local_state(); 313 PrefService* local_state = g_browser_process->local_state();
318 if (local_state) { 314 if (local_state) {
319 local_pref_registrar_.Init(local_state); 315 local_pref_registrar_.Init(local_state);
320 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); 316 local_pref_registrar_.Add(prefs::kPrintingEnabled, this);
321 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); 317 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this);
322 local_pref_registrar_.Add(prefs::kMetricsReportingEnabled, this); 318 local_pref_registrar_.Add(prefs::kMetricsReportingEnabled, this);
323 } 319 }
324 320
325 profile_pref_registrar_.Init(profile_->GetPrefs()); 321 profile_pref_registrar_.Init(profile_->GetPrefs());
326 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); 322 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this);
327 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); 323 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this);
328 profile_pref_registrar_.Add(prefs::kEnableBookmarkBar, this); 324 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this);
329 profile_pref_registrar_.Add(prefs::kHomePage, this); 325 profile_pref_registrar_.Add(prefs::kHomePage, this);
330 profile_pref_registrar_.Add(prefs::kInstantEnabled, this); 326 profile_pref_registrar_.Add(prefs::kInstantEnabled, this);
331 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); 327 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this);
332 profile_pref_registrar_.Add(prefs::kSearchSuggestEnabled, this); 328 profile_pref_registrar_.Add(prefs::kSearchSuggestEnabled, this);
333 329
334 InitCommandState(); 330 InitCommandState();
335 BrowserList::AddBrowser(this); 331 BrowserList::AddBrowser(this);
336 332
337 // NOTE: These prefs all need to be explicitly destroyed in the destructor 333 // NOTE: These prefs all need to be explicitly destroyed in the destructor
338 // or you'll get a nasty surprise when you run the incognito tests. 334 // or you'll get a nasty surprise when you run the incognito tests.
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 PrefService::UNSYNCABLE_PREF); 2275 PrefService::UNSYNCABLE_PREF);
2280 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, 2276 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar,
2281 true, 2277 true,
2282 PrefService::UNSYNCABLE_PREF); 2278 PrefService::UNSYNCABLE_PREF);
2283 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, 2279 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs,
2284 false, 2280 false,
2285 PrefService::UNSYNCABLE_PREF); 2281 PrefService::UNSYNCABLE_PREF);
2286 prefs->RegisterBooleanPref(prefs::kEnableTranslate, 2282 prefs->RegisterBooleanPref(prefs::kEnableTranslate,
2287 true, 2283 true,
2288 PrefService::SYNCABLE_PREF); 2284 PrefService::SYNCABLE_PREF);
2289 prefs->RegisterBooleanPref(prefs::kEnableBookmarkBar,
2290 true,
2291 PrefService::UNSYNCABLE_PREF);
2292 prefs->RegisterStringPref(prefs::kCloudPrintEmail, 2285 prefs->RegisterStringPref(prefs::kCloudPrintEmail,
2293 std::string(), 2286 std::string(),
2294 PrefService::UNSYNCABLE_PREF); 2287 PrefService::UNSYNCABLE_PREF);
2295 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, 2288 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled,
2296 true, 2289 true,
2297 PrefService::UNSYNCABLE_PREF); 2290 PrefService::UNSYNCABLE_PREF);
2298 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, 2291 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled,
2299 false, 2292 false,
2300 PrefService::UNSYNCABLE_PREF); 2293 PrefService::UNSYNCABLE_PREF);
2301 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, 2294 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation,
(...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after
4096 available != IncognitoModePrefs::FORCED); 4089 available != IncognitoModePrefs::FORCED);
4097 command_updater_.UpdateCommandEnabled( 4090 command_updater_.UpdateCommandEnabled(
4098 IDC_NEW_INCOGNITO_WINDOW, 4091 IDC_NEW_INCOGNITO_WINDOW,
4099 available != IncognitoModePrefs::DISABLED); 4092 available != IncognitoModePrefs::DISABLED);
4100 } else if (pref_name == prefs::kDevToolsDisabled) { 4093 } else if (pref_name == prefs::kDevToolsDisabled) {
4101 UpdateCommandsForDevTools(); 4094 UpdateCommandsForDevTools();
4102 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 4095 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
4103 g_browser_process->devtools_manager()->CloseAllClientHosts(); 4096 g_browser_process->devtools_manager()->CloseAllClientHosts();
4104 } else if (pref_name == prefs::kEditBookmarksEnabled) { 4097 } else if (pref_name == prefs::kEditBookmarksEnabled) {
4105 UpdateCommandsForBookmarkEditing(); 4098 UpdateCommandsForBookmarkEditing();
4106 } else if (pref_name == prefs::kEnableBookmarkBar) { 4099 } else if (pref_name == prefs::kShowBookmarkBar) {
4107 UpdateCommandsForBookmarkBar(); 4100 UpdateCommandsForBookmarkBar();
4101 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE);
4108 } else if (pref_name == prefs::kHomePage) { 4102 } else if (pref_name == prefs::kHomePage) {
4109 PrefService* pref_service = Source<PrefService>(source).ptr(); 4103 PrefService* pref_service = Source<PrefService>(source).ptr();
4110 MarkHomePageAsChanged(pref_service); 4104 MarkHomePageAsChanged(pref_service);
4111 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { 4105 } else if (pref_name == prefs::kAllowFileSelectionDialogs) {
4112 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); 4106 UpdateSaveAsState(GetContentRestrictionsForSelectedTab());
4113 UpdateOpenFileState(); 4107 UpdateOpenFileState();
4114 } else { 4108 } else {
4115 NOTREACHED(); 4109 NOTREACHED();
4116 } 4110 }
4117 break; 4111 break;
4118 } 4112 }
4119 4113
4120 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { 4114 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: {
4121 TabContents* tab_contents = Source<TabContents>(source).ptr(); 4115 TabContents* tab_contents = Source<TabContents>(source).ptr();
4122 if (tab_contents == GetSelectedTabContents()) { 4116 if (tab_contents == GetSelectedTabContents()) {
4123 LocationBar* location_bar = window()->GetLocationBar(); 4117 LocationBar* location_bar = window()->GetLocationBar();
4124 if (location_bar) 4118 if (location_bar)
4125 location_bar->UpdateContentSettingsIcons(); 4119 location_bar->UpdateContentSettingsIcons();
4126 } 4120 }
4127 break; 4121 break;
4128 } 4122 }
4129 4123
4130 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: 4124 case content::NOTIFICATION_INTERSTITIAL_ATTACHED:
4131 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 4125 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
4132 break; 4126 break;
4133 4127
4134 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED:
4135 if (profile_->IsSameProfile(Source<Profile>(source).ptr()))
4136 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE);
4137 break;
4138
4139 default: 4128 default:
4140 NOTREACHED() << "Got a notification we didn't register for."; 4129 NOTREACHED() << "Got a notification we didn't register for.";
4141 } 4130 }
4142 } 4131 }
4143 4132
4144 /////////////////////////////////////////////////////////////////////////////// 4133 ///////////////////////////////////////////////////////////////////////////////
4145 // Browser, ProfileSyncServiceObserver implementation: 4134 // Browser, ProfileSyncServiceObserver implementation:
4146 4135
4147 void Browser::OnStateChanged() { 4136 void Browser::OnStateChanged() {
4148 DCHECK(profile_->GetProfileSyncService()); 4137 DCHECK(profile_->GetProfileSyncService());
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
4564 4553
4565 void Browser::UpdateCommandsForBookmarkBar() { 4554 void Browser::UpdateCommandsForBookmarkBar() {
4566 #if !defined(OS_MACOSX) 4555 #if !defined(OS_MACOSX)
4567 const bool show_main_ui = is_type_tabbed() && 4556 const bool show_main_ui = is_type_tabbed() &&
4568 (!window_ || !window_->IsFullscreen()); 4557 (!window_ || !window_->IsFullscreen());
4569 #else 4558 #else
4570 const bool show_main_ui = is_type_tabbed(); 4559 const bool show_main_ui = is_type_tabbed();
4571 #endif 4560 #endif
4572 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, 4561 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR,
4573 browser_defaults::bookmarks_enabled && 4562 browser_defaults::bookmarks_enabled &&
4574 !profile_->GetPrefs()->IsManagedPreference(prefs::kEnableBookmarkBar) && 4563 !profile_->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) &&
4575 show_main_ui); 4564 show_main_ui);
4576 } 4565 }
4577 4566
4578 void Browser::MarkHomePageAsChanged(PrefService* pref_service) { 4567 void Browser::MarkHomePageAsChanged(PrefService* pref_service) {
4579 pref_service->SetBoolean(prefs::kHomePageChanged, true); 4568 pref_service->SetBoolean(prefs::kHomePageChanged, true);
4580 pref_service->ScheduleSavePersistentPrefs(); 4569 pref_service->ScheduleSavePersistentPrefs();
4581 } 4570 }
4582 4571
4583 void Browser::UpdateSaveAsState(int content_restrictions) { 4572 void Browser::UpdateSaveAsState(int content_restrictions) {
4584 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); 4573 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE);
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
5225 // See comment in UpdateCommandsForTabState about why we call url(). 5214 // See comment in UpdateCommandsForTabState about why we call url().
5226 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) 5215 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL()))
5227 content_restrictions |= CONTENT_RESTRICTION_SAVE; 5216 content_restrictions |= CONTENT_RESTRICTION_SAVE;
5228 } 5217 }
5229 return content_restrictions; 5218 return content_restrictions;
5230 } 5219 }
5231 5220
5232 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { 5221 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
5233 BookmarkBar::State state; 5222 BookmarkBar::State state;
5234 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page. 5223 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page.
5235 if ((profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && 5224 if (browser_defaults::bookmarks_enabled &&
5236 profile_->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar)) && 5225 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) &&
5237 (!window_ || !window_->IsFullscreen())) { 5226 (!window_ || !window_->IsFullscreen())) {
5238 state = BookmarkBar::SHOW; 5227 state = BookmarkBar::SHOW;
5239 } else { 5228 } else {
5240 TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); 5229 TabContentsWrapper* tab = GetSelectedTabContentsWrapper();
5241 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) 5230 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar())
5242 state = BookmarkBar::DETACHED; 5231 state = BookmarkBar::DETACHED;
5243 else 5232 else
5244 state = BookmarkBar::HIDDEN; 5233 state = BookmarkBar::HIDDEN;
5245 } 5234 }
5246 if (state == bookmark_bar_state_) 5235 if (state == bookmark_bar_state_)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
5303 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); 5292 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type);
5304 } else if (is_type_tabbed()) { 5293 } else if (is_type_tabbed()) {
5305 GlobalErrorService* service = 5294 GlobalErrorService* service =
5306 GlobalErrorServiceFactory::GetForProfile(profile()); 5295 GlobalErrorServiceFactory::GetForProfile(profile());
5307 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); 5296 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
5308 if (error) { 5297 if (error) {
5309 error->ShowBubbleView(this); 5298 error->ShowBubbleView(this);
5310 } 5299 }
5311 } 5300 }
5312 } 5301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698