#include "stdafx.h" #pragma once #include "include/cef_client.h" namespace CefSharp { using namespace System; interface class IWebBrowser; class ClientAdapter : public CefClient, public CefLifeSpanHandler, public CefLoadHandler, public CefRequestHandler, public CefDisplayHandler, public CefV8ContextHandler, public CefMenuHandler, public CefFocusHandler { private: gcroot _browserControl; HWND _browserHwnd; CefRefPtr _cefBrowser; gcroot _tooltip; public: ~ClientAdapter() { _browserControl = nullptr; } ClientAdapter(IWebBrowser^ browserControl) : _browserControl(browserControl) {} HWND GetBrowserHwnd() { return _browserHwnd; } CefRefPtr GetCefBrowser() { return _cefBrowser; } // CefClient virtual CefRefPtr GetLifeSpanHandler() OVERRIDE { return this; } virtual CefRefPtr GetLoadHandler() OVERRIDE { return this; } virtual CefRefPtr GetRequestHandler() OVERRIDE { return this; } virtual CefRefPtr GetDisplayHandler() OVERRIDE { return this; } virtual CefRefPtr GetV8ContextHandler() OVERRIDE { return this; } virtual CefRefPtr GetMenuHandler() OVERRIDE { return this; } virtual CefRefPtr GetFocusHandler() OVERRIDE { return this; } // CefLifeSpanHandler virtual DECL bool OnBeforePopup(CefRefPtr parentBrowser, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, const CefString& url, CefRefPtr& client, CefBrowserSettings& settings) OVERRIDE; virtual DECL void OnAfterCreated(CefRefPtr browser) OVERRIDE; virtual DECL void OnBeforeClose(CefRefPtr browser) OVERRIDE; // CefLoadHandler virtual DECL void OnLoadStart(CefRefPtr browser, CefRefPtr frame) OVERRIDE; virtual DECL void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) OVERRIDE; // CefRequestHandler virtual DECL bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, NavType navType, bool isRedirect) OVERRIDE; virtual DECL bool OnBeforeResourceLoad(CefRefPtr browser, CefRefPtr request, CefString& redirectUrl, CefRefPtr& resourceStream, CefRefPtr response, int loadFlags) OVERRIDE; virtual DECL void OnResourceResponse(CefRefPtr browser, const CefString& url, CefRefPtr response, CefRefPtr& filter) OVERRIDE; // CefDisplayHandler virtual DECL void OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) OVERRIDE; virtual DECL void OnContentsSizeChange(CefRefPtr browser, CefRefPtr frame, int width, int height) OVERRIDE; virtual DECL void OnTitleChange(CefRefPtr browser, const CefString& title) OVERRIDE; virtual DECL bool OnTooltip(CefRefPtr browser, CefString& text) OVERRIDE; virtual DECL bool OnConsoleMessage(CefRefPtr browser, const CefString& message, const CefString& source, int line) OVERRIDE; // CefV8ContextHandler virtual DECL void OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; // CefMenuHandler virtual DECL bool OnBeforeMenu(CefRefPtr browser, const CefMenuInfo& menuInfo) OVERRIDE; // CefFocusHandler virtual DECL void OnTakeFocus(CefRefPtr browser, bool next) OVERRIDE; IMPLEMENT_LOCKING(ClientAdapter); IMPLEMENT_REFCOUNTING(ClientAdapter); }; }