Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/ui/exclusive_access/fullscreen_controller.h

Issue 836933005: Refactor fullscreen_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build break Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 explicit FullscreenController(ExclusiveAccessManager* manager,
miu 2015/01/16 22:17:39 Don't need explicit keyword anymore.
Sriram 2015/01/21 01:38:57 Done.
53 Browser* browser);
57 ~FullscreenController() override; 54 ~FullscreenController() override;
58 55
59 // Browser/User Fullscreen /////////////////////////////////////////////////// 56 // Browser/User Fullscreen ///////////////////////////////////////////////////
60 57
61 // Returns true if the window is currently fullscreen and was initially 58 // Returns true if the window is currently fullscreen and was initially
62 // transitioned to fullscreen by a browser (i.e., not tab-initiated) mode 59 // transitioned to fullscreen by a browser (i.e., not tab-initiated) mode
63 // transition. 60 // transition.
64 bool IsFullscreenForBrowser() const; 61 bool IsFullscreenForBrowser() const;
65 62
63 bool IsPrivilegedFullscreenForTab() const;
miu 2015/01/16 22:17:39 Needs comment. Might be worth mentioning this is
Sriram 2015/01/21 01:38:57 Done.
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 fullscrene mode.
miu 2015/01/16 22:17:39 /fullscrene/fullscreen/
Sriram 2015/01/21 01:38:57 Done.
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
94 // Enter or leave tab-initiated fullscreen mode. FullscreenController will 103 // Enter or leave tab-initiated fullscreen mode. FullscreenController will
95 // decide whether to also fullscreen the browser window. See 104 // decide whether to also fullscreen the browser window. See
96 // 'FullscreenWithinTab Note'. 105 // 'FullscreenWithinTab Note'.
97 void ToggleFullscreenModeForTab(content::WebContents* web_contents, 106 void ToggleFullscreenModeForTab(content::WebContents* web_contents,
98 bool enter_fullscreen); 107 bool enter_fullscreen);
99 108
100 // Platform Fullscreen /////////////////////////////////////////////////////// 109 // Platform Fullscreen ///////////////////////////////////////////////////////
101 110
102 // Returns whether we are currently in a Metro snap view. 111 // Returns whether we are currently in a Metro snap view.
103 bool IsInMetroSnapMode(); 112 bool IsInMetroSnapMode();
104 113
105 #if defined(OS_WIN) 114 #if defined(OS_WIN)
106 // API that puts the window into a mode suitable for rendering when Chrome 115 // API that puts the window into a mode suitable for rendering when Chrome
107 // is rendered in a 20% screen-width Metro snap view on Windows 8. 116 // is rendered in a 20% screen-width Metro snap view on Windows 8.
108 void SetMetroSnapMode(bool enable); 117 void SetMetroSnapMode(bool enable);
109 #endif 118 #endif
110 119
111 // Mouse Lock //////////////////////////////////////////////////////////////// 120 // Overrde from ExclusiveAccessControllerBase.
121 void OnTabDetachedFromView(content::WebContents* web_contents) override;
122 void OnTabClosing(content::WebContents* web_contents) override;
123 bool HandleUserPressedEscape() override;
112 124
113 bool IsMouseLockRequested() const; 125 void ExitExclusiveAccessToPreviousState() override;
114 bool IsMouseLocked() const; 126 bool OnAcceptExclusiveAccessPermission() override;
115 127 bool OnDenyExclusiveAccessPermission() override;
116 void RequestToLockMouse(content::WebContents* web_contents, 128 GURL GetURLForExclusiveAccessBubble() const override;
117 bool user_gesture, 129 void ExitExclusiveAccessIfNecessary() override;
118 bool last_unlocked_by_target);
119
120 // Callbacks ///////////////////////////////////////////////////////////////// 130 // Callbacks /////////////////////////////////////////////////////////////////
121 131
122 // Called by Browser::TabDeactivated.
123 void OnTabDeactivated(content::WebContents* web_contents);
124
125 // Called by Browser::ActiveTabChanged.
126 void OnTabDetachedFromView(content::WebContents* web_contents);
127
128 // Called by Browser::TabClosingAt.
129 void OnTabClosing(content::WebContents* web_contents);
130
131 // Called by Browser::WindowFullscreenStateChanged. 132 // Called by Browser::WindowFullscreenStateChanged.
132 void WindowFullscreenStateChanged(); 133 void WindowFullscreenStateChanged();
133 134
134 // Called by Browser::PreHandleKeyboardEvent.
135 bool HandleUserPressedEscape();
136
137 // Called by platform FullscreenExitBubble.
138 void ExitTabOrBrowserFullscreenToPreviousState();
139 void OnAcceptFullscreenPermission();
140 void OnDenyFullscreenPermission();
141
142 // Called by Browser::LostMouseLock.
143 void LostMouseLock();
144
145 // content::NotificationObserver:
146 void Observe(int type,
147 const content::NotificationSource& source,
148 const content::NotificationDetails& details) override;
149
150 // Bubble Content ////////////////////////////////////////////////////////////
151
152 GURL GetFullscreenExitBubbleURL() const;
153 ExclusiveAccessBubbleType GetExclusiveAccessBubbleType() const;
154
155 private: 135 private:
156 friend class FullscreenControllerTest; 136 friend class FullscreenControllerTest;
157 137
158 enum MouseLockState {
159 MOUSELOCK_NOT_REQUESTED,
160 // The page requests to lock the mouse and the user hasn't responded to the
161 // request.
162 MOUSELOCK_REQUESTED,
163 // Mouse lock has been allowed by the user.
164 MOUSELOCK_ACCEPTED,
165 // Mouse lock has been silently accepted, no notification to user.
166 MOUSELOCK_ACCEPTED_SILENTLY
167 };
168
169 enum FullscreenInternalOption { 138 enum FullscreenInternalOption {
170 BROWSER, 139 BROWSER,
171 BROWSER_WITH_TOOLBAR, 140 BROWSER_WITH_TOOLBAR,
172 TAB 141 TAB
173 }; 142 };
174 143
175 void UpdateNotificationRegistrations();
176
177 // Posts a task to call NotifyFullscreenChange. 144 // Posts a task to call NotifyFullscreenChange.
178 void PostFullscreenChangeNotification(bool is_fullscreen); 145 void PostFullscreenChangeNotification(bool is_fullscreen);
179 // Sends a NOTIFICATION_FULLSCREEN_CHANGED notification. 146 // Sends a NOTIFICATION_FULLSCREEN_CHANGED notification.
180 void NotifyFullscreenChange(bool is_fullscreen); 147 void NotifyFullscreenChange(bool is_fullscreen);
181 // Notifies the tab that it has been forced out of fullscreen and mouse lock 148
182 // mode if necessary. 149 // Notifies the tab that it has been forced out of fullscreen mode if
183 void NotifyTabOfExitIfNecessary(); 150 // necessary.
184 void NotifyMouseLockChange(); 151 void NotifyTabOfExclusiveAccessChange() override;
185 152
186 void ToggleFullscreenModeInternal(FullscreenInternalOption option); 153 void ToggleFullscreenModeInternal(FullscreenInternalOption option);
187 void EnterFullscreenModeInternal(FullscreenInternalOption option); 154 void EnterFullscreenModeInternal(FullscreenInternalOption option);
188 void ExitFullscreenModeInternal(); 155 void ExitFullscreenModeInternal();
189 void SetFullscreenedTab(content::WebContents* tab);
190 void SetMouseLockTab(content::WebContents* tab);
191
192 // Make the current tab exit fullscreen mode or mouse lock if it is in it.
193 void ExitTabFullscreenOrMouseLockIfNecessary();
194 void UpdateFullscreenExitBubbleContent();
195 156
196 ContentSetting GetFullscreenSetting(const GURL& url) const; 157 ContentSetting GetFullscreenSetting(const GURL& url) const;
197 ContentSetting GetMouseLockSetting(const GURL& url) const;
198 158
199 bool IsPrivilegedFullscreenForTab() const;
200 void SetPrivilegedFullscreenForTesting(bool is_privileged); 159 void SetPrivilegedFullscreenForTesting(bool is_privileged);
201 // Returns true if |web_contents| was toggled into/out of fullscreen mode as a 160 // Returns true if |web_contents| was toggled into/out of fullscreen mode as a
202 // screen-captured tab. See 'FullscreenWithinTab Note'. 161 // screen-captured tab. See 'FullscreenWithinTab Note'.
203 bool MaybeToggleFullscreenForCapturedTab(content::WebContents* web_contents, 162 bool MaybeToggleFullscreenForCapturedTab(content::WebContents* web_contents,
204 bool enter_fullscreen); 163 bool enter_fullscreen);
205 // Returns true if |web_contents| is in fullscreen mode as a screen-captured 164 // Returns true if |web_contents| is in fullscreen mode as a screen-captured
206 // tab. See 'FullscreenWithinTab Note'. 165 // tab. See 'FullscreenWithinTab Note'.
207 bool IsFullscreenForCapturedTab(const content::WebContents* web_contents) 166 bool IsFullscreenForCapturedTab(const content::WebContents* web_contents)
208 const; 167 const;
209 void UnlockMouse(); 168 void UnlockMouse();
miu 2015/01/16 22:17:39 Should UnlockMouse() be removed?
Sriram 2015/01/21 01:38:57 Done.
210 169
211 Browser* const browser_;
212 BrowserWindow* const window_;
213 Profile* const profile_;
214
215 // If there is currently a tab in fullscreen mode (entered via
216 // webkitRequestFullScreen), this is its WebContents.
217 // Assign using SetFullscreenedTab().
218 content::WebContents* fullscreened_tab_;
219
220 // The URL of the extension which trigerred "browser fullscreen" mode. 170 // The URL of the extension which trigerred "browser fullscreen" mode.
221 GURL extension_caused_fullscreen_; 171 GURL extension_caused_fullscreen_;
222 172
223 enum PriorFullscreenState { 173 enum PriorFullscreenState {
224 STATE_INVALID, 174 STATE_INVALID,
225 STATE_NORMAL, 175 STATE_NORMAL,
226 STATE_BROWSER_FULLSCREEN_NO_TOOLBAR, 176 STATE_BROWSER_FULLSCREEN_NO_TOOLBAR,
227 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR, 177 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR,
228 }; 178 };
229 // The state before entering tab fullscreen mode via webkitRequestFullScreen. 179 // The state before entering tab fullscreen mode via webkitRequestFullScreen.
230 // When not in tab fullscreen, it is STATE_INVALID. 180 // When not in tab fullscreen, it is STATE_INVALID.
231 PriorFullscreenState state_prior_to_tab_fullscreen_; 181 PriorFullscreenState state_prior_to_tab_fullscreen_;
232 // True if tab fullscreen has been allowed, either by settings or by user 182 // True if tab fullscreen has been allowed, either by settings or by user
233 // clicking the allow button on the fullscreen infobar. 183 // clicking the allow button on the fullscreen infobar.
234 bool tab_fullscreen_accepted_; 184 bool tab_fullscreen_accepted_;
235 185
236 // True if this controller has toggled into tab OR browser fullscreen. 186 // True if this controller has toggled into tab OR browser fullscreen.
237 bool toggled_into_fullscreen_; 187 bool toggled_into_fullscreen_;
238 188
239 // WebContents for current tab requesting or currently in mouse lock.
240 // Assign using SetMouseLockTab().
241 content::WebContents* mouse_lock_tab_;
242
243 MouseLockState mouse_lock_state_;
244
245 content::NotificationRegistrar registrar_;
246
247 // Used to verify that calls we expect to reenter by calling 189 // Used to verify that calls we expect to reenter by calling
248 // WindowFullscreenStateChanged do so. 190 // WindowFullscreenStateChanged do so.
249 bool reentrant_window_state_change_call_check_; 191 bool reentrant_window_state_change_call_check_;
250 192
251 // Used in testing to confirm proper behavior for specific, privileged 193 // Used in testing to confirm proper behavior for specific, privileged
252 // fullscreen cases. 194 // fullscreen cases.
253 bool is_privileged_fullscreen_for_testing_; 195 bool is_privileged_fullscreen_for_testing_;
254 196
255 base::WeakPtrFactory<FullscreenController> ptr_factory_; 197 base::WeakPtrFactory<FullscreenController> ptr_factory_;
256 198
257 DISALLOW_COPY_AND_ASSIGN(FullscreenController); 199 DISALLOW_COPY_AND_ASSIGN(FullscreenController);
258 }; 200 };
259 201
260 #endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_ 202 #endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698