| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/fullscreen_controller.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/message_loop.h" | |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
| 11 #include "chrome/browser/download/download_shelf.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/browser_window.h" | |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 16 #include "chrome/common/chrome_notification_types.h" | |
| 17 #include "chrome/common/chrome_switches.h" | |
| 18 #include "chrome/common/extensions/extension.h" | |
| 19 #include "content/public/browser/navigation_details.h" | |
| 20 #include "content/public/browser/navigation_entry.h" | |
| 21 #include "content/public/browser/notification_service.h" | |
| 22 #include "content/public/browser/render_view_host.h" | |
| 23 #include "content/public/browser/render_widget_host_view.h" | |
| 24 #include "content/public/browser/user_metrics.h" | |
| 25 #include "content/public/browser/web_contents.h" | |
| 26 | |
| 27 using content::RenderViewHost; | |
| 28 using content::UserMetricsAction; | |
| 29 using content::WebContents; | |
| 30 | |
| 31 FullscreenController::FullscreenController(BrowserWindow* window, | |
| 32 Profile* profile, | |
| 33 Browser* browser) | |
| 34 : window_(window), | |
| 35 profile_(profile), | |
| 36 browser_(browser), | |
| 37 fullscreened_tab_(NULL), | |
| 38 tab_caused_fullscreen_(false), | |
| 39 tab_fullscreen_accepted_(false), | |
| 40 toggled_into_fullscreen_(false), | |
| 41 mouse_lock_tab_(NULL), | |
| 42 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { | |
| 43 } | |
| 44 | |
| 45 void FullscreenController::Observe(int type, | |
| 46 const content::NotificationSource& source, | |
| 47 const content::NotificationDetails& details) { | |
| 48 switch (type) { | |
| 49 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
| 50 if (content::Details<content::LoadCommittedDetails>(details)-> | |
| 51 is_navigation_to_different_page()) { | |
| 52 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 53 } | |
| 54 break; | |
| 55 | |
| 56 default: | |
| 57 NOTREACHED() << "Got a notification we didn't register for."; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 bool FullscreenController::IsFullscreenForBrowser() const { | |
| 62 return window_->IsFullscreen() && !tab_caused_fullscreen_; | |
| 63 } | |
| 64 | |
| 65 bool FullscreenController::IsFullscreenForTabOrPending() const { | |
| 66 return fullscreened_tab_ != NULL; | |
| 67 } | |
| 68 | |
| 69 bool FullscreenController::IsFullscreenForTabOrPending( | |
| 70 const WebContents* web_contents) const { | |
| 71 const TabContents* tab_contents = | |
| 72 TabContents::FromWebContents(web_contents); | |
| 73 if (!tab_contents || (tab_contents != fullscreened_tab_)) | |
| 74 return false; | |
| 75 DCHECK(web_contents == browser_->GetActiveWebContents()); | |
| 76 return true; | |
| 77 } | |
| 78 | |
| 79 #if defined(OS_WIN) | |
| 80 bool FullscreenController::IsInMetroSnapMode() { | |
| 81 return window_->IsInMetroSnapMode(); | |
| 82 } | |
| 83 #endif | |
| 84 | |
| 85 bool FullscreenController::IsMouseLockRequested() const { | |
| 86 return mouse_lock_state_ == MOUSELOCK_REQUESTED; | |
| 87 } | |
| 88 | |
| 89 bool FullscreenController::IsMouseLocked() const { | |
| 90 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || | |
| 91 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; | |
| 92 } | |
| 93 | |
| 94 void FullscreenController::RequestToLockMouse(WebContents* web_contents, | |
| 95 bool user_gesture, | |
| 96 bool last_unlocked_by_target) { | |
| 97 DCHECK(!IsMouseLocked()); | |
| 98 NotifyMouseLockChange(); | |
| 99 | |
| 100 // Check for command line switch disabling mouse lock when not tab fullscreen. | |
| 101 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 102 switches::kDisableNonFullscreenMouseLock) && | |
| 103 !IsFullscreenForTabOrPending(web_contents)) { | |
| 104 web_contents->GotResponseToLockMouseRequest(false); | |
| 105 return; | |
| 106 } | |
| 107 | |
| 108 // Must have a user gesture to prevent misbehaving sites from constantly | |
| 109 // re-locking the mouse. Exceptions are when the page has unlocked | |
| 110 // (i.e. not the user), or if we're in tab fullscreen (user gesture required | |
| 111 // for that) | |
| 112 if (!last_unlocked_by_target && !user_gesture && | |
| 113 !IsFullscreenForTabOrPending(web_contents)) { | |
| 114 web_contents->GotResponseToLockMouseRequest(false); | |
| 115 return; | |
| 116 } | |
| 117 SetMouseLockTab(TabContents::FromWebContents(web_contents)); | |
| 118 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | |
| 119 | |
| 120 switch (GetMouseLockSetting(web_contents->GetURL())) { | |
| 121 case CONTENT_SETTING_ALLOW: | |
| 122 // If bubble already displaying buttons we must not lock the mouse yet, | |
| 123 // or it would prevent pressing those buttons. Instead, merge the request. | |
| 124 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { | |
| 125 mouse_lock_state_ = MOUSELOCK_REQUESTED; | |
| 126 } else { | |
| 127 // Lock mouse. | |
| 128 if (web_contents->GotResponseToLockMouseRequest(true)) { | |
| 129 if (last_unlocked_by_target) { | |
| 130 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; | |
| 131 } else { | |
| 132 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | |
| 133 } | |
| 134 } else { | |
| 135 SetMouseLockTab(NULL); | |
| 136 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 137 } | |
| 138 } | |
| 139 break; | |
| 140 case CONTENT_SETTING_BLOCK: | |
| 141 web_contents->GotResponseToLockMouseRequest(false); | |
| 142 SetMouseLockTab(NULL); | |
| 143 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 144 break; | |
| 145 case CONTENT_SETTING_ASK: | |
| 146 mouse_lock_state_ = MOUSELOCK_REQUESTED; | |
| 147 break; | |
| 148 default: | |
| 149 NOTREACHED(); | |
| 150 } | |
| 151 UpdateFullscreenExitBubbleContent(); | |
| 152 } | |
| 153 | |
| 154 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, | |
| 155 bool enter_fullscreen) { | |
| 156 if (web_contents != browser_->GetActiveWebContents()) | |
| 157 return; | |
| 158 | |
| 159 #if defined(OS_WIN) | |
| 160 // For now, avoid breaking when initiating full screen tab mode while in | |
| 161 // a metro snap. | |
| 162 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | |
| 163 // modes with metro snap. | |
| 164 if (IsInMetroSnapMode()) | |
| 165 return; | |
| 166 #endif | |
| 167 | |
| 168 bool in_browser_or_tab_fullscreen_mode; | |
| 169 #if defined(OS_MACOSX) | |
| 170 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); | |
| 171 #else | |
| 172 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | |
| 173 #endif | |
| 174 | |
| 175 if (enter_fullscreen) { | |
| 176 SetFullscreenedTab(TabContents::FromWebContents(web_contents)); | |
| 177 if (!in_browser_or_tab_fullscreen_mode) { | |
| 178 tab_caused_fullscreen_ = true; | |
| 179 #if defined(OS_MACOSX) | |
| 180 TogglePresentationModeInternal(true); | |
| 181 #else | |
| 182 ToggleFullscreenModeInternal(true); | |
| 183 #endif | |
| 184 } else { | |
| 185 // We need to update the fullscreen exit bubble, e.g., going from browser | |
| 186 // fullscreen to tab fullscreen will need to show different content. | |
| 187 const GURL& url = web_contents->GetURL(); | |
| 188 if (!tab_fullscreen_accepted_) { | |
| 189 tab_fullscreen_accepted_ = | |
| 190 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
| 191 } | |
| 192 UpdateFullscreenExitBubbleContent(); | |
| 193 } | |
| 194 } else { | |
| 195 if (in_browser_or_tab_fullscreen_mode) { | |
| 196 if (tab_caused_fullscreen_) { | |
| 197 #if defined(OS_MACOSX) | |
| 198 TogglePresentationModeInternal(true); | |
| 199 #else | |
| 200 ToggleFullscreenModeInternal(true); | |
| 201 #endif | |
| 202 } else { | |
| 203 // If currently there is a tab in "tab fullscreen" mode and fullscreen | |
| 204 // was not caused by it (i.e., previously it was in "browser fullscreen" | |
| 205 // mode), we need to switch back to "browser fullscreen" mode. In this | |
| 206 // case, all we have to do is notifying the tab that it has exited "tab | |
| 207 // fullscreen" mode. | |
| 208 NotifyTabOfExitIfNecessary(); | |
| 209 } | |
| 210 } | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 #if defined(OS_WIN) | |
| 215 void FullscreenController::SetMetroSnapMode(bool enable) { | |
| 216 toggled_into_fullscreen_ = false; | |
| 217 window_->SetMetroSnapMode(enable); | |
| 218 } | |
| 219 #endif | |
| 220 | |
| 221 #if defined(OS_MACOSX) | |
| 222 void FullscreenController::TogglePresentationMode() { | |
| 223 TogglePresentationModeInternal(false); | |
| 224 } | |
| 225 #endif | |
| 226 | |
| 227 void FullscreenController::ToggleFullscreenMode() { | |
| 228 extension_caused_fullscreen_ = GURL(); | |
| 229 ToggleFullscreenModeInternal(false); | |
| 230 } | |
| 231 | |
| 232 void FullscreenController::ToggleFullscreenModeWithExtension( | |
| 233 const GURL& extension_url) { | |
| 234 // |extension_caused_fullscreen_| will be reset if this causes fullscreen to | |
| 235 // exit. | |
| 236 extension_caused_fullscreen_ = extension_url; | |
| 237 ToggleFullscreenModeInternal(false); | |
| 238 } | |
| 239 | |
| 240 void FullscreenController::LostMouseLock() { | |
| 241 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 242 SetMouseLockTab(NULL); | |
| 243 NotifyMouseLockChange(); | |
| 244 UpdateFullscreenExitBubbleContent(); | |
| 245 } | |
| 246 | |
| 247 void FullscreenController::OnTabClosing(WebContents* web_contents) { | |
| 248 const TabContents* contents = TabContents::FromWebContents(web_contents); | |
| 249 if (contents && | |
| 250 (contents == fullscreened_tab_ || contents == mouse_lock_tab_)) { | |
| 251 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 252 // The call to exit fullscreen may result in asynchronous notification of | |
| 253 // fullscreen state change (e.g., on Linux). We don't want to rely on it | |
| 254 // to call NotifyTabOfExitIfNecessary(), because at that point | |
| 255 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean | |
| 256 // up tab fullscreen related state. | |
| 257 NotifyTabOfExitIfNecessary(); | |
| 258 } | |
| 259 } | |
| 260 | |
| 261 void FullscreenController::OnTabDeactivated(TabContents* contents) { | |
| 262 if (contents && | |
| 263 (contents == fullscreened_tab_ || contents == mouse_lock_tab_)) | |
| 264 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 265 } | |
| 266 | |
| 267 void FullscreenController::OnAcceptFullscreenPermission( | |
| 268 const GURL& url, | |
| 269 FullscreenExitBubbleType bubble_type) { | |
| 270 bool mouse_lock = false; | |
| 271 bool fullscreen = false; | |
| 272 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
| 273 &mouse_lock); | |
| 274 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | |
| 275 DCHECK(!(mouse_lock && IsMouseLocked())); | |
| 276 | |
| 277 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | |
| 278 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); | |
| 279 | |
| 280 if (mouse_lock && !IsMouseLocked()) { | |
| 281 DCHECK(IsMouseLockRequested()); | |
| 282 // TODO(markusheintz): We should allow patterns for all possible URLs here. | |
| 283 if (pattern.IsValid()) { | |
| 284 settings_map->SetContentSetting( | |
| 285 pattern, ContentSettingsPattern::Wildcard(), | |
| 286 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), | |
| 287 CONTENT_SETTING_ALLOW); | |
| 288 } | |
| 289 | |
| 290 if (mouse_lock_tab_ && | |
| 291 mouse_lock_tab_->web_contents() && | |
| 292 mouse_lock_tab_->web_contents()->GotResponseToLockMouseRequest(true)) { | |
| 293 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | |
| 294 } else { | |
| 295 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 296 SetMouseLockTab(NULL); | |
| 297 } | |
| 298 NotifyMouseLockChange(); | |
| 299 } | |
| 300 | |
| 301 if (fullscreen && !tab_fullscreen_accepted_) { | |
| 302 DCHECK(fullscreened_tab_); | |
| 303 if (pattern.IsValid()) { | |
| 304 settings_map->SetContentSetting( | |
| 305 pattern, ContentSettingsPattern::Wildcard(), | |
| 306 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), | |
| 307 CONTENT_SETTING_ALLOW); | |
| 308 } | |
| 309 tab_fullscreen_accepted_ = true; | |
| 310 } | |
| 311 UpdateFullscreenExitBubbleContent(); | |
| 312 } | |
| 313 | |
| 314 void FullscreenController::OnDenyFullscreenPermission( | |
| 315 FullscreenExitBubbleType bubble_type) { | |
| 316 bool mouse_lock = false; | |
| 317 bool fullscreen = false; | |
| 318 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
| 319 &mouse_lock); | |
| 320 DCHECK(fullscreened_tab_ || mouse_lock_tab_); | |
| 321 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | |
| 322 DCHECK(!(mouse_lock && IsMouseLocked())); | |
| 323 | |
| 324 if (mouse_lock) { | |
| 325 DCHECK(IsMouseLockRequested()); | |
| 326 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 327 if (mouse_lock_tab_ && mouse_lock_tab_->web_contents()) | |
| 328 mouse_lock_tab_->web_contents()->GotResponseToLockMouseRequest(false); | |
| 329 SetMouseLockTab(NULL); | |
| 330 NotifyMouseLockChange(); | |
| 331 | |
| 332 // UpdateFullscreenExitBubbleContent() must be called, but to avoid | |
| 333 // duplicate calls we do so only if not adjusting the fullscreen state | |
| 334 // below, which also calls UpdateFullscreenExitBubbleContent(). | |
| 335 if (!fullscreen) | |
| 336 UpdateFullscreenExitBubbleContent(); | |
| 337 } | |
| 338 | |
| 339 if (fullscreen) | |
| 340 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 341 } | |
| 342 | |
| 343 void FullscreenController::WindowFullscreenStateChanged() { | |
| 344 bool exiting_fullscreen; | |
| 345 #if defined(OS_MACOSX) | |
| 346 exiting_fullscreen = !window_->InPresentationMode(); | |
| 347 #else | |
| 348 exiting_fullscreen = !window_->IsFullscreen(); | |
| 349 #endif | |
| 350 MessageLoop::current()->PostTask(FROM_HERE, | |
| 351 base::Bind(&FullscreenController::NotifyFullscreenChange, | |
| 352 this, !exiting_fullscreen)); | |
| 353 if (exiting_fullscreen) | |
| 354 NotifyTabOfExitIfNecessary(); | |
| 355 if (exiting_fullscreen) | |
| 356 window_->GetDownloadShelf()->Unhide(); | |
| 357 else | |
| 358 window_->GetDownloadShelf()->Hide(); | |
| 359 } | |
| 360 | |
| 361 bool FullscreenController::HandleUserPressedEscape() { | |
| 362 if (IsFullscreenForTabOrPending() || | |
| 363 IsMouseLocked() || IsMouseLockRequested()) { | |
| 364 ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 365 return true; | |
| 366 } | |
| 367 | |
| 368 return false; | |
| 369 } | |
| 370 | |
| 371 FullscreenController::~FullscreenController() {} | |
| 372 | |
| 373 void FullscreenController::NotifyTabOfExitIfNecessary() { | |
| 374 if (fullscreened_tab_) { | |
| 375 RenderViewHost* rvh = | |
| 376 fullscreened_tab_->web_contents()->GetRenderViewHost(); | |
| 377 SetFullscreenedTab(NULL); | |
| 378 tab_caused_fullscreen_ = false; | |
| 379 tab_fullscreen_accepted_ = false; | |
| 380 if (rvh) | |
| 381 rvh->ExitFullscreen(); | |
| 382 } | |
| 383 | |
| 384 if (mouse_lock_tab_) { | |
| 385 WebContents* web_contents = mouse_lock_tab_->web_contents(); | |
| 386 if (IsMouseLockRequested()) { | |
| 387 web_contents->GotResponseToLockMouseRequest(false); | |
| 388 NotifyMouseLockChange(); | |
| 389 } else if (web_contents->GetRenderViewHost() && | |
| 390 web_contents->GetRenderViewHost()->GetView()) { | |
| 391 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); | |
| 392 } | |
| 393 SetMouseLockTab(NULL); | |
| 394 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
| 395 } | |
| 396 | |
| 397 UpdateFullscreenExitBubbleContent(); | |
| 398 } | |
| 399 | |
| 400 void FullscreenController::UpdateNotificationRegistrations() { | |
| 401 if (fullscreened_tab_ && mouse_lock_tab_) | |
| 402 DCHECK(fullscreened_tab_ == mouse_lock_tab_); | |
| 403 | |
| 404 TabContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; | |
| 405 | |
| 406 if (tab && registrar_.IsEmpty()) { | |
| 407 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 408 content::Source<content::NavigationController>( | |
| 409 &tab->web_contents()->GetController())); | |
| 410 } else if (!tab && !registrar_.IsEmpty()) { | |
| 411 registrar_.RemoveAll(); | |
| 412 } | |
| 413 } | |
| 414 | |
| 415 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | |
| 416 if (tab_caused_fullscreen_) | |
| 417 ToggleFullscreenMode(); | |
| 418 else | |
| 419 NotifyTabOfExitIfNecessary(); | |
| 420 } | |
| 421 | |
| 422 void FullscreenController::UpdateFullscreenExitBubbleContent() { | |
| 423 GURL url; | |
| 424 if (fullscreened_tab_) | |
| 425 url = fullscreened_tab_->web_contents()->GetURL(); | |
| 426 else if (mouse_lock_tab_) | |
| 427 url = mouse_lock_tab_->web_contents()->GetURL(); | |
| 428 else if (!extension_caused_fullscreen_.is_empty()) | |
| 429 url = extension_caused_fullscreen_; | |
| 430 | |
| 431 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | |
| 432 | |
| 433 // If bubble displays buttons, unlock mouse to allow pressing them. | |
| 434 if (fullscreen_bubble::ShowButtonsForType(bubble_type) && | |
| 435 IsMouseLocked() && | |
| 436 mouse_lock_tab_->web_contents()) { | |
| 437 WebContents* web_contents = mouse_lock_tab_->web_contents(); | |
| 438 if (web_contents && web_contents->GetRenderViewHost() && | |
| 439 web_contents->GetRenderViewHost()->GetView()) | |
| 440 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); | |
| 441 } | |
| 442 | |
| 443 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); | |
| 444 } | |
| 445 | |
| 446 void FullscreenController::NotifyFullscreenChange(bool is_fullscreen) { | |
| 447 content::NotificationService::current()->Notify( | |
| 448 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 449 content::Source<FullscreenController>(this), | |
| 450 content::Details<bool>(&is_fullscreen)); | |
| 451 } | |
| 452 | |
| 453 void FullscreenController::NotifyMouseLockChange() { | |
| 454 content::NotificationService::current()->Notify( | |
| 455 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, | |
| 456 content::Source<FullscreenController>(this), | |
| 457 content::NotificationService::NoDetails()); | |
| 458 } | |
| 459 | |
| 460 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() | |
| 461 const { | |
| 462 // In kiosk mode we always want to be fullscreen and do not want to show | |
| 463 // exit instructions for browser mode fullscreen. | |
| 464 bool kiosk = false; | |
| 465 #if !defined(OS_MACOSX) // Kiosk mode not available on Mac. | |
| 466 kiosk = CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); | |
| 467 #endif | |
| 468 | |
| 469 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) { | |
| 470 return FEB_TYPE_NONE; | |
| 471 } | |
| 472 | |
| 473 if (fullscreened_tab_) { | |
| 474 if (tab_fullscreen_accepted_) { | |
| 475 if (IsMouseLocked()) { | |
| 476 return FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | |
| 477 } else if (IsMouseLockRequested()) { | |
| 478 return FEB_TYPE_MOUSELOCK_BUTTONS; | |
| 479 } else { | |
| 480 return FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | |
| 481 } | |
| 482 } else { // Full screen not yet accepted. | |
| 483 if (IsMouseLockRequested()) { | |
| 484 return FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; | |
| 485 } else { | |
| 486 return FEB_TYPE_FULLSCREEN_BUTTONS; | |
| 487 } | |
| 488 } | |
| 489 } else { // Not tab full screen. | |
| 490 if (IsMouseLocked()) { | |
| 491 return FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION; | |
| 492 } else if (IsMouseLockRequested()) { | |
| 493 return FEB_TYPE_MOUSELOCK_BUTTONS; | |
| 494 } else { | |
| 495 if (!extension_caused_fullscreen_.is_empty()) { | |
| 496 return FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; | |
| 497 } else if (toggled_into_fullscreen_ && !kiosk) { | |
| 498 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
| 499 } else { | |
| 500 return FEB_TYPE_NONE; | |
| 501 } | |
| 502 } | |
| 503 } | |
| 504 NOTREACHED(); | |
| 505 return FEB_TYPE_NONE; | |
| 506 } | |
| 507 | |
| 508 ContentSetting | |
| 509 FullscreenController::GetFullscreenSetting(const GURL& url) const { | |
| 510 if (url.SchemeIsFile()) | |
| 511 return CONTENT_SETTING_ALLOW; | |
| 512 | |
| 513 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, | |
| 514 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | |
| 515 } | |
| 516 | |
| 517 ContentSetting | |
| 518 FullscreenController::GetMouseLockSetting(const GURL& url) const { | |
| 519 if (url.SchemeIsFile()) | |
| 520 return CONTENT_SETTING_ALLOW; | |
| 521 | |
| 522 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | |
| 523 return settings_map->GetContentSetting(url, url, | |
| 524 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | |
| 525 } | |
| 526 | |
| 527 #if defined(OS_MACOSX) | |
| 528 void FullscreenController::TogglePresentationModeInternal(bool for_tab) { | |
| 529 toggled_into_fullscreen_ = !window_->InPresentationMode(); | |
| 530 GURL url; | |
| 531 if (for_tab) { | |
| 532 url = browser_->GetActiveWebContents()->GetURL(); | |
| 533 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && | |
| 534 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
| 535 } | |
| 536 if (toggled_into_fullscreen_) | |
| 537 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); | |
| 538 else | |
| 539 window_->ExitPresentationMode(); | |
| 540 UpdateFullscreenExitBubbleContent(); | |
| 541 | |
| 542 // WindowFullscreenStateChanged will be called by BrowserWindowController | |
| 543 // when the transition completes. | |
| 544 } | |
| 545 #endif | |
| 546 | |
| 547 // TODO(koz): Change |for_tab| to an enum. | |
| 548 void FullscreenController::ToggleFullscreenModeInternal(bool for_tab) { | |
| 549 #if defined(OS_WIN) | |
| 550 // When in Metro snap mode, toggling in and out of fullscreen is prevented. | |
| 551 if (IsInMetroSnapMode()) | |
| 552 return; | |
| 553 #endif | |
| 554 | |
| 555 toggled_into_fullscreen_ = !window_->IsFullscreen(); | |
| 556 | |
| 557 // In kiosk mode, we always want to be fullscreen. When the browser first | |
| 558 // starts we're not yet fullscreen, so let the initial toggle go through. | |
| 559 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | |
| 560 !toggled_into_fullscreen_) | |
| 561 return; | |
| 562 | |
| 563 GURL url; | |
| 564 if (for_tab) { | |
| 565 url = browser_->GetActiveWebContents()->GetURL(); | |
| 566 tab_fullscreen_accepted_ = toggled_into_fullscreen_ && | |
| 567 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
| 568 } else { | |
| 569 if (!extension_caused_fullscreen_.is_empty()) | |
| 570 url = extension_caused_fullscreen_; | |
| 571 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | |
| 572 } | |
| 573 if (toggled_into_fullscreen_) { | |
| 574 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); | |
| 575 } else { | |
| 576 window_->ExitFullscreen(); | |
| 577 extension_caused_fullscreen_ = GURL(); | |
| 578 } | |
| 579 UpdateFullscreenExitBubbleContent(); | |
| 580 | |
| 581 // Once the window has become fullscreen it'll call back to | |
| 582 // WindowFullscreenStateChanged(). We don't do this immediately as | |
| 583 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | |
| 584 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | |
| 585 } | |
| 586 | |
| 587 void FullscreenController::SetFullscreenedTab(TabContents* tab) { | |
| 588 fullscreened_tab_ = tab; | |
| 589 UpdateNotificationRegistrations(); | |
| 590 } | |
| 591 | |
| 592 void FullscreenController::SetMouseLockTab(TabContents* tab) { | |
| 593 mouse_lock_tab_ = tab; | |
| 594 UpdateNotificationRegistrations(); | |
| 595 } | |
| OLD | NEW |