Skip to content

Commit

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

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

---------

Co-authored-by: WebView2 Github Bot <webview2github@microsoft.com>
  • Loading branch information
oggy22 and WebView2GithubBot committed Nov 6, 2023
1 parent ac00a84 commit 85e53c9
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 89 deletions.
62 changes: 26 additions & 36 deletions SampleApps/WebView2APISample/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ DWORD WINAPI DownloadAndInstallWV2RT(_In_ LPVOID lpParameter)

if (ShellExecuteEx(&shExInfo))
{
returnCode = 0; // Install successfull
returnCode = 0; // Install successful
}
else
{
Expand Down Expand Up @@ -1313,10 +1313,10 @@ void AppWindow::InitializeWebView()
options5->put_EnableTrackingPrevention(m_TrackingPreventionEnabled ? TRUE : FALSE));
}

Microsoft::WRL::ComPtr<ICoreWebView2ExperimentalEnvironmentOptions> optionsExperimental;
if (options.As(&optionsExperimental) == S_OK)
Microsoft::WRL::ComPtr<ICoreWebView2EnvironmentOptions6> options6;
if (options.As(&options6) == S_OK)
{
CHECK_FAILURE(optionsExperimental->put_AreBrowserExtensionsEnabled(TRUE));
CHECK_FAILURE(options6->put_AreBrowserExtensionsEnabled(TRUE));
}

HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(
Expand Down Expand Up @@ -1874,41 +1874,31 @@ void AppWindow::RegisterEventHandlers()
.Get(),
nullptr));
//! [NewBrowserVersionAvailable]

//! [ProfileDeleted]
auto webView2_13 = m_webView.try_query<ICoreWebView2_13>();
if (webView2_13)
{
wil::com_ptr<ICoreWebView2Profile> webView2ProfileBase;
webView2_13->get_Profile(&webView2ProfileBase);
if (webView2ProfileBase)
{
auto webView2Profile =
webView2ProfileBase.try_query<ICoreWebView2ExperimentalProfile10>();
if (webView2Profile)
CHECK_FEATURE_RETURN_EMPTY(webView2_13);
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
CHECK_FAILURE(webView2_13->get_Profile(&webView2Profile));
CHECK_FEATURE_RETURN_EMPTY(webView2Profile);
auto webView2Profile8 = webView2Profile.try_query<ICoreWebView2Profile8>();
CHECK_FEATURE_RETURN_EMPTY(webView2Profile8);
CHECK_FAILURE(webView2Profile8->add_Deleted(
Microsoft::WRL::Callback<ICoreWebView2ProfileDeletedEventHandler>(
[this](ICoreWebView2Profile* sender, IUnknown* args)
{
CHECK_FAILURE(webView2Profile->add_Deleted(
Microsoft::WRL::Callback<
ICoreWebView2ExperimentalProfileDeletedEventHandler>(
[this](ICoreWebView2Profile* sender, IUnknown* args)
{
RunAsync(
[this]()
{
std::wstring message =
L"The profile has been marked for deletion. Any "
L"associated webview2 objects will be closed.";
MessageBox(
m_mainWindow, message.c_str(), L"webview2 closed",
MB_OK);
CloseAppWindow();
});
return S_OK;
})
.Get(),
nullptr));
}
}
}
RunAsync(
[this]()
{
std::wstring message = L"The profile has been marked for deletion. Any "
L"associated webview2 objects will be closed.";
MessageBox(m_mainWindow, message.c_str(), L"webview2 closed", MB_OK);
CloseAppWindow();
});
return S_OK;
})
.Get(),
nullptr));
//! [ProfileDeleted]
}

Expand Down
45 changes: 19 additions & 26 deletions SampleApps/WebView2APISample/ScenarioExtensionsManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ void ScenarioExtensionsManagement::InstallDefaultExtensions()
CHECK_FEATURE_RETURN_EMPTY(webView2_13);
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
CHECK_FAILURE(webView2_13->get_Profile(&webView2Profile));
auto webView2ExperimentalProfile12 =
webView2Profile.try_query<ICoreWebView2ExperimentalProfile12>();
CHECK_FEATURE_RETURN_EMPTY(webView2ExperimentalProfile12);
auto profile7 = webView2Profile.try_query<ICoreWebView2Profile7>();
CHECK_FEATURE_RETURN_EMPTY(profile7);

