WebView2 added as embedded browser

This commit is contained in:
d1str4ught
2025-08-23 03:32:06 +02:00
parent 18b92aaeb6
commit d10ee0fc26
46 changed files with 114423 additions and 1785 deletions

View File

@@ -9,7 +9,6 @@ set_target_properties(UserInterface PROPERTIES LINK_FLAGS "/level='requireAdmini
)
target_link_libraries(UserInterface
CWebBrowser
Discord
EffectLib
EterBase
@@ -34,6 +33,7 @@ target_link_libraries(UserInterface
SpeedTree
MilesSoundSystem
Python
WebView
ws2_32
strmiids

View File

@@ -1,10 +1,9 @@
#include "StdAfx.h"
#include "../eterBase/Error.h"
#include "../eterlib/Camera.h"
#include "../eterlib/AttributeInstance.h"
#include "../gamelib/AreaTerrain.h"
#include "../EterGrnLib/Material.h"
#include "../CWebBrowser/CWebBrowser.h"
#include "eterBase/Error.h"
#include "eterlib/Camera.h"
#include "eterlib/AttributeInstance.h"
#include "gamelib/AreaTerrain.h"
#include "EterGrnLib/Material.h"
#include "resource.h"
#include "PythonApplication.h"
@@ -1386,8 +1385,6 @@ void CPythonApplication::Clear()
void CPythonApplication::Destroy()
{
WebBrowser_Destroy();
// SphereMap
CGrannyMaterial::DestroySphereMap();

View File

@@ -1,7 +1,6 @@
#include "StdAfx.h"
#include "PythonApplication.h"
#include "../eterlib/Camera.h"
#include "../CWebBrowser/CWebBrowser.h"
#include "Eterlib/Camera.h"
#include <winuser.h>
@@ -180,7 +179,7 @@ LRESULT CPythonApplication::WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam
return 0;
case 0x20a:
if (WebBrowser_IsVisible())
if (CPythonApplication::Instance().IsWebPageMode())
{
// 웹브라우저 상태일때는 휠 작동 안되도록 처리
}

View File

@@ -1,46 +1,123 @@
#include "StdAfx.h"
#include "PythonApplication.h"
#include "../CWebBrowser/CWebBrowser.h"
#undef C8
#include <wrl.h>
#include <wil/com.h>
#include <WebView2.h>
#include <WebView2EnvironmentOptions.h>
#include <shlobj.h>
#include <filesystem>
#include <locale>
#include <codecvt>
static wil::com_ptr<ICoreWebView2> gs_webView;
static wil::com_ptr<ICoreWebView2Controller> gs_webViewController;
using convert_type = std::codecvt_utf8<wchar_t>;
static std::wstring_convert<convert_type, wchar_t> converter;
bool CPythonApplication::IsWebPageMode()
{
return WebBrowser_IsVisible() ? true : false;
return gs_webViewController.get();
}
void CPythonApplication::ShowWebPage(const char* c_szURL, const RECT& c_rcWebPage)
{
if (WebBrowser_IsVisible())
return;
SetCursorMode(CURSOR_MODE_HARDWARE);
m_grpDevice.EnableWebBrowserMode(c_rcWebPage);
if (!WebBrowser_Show(GetWindowHandle(), c_szURL, &c_rcWebPage))
PWSTR path_tmp;
SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &path_tmp);
std::filesystem::path tempPath = std::filesystem::temp_directory_path();
tempPath /= "Metin2";
tempPath /= "WebCache";
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
{
TraceError("CREATE_WEBBROWSER_ERROR:%d", GetLastError());
Microsoft::WRL::ComPtr<ICoreWebView2EnvironmentOptions6> options6;
if (options.As(&options6) == S_OK) {
options6->put_AreBrowserExtensionsEnabled(FALSE);
}
}
SetCursorMode(CURSOR_MODE_HARDWARE);
std::wstring stURL = converter.from_bytes(c_szURL);
CreateCoreWebView2EnvironmentWithOptions(nullptr, tempPath.c_str(), options.Get(),
Microsoft::WRL::Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
[handle = GetWindowHandle(), stURL, myRect = c_rcWebPage](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWnd
env->CreateCoreWebView2Controller(handle, Microsoft::WRL::Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
[stURL, myRect](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {
if (controller != nullptr) {
gs_webViewController = controller;
gs_webViewController->get_CoreWebView2(&gs_webView);
}
if (!gs_webView) {
TraceError("failed to get controller for webview, result: 0x%X", result);
return -1;
}
// Add a few settings for the webview
// The demo step is redundant since the values are the default settings
#ifdef _LIVE
wil::com_ptr<ICoreWebView2Settings> baseSettings;
gs_webView->get_Settings(&baseSettings);
auto settings = baseSettings.try_query< ICoreWebView2Settings3>();
if (settings) {
settings->put_AreDevToolsEnabled(FALSE);
settings->put_AreDefaultContextMenusEnabled(FALSE);
settings->put_AreBrowserAcceleratorKeysEnabled(FALSE);
settings->put_IsZoomControlEnabled(FALSE);
}
#endif
// Resize WebView to fit the bounds of the parent window
gs_webViewController->put_Bounds(myRect);
// Schedule an async task to navigate to Bing
gs_webView->Navigate(stURL.c_str());
// <NavigationEvents>
// Step 4 - Navigation events
// register an ICoreWebView2NavigationStartingEventHandler to cancel any non-https navigation
EventRegistrationToken token;
gs_webView->add_NavigationStarting(Microsoft::WRL::Callback<ICoreWebView2NavigationStartingEventHandler>(
[](ICoreWebView2* gs_webView, ICoreWebView2NavigationStartingEventArgs* args) -> HRESULT {
wil::unique_cotaskmem_string uri;
args->get_Uri(&uri);
std::wstring source(uri.get());
if (source.substr(0, 5) != L"https") {
args->put_Cancel(TRUE);
}
return S_OK;
}).Get(), &token);
// </NavigationEvents>
return S_OK;
}).Get());
return S_OK;
}).Get());
}
void CPythonApplication::MoveWebPage(const RECT& c_rcWebPage)
{
if (WebBrowser_IsVisible())
{
m_grpDevice.MoveWebBrowserRect(c_rcWebPage);
WebBrowser_Move(&c_rcWebPage);
}
if (gs_webViewController)
gs_webViewController->put_Bounds(c_rcWebPage);
}
void CPythonApplication::HideWebPage()
{
if (WebBrowser_IsVisible())
{
WebBrowser_Hide();
if (gs_webView)
gs_webView.reset();
m_grpDevice.DisableWebBrowserMode();
if (gs_webViewController)
gs_webViewController.reset();
if (m_pySystem.IsSoftwareCursor())
SetCursorMode(CURSOR_MODE_SOFTWARE);
else
SetCursorMode(CURSOR_MODE_HARDWARE);
}
if (m_pySystem.IsSoftwareCursor())
SetCursorMode(CURSOR_MODE_SOFTWARE);
else
SetCursorMode(CURSOR_MODE_HARDWARE);
}

View File

@@ -9,10 +9,9 @@
#include <crtdbg.h>
#endif
#include "../eterPack/EterPackManager.h"
#include "../eterLib/Util.h"
#include "../CWebBrowser/CWebBrowser.h"
#include "../eterBase/CPostIt.h"
#include "eterPack/EterPackManager.h"
#include "eterLib/Util.h"
#include "eterBase/CPostIt.h"
#include "CheckLatestFiles.h"
@@ -637,8 +636,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
}
#endif
WebBrowser_Startup(hInstance);
if (!CheckPythonLibraryFilenames())
{
__ErrorPythonLibraryIsNotExist();
@@ -651,8 +648,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
GameGuard_NoticeMessage();
#endif
WebBrowser_Cleanup();
::CoUninitialize();
if(gs_szErrorString[0])