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, &fullscreen, |
376 &mouse_lock); | 376 &mouse_lock); |
377 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); | 377 DCHECK(!(fullscreen && tab_fullscreen_accepted_)); |
378 DCHECK(!(mouse_lock && IsMouseLocked())); | 378 DCHECK(!(mouse_lock && IsMouseLocked())); |
379 | 379 |
380 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 380 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
381 | 381 |
382 GURL url = GetFullscreenExitBubbleURL(); | 382 GURL url = GetFullscreenExitBubbleURL(); |
383 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); | 383 ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); |
384 | 384 |
385 if (mouse_lock && !IsMouseLocked()) { | 385 if (mouse_lock && !IsMouseLocked()) { |
386 DCHECK(IsMouseLockRequested()); | 386 DCHECK(IsMouseLockRequested()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 } | 454 } |
455 | 455 |
456 GURL FullscreenController::GetFullscreenExitBubbleURL() const { | 456 GURL FullscreenController::GetFullscreenExitBubbleURL() const { |
457 if (fullscreened_tab_) | 457 if (fullscreened_tab_) |
458 return fullscreened_tab_->GetURL(); | 458 return fullscreened_tab_->GetURL(); |
459 if (mouse_lock_tab_) | 459 if (mouse_lock_tab_) |
460 return mouse_lock_tab_->GetURL(); | 460 return mouse_lock_tab_->GetURL(); |
461 return extension_caused_fullscreen_; | 461 return extension_caused_fullscreen_; |
462 } | 462 } |
463 | 463 |
464 FullscreenExitBubbleType FullscreenController::GetFullscreenExitBubbleType() | 464 ExclusiveAccessBubbleType FullscreenController::GetExclusiveAccessBubbleType() |
465 const { | 465 const { |
466 // In kiosk and exclusive app mode we always want to be fullscreen and do not | 466 // 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. | 467 // want to show exit instructions for browser mode fullscreen. |
468 bool app_mode = false; | 468 bool app_mode = false; |
469 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet. | 469 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet. |
470 app_mode = chrome::IsRunningInAppMode(); | 470 app_mode = chrome::IsRunningInAppMode(); |
471 #endif | 471 #endif |
472 | 472 |
473 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) | 473 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY) |
474 return FEB_TYPE_NONE; | 474 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
475 | 475 |
476 if (!fullscreened_tab_) { | 476 if (!fullscreened_tab_) { |
477 if (IsMouseLocked()) | 477 if (IsMouseLocked()) |
478 return FEB_TYPE_MOUSELOCK_EXIT_INSTRUCTION; | 478 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION; |
479 if (IsMouseLockRequested()) | 479 if (IsMouseLockRequested()) |
480 return FEB_TYPE_MOUSELOCK_BUTTONS; | 480 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; |
481 if (!extension_caused_fullscreen_.is_empty()) | 481 if (!extension_caused_fullscreen_.is_empty()) |
482 return FEB_TYPE_BROWSER_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; | 482 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; |
483 if (toggled_into_fullscreen_ && !app_mode) | 483 if (toggled_into_fullscreen_ && !app_mode) |
484 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | 484 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; |
485 return FEB_TYPE_NONE; | 485 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
486 } | 486 } |
487 | 487 |
488 if (tab_fullscreen_accepted_) { | 488 if (tab_fullscreen_accepted_) { |
489 if (IsPrivilegedFullscreenForTab()) | 489 if (IsPrivilegedFullscreenForTab()) |
490 return FEB_TYPE_NONE; | 490 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
491 if (IsMouseLocked()) | 491 if (IsMouseLocked()) |
492 return FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | 492 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
493 if (IsMouseLockRequested()) | 493 if (IsMouseLockRequested()) |
494 return FEB_TYPE_MOUSELOCK_BUTTONS; | 494 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; |
495 return FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | 495 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
496 } | 496 } |
497 | 497 |
498 if (IsMouseLockRequested()) | 498 if (IsMouseLockRequested()) |
499 return FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; | 499 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; |
500 return FEB_TYPE_FULLSCREEN_BUTTONS; | 500 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; |
501 } | 501 } |
502 | 502 |
503 void FullscreenController::UpdateNotificationRegistrations() { | 503 void FullscreenController::UpdateNotificationRegistrations() { |
504 if (fullscreened_tab_ && mouse_lock_tab_) | 504 if (fullscreened_tab_ && mouse_lock_tab_) |
505 DCHECK(fullscreened_tab_ == mouse_lock_tab_); | 505 DCHECK(fullscreened_tab_ == mouse_lock_tab_); |
506 | 506 |
507 WebContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; | 507 WebContents* tab = fullscreened_tab_ ? fullscreened_tab_ : mouse_lock_tab_; |
508 | 508 |
509 if (tab && registrar_.IsEmpty()) { | 509 if (tab && registrar_.IsEmpty()) { |
510 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 510 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 } else { | 616 } else { |
617 if (!extension_caused_fullscreen_.is_empty()) | 617 if (!extension_caused_fullscreen_.is_empty()) |
618 url = extension_caused_fullscreen_; | 618 url = extension_caused_fullscreen_; |
619 } | 619 } |
620 | 620 |
621 if (option == BROWSER) | 621 if (option == BROWSER) |
622 content::RecordAction(UserMetricsAction("ToggleFullscreen")); | 622 content::RecordAction(UserMetricsAction("ToggleFullscreen")); |
623 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions | 623 // TODO(scheib): Record metrics for WITH_TOOLBAR, without counting transitions |
624 // from tab fullscreen out to browser with toolbar. | 624 // from tab fullscreen out to browser with toolbar. |
625 | 625 |
626 window_->EnterFullscreen(url, | 626 window_->EnterFullscreen(url, GetExclusiveAccessBubbleType(), |
627 GetFullscreenExitBubbleType(), | |
628 option == BROWSER_WITH_TOOLBAR); | 627 option == BROWSER_WITH_TOOLBAR); |
629 | 628 |
630 UpdateFullscreenExitBubbleContent(); | 629 UpdateFullscreenExitBubbleContent(); |
631 | 630 |
632 // Once the window has become fullscreen it'll call back to | 631 // Once the window has become fullscreen it'll call back to |
633 // WindowFullscreenStateChanged(). We don't do this immediately as | 632 // WindowFullscreenStateChanged(). We don't do this immediately as |
634 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 633 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
635 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 634 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
636 } | 635 } |
637 | 636 |
(...skipping 23 matching lines...) Expand all Loading... |
661 | 660 |
662 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { | 661 void FullscreenController::ExitTabFullscreenOrMouseLockIfNecessary() { |
663 if (IsWindowFullscreenForTabOrPending()) | 662 if (IsWindowFullscreenForTabOrPending()) |
664 ToggleFullscreenModeForTab(fullscreened_tab_, false); | 663 ToggleFullscreenModeForTab(fullscreened_tab_, false); |
665 else | 664 else |
666 NotifyTabOfExitIfNecessary(); | 665 NotifyTabOfExitIfNecessary(); |
667 } | 666 } |
668 | 667 |
669 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 668 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
670 GURL url = GetFullscreenExitBubbleURL(); | 669 GURL url = GetFullscreenExitBubbleURL(); |
671 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 670 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessBubbleType(); |
672 | 671 |
673 // If bubble displays buttons, unlock mouse to allow pressing them. | 672 // If bubble displays buttons, unlock mouse to allow pressing them. |
674 if (fullscreen_bubble::ShowButtonsForType(bubble_type) && IsMouseLocked()) | 673 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) && |
| 674 IsMouseLocked()) |
675 UnlockMouse(); | 675 UnlockMouse(); |
676 | 676 |
677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); | 677 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); |
678 } | 678 } |
679 | 679 |
680 ContentSetting | 680 ContentSetting |
681 FullscreenController::GetFullscreenSetting(const GURL& url) const { | 681 FullscreenController::GetFullscreenSetting(const GURL& url) const { |
682 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) | 682 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) |
683 return CONTENT_SETTING_ALLOW; | 683 return CONTENT_SETTING_ALLOW; |
684 | 684 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? | 747 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? |
748 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; | 748 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; |
749 if (!mouse_lock_view) { | 749 if (!mouse_lock_view) { |
750 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); | 750 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); |
751 if (rvh) | 751 if (rvh) |
752 mouse_lock_view = rvh->GetView(); | 752 mouse_lock_view = rvh->GetView(); |
753 } | 753 } |
754 if (mouse_lock_view) | 754 if (mouse_lock_view) |
755 mouse_lock_view->UnlockMouse(); | 755 mouse_lock_view->UnlockMouse(); |
756 } | 756 } |
OLD | NEW |