Skip to content

Commit

Permalink
Update projects to use latest WebView2 SDK 1.0.2065-prerelease (#206)
Browse files Browse the repository at this point in the history
* Updates for Win32, WPF and WinForms sample apps from 118.0.2065.0

* Updated package version for Win32, WPF and WinForms sample apps to 1.0.2065-prerelease

---------

Co-authored-by: WebView2 Github Bot <[email protected]>
  • Loading branch information
peiche-jessica and WebView2GithubBot authored Aug 30, 2023
1 parent c8e255f commit 4f28fa3
Show file tree
Hide file tree
Showing 28 changed files with 560 additions and 179 deletions.
3 changes: 2 additions & 1 deletion SampleApps/WebView2APISample/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmd
std::wstring userDataFolder(L"");
std::wstring initialUri;
DWORD creationModeId = IDM_CREATION_MODE_WINDOWED;
WebViewCreateOption opt;

if (lpCmdLine && lpCmdLine[0])
{
Expand Down Expand Up @@ -120,7 +121,7 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmd

DpiUtil::SetProcessDpiAwarenessContext(dpiAwarenessContext);

new AppWindow(creationModeId, WebViewCreateOption(), initialUri, userDataFolder, true);
new AppWindow(creationModeId, opt, initialUri, userDataFolder, true);

int retVal = RunMessagePump();

Expand Down
34 changes: 31 additions & 3 deletions SampleApps/WebView2APISample/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,11 @@ void AppWindow::InitializeWebView()
HRESULT AppWindow::OnCreateEnvironmentCompleted(
HRESULT result, ICoreWebView2Environment* environment)
{
CHECK_FAILURE(result);
if (result != S_OK)
{
ShowFailure(result, L"Failed to create environment object.");
return S_OK;
}
m_webViewEnvironment = environment;

if (m_webviewOption.entry == WebViewCreateEntry::EVER_FROM_CREATE_WITH_OPTION_MENU
Expand Down Expand Up @@ -1569,7 +1573,6 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(
}
NewComponent<ScenarioPermissionManagement>(this);
NewComponent<ScenarioNotificationReceived>(this);

// We have a few of our own event handlers to register here as well
RegisterEventHandlers();

Expand Down Expand Up @@ -1721,6 +1724,32 @@ void AppWindow::RegisterEventHandlers()
args->put_Handled(FALSE);
return S_OK;
}
wil::com_ptr<ICoreWebView2ExperimentalNewWindowRequestedEventArgs2>
experimental_args;
if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&experimental_args))))
{
wil::com_ptr<ICoreWebView2FrameInfo> frame_info;
CHECK_FAILURE(experimental_args->get_OriginalSourceFrameInfo(&frame_info));
wil::unique_cotaskmem_string source;
CHECK_FAILURE(frame_info->get_Source(&source));
// The host can decide how to open based on source frame info,
// such as URI.
static const wchar_t* browser_launching_domain = L"www.example.com";
wil::unique_bstr source_domain = GetDomainOfUri(source.get());
const wchar_t* source_domain_as_wchar = source_domain.get();
if (wcscmp(browser_launching_domain, source_domain_as_wchar) == 0)
{
// Open the URI in the default browser.
wil::unique_cotaskmem_string target_uri;
CHECK_FAILURE(args->get_Uri(&target_uri));
ShellExecute(
nullptr, L"open", target_uri.get(), nullptr, nullptr,
SW_SHOWNORMAL);
CHECK_FAILURE(args->put_Handled(TRUE));
return S_OK;
}
}

wil::com_ptr<ICoreWebView2Deferral> deferral;
CHECK_FAILURE(args->GetDeferral(&deferral));
AppWindow* newAppWindow;
Expand Down Expand Up @@ -2176,7 +2205,6 @@ std::wstring AppWindow::GetLocalUri(
else
{
std::wstring path = GetLocalPath(L"assets\\" + relativePath, false);

wil::com_ptr<IUri> uri;
CHECK_FAILURE(CreateUri(path.c_str(), Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, &uri));

Expand Down
2 changes: 0 additions & 2 deletions SampleApps/WebView2APISample/AppWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct WebViewCreateOption
WebViewCreateOption()
{
}

WebViewCreateOption(
const std::wstring& profile_, bool inPrivate, const std::wstring& downloadPath,
const std::wstring& scriptLocale_, WebViewCreateEntry entry_, bool useOSRegion_)
Expand All @@ -59,7 +58,6 @@ struct WebViewCreateOption
entry = opt.entry;
useOSRegion = opt.useOSRegion;
}

void PopupDialog(AppWindow* app);
};

Expand Down
156 changes: 63 additions & 93 deletions SampleApps/WebView2APISample/ProcessComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,63 +215,65 @@ std::wstring ProcessComponent::FrameKindToString(const COREWEBVIEW2_FRAME_KIND k
}

