comparison win/edge.cpp @ 2625:2e804b4db81e

Win: Standardize internal function name style...
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 27 Jul 2021 23:09:52 +0000
parents d3974aa8ad64
children f99414164f5b
comparison
equal deleted inserted replaced
2624:42cacc1a1783 2625:2e804b4db81e
17 #define _DW_HTML_DATA_RAW "_dw_edge_raw" 17 #define _DW_HTML_DATA_RAW "_dw_edge_raw"
18 18
19 extern "C" { 19 extern "C" {
20 20
21 /* Import the character conversion functions from dw.c */ 21 /* Import the character conversion functions from dw.c */
22 LPWSTR _myUTF8toWide(const char* utf8string, void* outbuf); 22 LPWSTR _dw_UTF8toWide(const char* utf8string, void* outbuf);
23 char* _myWideToUTF8(LPCWSTR widestring, void* outbuf); 23 char* _dw_WideToUTF8(LPCWSTR widestring, void* outbuf);
24 #define UTF8toWide(a) _myUTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL) 24 #define UTF8toWide(a) _dw_UTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL)
25 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL) 25 #define WideToUTF8(a) _dw_WideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL)
26 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); 26 LRESULT CALLBACK _dw_wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
27 void _DWCreateJunction(LPWSTR source, LPWSTR target); 27 void _dw_create_junction(LPWSTR source, LPWSTR target);
28 LPWSTR _DWGetEdgeStablePath(void); 28 LPWSTR _dw_get_edge_stable_path(void);
29 } 29 }
30 30
31 class EdgeBrowser 31 class EdgeBrowser
32 { 32 {
33 public: 33 public:
114 ICoreWebView2NavigationStartingEventArgs* args) -> HRESULT 114 ICoreWebView2NavigationStartingEventArgs* args) -> HRESULT
115 { 115 {
116 LPWSTR uri; 116 LPWSTR uri;
117 sender->get_Source(&uri); 117 sender->get_Source(&uri);
118 118
119 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), 119 _dw_wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED),
120 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); 120 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri));
121 121
122 return S_OK; 122 return S_OK;
123 }).Get(), &token); 123 }).Get(), &token);
124 124
129 ICoreWebView2SourceChangedEventArgs* args) -> HRESULT 129 ICoreWebView2SourceChangedEventArgs* args) -> HRESULT
130 { 130 {
131 LPWSTR uri; 131 LPWSTR uri;
132 sender->get_Source(&uri); 132 sender->get_Source(&uri);
133 133
134 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), 134 _dw_wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT),
135 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); 135 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri));
136 136
137 return S_OK; 137 return S_OK;
138 }).Get(), &token); 138 }).Get(), &token);
139 139
144 ICoreWebView2ContentLoadingEventArgs* args) -> HRESULT 144 ICoreWebView2ContentLoadingEventArgs* args) -> HRESULT
145 { 145 {
146 LPWSTR uri; 146 LPWSTR uri;
147 sender->get_Source(&uri); 147 sender->get_Source(&uri);
148 148
149 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), 149 _dw_wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING),
150 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); 150 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri));
151 151
152 return S_OK; 152 return S_OK;
153 }).Get(), &token); 153 }).Get(), &token);
154 154
159 ICoreWebView2NavigationCompletedEventArgs* args) -> HRESULT 159 ICoreWebView2NavigationCompletedEventArgs* args) -> HRESULT
160 { 160 {
161 LPWSTR uri; 161 LPWSTR uri;
162 sender->get_Source(&uri); 162 sender->get_Source(&uri);
163 163
164 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), 164 _dw_wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE),
165 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); 165 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri));
166 166
167 return S_OK; 167 return S_OK;
168 }).Get(), &token); 168 }).Get(), &token);
169 } 169 }
253 253
254 wcscpy(edgepath, tempdir); 254 wcscpy(edgepath, tempdir);
255 wcscat(edgepath, L"EdgeStable"); 255 wcscat(edgepath, L"EdgeStable");
256 256
257 // Create the NTFS junction to get around Microsoft's path blacklist 257 // Create the NTFS junction to get around Microsoft's path blacklist
258 _DWCreateJunction(_DWGetEdgeStablePath(), edgepath); 258 _dw_create_junction(_dw_get_edge_stable_path(), edgepath);
259 259
260 CreateCoreWebView2EnvironmentWithOptions(edgepath, tempdir, nullptr, 260 CreateCoreWebView2EnvironmentWithOptions(edgepath, tempdir, nullptr,
261 Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>( 261 Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
262 [this](HRESULT result, ICoreWebView2Environment* env) -> HRESULT { 262 [this](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
263 // Successfully created Edge environment, return TRUE 263 // Successfully created Edge environment, return TRUE
358 if(end) 358 if(end)
359 *end = '\0'; 359 *end = '\0';
360 scriptresult++; 360 scriptresult++;
361 } 361 }
362 void *params[2] = { (void *)scriptresult, DW_INT_TO_POINTER((error == S_OK ? DW_ERROR_NONE : DW_ERROR_UNKNOWN)) }; 362 void *params[2] = { (void *)scriptresult, DW_INT_TO_POINTER((error == S_OK ? DW_ERROR_NONE : DW_ERROR_UNKNOWN)) };
363 _wndproc(thishwnd, WM_USER + 100, (WPARAM)params, (LPARAM)scriptdata); 363 _dw_wndproc(thishwnd, WM_USER + 100, (WPARAM)params, (LPARAM)scriptdata);
364 return S_OK; 364 return S_OK;
365 }).Get()); 365 }).Get());
366 return DW_ERROR_NONE; 366 return DW_ERROR_NONE;
367 } 367 }
368 368
383 383
384 extern "C" { 384 extern "C" {
385 // Create a junction to Edge Stable current version so we can load it... 385 // Create a junction to Edge Stable current version so we can load it...
386 // For now we are using CreateProcess() to execute the mklink command... 386 // For now we are using CreateProcess() to execute the mklink command...
387 // May switch to using C code but that seems to be overly complicated 387 // May switch to using C code but that seems to be overly complicated
388 void _DWCreateJunction(LPWSTR source, LPWSTR target) 388 void _dw_create_junction(LPWSTR source, LPWSTR target)
389 { 389 {
390 // Command line must be at least 2 MAX_PATHs and "cmd /c mklink /J "<path1>" "<path2>"" (22) and a NULL 390 // Command line must be at least 2 MAX_PATHs and "cmd /c mklink /J "<path1>" "<path2>"" (22) and a NULL
391 WCHAR cmdLine[(MAX_PATH*2)+23] = L"cmd /c mklink /J \""; 391 WCHAR cmdLine[(MAX_PATH*2)+23] = L"cmd /c mklink /J \"";
392 STARTUPINFO si = {sizeof(si)}; 392 STARTUPINFO si = {sizeof(si)};
393 PROCESS_INFORMATION pi = {0}; 393 PROCESS_INFORMATION pi = {0};
416 CloseHandle(pi.hProcess); 416 CloseHandle(pi.hProcess);
417 CloseHandle(pi.hThread); 417 CloseHandle(pi.hThread);
418 } 418 }
419 419
420 // Return the path the the current Edge Stable version 420 // Return the path the the current Edge Stable version
421 LPWSTR _DWGetEdgeStablePath(void) 421 LPWSTR _dw_get_edge_stable_path(void)
422 { 422 {
423 HKEY hKey; 423 HKEY hKey;
424 WCHAR szBuffer[100] = {0}; 424 WCHAR szBuffer[100] = {0};
425 DWORD dwBufferSize = sizeof(szBuffer); 425 DWORD dwBufferSize = sizeof(szBuffer);
426 static WCHAR EdgeStablePath[MAX_PATH+1] = {0}; 426 static WCHAR EdgeStablePath[MAX_PATH+1] = {0};
550 550
551 /************************** edgeWindowProc() ************************* 551 /************************** edgeWindowProc() *************************
552 * Our message handler for our window to host the browser. 552 * Our message handler for our window to host the browser.
553 */ 553 */
554 554
555 LRESULT CALLBACK _edgeWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 555 LRESULT CALLBACK _dw_edgewndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
556 { 556 {
557 if (DW_EDGE) 557 if (DW_EDGE)
558 return DW_EDGE->WndProc(hWnd, uMsg, wParam, lParam); 558 return DW_EDGE->WndProc(hWnd, uMsg, wParam, lParam);
559 return DefWindowProc(hWnd, uMsg, wParam, lParam); 559 return DefWindowProc(hWnd, uMsg, wParam, lParam);
560 } 560 }