Batch #15497 by youko: 0 byte-identical, 1 confirmed by peer review. - fn_17433 CWebEventReceiver::Invoke: logic confirmed by peer review Peer-reviewed-by: eAthena, Yommy, kyoshi Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
194 lines
4.9 KiB
C++
194 lines
4.9 KiB
C++
#include "Client/Browser/WebBrowser.h"
|
|
#include "Client/Browser/WebEventReceiver.h"
|
|
#include "UI/Window/UIWindowMgr.h"
|
|
|
|
#include <exdispid.h>
|
|
#include <mshtmdid.h>
|
|
|
|
#include <mshtml.h>
|
|
|
|
// OFFSET: 0x00AB3710
|
|
// FUNCTION: fn_17424
|
|
CWebEventReceiver::CWebEventReceiver()
|
|
: m_references(0), m_browser(nullptr), m_browserCookie(0), m_document(nullptr), m_documentCookie(0), m_host(nullptr) {
|
|
OutputDebugStringA("CWebEventReceiver() \n");
|
|
}
|
|
|
|
// OFFSET: 0x00AB38A0
|
|
// FUNCTION: fn_17425
|
|
CWebEventReceiver::~CWebEventReceiver() {
|
|
OutputDebugStringA("~CWebEventReceiver() \n");
|
|
}
|
|
|
|
// OFFSET: 0x00AB3AE0
|
|
// FUNCTION: fn_17432
|
|
bool CWebEventReceiver::Register(IWebBrowser2* browser, HWND host) {
|
|
this->m_browser = browser;
|
|
this->m_host = host;
|
|
this->m_browser->AddRef();
|
|
|
|
return SUCCEEDED(AdviseBrowserEvents(this->m_browser, this, DIID_DWebBrowserEvents2, &this->m_browserCookie));
|
|
}
|
|
|
|
// OFFSET: 0x00AB3F30
|
|
// FUNCTION: fn_17434
|
|
HRESULT STDMETHODCALLTYPE CWebEventReceiver::QueryInterface(REFIID iid, void** output) {
|
|
if (iid != IID_IUnknown && iid != IID_IDispatch) {
|
|
return E_NOINTERFACE;
|
|
}
|
|
|
|
*output = static_cast<IDispatch*>(this);
|
|
static_cast<IUnknown*>(*output)->AddRef();
|
|
return S_OK;
|
|
}
|
|
|
|
// OFFSET: 0x00AB38F0
|
|
// FUNCTION: fn_17426
|
|
ULONG STDMETHODCALLTYPE CWebEventReceiver::AddRef() {
|
|
return InterlockedIncrement(&this->m_references);
|
|
}
|
|
|
|
// OFFSET: 0x00AB4020
|
|
// FUNCTION: fn_17435
|
|
ULONG STDMETHODCALLTYPE CWebEventReceiver::Release() {
|
|
const LONG references = InterlockedDecrement(&this->m_references);
|
|
if (references <= 0) {
|
|
delete this;
|
|
}
|
|
|
|
return static_cast<ULONG>(references);
|
|
}
|
|
|
|
// OFFSET: 0x00AB3AD0
|
|
// FUNCTION: fn_17431
|
|
HRESULT STDMETHODCALLTYPE CWebEventReceiver::GetTypeInfoCount(UINT*) {
|
|
return S_OK;
|
|
}
|
|
|
|
// OFFSET: 0x00AB3AC0
|
|
// FUNCTION: fn_17430
|
|
HRESULT STDMETHODCALLTYPE CWebEventReceiver::GetTypeInfo(UINT, LCID, ITypeInfo**) {
|
|
return S_OK;
|
|
}
|
|
|
|
// OFFSET: 0x00AB3AB0
|
|
// FUNCTION: fn_17429
|
|
HRESULT STDMETHODCALLTYPE CWebEventReceiver::GetIDsOfNames(REFIID, LPOLESTR*, UINT, LCID, DISPID*) {
|
|
return S_OK;
|
|
}
|
|
|
|
// INLINED
|
|
void CWebEventReceiver::ReleaseDocument() {
|
|
if (this->m_document) {
|
|
UnadviseBrowserEvents(this->m_document, DIID_HTMLDocumentEvents2, this->m_documentCookie);
|
|
this->m_document->Release();
|
|
this->m_document = nullptr;
|
|
this->m_documentCookie = 0;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00AB3FA0
|
|
// FUNCTION: fn_45418
|
|
HRESULT __stdcall CWebEventReceiver::Disconnect() {
|
|
this->ReleaseDocument();
|
|
if (this->m_browser) {
|
|
this->m_browser->Stop();
|
|
UnadviseBrowserEvents(this->m_browser, DIID_DWebBrowserEvents2, this->m_browserCookie);
|
|
this->m_browser->Release();
|
|
this->m_browser = nullptr;
|
|
}
|
|
|
|
g_windowMgr.RemoveBrowser(this->m_host);
|
|
return S_OK;
|
|
}
|
|
|
|
// OFFSET: 0x00AB3B20
|
|
// FUNCTION: fn_17433
|
|
HRESULT STDMETHODCALLTYPE CWebEventReceiver::Invoke(DISPID id, REFIID, LCID, WORD, DISPPARAMS* args, VARIANT*, EXCEPINFO*, UINT*) {
|
|
switch (id) {
|
|
case DISPID_HTMLDOCUMENTEVENTS2_ONKEYDOWN: {
|
|
IHTMLEventObj* event = nullptr;
|
|
if (FAILED(args->rgvarg[0].pdispVal->QueryInterface(IID_IHTMLEventObj, reinterpret_cast<void**>(&event)))) {
|
|
break;
|
|
}
|
|
|
|
long key = 0;
|
|
if (FAILED(event->get_keyCode(&key))) {
|
|
break;
|
|
}
|
|
|
|
switch (key) {
|
|
case VK_MENU:
|
|
case VK_F1:
|
|
case VK_F3:
|
|
case VK_F4:
|
|
case VK_F11: {
|
|
event->put_keyCode(0);
|
|
|
|
VARIANT cancelled;
|
|
cancelled.vt = VT_BOOL;
|
|
cancelled.boolVal = VARIANT_FALSE;
|
|
event->put_returnValue(cancelled);
|
|
event->Release();
|
|
return S_FALSE;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
case DISPID_HTMLDOCUMENTEVENTS2_ONHELP: {
|
|
IHTMLEventObj* event = nullptr;
|
|
if (FAILED(args->rgvarg[0].pdispVal->QueryInterface(IID_IHTMLEventObj, reinterpret_cast<void**>(&event)))) {
|
|
break;
|
|
}
|
|
|
|
event->put_keyCode(0);
|
|
|
|
VARIANT cancelled;
|
|
cancelled.vt = VT_BOOL;
|
|
cancelled.boolVal = VARIANT_FALSE;
|
|
event->put_returnValue(cancelled);
|
|
event->Release();
|
|
break;
|
|
}
|
|
|
|
case DISPID_ONQUIT:
|
|
this->Disconnect();
|
|
break;
|
|
|
|
case DISPID_HTMLDOCUMENTEVENTS2_ONCONTEXTMENU: {
|
|
IHTMLEventObj* event = nullptr;
|
|
if (FAILED(args->rgvarg[0].pdispVal->QueryInterface(IID_IHTMLEventObj, reinterpret_cast<void**>(&event)))) {
|
|
break;
|
|
}
|
|
|
|
VARIANT cancelled;
|
|
cancelled.vt = VT_BOOL;
|
|
cancelled.boolVal = VARIANT_FALSE;
|
|
event->put_returnValue(cancelled);
|
|
event->Release();
|
|
break;
|
|
}
|
|
|
|
case DISPID_DOCUMENTCOMPLETE: {
|
|
IDispatch* browserIdentity = nullptr;
|
|
if (FAILED(this->m_browser->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(&browserIdentity)))) {
|
|
break;
|
|
}
|
|
|
|
if (args->rgvarg[1].pdispVal != browserIdentity) {
|
|
break;
|
|
}
|
|
|
|
this->ReleaseDocument();
|
|
if (SUCCEEDED(this->m_browser->get_Document(&this->m_document)) && this->m_document) {
|
|
AdviseBrowserEvents(this->m_document, this, DIID_HTMLDocumentEvents2, &this->m_documentCookie);
|
|
}
|
|
|
|
browserIdentity->Release();
|
|
break;
|
|
}
|
|
}
|
|
|
|
return S_OK;
|
|
}
|