void ProcessComponent::AppendFrameInfo(
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring& result)
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstringstream& result)
{
if (!frameInfo)
{
return;
}

UINT32 frameId = 0;
UINT32 parentFrameId = 0;
UINT32 mainFrameId = 0;
UINT32 firstLevelFrameId = 0;
std::wstring type = L"other child frame";
wil::unique_cotaskmem_string nameRaw;
wil::unique_cotaskmem_string sourceRaw;
COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_OTHER;

CHECK_FAILURE(frameInfo->get_Name(&nameRaw));
result.append(L"{frame name:");
result.append(nameRaw.get());
std::wstring name = ((std::wstring)(nameRaw.get())).empty() ? L"none" : nameRaw.get();
CHECK_FAILURE(frameInfo->get_Source(&sourceRaw));
std::wstring source = ((std::wstring)(sourceRaw.get())).empty() ? L"none" : sourceRaw.get();

wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
UINT32 frameId = 0;
frameInfoExperimental->get_FrameId(&frameId);
result.append(L" | frame Id:" + std::to_wstring(frameId));
frameInfoExperimental->get_FrameKind(&frameKind);

wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
CHECK_FAILURE(frameInfoExperimental->get_ParentFrameInfo(&parentFrameInfo));
if (parentFrameInfo)
{
CHECK_FAILURE(parentFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&parentFrameId));
}

BOOL isMainFrameOrFirstLevelframeInfo = false;
wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetAncestorMainFrameInfo(frameInfo);
wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
GetAncestorFirstLevelFrameInfo(frameInfo);
// check if a frame is a main frame.
if (mainFrameInfo == frameInfo)
{
result.append(L" | frame type: main frame");
isMainFrameOrFirstLevelframeInfo = true;
type = L"main frame";
}
// check if a frame is a first level frame.
CHECK_FAILURE(mainFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&mainFrameId));

wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
GetAncestorFirstLevelFrameInfo(frameInfo);
if (firstLevelFrameInfo == frameInfo)
{
result.append(L" | frame type: first level frame");
isMainFrameOrFirstLevelframeInfo = true;
}
if (!isMainFrameOrFirstLevelframeInfo)
{
result.append(L" | frame type: other child frame");
type = L"first level frame";
}

COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_OTHER;
frameInfoExperimental->get_FrameKind(&frameKind);
result.append(L"\n | frame kind:" + FrameKindToString(frameKind));

wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
CHECK_FAILURE(frameInfoExperimental->get_ParentFrameInfo(&parentFrameInfo));
if (parentFrameInfo)
if (firstLevelFrameInfo)
{
CHECK_FAILURE(parentFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&frameId));
result.append(L" | parent frame Id:" + std::to_wstring(frameId));
CHECK_FAILURE(
firstLevelFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&firstLevelFrameId));
}

wil::unique_cotaskmem_string sourceRaw;
CHECK_FAILURE(frameInfo->get_Source(&sourceRaw));
result.append(L"\n | frame source:\n\"");
result.append(sourceRaw.get());
result.append(L"\"");
result << L"{frame name:" << name << L" | frame Id:" << std::to_wstring(frameId)
<< L" | parent frame Id:"
<< ((parentFrameId == 0) ? L"none" : std::to_wstring(parentFrameId))
<< L" | frame type:" << type << L"\n"
<< L" | ancestor main frame Id:" << std::to_wstring(mainFrameId)
<< L" | ancestor first level frame Id:"
<< ((firstLevelFrameId == 0) ? L"none" : std::to_wstring(firstLevelFrameId)) << L"\n"
<< L" | frame kind:" << FrameKindToString(frameKind) << L"\n"
<< L" | frame source:" << source << L"}," << std::endl;
}

// Get the ancestor main frameInfo.
Expand Down Expand Up @@ -308,36 +310,6 @@ wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorFirstLevelFram
return firstLevelFrameInfo;
}

// Append the frame Id of the ancestor first level frame and ancestor main frame.
void ProcessComponent::AppendAncestorFrameInfo(
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring& result)
{
if (!frameInfo)
{
return;
}

wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetAncestorMainFrameInfo(frameInfo);
wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
GetAncestorFirstLevelFrameInfo(frameInfo);
wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
UINT32 frameId = 0;
if (firstLevelFrameInfo)
{
CHECK_FAILURE(
firstLevelFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&frameId));
result.append(L"\n | ancestor first level frame Id:" + std::to_wstring(frameId));
}
if (mainFrameInfo)
{
CHECK_FAILURE(mainFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&frameId));
result.append(L"\n | ancestor main frame Id:" + std::to_wstring(frameId));
}
result.append(L"},\n");
}

