#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, public CefKeyboardHandler, public CefJSDialogHandler { 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; } virtual CefRefPtr GetKeyboardHandler() OVERRIDE { return this; } virtual CefRefPtr GetJSDialogHandler() 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; virtual DECL bool OnLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& failedUrl, CefString& errorText) 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; virtual DECL bool GetDownloadHandler(CefRefPtr browser, const CefString& mimeType, const CefString& fileName, int64 contentLength, CefRefPtr& handler) OVERRIDE; virtual DECL bool GetAuthCredentials(CefRefPtr browser, bool isProxy, const CefString& host, int port, const CefString& realm, const CefString& scheme, CefString& username, CefString& password) 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; // CefKeyboardHandler virtual DECL bool OnKeyEvent(CefRefPtr browser, KeyEventType type, int code, int modifiers, bool isSystemKey, bool isAfterJavaScript) OVERRIDE; // CefJSDialogHandler virtual DECL bool OnJSAlert(CefRefPtr browser, CefRefPtr frame, const CefString& message) OVERRIDE; virtual DECL bool OnJSConfirm(CefRefPtr browser, CefRefPtr frame, const CefString& message, bool& retval) OVERRIDE; virtual DECL bool OnJSPrompt(CefRefPtr browser, CefRefPtr frame, const CefString& message, const CefString& defaultValue, bool& retval, CefString& result) OVERRIDE; IMPLEMENT_LOCKING(ClientAdapter); IMPLEMENT_REFCOUNTING(ClientAdapter); }; }