-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUICef3Web.cpp
359 lines (304 loc) · 7.9 KB
/
UICef3Web.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include "stdafx.h"
#include "UICef3Web.h"
namespace DuiLib
{
CCef3WebUI::CCef3WebUI(void)
: m_pCef3Callback(NULL)
{
}
CCef3WebUI::~CCef3WebUI(void)
{
LOGPRINTTIMESTAMP(L"CCef3WebUI::~CCef3WebUI");
}
LPCTSTR CCef3WebUI::GetClass() const
{
return _T("UICCef3Web");
}
LPVOID CCef3WebUI::GetInterface( LPCTSTR pstrName )
{
if( _tcscmp(pstrName, _T("Cef3Web")) == 0 )
return static_cast<CCef3WebUI*>(this);
return CControlUI::GetInterface(pstrName);
}
void CCef3WebUI::SetVisible(bool bVisible)
{
CControlUI::SetVisible(bVisible);
if(m_spCefWebBrowser)
m_spCefWebBrowser->SetShow(bVisible?TRUE:FALSE);
}
void CCef3WebUI::SetInternVisible(bool bVisible)
{
CControlUI::SetInternVisible(bVisible);
if(m_spCefWebBrowser)
m_spCefWebBrowser->SetShow(bVisible?TRUE:FALSE);
if (bVisible)
InvalidateBrowserWndRect(&m_rcItem, true);
}
void CCef3WebUI::SetCef3CallBack( CCef3CallBack* pCallBack )
{
if (NULL == m_pCef3Callback)
{
m_pCef3Callback = pCallBack;
}
}
void CCef3WebUI::OpenURL( LPCWSTR lpUrl, BOOL bIgnore404/* = TRUE*/)
{
if(m_spCefWebBrowser)
m_spCefWebBrowser->LoadURL(lpUrl, bIgnore404);
}
void CCef3WebUI::Reload()
{
if(m_spCefWebBrowser)
m_spCefWebBrowser->Reload(FALSE);
}
void CCef3WebUI::GoBack()
{
if (m_spCefWebBrowser)
{
m_spCefWebBrowser->Goback();
}
}
void CCef3WebUI::GoForward()
{
if (m_spCefWebBrowser)
{
m_spCefWebBrowser->GoForward();
}
}
// bool CCef3WebUI::CreateBrowser(LPCTSTR szName, LPRECT rcBrowser)
// {
// if (__super::CreateBrowser(szName, rcBrowser))
// {
// m_spCefWebBrowser->AdvisEvent(this);
// return true;
// }
// return false;
// }
//
// void CCef3WebUI::CloseBrowser()
// {
// if (m_spCefWebBrowser)
// {
// CComQIPtr<ICefBrowser2> spWB2 = m_spCefWebBrowser;
// spWB2->Close();
// }
// }
const HWND CCef3WebUI::GetBrowserHWND() const
{
return m_hBrowerWnd;
}
// void CCef3WebUI::DestroyBrowser()
// {
// if (m_hBrowerWnd)
// {
// if (::IsWindow(m_hBrowerWnd))
// DestroyWindow(m_hBrowerWnd);
// m_hBrowerWnd = NULL;
// }
//
// if (m_spCefWebBrowser)
// m_spCefWebBrowser->AdvisEvent(NULL);
// m_spCefWebBrowser.Release();
//
// m_pCef3Callback = NULL;
// }
void CCef3WebUI::SetPos(RECT rc, bool bNeedInvalidate /*= true*/)
{
__super::SetPos(rc, bNeedInvalidate);
if(m_spCefWebBrowser)
{
m_spCefWebBrowser->AdjustRect(&rc);
}
}
HRESULT CCef3WebUI::CallJSCommonFunc(LPCWSTR lpwsJSFuncName, LPCWSTR lpwsJSFuncParamJson)
{
if (!lpwsJSFuncName || !lpwsJSFuncParamJson)
return E_FAIL;
CString strJSFuncName =lpwsJSFuncName;
CString strJSFuncParamJson = lpwsJSFuncParamJson;
{
strJSFuncName = MakeSafeJSString(lpwsJSFuncName);
strJSFuncParamJson = MakeSafeJSString(lpwsJSFuncParamJson);
}
CString str;
str.Format(L"comm_type_get('%s', '%s')", strJSFuncName, strJSFuncParamJson);
LOGPRINTTIMESTAMP(L"CCef3WebWindow::CallJSCommonFunc %s", (LPCTSTR)str);
return CallJS(str);
}
HRESULT CCef3WebUI::CallJS(LPCWSTR lpwsJS)
{
if(NULL == lpwsJS)
return E_INVALIDARG;
if(m_spCefWebBrowser)
return m_spCefWebBrowser->CallJS(lpwsJS);
return E_FAIL;
}
HRESULT CCef3WebUI::CallJS2(ICefStringArray* lpJS)
{
LOGPRINTTIMESTAMP(L"CCef3WebWindow::[%#X]CallJS2()", (DWORD_PTR)this);
CComQIPtr<ICefBrowser2> spWB2 = m_spCefWebBrowser;
if(!spWB2)
return E_FAIL;
return spWB2->CallJS2(lpJS);
}
HRESULT CCef3WebUI::SelectAll()
{
CComQIPtr<ICefBrowser2> spWB2 = m_spCefWebBrowser;
if(!spWB2)
return E_FAIL;
return spWB2->SelectAll();
}
HRESULT CCef3WebUI::CopySelect()
{
CComQIPtr<ICefBrowser2> spWB2 = m_spCefWebBrowser;
if(!spWB2)
return E_FAIL;
return spWB2->CopySelect();
}
HRESULT CCef3WebUI::Stop()
{
if (!m_spCefWebBrowser)
return E_FAIL;
return m_spCefWebBrowser->Stop();
}
HRESULT CCef3WebUI::LogError(LPCWSTR lpwsId, LPCWSTR lpwsContent, LPCWSTR lpwsError)
{
if (!m_spCefWebBrowser)
return E_FAIL;
return m_spCefWebBrowser->LogError(lpwsId, lpwsContent, lpwsError);
}
STDMETHODIMP CCef3WebUI::OnBrowserCreated(LPCWSTR lpwsFlag)
{
LOGPRINTTIMESTAMP(L"CCef3WebWindow::[%#X]OnBrowserCreated(%s)", (DWORD_PTR)this, lpwsFlag?lpwsFlag:L"NOFLAG");
CComQIPtr<ICefBrowser2> spWB2 = m_spCefWebBrowser;
if(spWB2)
m_hBrowerWnd = spWB2->GetBrowserWindow();
if (m_pCef3Callback )
{
m_pCef3Callback->OnBrowserCreated(this);
}
m_nTimeCreate = ::GetTickCount();
NotifyCreated();
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnLoadError(LPCWSTR lpwsUrl, BOOL bMain, int nError)
{
if (!bMain)
return S_OK;
LOGPRINTTIMESTAMP(L"CCef3WebWindow::[%#X]OnLoadError(%d, %s)", (DWORD_PTR)this, nError, lpwsUrl?lpwsUrl:L"NOURL");
if (m_pCef3Callback )
{
m_pCef3Callback->OnLoadError(nError, this);
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnJSCallCPlus(LPCWSTR lpwsUrl, LPCWSTR lpwsId, LPCWSTR lpwsContent)
{
if (lpwsUrl == NULL || lpwsId == NULL || lpwsContent == NULL)
{
return S_FALSE;
}
LOGPRINTTIMESTAMP(L"CCef3WebUI[%s]::OnJSCallCPlus(%s, %s)[%#X][%s]", GetClass(), lpwsId, lpwsContent, this, lpwsUrl);
if (m_pCef3Callback )
{
m_pCef3Callback->OnJSCallCPlus(lpwsId, lpwsContent, this);
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnLoadHtmlSize(LPCWSTR lpwsUrl, LONGLONG llSize)
{
m_nLoadSize = llSize;
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnSnapShot(IRingBuffer* spBuffer, int nWidth, int nHeight)
{
if (spBuffer)
{
CComPtr<IRingBuffer> spRingBuffer;
spRingBuffer.Attach(spBuffer);
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnBrowserClosed(int)
{
if (m_pCef3Callback)
{
m_pCef3Callback->OnBrowserClosed();
}
NotifyClosed();
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnRenderProcessTerminated(LPCWSTR lpwsUrl, int nStatus, int nReserved)
{
if (m_pCef3Callback)
{
m_pCef3Callback->OnRenderProcessTerminated(lpwsUrl, nStatus);
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnTitleChange(LPCWSTR lpwsTitle)
{
if (m_pCef3Callback)
{
m_pCef3Callback->OnTitleChange(lpwsTitle, this );
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnAddressChange(LPCWSTR lpwsaddress)
{
if (m_pCef3Callback)
{
m_pCef3Callback->OnAddressChange(lpwsaddress, this);
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnGetCookie(LPCWSTR lpcookie)
{
if (m_pCef3Callback)
{
m_pCef3Callback->OnCookie(lpcookie, this);
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnLoadingStateChange(bool bisLoading, bool isgoforure, bool isgoback)
{
if (m_pCef3Callback)
{
m_pCef3Callback->OnLoadingStateChange(this, bisLoading, isgoback, isgoforure);
}
return S_OK;
}
STDMETHODIMP CCef3WebUI::OnLoadEnd(LPCWSTR lpwsUrl, BOOL bMain)
{
if (!bMain)
return S_OK;
LOGPRINTTIMESTAMP(L"CCef3WebWindow::[%#X]OnLoadEnd(%s)", (DWORD_PTR)this, lpwsUrl?lpwsUrl:L"NOURL");
if (m_pCef3Callback )
{
m_pCef3Callback->OnLoadEnd(this);
}
return S_OK;
}
HRESULT CCef3WebUI::CreateCEFStrignArray(ICefStringArray** lppArr)
{
//CComPtr<IServiceModule> spModule;
//HRESULT hr = g_ACTalkApp.GetService(SID_ServiceModule, &spModule);
//if(!spModule)
// return hr;
//CComPtr<ICefStringArray> spCEFStrArray;
//hr = spModule->GetObject(MODULE_ID_ACCEF, CLSID_CefStringArray, __uuidof(ICefStringArray), (LPVOID*)&spCEFStrArray);
//if(!spCEFStrArray)
// return hr;
//return spCEFStrArray.QueryInterface(lppArr);
return S_OK;
}
HRESULT CCef3WebUI::InvalidateBrowserWndRect(LPRECT lprc, BOOL bRedraw)
{
if(m_hBrowerWnd && ::IsWindow(m_hBrowerWnd))
{
::InvalidateRect(m_hBrowerWnd, lprc, bRedraw);
::UpdateWindow(m_hBrowerWnd);
}
return S_OK;
}
}//namespace