| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/exclusive_access/fullscreen_controller.h" | 5 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/app_mode/app_mode_utils.h" | 10 #include "chrome/browser/app_mode/app_mode_utils.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #if !defined(OS_MACOSX) | 31 #if !defined(OS_MACOSX) |
| 32 #include "base/prefs/pref_service.h" | 32 #include "base/prefs/pref_service.h" |
| 33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 using base::UserMetricsAction; | 36 using base::UserMetricsAction; |
| 37 using content::RenderViewHost; | 37 using content::RenderViewHost; |
| 38 using content::WebContents; | 38 using content::WebContents; |
| 39 | 39 |
| 40 FullscreenController::FullscreenController(Browser* browser) | 40 FullscreenController::FullscreenController( |
| 41 : browser_(browser), | 41 ExclusiveAccessControllerManager* manager, |
| 42 window_(browser->window()), | 42 Browser* browser) |
| 43 profile_(browser->profile()), | 43 : ExclusiveAccessControllerBase(manager, browser), |
| 44 fullscreened_tab_(NULL), | |
| 45 state_prior_to_tab_fullscreen_(STATE_INVALID), | 44 state_prior_to_tab_fullscreen_(STATE_INVALID), |
| 46 tab_fullscreen_accepted_(false), | 45 tab_fullscreen_accepted_(false), |
| 47 toggled_into_fullscreen_(false), | 46 toggled_into_fullscreen_(false), |
| 48 mouse_lock_tab_(NULL), | |
| 49 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), | |
| 50 reentrant_window_state_change_call_check_(false), | 47 reentrant_window_state_change_call_check_(false), |
| 51 is_privileged_fullscreen_for_testing_(false), | 48 is_privileged_fullscreen_for_testing_(false), |
| 52 ptr_factory_(this) { | 49 ptr_factory_(this) { |
| 53 DCHECK(window_); | |
| 54 DCHECK(profile_); | |
| 55 } | 50 } |
| 56 | 51 |
| 57 FullscreenController::~FullscreenController() { | 52 FullscreenController::~FullscreenController() { |
| 58 } | 53 } |
| 59 | 54 |
| 60 bool FullscreenController::IsFullscreenForBrowser() const { | 55 bool FullscreenController::IsFullscreenForBrowser() const { |
| 61 return window_->IsFullscreen() && !IsFullscreenCausedByTab(); | 56 return GetWindow()->IsFullscreen() && !IsFullscreenCausedByTab(); |
| 62 } | 57 } |
| 63 | 58 |
| 64 void FullscreenController::ToggleBrowserFullscreenMode() { | 59 void FullscreenController::ToggleBrowserFullscreenMode() { |
| 65 extension_caused_fullscreen_ = GURL(); | 60 extension_caused_fullscreen_ = GURL(); |
| 66 ToggleFullscreenModeInternal(BROWSER); | 61 ToggleFullscreenModeInternal(BROWSER); |
| 67 } | 62 } |
| 68 | 63 |
| 69 void FullscreenController::ToggleBrowserFullscreenWithToolbar() { | 64 void FullscreenController::ToggleBrowserFullscreenWithToolbar() { |
| 70 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR); | 65 ToggleFullscreenModeInternal(BROWSER_WITH_TOOLBAR); |
| 71 } | 66 } |
| 72 | 67 |
| 73 void FullscreenController::ToggleBrowserFullscreenModeWithExtension( | 68 void FullscreenController::ToggleBrowserFullscreenModeWithExtension( |
| 74 const GURL& extension_url) { | 69 const GURL& extension_url) { |
| 75 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to | 70 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to |
| 76 // exit. | 71 // exit. |
| 77 extension_caused_fullscreen_ = extension_url; | 72 extension_caused_fullscreen_ = extension_url; |
| 78 ToggleFullscreenModeInternal(BROWSER); | 73 ToggleFullscreenModeInternal(BROWSER); |
| 79 } | 74 } |
| 80 | 75 |
| 81 bool FullscreenController::IsWindowFullscreenForTabOrPending() const { | 76 bool FullscreenController::IsWindowFullscreenForTabOrPending() const { |
| 82 return fullscreened_tab_ != NULL; | 77 return GetExclusiveAccessTab() != nullptr; |
| 78 } |
| 79 |
| 80 bool FullscreenController::IsExtensionFullscreenOrPending() const { |
| 81 return !extension_caused_fullscreen_.is_empty(); |
| 82 } |
| 83 |
| 84 bool FullscreenController::IsControllerInitiatedFullscreen() const { |
| 85 return toggled_into_fullscreen_; |
| 86 } |
| 87 |
| 88 bool FullscreenController::IsUserAcceptedFullscreen() const { |
| 89 return tab_fullscreen_accepted_; |
| 83 } | 90 } |
| 84 | 91 |
| 85 bool FullscreenController::IsFullscreenForTabOrPending( | 92 bool FullscreenController::IsFullscreenForTabOrPending( |
| 86 const WebContents* web_contents) const { | 93 const WebContents* web_contents) const { |
| 87 if (web_contents == fullscreened_tab_) { | 94 if (web_contents == GetExclusiveAccessTab()) { |
| 88 DCHECK(web_contents == browser_->tab_strip_model()->GetActiveWebContents()); | 95 DCHECK(web_contents == |
| 96 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
| 89 DCHECK(web_contents->GetCapturerCount() == 0); | 97 DCHECK(web_contents->GetCapturerCount() == 0); |
| 90 return true; | 98 return true; |
| 91 } | 99 } |
| 92 return IsFullscreenForCapturedTab(web_contents); | 100 return IsFullscreenForCapturedTab(web_contents); |
| 93 } | 101 } |
| 94 | 102 |
| 95 bool FullscreenController::IsFullscreenCausedByTab() const { | 103 bool FullscreenController::IsFullscreenCausedByTab() const { |
| 96 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; | 104 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; |
| 97 } | 105 } |
| 98 | 106 |
| 99 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, | 107 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, |
| 100 bool enter_fullscreen) { | 108 bool enter_fullscreen) { |
| 101 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) { | 109 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) { |
| 102 // During tab capture of fullscreen-within-tab views, the browser window | 110 // During tab capture of fullscreen-within-tab views, the browser window |
| 103 // fullscreen state is unchanged, so return now. | 111 // fullscreen state is unchanged, so return now. |
| 104 return; | 112 return; |
| 105 } | 113 } |
| 106 if (fullscreened_tab_) { | 114 if (GetExclusiveAccessTab()) { |
| 107 if (web_contents != fullscreened_tab_) | 115 if (web_contents != GetExclusiveAccessTab()) |
| 108 return; | 116 return; |
| 109 } else if ( | 117 } else if (web_contents != |
| 110 web_contents != browser_->tab_strip_model()->GetActiveWebContents()) { | 118 GetBrowser()->tab_strip_model()->GetActiveWebContents()) { |
| 111 return; | 119 return; |
| 112 } | 120 } |
| 113 if (IsWindowFullscreenForTabOrPending() == enter_fullscreen) | 121 if (IsWindowFullscreenForTabOrPending() == enter_fullscreen) |
| 114 return; | 122 return; |
| 115 | 123 |
| 116 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
| 117 // For now, avoid breaking when initiating full screen tab mode while in | 125 // For now, avoid breaking when initiating full screen tab mode while in |
| 118 // a metro snap. | 126 // a metro snap. |
| 119 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | 127 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen |
| 120 // modes with metro snap. | 128 // modes with metro snap. |
| 121 if (IsInMetroSnapMode()) | 129 if (IsInMetroSnapMode()) |
| 122 return; | 130 return; |
| 123 #endif | 131 #endif |
| 124 | 132 |
| 125 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | 133 bool in_browser_or_tab_fullscreen_mode = GetWindow()->IsFullscreen(); |
| 126 | 134 |
| 127 if (enter_fullscreen) { | 135 if (enter_fullscreen) { |
| 128 SetFullscreenedTab(web_contents); | 136 SetTabWithExclusiveAccess(web_contents); |
| 129 if (!in_browser_or_tab_fullscreen_mode) { | 137 if (!in_browser_or_tab_fullscreen_mode) { |
| 130 // Normal -> Tab Fullscreen. | 138 // Normal -> Tab Fullscreen. |
| 131 state_prior_to_tab_fullscreen_ = STATE_NORMAL; | 139 state_prior_to_tab_fullscreen_ = STATE_NORMAL; |
| 132 ToggleFullscreenModeInternal(TAB); | 140 ToggleFullscreenModeInternal(TAB); |
| 133 } else { | 141 } else { |
| 134 if (window_->IsFullscreenWithToolbar()) { | 142 if (GetWindow()->IsFullscreenWithToolbar()) { |
| 135 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). | 143 // Browser Fullscreen with Toolbar -> Tab Fullscreen (no toolbar). |
| 136 window_->UpdateFullscreenWithToolbar(false); | 144 GetWindow()->UpdateFullscreenWithToolbar(false); |
| 137 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; | 145 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR; |
| 138 } else { | 146 } else { |
| 139 // Browser Fullscreen without Toolbar -> Tab Fullscreen. | 147 // Browser Fullscreen without Toolbar -> Tab Fullscreen. |
| 140 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; | 148 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_TOOLBAR; |
| 141 } | 149 } |
| 142 | 150 |
| 143 // We need to update the fullscreen exit bubble, e.g., going from browser | 151 // We need to update the fullscreen exit bubble, e.g., going from browser |
| 144 // fullscreen to tab fullscreen will need to show different content. | 152 // fullscreen to tab fullscreen will need to show different content. |
| 145 const GURL& url = web_contents->GetURL(); | 153 const GURL& url = web_contents->GetURL(); |
| 146 if (!tab_fullscreen_accepted_) { | 154 if (!tab_fullscreen_accepted_) { |
| 147 tab_fullscreen_accepted_ = | 155 tab_fullscreen_accepted_ = |
| 148 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 156 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| 149 } | 157 } |
| 150 UpdateFullscreenExitBubbleContent(); | 158 UpdateExclusiveAccessExitBubbleContent(); |
| 151 | 159 |
| 152 // This is only a change between Browser and Tab fullscreen. We generate | 160 // This is only a change between Browser and Tab fullscreen. We generate |
| 153 // a fullscreen notification now because there is no window change. | 161 // a fullscreen notification now because there is no window change. |
| 154 PostFullscreenChangeNotification(true); | 162 PostFullscreenChangeNotification(true); |
| 155 } | 163 } |
| 156 } else { | 164 } else { |
| 157 if (in_browser_or_tab_fullscreen_mode) { | 165 if (in_browser_or_tab_fullscreen_mode) { |
| 158 if (IsFullscreenCausedByTab()) { | 166 if (IsFullscreenCausedByTab()) { |
| 159 // Tab Fullscreen -> Normal. | 167 // Tab Fullscreen -> Normal. |
| 160 ToggleFullscreenModeInternal(TAB); | 168 ToggleFullscreenModeInternal(TAB); |
| 161 } else { | 169 } else { |
| 162 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). | 170 // Tab Fullscreen -> Browser Fullscreen (with or without toolbar). |
| 163 if (state_prior_to_tab_fullscreen_ == | 171 if (state_prior_to_tab_fullscreen_ == |
| 164 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { | 172 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR) { |
| 165 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. | 173 // Tab Fullscreen (no toolbar) -> Browser Fullscreen with Toolbar. |
| 166 window_->UpdateFullscreenWithToolbar(true); | 174 GetWindow()->UpdateFullscreenWithToolbar(true); |
| 167 } | 175 } |
| 168 | 176 |
| 169 #if defined(OS_MACOSX) | 177 #if defined(OS_MACOSX) |
| 170 // Clear the bubble URL, which forces the Mac UI to redraw. | 178 // Clear the bubble URL, which forces the Mac UI to redraw. |
| 171 UpdateFullscreenExitBubbleContent(); | 179 UpdateExclusiveAccessExitBubbleContent(); |
| 172 #endif // defined(OS_MACOSX) | 180 #endif // defined(OS_MACOSX) |
| 173 | 181 |
| 174 // If currently there is a tab in "tab fullscreen" mode and fullscreen | 182 // If currently there is a tab in "tab fullscreen" mode and fullscreen |
| 175 // was not caused by it (i.e., previously it was in "browser fullscreen" | 183 // was not caused by it (i.e., previously it was in "browser fullscreen" |
| 176 // mode), we need to switch back to "browser fullscreen" mode. In this | 184 // mode), we need to switch back to "browser fullscreen" mode. In this |
| 177 // case, all we have to do is notifying the tab that it has exited "tab | 185 // case, all we have to do is notifying the tab that it has exited "tab |
| 178 // fullscreen" mode. | 186 // fullscreen" mode. |
| 179 NotifyTabOfExitIfNecessary(); | 187 NotifyTabOfExclusiveAccessChange(); |
| 180 | 188 |
| 181 // This is only a change between Browser and Tab fullscreen. We generate | 189 // This is only a change between Browser and Tab fullscreen. We generate |
| 182 // a fullscreen notification now because there is no window change. | 190 // a fullscreen notification now because there is no window change. |
| 183 PostFullscreenChangeNotification(true); | 191 PostFullscreenChangeNotification(true); |
| 184 } | 192 } |
| 185 } | 193 } |
| 186 } | 194 } |
| 187 } | 195 } |
| 188 | 196 |
| 189 bool FullscreenController::IsInMetroSnapMode() { | 197 bool FullscreenController::IsInMetroSnapMode() { |
| 190 #if defined(OS_WIN) | 198 #if defined(OS_WIN) |
| 191 return window_->IsInMetroSnapMode(); | 199 return GetWindow()->IsInMetroSnapMode(); |
| 192 #else | 200 #else |
| 193 return false; | 201 return false; |
| 194 #endif | 202 #endif |
| 195 } | 203 } |
| 196 | 204 |
| 197 #if defined(OS_WIN) | 205 #if defined(OS_WIN) |
| 198 void FullscreenController::SetMetroSnapMode(bool enable) { | 206 void FullscreenController::SetMetroSnapMode(bool enable) { |
| 199 reentrant_window_state_change_call_check_ = false; | 207 reentrant_window_state_change_call_check_ = false; |
| 200 | 208 |
| 201 toggled_into_fullscreen_ = false; | 209 toggled_into_fullscreen_ = false; |
| 202 window_->SetMetroSnapMode(enable); | 210 GetWindow()->SetMetroSnapMode(enable); |
| 203 | 211 |
| 204 // FullscreenController unit tests for metro snap assume that on Windows calls | 212 // FullscreenController unit tests for metro snap assume that on Windows calls |
| 205 // to WindowFullscreenStateChanged are reentrant. If that assumption is | 213 // to WindowFullscreenStateChanged are reentrant. If that assumption is |
| 206 // invalidated, the tests must be updated to maintain coverage. | 214 // invalidated, the tests must be updated to maintain coverage. |
| 207 CHECK(reentrant_window_state_change_call_check_); | 215 CHECK(reentrant_window_state_change_call_check_); |
| 208 } | 216 } |
| 209 #endif // defined(OS_WIN) | 217 #endif // defined(OS_WIN) |
| 210 | 218 |
| 211 bool FullscreenController::IsMouseLockRequested() const { | |
| 212 return mouse_lock_state_ == MOUSELOCK_REQUESTED; | |
| 213 } | |
| 214 | |
| 215 bool FullscreenController::IsMouseLocked() const { | |
| 216 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || | |
| 217 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; | |
| 218 } | |
| 219 | |
| 220 void FullscreenController::RequestToLockMouse(WebContents* web_contents, | |
| 221 bool user_gesture, | |
| 222 bool last_unlocked_by_target) { | |
| 223 DCHECK(!IsMouseLocked()); | |
| 224 NotifyMouseLockChange(); | |
| 225 | |
| 226 // Must have a user gesture to prevent misbehaving sites from constantly | |
| 227 // re-locking the mouse. Exceptions are when the page has unlocked | |
| 228 // (i.e. not the user), or if we're in tab fullscreen (user gesture required | |
| 229 // for that) | |
| 230 if (!last_unlocked_by_target && !user_gesture && | |
| 231 !IsFullscreenForTabOrPending(web_contents)) { | |
| 232 web_contents->GotResponseToLockMouseRequest(false); | |
| 233 return; | |
| 234 } | |
| 235 SetMouseLockTab(web_contents); | |
| 236 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | |
| 237 | |
| 238 switch (GetMouseLockSetting(web_contents->GetURL())) { | |
| 239 case CONTENT_SETTING_ALLOW: | |
| 240 // If bubble already displaying buttons we must not lock the mouse yet, | |
| 241 // or it would prevent pressing those buttons. Instead, merge the request. | |
| 242 if (!IsPrivilegedFullscreenForTab() && | |
| 243 exclusive_access_bubble::ShowButtonsForType(bubble_type)) { | |
| 244 mouse_lock_state_ = MOUSELOCK_REQUESTED; | |
| 245 } else { | |
| 246 // Lock mouse. | |
| 247 if (web_contents->GotResponseToLockMouseRequest(true)) { | |
| 248 if (last_unlocked_by_target) { | |
| 249 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; | |
| 250 } else { | |
| 251 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | |
| 252 } | |
| 253 } else { | |
| 254 SetMouseLockTab(NULL); | |
| 255 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 256 } | |
| 257 } | |
| 258 break; | |
| 259 case CONTENT_SETTING_BLOCK: | |
| 260 web_contents->GotResponseToLockMouseRequest(false); | |
| 261 SetMouseLockTab(NULL); | |
| 262 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 263 break; | |
| 264 case CONTENT_SETTING_ASK: | |
| 265 mouse_lock_state_ = MOUSELOCK_REQUESTED; | |
| 266 break; | |
| 267 default: | |
| 268 NOTREACHED(); | |
| 269 } | |
| 270 UpdateFullscreenExitBubbleContent(); | |
| 271 } | |
| 272 | |
| 273 void FullscreenController::OnTabDeactivated(WebContents* web_contents) { | |
| 274 if (web_contents == fullscreened_tab_ || web_contents == mouse_lock_tab_) | |
| 275 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 276 } | |
| 277 | |
| 278 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { | 219 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { |
| 279 if (!IsFullscreenForCapturedTab(old_contents)) | 220 if (!IsFullscreenForCapturedTab(old_contents)) |
| 280 return; | 221 return; |
| 281 | 222 |
| 282 // A fullscreen-within-tab view undergoing screen capture has been detached | 223 // A fullscreen-within-tab view undergoing screen capture has been detached |
| 283 // and is no longer visible to the user. Set it to exactly the WebContents' | 224 // and is no longer visible to the user. Set it to exactly the WebContents' |
| 284 // preferred size. See 'FullscreenWithinTab Note'. | 225 // preferred size. See 'FullscreenWithinTab Note'. |
| 285 // | 226 // |
| 286 // When the user later selects the tab to show |old_contents| again, UI code | 227 // When the user later selects the tab to show |old_contents| again, UI code |
| 287 // elsewhere (e.g., views::WebView) will resize the view to fit within the | 228 // elsewhere (e.g., views::WebView) will resize the view to fit within the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 305 if (current_fs_view) | 246 if (current_fs_view) |
| 306 current_fs_view->SetSize(old_contents->GetPreferredSize()); | 247 current_fs_view->SetSize(old_contents->GetPreferredSize()); |
| 307 ResizeWebContents(old_contents, old_contents->GetPreferredSize()); | 248 ResizeWebContents(old_contents, old_contents->GetPreferredSize()); |
| 308 } | 249 } |
| 309 | 250 |
| 310 void FullscreenController::OnTabClosing(WebContents* web_contents) { | 251 void FullscreenController::OnTabClosing(WebContents* web_contents) { |
| 311 if (IsFullscreenForCapturedTab(web_contents)) { | 252 if (IsFullscreenForCapturedTab(web_contents)) { |
| 312 RenderViewHost* const rvh = web_contents->GetRenderViewHost(); | 253 RenderViewHost* const rvh = web_contents->GetRenderViewHost(); |
| 313 if (rvh) | 254 if (rvh) |
| 314 rvh->ExitFullscreen(); | 255 rvh->ExitFullscreen(); |
| 315 } else if (web_contents == fullscreened_tab_ || | 256 } else { |
| 316 web_contents == mouse_lock_tab_) { | 257 ExclusiveAccessControllerBase::OnTabClosing(web_contents); |
| 317 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 318 // The call to exit fullscreen may result in asynchronous notification of | |
| 319 // fullscreen state change (e.g., on Linux). We don't want to rely on it | |
| 320 // to call NotifyTabOfExitIfNecessary(), because at that point | |
| 321 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean | |
| 322 // up tab fullscreen related state. | |
| 323 NotifyTabOfExitIfNecessary(); | |
| 324 } | 258 } |
| 325 } | 259 } |
| 326 | 260 |
| 327 void FullscreenController::WindowFullscreenStateChanged() { | 261 void FullscreenController::WindowFullscreenStateChanged() { |
| 328 reentrant_window_state_change_call_check_ = true; | 262 reentrant_window_state_change_call_check_ = true; |
| 329 | 263 |
| 330 bool exiting_fullscreen = !window_->IsFullscreen(); | 264 bool exiting_fullscreen = !GetWindow()->IsFullscreen(); |
| 331 | 265 |
| 332 PostFullscreenChangeNotification(!exiting_fullscreen); | 266 PostFullscreenChangeNotification(!exiting_fullscreen); |
| 333 if (exiting_fullscreen) { | 267 if (exiting_fullscreen) { |
| 334 toggled_into_fullscreen_ = false; | 268 toggled_into_fullscreen_ = false; |
| 335 extension_caused_fullscreen_ = GURL(); | 269 extension_caused_fullscreen_ = GURL(); |
| 336 NotifyTabOfExitIfNecessary(); | 270 NotifyTabOfExclusiveAccessChange(); |
| 337 } | 271 } |
| 338 if (exiting_fullscreen) { | 272 if (exiting_fullscreen) { |
| 339 window_->GetDownloadShelf()->Unhide(); | 273 GetWindow()->GetDownloadShelf()->Unhide(); |
| 340 } else { | 274 } else { |
| 341 window_->GetDownloadShelf()->Hide(); | 275 GetWindow()->GetDownloadShelf()->Hide(); |
| 342 if (window_->GetStatusBubble()) | 276 if (GetWindow()->GetStatusBubble()) |
| 343 window_->GetStatusBubble()->Hide(); | 277 GetWindow()->GetStatusBubble()->Hide(); |
| 344 } | 278 } |
| 345 } | 279 } |
| 346 | 280 |
| 347 bool FullscreenController::HandleUserPressedEscape() { | 281 bool FullscreenController::HandleUserPressedEscape() { |
| 348 WebContents* const active_web_contents = | 282 WebContents* const active_web_contents = |
| 349 browser_->tab_strip_model()->GetActiveWebContents(); | 283 GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 350 if (IsFullscreenForCapturedTab(active_web_contents)) { | 284 if (IsFullscreenForCapturedTab(active_web_contents)) { |
| 351 RenderViewHost* const rvh = active_web_contents->GetRenderViewHost(); | 285 RenderViewHost* const rvh = active_web_contents->GetRenderViewHost(); |
| 352 if (rvh) | 286 if (rvh) |
| 353 rvh->ExitFullscreen(); | 287 rvh->ExitFullscreen(); |
| 354 return true; | 288 return true; |
| 355 } else if (IsWindowFullscreenForTabOrPending() || | 289 } else if (IsWindowFullscreenForTabOrPending()) { |
| 356 IsMouseLocked() || IsMouseLockRequested()) { | 290 ExitExclusiveAccessIfNecessary(); |
| 357 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 358 return true; | 291 return true; |
| 359 } | 292 } |
| 360 | 293 |
| 361 return false; | 294 return false; |
| 362 } | 295 } |
| 363 | 296 |
| 364 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { | 297 void FullscreenController::ExitExclusiveAccessToPreviousState() { |
| 365 if (IsWindowFullscreenForTabOrPending()) | 298 if (IsWindowFullscreenForTabOrPending()) |
| 366 ExitTabFullscreenOrMouseLockIfNecessary(); | 299 ToggleFullscreenModeForTab(GetExclusiveAccessTab(), false); |
| 367 else if (IsFullscreenForBrowser()) | 300 else if (IsFullscreenForBrowser()) |
| 368 ExitFullscreenModeInternal(); | 301 ExitFullscreenModeInternal(); |
| 369 } | 302 } |
| 370 | 303 |
| 371 void FullscreenController::OnAcceptFullscreenPermission() { | 304 bool FullscreenController::OnAcceptExclusiveAccessPermission() { |
| 372 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | 305 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessExitBubbleType(); |
| 373 bool mouse_lock = false; | |
| 374 bool fullscreen = false; | 306 bool fullscreen = false; |
| 375 exclusive_access_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | 307 exclusive_access_bubble::PermissionRequestedByType(bubble_type, &fullscreen, |
| 376 &mouse_lock); | 308 nullptr); |
| 377 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | 309 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); |
| 378 DCHECK(!(mouse_lock && IsMouseLocked())); | |
| 379 | 310 |
| 380 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 311 if (fullscreen && !tab_fullscreen_accepted_) { |
| 312 DCHECK(GetExclusiveAccessTab()); |
| 381 | 313 |
| 382 GURL url = GetFullscreenExitBubbleURL(); | 314 HostContentSettingsMap* settings_map = |
| 383 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); | 315 GetProfile()->GetHostContentSettingsMap(); |
| 384 | 316 |
| 385 if (mouse_lock && !IsMouseLocked()) { | 317 GURL url = GetExclusiveAccessBubbleURL(); |
| 386 DCHECK(IsMouseLockRequested()); | 318 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); |
| 387 // TODO(markusheintz): We should allow patterns for all possible URLs here. | 319 |
| 388 if (pattern.IsValid()) { | 320 if (pattern.IsValid()) { |
| 389 settings_map->SetContentSetting( | 321 settings_map->SetContentSetting( |
| 390 pattern, ContentSettingsPattern::Wildcard(), | 322 pattern, ContentSettingsPattern::Wildcard(), |
| 391 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | |
| 392 CONTENT_SETTING_ALLOW); | |
| 393 } | |
| 394 | |
| 395 if (mouse_lock_tab_ && | |
| 396 mouse_lock_tab_->GotResponseToLockMouseRequest(true)) { | |
| 397 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | |
| 398 } else { | |
| 399 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 400 SetMouseLockTab(NULL); | |
| 401 } | |
| 402 NotifyMouseLockChange(); | |
| 403 } | |
| 404 | |
| 405 if (fullscreen && !tab_fullscreen_accepted_) { | |
| 406 DCHECK(fullscreened_tab_); | |
| 407 if (pattern.IsValid()) { | |
| 408 settings_map->SetContentSetting( | |
| 409 pattern, ContentSettingsPattern::Wildcard(), | |
| 410 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), | 323 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), |
| 411 CONTENT_SETTING_ALLOW); | 324 CONTENT_SETTING_ALLOW); |
| 412 } | 325 } |
| 413 tab_fullscreen_accepted_ = true; | 326 tab_fullscreen_accepted_ = true; |
| 327 return true; |
| 414 } | 328 } |
| 415 UpdateFullscreenExitBubbleContent(); | 329 |
| 330 return false; |
| 416 } | 331 } |
| 417 | 332 |
| 418 void FullscreenController::OnDenyFullscreenPermission() { | 333 bool FullscreenController::OnDenyExclusiveAccessPermission() { |
| 419 if (!fullscreened_tab_ && !mouse_lock_tab_) | 334 if (IsWindowFullscreenForTabOrPending()) { |
| 420 return; | 335 ExitExclusiveAccessIfNecessary(); |
| 421 | 336 return true; |
| 422 if (IsMouseLockRequested()) { | |
| 423 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 424 if (mouse_lock_tab_) | |
| 425 mouse_lock_tab_->GotResponseToLockMouseRequest(false); | |
| 426 SetMouseLockTab(NULL); | |
| 427 NotifyMouseLockChange(); | |
| 428 | |
| 429 // UpdateFullscreenExitBubbleContent() must be called, but to avoid | |
| 430 // duplicate calls we do so only if not adjusting the fullscreen state | |
| 431 // below, which also calls UpdateFullscreenExitBubbleContent(). | |
| 432 if (!IsWindowFullscreenForTabOrPending()) | |
| 433 UpdateFullscreenExitBubbleContent(); | |
| 434 } | 337 } |
| 435 | 338 |
| 436 if (IsWindowFullscreenForTabOrPending()) | 339 return false; |
| 437 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 438 } | 340 } |
| 439 | 341 |
| 440 void FullscreenController::LostMouseLock() { | 342 GURL FullscreenController::GetURLForExclusiveAccessBubble() const { |
| 441 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 343 if (GetExclusiveAccessTab()) |
| 442 SetMouseLockTab(NULL); | 344 return GetExclusiveAccessTab()->GetURL(); |
| 443 NotifyMouseLockChange(); | |
| 444 UpdateFullscreenExitBubbleContent(); | |
| 445 } | |
| 446 | |
| 447 void FullscreenController::Observe(int type, | |
| 448 const content::NotificationSource& source, | |
| 449 const content::NotificationDetails& details) { | |
| 450 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | |
| 451 if (content::Details<content::LoadCommittedDetails>(details)-> | |
| 452 is_navigation_to_different_page()) | |
| 453 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 454 } | |
| 455 | |
| 456 GURL FullscreenController::GetFullscreenExitBubbleURL() const { | |
| 457 if (fullscreened_tab_) | |
| 458 return fullscreened_tab_->GetURL(); | |
| 459 if (mouse_lock_tab_) | |
| 460 return mouse_lock_tab_->GetURL(); | |
| 461 return extension_caused_fullscreen_; | 345 return extension_caused_fullscreen_; |
| 462 } | 346 } |
| 463 | 347 |
| 464 ExclusiveAccessBubbleType FullscreenController::GetExclusiveAccessBubbleType() | 348 void FullscreenController::ExitExclusiveAccessIfNecessary() { |
| 465 const { | 349 if (IsWindowFullscreenForTabOrPending()) |
| 466 // In kiosk and exclusive app mode we always want to be fullscreen and do not | 350 ToggleFullscreenModeForTab(GetExclusiveAccessTab(), false); |
| 467 // want to show exit instructions for browser mode fullscreen. | 351 else |
| 468 bool app_mode = false; | 352 NotifyTabOfExclusiveAccessChange(); |
| 469 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet. | |
| 470 app_mode = chrome::IsRunningInAppMode(); | |
| 471 #endif | |
| 472 | |
| 473 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) | |
| 474 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | |
| 475 | |
| 476 if (!fullscreened_tab_) { | |
| 477 if (IsMouseLocked()) | |
| 478 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION; | |
| 479 if (IsMouseLockRequested()) | |
| 480 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; | |
| 481 if (!extension_caused_fullscreen_.is_empty()) | |
| 482 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; | |
| 483 if (toggled_into_fullscreen_ && !app_mode) | |
| 484 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
| 485 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | |
| 486 } | |
| 487 | |
| 488 if (tab_fullscreen_accepted_) { | |
| 489 if (IsPrivilegedFullscreenForTab()) | |
| 490 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | |
| 491 if (IsMouseLocked()) | |
| 492 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | |
| 493 if (IsMouseLockRequested()) | |
| 494 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; | |
| 495 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | |
| 496 } | |
| 497 | |
| 498 if (IsMouseLockRequested()) | |
| 499 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; | |
| 500 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; | |
| 501 } | |
| 502 | |
| 503 void FullscreenController::UpdateNotificationRegistrations() { | |
| 504 if (fullscreened_tab_ && mouse_lock_tab_) | |
| 505 DCHECK(fullscreened_tab_ == mouse_lock_tab_); | |
| 506 | |
| 507 WebContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; | |
| 508 | |
| 509 if (tab && registrar_.IsEmpty()) { | |
| 510 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 511 content::Source<content::NavigationController>(&tab->GetController())); | |
| 512 } else if (!tab && !registrar_.IsEmpty()) { | |
| 513 registrar_.RemoveAll(); | |
| 514 } | |
| 515 } | 353 } |
| 516 | 354 |
| 517 void FullscreenController::PostFullscreenChangeNotification( | 355 void FullscreenController::PostFullscreenChangeNotification( |
| 518 bool is_fullscreen) { | 356 bool is_fullscreen) { |
| 519 base::MessageLoop::current()->PostTask( | 357 base::MessageLoop::current()->PostTask( |
| 520 FROM_HERE, | 358 FROM_HERE, |
| 521 base::Bind(&FullscreenController::NotifyFullscreenChange, | 359 base::Bind(&FullscreenController::NotifyFullscreenChange, |
| 522 ptr_factory_.GetWeakPtr(), | 360 ptr_factory_.GetWeakPtr(), |
| 523 is_fullscreen)); | 361 is_fullscreen)); |
| 524 } | 362 } |
| 525 | 363 |
| 526 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { | 364 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { |
| 527 content::NotificationService::current()->Notify( | 365 content::NotificationService::current()->Notify( |
| 528 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 366 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 529 content::Source<FullscreenController>(this), | 367 content::Source<FullscreenController>(this), |
| 530 content::Details<bool>(&is_fullscreen)); | 368 content::Details<bool>(&is_fullscreen)); |
| 531 } | 369 } |
| 532 | 370 |
| 533 void FullscreenController::NotifyTabOfExitIfNecessary() { | 371 void FullscreenController::NotifyTabOfExclusiveAccessChange() { |
| 534 if (fullscreened_tab_) { | 372 if (GetExclusiveAccessTab()) { |
| 535 RenderViewHost* rvh = fullscreened_tab_->GetRenderViewHost(); | 373 RenderViewHost* rvh = GetExclusiveAccessTab()->GetRenderViewHost(); |
| 536 SetFullscreenedTab(NULL); | 374 SetTabWithExclusiveAccess(nullptr); |
| 537 state_prior_to_tab_fullscreen_ = STATE_INVALID; | 375 state_prior_to_tab_fullscreen_ = STATE_INVALID; |
| 538 tab_fullscreen_accepted_ = false; | 376 tab_fullscreen_accepted_ = false; |
| 539 if (rvh) | 377 if (rvh) |
| 540 rvh->ExitFullscreen(); | 378 rvh->ExitFullscreen(); |
| 379 UpdateExclusiveAccessExitBubbleContent(); |
| 541 } | 380 } |
| 542 | |
| 543 if (mouse_lock_tab_) { | |
| 544 if (IsMouseLockRequested()) { | |
| 545 mouse_lock_tab_->GotResponseToLockMouseRequest(false); | |
| 546 NotifyMouseLockChange(); | |
| 547 } else { | |
| 548 UnlockMouse(); | |
| 549 } | |
| 550 SetMouseLockTab(NULL); | |
| 551 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 552 } | |
| 553 | |
| 554 UpdateFullscreenExitBubbleContent(); | |
| 555 } | |
| 556 | |
| 557 void FullscreenController::NotifyMouseLockChange() { | |
| 558 content::NotificationService::current()->Notify( | |
| 559 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, | |
| 560 content::Source<FullscreenController>(this), | |
| 561 content::NotificationService::NoDetails()); | |
| 562 } | 381 } |
| 563 | 382 |
| 564 void FullscreenController::ToggleFullscreenModeInternal( | 383 void FullscreenController::ToggleFullscreenModeInternal( |
| 565 FullscreenInternalOption option) { | 384 FullscreenInternalOption option) { |
| 566 #if defined(OS_WIN) | 385 #if defined(OS_WIN) |
| 567 // When in Metro snap mode, toggling in and out of fullscreen is prevented. | 386 // When in Metro snap mode, toggling in and out of fullscreen is prevented. |
| 568 if (IsInMetroSnapMode()) | 387 if (IsInMetroSnapMode()) |
| 569 return; | 388 return; |
| 570 #endif | 389 #endif |
| 571 | 390 |
| 572 bool enter_fullscreen = !window_->IsFullscreen(); | 391 bool enter_fullscreen = !GetWindow()->IsFullscreen(); |
| 573 | 392 |
| 574 // When a Mac user requests a toggle they may be toggling between | 393 // When a Mac user requests a toggle they may be toggling between |
| 575 // FullscreenWithoutChrome and FullscreenWithToolbar. | 394 // FullscreenWithoutChrome and FullscreenWithToolbar. |
| 576 if (window_->IsFullscreen() && | 395 if (GetWindow()->IsFullscreen() && !IsWindowFullscreenForTabOrPending() && |
| 577 !IsWindowFullscreenForTabOrPending() && | 396 GetWindow()->SupportsFullscreenWithToolbar()) { |
| 578 window_->SupportsFullscreenWithToolbar()) { | |
| 579 if (option == BROWSER_WITH_TOOLBAR) { | 397 if (option == BROWSER_WITH_TOOLBAR) { |
| 580 enter_fullscreen = | 398 enter_fullscreen = |
| 581 enter_fullscreen || !window_->IsFullscreenWithToolbar(); | 399 enter_fullscreen || !GetWindow()->IsFullscreenWithToolbar(); |
| 582 } else { | 400 } else { |
| 583 enter_fullscreen = enter_fullscreen || window_->IsFullscreenWithToolbar(); | 401 enter_fullscreen = |
| 402 enter_fullscreen || GetWindow()->IsFullscreenWithToolbar(); |
| 584 } | 403 } |
| 585 } | 404 } |
| 586 | 405 |
| 587 // In kiosk mode, we always want to be fullscreen. When the browser first | 406 // In kiosk mode, we always want to be fullscreen. When the browser first |
| 588 // starts we're not yet fullscreen, so let the initial toggle go through. | 407 // starts we're not yet fullscreen, so let the initial toggle go through. |
| 589 if (chrome::IsRunningInAppMode() && window_->IsFullscreen()) | 408 if (chrome::IsRunningInAppMode() && GetWindow()->IsFullscreen()) |
| 590 return; | 409 return; |
| 591 | 410 |
| 592 #if !defined(OS_MACOSX) | 411 #if !defined(OS_MACOSX) |
| 593 // Do not enter fullscreen mode if disallowed by pref. This prevents the user | 412 // Do not enter fullscreen mode if disallowed by pref. This prevents the user |
| 594 // from manually entering fullscreen mode and also disables kiosk mode on | 413 // from manually entering fullscreen mode and also disables kiosk mode on |
| 595 // desktop platforms. | 414 // desktop platforms. |
| 596 if (enter_fullscreen && | 415 if (enter_fullscreen && |
| 597 !profile_->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { | 416 !GetProfile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { |
| 598 return; | 417 return; |
| 599 } | 418 } |
| 600 #endif | 419 #endif |
| 601 | 420 |
| 602 if (enter_fullscreen) | 421 if (enter_fullscreen) |
| 603 EnterFullscreenModeInternal(option); | 422 EnterFullscreenModeInternal(option); |
| 604 else | 423 else |
| 605 ExitFullscreenModeInternal(); | 424 ExitFullscreenModeInternal(); |
| 606 } | 425 } |
| 607 | 426 |
| 608 void FullscreenController::EnterFullscreenModeInternal( | 427 void FullscreenController::EnterFullscreenModeInternal( |
| 609 FullscreenInternalOption option) { | 428 FullscreenInternalOption option) { |
| 610 toggled_into_fullscreen_ = true; | 429 toggled_into_fullscreen_ = true; |
| 611 GURL url; | 430 GURL url; |
| 612 if (option == TAB) { | 431 if (option == TAB) { |
| 613 url = browser_->tab_strip_model()->GetActiveWebContents()->GetURL(); | 432 url = GetBrowser()->tab_strip_model()->GetActiveWebContents()->GetURL(); |
| 614 tab_fullscreen_accepted_ = | 433 tab_fullscreen_accepted_ = |
| 615 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 434 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| 616 } else { | 435 } else { |
| 617 if (!extension_caused_fullscreen_.is_empty()) | 436 if (!extension_caused_fullscreen_.is_empty()) |
| 618 url = extension_caused_fullscreen_; | 437 url = extension_caused_fullscreen_; |
| 619 } | 438 } |
| 620 | 439 |
| 621 if (option == BROWSER) | 440 if (option == BROWSER) |
| 622 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 441 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
| 623 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions | 442 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions |
| 624 // from tab fullscreen out to browser with toolbar. | 443 // from tab fullscreen out to browser with toolbar. |
| 625 | 444 |
| 626 window_->EnterFullscreen(url, GetExclusiveAccessBubbleType(), | 445 GetWindow()->EnterFullscreen(url, GetExclusiveAccessExitBubbleType(), |
| 627 option == BROWSER_WITH_TOOLBAR); | 446 option == BROWSER_WITH_TOOLBAR); |
| 628 | 447 |
| 629 UpdateFullscreenExitBubbleContent(); | 448 UpdateExclusiveAccessExitBubbleContent(); |
| 630 | 449 |
| 631 // Once the window has become fullscreen it'll call back to | 450 // Once the window has become fullscreen it'll call back to |
| 632 // WindowFullscreenStateChanged(). We don't do this immediately as | 451 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 633 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 452 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| 634 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 453 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 635 } | 454 } |
| 636 | 455 |
| 637 void FullscreenController::ExitFullscreenModeInternal() { | 456 void FullscreenController::ExitFullscreenModeInternal() { |
| 638 toggled_into_fullscreen_ = false; | 457 toggled_into_fullscreen_ = false; |
| 639 #if defined(OS_MACOSX) | 458 #if defined(OS_MACOSX) |
| 640 // Mac windows report a state change instantly, and so we must also clear | 459 // Mac windows report a state change instantly, and so we must also clear |
| 641 // state_prior_to_tab_fullscreen_ to match them else other logic using | 460 // state_prior_to_tab_fullscreen_ to match them else other logic using |
| 642 // state_prior_to_tab_fullscreen_ will be incorrect. | 461 // state_prior_to_tab_fullscreen_ will be incorrect. |
| 643 NotifyTabOfExitIfNecessary(); | 462 NotifyTabOfExclusiveAccessChange(); |
| 644 #endif | 463 #endif |
| 645 window_->ExitFullscreen(); | 464 GetWindow()->ExitFullscreen(); |
| 646 extension_caused_fullscreen_ = GURL(); | 465 extension_caused_fullscreen_ = GURL(); |
| 647 | 466 |
| 648 UpdateFullscreenExitBubbleContent(); | 467 UpdateExclusiveAccessExitBubbleContent(); |
| 649 } | |
| 650 | |
| 651 void FullscreenController::SetFullscreenedTab(WebContents* tab) { | |
| 652 fullscreened_tab_ = tab; | |
| 653 UpdateNotificationRegistrations(); | |
| 654 } | |
| 655 | |
| 656 void FullscreenController::SetMouseLockTab(WebContents* tab) { | |
| 657 mouse_lock_tab_ = tab; | |
| 658 UpdateNotificationRegistrations(); | |
| 659 } | |
| 660 | |
| 661 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | |
| 662 if (IsWindowFullscreenForTabOrPending()) | |
| 663 ToggleFullscreenModeForTab(fullscreened_tab_, false); | |
| 664 else | |
| 665 NotifyTabOfExitIfNecessary(); | |
| 666 } | |
| 667 | |
| 668 void FullscreenController::UpdateFullscreenExitBubbleContent() { | |
| 669 GURL url = GetFullscreenExitBubbleURL(); | |
| 670 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); | |
| 671 | |
| 672 // If bubble displays buttons, unlock mouse to allow pressing them. | |
| 673 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) && | |
| 674 IsMouseLocked()) | |
| 675 UnlockMouse(); | |
| 676 | |
| 677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); | |
| 678 } | 468 } |
| 679 | 469 |
| 680 ContentSetting | 470 ContentSetting |
| 681 FullscreenController::GetFullscreenSetting(const GURL& url) const { | 471 FullscreenController::GetFullscreenSetting(const GURL& url) const { |
| 682 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | 472 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) |
| 683 return CONTENT_SETTING_ALLOW; | 473 return CONTENT_SETTING_ALLOW; |
| 684 | 474 |
| 685 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, | 475 return GetProfile()->GetHostContentSettingsMap()->GetContentSetting( |
| 686 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | 476 url, url, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); |
| 687 } | |
| 688 | |
| 689 ContentSetting | |
| 690 FullscreenController::GetMouseLockSetting(const GURL& url) const { | |
| 691 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | |
| 692 return CONTENT_SETTING_ALLOW; | |
| 693 | |
| 694 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | |
| 695 return settings_map->GetContentSetting(url, url, | |
| 696 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | |
| 697 } | 477 } |
| 698 | 478 |
| 699 bool FullscreenController::IsPrivilegedFullscreenForTab() const { | 479 bool FullscreenController::IsPrivilegedFullscreenForTab() const { |
| 700 const bool embedded_widget_present = | 480 const bool embedded_widget_present = |
| 701 fullscreened_tab_ && | 481 GetExclusiveAccessTab() && |
| 702 fullscreened_tab_->GetFullscreenRenderWidgetHostView(); | 482 GetExclusiveAccessTab()->GetFullscreenRenderWidgetHostView(); |
| 703 return embedded_widget_present || is_privileged_fullscreen_for_testing_; | 483 return embedded_widget_present || is_privileged_fullscreen_for_testing_; |
| 704 } | 484 } |
| 705 | 485 |
| 706 void FullscreenController::SetPrivilegedFullscreenForTesting( | 486 void FullscreenController::SetPrivilegedFullscreenForTesting( |
| 707 bool is_privileged) { | 487 bool is_privileged) { |
| 708 is_privileged_fullscreen_for_testing_ = is_privileged; | 488 is_privileged_fullscreen_for_testing_ = is_privileged; |
| 709 } | 489 } |
| 710 | 490 |
| 711 bool FullscreenController::MaybeToggleFullscreenForCapturedTab( | 491 bool FullscreenController::MaybeToggleFullscreenForCapturedTab( |
| 712 WebContents* web_contents, bool enter_fullscreen) { | 492 WebContents* web_contents, bool enter_fullscreen) { |
| 713 if (enter_fullscreen) { | 493 if (enter_fullscreen) { |
| 714 if (web_contents->GetCapturerCount() > 0) { | 494 if (web_contents->GetCapturerCount() > 0) { |
| 715 FullscreenWithinTabHelper::CreateForWebContents(web_contents); | 495 FullscreenWithinTabHelper::CreateForWebContents(web_contents); |
| 716 FullscreenWithinTabHelper::FromWebContents(web_contents)-> | 496 FullscreenWithinTabHelper::FromWebContents(web_contents)-> |
| 717 SetIsFullscreenForCapturedTab(true); | 497 SetIsFullscreenForCapturedTab(true); |
| 718 return true; | 498 return true; |
| 719 } | 499 } |
| 720 } else { | 500 } else { |
| 721 if (IsFullscreenForCapturedTab(web_contents)) { | 501 if (IsFullscreenForCapturedTab(web_contents)) { |
| 722 FullscreenWithinTabHelper::RemoveForWebContents(web_contents); | 502 FullscreenWithinTabHelper::RemoveForWebContents(web_contents); |
| 723 return true; | 503 return true; |
| 724 } | 504 } |
| 725 } | 505 } |
| 726 | 506 |
| 727 return false; | 507 return false; |
| 728 } | 508 } |
| 729 | 509 |
| 730 bool FullscreenController::IsFullscreenForCapturedTab( | 510 bool FullscreenController::IsFullscreenForCapturedTab( |
| 731 const WebContents* web_contents) const { | 511 const WebContents* web_contents) const { |
| 732 // Note: On Mac, some of the OnTabXXX() methods get called with a NULL value | 512 // Note: On Mac, some of the OnTabXXX() methods get called with a nullptr |
| 513 // value |
| 733 // for web_contents. Check for that here. | 514 // for web_contents. Check for that here. |
| 734 const FullscreenWithinTabHelper* const helper = web_contents ? | 515 const FullscreenWithinTabHelper* const helper = |
| 735 FullscreenWithinTabHelper::FromWebContents(web_contents) : NULL; | 516 web_contents ? FullscreenWithinTabHelper::FromWebContents(web_contents) |
| 517 : nullptr; |
| 736 if (helper && helper->is_fullscreen_for_captured_tab()) { | 518 if (helper && helper->is_fullscreen_for_captured_tab()) { |
| 737 DCHECK_NE(fullscreened_tab_, web_contents); | 519 DCHECK_NE(GetExclusiveAccessTab(), web_contents); |
| 738 return true; | 520 return true; |
| 739 } | 521 } |
| 740 return false; | 522 return false; |
| 741 } | 523 } |
| 742 | 524 |
| 743 void FullscreenController::UnlockMouse() { | |
| 744 if (!mouse_lock_tab_) | |
| 745 return; | |
| 746 content::RenderWidgetHostView* mouse_lock_view = | |
| 747 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? | |
| 748 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; | |
| 749 if (!mouse_lock_view) { | |
| 750 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); | |
| 751 if (rvh) | |
| 752 mouse_lock_view = rvh->GetView(); | |
| 753 } | |
| 754 if (mouse_lock_view) | |
| 755 mouse_lock_view->UnlockMouse(); | |
| 756 } | |
| OLD | NEW |