mirror of
https://github.com/Adamcake/Bolt.git
synced 2026-08-07 05:04:34 -04:00
browser/window_delegate: correctly handle closing
This commit is contained in:
1 parent
ac44cdc33f
commit
32fe7f1032
2 files changed
+23
-6
No files matched your search
@@ -6,13 +6,19 @@ Browser::WindowDelegate::WindowDelegate(
|
|||||||
CefRefPtr<CefBrowserView> browser_view,
|
CefRefPtr<CefBrowserView> browser_view,
|
||||||
CefRefPtr<CefBrowserViewDelegate> browser_view_delegate,
|
CefRefPtr<CefBrowserViewDelegate> browser_view_delegate,
|
||||||
Details details
|
Details details
|
||||||
): details(details), window(nullptr), browser_view(browser_view), browser_view_delegate(browser_view_delegate) { }
|
): details(details), window(nullptr), browser_view(browser_view), browser_view_delegate(browser_view_delegate), closing(false) { }
|
||||||
|
|
||||||
void Browser::WindowDelegate::Close() {
|
void Browser::WindowDelegate::Close() {
|
||||||
if (this->window) {
|
this->closing = true;
|
||||||
this->window->Close();
|
this->window->Close();
|
||||||
this->window = nullptr;
|
}
|
||||||
}
|
|
||||||
|
int Browser::WindowDelegate::GetBrowserIdentifier() {
|
||||||
|
return this->browser_view->GetBrowser()->GetIdentifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Browser::WindowDelegate::SendProcessMessage(CefProcessId target_process, CefRefPtr<CefProcessMessage> message) {
|
||||||
|
this->browser_view->GetBrowser()->GetMainFrame()->SendProcessMessage(target_process, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::WindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
|
void Browser::WindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
|
||||||
@@ -57,7 +63,15 @@ bool Browser::WindowDelegate::CanMinimize(CefRefPtr<CefWindow>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Browser::WindowDelegate::CanClose(CefRefPtr<CefWindow>) {
|
bool Browser::WindowDelegate::CanClose(CefRefPtr<CefWindow>) {
|
||||||
return true;
|
if (this->closing) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// CEF will call CefLifeSpanHandler::DoClose (implemented in Client), giving us a chance to
|
||||||
|
// do cleanup, then set this->closing to true, then call Close() again.
|
||||||
|
// This strategy is suggested by official examples eg cefsimple
|
||||||
|
// https://github.com/chromiumembedded/cef/blob/5563/tests/cefsimple/simple_app.cc#L38-L45
|
||||||
|
return this->browser_view->GetBrowser()->GetHost()->TryCloseBrowser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CefSize Browser::WindowDelegate::GetPreferredSize(CefRefPtr<CefView>) {
|
CefSize Browser::WindowDelegate::GetPreferredSize(CefRefPtr<CefView>) {
|
||||||
|
|||||||
@@ -27,11 +27,14 @@ namespace Browser {
|
|||||||
CefSize GetMaximumSize(CefRefPtr<CefView>) override;
|
CefSize GetMaximumSize(CefRefPtr<CefView>) override;
|
||||||
|
|
||||||
void Close();
|
void Close();
|
||||||
|
int GetBrowserIdentifier();
|
||||||
|
void SendProcessMessage(CefProcessId, CefRefPtr<CefProcessMessage>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CefRefPtr<CefWindow> window;
|
CefRefPtr<CefWindow> window;
|
||||||
CefRefPtr<CefBrowserView> browser_view;
|
CefRefPtr<CefBrowserView> browser_view;
|
||||||
CefRefPtr<CefBrowserViewDelegate> browser_view_delegate;
|
CefRefPtr<CefBrowserViewDelegate> browser_view_delegate;
|
||||||
|
bool closing;
|
||||||
|
|
||||||
IMPLEMENT_REFCOUNTING(WindowDelegate);
|
IMPLEMENT_REFCOUNTING(WindowDelegate);
|
||||||
DISALLOW_COPY_AND_ASSIGN(WindowDelegate);
|
DISALLOW_COPY_AND_ASSIGN(WindowDelegate);
|
||||||
|
|||||||
Reference in new issue
Block a user