fix: DCHECK entering fullscreen while loading url (#35111)

* fix: DCHECK entering fullscreen while loading url

* spec: fixup test
This commit is contained in:
Shelley Vohr 2022-08-01 22:52:58 +02:00 committed by GitHub
parent 6c17dd2296
commit 7588bb7425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 9 deletions

View file

@ -1327,6 +1327,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);
@ -3537,12 +3539,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_;
return html_fullscreen_ || transition_fs;
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_ || (in_transition && is_html_transition);
}
bool WebContents::TakeFocus(content::WebContents* source, bool reverse) {

View file

@ -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();

View file

@ -318,10 +318,11 @@ 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;
}
@ -329,6 +330,15 @@ class NativeWindow : public base::SupportsUserData,
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_; }
@ -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_;

View file

@ -19,7 +19,7 @@
using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
using FullScreenTransitionState =
electron::NativeWindowMac::FullScreenTransitionState;
electron::NativeWindow::FullScreenTransitionState;
@implementation ElectronNSWindowDelegate

View file

@ -4954,6 +4954,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');