/** * @file XTPWebViewProvider.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #if !defined(__XTPWEBVIEWPROVIDER_H__) /** @cond */ # define __XTPWEBVIEWPROVIDER_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" struct IXTPWebBrowserHost; struct ICoreWebView2Controller; struct ICoreWebView2; // Use this macro for linking WebView2LoaderStatic.lib instead of linking WebView2Loader.dll // dynamically. // #define XTP_USE_WEBVIEW2_STATIC_LIB /** @cond */ class CXTPWebViewProviderSpy; /** @endcond */ /** * @brief * Implements WebView2 WebBrowser provider and gives access to WebView2 specific * functionality. */ class _XTP_EXT_CLASS CXTPWebViewProvider : public CXTPWebBrowserProvider { /** @cond */ DECLARE_DYNAMIC(CXTPWebViewProvider) /** @endcond */ friend class CXTPWebViewProviderSpy; public: /** * @brief * Constructs provider object. * @param host The host control interface. */ CXTPWebViewProvider(IXTPWebBrowserHost& host); /** * @brief * Handles provider destruction. */ ~CXTPWebViewProvider(); /** * @brief * Determines if WebView2 implementation is available and can be used. * @return * TRUE if WebView2 implementation is available and can be used, otherwise FALSE. */ static BOOL IsAvailable(); /** * @brief * Executes a JavaScript code. * @param pText Script code text. * @param pvtResult The optional pointer to the variant object that is supposed to receive the * result of the executed script. * @return * S_OK if script execution or its attempt are successful or an error code otherwise. */ virtual HRESULT ExecuteScript(LPCWSTR pText, CComVariant* pvtResult = NULL); protected: /** @cond */ // CXTPWebBrowserProvider overrides virtual HRESULT Initialize(); virtual HRESULT Navigate(LPCTSTR pUrl); virtual HRESULT LoadHtml(LPCTSTR pHtml); virtual HRESULT WaitUntilReady(); virtual void ReleaseBrowser(); virtual BOOL OnHostWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult); virtual void OnCreateBrowser(IUnknown* pObject); virtual void UpdateExternal(); /** @endcond */ private: BOOL OnSize(UINT nType, int cx, int cy); BOOL OnDestroy(); protected: /** @cond */ void ApplyUserAgent(); void HookEvents(); void UnhookEvents(); void Layout(); void SetPendingExternalReady(); void OnExternalReady(); void OnBeforeNavigationStarting(ICoreWebView2NavigationStartingEventArgs* args); void OnBeforeContentLoading(ICoreWebView2ContentLoadingEventArgs* args); void OnBeforeSourceChanged(ICoreWebView2SourceChangedEventArgs* args); void OnBeforeHistoryChanged(IUnknown* args); void OnBeforeNavigationCompleted(ICoreWebView2NavigationCompletedEventArgs* args); void OnBeforeFrameNavigationStarting(ICoreWebView2NavigationStartingEventArgs* args); void OnBeforeFrameNavigationCompleted(ICoreWebView2NavigationCompletedEventArgs* args); void OnBeforeScriptDialogOpening(ICoreWebView2ScriptDialogOpeningEventArgs* args); void OnBeforePermissionRequested(ICoreWebView2PermissionRequestedEventArgs* args); void OnBeforeProcessFailed(ICoreWebView2ProcessFailedEventArgs* args); void OnBeforeNewWindowRequested(ICoreWebView2NewWindowRequestedEventArgs* args); void OnBeforeDocumentTitleChanged(IUnknown* args); void OnBeforeContainsFullScreenElementChanged(IUnknown* args); void OnBeforeWebResourceRequested(ICoreWebView2WebResourceRequestedEventArgs* args); void OnBeforeWindowCloseRequested(IUnknown* args); void OnAfterNavigationStarting(ICoreWebView2NavigationStartingEventArgs* args); void OnAfterContentLoading(ICoreWebView2ContentLoadingEventArgs* args); void OnAfterSourceChanged(ICoreWebView2SourceChangedEventArgs* args); void OnAfterHistoryChanged(IUnknown* args); void OnAfterNavigationCompleted(ICoreWebView2NavigationCompletedEventArgs* args); void OnAfterFrameNavigationStarting(ICoreWebView2NavigationStartingEventArgs* args); void OnAfterFrameNavigationCompleted(ICoreWebView2NavigationCompletedEventArgs* args); void OnAfterScriptDialogOpening(ICoreWebView2ScriptDialogOpeningEventArgs* args); void OnAfterPermissionRequested(ICoreWebView2PermissionRequestedEventArgs* args); void OnAfterProcessFailed(ICoreWebView2ProcessFailedEventArgs* args); void OnAfterNewWindowRequested(ICoreWebView2NewWindowRequestedEventArgs* args); void OnAfterDocumentTitleChanged(IUnknown* args); void OnAfterContainsFullScreenElementChanged(IUnknown* args); void OnAfterWebResourceRequested(ICoreWebView2WebResourceRequestedEventArgs* args); void OnAfterWindowCloseRequested(IUnknown* args); /** @endcond */ private: CXTPWebViewProvider(const CXTPWebViewProvider&); CXTPWebViewProvider& operator=(const CXTPWebViewProvider&); static void StaticInit(); private: # ifndef XTP_USE_WEBVIEW2_STATIC_LIB static HMODULE m_hWebView2Loader; # endif typedef HRESULT(STDAPICALLTYPE* PFNGetAvailableCoreWebView2BrowserVersionString)( PCWSTR browserExecutableFolder, LPWSTR* versionInfo); static PFNGetAvailableCoreWebView2BrowserVersionString m_pfnGetAvailableCoreWebView2BrowserVersionString; typedef HRESULT(STDAPICALLTYPE* PFNCreateCoreWebView2EnvironmentWithOptions)( PCWSTR browserExecutableFolder, PCWSTR userDataFolder, ICoreWebView2EnvironmentOptions* environmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler* environmentCreatedHandler); static PFNCreateCoreWebView2EnvironmentWithOptions m_pfnCreateCoreWebView2EnvironmentWithOptions; ICoreWebView2* m_pWebView; ICoreWebView2Controller* m_pWebViewController; CComVariant* m_pvtScriptResult; BOOL m_bNavigationInitiated; BOOL m_bNavigationCompleted; BOOL m_bPendingExternalReady; CComVariant* m_pvtDummyResult; BOOL m_bControllerCreationHandled; DWORD m_dwUnusedPadding; struct { EventRegistrationToken NavigationStarting; EventRegistrationToken ContentLoading; EventRegistrationToken SourceChanged; EventRegistrationToken HistoryChanged; EventRegistrationToken NavigationCompleted; EventRegistrationToken FrameNavigationStarting; EventRegistrationToken FrameNavigationCompleted; EventRegistrationToken ScriptDialogOpening; EventRegistrationToken PermissionRequested; EventRegistrationToken ProcessFailed; EventRegistrationToken NewWindowRequested; EventRegistrationToken DocumentTitleChanged; EventRegistrationToken ContainsFullScreenElementChanged; EventRegistrationToken WebResourceRequested; EventRegistrationToken WindowCloseRequested; } m_eventTokens; }; # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif /** @endcond */