comparison win/edge.cpp @ 2015:c30f4354966e

Win: Added support for dw_html_javascript_run() using Edge (Chromium). OS/2: Added dw_html_javascript_run() stub for OS/2 so things compile.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 07 Nov 2019 10:12:25 +0000
parents f7acca46f795
children 663d79f28e46
comparison
equal deleted inserted replaced
2014:b1838dd5509a 2015:c30f4354966e
87 } 87 }
88 88
89 case DW_HTML_GOHOME: 89 case DW_HTML_GOHOME:
90 { 90 {
91 // Call the IWebView2WebView object's GoHome function. 91 // Call the IWebView2WebView object's GoHome function.
92 //webview->GoHome(); 92 dw_html_url(hwnd, (char *)DW_HOME_URL);
93 break; 93 break;
94 } 94 }
95 95
96 case DW_HTML_SEARCH: 96 case DW_HTML_SEARCH:
97 { 97 {
145 145
146 /******************************* dw_edge_url() **************************** 146 /******************************* dw_edge_url() ****************************
147 * Displays a URL, or HTML file on disk. 147 * Displays a URL, or HTML file on disk.
148 * 148 *
149 * hwnd = Handle to the window hosting the browser object. 149 * hwnd = Handle to the window hosting the browser object.
150 * webPageName = Pointer to nul-terminated name of the URL/file. 150 * url = Pointer to nul-terminated name of the URL/file.
151 * 151 *
152 * RETURNS: 0 if success, or non-zero if an error. 152 * RETURNS: 0 if success, or non-zero if an error.
153 */ 153 */
154 154
155 int _dw_edge_url(HWND hwnd, LPCWSTR url) 155 int _dw_edge_url(HWND hwnd, LPCWSTR url)
162 162
163 if (webview) 163 if (webview)
164 webview->Navigate(url); 164 webview->Navigate(url);
165 else 165 else
166 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(url)); 166 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(url));
167 return DW_ERROR_NONE;
168 }
169
170 /* These reference functions in dw.c */
171 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL)
172 char* _myWideToUTF8(LPWSTR widestring, void* outbuf);
173 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
174
175 /******************************* dw_edge_javascript_run() ****************************
176 * Runs a javascript in the specified browser context.
177 *
178 * hwnd = Handle to the window hosting the browser object.
179 * script = Pointer to nul-terminated javascript string.
180 * scriptdata = Pointer to user data to be passed to the callback.
181 *
182 * RETURNS: 0 if success, or non-zero if an error.
183 */
184
185 int _dw_edge_javascript_run(HWND hwnd, LPCWSTR script, void *scriptdata)
186 {
187 IWebView2WebView* webview;
188
189 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
190 // we initially attached the browser object to this window.
191 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
192
193 if (webview)
194 webview->ExecuteScript(script,
195 Callback<IWebView2ExecuteScriptCompletedHandler>(
196 [hwnd, scriptdata](HRESULT error, PCWSTR result) -> HRESULT
197 {
198 _wndproc(hwnd, WM_USER + 100, (error == S_OK ? (WPARAM)WideToUTF8((LPWSTR)result) : NULL), (LPARAM)scriptdata);
199 return S_OK;
200 }).Get());
167 return DW_ERROR_NONE; 201 return DW_ERROR_NONE;
168 } 202 }
169 203
170 /************************** edgeWindowProc() ************************* 204 /************************** edgeWindowProc() *************************
171 * Our message handler for our window to host the browser. 205 * Our message handler for our window to host the browser.