| 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/fullscreen_controller.h" | 5 #include "chrome/browser/ui/fullscreen/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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // Must have a user gesture to prevent misbehaving sites from constantly | 226 // Must have a user gesture to prevent misbehaving sites from constantly |
| 227 // re-locking the mouse. Exceptions are when the page has unlocked | 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 | 228 // (i.e. not the user), or if we're in tab fullscreen (user gesture required |
| 229 // for that) | 229 // for that) |
| 230 if (!last_unlocked_by_target && !user_gesture && | 230 if (!last_unlocked_by_target && !user_gesture && |
| 231 !IsFullscreenForTabOrPending(web_contents)) { | 231 !IsFullscreenForTabOrPending(web_contents)) { |
| 232 web_contents->GotResponseToLockMouseRequest(false); | 232 web_contents->GotResponseToLockMouseRequest(false); |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 SetMouseLockTab(web_contents); | 235 SetMouseLockTab(web_contents); |
| 236 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 236 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); |
| 237 | 237 |
| 238 switch (GetMouseLockSetting(web_contents->GetURL())) { | 238 switch (GetMouseLockSetting(web_contents->GetURL())) { |
| 239 case CONTENT_SETTING_ALLOW: | 239 case CONTENT_SETTING_ALLOW: |
| 240 // If bubble already displaying buttons we must not lock the mouse yet, | 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. | 241 // or it would prevent pressing those buttons. Instead, merge the request. |
| 242 if (!IsPrivilegedFullscreenForTab() && | 242 if (!IsPrivilegedFullscreenForTab() && |
| 243 fullscreen_bubble::ShowButtonsForType(bubble_type)) { | 243 exclusive_access_bubble::ShowButtonsForType(bubble_type)) { |
| 244 mouse_lock_state_ = MOUSELOCK_REQUESTED; | 244 mouse_lock_state_ = MOUSELOCK_REQUESTED; |
| 245 } else { | 245 } else { |
| 246 // Lock mouse. | 246 // Lock mouse. |
| 247 if (web_contents->GotResponseToLockMouseRequest(true)) { | 247 if (web_contents->GotResponseToLockMouseRequest(true)) { |
| 248 if (last_unlocked_by_target) { | 248 if (last_unlocked_by_target) { |
| 249 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; | 249 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; |
| 250 } else { | 250 } else { |
| 251 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 251 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| 252 } | 252 } |
| 253 } else { | 253 } else { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 362 } |
| 363 | 363 |
| 364 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { | 364 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { |
| 365 if (IsWindowFullscreenForTabOrPending()) | 365 if (IsWindowFullscreenForTabOrPending()) |
| 366 ExitTabFullscreenOrMouseLockIfNecessary(); | 366 ExitTabFullscreenOrMouseLockIfNecessary(); |
| 367 else if (IsFullscreenForBrowser()) | 367 else if (IsFullscreenForBrowser()) |
| 368 ExitFullscreenModeInternal(); | 368 ExitFullscreenModeInternal(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void FullscreenController::OnAcceptFullscreenPermission() { | 371 void FullscreenController::OnAcceptFullscreenPermission() { |
| 372 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 372 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); |
| 373 bool mouse_lock = false; | 373 bool mouse_lock = false; |
| 374 bool fullscreen = false; | 374 bool fullscreen = false; |
| 375 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | 375 exclusive_access_bubble::PermissionRequestedByType(bubble_type, |
| 376 &mouse_lock); | 376 &fullscreen, |
| 377 &mouse_lock); |
| 377 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | 378 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); |
| 378 DCHECK(!(mouse_lock && IsMouseLocked())); | 379 DCHECK(!(mouse_lock && IsMouseLocked())); |
| 379 | 380 |
| 380 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 381 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
| 381 | 382 |
| 382 GURL url = GetFullscreenExitBubbleURL(); | 383 GURL url = GetFullscreenExitBubbleURL(); |
| 383 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); | 384 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); |
| 384 | 385 |
| 385 if (mouse_lock && !IsMouseLocked()) { | 386 if (mouse_lock && !IsMouseLocked()) { |
| 386 DCHECK(IsMouseLockRequested()); | 387 DCHECK(IsMouseLockRequested()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 455 } |
| 455 | 456 |
| 456 GURL FullscreenController::GetFullscreenExitBubbleURL() const { | 457 GURL FullscreenController::GetFullscreenExitBubbleURL() const { |
| 457 if (fullscreened_tab_) | 458 if (fullscreened_tab_) |
| 458 return fullscreened_tab_->GetURL(); | 459 return fullscreened_tab_->GetURL(); |
| 459 if (mouse_lock_tab_) | 460 if (mouse_lock_tab_) |
| 460 return mouse_lock_tab_->GetURL(); | 461 return mouse_lock_tab_->GetURL(); |
| 461 return extension_caused_fullscreen_; | 462 return extension_caused_fullscreen_; |
| 462 } | 463 } |
| 463 | 464 |
| 464 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() | 465 ExclusiveAccessBubbleType FullscreenController::GetExclusiveAccessBubbleType() |
| 465 const { | 466 const { |
| 466 // In kiosk and exclusive app mode we always want to be fullscreen and do not | 467 // In kiosk and exclusive app mode we always want to be fullscreen and do not |
| 467 // want to show exit instructions for browser mode fullscreen. | 468 // want to show exit instructions for browser mode fullscreen. |
| 468 bool app_mode = false; | 469 bool app_mode = false; |
| 469 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet. | 470 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet. |
| 470 app_mode = chrome::IsRunningInAppMode(); | 471 app_mode = chrome::IsRunningInAppMode(); |
| 471 #endif | 472 #endif |
| 472 | 473 |
| 473 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) | 474 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) |
| 474 return FEB_TYPE_NONE; | 475 return EAB_TYPE_NONE; |
| 475 | 476 |
| 476 if (!fullscreened_tab_) { | 477 if (!fullscreened_tab_) { |
| 477 if (IsMouseLocked()) | 478 if (IsMouseLocked()) |
| 478 return FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION; | 479 return EAB_TYPE_MOUSELOCK_EXIT_INSTRUCTION; |
| 479 if (IsMouseLockRequested()) | 480 if (IsMouseLockRequested()) |
| 480 return FEB_TYPE_MOUSELOCK_BUTTONS; | 481 return EAB_TYPE_MOUSELOCK_BUTTONS; |
| 481 if (!extension_caused_fullscreen_.is_empty()) | 482 if (!extension_caused_fullscreen_.is_empty()) |
| 482 return FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; | 483 return EAB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; |
| 483 if (toggled_into_fullscreen_ && !app_mode) | 484 if (toggled_into_fullscreen_ && !app_mode) |
| 484 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | 485 return EAB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; |
| 485 return FEB_TYPE_NONE; | 486 return EAB_TYPE_NONE; |
| 486 } | 487 } |
| 487 | 488 |
| 488 if (tab_fullscreen_accepted_) { | 489 if (tab_fullscreen_accepted_) { |
| 489 if (IsPrivilegedFullscreenForTab()) | 490 if (IsPrivilegedFullscreenForTab()) |
| 490 return FEB_TYPE_NONE; | 491 return EAB_TYPE_NONE; |
| 491 if (IsMouseLocked()) | 492 if (IsMouseLocked()) |
| 492 return FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | 493 return EAB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
| 493 if (IsMouseLockRequested()) | 494 if (IsMouseLockRequested()) |
| 494 return FEB_TYPE_MOUSELOCK_BUTTONS; | 495 return EAB_TYPE_MOUSELOCK_BUTTONS; |
| 495 return FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | 496 return EAB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
| 496 } | 497 } |
| 497 | 498 |
| 498 if (IsMouseLockRequested()) | 499 if (IsMouseLockRequested()) |
| 499 return FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; | 500 return EAB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; |
| 500 return FEB_TYPE_FULLSCREEN_BUTTONS; | 501 return EAB_TYPE_FULLSCREEN_BUTTONS; |
| 501 } | 502 } |
| 502 | 503 |
| 503 void FullscreenController::UpdateNotificationRegistrations() { | 504 void FullscreenController::UpdateNotificationRegistrations() { |
| 504 if (fullscreened_tab_ && mouse_lock_tab_) | 505 if (fullscreened_tab_ && mouse_lock_tab_) |
| 505 DCHECK(fullscreened_tab_ == mouse_lock_tab_); | 506 DCHECK(fullscreened_tab_ == mouse_lock_tab_); |
| 506 | 507 |
| 507 WebContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; | 508 WebContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; |
| 508 | 509 |
| 509 if (tab && registrar_.IsEmpty()) { | 510 if (tab && registrar_.IsEmpty()) { |
| 510 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 511 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 if (!extension_caused_fullscreen_.is_empty()) | 618 if (!extension_caused_fullscreen_.is_empty()) |
| 618 url = extension_caused_fullscreen_; | 619 url = extension_caused_fullscreen_; |
| 619 } | 620 } |
| 620 | 621 |
| 621 if (option == BROWSER) | 622 if (option == BROWSER) |
| 622 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 623 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
| 623 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions | 624 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions |
| 624 // from tab fullscreen out to browser with toolbar. | 625 // from tab fullscreen out to browser with toolbar. |
| 625 | 626 |
| 626 window_->EnterFullscreen(url, | 627 window_->EnterFullscreen(url, |
| 627 GetFullscreenExitBubbleType(), | 628 GetExclusiveAccessBubbleType(), |
| 628 option == BROWSER_WITH_TOOLBAR); | 629 option == BROWSER_WITH_TOOLBAR); |
| 629 | 630 |
| 630 UpdateFullscreenExitBubbleContent(); | 631 UpdateFullscreenExitBubbleContent(); |
| 631 | 632 |
| 632 // Once the window has become fullscreen it'll call back to | 633 // Once the window has become fullscreen it'll call back to |
| 633 // WindowFullscreenStateChanged(). We don't do this immediately as | 634 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 634 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 635 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| 635 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 636 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 636 } | 637 } |
| 637 | 638 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 661 | 662 |
| 662 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | 663 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { |
| 663 if (IsWindowFullscreenForTabOrPending()) | 664 if (IsWindowFullscreenForTabOrPending()) |
| 664 ToggleFullscreenModeForTab(fullscreened_tab_, false); | 665 ToggleFullscreenModeForTab(fullscreened_tab_, false); |
| 665 else | 666 else |
| 666 NotifyTabOfExitIfNecessary(); | 667 NotifyTabOfExitIfNecessary(); |
| 667 } | 668 } |
| 668 | 669 |
| 669 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 670 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
| 670 GURL url = GetFullscreenExitBubbleURL(); | 671 GURL url = GetFullscreenExitBubbleURL(); |
| 671 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 672 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); |
| 672 | 673 |
| 673 // If bubble displays buttons, unlock mouse to allow pressing them. | 674 // If bubble displays buttons, unlock mouse to allow pressing them. |
| 674 if (fullscreen_bubble::ShowButtonsForType(bubble_type) && IsMouseLocked()) | 675 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) |
| 676 && IsMouseLocked()) |
| 675 UnlockMouse(); | 677 UnlockMouse(); |
| 676 | 678 |
| 677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); | 679 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); |
| 678 } | 680 } |
| 679 | 681 |
| 680 ContentSetting | 682 ContentSetting |
| 681 FullscreenController::GetFullscreenSetting(const GURL& url) const { | 683 FullscreenController::GetFullscreenSetting(const GURL& url) const { |
| 682 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | 684 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) |
| 683 return CONTENT_SETTING_ALLOW; | 685 return CONTENT_SETTING_ALLOW; |
| 684 | 686 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? | 749 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? |
| 748 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; | 750 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; |
| 749 if (!mouse_lock_view) { | 751 if (!mouse_lock_view) { |
| 750 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); | 752 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); |
| 751 if (rvh) | 753 if (rvh) |
| 752 mouse_lock_view = rvh->GetView(); | 754 mouse_lock_view = rvh->GetView(); |
| 753 } | 755 } |
| 754 if (mouse_lock_view) | 756 if (mouse_lock_view) |
| 755 mouse_lock_view->UnlockMouse(); | 757 mouse_lock_view->UnlockMouse(); |
| 756 } | 758 } |
| OLD | NEW |