| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" | |
| 12 #include "chrome/common/content_settings.h" | |
| 13 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 | |
| 16 class Browser; | |
| 17 class BrowserWindow; | |
| 18 class GURL; | |
| 19 class Profile; | |
| 20 class TabContents; | |
| 21 | |
| 22 namespace content { | |
| 23 class WebContents; | |
| 24 } | |
| 25 | |
| 26 // There are two different kinds of fullscreen mode - "tab fullscreen" and | |
| 27 // "browser fullscreen". "Tab fullscreen" refers to when a tab enters | |
| 28 // fullscreen mode via the JS fullscreen API, and "browser fullscreen" refers | |
| 29 // to the user putting the browser itself into fullscreen mode from the UI. The | |
| 30 // difference is that tab fullscreen has implications for how the contents of | |
| 31 // the tab render (eg: a video element may grow to consume the whole tab), | |
| 32 // whereas browser fullscreen mode doesn't. Therefore if a user forces an exit | |
| 33 // from tab fullscreen, we need to notify the tab so it can stop rendering in | |
| 34 // its fullscreen mode. | |
| 35 | |
| 36 // This class implements fullscreen and mouselock behaviour. | |
| 37 class FullscreenController : public base::RefCounted<FullscreenController>, | |
| 38 public content::NotificationObserver { | |
| 39 public: | |
| 40 FullscreenController(BrowserWindow* window, | |
| 41 Profile* profile, | |
| 42 Browser* browser); | |
| 43 | |
| 44 // Querying. | |
| 45 | |
| 46 // Returns true if the window is currently fullscreen and was initially | |
| 47 // transitioned to fullscreen by a browser (vs tab) mode transition. | |
| 48 bool IsFullscreenForBrowser() const; | |
| 49 | |
| 50 // Returns true if fullscreen has been caused by a tab. | |
| 51 // The window may still be transitioning, and window_->IsFullscreen() | |
| 52 // may still return false. | |
| 53 bool IsFullscreenForTabOrPending() const; | |
| 54 bool IsFullscreenForTabOrPending( | |
| 55 const content::WebContents* web_contents) const; | |
| 56 | |
| 57 #if defined(OS_WIN) | |
| 58 // Returns whether we are currently in a Metro snap view. | |
| 59 bool IsInMetroSnapMode(); | |
| 60 #endif | |
| 61 | |
| 62 bool IsMouseLockRequested() const; | |
| 63 bool IsMouseLocked() const; | |
| 64 | |
| 65 // Requests. | |
| 66 void RequestToLockMouse(content::WebContents* web_contents, | |
| 67 bool user_gesture, | |
| 68 bool last_unlocked_by_target); | |
| 69 void ToggleFullscreenModeForTab(content::WebContents* web_contents, | |
| 70 bool enter_fullscreen); | |
| 71 #if defined(OS_WIN) | |
| 72 // API that puts the window into a mode suitable for rendering when Chrome | |
| 73 // is rendered in a 20% screen-width Metro snap view on Windows 8. | |
| 74 void SetMetroSnapMode(bool enable); | |
| 75 #endif | |
| 76 #if defined(OS_MACOSX) | |
| 77 void TogglePresentationMode(); | |
| 78 #endif | |
| 79 void ToggleFullscreenMode(); | |
| 80 // Extension API implementation uses this method to toggle fullscreen mode. | |
| 81 // The extension's name is displayed in the full screen bubble UI to attribute | |
| 82 // the cause of the full screen state change. | |
| 83 void ToggleFullscreenModeWithExtension(const GURL& extension_url); | |
| 84 | |
| 85 // Notifications. | |
| 86 void LostMouseLock(); | |
| 87 void OnTabClosing(content::WebContents* web_contents); | |
| 88 void OnTabDeactivated(TabContents* contents); | |
| 89 void OnAcceptFullscreenPermission(const GURL& url, | |
| 90 FullscreenExitBubbleType bubble_type); | |
| 91 void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type); | |
| 92 void WindowFullscreenStateChanged(); | |
| 93 bool HandleUserPressedEscape(); | |
| 94 | |
| 95 FullscreenExitBubbleType GetFullscreenExitBubbleType() const; | |
| 96 | |
| 97 // content::NotificationObserver | |
| 98 virtual void Observe(int type, | |
| 99 const content::NotificationSource& source, | |
| 100 const content::NotificationDetails& details) OVERRIDE; | |
| 101 | |
| 102 private: | |
| 103 friend class base::RefCounted<FullscreenController>; | |
| 104 | |
| 105 enum MouseLockState { | |
| 106 MOUSELOCK_NOT_REQUESTED, | |
| 107 // The page requests to lock the mouse and the user hasn't responded to the | |
| 108 // request. | |
| 109 MOUSELOCK_REQUESTED, | |
| 110 // Mouse lock has been allowed by the user. | |
| 111 MOUSELOCK_ACCEPTED, | |
| 112 // Mouse lock has been silently accepted, no notification to user. | |
| 113 MOUSELOCK_ACCEPTED_SILENTLY | |
| 114 }; | |
| 115 | |
| 116 virtual ~FullscreenController(); | |
| 117 | |
| 118 // Notifies the tab that it has been forced out of fullscreen and mouse lock | |
| 119 // mode if necessary. | |
| 120 void NotifyTabOfExitIfNecessary(); | |
| 121 | |
| 122 void UpdateNotificationRegistrations(); | |
| 123 | |
| 124 // Make the current tab exit fullscreen mode or mouse lock if it is in it. | |
| 125 void ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 126 void UpdateFullscreenExitBubbleContent(); | |
| 127 void NotifyFullscreenChange(bool is_fullscreen); | |
| 128 void NotifyMouseLockChange(); | |
| 129 ContentSetting GetFullscreenSetting(const GURL& url) const; | |
| 130 ContentSetting GetMouseLockSetting(const GURL& url) const; | |
| 131 | |
| 132 #if defined(OS_MACOSX) | |
| 133 void TogglePresentationModeInternal(bool for_tab); | |
| 134 #endif | |
| 135 // TODO(koz): Change |for_tab| to an enum. | |
| 136 void ToggleFullscreenModeInternal(bool for_tab); | |
| 137 | |
| 138 void SetFullscreenedTab(TabContents* tab); | |
| 139 void SetMouseLockTab(TabContents* tab); | |
| 140 | |
| 141 BrowserWindow* window_; | |
| 142 Profile* profile_; | |
| 143 Browser* browser_; | |
| 144 | |
| 145 // If there is currently a tab in fullscreen mode (entered via | |
| 146 // webkitRequestFullScreen), this is its TabContents. | |
| 147 // Assign using SetFullscreenedTab(). | |
| 148 TabContents* fullscreened_tab_; | |
| 149 | |
| 150 // The URL of the extension which trigerred "browser fullscreen" mode. | |
| 151 GURL extension_caused_fullscreen_; | |
| 152 | |
| 153 // True if the current tab entered fullscreen mode via webkitRequestFullScreen | |
| 154 bool tab_caused_fullscreen_; | |
| 155 // True if tab fullscreen has been allowed, either by settings or by user | |
| 156 // clicking the allow button on the fullscreen infobar. | |
| 157 bool tab_fullscreen_accepted_; | |
| 158 | |
| 159 // True if this controller has toggled into tab OR browser fullscreen. | |
| 160 bool toggled_into_fullscreen_; | |
| 161 | |
| 162 // TabContents for current tab requesting or currently in mouse lock. | |
| 163 // Assign using SetMouseLockTab(). | |
| 164 TabContents* mouse_lock_tab_; | |
| 165 | |
| 166 MouseLockState mouse_lock_state_; | |
| 167 | |
| 168 content::NotificationRegistrar registrar_; | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(FullscreenController); | |
| 171 }; | |
| 172 | |
| 173 #endif // CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_H_ | |
| OLD | NEW |