Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / fullscreen_controller.h
blob64202e3faf7aa517b3e20d2d016a108b5ddf8377
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.
5 #ifndef CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_
8 #include <set>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/ui/exclusive_access/exclusive_access_controller_base.h"
13 #include "components/content_settings/core/common/content_settings.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
17 class GURL;
19 namespace content {
20 class WebContents;
23 // There are two different kinds of fullscreen mode - "tab fullscreen" and
24 // "browser fullscreen". "Tab fullscreen" refers to a renderer-initiated
25 // fullscreen mode (eg: from a Flash plugin or via the JS fullscreen API),
26 // whereas "browser fullscreen" refers to the user putting the browser itself
27 // into fullscreen mode from the UI. The difference is that tab fullscreen has
28 // implications for how the contents of the tab render (eg: a video element may
29 // grow to consume the whole tab), whereas browser fullscreen mode doesn't.
30 // Therefore if a user forces an exit from tab fullscreen, we need to notify the
31 // tab so it can stop rendering in its fullscreen mode.
33 // For Flash, FullscreenController will auto-accept all permission requests for
34 // fullscreen, since the assumption is that the plugin handles this for us.
36 // FullscreenWithinTab Note:
37 // All fullscreen widgets are displayed within the tab contents area, and
38 // FullscreenController will expand the browser window so that the tab contents
39 // area fills the entire screen. However, special behavior applies when a tab is
40 // being screen-captured. First, the browser window will not be
41 // fullscreened. This allows the user to retain control of their desktop to work
42 // in other browser tabs or applications while the fullscreen view is displayed
43 // on a remote screen. Second, FullscreenController will auto-resize fullscreen
44 // widgets to that of the capture video resolution when they are hidden (e.g.,
45 // when a user has switched to another tab). This is both a performance and
46 // quality improvement since scaling and letterboxing steps can be skipped in
47 // the capture pipeline.
49 // This class implements fullscreen behaviour.
50 class FullscreenController : public ExclusiveAccessControllerBase {
51 public:
52 explicit FullscreenController(ExclusiveAccessManager* manager);
53 ~FullscreenController() override;
55 // Browser/User Fullscreen ///////////////////////////////////////////////////
57 // Returns true if the window is currently fullscreen and was initially
58 // transitioned to fullscreen by a browser (i.e., not tab-initiated) mode
59 // transition.
60 bool IsFullscreenForBrowser() const;
62 // Returns true if Flash is providing the "exit from fullscreen" message.
63 bool IsPrivilegedFullscreenForTab() const;
65 void ToggleBrowserFullscreenMode();
67 // Fullscreen mode with tab strip and toolbar shown.
68 // Currently only supported on Mac.
69 void ToggleBrowserFullscreenWithToolbar();
71 // Extension API implementation uses this method to toggle fullscreen mode.
72 // The extension's name is displayed in the full screen bubble UI to attribute
73 // the cause of the full screen state change.
74 void ToggleBrowserFullscreenModeWithExtension(const GURL& extension_url);
76 // Tab/HTML/Flash Fullscreen /////////////////////////////////////////////////
78 // Returns true if the browser window has/will fullscreen because of
79 // tab-initiated fullscreen. The window may still be transitioning, and
80 // BrowserWindow::IsFullscreen() may still return false.
81 bool IsWindowFullscreenForTabOrPending() const;
83 // Returns true if the browser window is fullscreen because of extension
84 // initiated fullscreen.
85 bool IsExtensionFullscreenOrPending() const;
87 // Returns true if controller has entered fullscreen mode.
88 bool IsControllerInitiatedFullscreen() const;
90 // Returns true if the user has accepted fullscreen.
91 bool IsUserAcceptedFullscreen() const;
93 // Returns true if the tab is/will be in fullscreen mode. Note: This does NOT
94 // indicate whether the browser window is/will be fullscreened as well. See
95 // 'FullscreenWithinTab Note'.
96 bool IsFullscreenForTabOrPending(
97 const content::WebContents* web_contents) const;
99 // True if fullscreen was entered because of tab fullscreen (was not
100 // previously in user-initiated fullscreen).
101 bool IsFullscreenCausedByTab() const;
103 // Enter tab-initiated fullscreen mode. FullscreenController will decide
104 // whether to also fullscreen the browser window. See 'FullscreenWithinTab
105 // Note'.
106 // |web_contents| represents the tab that requests to be fullscreen.
107 // |origin| represents the origin of the requesting frame inside the
108 // WebContents. If empty, then the |web_contents|'s latest committed URL
109 // origin will be used.
110 void EnterFullscreenModeForTab(content::WebContents* web_contents,
111 const GURL& origin);
113 // Leave a tab-initiated fullscreen mode.
114 // |web_contents| represents the tab that requests to no longer be fullscreen.
115 void ExitFullscreenModeForTab(content::WebContents* web_contents);
117 // Platform Fullscreen ///////////////////////////////////////////////////////
119 #if defined(OS_WIN)
120 // Returns whether we are currently in a Metro snap view.
121 bool IsInMetroSnapMode();
123 // API that puts the window into a mode suitable for rendering when Chrome
124 // is rendered in a 20% screen-width Metro snap view on Windows 8.
125 void SetMetroSnapMode(bool enable);
126 #endif // OS_WIN
128 // Overrde from ExclusiveAccessControllerBase.
129 void OnTabDetachedFromView(content::WebContents* web_contents) override;
130 void OnTabClosing(content::WebContents* web_contents) override;
131 bool HandleUserPressedEscape() override;
133 void ExitExclusiveAccessToPreviousState() override;
134 bool OnAcceptExclusiveAccessPermission() override;
135 bool OnDenyExclusiveAccessPermission() override;
136 GURL GetURLForExclusiveAccessBubble() const override;
137 void ExitExclusiveAccessIfNecessary() override;
138 // Callbacks /////////////////////////////////////////////////////////////////
140 // Called by Browser::WindowFullscreenStateChanged.
141 void WindowFullscreenStateChanged();
143 private:
144 friend class FullscreenControllerTest;
146 enum FullscreenInternalOption {
147 BROWSER,
148 BROWSER_WITH_TOOLBAR,
152 // Posts a task to call NotifyFullscreenChange.
153 void PostFullscreenChangeNotification(bool is_fullscreen);
154 // Sends a NOTIFICATION_FULLSCREEN_CHANGED notification.
155 void NotifyFullscreenChange(bool is_fullscreen);
157 // Notifies the tab that it has been forced out of fullscreen mode if
158 // necessary.
159 void NotifyTabExclusiveAccessLost() override;
161 void ToggleFullscreenModeInternal(FullscreenInternalOption option);
162 void EnterFullscreenModeInternal(FullscreenInternalOption option);
163 void ExitFullscreenModeInternal();
164 void SetFullscreenedTab(content::WebContents* tab, const GURL& origin);
166 ContentSetting GetFullscreenSetting() const;
168 void SetPrivilegedFullscreenForTesting(bool is_privileged);
169 // Returns true if |web_contents| was toggled into/out of fullscreen mode as a
170 // screen-captured tab. See 'FullscreenWithinTab Note'.
171 bool MaybeToggleFullscreenForCapturedTab(content::WebContents* web_contents,
172 bool enter_fullscreen);
173 // Returns true if |web_contents| is in fullscreen mode as a screen-captured
174 // tab. See 'FullscreenWithinTab Note'.
175 bool IsFullscreenForCapturedTab(const content::WebContents* web_contents)
176 const;
178 // Helper methods that should be used in a TAB context.
179 GURL GetRequestingOrigin() const;
180 GURL GetEmbeddingOrigin() const;
182 // If a tab is fullscreen, the |fullscreen_origin_| should be used as the
183 // origin with regards to fullscreen. The |fullscreened_tab_| url should be
184 // used as the embedder url.
185 GURL fullscreened_origin_;
187 // The URL of the extension which trigerred "browser fullscreen" mode.
188 GURL extension_caused_fullscreen_;
190 enum PriorFullscreenState {
191 STATE_INVALID,
192 STATE_NORMAL,
193 STATE_BROWSER_FULLSCREEN_NO_TOOLBAR,
194 STATE_BROWSER_FULLSCREEN_WITH_TOOLBAR,
196 // The state before entering tab fullscreen mode via webkitRequestFullScreen.
197 // When not in tab fullscreen, it is STATE_INVALID.
198 PriorFullscreenState state_prior_to_tab_fullscreen_;
199 // True if tab fullscreen has been allowed, either by settings or by user
200 // clicking the allow button on the fullscreen infobar.
201 bool tab_fullscreen_accepted_;
203 // True if this controller has toggled into tab OR browser fullscreen.
204 bool toggled_into_fullscreen_;
206 // Used to verify that calls we expect to reenter by calling
207 // WindowFullscreenStateChanged do so.
208 bool reentrant_window_state_change_call_check_;
210 // Used in testing to confirm proper behavior for specific, privileged
211 // fullscreen cases.
212 bool is_privileged_fullscreen_for_testing_;
214 base::WeakPtrFactory<FullscreenController> ptr_factory_;
216 DISALLOW_COPY_AND_ASSIGN(FullscreenController);
219 #endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_FULLSCREEN_CONTROLLER_H_