Skip to content

Commit

Permalink
fix: DCHECK entering fullscreen while loading url (#35164)
Browse files Browse the repository at this point in the history
* fix: DCHECK entering fullscreen while loading url

* spec: fixup test

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Aug 2, 2022
1 parent a07f56b commit 21fcf51
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
15 changes: 10 additions & 5 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1340,6 +1340,8 @@ void WebContents::OnEnterFullscreenModeForTab(
return;
}

owner_window()->set_fullscreen_transition_type(
NativeWindow::FullScreenTransitionType::HTML);
exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab(
requesting_frame, options.display_id);

Expand Down Expand Up @@ -3519,12 +3521,15 @@ void WebContents::EnumerateDirectory(

bool WebContents::IsFullscreenForTabOrPending(
const content::WebContents* source) {
bool transition_fs = owner_window()
? owner_window()->fullscreen_transition_state() !=
NativeWindow::FullScreenTransitionState::NONE
: false;
if (!owner_window())
return html_fullscreen_;

bool in_transition = owner_window()->fullscreen_transition_state() !=
NativeWindow::FullScreenTransitionState::NONE;
bool is_html_transition = owner_window()->fullscreen_transition_type() ==
NativeWindow::FullScreenTransitionType::HTML;

return html_fullscreen_ || transition_fs;
return html_fullscreen_ || (in_transition && is_html_transition);
}

bool WebContents::TakeFocus(content::WebContents* source, bool reverse) {
Expand Down
4 changes: 3 additions & 1 deletion shell/browser/native_window.cc
Expand Up @@ -719,8 +719,10 @@ std::string NativeWindow::GetAccessibleTitle() {
}

void NativeWindow::HandlePendingFullscreenTransitions() {
if (pending_transitions_.empty())
if (pending_transitions_.empty()) {
set_fullscreen_transition_type(FullScreenTransitionType::NONE);
return;
}

bool next_transition = pending_transitions_.front();
pending_transitions_.pop();
Expand Down
16 changes: 14 additions & 2 deletions shell/browser/native_window.h
Expand Up @@ -318,17 +318,27 @@ class NativeWindow : public base::SupportsUserData,
observers_.RemoveObserver(obs);
}

enum class FullScreenTransitionState { ENTERING, EXITING, NONE };

// Handle fullscreen transitions.
void HandlePendingFullscreenTransitions();

enum class FullScreenTransitionState { ENTERING, EXITING, NONE };

void set_fullscreen_transition_state(FullScreenTransitionState state) {
fullscreen_transition_state_ = state;
}
FullScreenTransitionState fullscreen_transition_state() const {
return fullscreen_transition_state_;
}

enum class FullScreenTransitionType { HTML, NATIVE, NONE };

void set_fullscreen_transition_type(FullScreenTransitionType type) {
fullscreen_transition_type_ = type;
}
FullScreenTransitionType fullscreen_transition_type() const {
return fullscreen_transition_type_;
}

views::Widget* widget() const { return widget_.get(); }
views::View* content_view() const { return content_view_; }

Expand Down Expand Up @@ -390,6 +400,8 @@ class NativeWindow : public base::SupportsUserData,
std::queue<bool> pending_transitions_;
FullScreenTransitionState fullscreen_transition_state_ =
FullScreenTransitionState::NONE;
FullScreenTransitionType fullscreen_transition_type_ =
FullScreenTransitionType::NONE;

private:
std::unique_ptr<views::Widget> widget_;
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/ui/cocoa/electron_ns_window_delegate.mm
Expand Up @@ -19,7 +19,7 @@

using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
using FullScreenTransitionState =
electron::NativeWindowMac::FullScreenTransitionState;
electron::NativeWindow::FullScreenTransitionState;

@implementation ElectronNSWindowDelegate

Expand Down
17 changes: 17 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -4946,6 +4946,23 @@ describe('BrowserWindow module', () => {
await leaveFullScreen;
});

it('should be able to load a URL while transitioning to fullscreen', async () => {
const w = new BrowserWindow({ fullscreen: true });
w.loadFile(path.join(fixtures, 'pages', 'c.html'));

const load = emittedOnce(w.webContents, 'did-finish-load');
const enterFS = emittedOnce(w, 'enter-full-screen');

await Promise.all([enterFS, load]);
expect(w.fullScreen).to.be.true();

await delay();

const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
});

it('can be changed with setFullScreen method', async () => {
const w = new BrowserWindow();
const enterFullScreen = emittedOnce(w, 'enter-full-screen');
Expand Down

0 comments on commit 21fcf51

Please sign in to comment.