Skip to content

Commit

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

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

---------

Co-authored-by: WebView2 Github Bot <webview2github@microsoft.com>
  • Loading branch information
peiche-jessica and WebView2GithubBot committed Feb 26, 2024
1 parent bd07ad2 commit 5396ff5
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 45 deletions.
4 changes: 4 additions & 0 deletions SampleApps/WebView2APISample/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmd
{
creationModeId = IDM_CREATION_MODE_WINDOWED;
}
else if (NEXT_PARAM_CONTAINS(L"allowhostinput"))
{
creationModeId = IDM_CREATION_MODE_HOST_INPUT_PROCESSING;
}
else if (NEXT_PARAM_CONTAINS(L"visualdcomp"))
{
creationModeId = IDM_CREATION_MODE_VISUAL_DCOMP;
Expand Down
25 changes: 20 additions & 5 deletions SampleApps/WebView2APISample/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "FileComponent.h"
#include "ProcessComponent.h"
#include "Resource.h"
#include "ScenarioAcceleratorKeyPressed.h"
#include "ScenarioAddHostObject.h"
#include "ScenarioAuthentication.h"
#include "ScenarioClientCertificateRequested.h"
Expand All @@ -40,7 +41,6 @@
#include "ScenarioIFrameDevicePermission.h"
#include "ScenarioNavigateWithWebResourceRequest.h"
#include "ScenarioNonClientRegionSupport.h"
#include "ScenarioAcceleratorKeyPressed.h"
#include "ScenarioNotificationReceived.h"
#include "ScenarioPermissionManagement.h"
#include "ScenarioSharedBuffer.h"
Expand Down Expand Up @@ -729,6 +729,7 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
CloseAppWindow();
return true;
case IDM_CREATION_MODE_WINDOWED:
case IDM_CREATION_MODE_HOST_INPUT_PROCESSING:
case IDM_CREATION_MODE_VISUAL_DCOMP:
case IDM_CREATION_MODE_TARGET_DCOMP:
case IDM_CREATION_MODE_VISUAL_WINCOMP:
Expand Down Expand Up @@ -794,7 +795,8 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
case IDM_SCENARIO_CLEAR_BROWSING_DATA_AUTOFILL:
{
return ClearBrowsingData((
COREWEBVIEW2_BROWSING_DATA_KINDS)(COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL | COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE));
COREWEBVIEW2_BROWSING_DATA_KINDS)(COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL |
COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE));
}
case IDM_SCENARIO_CLEAR_BROWSING_DATA_BROWSING_HISTORY:
{
Expand Down Expand Up @@ -1390,7 +1392,8 @@ HRESULT AppWindow::OnCreateEnvironmentCompleted(
}
m_webViewEnvironment = environment;

if (m_webviewOption.entry == WebViewCreateEntry::EVER_FROM_CREATE_WITH_OPTION_MENU
if (m_webviewOption.entry == WebViewCreateEntry::EVER_FROM_CREATE_WITH_OPTION_MENU ||
m_creationModeId == IDM_CREATION_MODE_HOST_INPUT_PROCESSING
)
{
return CreateControllerWithOptions();
Expand Down Expand Up @@ -1470,6 +1473,19 @@ HRESULT AppWindow::CreateControllerWithOptions()
}
//! [ScriptLocaleSetting]

//! [AllowHostInputProcessing]
if (m_creationModeId == IDM_CREATION_MODE_HOST_INPUT_PROCESSING)
{
wil::com_ptr<ICoreWebView2ExperimentalControllerOptions2>
webView2ExperimentalControllerOptions2;
if (SUCCEEDED(
options->QueryInterface(IID_PPV_ARGS(&webView2ExperimentalControllerOptions2))))
{
CHECK_FAILURE(
webView2ExperimentalControllerOptions2->put_AllowHostInputProcessing(TRUE));
}
}
//! [AllowHostInputProcessing]
if (m_dcompDevice || m_wincompCompositor)
{
//! [OnCreateCoreWebView2ControllerCompleted]
Expand Down Expand Up @@ -2346,8 +2362,7 @@ void AppWindow::UpdateCreationModeMenu()
{
HMENU hMenu = GetMenu(m_mainWindow);
CheckMenuRadioItem(
hMenu, IDM_CREATION_MODE_WINDOWED,
IDM_CREATION_MODE_VISUAL_WINCOMP,
hMenu, IDM_CREATION_MODE_WINDOWED, IDM_CREATION_MODE_HOST_INPUT_PROCESSING,
m_creationModeId, MF_BYCOMMAND);
}

Expand Down
2 changes: 1 addition & 1 deletion SampleApps/WebView2APISample/ControlComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void ControlComponent::NavigateToAddressBar()
}
else
{
// Otherwise treat it as a web search.
// Otherwise treat it as a web search.
std::wstring urlEscaped(2048, ' ');
DWORD dwEscaped = (DWORD)urlEscaped.length();
UrlEscapeW(uri.c_str(), &urlEscaped[0], &dwEscaped, URL_ESCAPE_ASCII_URI_COMPONENT);
Expand Down
33 changes: 14 additions & 19 deletions SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ ScenarioNonClientRegionSupport::ScenarioNonClientRegionSupport(AppWindow* appWin
controller.try_query<ICoreWebView2CompositionController>();
if (compController)
{
m_compController5 =
compController.try_query<ICoreWebView2ExperimentalCompositionController5>();
m_compController4 = compController.try_query<ICoreWebView2CompositionController4>();
}

CHECK_FAILURE(m_webView->get_Settings(&m_settings));

m_experimentalSettings = m_settings.try_query<ICoreWebView2ExperimentalSettings8>();
m_settings9 = m_settings.try_query<ICoreWebView2Settings9>();

CHECK_FAILURE(m_webView->add_NavigationStarting(
Callback<ICoreWebView2NavigationStartingEventHandler>(
Expand All @@ -36,22 +35,19 @@ ScenarioNonClientRegionSupport::ScenarioNonClientRegionSupport(AppWindow* appWin
{
wil::unique_cotaskmem_string uri;
CHECK_FAILURE(args->get_Uri(&uri));
CHECK_FEATURE_RETURN(m_experimentalSettings);
CHECK_FEATURE_RETURN(m_settings9);

BOOL enabled = 0;
CHECK_FAILURE(
m_experimentalSettings->get_IsNonClientRegionSupportEnabled(&enabled));
CHECK_FAILURE(m_settings9->get_IsNonClientRegionSupportEnabled(&enabled));

if (uri.get() == m_sampleUri && !enabled)
{
CHECK_FAILURE(
m_experimentalSettings->put_IsNonClientRegionSupportEnabled(TRUE));
CHECK_FAILURE(m_settings9->put_IsNonClientRegionSupportEnabled(TRUE));
AddChangeListener();
}
else if (uri.get() != m_sampleUri && enabled)
{
CHECK_FAILURE(
m_experimentalSettings->put_IsNonClientRegionSupportEnabled(FALSE));
CHECK_FAILURE(m_settings9->put_IsNonClientRegionSupportEnabled(FALSE));
}
return S_OK;
})
Expand Down Expand Up @@ -79,20 +75,19 @@ ScenarioNonClientRegionSupport::ScenarioNonClientRegionSupport(AppWindow* appWin
//! [AddChangeListener]
void ScenarioNonClientRegionSupport::AddChangeListener()
{
if (m_compController5)
if (m_compController4)
{
CHECK_FAILURE(m_compController5->add_NonClientRegionChanged(
Callback<ICoreWebView2ExperimentalNonClientRegionChangedEventHandler>(
CHECK_FAILURE(m_compController4->add_NonClientRegionChanged(
Callback<ICoreWebView2NonClientRegionChangedEventHandler>(
[this](
ICoreWebView2CompositionController* sender,
ICoreWebView2ExperimentalNonClientRegionChangedEventArgs* args) -> HRESULT
ICoreWebView2NonClientRegionChangedEventArgs* args) -> HRESULT
{
COREWEBVIEW2_NON_CLIENT_REGION_KIND region =
COREWEBVIEW2_NON_CLIENT_REGION_KIND_NOWHERE;
args->get_RegionKind(&region);
wil::com_ptr<ICoreWebView2ExperimentalRegionRectCollectionView>
regionsCollection;
m_compController5->QueryNonClientRegion(region, &regionsCollection);
wil::com_ptr<ICoreWebView2RegionRectCollectionView> regionsCollection;
m_compController4->QueryNonClientRegion(region, &regionsCollection);
UINT32 count = 0;
regionsCollection->get_Count(&count);
RECT rect;
Expand All @@ -108,9 +103,9 @@ ScenarioNonClientRegionSupport::~ScenarioNonClientRegionSupport()
{
CHECK_FAILURE(m_webView->remove_NavigationStarting(m_navigationStartingToken));
CHECK_FAILURE(m_webView->remove_ContentLoading(m_ContentLoadingToken));
if (m_compController5)
if (m_compController4)
{
CHECK_FAILURE(
m_compController5->remove_NonClientRegionChanged(m_nonClientRegionChanged));
m_compController4->remove_NonClientRegionChanged(m_nonClientRegionChanged));
}
}
5 changes: 3 additions & 2 deletions SampleApps/WebView2APISample/ScenarioNonClientRegionSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class ScenarioNonClientRegionSupport : public ComponentBase
AppWindow* m_appWindow;
wil::com_ptr<ICoreWebView2> m_webView;
wil::com_ptr<ICoreWebView2Settings> m_settings;
wil::com_ptr<ICoreWebView2ExperimentalSettings8> m_experimentalSettings;
wil::com_ptr<ICoreWebView2ExperimentalCompositionController5> m_compController5;

wil::com_ptr<ICoreWebView2Settings9> m_settings9;
wil::com_ptr<ICoreWebView2CompositionController4> m_compController4;
std::wstring m_sampleUri;

EventRegistrationToken m_navigationStartingToken = {};
Expand Down
14 changes: 7 additions & 7 deletions SampleApps/WebView2APISample/SettingsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,23 +1293,23 @@ bool SettingsComponent::HandleWindowMessage(
{
//![ToggleNonClientRegionSupportEnabled]
BOOL nonClientRegionSupportEnabled;
wil::com_ptr<ICoreWebView2ExperimentalSettings8> experimentalSettings;
experimentalSettings = m_settings.try_query<ICoreWebView2ExperimentalSettings8>();
CHECK_FEATURE_RETURN(experimentalSettings);
wil::com_ptr<ICoreWebView2Settings9> settings;
settings = m_settings.try_query<ICoreWebView2Settings9>();
CHECK_FEATURE_RETURN(settings);

CHECK_FAILURE(experimentalSettings->get_IsNonClientRegionSupportEnabled(
&nonClientRegionSupportEnabled));
CHECK_FAILURE(
settings->get_IsNonClientRegionSupportEnabled(&nonClientRegionSupportEnabled));
if (nonClientRegionSupportEnabled)
{
CHECK_FAILURE(experimentalSettings->put_IsNonClientRegionSupportEnabled(FALSE));
CHECK_FAILURE(settings->put_IsNonClientRegionSupportEnabled(FALSE));
MessageBox(
nullptr,
L"Non-client region support will be disabled after the next navigation",
L"Settings change", MB_OK);
}
else
{
CHECK_FAILURE(experimentalSettings->put_IsNonClientRegionSupportEnabled(TRUE));
CHECK_FAILURE(settings->put_IsNonClientRegionSupportEnabled(TRUE));
MessageBox(
nullptr,
L"Non-client region support will be enabled after the next navigation",
Expand Down
11 changes: 5 additions & 6 deletions SampleApps/WebView2APISample/ViewComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,16 @@ ViewComponent::ViewComponent(
bool ViewComponent::HandleWindowMessage(
HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* result)
{
wil::com_ptr<ICoreWebView2ExperimentalCompositionController5> compositionController5;
wil::com_ptr<ICoreWebView2CompositionController4> compositionController4;

if (m_compositionController)
{
compositionController5 =
m_compositionController
.try_query<ICoreWebView2ExperimentalCompositionController5>();
compositionController4 =
m_compositionController.try_query<ICoreWebView2CompositionController4>();
}

//! [DraggableRegions1]
if (message == WM_NCHITTEST && compositionController5)
if (message == WM_NCHITTEST && compositionController4)
{
POINT point{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
ScreenToClient(hWnd, &point);
Expand All @@ -230,7 +229,7 @@ bool ViewComponent::HandleWindowMessage(

COREWEBVIEW2_NON_CLIENT_REGION_KIND region =
COREWEBVIEW2_NON_CLIENT_REGION_KIND_NOWHERE;
CHECK_FAILURE(compositionController5->GetNonClientRegionAtPoint(point, &region));
CHECK_FAILURE(compositionController4->GetNonClientRegionAtPoint(point, &region));
*result = region;
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions SampleApps/WebView2APISample/WebView2APISample.rc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ BEGIN
POPUP "WebView Creation Mode"
BEGIN
MENUITEM "Windowed", IDM_CREATION_MODE_WINDOWED
MENUITEM "Windowed - HostInputProcessing", IDM_CREATION_MODE_HOST_INPUT_PROCESSING
MENUITEM "Visual - DComp", IDM_CREATION_MODE_VISUAL_DCOMP
MENUITEM "Target - DComp", IDM_CREATION_MODE_TARGET_DCOMP
MENUITEM "Visual - WinComp", IDM_CREATION_MODE_VISUAL_WINCOMP
Expand Down Expand Up @@ -294,6 +295,7 @@ BEGIN
MENUITEM "Virtual Host Mapping For Pop Up Window", IDM_SCENARIO_VIRTUAL_HOST_MAPPING_POP_UP_WINDOW
MENUITEM "Web Messaging", IDM_SCENARIO_POST_WEB_MESSAGE
MENUITEM "WebView Event Monitor", IDM_SCENARIO_WEB_VIEW_EVENT_MONITOR
MENUITEM "Dropped file path", IDM_SCENARIO_DROPPED_FILE_PATH
MENUITEM "Accelerator Key Pressed", IDM_SCENARIO_ACCELERATOR_KEY_PRESSED
END
POPUP "&Audio"
Expand Down
4 changes: 2 additions & 2 deletions SampleApps/WebView2APISample/WebView2APISample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,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.2357-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2357-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2415-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2415-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.2357-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2357-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2415-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2415-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
4 changes: 4 additions & 0 deletions SampleApps/WebView2APISample/assets/AppStartPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html {
color-scheme: light dark;
}

/*
This style is used when the app cannot make the background transparent.
It will enable this style by executing script.
Expand Down
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.2357-prerelease" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.2415-prerelease" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
</packages>
2 changes: 2 additions & 0 deletions SampleApps/WebView2APISample/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
#define IDM_SCENARIO_PRINT_TO_PRINTER 2032
#define IDM_SCENARIO_PRINT_TO_PDF_STREAM 2033
#define IDM_SCENARIO_SHARED_BUFFER 2034
#define IDM_SCENARIO_DROPPED_FILE_PATH 2035
#define IDM_PERMISSION_MANAGEMENT 2036
#define IDM_SCENARIO_CLEAR_CUSTOM_DATA_PARTITION 2037
#define IDM_SCENARIO_NON_CLIENT_REGION_SUPPORT 2038
Expand All @@ -182,6 +183,7 @@
#define IDM_CREATION_MODE_VISUAL_DCOMP 3001
#define IDM_CREATION_MODE_TARGET_DCOMP 3002
#define IDM_CREATION_MODE_VISUAL_WINCOMP 3003
#define IDM_CREATION_MODE_HOST_INPUT_PROCESSING 3006
#define ID_BLOCKEDSITES 32773
#define ID_SETTINGS_NAVIGATETOSTRING 32774
#define ID_ADD_INITIALIZE_SCRIPT 32775
Expand Down
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.2357-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2415-prerelease" />
</ItemGroup>
<ItemGroup>
<Folder Include="assets\" />
Expand Down
5 changes: 5 additions & 0 deletions SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public partial class MainWindow : Window
public static RoutedCommand ProgrammaticSaveAsCommand = new RoutedCommand();
public static RoutedCommand ToggleSilentCommand = new RoutedCommand();
public static RoutedCommand ThrottlingControlCommand = new RoutedCommand();
public static RoutedCommand FileExplorerCommand = new RoutedCommand();

#endregion commands

bool _isNavigating = false;
Expand Down Expand Up @@ -3313,6 +3315,9 @@ string GetJSONStringField(string jsonMessage, string fieldName)
return jsonMessage.Substring(start, end);
}

void FileExplorerExecuted(object target, ExecutedRoutedEventArgs e)
{
}
void ThrottlingControlExecuted(object target, ExecutedRoutedEventArgs e)
{
}
Expand Down
2 changes: 1 addition & 1 deletion SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2357-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2415-prerelease" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>

0 comments on commit 5396ff5

Please sign in to comment.