Mercurial > dwindows
annotate 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 |
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 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
24 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
|
25 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
|
26 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
27 /******************************* 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
|
28 * 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
|
29 * 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
|
30 * 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
|
31 */ |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
32 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
|
33 { |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
34 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
|
35 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
36 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
|
37 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
|
38 [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
|
39 // 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
|
40 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
|
41 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
|
42 }).Get()); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
43 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
|
44 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
45 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
46 /******************************* 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
|
47 * 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
|
48 * "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
|
49 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
50 * 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
|
51 * 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
|
52 * 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
|
53 * 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
|
54 * 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
|
55 * 3 = Search. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
56 * 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
|
57 * 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
|
58 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
59 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
60 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
|
61 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
62 IWebView2WebView* webview; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
63 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
64 // 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
|
65 // 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
|
66 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
|
67 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
68 // 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
|
69 // 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
|
70 if (webview) |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
71 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
72 // 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
|
73 switch (action) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
74 { |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
75 case DW_HTML_GOBACK: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
76 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
77 // 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
|
78 webview->GoBack(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
79 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
80 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
81 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
82 case DW_HTML_GOFORWARD: |
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 GoForward function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
85 webview->GoForward(); |
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_GOHOME: |
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 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
|
92 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
|
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_SEARCH: |
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 GoSearch function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
99 //webview->GoSearch(); |
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_RELOAD: |
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 Refresh function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
106 webview->Reload(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
107 } |
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 case DW_HTML_STOP: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
110 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
111 // 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
|
112 //webview->Stop(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
113 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
114 } |
1999
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 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
117 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
118 /******************************* 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
|
119 * 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
|
120 * 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
|
121 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
122 * <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
|
123 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
124 * 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
|
125 * 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
|
126 * (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
|
127 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
128 * 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
|
129 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
130 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
131 int _dw_edge_raw(HWND hwnd, LPCWSTR string) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
132 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
133 IWebView2WebView* webview; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
134 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
135 // 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
|
136 // 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
|
137 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
|
138 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
139 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
|
140 webview->NavigateToString(string); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
141 else |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
142 dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(string)); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
143 return DW_ERROR_NONE; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
144 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
145 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
146 /******************************* 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
|
147 * 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
|
148 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
149 * 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
|
150 * 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
|
151 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
152 * 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
|
153 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
154 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
155 int _dw_edge_url(HWND hwnd, LPCWSTR url) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
156 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
157 IWebView2WebView* webview; |
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 // 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
|
160 // 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
|
161 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
|
162 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
163 if (webview) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
164 webview->Navigate(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
|
165 else |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
166 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(url)); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
167 return DW_ERROR_NONE; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
168 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
169 |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
170 /* These reference functions in dw.c */ |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
171 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL) |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
172 char* _myWideToUTF8(LPWSTR widestring, void* outbuf); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
173 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
174 |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
175 /******************************* 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
|
176 * 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
|
177 * |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
178 * 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
|
179 * 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
|
180 * 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
|
181 * |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
182 * 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
|
183 */ |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
184 |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
185 int _dw_edge_javascript_run(HWND hwnd, LPCWSTR script, void *scriptdata) |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
186 { |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
187 IWebView2WebView* webview; |
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 // 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
|
190 // 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
|
191 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
|
192 |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
193 if (webview) |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
194 webview->ExecuteScript(script, |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
195 Callback<IWebView2ExecuteScriptCompletedHandler>( |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
196 [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
|
197 { |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
198 _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
|
199 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
|
200 }).Get()); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
201 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
|
202 } |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
203 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
204 /************************** edgeWindowProc() ************************* |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
205 * 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
|
206 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
207 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
208 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
|
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 switch (uMsg) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
211 { |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
212 case WM_SIZE: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
213 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
214 // 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
|
215 IWebView2WebView* webview; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
216 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
217 // 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
|
218 // 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
|
219 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
|
220 // 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
|
221 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
|
222 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
223 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
|
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 GetClientRect(hWnd, &bounds); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
226 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
|
227 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
228 return(0); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
229 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
230 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
231 case WM_CREATE: |
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 // 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
|
234 // 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
|
235 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
236 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
237 [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
|
238 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
239 // 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
|
240 env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>( |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
241 [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
|
242 if (webview != nullptr) { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
243 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
|
244 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
245 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
246 // 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
|
247 // 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
|
248 IWebView2Settings* Settings; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
249 webview->get_Settings(&Settings); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
250 Settings->put_IsScriptEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
251 Settings->put_AreDefaultScriptDialogsEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
252 Settings->put_IsWebMessageEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
253 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
254 // 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
|
255 RECT bounds; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
256 GetClientRect(hWnd, &bounds); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
257 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
|
258 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
259 // 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
|
260 // 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
|
261 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
|
262 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
|
263 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
264 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
|
265 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
|
266 } |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
267 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
|
268 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
|
269 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
270 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
|
271 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
|
272 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
273 return S_OK; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
274 }).Get()); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
275 return S_OK; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
276 }).Get()); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
277 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
278 // Success |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
279 return(0); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
280 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
281 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
282 case WM_DESTROY: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
283 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
284 // 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
|
285 IWebView2WebView* webview; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
286 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
287 // 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
|
288 // 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
|
289 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
|
290 if (webview) |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
291 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
292 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
|
293 webview->Close(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
294 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
295 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
296 return(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
297 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
298 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
299 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
300 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
|
301 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
302 } |