Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion SampleApps/WebView2APISample/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "ScenarioVirtualHostMappingForPopUpWindow.h"
#include "ScenarioVirtualHostMappingForSW.h"
#include "ScenarioWebMessage.h"
#include "ScenarioWebRtcUdpPortConfiguration.h"
#include "ScenarioWebViewEventMonitor.h"
#include "ScenarioWindowControlsOverlay.h"
#include "ScriptComponent.h"
Expand Down Expand Up @@ -531,6 +532,11 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
NewComponent<ScenarioWebMessage>(this);
return true;
}
case IDM_SCENARIO_WEBRTC_UDP_PORT_CONFIGURATION:
{
NewComponent<ScenarioWebRtcUdpPortConfiguration>(this);
return true;
}
case IDM_SCENARIO_ADD_HOST_OBJECT:
{
NewComponent<ScenarioAddHostObject>(this);
Expand Down Expand Up @@ -597,6 +603,21 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
NewComponent<ScenarioExtensionsManagement>(this, true);
return true;
}
case IDM_SCENARIO_DRAG_DROP_OVERRIDE:
{
if (m_dcompDevice || m_wincompCompositor)
{
NewComponent<ScenarioDragDropOverride>(this);
}
else
{
MessageBox(
m_mainWindow,
L"Drag and Drop Override is only supported in visual hosting mode",
L"Drag and Drop Override", MB_OK);
}
return true;
}
case IDM_SCENARIO_CUSTOM_SCHEME:
{
NewComponent<ScenarioCustomScheme>(this);
Expand Down Expand Up @@ -1777,7 +1798,7 @@ void AppWindow::InitializeWebView()
args.append(
L"--enable-features=ThirdPartyStoragePartitioning,PartitionedCookies,"
L"msPageInteractionManagerWebview2");
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
auto options = Microsoft::WRL::Make<CoreWebView2ExperimentalEnvironmentOptions>();
options->put_AdditionalBrowserArguments(args.c_str());
CHECK_FAILURE(
options->put_AllowSingleSignOnUsingOSPrimaryAccount(m_AADSSOEnabled ? TRUE : FALSE));
Expand Down Expand Up @@ -1833,6 +1854,24 @@ void AppWindow::InitializeWebView()
CHECK_FAILURE(options8->put_ScrollBarStyle(style));
}

Microsoft::WRL::ComPtr<ICoreWebView2ExperimentalEnvironmentOptions> optionsExperimental;
if (options.As(&optionsExperimental) == S_OK)
{
// Configure port ranges for WebRTC UDP traffic to work within enterprise firewalls
// Set UDP port range (example: 50000-55000 for enterprise environments)
const INT32 udpMin = 50000, udpMax = 55000;

CHECK_FAILURE(optionsExperimental->SetAllowedPortRange(
COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_WEB_RTC,
COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP, udpMin, udpMax));

// Get the configured port range
CHECK_FAILURE(optionsExperimental->GetEffectiveAllowedPortRange(
COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_WEB_RTC,
COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP, &m_udpPortRange.minPort,
&m_udpPortRange.maxPort));
}

HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(
subFolder, m_userDataFolder.c_str(), options.Get(),
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
Expand Down
14 changes: 14 additions & 0 deletions SampleApps/WebView2APISample/AppWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ struct SamplePrintSettings
std::wstring FooterUri = L"";
};

// Port range configuration
struct PortRangeConfig
{
INT32 minPort = 0;
INT32 maxPort = 0;
};

class AppWindow
{
public:
Expand Down Expand Up @@ -172,6 +179,12 @@ class AppWindow
{
return m_webviewOption;
}

const PortRangeConfig& GetUdpPortRange() const
{
return m_udpPortRange;
}

private:
static PCWSTR GetWindowClass();

Expand Down Expand Up @@ -290,6 +303,7 @@ class AppWindow

bool m_CustomCrashReportingEnabled = false;
bool m_TrackingPreventionEnabled = true;
PortRangeConfig m_udpPortRange;
private:
// Fullscreen related code
RECT m_previousWindowRect;
Expand Down
15 changes: 7 additions & 8 deletions SampleApps/WebView2APISample/ScenarioDragDropOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ ScenarioDragDropOverride::ScenarioDragDropOverride(AppWindow* appWindow)
return;
}

