forked from ThinBridge/Chronos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_app.cpp
253 lines (231 loc) · 7.55 KB
/
client_app.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
#include "StdAfx.h"
#include "client_app.h"
#include "client_util.h"
#include "Sazabi.h"
ClientApp::ClientApp(void)
{
}
ClientApp::ClientApp(HWND hWnd)
{
}
ClientApp::~ClientApp(void)
{
}
void ClientApp::OnContextInitialized()
{
REQUIRE_UI_THREAD()
}
void ClientApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
{
PROC_TIME(OnBeforeCommandLineProcessing)
//GetAuthCredentialsが動かなくなったので2019-06-13
//command_line->AppendSwitchWithValue(_T("disable-features"), _T("NetworkService"));
//2019-07-24 動くようになった。
//Chromium Embedded Framework Version 75.1.4+g4210896+chromium-75.0.3770.100
//2020-09-16
//https://bitbucket.org/chromiumembedded/cef/issues/2989/m85-print-preview-fails-to-load-pdf-file
//CEF 85.3.6+gacfac2f+chromium-85.0.4183.102 / Chromium 85.0.4183.102
//CEF 84まではOKだった。
//--enable-print-preview
command_line->AppendSwitch(_T("enable-print-preview"));
//--disk-cache-size=536870912 512MB
command_line->AppendSwitchWithValue(_T("disk-cache-size"), _T("536870912")); //512MB
command_line->AppendSwitchWithValue(_T("media-cache-size"), _T("209715200")); //200MB
// //enable-net-security-expiration
// command_line->AppendSwitch(_T("enable-net-security-expiration"));
//"enable-media-stream"
//localhostだけはOK、その他は許可する方法が不明
//command_line->AppendSwitch(_T("enable-media-stream"));
// m_Command_line = CefCommandLine::CreateCommandLine();
// m_Command_line->InitFromString(::GetCommandLineW());
// //--single-process --ppapi-in-process
// command_line->AppendSwitch(_T("disable-extensions"));
//command_line->AppendSwitchWithValue(_T("proxy-server"),_T("127.0.0.1:8080"));
//pdf
if (!theApp.m_AppSettings.IsEnablePDFExtension())
command_line->AppendSwitch(_T("disable-pdf-extension"));
////flash
//2020-12-31 EOL
//if(theApp.m_AppSettings.IsEnableFlashPlayer())
//{
// command_line->AppendSwitch(_T("enable-system-flash"));
//}
//MemCache
if (theApp.m_AppSettings.IsEnableMemcache())
{
command_line->AppendSwitch(_T("disable-gpu-shader-disk-cache"));
}
//gpu
if (!theApp.m_AppSettings.IsGPURendering())
{
command_line->AppendSwitch(_T("disable-gpu"));
command_line->AppendSwitch(_T("disable-gpu-compositing"));
command_line->AppendSwitch(_T("enable-begin-frame-scheduling"));
}
//else
//{
// command_line->AppendSwitchWithValue(_T("enable-gpu-rasterization"),_T("Enabled"));
// command_line->AppendSwitchWithValue(_T("num-raster-threads"), _T("4"));
// command_line->AppendSwitch(_T("disable-accelerated-2d-canvas"));
// command_line->AppendSwitch(_T("disable-gpu-compositing"));
// command_line->AppendSwitch(_T("disable-gpu-driver-bug-workarounds"));
// command_line->AppendSwitch(_T("disable-gpu-rasterization"));
// command_line->AppendSwitch(_T("disable-gpu-sandbox"));
// command_line->AppendSwitch(_T("disable-gpu-shader-disk-cache"));
// command_line->AppendSwitch(_T("disable-native-gpu-memory-buffers"));
// command_line->AppendSwitch(_T("disable-gpu-early-init"));
// command_line->AppendSwitch(_T("disable-gpu-memory-buffer-compositor-resources"));
//}
//Proxy Settings
CString strProxyName;
//独自のProxyルールをセット
//Direct
if (theApp.m_AppSettings.GetProxyType() == CSG_PROXY_NA)
{
command_line->AppendSwitch(_T("no-proxy-server"));
}
//IE依存
else if (theApp.m_AppSettings.GetProxyType() == CSG_PROXY_IE)
{
;
}
//Proxy
else if (theApp.m_AppSettings.GetProxyType() == CSG_PROXY_TF)
{
strProxyName = theApp.m_AppSettings.GetProxyAddress();
if (!strProxyName.IsEmpty())
{
//pacを利用
if (SBUtil::IsURL_HTTP(strProxyName) || SBUtil::IsURL_FILE(strProxyName))
{
command_line->AppendSwitchWithValue(_T("proxy-pac-url"), (LPCTSTR)strProxyName);
}
else
{
command_line->AppendSwitchWithValue(_T("proxy-server"), (LPCTSTR)strProxyName);
//Proxy Bypass Name
CString strProxyBypassName = theApp.m_AppSettings.GetProxyBypassAddress();
strProxyBypassName.TrimLeft();
strProxyBypassName.TrimRight();
if (!strProxyBypassName.IsEmpty())
command_line->AppendSwitchWithValue(_T("proxy-bypass-list"), (LPCTSTR)strProxyBypassName);
}
}
}
}
void ClientApp::OnScheduleMessagePumpWork(int64_t delayMs)
{
MessageLoopWorker* messageLoopWorker = theApp.m_pMessageLoopWorker;
if (!messageLoopWorker)
return;
messageLoopWorker->PostScheduleMessage(delayMs);
}
void DownloadFaviconCB::OnDownloadImageFinished(const CefString& image_url,
int http_status_code,
CefRefPtr<CefImage> image)
{
REQUIRE_UI_THREAD();
if (image == NULL || image->IsEmpty())
{
theApp.SetDefaultFavicon(m_pwndFrame);
}
else
{
CefRefPtr<CefBinaryValue> value;
float scale_factor = 1.0;
int pixel_width = 0;
int pixel_height = 0;
value = image->GetAsPNG(scale_factor, true, pixel_width, pixel_height);
size_t iSize = 0;
iSize = value->GetSize();
std::vector<unsigned char> data(iSize);
value->GetData(&data[0], iSize, 0);
HRESULT hr = {0};
IStream* pIStream = NULL;
hr = ::CreateStreamOnHGlobal(NULL, TRUE, &pIStream);
if (SUCCEEDED(hr) && pIStream)
{
hr = pIStream->Write(&data[0], (ULONG)iSize, NULL);
CImage pngImage_src;
// メモリ上からビットマップファイルを読み込む
pngImage_src.Load(pIStream);
//// 確認用Save
if (theApp.m_AppSettings.IsAdvancedLogMode())
{
CefURLParts cfURLparts;
if (CefParseURL(image_url, cfURLparts))
{
//CefString cfScheme(&cfURLparts.scheme);
CefString cfHost(&cfURLparts.host);
CefString cfPath(&cfURLparts.path);
//CString strScheme((LPCWSTR)cfScheme.c_str());
CString strHost((LPCWSTR)cfHost.c_str());
CString strPath((LPCWSTR)cfPath.c_str());
CString strFileName;
strFileName += strHost;
//strFileName += _T("");
strFileName += strPath;
strFileName += _T(".png");
//ファイル名に使えない文字を置き換える。
strFileName = SBUtil::GetValidFileName(strFileName);
CString strFullPath;
strFullPath = theApp.m_strFaviconCachePath;
strFullPath += strFileName;
pngImage_src.Save(strFullPath, Gdiplus::ImageFormatPNG);
}
}
if (!pngImage_src.IsNull())
{
theApp.SetFavicon(&pngImage_src, m_pwndFrame);
}
pIStream->Release();
}
}
}
void DownloadImageCopyClipboard::OnDownloadImageFinished(const CefString& image_url,
int http_status_code,
CefRefPtr<CefImage> image)
{
REQUIRE_UI_THREAD();
if (image == NULL || image->IsEmpty())
{
return;
}
else
{
CefRefPtr<CefBinaryValue> value;
float scale_factor = 1.0;
int pixel_width = 0;
int pixel_height = 0;
value = image->GetAsPNG(scale_factor, true, pixel_width, pixel_height);
size_t iSize = 0;
iSize = value->GetSize();
std::vector<unsigned char> data(iSize);
value->GetData(&data[0], iSize, 0);
HRESULT hr = {0};
try
{
if (::OpenClipboard(NULL))
{
HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, iSize);
if (hGlobal != NULL)
{
BYTE* pData = (BYTE*)::GlobalLock(hGlobal);
if (pData != NULL)
{
::memcpy(pData, (LPCTSTR)&data[0], iSize);
::GlobalUnlock(hGlobal);
::EmptyClipboard();
if (!::SetClipboardData(RegisterClipboardFormat(L"PNG"), hGlobal))
::GlobalFree(hGlobal);
}
}
::CloseClipboard();
}
}
catch (...)
{
return;
}
}
}