| 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" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/download/download_shelf.h" | 13 #include "chrome/browser/download/download_shelf.h" |
| 14 #include "chrome/browser/fullscreen.h" | 14 #include "chrome/browser/fullscreen.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/status_bubble.h" | 18 #include "chrome/browser/ui/status_bubble.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
| 22 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
| 26 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_view.h" |
| 28 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 29 | 30 |
| 30 #if defined(OS_MACOSX) | 31 #if defined(OS_MACOSX) |
| 31 #include "base/mac/mac_util.h" | 32 #include "base/mac/mac_util.h" |
| 32 #else | 33 #else |
| 33 #include "base/prefs/pref_service.h" | 34 #include "base/prefs/pref_service.h" |
| 34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 using base::UserMetricsAction; | 38 using base::UserMetricsAction; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 66 extension_caused_fullscreen_ = GURL(); | 67 extension_caused_fullscreen_ = GURL(); |
| 67 ToggleFullscreenModeInternal(BROWSER); | 68 ToggleFullscreenModeInternal(BROWSER); |
| 68 } | 69 } |
| 69 | 70 |
| 70 bool FullscreenController::IsFullscreenForTabOrPending() const { | 71 bool FullscreenController::IsFullscreenForTabOrPending() const { |
| 71 return fullscreened_tab_ != NULL; | 72 return fullscreened_tab_ != NULL; |
| 72 } | 73 } |
| 73 | 74 |
| 74 bool FullscreenController::IsFullscreenForTabOrPending( | 75 bool FullscreenController::IsFullscreenForTabOrPending( |
| 75 const WebContents* web_contents) const { | 76 const WebContents* web_contents) const { |
| 76 if (web_contents != fullscreened_tab_) | 77 if (web_contents == fullscreened_tab_) { |
| 77 return false; | 78 DCHECK(web_contents == browser_->tab_strip_model()->GetActiveWebContents()); |
| 78 DCHECK(web_contents == browser_->tab_strip_model()->GetActiveWebContents()); | 79 return true; |
| 79 return true; | 80 } |
| 81 return IsFullscreenForCapturedTab(web_contents); |
| 80 } | 82 } |
| 81 | 83 |
| 82 bool FullscreenController::IsFullscreenCausedByTab() const { | 84 bool FullscreenController::IsFullscreenCausedByTab() const { |
| 83 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; | 85 return state_prior_to_tab_fullscreen_ == STATE_NORMAL; |
| 84 } | 86 } |
| 85 | 87 |
| 86 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, | 88 void FullscreenController::ToggleFullscreenModeForTab(WebContents* web_contents, |
| 87 bool enter_fullscreen) { | 89 bool enter_fullscreen) { |
| 90 if (MaybeToggleFullscreenForCapturedTab(web_contents, enter_fullscreen)) { |
| 91 // During tab capture of fullscreen-within-tab views, the browser window |
| 92 // fullscreen state is unchanged, so return now. |
| 93 return; |
| 94 } |
| 88 if (fullscreened_tab_) { | 95 if (fullscreened_tab_) { |
| 89 if (web_contents != fullscreened_tab_) | 96 if (web_contents != fullscreened_tab_) |
| 90 return; | 97 return; |
| 91 } else if ( | 98 } else if ( |
| 92 web_contents != browser_->tab_strip_model()->GetActiveWebContents()) { | 99 web_contents != browser_->tab_strip_model()->GetActiveWebContents()) { |
| 93 return; | 100 return; |
| 94 } | 101 } |
| 95 if (IsFullscreenForTabOrPending() == enter_fullscreen) | 102 if (IsFullscreenForTabOrPending() == enter_fullscreen) |
| 96 return; | 103 return; |
| 97 | 104 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 NOTREACHED(); | 273 NOTREACHED(); |
| 267 } | 274 } |
| 268 UpdateFullscreenExitBubbleContent(); | 275 UpdateFullscreenExitBubbleContent(); |
| 269 } | 276 } |
| 270 | 277 |
| 271 void FullscreenController::OnTabDeactivated(WebContents* web_contents) { | 278 void FullscreenController::OnTabDeactivated(WebContents* web_contents) { |
| 272 if (web_contents == fullscreened_tab_ || web_contents == mouse_lock_tab_) | 279 if (web_contents == fullscreened_tab_ || web_contents == mouse_lock_tab_) |
| 273 ExitTabFullscreenOrMouseLockIfNecessary(); | 280 ExitTabFullscreenOrMouseLockIfNecessary(); |
| 274 } | 281 } |
| 275 | 282 |
| 283 void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { |
| 284 if (!IsFullscreenForCapturedTab(old_contents)) |
| 285 return; |
| 286 |
| 287 // A fullscreen-within-tab view undergoing screen capture has been detached |
| 288 // and is no longer visible to the user. Set it to exactly the WebContents' |
| 289 // preferred size. See 'FullscreenWithinTab Note'. |
| 290 // |
| 291 // When the user later selects the tab to show |old_contents| again, UI code |
| 292 // elsewhere (e.g., views::WebView) will resize the view to fit within the |
| 293 // browser window once again. |
| 294 if (old_contents->GetCapturerCount() == 0 || |
| 295 old_contents->GetPreferredSize().IsEmpty()) { |
| 296 // Do nothing if tab capture ended after toggling fullscreen, or a preferred |
| 297 // size was never specified by the capturer. |
| 298 return; |
| 299 } |
| 300 content::RenderWidgetHostView* const current_fs_view = |
| 301 old_contents->GetFullscreenRenderWidgetHostView(); |
| 302 if (current_fs_view) |
| 303 current_fs_view->SetSize(old_contents->GetPreferredSize()); |
| 304 old_contents->GetView()->SizeContents(old_contents->GetPreferredSize()); |
| 305 } |
| 306 |
| 276 void FullscreenController::OnTabClosing(WebContents* web_contents) { | 307 void FullscreenController::OnTabClosing(WebContents* web_contents) { |
| 277 if (web_contents == fullscreened_tab_ || web_contents == mouse_lock_tab_) { | 308 if (IsFullscreenForCapturedTab(web_contents)) { |
| 309 RenderViewHost* const rvh = web_contents->GetRenderViewHost(); |
| 310 if (rvh) |
| 311 rvh->ExitFullscreen(); |
| 312 } else if (web_contents == fullscreened_tab_ || |
| 313 web_contents == mouse_lock_tab_) { |
| 278 ExitTabFullscreenOrMouseLockIfNecessary(); | 314 ExitTabFullscreenOrMouseLockIfNecessary(); |
| 279 // The call to exit fullscreen may result in asynchronous notification of | 315 // The call to exit fullscreen may result in asynchronous notification of |
| 280 // fullscreen state change (e.g., on Linux). We don't want to rely on it | 316 // fullscreen state change (e.g., on Linux). We don't want to rely on it |
| 281 // to call NotifyTabOfExitIfNecessary(), because at that point | 317 // to call NotifyTabOfExitIfNecessary(), because at that point |
| 282 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean | 318 // |fullscreened_tab_| may not be valid. Instead, we call it here to clean |
| 283 // up tab fullscreen related state. | 319 // up tab fullscreen related state. |
| 284 NotifyTabOfExitIfNecessary(); | 320 NotifyTabOfExitIfNecessary(); |
| 285 } | 321 } |
| 286 } | 322 } |
| 287 | 323 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 299 if (exiting_fullscreen) { | 335 if (exiting_fullscreen) { |
| 300 window_->GetDownloadShelf()->Unhide(); | 336 window_->GetDownloadShelf()->Unhide(); |
| 301 } else { | 337 } else { |
| 302 window_->GetDownloadShelf()->Hide(); | 338 window_->GetDownloadShelf()->Hide(); |
| 303 if (window_->GetStatusBubble()) | 339 if (window_->GetStatusBubble()) |
| 304 window_->GetStatusBubble()->Hide(); | 340 window_->GetStatusBubble()->Hide(); |
| 305 } | 341 } |
| 306 } | 342 } |
| 307 | 343 |
| 308 bool FullscreenController::HandleUserPressedEscape() { | 344 bool FullscreenController::HandleUserPressedEscape() { |
| 309 if (IsFullscreenForTabOrPending() || | 345 WebContents* const active_web_contents = |
| 310 IsMouseLocked() || IsMouseLockRequested()) { | 346 browser_->tab_strip_model()->GetActiveWebContents(); |
| 347 if (IsFullscreenForCapturedTab(active_web_contents)) { |
| 348 RenderViewHost* const rvh = active_web_contents->GetRenderViewHost(); |
| 349 if (rvh) |
| 350 rvh->ExitFullscreen(); |
| 351 return true; |
| 352 } else if (IsFullscreenForTabOrPending() || |
| 353 IsMouseLocked() || IsMouseLockRequested()) { |
| 311 ExitTabFullscreenOrMouseLockIfNecessary(); | 354 ExitTabFullscreenOrMouseLockIfNecessary(); |
| 312 return true; | 355 return true; |
| 313 } | 356 } |
| 314 | 357 |
| 315 return false; | 358 return false; |
| 316 } | 359 } |
| 317 | 360 |
| 318 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { | 361 void FullscreenController::ExitTabOrBrowserFullscreenToPreviousState() { |
| 319 if (IsFullscreenForTabOrPending()) | 362 if (IsFullscreenForTabOrPending()) |
| 320 ExitTabFullscreenOrMouseLockIfNecessary(); | 363 ExitTabFullscreenOrMouseLockIfNecessary(); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 715 |
| 673 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); | 716 HostContentSettingsMap* settings_map = profile_->GetHostContentSettingsMap(); |
| 674 return settings_map->GetContentSetting(url, url, | 717 return settings_map->GetContentSetting(url, url, |
| 675 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | 718 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); |
| 676 } | 719 } |
| 677 | 720 |
| 678 bool FullscreenController::IsPrivilegedFullscreenForTab() const { | 721 bool FullscreenController::IsPrivilegedFullscreenForTab() const { |
| 679 const bool embedded_widget_present = | 722 const bool embedded_widget_present = |
| 680 fullscreened_tab_ && | 723 fullscreened_tab_ && |
| 681 fullscreened_tab_->GetFullscreenRenderWidgetHostView() && | 724 fullscreened_tab_->GetFullscreenRenderWidgetHostView() && |
| 682 implicit_cast<const content::WebContentsDelegate*>(browser_)-> | 725 IsFullscreenWithinTabPossible(); |
| 683 EmbedsFullscreenWidget(); | |
| 684 return embedded_widget_present || is_privileged_fullscreen_for_testing_; | 726 return embedded_widget_present || is_privileged_fullscreen_for_testing_; |
| 685 } | 727 } |
| 686 | 728 |
| 687 void FullscreenController::SetPrivilegedFullscreenForTesting( | 729 void FullscreenController::SetPrivilegedFullscreenForTesting( |
| 688 bool is_privileged) { | 730 bool is_privileged) { |
| 689 is_privileged_fullscreen_for_testing_ = is_privileged; | 731 is_privileged_fullscreen_for_testing_ = is_privileged; |
| 690 } | 732 } |
| 691 | 733 |
| 734 bool FullscreenController::IsFullscreenWithinTabPossible() const { |
| 735 return implicit_cast<const content::WebContentsDelegate*>(browser_)-> |
| 736 EmbedsFullscreenWidget(); |
| 737 } |
| 738 |
| 739 bool FullscreenController::MaybeToggleFullscreenForCapturedTab( |
| 740 WebContents* web_contents, bool enter_fullscreen) { |
| 741 if (!IsFullscreenWithinTabPossible()) |
| 742 return false; |
| 743 |
| 744 if (enter_fullscreen) { |
| 745 if (web_contents->GetCapturerCount() > 0) { |
| 746 captured_tabs_.insert(web_contents); |
| 747 return true; |
| 748 } |
| 749 } else { |
| 750 const std::set<const WebContents*>::iterator it = |
| 751 captured_tabs_.find(web_contents); |
| 752 if (it != captured_tabs_.end()) { |
| 753 captured_tabs_.erase(it); |
| 754 return true; |
| 755 } |
| 756 } |
| 757 |
| 758 return false; |
| 759 } |
| 760 |
| 761 bool FullscreenController::IsFullscreenForCapturedTab( |
| 762 const WebContents* web_contents) const { |
| 763 if (captured_tabs_.find(web_contents) != captured_tabs_.end()) { |
| 764 DCHECK(IsFullscreenWithinTabPossible()); |
| 765 DCHECK_NE(fullscreened_tab_, web_contents); |
| 766 return true; |
| 767 } |
| 768 return false; |
| 769 } |
| 770 |
| 692 void FullscreenController::UnlockMouse() { | 771 void FullscreenController::UnlockMouse() { |
| 693 if (!mouse_lock_tab_) | 772 if (!mouse_lock_tab_) |
| 694 return; | 773 return; |
| 695 content::RenderWidgetHostView* mouse_lock_view = | 774 content::RenderWidgetHostView* mouse_lock_view = |
| 696 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? | 775 (fullscreened_tab_ == mouse_lock_tab_ && IsPrivilegedFullscreenForTab()) ? |
| 697 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; | 776 mouse_lock_tab_->GetFullscreenRenderWidgetHostView() : NULL; |
| 698 if (!mouse_lock_view) { | 777 if (!mouse_lock_view) { |
| 699 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); | 778 RenderViewHost* const rvh = mouse_lock_tab_->GetRenderViewHost(); |
| 700 if (rvh) | 779 if (rvh) |
| 701 mouse_lock_view = rvh->GetView(); | 780 mouse_lock_view = rvh->GetView(); |
| 702 } | 781 } |
| 703 if (mouse_lock_view) | 782 if (mouse_lock_view) |
| 704 mouse_lock_view->UnlockMouse(); | 783 mouse_lock_view->UnlockMouse(); |
| 705 } | 784 } |
| OLD | NEW |