std::wstring extension_path_file = m_appWindow->GetLocalUri(c_samplePath, false);
// Remove "file:///" from the beginning of extension_path_file
std::wstring extension_path = extension_path_file.substr(8);

webView2ExperimentalProfile12->GetBrowserExtensions(
Callback<ICoreWebView2ExperimentalProfileGetBrowserExtensionsCompletedHandler>(
[this, webView2ExperimentalProfile12, extension_path](
HRESULT error,
ICoreWebView2ExperimentalBrowserExtensionList* extensions) -> HRESULT
profile7->GetBrowserExtensions(
Callback<ICoreWebView2ProfileGetBrowserExtensionsCompletedHandler>(
[this, profile7, extension_path](
HRESULT error, ICoreWebView2BrowserExtensionList* extensions) -> HRESULT
{
std::wstring extensionIdString;
bool extensionInstalled = false;
Expand All @@ -53,7 +51,7 @@ void ScenarioExtensionsManagement::InstallDefaultExtensions()

for (UINT index = 0; index < extensionsCount; ++index)
{
wil::com_ptr<ICoreWebView2ExperimentalBrowserExtension> extension;
wil::com_ptr<ICoreWebView2BrowserExtension> extension;
extensions->GetValueAtIndex(index, &extension);

wil::unique_cotaskmem_string id;
Expand All @@ -79,8 +77,7 @@ void ScenarioExtensionsManagement::InstallDefaultExtensions()
message += L" but was disabled.";
extension->Enable(
!enabled,
Callback<
ICoreWebView2ExperimentalBrowserExtensionEnableCompletedHandler>(
Callback<ICoreWebView2BrowserExtensionEnableCompletedHandler>(
[](HRESULT error) -> HRESULT
{
if (error != S_OK)
Expand All @@ -99,12 +96,11 @@ void ScenarioExtensionsManagement::InstallDefaultExtensions()

if (!extensionInstalled)
{
CHECK_FAILURE(webView2ExperimentalProfile12->AddBrowserExtension(
CHECK_FAILURE(profile7->AddBrowserExtension(
extension_path.c_str(),
Callback<
ICoreWebView2ExperimentalProfileAddBrowserExtensionCompletedHandler>(
Callback<ICoreWebView2ProfileAddBrowserExtensionCompletedHandler>(
[](HRESULT error,
ICoreWebView2ExperimentalBrowserExtension* extension) -> HRESULT
ICoreWebView2BrowserExtension* extension) -> HRESULT
{
if (error != S_OK)
{
Expand Down Expand Up @@ -135,14 +131,12 @@ void ScenarioExtensionsManagement::OffloadDefaultExtensionsIfExtraExtensionsInst
CHECK_FEATURE_RETURN_EMPTY(webView2_13);
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
CHECK_FAILURE(webView2_13->get_Profile(&webView2Profile));
auto webView2ExperimentalProfile12 =
webView2Profile.try_query<ICoreWebView2ExperimentalProfile12>();
CHECK_FEATURE_RETURN_EMPTY(webView2ExperimentalProfile12);

webView2ExperimentalProfile12->GetBrowserExtensions(
Callback<ICoreWebView2ExperimentalProfileGetBrowserExtensionsCompletedHandler>(
[this](HRESULT error, ICoreWebView2ExperimentalBrowserExtensionList* extensions)
-> HRESULT
auto profile7 = webView2Profile.try_query<ICoreWebView2Profile7>();
CHECK_FEATURE_RETURN_EMPTY(profile7);

profile7->GetBrowserExtensions(
Callback<ICoreWebView2ProfileGetBrowserExtensionsCompletedHandler>(
[this](HRESULT error, ICoreWebView2BrowserExtensionList* extensions) -> HRESULT
{
std::wstring extensionIdString;
UINT extensionsCount = 0;
Expand All @@ -152,7 +146,7 @@ void ScenarioExtensionsManagement::OffloadDefaultExtensionsIfExtraExtensionsInst
{
for (UINT index = 0; index < extensionsCount; ++index)
{
wil::com_ptr<ICoreWebView2ExperimentalBrowserExtension> extension;
wil::com_ptr<ICoreWebView2BrowserExtension> extension;
extensions->GetValueAtIndex(index, &extension);

wil::unique_cotaskmem_string id;
Expand All @@ -162,8 +156,7 @@ void ScenarioExtensionsManagement::OffloadDefaultExtensionsIfExtraExtensionsInst
if (extensionIdString.compare(m_extensionId) == 0)
{
extension->Remove(
Callback<
ICoreWebView2ExperimentalBrowserExtensionRemoveCompletedHandler>(
Callback<ICoreWebView2BrowserExtensionRemoveCompletedHandler>(
[extension](HRESULT error) -> HRESULT
{
if (error != S_OK)
Expand Down
34 changes: 16 additions & 18 deletions SampleApps/WebView2APISample/ScriptComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ void ScriptComponent::AddBrowserExtension()
auto webView2_13 = m_webView.try_query<ICoreWebView2_13>();
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
CHECK_FAILURE(webView2_13->get_Profile(&webView2Profile));
auto webView2ExperimentalProfile12 =
webView2Profile.try_query<ICoreWebView2ExperimentalProfile12>();
auto profile7 = webView2Profile.try_query<ICoreWebView2Profile7>();
CHECK_FEATURE_RETURN_EMPTY(profile7);

OPENFILENAME openFileName = {};
openFileName.lStructSize = sizeof(openFileName);
Expand All @@ -196,11 +196,10 @@ void ScriptComponent::AddBrowserExtension()
{
// Remove the filename part of the path.
*wcsrchr(fileName, L'\\') = L'\0';
webView2ExperimentalProfile12->AddBrowserExtension(
profile7->AddBrowserExtension(
fileName,
Callback<ICoreWebView2ExperimentalProfileAddBrowserExtensionCompletedHandler>(
[](HRESULT error,
ICoreWebView2ExperimentalBrowserExtension* extension) -> HRESULT
Callback<ICoreWebView2ProfileAddBrowserExtensionCompletedHandler>(
[](HRESULT error, ICoreWebView2BrowserExtension* extension) -> HRESULT
{
if (error != S_OK)
{
Expand Down Expand Up @@ -231,22 +230,21 @@ void ScriptComponent::RemoveOrDisableBrowserExtension(const bool remove)
auto webView2_13 = m_webView.try_query<ICoreWebView2_13>();
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
CHECK_FAILURE(webView2_13->get_Profile(&webView2Profile));
auto webView2ExperimentalProfile12 =
webView2Profile.try_query<ICoreWebView2ExperimentalProfile12>();

webView2ExperimentalProfile12->GetBrowserExtensions(
Callback<ICoreWebView2ExperimentalProfileGetBrowserExtensionsCompletedHandler>(
[this, webView2ExperimentalProfile12, remove](
HRESULT error,
ICoreWebView2ExperimentalBrowserExtensionList* extensions) -> HRESULT
auto profile7 = webView2Profile.try_query<ICoreWebView2Profile7>();
CHECK_FEATURE_RETURN_EMPTY(profile7);

profile7->GetBrowserExtensions(
Callback<ICoreWebView2ProfileGetBrowserExtensionsCompletedHandler>(
[this, profile7,
remove](HRESULT error, ICoreWebView2BrowserExtensionList* extensions) -> HRESULT
{
std::wstring extensionIdString;
UINT extensionsCount = 0;
extensions->get_Count(&extensionsCount);

for (UINT index = 0; index < extensionsCount; ++index)
{
wil::com_ptr<ICoreWebView2ExperimentalBrowserExtension> extension;
wil::com_ptr<ICoreWebView2BrowserExtension> extension;
extensions->GetValueAtIndex(index, &extension);

wil::unique_cotaskmem_string id;
Expand Down Expand Up @@ -279,7 +277,7 @@ void ScriptComponent::RemoveOrDisableBrowserExtension(const bool remove)
{
for (UINT index = 0; index < extensionsCount; ++index)
{
wil::com_ptr<ICoreWebView2ExperimentalBrowserExtension> extension;
wil::com_ptr<ICoreWebView2BrowserExtension> extension;
extensions->GetValueAtIndex(index, &extension);

wil::unique_cotaskmem_string id;
Expand All @@ -292,7 +290,7 @@ void ScriptComponent::RemoveOrDisableBrowserExtension(const bool remove)
{
extension->Remove(
Callback<
ICoreWebView2ExperimentalBrowserExtensionRemoveCompletedHandler>(
ICoreWebView2BrowserExtensionRemoveCompletedHandler>(
[](HRESULT error) -> HRESULT
{
if (error != S_OK)
Expand All @@ -313,7 +311,7 @@ void ScriptComponent::RemoveOrDisableBrowserExtension(const bool remove)
extension->Enable(
!enabled,
Callback<
ICoreWebView2ExperimentalBrowserExtensionEnableCompletedHandler>(
ICoreWebView2BrowserExtensionEnableCompletedHandler>(
[](HRESULT error) -> HRESULT
{
if (error != S_OK)
Expand Down
3 changes: 1 addition & 2 deletions SampleApps/WebView2APISample/SettingsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,7 @@ bool SettingsComponent::HandleWindowMessage(
wil::com_ptr<ICoreWebView2Profile> webView2ProfileBase;
m_webView2_13->get_Profile(&webView2ProfileBase);
CHECK_FEATURE_RETURN(webView2ProfileBase);
auto webView2Profile =
webView2ProfileBase.try_query<ICoreWebView2ExperimentalProfile10>();
auto webView2Profile = webView2ProfileBase.try_query<ICoreWebView2Profile8>();
CHECK_FEATURE_RETURN(webView2Profile);
webView2Profile->Delete();
//! [DeleteProfile]
Expand Down
4 changes: 2 additions & 2 deletions SampleApps/WebView2APISample/WebView2APISample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2164-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2164-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2194-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2194-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2164-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2164-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2194-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2194-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,63 @@
text-align: center;
app-region: no-drag;
}

#textarea {
app-region: drag;
}

#textarea:hover {
border: 1px solid red;
}

#button {
app-region: drag;
}

#button:hover {
border: 1px solid red;
}
</style>
</head>
<body>
<h1 class="center">Non-Client Region Support</h1>
<div class="draggable">
<div class="draggable" id="drag-region">
<p>Draggable Region</p>
</div>
<p>
<p>
Note: This site will always have non-client region support enabled.
Upon navigating away from this site, non-client region support will be disabled.
</p>

<h2>Interactive Elements</h2>
<p>
This shows how app-region drag can work with interactive elements
</p>
<textarea id="textarea" placeholder="type here" rows="4" cols="13"></textarea>
<button id="button">Click or Drag me</button>
<p>Click counter: <span id="counter">0</span></p>

<script>
const textarea = document.getElementById("textarea");
const dragarea = document.getElementById("drag-region");
const button = document.getElementById("button");
const dragareaInitialWidth = dragarea.clientWidth;
const counter = document.getElementById("counter");


textarea.addEventListener("focus", (e) => {
textarea.style['app-region'] = "no-drag";
dragarea.style.width = `${dragareaInitialWidth - 1}px`;
});

textarea.addEventListener("blur", (e) => {
textarea.style['app-region'] = "drag";
dragarea.style.width = `${dragareaInitialWidth + 1}px`;
})

button.addEventListener("click", () => {
counter.innerText = parseInt(counter.innerText) + 1;
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion SampleApps/WebView2APISample/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.WebView2" version="1.0.2164-prerelease" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.2194-prerelease" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2164-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2194-prerelease" />
</ItemGroup>
<ItemGroup>
<Folder Include="assets\" />
Expand Down
Loading

0 comments on commit 85e53c9

Please sign in to comment.