Chromium Code Reviews| Index: chrome/browser/ui/fullscreen_controller.cc |
| diff --git a/chrome/browser/ui/fullscreen_controller.cc b/chrome/browser/ui/fullscreen_controller.cc |
| index d171bf016ef8802287abce5c16d4dfc91b98b273..7b803cbabf199a4d33da5fc8cea986cbe9cf9ace 100644 |
| --- a/chrome/browser/ui/fullscreen_controller.cc |
| +++ b/chrome/browser/ui/fullscreen_controller.cc |
| @@ -39,8 +39,7 @@ FullscreenController::FullscreenController(BrowserWindow* window, |
| tab_fullscreen_accepted_(false), |
| toggled_into_fullscreen_(false), |
| mouse_lock_tab_(NULL), |
| - mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), |
| - cancel_fullscreen_on_navigate_mode_(false) { |
| + mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { |
| } |
| void FullscreenController::Observe(int type, |
| @@ -116,7 +115,7 @@ void FullscreenController::RequestToLockMouse(WebContents* web_contents, |
| web_contents->GotResponseToLockMouseRequest(false); |
| return; |
| } |
| - mouse_lock_tab_ = TabContents::FromWebContents(web_contents); |
| + set_mouse_lock_tab(TabContents::FromWebContents(web_contents)); |
| FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); |
| switch (GetMouseLockSetting(web_contents->GetURL())) { |
| @@ -134,14 +133,14 @@ void FullscreenController::RequestToLockMouse(WebContents* web_contents, |
| mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| } |
| } else { |
| - mouse_lock_tab_ = NULL; |
| + set_mouse_lock_tab(NULL); |
| mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| } |
| } |
| break; |
| case CONTENT_SETTING_BLOCK: |
| web_contents->GotResponseToLockMouseRequest(false); |
| - mouse_lock_tab_ = NULL; |
| + set_mouse_lock_tab(NULL); |
| mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| break; |
| case CONTENT_SETTING_ASK: |
| @@ -166,8 +165,7 @@ void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, |
| #endif |
| if (enter_fullscreen) { |
| - fullscreened_tab_ = TabContents::FromWebContents(web_contents); |
| - EnterCancelFullscreenOnNavigateMode(); |
| + set_fullscreened_tab(TabContents::FromWebContents(web_contents)); |
| if (!in_browser_or_tab_fullscreen_mode) { |
| tab_caused_fullscreen_ = true; |
| #if defined(OS_MACOSX) |
| @@ -186,7 +184,6 @@ void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, |
| UpdateFullscreenExitBubbleContent(); |
| } |
| } else { |
| - ExitCancelFullscreenOnNavigateMode(); |
| if (in_browser_or_tab_fullscreen_mode) { |
| if (tab_caused_fullscreen_) { |
| #if defined(OS_MACOSX) |
| @@ -233,7 +230,7 @@ void FullscreenController::ToggleFullscreenModeWithExtension( |
| void FullscreenController::LostMouseLock() { |
| mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| - mouse_lock_tab_ = NULL; |
| + set_mouse_lock_tab(NULL); |
| NotifyMouseLockChange(); |
| UpdateFullscreenExitBubbleContent(); |
| } |
| @@ -284,7 +281,7 @@ void FullscreenController::OnAcceptFullscreenPermission( |
| mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| } else { |
| mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| - mouse_lock_tab_ = NULL; |
| + set_mouse_lock_tab(NULL); |
| } |
| NotifyMouseLockChange(); |
| } |
| @@ -317,7 +314,7 @@ void FullscreenController::OnDenyFullscreenPermission( |
| mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| if (mouse_lock_tab_ && mouse_lock_tab_->web_contents()) |
| mouse_lock_tab_->web_contents()->GotResponseToLockMouseRequest(false); |
| - mouse_lock_tab_ = NULL; |
| + set_mouse_lock_tab(NULL); |
| NotifyMouseLockChange(); |
| // UpdateFullscreenExitBubbleContent() must be called, but to avoid |
| @@ -363,10 +360,9 @@ FullscreenController::~FullscreenController() {} |
| void FullscreenController::NotifyTabOfExitIfNecessary() { |
| if (fullscreened_tab_) { |
| - ExitCancelFullscreenOnNavigateMode(); |
| RenderViewHost* rvh = |
| fullscreened_tab_->web_contents()->GetRenderViewHost(); |
| - fullscreened_tab_ = NULL; |
| + set_fullscreened_tab(NULL); |
| tab_caused_fullscreen_ = false; |
| tab_fullscreen_accepted_ = false; |
| if (rvh) |
| @@ -377,33 +373,32 @@ void FullscreenController::NotifyTabOfExitIfNecessary() { |
| WebContents* web_contents = mouse_lock_tab_->web_contents(); |
| if (IsMouseLockRequested()) { |
| web_contents->GotResponseToLockMouseRequest(false); |
| + NotifyMouseLockChange(); |
| } else if (web_contents->GetRenderViewHost() && |
| web_contents->GetRenderViewHost()->GetView()) { |
| web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); |
| } |
| - mouse_lock_tab_ = NULL; |
| + set_mouse_lock_tab(NULL); |
| mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| } |
| UpdateFullscreenExitBubbleContent(); |
| } |
| -void FullscreenController::EnterCancelFullscreenOnNavigateMode() { |
| - if (cancel_fullscreen_on_navigate_mode_) |
| - return; |
| - cancel_fullscreen_on_navigate_mode_ = true; |
| - registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| - content::Source<content::NavigationController>( |
| - &fullscreened_tab_->web_contents()->GetController())); |
| -} |
| +void FullscreenController::UpdateNotificationRegistrations() { |
| + if (fullscreened_tab_ && mouse_lock_tab_) |
| + DCHECK(fullscreened_tab_ == mouse_lock_tab_); |
|
yzshen1
2012/06/20 18:07:54
nit: you could DCHECK(!(fullscreened_tab_ && mouse
scheib
2012/06/20 20:38:24
I considered, but felt this was easier to read.
yzshen1
2012/06/20 20:56:46
A if-block containing only a DCHECK is a little bi
|
| -void FullscreenController::ExitCancelFullscreenOnNavigateMode() { |
| - if (!cancel_fullscreen_on_navigate_mode_) |
| - return; |
| - cancel_fullscreen_on_navigate_mode_ = false; |
| - registrar_.RemoveAll(); |
| -} |
| + TabContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; |
| + if (tab && registrar_.IsEmpty()) { |
| + registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| + content::Source<content::NavigationController>( |
| + &tab->web_contents()->GetController())); |
| + } else if (!tab && !registrar_.IsEmpty()) { |
| + registrar_.RemoveAll(); |
| + } |
| +} |
| void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { |
| if (tab_caused_fullscreen_) |
| @@ -572,3 +567,13 @@ void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) { |
| // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| } |
| + |
| +void FullscreenController::set_fullscreened_tab(TabContents* tab) { |
|
koz (OOO until 15th September)
2012/06/19 23:57:17
nit: I think it's more in line with C++ style to h
scheib
2012/06/20 20:38:24
Done.
|
| + fullscreened_tab_ = tab; |
| + UpdateNotificationRegistrations(); |
| +} |
| + |
| +void FullscreenController::set_mouse_lock_tab(TabContents* tab) { |
| + mouse_lock_tab_ = tab; |
| + UpdateNotificationRegistrations(); |
| +} |