Chromium Code Reviews| Index: chrome/browser/ui/browser.cc |
| diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc |
| index 1d6b6a826914d0fdabeef6621fb501bdce786018..f35d627c5c959684c06330187d8f7f3649de5da2 100644 |
| --- a/chrome/browser/ui/browser.cc |
| +++ b/chrome/browser/ui/browser.cc |
| @@ -104,6 +104,7 @@ |
| #include "chrome/browser/ui/find_bar/find_bar.h" |
| #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| +#include "chrome/browser/ui/fullscreen_controller.h" |
| #include "chrome/browser/ui/global_error.h" |
| #include "chrome/browser/ui/global_error_service.h" |
| #include "chrome/browser/ui/global_error_service_factory.h" |
| @@ -146,6 +147,7 @@ |
| #include "content/browser/site_instance.h" |
| #include "content/browser/tab_contents/interstitial_page.h" |
| #include "content/browser/tab_contents/navigation_controller.h" |
| +#include "content/browser/tab_contents/navigation_details.h" |
|
yzshen1
2011/11/04 01:56:32
Why this is needed?
koz (OOO until 15th September)
2011/11/06 23:30:20
Hm, turns out it's not. I'm not sure how that got
|
| #include "content/browser/tab_contents/navigation_entry.h" |
| #include "content/browser/tab_contents/tab_contents_view.h" |
| #include "content/browser/user_metrics.h" |
| @@ -153,7 +155,6 @@ |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/common/content_restriction.h" |
| #include "content/public/common/content_switches.h" |
| -#include "grit/chromium_strings.h" |
| #include "grit/generated_resources.h" |
| #include "grit/locale_settings.h" |
| #include "grit/theme_resources_standard.h" |
| @@ -288,10 +289,6 @@ Browser::Browser(Type type, Profile* profile) |
| synced_window_delegate_( |
| new BrowserSyncedWindowDelegate(this))), |
| bookmark_bar_state_(BookmarkBar::HIDDEN), |
| - fullscreened_tab_(NULL), |
| - tab_caused_fullscreen_(false), |
| - tab_fullscreen_accepted_(false), |
| - mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), |
| window_has_shown_(false) { |
| registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
| content::NotificationService::AllSources()); |
| @@ -406,6 +403,10 @@ Browser::~Browser() { |
| TabRestoreServiceDestroyed(tab_restore_service_); |
| } |
| +bool Browser::IsFullscreenForTab() const { |
|
yzshen1
2011/11/04 01:56:32
Please try to keep the method definition the same
koz (OOO until 15th September)
2011/11/06 23:30:20
Done.
|
| + return fullscreen_controller_->IsFullscreenForTab(); |
| +} |
| + |
| // static |
| Browser* Browser::Create(Profile* profile) { |
| Browser* browser = new Browser(TYPE_TABBED, profile); |
| @@ -517,6 +518,7 @@ void Browser::InitBrowserWindow() { |
| // Permanently dismiss ntp4 bubble for new users. |
| if (FirstRun::IsChromeFirstRun()) |
| NewTabPageHandler::DismissIntroMessage(local_state); |
| + fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
|
Peter Kasting
2011/11/03 18:24:56
Nit: Seems like this might be better just below th
koz (OOO until 15th September)
2011/11/06 23:30:20
Done.
|
| } |
| /////////////////////////////////////////////////////////////////////////////// |
| @@ -1360,26 +1362,7 @@ void Browser::ShowSingletonTabOverwritingNTP( |
| } |
| void Browser::WindowFullscreenStateChanged() { |
| - UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| - UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
| - MessageLoop::current()->PostTask( |
| - FROM_HERE, method_factory_.NewRunnableMethod( |
| - &Browser::NotifyFullscreenChange)); |
| - bool notify_tab_of_exit; |
| -#if defined(OS_MACOSX) |
| - notify_tab_of_exit = !window_->InPresentationMode(); |
| -#else |
| - notify_tab_of_exit = !window_->IsFullscreen(); |
| -#endif |
| - if (notify_tab_of_exit) |
| - NotifyTabOfFullscreenExitIfNecessary(); |
| -} |
| - |
| -void Browser::NotifyFullscreenChange() { |
| - content::NotificationService::current()->Notify( |
| - chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| - content::Source<Browser>(this), |
| - content::NotificationService::NoDetails()); |
| + fullscreen_controller_->WindowFullscreenStateChanged(); |
| } |
| /////////////////////////////////////////////////////////////////////////////// |
| @@ -1720,76 +1703,12 @@ void Browser::ConvertPopupToTabbedBrowser() { |
| // TODO(koz): Change |for_tab| to an enum. |
| void Browser::ToggleFullscreenMode(bool for_tab) { |
| - bool entering_fullscreen = !window_->IsFullscreen(); |
| - |
| -#if !defined(OS_MACOSX) |
| - // In kiosk mode, we always want to be fullscreen. When the browser first |
| - // starts we're not yet fullscreen, so let the initial toggle go through. |
| - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
| - window_->IsFullscreen()) |
| - return; |
| -#endif |
| - |
| - GURL url; |
| - if (for_tab) { |
| - url = GetSelectedTabContents()->GetURL(); |
| - tab_fullscreen_accepted_ = entering_fullscreen && |
| - GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| - } else { |
| - UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); |
| - } |
| - if (entering_fullscreen) |
| - window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); |
| - else |
| - window_->ExitFullscreen(); |
| - |
| - // Once the window has become fullscreen it'll call back to |
| - // WindowFullscreenStateChanged(). We don't do this immediately as |
| - // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| - // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| - |
| - // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
| - // the necessary state of the frame. |
| -#if defined(OS_MACOSX) |
| - WindowFullscreenStateChanged(); |
| -#endif |
| -} |
| - |
| -void Browser::NotifyTabOfFullscreenExitIfNecessary() { |
| - if (fullscreened_tab_) |
| - fullscreened_tab_->ExitFullscreenMode(); |
| - else |
| - DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); |
| - |
| - fullscreened_tab_ = NULL; |
| - tab_caused_fullscreen_ = false; |
| - tab_fullscreen_accepted_ = false; |
| - mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| - |
| - UpdateFullscreenExitBubbleContent(); |
| + fullscreen_controller_->ToggleFullscreenMode(for_tab); |
| } |
| #if defined(OS_MACOSX) |
| void Browser::TogglePresentationMode(bool for_tab) { |
| - bool entering_fullscreen = !window_->InPresentationMode(); |
| - GURL url; |
| - bool ask_permission = false; |
| - if (for_tab) { |
| - url = GetSelectedTabContents()->GetURL(); |
| - ask_permission = GetFullscreenSetting(url) != CONTENT_SETTING_ALLOW; |
| - } |
| - if (entering_fullscreen) { |
| - FullscreenExitBubbleType type = |
| - FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; |
| - if (for_tab) { |
| - type = ask_permission ? FEB_TYPE_FULLSCREEN_BUTTONS : |
| - FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
| - } |
| - window_->EnterPresentationMode(url, type); |
| - } else { |
| - window_->ExitPresentationMode(); |
| - } |
| - WindowFullscreenStateChanged(); |
| + fullscreen_controller_->TogglePresentationMode(for_tab); |
|
yzshen1
2011/11/04 01:56:32
FYI, jeremy is changing the content of this method
koz (OOO until 15th September)
2011/11/06 23:30:20
Yep, I will. Thanks for the tip.
|
| } |
| #endif |
| @@ -3235,15 +3154,7 @@ void Browser::TabInsertedAt(TabContentsWrapper* contents, |
| void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
| TabContentsWrapper* contents, |
| int index) { |
| - if (fullscreened_tab_ == contents) { |
| - ExitTabbedFullscreenModeIfNecessary(); |
| - // The call to exit fullscreen may result in asynchronous notification of |
| - // fullscreen state change (e.g., on Linux). We don't want to rely on it |
| - // to call NotifyTabOfFullscreenExitIfNecessary(), because at that point |
| - // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up |
| - // tab fullscreen related state. |
| - NotifyTabOfFullscreenExitIfNecessary(); |
| - } |
| + fullscreen_controller_->OnTabClosing(contents->tab_contents()); |
| content::NotificationService::current()->Notify( |
| content::NOTIFICATION_TAB_CLOSING, |
| content::Source<NavigationController>(&contents->controller()), |
| @@ -3258,8 +3169,7 @@ void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
| } |
| void Browser::TabDeactivated(TabContentsWrapper* contents) { |
| - if (contents == fullscreened_tab_) |
| - ExitTabbedFullscreenModeIfNecessary(); |
| + fullscreen_controller_->OnTabDeactivated(contents); |
| if (instant()) |
| instant()->Hide(); |
| @@ -3797,8 +3707,8 @@ bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| bool* is_keyboard_shortcut) { |
| // Escape exits tabbed fullscreen mode. |
| // TODO(koz): Write a test for this http://crbug.com/100441. |
| - if (event.windowsKeyCode == 27 && fullscreened_tab_) { |
| - ExitTabbedFullscreenModeIfNecessary(); |
| + if (event.windowsKeyCode == 27 && |
| + fullscreen_controller_->HandleUserPressedEscape()) { |
| return true; |
| } |
| return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| @@ -3887,63 +3797,11 @@ void Browser::EnumerateDirectory(TabContents* tab, int request_id, |
| void Browser::ToggleFullscreenModeForTab(TabContents* tab, |
| bool enter_fullscreen) { |
|
Peter Kasting
2011/11/03 18:24:56
Nit: While here, indent this arg even with the oth
koz (OOO until 15th September)
2011/11/06 23:30:20
Done.
|
| - if (tab != GetSelectedTabContents()) |
| - return; |
| - |
| - bool in_browser_or_tab_fullscreen_mode; |
| -#if defined(OS_MACOSX) |
| - in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); |
| -#else |
| - in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); |
| -#endif |
| - |
| - if (enter_fullscreen) { |
| - fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| - if (!in_browser_or_tab_fullscreen_mode) { |
| - tab_caused_fullscreen_ = true; |
| -#if defined(OS_MACOSX) |
| - TogglePresentationMode(true); |
| -#else |
| - ToggleFullscreenMode(true); |
| -#endif |
| - } else { |
| - // We need to update the fullscreen exit bubble, e.g., going from browser |
| - // fullscreen to tab fullscreen will need to show different content. |
| - const GURL& url = tab->GetURL(); |
| - if (!tab_fullscreen_accepted_) { |
| - tab_fullscreen_accepted_ = |
| - GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| - } |
| - UpdateFullscreenExitBubbleContent(); |
| - } |
| - } else { |
| - if (in_browser_or_tab_fullscreen_mode) { |
| - if (tab_caused_fullscreen_) { |
| -#if defined(OS_MACOSX) |
| - TogglePresentationMode(true); |
| -#else |
| - ToggleFullscreenMode(true); |
| -#endif |
| - } else { |
| - // If currently there is a tab in "tab fullscreen" mode and fullscreen |
| - // was not caused by it (i.e., previously it was in "browser fullscreen" |
| - // mode), we need to switch back to "browser fullscreen" mode. In this |
| - // case, all we have to do is notifying the tab that it has exited "tab |
| - // fullscreen" mode. |
| - NotifyTabOfFullscreenExitIfNecessary(); |
| - } |
| - } |
| - } |
| + fullscreen_controller_->ToggleFullscreenModeForTab(tab, enter_fullscreen); |
| } |
| bool Browser::IsFullscreenForTab(const TabContents* tab) const { |
| - const TabContentsWrapper* wrapper = |
| - TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| - bool result = wrapper && wrapper == fullscreened_tab_; |
| - DCHECK(!result || tab == GetSelectedTabContents()); |
| - DCHECK(!result || window_->IsFullscreen()); |
| - |
| - return result; |
| + return fullscreen_controller_->IsFullscreenForTab(tab); |
| } |
| void Browser::JSOutOfMemory(TabContents* tab) { |
| @@ -3996,122 +3854,29 @@ void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
| CrashedPluginHelper(tab, plugin_path); |
| } |
| -void Browser::ExitTabbedFullscreenModeIfNecessary() { |
| - if (tab_caused_fullscreen_) |
| - ToggleFullscreenMode(false); |
| - else |
| - NotifyTabOfFullscreenExitIfNecessary(); |
| -} |
| - |
| void Browser::UpdatePreferredSize(TabContents* source, |
| const gfx::Size& pref_size) { |
| window_->UpdatePreferredSize(source, pref_size); |
| } |
| void Browser::RequestToLockMouse(TabContents* tab) { |
| - // Mouse Lock is only permitted when browser is in tab fullscreen. |
| - if (!IsFullscreenForTab(tab)) { |
| - tab->GotResponseToLockMouseRequest(false); |
| - return; |
| - } |
| - |
| - if (mouse_lock_state_ == MOUSELOCK_ACCEPTED) { |
| - tab->GotResponseToLockMouseRequest(true); |
| - return; |
| - } |
| - |
| - switch (GetMouseLockSetting(tab->GetURL())) { |
| - case CONTENT_SETTING_ALLOW: |
| - mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| - tab->GotResponseToLockMouseRequest(true); |
| - break; |
| - case CONTENT_SETTING_BLOCK: |
| - mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| - tab->GotResponseToLockMouseRequest(false); |
| - break; |
| - case CONTENT_SETTING_ASK: |
| - mouse_lock_state_ = MOUSELOCK_REQUESTED; |
| - break; |
| - default: |
| - NOTREACHED(); |
| - } |
| - UpdateFullscreenExitBubbleContent(); |
| + fullscreen_controller_->RequestToLockMouse(tab); |
| } |
| void Browser::LostMouseLock() { |
| - mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| - UpdateFullscreenExitBubbleContent(); |
| + fullscreen_controller_->LostMouseLock(); |
| } |
| void Browser::OnAcceptFullscreenPermission( |
| const GURL& url, |
| FullscreenExitBubbleType bubble_type) { |
| - bool mouse_lock = false; |
| - bool fullscreen = false; |
| - fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, |
| - &mouse_lock); |
| - DCHECK(fullscreened_tab_); |
| - DCHECK_NE(tab_fullscreen_accepted_, fullscreen); |
| - |
| - HostContentSettingsMap* settings_map = |
| - profile()->GetHostContentSettingsMap(); |
| - if (mouse_lock) { |
| - DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); |
| - settings_map->SetContentSetting( |
| - ContentSettingsPattern::FromURL(url), |
| - ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_MOUSELOCK, |
| - std::string(), CONTENT_SETTING_ALLOW); |
| - mouse_lock_state_ = |
| - fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(true) ? |
| - MOUSELOCK_ACCEPTED : MOUSELOCK_NOT_REQUESTED; |
| - } |
| - if (!tab_fullscreen_accepted_) { |
| - settings_map->SetContentSetting( |
| - ContentSettingsPattern::FromURL(url), |
| - ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| - std::string(), CONTENT_SETTING_ALLOW); |
| - tab_fullscreen_accepted_ = true; |
| - } |
| - UpdateFullscreenExitBubbleContent(); |
| + fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); |
| } |
| void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
| - bool mouse_lock = false; |
| - bool fullscreen = false; |
| - fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, |
| - &mouse_lock); |
| - DCHECK(fullscreened_tab_); |
| - DCHECK_NE(tab_fullscreen_accepted_, fullscreen); |
| - |
| - if (mouse_lock) { |
| - DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); |
| - mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| - fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(false); |
| - if (!fullscreen) |
| - UpdateFullscreenExitBubbleContent(); |
| - } |
| - |
| - if (fullscreen) |
| - ExitTabbedFullscreenModeIfNecessary(); |
| -} |
| - |
| -ContentSetting Browser::GetFullscreenSetting(const GURL& url) { |
| - if (url.SchemeIsFile()) |
| - return CONTENT_SETTING_ALLOW; |
| - |
| - HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); |
| - return settings_map->GetContentSetting(url, url, |
| - CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); |
| + fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); |
| } |
| -ContentSetting Browser::GetMouseLockSetting(const GURL& url) { |
| - if (url.SchemeIsFile()) |
| - return CONTENT_SETTING_ALLOW; |
| - |
| - HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); |
| - return settings_map->GetContentSetting(url, url, |
| - CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
| -} |
| /////////////////////////////////////////////////////////////////////////////// |
| // Browser, TabContentsWrapperDelegate implementation: |
| @@ -4354,6 +4119,11 @@ void Browser::Observe(int type, |
| UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| break; |
| + case chrome::NOTIFICATION_FULLSCREEN_CHANGED: |
|
yzshen1
2011/11/04 01:56:32
[Not sure whether it affects anything, just want t
koz (OOO until 15th September)
2011/11/06 23:30:20
I did consider this. I tested the UpdateCommands..
|
| + UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| + UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
| + break; |
| + |
| default: |
| NOTREACHED() << "Got a notification we didn't register for."; |
| } |
| @@ -5481,31 +5251,3 @@ void Browser::OnWindowDidShow() { |
| } |
| } |
| } |
| - |
| -FullscreenExitBubbleType Browser::GetFullscreenExitBubbleType() const { |
| - bool tab_fullscreen_requested = |
| - fullscreened_tab_ && !tab_fullscreen_accepted_; |
| - if (!tab_fullscreen_requested && !tab_fullscreen_accepted_) { |
| - DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); |
| - return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; |
| - } |
| - if (tab_fullscreen_requested) { |
| - DCHECK_NE(mouse_lock_state_, MOUSELOCK_ACCEPTED); |
| - return mouse_lock_state_ == MOUSELOCK_REQUESTED ? |
| - FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS; |
| - } |
| - if (mouse_lock_state_ == MOUSELOCK_REQUESTED) |
| - return FEB_TYPE_MOUSELOCK_BUTTONS; |
| - return mouse_lock_state_ == MOUSELOCK_ACCEPTED ? |
| - FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION : |
| - FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
| -} |
| - |
| -void Browser::UpdateFullscreenExitBubbleContent() { |
| - GURL url; |
| - if (fullscreened_tab_) |
| - url = fullscreened_tab_->tab_contents()->GetURL(); |
| - |
| - window_->UpdateFullscreenExitBubbleContent( |
| - url, GetFullscreenExitBubbleType()); |
| -} |