Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom JS dialog #44

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions d3d9/d3d9.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ClCompile Include="src\browser\assets.cc" />
<ClCompile Include="src\browser\browser.cc" />
<ClCompile Include="src\browser\devtools.cc" />
<ClCompile Include="src\browser\jsdialog.cc" />
<ClCompile Include="src\browser\riotclient.cc" />
<ClCompile Include="src\browser\server.cc" />
<ClCompile Include="src\browser\window.cc" />
Expand Down
3 changes: 3 additions & 0 deletions d3d9/d3d9.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
<ClCompile Include="src\renderer\auth_callback.cc">
<Filter>src\renderer</Filter>
</ClCompile>
<ClCompile Include="src\browser\jsdialog.cc">
<Filter>src\browser</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="src\renderer\extension.js">
Expand Down
8 changes: 8 additions & 0 deletions d3d9/src/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void SetRiotClientCredentials(const wstring &appPort, const wstring &authToken);
void OpenInternalServer();
void CloseInternalServer();

cef_jsdialog_handler_t *CreateCustomJSDialogHandler();

static decltype(cef_life_span_handler_t::on_after_created) Old_OnAfterCreated;
static void CEF_CALLBACK Hooked_OnAfterCreated(struct _cef_life_span_handler_t* self,
struct _cef_browser_t* browser)
Expand Down Expand Up @@ -154,6 +156,12 @@ static void HookClient(cef_client_t *client)
return handler;
};

static auto GetJSDialogHandler = client->get_jsdialog_handler;
client->get_jsdialog_handler = [](struct _cef_client_t* self)
{
return CreateCustomJSDialogHandler();
};

static auto OnProcessMessageReceived = client->on_process_message_received;
client->on_process_message_received = [](struct _cef_client_t* self,
struct _cef_browser_t* browser,
Expand Down
74 changes: 74 additions & 0 deletions d3d9/src/browser/jsdialog.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "../internal.h"
#include "include/capi/cef_jsdialog_handler_capi.h"

extern HWND rclient_window_;

class CustomJSDialogHandler : public CefRefCount<cef_jsdialog_handler_t>
{
public:
CustomJSDialogHandler() : CefRefCount(this)
{
cef_jsdialog_handler_t::on_jsdialog = on_jsdialog;
cef_jsdialog_handler_t::on_before_unload_dialog = on_before_unload_dialog;
cef_jsdialog_handler_t::on_reset_dialog_state = on_reset_dialog_state;
cef_jsdialog_handler_t::on_dialog_closed = on_dialog_closed;
}

private:
static int CEF_CALLBACK on_jsdialog(struct _cef_jsdialog_handler_t* self,
struct _cef_browser_t* browser,
const cef_string_t* origin_url,
cef_jsdialog_type_t dialog_type,
const cef_string_t* message_text,
const cef_string_t* default_prompt_text,
struct _cef_jsdialog_callback_t* callback,
int* suppress_message)
{
LPCWSTR message = L"";
if (message_text)
message = message_text->str;

if (dialog_type == JSDIALOGTYPE_ALERT)
{
MessageBoxW(rclient_window_, message, L"League of Legends Client", MB_ICONINFORMATION | MB_OK);
callback->cont(callback, 0, nullptr);
return true;
}
else if (dialog_type == JSDIALOGTYPE_CONFIRM)
{
int ret = MessageBoxW(rclient_window_, message, L"League of Legends Client", MB_ICONQUESTION | MB_YESNO);
callback->cont(callback, ret == IDYES, nullptr);
return true;
}

return 0;
}

static int CEF_CALLBACK on_before_unload_dialog(
struct _cef_jsdialog_handler_t* self,
struct _cef_browser_t* browser,
const cef_string_t* message_text,
int is_reload,
struct _cef_jsdialog_callback_t* callback)
{
return 0;
}

static void CEF_CALLBACK on_reset_dialog_state(
struct _cef_jsdialog_handler_t* self,
struct _cef_browser_t* browser)
{

}

static void CEF_CALLBACK on_dialog_closed(struct _cef_jsdialog_handler_t* self,
struct _cef_browser_t* browser)
{

}
};

cef_jsdialog_handler_t *CreateCustomJSDialogHandler()
{
return new CustomJSDialogHandler();
}