| 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 #ifndef CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble_type.h" | 12 #include "chrome/browser/ui/exclusive_access/exclusive_access_controller_base.h" |
| 13 #include "components/content_settings/core/common/content_settings.h" | 13 #include "components/content_settings/core/common/content_settings.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 | 16 |
| 17 class Browser; | |
| 18 class BrowserWindow; | |
| 19 class GURL; | 17 class GURL; |
| 20 class Profile; | |
| 21 | 18 |
| 22 namespace content { | 19 namespace content { |
| 23 class WebContents; | 20 class WebContents; |
| 24 } | 21 } |
| 25 | 22 |
| 26 // There are two different kinds of fullscreen mode - "tab fullscreen" and | 23 // There are two different kinds of fullscreen mode - "tab fullscreen" and |
| 27 // "browser fullscreen". "Tab fullscreen" refers to a renderer-initiated | 24 // "browser fullscreen". "Tab fullscreen" refers to a renderer-initiated |
| 28 // fullscreen mode (eg: from a Flash plugin or via the JS fullscreen API), | 25 // fullscreen mode (eg: from a Flash plugin or via the JS fullscreen API), |
| 29 // whereas "browser fullscreen" refers to the user putting the browser itself | 26 // whereas "browser fullscreen" refers to the user putting the browser itself |
| 30 // into fullscreen mode from the UI. The difference is that tab fullscreen has | 27 // into fullscreen mode from the UI. The difference is that tab fullscreen has |
| 31 // implications for how the contents of the tab render (eg: a video element may | 28 // implications for how the contents of the tab render (eg: a video element may |
| 32 // grow to consume the whole tab), whereas browser fullscreen mode doesn't. | 29 // grow to consume the whole tab), whereas browser fullscreen mode doesn't. |
| 33 // Therefore if a user forces an exit from tab fullscreen, we need to notify the | 30 // Therefore if a user forces an exit from tab fullscreen, we need to notify the |
| 34 // tab so it can stop rendering in its fullscreen mode. | 31 // tab so it can stop rendering in its fullscreen mode. |
| 35 // | 32 // |
| 36 // For Flash, FullscreenController will auto-accept all permission requests for | 33 // For Flash, FullscreenController will auto-accept all permission requests for |
| 37 // fullscreen and/or mouse lock, since the assumption is that the plugin handles | 34 // fullscreen, since the assumption is that the plugin handles this for us. |
| 38 // this for us. | |
| 39 // | 35 // |
| 40 // FullscreenWithinTab Note: | 36 // FullscreenWithinTab Note: |
| 41 // All fullscreen widgets are displayed within the tab contents area, and | 37 // All fullscreen widgets are displayed within the tab contents area, and |
| 42 // FullscreenController will expand the browser window so that the tab contents | 38 // FullscreenController will expand the browser window so that the tab contents |
| 43 // area fills the entire screen. However, special behavior applies when a tab is | 39 // area fills the entire screen. However, special behavior applies when a tab is |
| 44 // being screen-captured. First, the browser window will not be | 40 // being screen-captured. First, the browser window will not be |
| 45 // fullscreened. This allows the user to retain control of their desktop to work | 41 // fullscreened. This allows the user to retain control of their desktop to work |
| 46 // in other browser tabs or applications while the fullscreen view is displayed | 42 // in other browser tabs or applications while the fullscreen view is displayed |
| 47 // on a remote screen. Second, FullscreenController will auto-resize fullscreen | 43 // on a remote screen. Second, FullscreenController will auto-resize fullscreen |
| 48 // widgets to that of the capture video resolution when they are hidden (e.g., | 44 // widgets to that of the capture video resolution when they are hidden (e.g., |
| 49 // when a user has switched to another tab). This is both a performance and | 45 // when a user has switched to another tab). This is both a performance and |
| 50 // quality improvement since scaling and letterboxing steps can be skipped in | 46 // quality improvement since scaling and letterboxing steps can be skipped in |
| 51 // the capture pipeline. | 47 // the capture pipeline. |
| 52 | 48 |
| 53 // This class implements fullscreen and mouselock behaviour. | 49 // This class implements fullscreen behaviour. |
| 54 class FullscreenController : public content::NotificationObserver { | 50 class FullscreenController : public ExclusiveAccessControllerBase { |
| 55 public: | 51 public: |
| 56 explicit FullscreenController(Browser* browser); | 52 FullscreenController(ExclusiveAccessManager* manager, Browser* browser); |
| 57 ~FullscreenController() override; | 53 ~FullscreenController() override; |
| 58 | 54 |
| 59 // Browser/User Fullscreen /////////////////////////////////////////////////// | 55 // Browser/User Fullscreen /////////////////////////////////////////////////// |
| 60 | 56 |
| 61 // Returns true if the window is currently fullscreen and was initially | 57 // Returns true if the window is currently fullscreen and was initially |
| 62 // transitioned to fullscreen by a browser (i.e., not tab-initiated) mode | 58 // transitioned to fullscreen by a browser (i.e., not tab-initiated) mode |
| 63 // transition. | 59 // transition. |
| 64 bool IsFullscreenForBrowser() const; | 60 bool IsFullscreenForBrowser() const; |
| 65 | 61 |
| 62 // Returns true if Flash is providing the "exit from fullscreen" message. |
| 63 bool IsPrivilegedFullscreenForTab() const; |
| 64 |
| 66 void ToggleBrowserFullscreenMode(); | 65 void ToggleBrowserFullscreenMode(); |
| 67 | 66 |
| 68 // Fullscreen mode with tab strip and toolbar shown. | 67 // Fullscreen mode with tab strip and toolbar shown. |
| 69 // Currently only supported on Mac. | 68 // Currently only supported on Mac. |
| 70 void ToggleBrowserFullscreenWithToolbar(); | 69 void ToggleBrowserFullscreenWithToolbar(); |
| 71 | 70 |
| 72 // Extension API implementation uses this method to toggle fullscreen mode. | 71 // Extension API implementation uses this method to toggle fullscreen mode. |
| 73 // The extension's name is displayed in the full screen bubble UI to attribute | 72 // The extension's name is displayed in the full screen bubble UI to attribute |
| 74 // the cause of the full screen state change. | 73 // the cause of the full screen state change. |
| 75 void ToggleBrowserFullscreenModeWithExtension(const GURL& extension_url); | 74 void ToggleBrowserFullscreenModeWithExtension(const GURL& extension_url); |
| 76 | 75 |
| 77 // Tab/HTML/Flash Fullscreen ///////////////////////////////////////////////// | 76 // Tab/HTML/Flash Fullscreen ///////////////////////////////////////////////// |
| 78 | 77 |
| 79 // Returns true if the browser window has/will fullscreen because of | 78 // Returns true if the browser window has/will fullscreen because of |
| 80 // tab-initiated fullscreen. The window may still be transitioning, and | 79 // tab-initiated fullscreen. The window may still be transitioning, and |
| 81 // BrowserWindow::IsFullscreen() may still return false. | 80 // BrowserWindow::IsFullscreen() may still return false. |
| 82 bool IsWindowFullscreenForTabOrPending() const; | 81 bool IsWindowFullscreenForTabOrPending() const; |
| 83 | 82 |
| 83 // Returns true if the browser window is fullscreen because of extension |
| 84 // initiated fullscreen. |
| 85 bool IsExtensionFullscreenOrPending() const; |
| 86 |
| 87 // Returns true if controller has entered fullscreen mode. |
| 88 bool IsControllerInitiatedFullscreen() const; |
| 89 |
| 90 // Returns true if the user has accepted fullscreen. |
| 91 bool IsUserAcceptedFullscreen() const; |
| 92 |
| 84 // Returns true if the tab is/will be in fullscreen mode. Note: This does NOT | 93 // Returns true if the tab is/will be in fullscreen mode. Note: This does NOT |
| 85 // indicate whether the browser window is/will be fullscreened as well. See | 94 // indicate whether the browser window is/will be fullscreened as well. See |
| 86 // 'FullscreenWithinTab Note'. | 95 // 'FullscreenWithinTab Note'. |
| 87 bool IsFullscreenForTabOrPending( | 96 bool IsFullscreenForTabOrPending( |
| 88 const content::WebContents* web_contents) const; | 97 const content::WebContents* web_contents) const; |
| 89 | 98 |
| 90 // True if fullscreen was entered because of tab fullscreen (was not | 99 // True if fullscreen was entered because of tab fullscreen (was not |
| 91 // previously in user-initiated fullscreen). | 100 // previously in user-initiated fullscreen). |
| 92 bool IsFullscreenCausedByTab() const; | 101 bool IsFullscreenCausedByTab() const; |
| 93 | 102 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 | 118 |
| 110 // Returns whether we are currently in a Metro snap view. | 119 // Returns whether we are currently in a Metro snap view. |
| 111 bool IsInMetroSnapMode(); | 120 bool IsInMetroSnapMode(); |
| 112 | 121 |
| 113 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
| 114 // API that puts the window into a mode suitable for rendering when Chrome | 123 // API that puts the window into a mode suitable for rendering when Chrome |
| 115 // is rendered in a 20% screen-width Metro snap view on Windows 8. | 124 // is rendered in a 20% screen-width Metro snap view on Windows 8. |
| 116 void SetMetroSnapMode(bool enable); | 125 void SetMetroSnapMode(bool enable); |
| 117 #endif | 126 #endif |
| 118 | 127 |
| 119 // Mouse Lock //////////////////////////////////////////////////////////////// | 128 // Overrde from ExclusiveAccessControllerBase. |
| 129 void OnTabDetachedFromView(content::WebContents* web_contents) override; |
| 130 void OnTabClosing(content::WebContents* web_contents) override; |
| 131 bool HandleUserPressedEscape() override; |
| 120 | 132 |
| 121 bool IsMouseLockRequested() const; | 133 void ExitExclusiveAccessToPreviousState() override; |
| 122 bool IsMouseLocked() const; | 134 bool OnAcceptExclusiveAccessPermission() override; |
| 123 | 135 bool OnDenyExclusiveAccessPermission() override; |
| 124 void RequestToLockMouse(content::WebContents* web_contents, | 136 GURL GetURLForExclusiveAccessBubble() const override; |
| 125 bool user_gesture, | 137 void ExitExclusiveAccessIfNecessary() override; |
| 126 bool last_unlocked_by_target); | |
| 127 | |
| 128 // Callbacks ///////////////////////////////////////////////////////////////// | 138 // Callbacks ///////////////////////////////////////////////////////////////// |
| 129 | 139 |
| 130 // Called by Browser::TabDeactivated. | |
| 131 void OnTabDeactivated(content::WebContents* web_contents); | |
| 132 | |
| 133 // Called by Browser::ActiveTabChanged. | |
| 134 void OnTabDetachedFromView(content::WebContents* web_contents); | |
| 135 | |
| 136 // Called by Browser::TabClosingAt. | |
| 137 void OnTabClosing(content::WebContents* web_contents); | |
| 138 | |
| 139 // Called by Browser::WindowFullscreenStateChanged. | 140 // Called by Browser::WindowFullscreenStateChanged. |
| 140 void WindowFullscreenStateChanged(); | 141 void WindowFullscreenStateChanged(); |
| 141 | 142 |
| 142 // Called by Browser::PreHandleKeyboardEvent. | |
| 143 bool HandleUserPressedEscape(); | |
| 144 | |
| 145 // Called by platform FullscreenExitBubble. | |
| 146 void ExitTabOrBrowserFullscreenToPreviousState(); | |
| 147 void OnAcceptFullscreenPermission(); | |
| 148 void OnDenyFullscreenPermission(); | |
| 149 | |
| 150 // Called by Browser::LostMouseLock. | |
| 151 void LostMouseLock(); | |
| 152 | |
| 153 // content::NotificationObserver: | |
| 154 void Observe(int type, | |
| 155 const content::NotificationSource& source, | |
| 156 const content::NotificationDetails& details) override; | |
| 157 | |
| 158 // Bubble Content //////////////////////////////////////////////////////////// | |
| 159 | |
| 160 GURL GetFullscreenExitBubbleURL() const; | |
| 161 ExclusiveAccessBubbleType GetExclusiveAccessBubbleType() const; | |
| 162 | |
| 163 private: | 143 private: |
| 164 friend class FullscreenControllerTest; | 144 friend class FullscreenControllerTest; |
| 165 | 145 |
| 166 enum MouseLockState { | |
| 167 MOUSELOCK_NOT_REQUESTED, | |
| 168 // The page requests to lock the mouse and the user hasn't responded to the | |
| 169 // request. | |
| 170 MOUSELOCK_REQUESTED, | |
| 171 // Mouse lock has been allowed by the user. | |
| 172 MOUSELOCK_ACCEPTED, | |
| 173 // Mouse lock has been silently accepted, no notification to user. | |
| 174 MOUSELOCK_ACCEPTED_SILENTLY | |
| 175 }; | |
| 176 | |
| 177 enum FullscreenInternalOption { | 146 enum FullscreenInternalOption { |
| 178 BROWSER, | 147 BROWSER, |
| 179 BROWSER_WITH_TOOLBAR, | 148 BROWSER_WITH_TOOLBAR, |
| 180 TAB | 149 TAB |
| 181 }; | 150 }; |
| 182 | 151 |
| 183 void UpdateNotificationRegistrations(); | |
| 184 | |
| 185 // Posts a task to call NotifyFullscreenChange. | 152 // Posts a task to call NotifyFullscreenChange. |
| 186 void PostFullscreenChangeNotification(bool is_fullscreen); | 153 void PostFullscreenChangeNotification(bool is_fullscreen); |
| 187 // Sends a NOTIFICATION_FULLSCREEN_CHANGED notification. | 154 // Sends a NOTIFICATION_FULLSCREEN_CHANGED notification. |
| 188 void NotifyFullscreenChange(bool is_fullscreen); | 155 void NotifyFullscreenChange(bool is_fullscreen); |
| 189 // Notifies the tab that it has been forced out of fullscreen and mouse lock | 156 |
| 190 // mode if necessary. | 157 // Notifies the tab that it has been forced out of fullscreen mode if |
| 191 void NotifyTabOfExitIfNecessary(); | 158 // necessary. |
| 192 void NotifyMouseLockChange(); | 159 void NotifyTabOfExclusiveAccessChange() override; |
| 193 | 160 |
| 194 void ToggleFullscreenModeInternal(FullscreenInternalOption option); | 161 void ToggleFullscreenModeInternal(FullscreenInternalOption option); |
| 195 void EnterFullscreenModeInternal(FullscreenInternalOption option); | 162 void EnterFullscreenModeInternal(FullscreenInternalOption option); |
| 196 void ExitFullscreenModeInternal(); | 163 void ExitFullscreenModeInternal(); |
| 197 void SetFullscreenedTab(content::WebContents* tab, const GURL& origin); | 164 void SetFullscreenedTab(content::WebContents* tab, const GURL& origin); |
| 198 void SetMouseLockTab(content::WebContents* tab); | |
| 199 | |
| 200 // Make the current tab exit fullscreen mode or mouse lock if it is in it. | |
| 201 void ExitTabFullscreenOrMouseLockIfNecessary(); | |
| 202 void UpdateFullscreenExitBubbleContent(); | |
| 203 | 165 |
| 204 ContentSetting GetFullscreenSetting() const; | 166 ContentSetting GetFullscreenSetting() const; |
| 205 ContentSetting GetMouseLockSetting(const GURL& url) const; | |
| 206 | 167 |
| 207 bool IsPrivilegedFullscreenForTab() const; | |
| 208 void SetPrivilegedFullscreenForTesting(bool is_privileged); | 168 void SetPrivilegedFullscreenForTesting(bool is_privileged); |
| 209 // Returns true if |web_contents| was toggled into/out of fullscreen mode as a | 169 // Returns true if |web_contents| was toggled into/out of fullscreen mode as a |
| 210 // screen-captured tab. See 'FullscreenWithinTab Note'. | 170 // screen-captured tab. See 'FullscreenWithinTab Note'. |
| 211 bool MaybeToggleFullscreenForCapturedTab(content::WebContents* web_contents, | 171 bool MaybeToggleFullscreenForCapturedTab(content::WebContents* web_contents, |
| 212 bool enter_fullscreen); | 172 bool enter_fullscreen); |
| 213 // Returns true if |web_contents| is in fullscreen mode as a screen-captured | 173 // Returns true if |web_contents| is in fullscreen mode as a screen-captured |
| 214 // tab. See 'FullscreenWithinTab Note'. | 174 // tab. See 'FullscreenWithinTab Note'. |
| 215 bool IsFullscreenForCapturedTab(const content::WebContents* web_contents) | 175 bool IsFullscreenForCapturedTab(const content::WebContents* web_contents) |
| 216 const; | 176 const; |
| 217 void UnlockMouse(); | |
| 218 | 177 |
| 219 // Helper methods that should be used in a TAB context. | 178 // Helper methods that should be used in a TAB context. |
| 220 GURL GetRequestingOrigin() const; | 179 GURL GetRequestingOrigin() const; |
| 221 GURL GetEmbeddingOrigin() const; | 180 GURL GetEmbeddingOrigin() const; |
| 222 | 181 |
| 223 Browser* const browser_; | |
| 224 BrowserWindow* const window_; | |
| 225 Profile* const profile_; | |
| 226 | |
| 227 // If there is currently a tab in fullscreen mode (entered via | |
| 228 // webkitRequestFullScreen), this is its WebContents. | |
| 229 // Assign using SetFullscreenedTab(). | |
| 230 content::WebContents* fullscreened_tab_; | |
| 231 | |
| 232 // If a tab is fullscreen, the |fullscreen_origin_| should be used as the | 182 // If a tab is fullscreen, the |fullscreen_origin_| should be used as the |
| 233 // origin with regards to fullscreen. The |fullscreened_tab_| url should be | 183 // origin with regards to fullscreen. The |fullscreened_tab_| url should be |
| 234 // used as the embedder url. | 184 // used as the embedder url. |
| 235 GURL fullscreened_origin_; | 185 GURL fullscreened_origin_; |
| 236 | 186 |
| 237 // The URL of the extension which trigerred "browser fullscreen" mode. | 187 // The URL of the extension which trigerred "browser fullscreen" mode. |
| 238 GURL extension_caused_fullscreen_; | 188 GURL extension_caused_fullscreen_; |
| 239 | 189 |
| 240 enum PriorFullscreenState { | 190 enum PriorFullscreenState { |
| 241 STATE_INVALID, | 191 STATE_INVALID, |
| 242 STATE_NORMAL, | 192 STATE_NORMAL, |
| 243 STATE_BROWSER_FULLSCREEN_NO_TOOLBAR, | 193 STATE_BROWSER_FULLSCREEN_NO_TOOLBAR, |
| 244 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR, | 194 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR, |
| 245 }; | 195 }; |
| 246 // The state before entering tab fullscreen mode via webkitRequestFullScreen. | 196 // The state before entering tab fullscreen mode via webkitRequestFullScreen. |
| 247 // When not in tab fullscreen, it is STATE_INVALID. | 197 // When not in tab fullscreen, it is STATE_INVALID. |
| 248 PriorFullscreenState state_prior_to_tab_fullscreen_; | 198 PriorFullscreenState state_prior_to_tab_fullscreen_; |
| 249 // True if tab fullscreen has been allowed, either by settings or by user | 199 // True if tab fullscreen has been allowed, either by settings or by user |
| 250 // clicking the allow button on the fullscreen infobar. | 200 // clicking the allow button on the fullscreen infobar. |
| 251 bool tab_fullscreen_accepted_; | 201 bool tab_fullscreen_accepted_; |
| 252 | 202 |
| 253 // True if this controller has toggled into tab OR browser fullscreen. | 203 // True if this controller has toggled into tab OR browser fullscreen. |
| 254 bool toggled_into_fullscreen_; | 204 bool toggled_into_fullscreen_; |
| 255 | 205 |
| 256 // WebContents for current tab requesting or currently in mouse lock. | |
| 257 // Assign using SetMouseLockTab(). | |
| 258 content::WebContents* mouse_lock_tab_; | |
| 259 | |
| 260 MouseLockState mouse_lock_state_; | |
| 261 | |
| 262 content::NotificationRegistrar registrar_; | |
| 263 | |
| 264 // Used to verify that calls we expect to reenter by calling | 206 // Used to verify that calls we expect to reenter by calling |
| 265 // WindowFullscreenStateChanged do so. | 207 // WindowFullscreenStateChanged do so. |
| 266 bool reentrant_window_state_change_call_check_; | 208 bool reentrant_window_state_change_call_check_; |
| 267 | 209 |
| 268 // Used in testing to confirm proper behavior for specific, privileged | 210 // Used in testing to confirm proper behavior for specific, privileged |
| 269 // fullscreen cases. | 211 // fullscreen cases. |
| 270 bool is_privileged_fullscreen_for_testing_; | 212 bool is_privileged_fullscreen_for_testing_; |
| 271 | 213 |
| 272 base::WeakPtrFactory<FullscreenController> ptr_factory_; | 214 base::WeakPtrFactory<FullscreenController> ptr_factory_; |
| 273 | 215 |
| 274 DISALLOW_COPY_AND_ASSIGN(FullscreenController); | 216 DISALLOW_COPY_AND_ASSIGN(FullscreenController); |
| 275 }; | 217 }; |
| 276 | 218 |
| 277 #endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_ | 219 #endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_ |
| OLD | NEW |