Skip to content

Commit

Permalink
fix: DCHECK entering fullscreen while loading url
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jul 28, 2022
1 parent b0c6fb5 commit 2ba8c60
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
15 changes: 10 additions & 5 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1332,6 +1332,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 @@ -3542,12 +3544,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 @@ -718,8 +718,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

0 comments on commit 2ba8c60

Please sign in to comment.