Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DCHECK entering fullscreen while loading url #35164

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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