| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 #if defined(OS_WIN) | 96 #if defined(OS_WIN) |
| 97 // For now, avoid breaking when initiating full screen tab mode while in | 97 // For now, avoid breaking when initiating full screen tab mode while in |
| 98 // a metro snap. | 98 // a metro snap. |
| 99 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen | 99 // TODO(robertshield): Find a way to reconcile tab-initiated fullscreen |
| 100 // modes with metro snap. | 100 // modes with metro snap. |
| 101 if (IsInMetroSnapMode()) | 101 if (IsInMetroSnapMode()) |
| 102 return; | 102 return; |
| 103 #endif | 103 #endif |
| 104 | 104 |
| 105 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | 105 bool in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); |
| 106 bool window_is_fullscreen_with_chrome = false; | |
| 107 #if defined(OS_MACOSX) | |
| 108 window_is_fullscreen_with_chrome = window_->IsFullscreenWithChrome(); | |
| 109 #endif | |
| 110 | 106 |
| 111 if (enter_fullscreen) { | 107 if (enter_fullscreen) { |
| 112 SetFullscreenedTab(web_contents); | 108 SetFullscreenedTab(web_contents); |
| 113 if (!in_browser_or_tab_fullscreen_mode) { | 109 if (!in_browser_or_tab_fullscreen_mode) { |
| 114 state_prior_to_tab_fullscreen_ = STATE_NORMAL; | 110 state_prior_to_tab_fullscreen_ = STATE_NORMAL; |
| 115 ToggleFullscreenModeInternal(TAB); | 111 ToggleFullscreenModeInternal(TAB); |
| 116 } else if (window_is_fullscreen_with_chrome) { | |
| 117 #if defined(OS_MACOSX) | 112 #if defined(OS_MACOSX) |
| 113 } else if (window_->IsFullscreenWithChrome()) { |
| 118 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_CHROME; | 114 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_WITH_CHROME; |
| 119 EnterFullscreenModeInternal(TAB); | 115 EnterFullscreenModeInternal(TAB); |
| 120 #else | |
| 121 NOTREACHED(); | |
| 122 #endif | 116 #endif |
| 123 } else { | 117 } else { |
| 124 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_CHROME; | 118 state_prior_to_tab_fullscreen_ = STATE_BROWSER_FULLSCREEN_NO_CHROME; |
| 125 | 119 |
| 126 // We need to update the fullscreen exit bubble, e.g., going from browser | 120 // We need to update the fullscreen exit bubble, e.g., going from browser |
| 127 // fullscreen to tab fullscreen will need to show different content. | 121 // fullscreen to tab fullscreen will need to show different content. |
| 128 const GURL& url = web_contents->GetURL(); | 122 const GURL& url = web_contents->GetURL(); |
| 129 if (!tab_fullscreen_accepted_) { | 123 if (!tab_fullscreen_accepted_) { |
| 130 tab_fullscreen_accepted_ = | 124 tab_fullscreen_accepted_ = |
| 131 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | 125 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 web_contents->GotResponseToLockMouseRequest(false); | 222 web_contents->GotResponseToLockMouseRequest(false); |
| 229 return; | 223 return; |
| 230 } | 224 } |
| 231 SetMouseLockTab(web_contents); | 225 SetMouseLockTab(web_contents); |
| 232 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 226 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); |
| 233 | 227 |
| 234 switch (GetMouseLockSetting(web_contents->GetURL())) { | 228 switch (GetMouseLockSetting(web_contents->GetURL())) { |
| 235 case CONTENT_SETTING_ALLOW: | 229 case CONTENT_SETTING_ALLOW: |
| 236 // If bubble already displaying buttons we must not lock the mouse yet, | 230 // If bubble already displaying buttons we must not lock the mouse yet, |
| 237 // or it would prevent pressing those buttons. Instead, merge the request. | 231 // or it would prevent pressing those buttons. Instead, merge the request. |
| 238 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { | 232 if (!IsPrivilegedFullscreenForTab() && |
| 233 fullscreen_bubble::ShowButtonsForType(bubble_type)) { |
| 239 mouse_lock_state_ = MOUSELOCK_REQUESTED; | 234 mouse_lock_state_ = MOUSELOCK_REQUESTED; |
| 240 } else { | 235 } else { |
| 241 // Lock mouse. | 236 // Lock mouse. |
| 242 if (web_contents->GotResponseToLockMouseRequest(true)) { | 237 if (web_contents->GotResponseToLockMouseRequest(true)) { |
| 243 if (last_unlocked_by_target) { | 238 if (last_unlocked_by_target) { |
| 244 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; | 239 mouse_lock_state_ = MOUSELOCK_ACCEPTED_SILENTLY; |
| 245 } else { | 240 } else { |
| 246 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | 241 mouse_lock_state_ = MOUSELOCK_ACCEPTED; |
| 247 } | 242 } |
| 248 } else { | 243 } else { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 state_prior_to_tab_fullscreen_ = STATE_INVALID; | 499 state_prior_to_tab_fullscreen_ = STATE_INVALID; |
| 505 tab_fullscreen_accepted_ = false; | 500 tab_fullscreen_accepted_ = false; |
| 506 if (rvh) | 501 if (rvh) |
| 507 rvh->ExitFullscreen(); | 502 rvh->ExitFullscreen(); |
| 508 } | 503 } |
| 509 | 504 |
| 510 if (mouse_lock_tab_) { | 505 if (mouse_lock_tab_) { |
| 511 if (IsMouseLockRequested()) { | 506 if (IsMouseLockRequested()) { |
| 512 mouse_lock_tab_->GotResponseToLockMouseRequest(false); | 507 mouse_lock_tab_->GotResponseToLockMouseRequest(false); |
| 513 NotifyMouseLockChange(); | 508 NotifyMouseLockChange(); |
| 514 } else if (mouse_lock_tab_->GetRenderViewHost() && | 509 } else { |
| 515 mouse_lock_tab_->GetRenderViewHost()->GetView()) { | 510 UnlockMouse(); |
| 516 mouse_lock_tab_->GetRenderViewHost()->GetView()->UnlockMouse(); | |
| 517 } | 511 } |
| 518 SetMouseLockTab(NULL); | 512 SetMouseLockTab(NULL); |
| 519 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 513 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
| 520 } | 514 } |
| 521 | 515 |
| 522 UpdateFullscreenExitBubbleContent(); | 516 UpdateFullscreenExitBubbleContent(); |
| 523 } | 517 } |
| 524 | 518 |
| 525 void FullscreenController::NotifyMouseLockChange() { | 519 void FullscreenController::NotifyMouseLockChange() { |
| 526 content::NotificationService::current()->Notify( | 520 content::NotificationService::current()->Notify( |
| 527 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, | 521 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 528 content::Source<FullscreenController>(this), | 522 content::Source<FullscreenController>(this), |
| 529 content::NotificationService::NoDetails()); | 523 content::NotificationService::NoDetails()); |
| 530 } | 524 } |
| 531 | 525 |
| 532 // TODO(koz): Change |for_tab| to an enum. | |
| 533 void FullscreenController::ToggleFullscreenModeInternal( | 526 void FullscreenController::ToggleFullscreenModeInternal( |
| 534 FullscreenInternalOption option) { | 527 FullscreenInternalOption option) { |
| 535 #if defined(OS_WIN) | 528 #if defined(OS_WIN) |
| 536 // When in Metro snap mode, toggling in and out of fullscreen is prevented. | 529 // When in Metro snap mode, toggling in and out of fullscreen is prevented. |
| 537 if (IsInMetroSnapMode()) | 530 if (IsInMetroSnapMode()) |
| 538 return; | 531 return; |
| 539 #endif | 532 #endif |
| 540 | 533 |
| 541 bool enter_fullscreen = !window_->IsFullscreen(); | 534 bool enter_fullscreen = !window_->IsFullscreen(); |
| 542 #if defined(OS_MACOSX) | 535 #if defined(OS_MACOSX) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 ToggleFullscreenModeForTab(fullscreened_tab_, false); | 630 ToggleFullscreenModeForTab(fullscreened_tab_, false); |
| 638 else | 631 else |
| 639 NotifyTabOfExitIfNecessary(); | 632 NotifyTabOfExitIfNecessary(); |
| 640 } | 633 } |
| 641 | 634 |
| 642 void FullscreenController::UpdateFullscreenExitBubbleContent() { | 635 void FullscreenController::UpdateFullscreenExitBubbleContent() { |
| 643 GURL url = GetFullscreenExitBubbleURL(); | 636 GURL url = GetFullscreenExitBubbleURL(); |
| 644 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); | 637 FullscreenExitBubbleType bubble_type = GetFullscreenExitBubbleType(); |
| 645 | 638 |
| 646 // If bubble displays buttons, unlock mouse to allow pressing them. | 639 // If bubble displays buttons, unlock mouse to allow pressing them. |
| 647 if (fullscreen_bubble::ShowButtonsForType(bubble_type) && | 640 if (fullscreen_bubble::ShowButtonsForType(bubble_type) && IsMouseLocked()) |
| 648 IsMouseLocked() && | 641 UnlockMouse(); |
| 649 mouse_lock_tab_ && | |
| 650 mouse_lock_tab_->GetRenderViewHost() && | |
| 651 mouse_lock_tab_->GetRenderViewHost()->GetView()) { | |
| 652 mouse_lock_tab_->GetRenderViewHost()->GetView()->UnlockMouse(); | |
| 653 } | |
| 654 | 642 |
| 655 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); | 643 window_->UpdateFullscreenExitBubbleContent(url, bubble_type); |
| 656 } | 644 } |
| 657 | 645 |
| 658 ContentSetting | 646 ContentSetting |
| 659 FullscreenController::GetFullscreenSetting(const GURL& url) const { | 647 FullscreenController::GetFullscreenSetting(const GURL& url) const { |
| 660 if (url.SchemeIsFile()) | 648 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) |
| 661 return CONTENT_SETTING_ALLOW; | 649 return CONTENT_SETTING_ALLOW; |
| 662 | 650 |
| 663 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, | 651 return profile_->GetHostContentSettingsMap()->GetContentSetting(url, url, |
| 664 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | 652 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); |
| 665 } | 653 } |
| 666 | 654 |
| 667 ContentSetting | 655 ContentSetting |
| 668 FullscreenController::GetMouseLockSetting(const GURL& url) const { | 656 FullscreenController::GetMouseLockSetting(const GURL& url) const { |
| 669 if (url.SchemeIsFile()) | 657 if (IsPrivilegedFullscreenForTab() || url.SchemeIsFile()) |
| 670 return CONTENT_SETTING_ALLOW; | 658 return CONTENT_SETTING_ALLOW; |
| 671 | 659 |
| 672 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 660 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
| 673 return settings_map->GetContentSetting(url, url, | 661 return settings_map->GetContentSetting(url, url, |
| 674 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | 662 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
| 675 } | 663 } |
| 664 |
| 665 bool FullscreenController::IsPrivilegedFullscreenForTab() const { |
| 666 return fullscreened_tab_ && |
| 667 fullscreened_tab_->GetFullscreenRenderWidgetHostView() && |
| 668 implicit_cast<const content::WebContentsDelegate*>(browser_)-> |
| 669 EmbedsFullscreenWidget(); |
| 670 } |
| 671 |
| 672 void FullscreenController::UnlockMouse() { |
| 673 if (!mouse_lock_tab_) |
| 674 return; |
| 675 content::RenderWidgetHostView* mouse_lock_view = |
| 676 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? |
| 677 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; |
| 678 if (!mouse_lock_view) { |
| 679 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); |
| 680 if (rvh) |
| 681 mouse_lock_view = rvh->GetView(); |
| 682 } |
| 683 if (mouse_lock_view) |
| 684 mouse_lock_view->UnlockMouse(); |
| 685 } |
| OLD | NEW |