# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1573121545 0 # Node ID c30f4354966ea1fc1447e4a09ead310ee9509666 # Parent b1838dd5509a2efd523d2981f0ef2389b6834773 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. diff -r b1838dd5509a -r c30f4354966e os2/dw.c --- a/os2/dw.c Thu Nov 07 08:11:28 2019 +0000 +++ b/os2/dw.c Thu Nov 07 10:12:25 2019 +0000 @@ -12863,6 +12863,24 @@ } /* + * Executes the javascript contained in "script" in the HTML window. + * Parameters: + * handle: Handle to the HTML window. + * script: Javascript code to execute. + * scriptdata: Data passed to the signal handler. + * Notes: A DW_SIGNAL_HTML_RESULT event will be raised with scriptdata. + * Returns: + * DW_ERROR_NONE (0) on success. + */ +int dw_html_javascript_run(HWND handle, char *script, void *scriptdata) +{ + handle = handle; + script = script; + scriptdata = scriptdata; + return DW_ERROR_UNKNOWN; +} + +/* * Create a new HTML window (widget) to be packed. * Not available under OS/2, eCS * Parameters: diff -r b1838dd5509a -r c30f4354966e os2/dw.def --- a/os2/dw.def Thu Nov 07 08:11:28 2019 +0000 +++ b/os2/dw.def Thu Nov 07 10:12:25 2019 +0000 @@ -304,6 +304,7 @@ dw_html_action @471 dw_html_raw @472 dw_html_url @473 + dw_html_javascript_run @474 dw_calendar_new @480 dw_calendar_set_date @481 diff -r b1838dd5509a -r c30f4354966e win/browser.c --- a/win/browser.c Thu Nov 07 08:11:28 2019 +0000 +++ b/win/browser.c Thu Nov 07 10:12:25 2019 +0000 @@ -1421,7 +1421,20 @@ } +/******************************* dw_html_javascript_run() **************************** + * Runs a javascript in the specified browser context. + * + * hwnd = Handle to the window hosting the browser object. + * script = Pointer to nul-terminated javascript string. + * scriptdata = Pointer to user data to be passed to the callback. + * + * RETURNS: 0 if success, or non-zero if an error. + */ +int _dw_html_javascript_run(HWND hwnd, LPCWSTR script, void *scriptdata) +{ + return DW_ERROR_UNKNOWN; +} /******************************* ResizeBrowser() **************************** diff -r b1838dd5509a -r c30f4354966e win/dw-mingw.def --- a/win/dw-mingw.def Thu Nov 07 08:11:28 2019 +0000 +++ b/win/dw-mingw.def Thu Nov 07 10:12:25 2019 +0000 @@ -303,6 +303,7 @@ dw_html_action @471 dw_html_raw @472 dw_html_url @473 + dw_html_javascript_run @474 dw_calendar_new @480 dw_calendar_set_date @481 diff -r b1838dd5509a -r c30f4354966e win/dw.c --- a/win/dw.c Thu Nov 07 08:11:28 2019 +0000 +++ b/win/dw.c Thu Nov 07 10:12:25 2019 +0000 @@ -364,7 +364,7 @@ static int in_checkbox_handler = 0; /* List of signals and their equivilent Win32 message */ -#define SIGNALMAX 17 +#define SIGNALMAX 19 SignalList SignalTranslate[SIGNALMAX] = { { WM_SIZE, DW_SIGNAL_CONFIGURE }, @@ -383,7 +383,9 @@ { WM_VSCROLL, DW_SIGNAL_VALUE_CHANGED }, { TCN_SELCHANGE, DW_SIGNAL_SWITCH_PAGE }, { LVN_COLUMNCLICK, DW_SIGNAL_COLUMN_CLICK }, - { TVN_ITEMEXPANDED,DW_SIGNAL_TREE_EXPAND } + { TVN_ITEMEXPANDED,DW_SIGNAL_TREE_EXPAND }, + { WM_USER+100, DW_SIGNAL_HTML_RESULT }, + { WM_USER+101, DW_SIGNAL_HTML_CHANGED } }; #ifdef BUILD_DLL @@ -2382,6 +2384,20 @@ } } break; + case WM_USER+100: + { + int (DWSIGNAL *htmlresultfunc)(HWND, int, char *, void *, void *) = tmp->signalfunction; + + return htmlresultfunc(tmp->window, mp1 ? DW_ERROR_NONE : DW_ERROR_UNKNOWN, (char *)mp1, (void *)mp2, tmp->data); + } + break; + case WM_USER+101: + { + int (DWSIGNAL *htmlchangedfunc)(HWND, int, char *, void *) = tmp->signalfunction; + + return htmlchangedfunc(tmp->window, DW_POINTER_TO_INT(mp1), (char *)mp2, tmp->data); + } + break; } } if(tmp) @@ -5768,6 +5784,29 @@ } /* + * Executes the javascript contained in "script" in the HTML window. + * Parameters: + * handle: Handle to the HTML window. + * script: Javascript code to execute. + * scriptdata: Data passed to the signal handler. + * Notes: A DW_SIGNAL_HTML_RESULT event will be raised with scriptdata. + * Returns: + * DW_ERROR_NONE (0) on success. + */ +int dw_html_javascript_run(HWND handle, char *script, void *scriptdata) +{ +#if (defined(BUILD_DLL) || defined(BUILD_HTML)) +#if BUILD_EDGE + if (_DW_EDGE_DETECTED) + return _dw_edge_javascript_run(handle, UTF8toWide(script), scriptdata); +#endif + return _dw_html_javascript_run(handle, script, scriptdata); +#else + return DW_ERROR_UNKNOWN; +#endif +} + +/* * Create a bitmap object to be packed. * Parameters: * id: An ID to be used with dw_window_from_id or 0L. diff -r b1838dd5509a -r c30f4354966e win/dw.def --- a/win/dw.def Thu Nov 07 08:11:28 2019 +0000 +++ b/win/dw.def Thu Nov 07 10:12:25 2019 +0000 @@ -301,6 +301,7 @@ dw_html_action @471 dw_html_raw @472 dw_html_url @473 + dw_html_javascript_run @474 dw_calendar_new @480 dw_calendar_set_date @481 diff -r b1838dd5509a -r c30f4354966e win/edge.cpp --- a/win/edge.cpp Thu Nov 07 08:11:28 2019 +0000 +++ b/win/edge.cpp Thu Nov 07 10:12:25 2019 +0000 @@ -89,7 +89,7 @@ case DW_HTML_GOHOME: { // Call the IWebView2WebView object's GoHome function. - //webview->GoHome(); + dw_html_url(hwnd, (char *)DW_HOME_URL); break; } @@ -147,7 +147,7 @@ * Displays a URL, or HTML file on disk. * * hwnd = Handle to the window hosting the browser object. - * webPageName = Pointer to nul-terminated name of the URL/file. + * url = Pointer to nul-terminated name of the URL/file. * * RETURNS: 0 if success, or non-zero if an error. */ @@ -167,6 +167,40 @@ return DW_ERROR_NONE; } + /* These reference functions in dw.c */ + #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL) + char* _myWideToUTF8(LPWSTR widestring, void* outbuf); + LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); + + /******************************* dw_edge_javascript_run() **************************** + * Runs a javascript in the specified browser context. + * + * hwnd = Handle to the window hosting the browser object. + * script = Pointer to nul-terminated javascript string. + * scriptdata = Pointer to user data to be passed to the callback. + * + * RETURNS: 0 if success, or non-zero if an error. + */ + + int _dw_edge_javascript_run(HWND hwnd, LPCWSTR script, void *scriptdata) + { + IWebView2WebView* webview; + + // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when + // we initially attached the browser object to this window. + webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); + + if (webview) + webview->ExecuteScript(script, + Callback( + [hwnd, scriptdata](HRESULT error, PCWSTR result) -> HRESULT + { + _wndproc(hwnd, WM_USER + 100, (error == S_OK ? (WPARAM)WideToUTF8((LPWSTR)result) : NULL), (LPARAM)scriptdata); + return S_OK; + }).Get()); + return DW_ERROR_NONE; + } + /************************** edgeWindowProc() ************************* * Our message handler for our window to host the browser. */