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