Mercurial > dwindows
annotate win/edge.cpp @ 2033:d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 16 Nov 2019 09:43:17 +0000 |
parents | 28809bf17957 |
children | 89d62197124b |
rev | line source |
---|---|
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
1 /* edge.cpp |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
2 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
3 * Allows dw_html_new() to embed a Microsoft Edge (Chromium) browser. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
4 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
5 * Requires Windows 10, 8 or 7 with Microsoft Edge (Chromium) installed. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
6 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
7 * Only included when BUILD_EDGE is defined, will fall back to embedded IE. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
8 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
9 * Currently only buildable with Visual Studio since it requires the EDGE |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
10 * SDK which is currently distributed as a nuget package. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
11 */ |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
12 #include "dw.h" |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
13 #include "webview2.h" |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
14 #include <wrl.h> |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
15 |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
16 using namespace Microsoft::WRL; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
17 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
18 #define _DW_HTML_DATA_NAME (char *)"_dw_edge" |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
19 #define _DW_HTML_DATA_LOCATION (char *)"_dw_edge_location" |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
20 #define _DW_HTML_DATA_RAW (char *)"_dw_edge_raw" |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
21 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
22 extern "C" { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
23 |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
24 /* Import the character conversion functions from dw.c */ |
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
25 LPWSTR _myUTF8toWide(char *utf8string, void *outbuf); |
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
26 char *_myWideToUTF8(LPWSTR widestring, void *outbuf); |
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
27 #define UTF8toWide(a) _myUTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL) |
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
28 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL) |
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
29 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); |
2022
28809bf17957
Win: Switch to using _wcsicmp() from CompareStringOrdinal() for increased compatibility.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2018
diff
changeset
|
30 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
31 extern HWND DW_HWND_OBJECT; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
32 BOOL DW_EDGE_DETECTED = FALSE; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
33 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
34 /******************************* dw_edge_detect() ************************** |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
35 * Attempts to create a temporary Edge (Chromium) browser context... |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
36 * If we succeed return TRUE and use Edge for HTML windows. |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
37 * If it fails return FALSE and fall back to using embedded IE. |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
38 */ |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
39 BOOL _dw_edge_detect(VOID) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
40 { |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
41 HWND hWnd = DW_HWND_OBJECT; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
42 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
43 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
44 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
45 [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
46 // Successfully created Edge environment, return TRUE |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
47 DW_EDGE_DETECTED = TRUE; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
48 return S_OK; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
49 }).Get()); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
50 return DW_EDGE_DETECTED; |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
51 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
52 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
53 /******************************* dw_edge_action() ************************** |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
54 * Implements the functionality of a "Back". "Forward", "Home", "Search", |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
55 * "Refresh", or "Stop" button. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
56 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
57 * hwnd = Handle to the window hosting the browser object. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
58 * action = One of the following: |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
59 * 0 = Move back to the previously viewed web page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
60 * 1 = Move forward to the previously viewed web page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
61 * 2 = Move to the home page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
62 * 3 = Search. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
63 * 4 = Refresh the page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
64 * 5 = Stop the currently loading page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
65 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
66 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
67 void _dw_edge_action(HWND hwnd, int action) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
68 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
69 IWebView2WebView* webview; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
70 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
71 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
72 // we initially attached the browser object to this window. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
73 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
74 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
75 // We want to get the base address (ie, a pointer) to the IWebView2WebView object embedded within the browser |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
76 // object, so we can call some of the functions in the former's table. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
77 if (webview) |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
78 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
79 // Call the desired function |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
80 switch (action) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
81 { |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
82 case DW_HTML_GOBACK: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
83 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
84 // Call the IWebView2WebView object's GoBack function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
85 webview->GoBack(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
86 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
87 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
88 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
89 case DW_HTML_GOFORWARD: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
90 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
91 // Call the IWebView2WebView object's GoForward function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
92 webview->GoForward(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
93 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
94 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
95 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
96 case DW_HTML_GOHOME: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
97 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
98 // Call the IWebView2WebView object's GoHome function. |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
99 dw_html_url(hwnd, (char *)DW_HOME_URL); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
100 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
101 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
102 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
103 case DW_HTML_SEARCH: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
104 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
105 // Call the IWebView2WebView object's GoSearch function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
106 //webview->GoSearch(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
107 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
108 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
109 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
110 case DW_HTML_RELOAD: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
111 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
112 // Call the IWebView2WebView object's Refresh function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
113 webview->Reload(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
114 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
115 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
116 case DW_HTML_STOP: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
117 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
118 // Call the IWebView2WebView object's Stop function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
119 //webview->Stop(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
120 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
121 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
122 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
123 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
124 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
125 /******************************* dw_edge_raw() **************************** |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
126 * Takes a string containing some HTML BODY, and displays it in the specified |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
127 * window. For example, perhaps you want to display the HTML text of... |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
128 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
129 * <P>This is a picture.<P><IMG src="mypic.jpg"> |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
130 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
131 * hwnd = Handle to the window hosting the browser object. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
132 * string = Pointer to nul-terminated string containing the HTML BODY. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
133 * (NOTE: No <BODY></BODY> tags are required in the string). |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
134 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
135 * RETURNS: 0 if success, or non-zero if an error. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
136 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
137 |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
138 int _dw_edge_raw(HWND hwnd, char *string) |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
139 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
140 IWebView2WebView* webview; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
141 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
142 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
143 // we initially attached the browser object to this window. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
144 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
145 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
146 if (webview) |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
147 webview->NavigateToString(UTF8toWide(string)); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
148 else |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
149 dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(UTF8toWide(string))); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
150 return DW_ERROR_NONE; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
151 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
152 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
153 /******************************* dw_edge_url() **************************** |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
154 * Displays a URL, or HTML file on disk. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
155 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
156 * hwnd = Handle to the window hosting the browser object. |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
157 * url = Pointer to nul-terminated name of the URL/file. |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
158 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
159 * RETURNS: 0 if success, or non-zero if an error. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
160 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
161 |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
162 int _dw_edge_url(HWND hwnd, char *url) |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
163 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
164 IWebView2WebView* webview; |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
165 |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
166 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
167 // we initially attached the browser object to this window. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
168 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
169 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
170 if (webview) |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
171 webview->Navigate(UTF8toWide(url)); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
172 else |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
173 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(UTF8toWide(url))); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
174 return DW_ERROR_NONE; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
175 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
176 |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
177 /******************************* dw_edge_javascript_run() **************************** |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
178 * Runs a javascript in the specified browser context. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
179 * |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
180 * hwnd = Handle to the window hosting the browser object. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
181 * script = Pointer to nul-terminated javascript string. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
182 * scriptdata = Pointer to user data to be passed to the callback. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
183 * |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
184 * RETURNS: 0 if success, or non-zero if an error. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
185 */ |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
186 |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
187 int _dw_edge_javascript_run(HWND hwnd, char *script, void *scriptdata) |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
188 { |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
189 IWebView2WebView* webview; |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
190 |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
191 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
192 // we initially attached the browser object to this window. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
193 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
194 |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
195 if (webview) |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
196 webview->ExecuteScript(UTF8toWide(script), |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
197 Callback<IWebView2ExecuteScriptCompletedHandler>( |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
198 [hwnd, scriptdata](HRESULT error, PCWSTR result) -> HRESULT |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
199 { |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
200 _wndproc(hwnd, WM_USER + 100, (error == S_OK ? (WPARAM)WideToUTF8((LPWSTR)result) : NULL), (LPARAM)scriptdata); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
201 return S_OK; |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
202 }).Get()); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
203 return DW_ERROR_NONE; |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
204 } |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
205 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
206 /************************** edgeWindowProc() ************************* |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
207 * Our message handler for our window to host the browser. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
208 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
209 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
210 LRESULT CALLBACK _edgeWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
211 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
212 switch (uMsg) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
213 { |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
214 case WM_SIZE: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
215 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
216 // Resize the browser object to fit the window |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
217 IWebView2WebView* webview; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
218 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
219 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
220 // we initially attached the browser object to this window. |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
221 webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
222 // Resize WebView to fit the bounds of the parent window |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
223 if (webview) |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
224 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
225 RECT bounds; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
226 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
227 GetClientRect(hWnd, &bounds); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
228 webview->put_Bounds(bounds); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
229 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
230 return(0); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
231 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
232 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
233 case WM_CREATE: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
234 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
235 // Step 3 - Create a single WebView within the parent window |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
236 // Locate the browser and set up the environment for WebView |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
237 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
238 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
239 [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
240 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
241 // Create a WebView, whose parent is the main window hWnd |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
242 env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>( |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
243 [hWnd](HRESULT result, IWebView2WebView* webview) -> HRESULT { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
244 if (webview != nullptr) { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
245 dw_window_set_data(hWnd, _DW_HTML_DATA_NAME, DW_POINTER(webview)); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
246 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
247 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
248 // Add a few settings for the webview |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
249 // this is a redundant demo step as they are the default settings values |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
250 IWebView2Settings* Settings; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
251 webview->get_Settings(&Settings); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
252 Settings->put_IsScriptEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
253 Settings->put_AreDefaultScriptDialogsEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
254 Settings->put_IsWebMessageEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
255 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
256 // Resize WebView to fit the bounds of the parent window |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
257 RECT bounds; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
258 GetClientRect(hWnd, &bounds); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
259 webview->put_Bounds(bounds); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
260 |
2033
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
261 // Save the token, we might need to dw_window_set_data() this value |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
262 // for later use to remove the handlers |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
263 EventRegistrationToken token; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
264 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
265 // Register a handler for the NavigationStarting event. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
266 // This handler will check the domain being navigated to, and if the domain |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
267 // matches a list of blocked sites, it will cancel the navigation and |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
268 // possibly display a warning page. It will also disable JavaScript on |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
269 // selected websites. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
270 webview->add_NavigationStarting( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
271 Callback<IWebView2NavigationStartingEventHandler>( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
272 [hWnd](IWebView2WebView* sender, |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
273 IWebView2NavigationStartingEventArgs* args) -> HRESULT |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
274 { |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
275 LPWSTR uri; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
276 sender->get_Source(&uri); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
277 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
278 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
279 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
280 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
281 return S_OK; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
282 }).Get(), &token); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
283 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
284 // Register a handler for the DocumentStateChanged event. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
285 // This handler will read the webview's source URI and update |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
286 // the app's address bar. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
287 webview->add_DocumentStateChanged( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
288 Callback<IWebView2DocumentStateChangedEventHandler>( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
289 [hWnd](IWebView2WebView* sender, |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
290 IWebView2DocumentStateChangedEventArgs* args) -> HRESULT |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
291 { |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
292 LPWSTR uri; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
293 sender->get_Source(&uri); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
294 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
295 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
296 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
297 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
298 return S_OK; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
299 }).Get(), &token); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
300 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
301 // Register a handler for the NavigationCompleted event. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
302 // If the navigation was successful, update the back and forward buttons. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
303 webview->add_NavigationCompleted( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
304 Callback<IWebView2NavigationCompletedEventHandler>( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
305 [hWnd](IWebView2WebView* sender, |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
306 IWebView2NavigationCompletedEventArgs* args) -> HRESULT |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
307 { |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
308 LPWSTR uri; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
309 sender->get_Source(&uri); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
310 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
311 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
312 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
313 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
314 return S_OK; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
315 }).Get(), &token); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
316 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
317 // Handle cached load requests due to delayed |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
318 // loading of the edge webview contexts |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
319 LPCWSTR url = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_LOCATION); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
320 if(url) |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
321 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
322 webview->Navigate(url); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
323 free((void *)url); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
324 } |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
325 LPCWSTR raw = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_RAW); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
326 if (raw) |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
327 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
328 webview->NavigateToString(raw); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
329 free((void *)raw); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
330 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
331 return S_OK; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
332 }).Get()); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
333 return S_OK; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
334 }).Get()); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
335 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
336 // Success |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
337 return(0); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
338 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
339 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
340 case WM_DESTROY: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
341 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
342 // Detach the browser object from this window, and free resources. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
343 IWebView2WebView* webview; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
344 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
345 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
346 // we initially attached the browser object to this window. |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
347 webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
348 if (webview) |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
349 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
350 dw_window_set_data(hWnd, _DW_HTML_DATA_NAME, NULL); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
351 webview->Close(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
352 } |
2033
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
353 _free_window_memory(hWnd, 0); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
354 return(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
355 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
356 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
357 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
358 return(DefWindowProc(hWnd, uMsg, wParam, lParam)); |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
359 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
360 } |