void ProcessComponent::ShowProcessFrameInfo()
{
auto environmentExperimental11 =
Expand All @@ -353,8 +325,8 @@ void ProcessComponent::ShowProcessFrameInfo()
UINT32 processCount = 0;
UINT32 rendererProcessCount = 0;
CHECK_FAILURE(processCollection->get_Count(&processCount));
std::wstring result;
std::wstring otherProcessResult;
std::wstringstream otherProcessInfos;
std::wstringstream rendererProcessInfos;
for (UINT32 i = 0; i < processCount; i++)
{
Microsoft::WRL::ComPtr<ICoreWebView2ProcessInfo> processInfo;
Expand All @@ -366,7 +338,7 @@ void ProcessComponent::ShowProcessFrameInfo()
if (kind == COREWEBVIEW2_PROCESS_KIND_RENDERER)
{
//! [AssociatedFrameInfos]
std::wstring rendererProcessResult;
std::wstringstream rendererProcess;
wil::com_ptr<ICoreWebView2ExperimentalProcessInfo>
processInfoExperimental;
CHECK_FAILURE(processInfo->QueryInterface(
Expand All @@ -384,39 +356,37 @@ void ProcessComponent::ShowProcessFrameInfo()
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo;
CHECK_FAILURE(iterator->GetCurrent(&frameInfo));

AppendFrameInfo(frameInfo, rendererProcessResult);
AppendAncestorFrameInfo(frameInfo, rendererProcessResult);
AppendFrameInfo(frameInfo, rendererProcess);

BOOL hasNext = FALSE;
CHECK_FAILURE(iterator->MoveNext(&hasNext));
frameInfoCount++;
}
rendererProcessResult.insert(
0, std::to_wstring(frameInfoCount) +
L" frameInfo(s) found in Renderer Process ID:" +
std::to_wstring(processId) + L"\n");
result.append(rendererProcessResult + L"\n");
rendererProcessInfos
<< std::to_wstring(frameInfoCount)
<< L" frameInfo(s) found in Renderer Process ID:"
<< std::to_wstring(processId) << L"\n"
<< rendererProcess.str() << std::endl;
//! [AssociatedFrameInfos]
rendererProcessCount++;
}
else
{
otherProcessResult.append(
L"Process Id:" + std::to_wstring(processId) +
L" | Process Kind:" + ProcessKindToString(kind) + L"\n");
otherProcessInfos << L"Process Id:" << std::to_wstring(processId)
<< L" | Process Kind:"
<< ProcessKindToString(kind) << std::endl;
}
}
result.insert(
0, std::to_wstring(processCount) + L" process(es) found, from which " +
std::to_wstring(rendererProcessCount) +
L" renderer process(es) found\n\n");
otherProcessResult.insert(
0, L"\nRemaining " +
std::to_wstring(processCount - rendererProcessCount) +
L" Process(es) Infos:\n");
result.append(otherProcessResult);
MessageBox(
nullptr, result.c_str(), L"Process Info with Associated Frames", MB_OK);
std::wstringstream message;
message << std::to_wstring(processCount)
<< L" process(es) found, from which "
<< std::to_wstring(rendererProcessCount)
<< L" renderer process(es) found\n\n"
<< rendererProcessInfos.str() << L"Remaining Process(es) Infos:\n"
<< otherProcessInfos.str();

m_appWindow->AsyncMessageBox(
std::move(message.str()), L"Process Info with Associated Frames");
return S_OK;
})
.Get()));
Expand Down
5 changes: 2 additions & 3 deletions SampleApps/WebView2APISample/ProcessComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class ProcessComponent : public ComponentBase
wil::com_ptr<ICoreWebView2ProcessInfoCollection> m_processCollection;
EventRegistrationToken m_processFailedToken = {};
EventRegistrationToken m_processInfosChangedToken = {};
void AppendAncestorFrameInfo(
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring& result);
void AppendFrameInfo(wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring& result);
void AppendFrameInfo(
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstringstream& result);
wil::com_ptr<ICoreWebView2FrameInfo> GetAncestorFirstLevelFrameInfo(
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo);
wil::com_ptr<ICoreWebView2FrameInfo> GetAncestorMainFrameInfo(
Expand Down
16 changes: 16 additions & 0 deletions SampleApps/WebView2APISample/ScenarioSaveAs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "stdafx.h"

#include "ScenarioSaveAs.h"

#include "App.h"
#include "AppWindow.h"
#include "CheckFailure.h"
#include "Shlwapi.h"
#include "TextInputDialog.h"
#include "resource.h"

using namespace Microsoft::WRL;
10 changes: 10 additions & 0 deletions SampleApps/WebView2APISample/ScenarioSaveAs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "stdafx.h"

#include <string>

#include "AppWindow.h"
#include "ComponentBase.h"
Loading

0 comments on commit 4f28fa3

Please sign in to comment.