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: ensure ready-to-show event is fired #25490

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
22 changes: 21 additions & 1 deletion shell/browser/api/electron_api_browser_window.cc
Expand Up @@ -159,12 +159,32 @@ void BrowserWindow::DidFirstVisuallyNonEmptyPaint() {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(
[](base::WeakPtr<BrowserWindow> self) {
if (self)
if (self && !self->did_ready_to_show_fired_) {
self->did_ready_to_show_fired_ = true;
self->Emit("ready-to-show");
}
},
GetWeakPtr()));
}

void BrowserWindow::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) {
// The DidFirstVisuallyNonEmptyPaint event is not very stable that, sometimes
// on some machines it might not be fired, and the actual behavior depends on
// the version of Chromium.
// To work around this bug, we ensure the ready-to-show event is emitted if it
// has not been emitted in did-finish-load event.
// Note that we use did-finish-load event instead of dom-ready event because
// the latter may actually be emitted before the ready-to-show event.
// See also https://github.com/electron/electron/issues/7779.
if (window()->IsVisible() || did_ready_to_show_fired_)
return;
if (render_frame_host->GetParent()) // child frame
return;
did_ready_to_show_fired_ = true;
Emit("ready-to-show");
}

void BrowserWindow::BeforeUnloadDialogCancelled() {
WindowList::WindowCloseCancelled(window());
// Cancel unresponsive event when window close is cancelled.
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/api/electron_api_browser_window.h
Expand Up @@ -49,6 +49,8 @@ class BrowserWindow : public TopLevelWindow,
content::RenderViewHost* new_host) override;
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void DidFirstVisuallyNonEmptyPaint() override;
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
void BeforeUnloadDialogCancelled() override;
void OnRendererUnresponsive(content::RenderProcessHost*) override;

Expand Down Expand Up @@ -114,6 +116,8 @@ class BrowserWindow : public TopLevelWindow,
// it should be cancelled when we can prove that the window is responsive.
base::CancelableClosure window_unresponsive_closure_;

bool did_ready_to_show_fired_ = false;

#if defined(OS_MACOSX)
std::vector<mojom::DraggableRegionPtr> draggable_regions_;
#endif
Expand Down
2 changes: 1 addition & 1 deletion spec-main/api-browser-window-spec.ts
Expand Up @@ -1275,7 +1275,7 @@ describe('BrowserWindow module', () => {

it('preserves transparency', async () => {
const w = new BrowserWindow({ show: false, transparent: true });
w.loadURL('about:blank');
w.loadFile(path.join(fixtures, 'pages', 'theme-color.html'));
await emittedOnce(w, 'ready-to-show');
w.show();

Expand Down