m_compControllerExperimental6 =
compController.try_query<ICoreWebView2ExperimentalCompositionController6>();
if (!m_compControllerExperimental6)
m_compController5 = compController.try_query<ICoreWebView2CompositionController5>();
if (!m_compController5)
{
return;
}
Expand Down Expand Up @@ -70,11 +69,11 @@ ScenarioDragDropOverride::ScenarioDragDropOverride(AppWindow* appWindow)
//! [DragStarting]
// Using DragStarting to simply make a synchronous DoDragDrop call instead of
// having WebView2 do it.
CHECK_FAILURE(m_compControllerExperimental6->add_DragStarting(
Callback<ICoreWebView2ExperimentalDragStartingEventHandler>(
CHECK_FAILURE(m_compController5->add_DragStarting(
Callback<ICoreWebView2DragStartingEventHandler>(
[this](
ICoreWebView2CompositionController* sender,
ICoreWebView2ExperimentalDragStartingEventArgs* args)
ICoreWebView2DragStartingEventArgs* args)
{
if (m_dragOverrideMode != DragOverrideMode::OVERRIDE)
{
Expand Down Expand Up @@ -126,9 +125,9 @@ ScenarioDragDropOverride::ScenarioDragDropOverride(AppWindow* appWindow)

ScenarioDragDropOverride::~ScenarioDragDropOverride()
{
if (m_compControllerExperimental6)
if (m_compController5)
{
CHECK_FAILURE(m_compControllerExperimental6->remove_DragStarting(m_dragStartingToken));
CHECK_FAILURE(m_compController5->remove_DragStarting(m_dragStartingToken));
}
CHECK_FAILURE(m_webView->remove_WebMessageReceived(m_webMessageReceivedToken));
CHECK_FAILURE(m_webView->remove_ContentLoading(m_contentLoadingToken));
Expand Down
2 changes: 1 addition & 1 deletion SampleApps/WebView2APISample/ScenarioDragDropOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ScenarioDragDropOverride : public ComponentBase
AppWindow* m_appWindow = nullptr;
std::wstring m_sampleUri;
wil::com_ptr<ICoreWebView2> m_webView = nullptr;
wil::com_ptr<ICoreWebView2ExperimentalCompositionController6> m_compControllerExperimental6;
wil::com_ptr<ICoreWebView2CompositionController5> m_compController5;
wil::com_ptr<IDropSource> m_dropSource;
DragOverrideMode m_dragOverrideMode = DragOverrideMode::DEFAULT;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 "CheckFailure.h"
#include "TextInputDialog.h"

#include "ScenarioWebRtcUdpPortConfiguration.h"

using namespace Microsoft::WRL;

static constexpr WCHAR c_samplePath[] = L"ScenarioWebRtcUdpPortConfiguration.html";

ScenarioWebRtcUdpPortConfiguration::ScenarioWebRtcUdpPortConfiguration(AppWindow* appWindow)
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())
{
// Demonstrates how to configure a custom WebRTC UDP port range using the
// new ICoreWebView2WebRtcPortConfiguration exposed via
// ICoreWebView2ExperimentalEnvironmentOptions.

// Navigate to a demo page that will trigger WebRTC usage.
m_sampleUri = m_appWindow->GetLocalUri(c_samplePath);
CHECK_FAILURE(m_webView->Navigate(m_sampleUri.c_str()));

// If we navigate away from the demo page, turn off this scenario.
CHECK_FAILURE(m_webView->add_ContentLoading(
Callback<ICoreWebView2ContentLoadingEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2ContentLoadingEventArgs* /*args*/)
-> HRESULT
{
wil::unique_cotaskmem_string uri;
CHECK_FAILURE(sender->get_Source(&uri));
if (uri.get() != m_sampleUri)
{
m_appWindow->DeleteComponent(this);
}
return S_OK;
})
.Get(),
&m_contentLoadingToken));
}

ScenarioWebRtcUdpPortConfiguration::~ScenarioWebRtcUdpPortConfiguration()
{
CHECK_FAILURE(m_webView->remove_ContentLoading(m_contentLoadingToken));
}
22 changes: 22 additions & 0 deletions SampleApps/WebView2APISample/ScenarioWebRtcUdpPortConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 "AppWindow.h"
#include "ComponentBase.h"

// Demonstrates configuring WebRTC UDP port ranges via WebView2 environment options.
class ScenarioWebRtcUdpPortConfiguration : public ComponentBase
{
public:
ScenarioWebRtcUdpPortConfiguration(AppWindow* appWindow);
~ScenarioWebRtcUdpPortConfiguration() override;

private:
AppWindow* m_appWindow = nullptr;
wil::com_ptr<ICoreWebView2> m_webView;
EventRegistrationToken m_contentLoadingToken = {};
std::wstring m_sampleUri;
};
3 changes: 3 additions & 0 deletions SampleApps/WebView2APISample/WebView2APISample.rc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ BEGIN
MENUITEM "Service worker WebResourceRequested", IDM_SCENARIO_SERVICE_WORKER_WRR
MENUITEM "Shared worker WebResourceRequested", IDM_SCENARIO_SHARED_WORKER
END
MENUITEM "WebRTC UDP Port Configuration", IDM_SCENARIO_WEBRTC_UDP_PORT_CONFIGURATION
POPUP "Custom Download Experience"
BEGIN
MENUITEM "Use Deferred Download Dialog", IDM_SCENARIO_USE_DEFERRED_DOWNLOAD
Expand Down Expand Up @@ -301,6 +302,7 @@ BEGIN
MENUITEM "Web Messaging", IDM_SCENARIO_POST_WEB_MESSAGE
MENUITEM "WebView Event Monitor", IDM_SCENARIO_WEB_VIEW_EVENT_MONITOR
MENUITEM "WebView Window Controls Overlay", IDM_SCENARIO_WINDOW_CONTROLS_OVERLAY

MENUITEM "Dropped file path", IDM_SCENARIO_DROPPED_FILE_PATH
POPUP "Save As"
BEGIN
Expand Down Expand Up @@ -328,6 +330,7 @@ BEGIN
MENUITEM "Listen to new Shared Worker Creations", IDM_SCENARIO_SHARED_WORKER_MANAGER
MENUITEM "Get Shared Workers", IDM_SCENARIO_GET_SHARED_WORKERS
END
MENUITEM "Drag Drop Override", IDM_SCENARIO_DRAG_DROP_OVERRIDE
POPUP "Start Find"
BEGIN
MENUITEM "Start Find on Page Dialog", IDM_START_FIND
Expand Down
6 changes: 4 additions & 2 deletions SampleApps/WebView2APISample/WebView2APISample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
<ClInclude Include="ScenarioVirtualHostMappingForPopUpWindow.h" />
<ClInclude Include="ScenarioVirtualHostMappingForSW.h" />
<ClInclude Include="ScenarioWebMessage.h" />
<ClInclude Include="ScenarioWebRtcUdpPortConfiguration.h" />
<ClInclude Include="ScenarioWebViewEventMonitor.h" />
<ClInclude Include="ScenarioWindowControlsOverlay.h" />
<ClInclude Include="ScriptComponent.h" />
Expand Down Expand Up @@ -324,6 +325,7 @@
<ClCompile Include="ScenarioVirtualHostMappingForPopUpWindow.cpp" />
<ClCompile Include="ScenarioVirtualHostMappingForSW.cpp" />
<ClCompile Include="ScenarioWebMessage.cpp" />
<ClCompile Include="ScenarioWebRtcUdpPortConfiguration.cpp" />
<ClCompile Include="ScenarioWebViewEventMonitor.cpp" />
<ClCompile Include="ScenarioWindowControlsOverlay.cpp" />
<ClCompile Include="ScriptComponent.cpp" />
Expand Down Expand Up @@ -530,13 +532,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.3650-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3650-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3712-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3712-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.3650-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3650-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3712-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3712-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
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.3650-prerelease" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.3712-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 @@ -200,6 +200,7 @@
#define IDM_SCENARIO_GET_SERVICE_WORKER_REGISTERED_FOR_SCOPE 2054
#define IDM_SCENARIO_GET_SHARED_WORKERS 2055
#define IDM_SCENARIO_WINDOW_CONTROLS_OVERLAY 2057
#define IDM_SCENARIO_DRAG_DROP_OVERRIDE 2058
#define IDC_FIND_TERM 2059
#define IDC_IS_CASE_SENSITIVE 2060
#define IDC_SHOULD_MATCH_WHOLE_WORD 2061
Expand All @@ -217,6 +218,7 @@
#define IDM_CREATION_MODE_HOST_INPUT_PROCESSING 3006
#define IDM_SCENARIO_DEDICATED_WORKER_POST_MESSAGE 3009
#define IDM_SCENARIO_SERVICE_WORKER_POST_MESSAGE 3010
#define IDM_SCENARIO_WEBRTC_UDP_PORT_CONFIGURATION 3011
#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.3650-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3712-prerelease" />
</ItemGroup>
<ItemGroup>
<Folder Include="assets\" />
Expand Down
4 changes: 4 additions & 0 deletions SampleApps/WebView2WpfBrowser/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ found in the LICENSE file.
<CommandBinding Command="{x:Static local:MainWindow.DedicatedWorkerPostMessageCommand}" Executed="DedicatedWorkerPostMessageExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.SharedWorkerManagerCommand}" Executed="SharedWorkerManagerExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.GetSharedWorkersCommand}" Executed="GetSharedWorkersExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.WebRtcUdpPortConfigCommand}" Executed="WebRtcUdpPortConfigCommandExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<!-- #endif -->
<CommandBinding Command="{x:Static local:MainWindow.ChildFrameEventsCommand}" Executed="ChildFrameEventsExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.RemoveChildFrameEventsCommand}" Executed="RemoveChildFrameEventsExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
Expand Down Expand Up @@ -246,6 +247,9 @@ found in the LICENSE file.
<MenuItem Header="_Start Deferred Download" Command="{x:Static local:MainWindow.DownloadStartingCommand}"/>
<MenuItem Header="_Set Default Download Folder Path" Command="{x:Static local:MainWindow.SetDefaultDownloadPathCommand}"/>
</MenuItem>
<!-- #if USE_WEBVIEW2_EXPERIMENTAL -->
<MenuItem Header="_WebRTC UDP Port Configuration" Command="{x:Static local:MainWindow.WebRtcUdpPortConfigCommand}"/>
<!-- #endif -->
<MenuItem Header="_Print">
<MenuItem Header="_Print dialog">
<MenuItem Header="_Browser Print Preview" Command="{x:Static local:MainWindow.PrintDialogCommand}" CommandParameter="Browser"/>
Expand Down
Loading
Loading