| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 1927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2266 PrefService::UNSYNCABLE_PREF); | 2262 PrefService::UNSYNCABLE_PREF); |
| 2267 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, | 2263 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, |
| 2268 true, | 2264 true, |
| 2269 PrefService::UNSYNCABLE_PREF); | 2265 PrefService::UNSYNCABLE_PREF); |
| 2270 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, | 2266 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, |
| 2271 true, | 2267 true, |
| 2272 PrefService::UNSYNCABLE_PREF); | 2268 PrefService::UNSYNCABLE_PREF); |
| 2273 prefs->RegisterBooleanPref(prefs::kEnableTranslate, | 2269 prefs->RegisterBooleanPref(prefs::kEnableTranslate, |
| 2274 true, | 2270 true, |
| 2275 PrefService::SYNCABLE_PREF); | 2271 PrefService::SYNCABLE_PREF); |
| 2276 prefs->RegisterBooleanPref(prefs::kEnableBookmarkBar, | |
| 2277 true, | |
| 2278 PrefService::UNSYNCABLE_PREF); | |
| 2279 prefs->RegisterStringPref(prefs::kCloudPrintEmail, | 2272 prefs->RegisterStringPref(prefs::kCloudPrintEmail, |
| 2280 std::string(), | 2273 std::string(), |
| 2281 PrefService::UNSYNCABLE_PREF); | 2274 PrefService::UNSYNCABLE_PREF); |
| 2282 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, | 2275 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, |
| 2283 true, | 2276 true, |
| 2284 PrefService::UNSYNCABLE_PREF); | 2277 PrefService::UNSYNCABLE_PREF); |
| 2285 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, | 2278 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, |
| 2286 false, | 2279 false, |
| 2287 PrefService::UNSYNCABLE_PREF); | 2280 PrefService::UNSYNCABLE_PREF); |
| 2288 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, | 2281 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, |
| (...skipping 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4080 available != IncognitoModePrefs::FORCED); | 4073 available != IncognitoModePrefs::FORCED); |
| 4081 command_updater_.UpdateCommandEnabled( | 4074 command_updater_.UpdateCommandEnabled( |
| 4082 IDC_NEW_INCOGNITO_WINDOW, | 4075 IDC_NEW_INCOGNITO_WINDOW, |
| 4083 available != IncognitoModePrefs::DISABLED); | 4076 available != IncognitoModePrefs::DISABLED); |
| 4084 } else if (pref_name == prefs::kDevToolsDisabled) { | 4077 } else if (pref_name == prefs::kDevToolsDisabled) { |
| 4085 UpdateCommandsForDevTools(); | 4078 UpdateCommandsForDevTools(); |
| 4086 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 4079 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 4087 g_browser_process->devtools_manager()->CloseAllClientHosts(); | 4080 g_browser_process->devtools_manager()->CloseAllClientHosts(); |
| 4088 } else if (pref_name == prefs::kEditBookmarksEnabled) { | 4081 } else if (pref_name == prefs::kEditBookmarksEnabled) { |
| 4089 UpdateCommandsForBookmarkEditing(); | 4082 UpdateCommandsForBookmarkEditing(); |
| 4090 } else if (pref_name == prefs::kEnableBookmarkBar) { | 4083 } else if (pref_name == prefs::kShowBookmarkBar) { |
| 4091 UpdateCommandsForBookmarkBar(); | 4084 UpdateCommandsForBookmarkBar(); |
| 4085 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); |
| 4092 } else if (pref_name == prefs::kHomePage) { | 4086 } else if (pref_name == prefs::kHomePage) { |
| 4093 PrefService* pref_service = Source<PrefService>(source).ptr(); | 4087 PrefService* pref_service = Source<PrefService>(source).ptr(); |
| 4094 MarkHomePageAsChanged(pref_service); | 4088 MarkHomePageAsChanged(pref_service); |
| 4095 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { | 4089 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { |
| 4096 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); | 4090 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); |
| 4097 UpdateOpenFileState(); | 4091 UpdateOpenFileState(); |
| 4098 } else { | 4092 } else { |
| 4099 NOTREACHED(); | 4093 NOTREACHED(); |
| 4100 } | 4094 } |
| 4101 break; | 4095 break; |
| 4102 } | 4096 } |
| 4103 | 4097 |
| 4104 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { | 4098 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { |
| 4105 TabContents* tab_contents = Source<TabContents>(source).ptr(); | 4099 TabContents* tab_contents = Source<TabContents>(source).ptr(); |
| 4106 if (tab_contents == GetSelectedTabContents()) { | 4100 if (tab_contents == GetSelectedTabContents()) { |
| 4107 LocationBar* location_bar = window()->GetLocationBar(); | 4101 LocationBar* location_bar = window()->GetLocationBar(); |
| 4108 if (location_bar) | 4102 if (location_bar) |
| 4109 location_bar->UpdateContentSettingsIcons(); | 4103 location_bar->UpdateContentSettingsIcons(); |
| 4110 } | 4104 } |
| 4111 break; | 4105 break; |
| 4112 } | 4106 } |
| 4113 | 4107 |
| 4114 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: | 4108 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
| 4115 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 4109 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 4116 break; | 4110 break; |
| 4117 | 4111 |
| 4118 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: | |
| 4119 if (profile_->IsSameProfile(Source<Profile>(source).ptr())) | |
| 4120 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); | |
| 4121 break; | |
| 4122 | |
| 4123 default: | 4112 default: |
| 4124 NOTREACHED() << "Got a notification we didn't register for."; | 4113 NOTREACHED() << "Got a notification we didn't register for."; |
| 4125 } | 4114 } |
| 4126 } | 4115 } |
| 4127 | 4116 |
| 4128 /////////////////////////////////////////////////////////////////////////////// | 4117 /////////////////////////////////////////////////////////////////////////////// |
| 4129 // Browser, ProfileSyncServiceObserver implementation: | 4118 // Browser, ProfileSyncServiceObserver implementation: |
| 4130 | 4119 |
| 4131 void Browser::OnStateChanged() { | 4120 void Browser::OnStateChanged() { |
| 4132 DCHECK(profile_->GetProfileSyncService()); | 4121 DCHECK(profile_->GetProfileSyncService()); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4546 | 4535 |
| 4547 void Browser::UpdateCommandsForBookmarkBar() { | 4536 void Browser::UpdateCommandsForBookmarkBar() { |
| 4548 #if !defined(OS_MACOSX) | 4537 #if !defined(OS_MACOSX) |
| 4549 const bool show_main_ui = is_type_tabbed() && | 4538 const bool show_main_ui = is_type_tabbed() && |
| 4550 (!window_ || !window_->IsFullscreen()); | 4539 (!window_ || !window_->IsFullscreen()); |
| 4551 #else | 4540 #else |
| 4552 const bool show_main_ui = is_type_tabbed(); | 4541 const bool show_main_ui = is_type_tabbed(); |
| 4553 #endif | 4542 #endif |
| 4554 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, | 4543 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
| 4555 browser_defaults::bookmarks_enabled && | 4544 browser_defaults::bookmarks_enabled && |
| 4556 !profile_->GetPrefs()->IsManagedPreference(prefs::kEnableBookmarkBar) && | 4545 !profile_->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && |
| 4557 show_main_ui); | 4546 show_main_ui); |
| 4558 } | 4547 } |
| 4559 | 4548 |
| 4560 void Browser::MarkHomePageAsChanged(PrefService* pref_service) { | 4549 void Browser::MarkHomePageAsChanged(PrefService* pref_service) { |
| 4561 pref_service->SetBoolean(prefs::kHomePageChanged, true); | 4550 pref_service->SetBoolean(prefs::kHomePageChanged, true); |
| 4562 pref_service->ScheduleSavePersistentPrefs(); | 4551 pref_service->ScheduleSavePersistentPrefs(); |
| 4563 } | 4552 } |
| 4564 | 4553 |
| 4565 void Browser::UpdateSaveAsState(int content_restrictions) { | 4554 void Browser::UpdateSaveAsState(int content_restrictions) { |
| 4566 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); | 4555 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5207 // See comment in UpdateCommandsForTabState about why we call url(). | 5196 // See comment in UpdateCommandsForTabState about why we call url(). |
| 5208 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) | 5197 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) |
| 5209 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 5198 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
| 5210 } | 5199 } |
| 5211 return content_restrictions; | 5200 return content_restrictions; |
| 5212 } | 5201 } |
| 5213 | 5202 |
| 5214 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { | 5203 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { |
| 5215 BookmarkBar::State state; | 5204 BookmarkBar::State state; |
| 5216 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page. | 5205 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page. |
| 5217 if ((profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && | 5206 if (browser_defaults::bookmarks_enabled && |
| 5218 profile_->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar)) && | 5207 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && |
| 5219 (!window_ || !window_->IsFullscreen())) { | 5208 (!window_ || !window_->IsFullscreen())) { |
| 5220 state = BookmarkBar::SHOW; | 5209 state = BookmarkBar::SHOW; |
| 5221 } else { | 5210 } else { |
| 5222 TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); | 5211 TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); |
| 5223 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) | 5212 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) |
| 5224 state = BookmarkBar::DETACHED; | 5213 state = BookmarkBar::DETACHED; |
| 5225 else | 5214 else |
| 5226 state = BookmarkBar::HIDDEN; | 5215 state = BookmarkBar::HIDDEN; |
| 5227 } | 5216 } |
| 5228 if (state == bookmark_bar_state_) | 5217 if (state == bookmark_bar_state_) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5285 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5274 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
| 5286 } else if (is_type_tabbed()) { | 5275 } else if (is_type_tabbed()) { |
| 5287 GlobalErrorService* service = | 5276 GlobalErrorService* service = |
| 5288 GlobalErrorServiceFactory::GetForProfile(profile()); | 5277 GlobalErrorServiceFactory::GetForProfile(profile()); |
| 5289 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5278 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 5290 if (error) { | 5279 if (error) { |
| 5291 error->ShowBubbleView(this); | 5280 error->ShowBubbleView(this); |
| 5292 } | 5281 } |
| 5293 } | 5282 } |
| 5294 } | 5283 } |
| OLD | NEW |