Skip to content

Commit

Permalink
Update to latest webview2 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSandersonMS committed Feb 14, 2020
1 parent 5da55be commit 9618b32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/WebWindow.Native/WebWindow.Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,18 @@ void WebWindow::AttachWebView()
HRESULT envResult = CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr,
Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>(
[&, this](HRESULT result, IWebView2Environment* env) -> HRESULT {
_webviewEnvironment = env;
HRESULT envResult = env->QueryInterface(&_webviewEnvironment);
if (envResult != S_OK)
{
return envResult;
}

// Create a WebView, whose parent is the main window hWnd
env->CreateWebView(_hWnd, Callback<IWebView2CreateWebViewCompletedHandler>(
[&, this](HRESULT result, IWebView2WebView* webview) -> HRESULT {
if (webview != nullptr) {
_webviewWindow = webview;
}
if (result != S_OK) { return result; }
result = webview->QueryInterface(&_webviewWindow);
if (result != S_OK) { return result; }

// Add a few settings for the webview
// this is a redundant demo step as they are the default settings values
Expand All @@ -238,7 +242,7 @@ void WebWindow::AttachWebView()
}).Get(), &webMessageToken);

EventRegistrationToken webResourceRequestedToken;
_webviewWindow->add_WebResourceRequested_deprecated(nullptr, nullptr, 0, Callback<IWebView2WebResourceRequestedEventHandler>(
_webviewWindow->add_WebResourceRequested(Callback<IWebView2WebResourceRequestedEventHandler>(
[this](IWebView2WebView* sender, IWebView2WebResourceRequestedEventArgs* args)
{
IWebView2WebResourceRequest* req;
Expand Down
4 changes: 2 additions & 2 deletions src/WebWindow.Native/WebWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class WebWindow
static HINSTANCE _hInstance;
HWND _hWnd;
WebWindow* _parent;
wil::com_ptr<IWebView2Environment> _webviewEnvironment;
wil::com_ptr<IWebView2WebView> _webviewWindow;
wil::com_ptr<IWebView2Environment3> _webviewEnvironment;
wil::com_ptr<IWebView2WebView5> _webviewWindow;
std::map<std::wstring, WebResourceRequestedCallback> _schemeToRequestHandler;
void AttachWebView();
#elif OS_LINUX
Expand Down

0 comments on commit 9618b32

Please sign in to comment.