---
# System prepended metadata

title: Tab / Browser Fullscreen
tags: [Chromium-Graphics, elkurin-daily-note]

---

# Tab / Browser Fullscreen
There are two different kinds of fullscreen mode in Chrome, tab fullscreen and browser fullscreen.  
Let's see what they are and how they are controlled.

## Fullscreen Types
Here are the description in one sentense:  
Tab Fullscreen: the fullscreen mode initiated from renderer.  
Browser Fullscreen: the fullscreen mode initiated from user via UI  

When user clicked Fullscreen or pressed fullscreen key, it's browser fullscreen. This is a common use case.  
On the other hand, some service or application use [JS ullscreen API](https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API). Flash plugin is one of the examples.  
Fullscreen is defined in the WHATWG spec as [Fullscreen API](https://fullscreen.spec.whatwg.org/).

Tab fullscreen is coming from the service and there could be some specific way how the contents of the tab render, so when the user forces the tab to exit from the fullscreen, we need to notify the tab of the fullscreen exit so that it can render in the different way.


## How to enter fullscreen
For Tab Fullscreen, as mentioned above, the fullscreen mode must be entered only from the renderer.
[WebContentsImpl::EnterFullscreenMode](https://source.chromium.org/chromium/chromium/src/+/main:content/browser/web_contents/web_contents_impl.cc;l=3859;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1) notifies that the frame wants to enter fullscreen. This is called from renderer host and not from the user action.

For Browser Fullscreen, it's from [BrowserCommandController::ExecuteCommandWithDisposition](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/browser_command_controller.cc;l=393;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1) and then [chrome::ToggleFullscreenMode](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/browser_commands.cc;l=1985;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1).  
The key bind is defined by [AcceleratorTable](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/views/accelerator_table.cc;l=152;drc=fe5eeb265d7f2ed57c13fdff15e3a1d4d19844c7). In this case, it VKEY_F11.

## FullscreenController
[FullscreenController](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/fullscreen_controller.h;l=56;drc=f20c7d9683a23f66cb9f7da0b3d765c66a2608d6) controls the fullscreen state.  
All fullscreen widgets are displayed within the tab contents area, and FullscreenController will expand the browser window to fills the entire screen.

There are several APIs to enter fullscreen.  

[ToggleBrowserFullscreen](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/fullscreen_controller.h;l=75;drc=f20c7d9683a23f66cb9f7da0b3d765c66a2608d6) is for browser fullscreen.  
This is called from BrowserCommaned::ToggleFullscreenMode, or OnTabletModeToggled.  

For Tab Fullscreen, [EnterFullscreenModeForTab](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/fullscreen_controller.h;l=124;drc=f20c7d9683a23f66cb9f7da0b3d765c66a2608d6) should be called.  
FullscreenController decides whether we should also enter fullscreen for the browser window.  
Inside EnterFullscreenModeForTab, [MaybeToggleFullscreenWithinTab](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/fullscreen_controller.cc;l=554;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1) is called. When a tab is screen-captured or the contnet fullscreen feature is active, it also enters browser fullscreen.

Tab fullscreen cannot be dispatched always. There are the web contents that cannot enter tab fullscreen.  
[CanEnterFullscreenModeForTab](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/fullscreen_controller.cc;l=147;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1) decides it.  
If the [ActiveWebContents](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/exclusive_access_context.h;l=66;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1) is not the same as the RenderFrameHost for requesting frame, it cannot enter the tab fullscreen. `requesting_frame` is the specifi content frame requesting fullscreen, so the frame seems to be expected to be already rendered to fullscreen here.

### Popup on fullscreen
[FullscreenTabOpeningPopup](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/fullscreen_controller.cc;l=299;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1) is for checking whether we should preven opening popup on fullscreen.  
For some cases, we must exit the fullscreen on opening popup.  
[PopunderPreventer](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/exclusive_access/fullscreen_controller.h;l=249;drc=125dea0015c8b18e70d42e249437c3e49fe18ae1) tracks related popups that lost activation or were shown without activation dueing the fullscreen sessions.  
This is used to activate the popup under fullscreen after it exists fullscreen mode.