| 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/fullscreen_controller.h" | 5 #include "chrome/browser/ui/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.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return false; | 56 return false; |
| 57 DCHECK(tab == browser_->GetSelectedWebContents()); | 57 DCHECK(tab == browser_->GetSelectedWebContents()); |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool FullscreenController::IsMouseLockRequested() const { | 61 bool FullscreenController::IsMouseLockRequested() const { |
| 62 return mouse_lock_state_ == MOUSELOCK_REQUESTED; | 62 return mouse_lock_state_ == MOUSELOCK_REQUESTED; |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool FullscreenController::IsMouseLocked() const { | 65 bool FullscreenController::IsMouseLocked() const { |
| 66 return mouse_lock_state_ == MOUSELOCK_ACCEPTED; | 66 return mouse_lock_state_ == MOUSELOCK_ACCEPTED |
| 67 || mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; |
| 67 } | 68 } |
| 68 | 69 |
| 69 void FullscreenController::RequestToLockMouse(WebContents* tab, | 70 void FullscreenController::RequestToLockMouse( |
| 70 bool user_gesture) { | 71 content::WebContents* tab, |
| 72 content::MouseLockSource lock_source, |
| 73 content::MouseUnlockSource previous_unlock_source) { |
| 71 DCHECK(!IsMouseLocked()); | 74 DCHECK(!IsMouseLocked()); |
| 72 NotifyMouseLockChange(); | 75 NotifyMouseLockChange(); |
| 73 | 76 |
| 74 // Must have a user gesture, or we must already be in tab fullscreen. | 77 // Must have a user gesture to prevent misbehaving sites from constantly |
| 75 if (!user_gesture && !IsFullscreenForTabOrPending(tab)) { | 78 // re-locking the mouse. Exceptions are when the page has unlocked |
| 79 // (i.e. not the user), or if we're in tab fullscreen (user gesture required |
| 80 // for that) |
| 81 if (previous_unlock_source != content::TARGET && |
| 82 lock_source != content::USER_GESTURE && |
| 83 !IsFullscreenForTabOrPending(tab)) { |
| 76 tab->GotResponseToLockMouseRequest(false); | 84 tab->GotResponseToLockMouseRequest(false); |
| 77 return; | 85 return; |
| 78 } | 86 } |
| 79 | 87 |
| 80 mouse_lock_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); | 88 mouse_lock_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| 81 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 89 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); |
| 82 | 90 |
| 83 switch (GetMouseLockSetting(tab->GetURL())) { | 91 switch (GetMouseLockSetting(tab->GetURL())) { |
| 84 case CONTENT_SETTING_ALLOW: | 92 case CONTENT_SETTING_ALLOW: |
| 85 // If bubble already displaying buttons we must not lock the mouse yet, | 93 // If bubble already displaying buttons we must not lock the mouse yet, |
| 86 // or it would prevent pressing those buttons. Instead, merge the request. | 94 // or it would prevent pressing those buttons. Instead, merge the request. |
| 87 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { | 95 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { |
| 88 mouse_lock_state_ = MOUSELOCK_REQUESTED; | 96 mouse_lock_state_ = MOUSELOCK_REQUESTED; |
| 89 } else { | 97 } else { |
| 90 // Lock mouse. | 98 // Lock mouse. |
| 91 if (tab->GotResponseToLockMouseRequest(true)) { | 99 if (tab->GotResponseToLockMouseRequest(true)) { |
| 92 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 100 if (previous_unlock_source == content::TARGET) { |
| 101 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; |
| 102 } else { |
| 103 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| 104 } |
| 93 } else { | 105 } else { |
| 94 mouse_lock_tab_ = NULL; | 106 mouse_lock_tab_ = NULL; |
| 95 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 107 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 96 } | 108 } |
| 97 } | 109 } |
| 98 break; | 110 break; |
| 99 case CONTENT_SETTING_BLOCK: | 111 case CONTENT_SETTING_BLOCK: |
| 100 tab->GotResponseToLockMouseRequest(false); | 112 tab->GotResponseToLockMouseRequest(false); |
| 101 mouse_lock_tab_ = NULL; | 113 mouse_lock_tab_ = NULL; |
| 102 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 114 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 395 |
| 384 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() | 396 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() |
| 385 const { | 397 const { |
| 386 // In kiosk mode we always want to be fullscreen and do not want to show | 398 // In kiosk mode we always want to be fullscreen and do not want to show |
| 387 // exit instructions for browser mode fullscreen. | 399 // exit instructions for browser mode fullscreen. |
| 388 bool kiosk = false; | 400 bool kiosk = false; |
| 389 #if !defined(OS_MACOSX) // Kiosk mode not available on Mac. | 401 #if !defined(OS_MACOSX) // Kiosk mode not available on Mac. |
| 390 kiosk = CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); | 402 kiosk = CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); |
| 391 #endif | 403 #endif |
| 392 | 404 |
| 405 if(mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) { |
| 406 return FEB_TYPE_NONE; |
| 407 } |
| 408 |
| 393 if (fullscreened_tab_) { | 409 if (fullscreened_tab_) { |
| 394 if (tab_fullscreen_accepted_) { | 410 if (tab_fullscreen_accepted_) { |
| 395 if (IsMouseLocked()) { | 411 if (IsMouseLocked()) { |
| 396 return FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | 412 return FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
| 397 } else if (IsMouseLockRequested()) { | 413 } else if (IsMouseLockRequested()) { |
| 398 return FEB_TYPE_MOUSELOCK_BUTTONS; | 414 return FEB_TYPE_MOUSELOCK_BUTTONS; |
| 399 } else { | 415 } else { |
| 400 return FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | 416 return FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
| 401 } | 417 } |
| 402 } else { // Full screen not yet accepted. | 418 } else { // Full screen not yet accepted. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 window_->ExitFullscreen(); | 509 window_->ExitFullscreen(); |
| 494 extension_caused_fullscreen_ = GURL(); | 510 extension_caused_fullscreen_ = GURL(); |
| 495 } | 511 } |
| 496 UpdateFullscreenExitBubbleContent(); | 512 UpdateFullscreenExitBubbleContent(); |
| 497 | 513 |
| 498 // Once the window has become fullscreen it'll call back to | 514 // Once the window has become fullscreen it'll call back to |
| 499 // WindowFullscreenStateChanged(). We don't do this immediately as | 515 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 500 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 516 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| 501 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 517 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 502 } | 518 } |
| OLD | NEW |