browser/client: keep on stack

This commit is contained in:
Adam
2023-03-19 17:21:39 +00:00
parent b4d3c61730
commit 39f15ddced
2 changed files with 11 additions and 4 deletions

View File

@@ -5,15 +5,21 @@
#include "include/cef_client.h"
namespace Browser {
/// Implementation of CefClient. Store on the stack, but access only via CefRefPtr.
/// https://github.com/chromiumembedded/cef/blob/5563/include/cef_client.h
struct Client: public CefClient {
CefRefPtr<CefLifeSpanHandler> life_span_handler;
Client(CefRefPtr<CefLifeSpanHandler>);
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override;
private:
IMPLEMENT_REFCOUNTING(Client);
DISALLOW_COPY_AND_ASSIGN(Client);
Client(const Client&) = delete;
Client& operator=(const Client&) = delete;
void AddRef() const override { this->ref_count.AddRef(); }
bool Release() const override { return this->ref_count.Release(); }
bool HasOneRef() const override { return this->ref_count.HasOneRef(); }
bool HasAtLeastOneRef() const override { return this->ref_count.HasAtLeastOneRef(); }
private: CefRefCount ref_count;
};
}

View File

@@ -85,7 +85,8 @@ int main(int argc, char* argv[]) {
// Our CEF client and the various things it needs pointers to
CefRefPtr<CefLifeSpanHandler> life_span_handler = new Browser::LifeSpanHandler;
CefRefPtr<CefClient> client = new Browser::Client(life_span_handler);
Browser::Client client_(life_span_handler);
CefRefPtr<CefClient> client = &client_;
// Spawn a window using the "views" pipeline
Browser::Details details = {