@@ -23,7 +23,7 @@ Common scenarios:
2323
2424Usage steps:
25251 . Create ` CoreWebView2EnvironmentOptions ` .
26- 2 . Call ` SetAllowedPortRange ` for ` COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP ` .
26+ 2 . Call ` SetAllowedPortRange ` for ` COREWEBVIEW2_NETWORK_COMPONENT_SCOPE_WEB_R_T_C ` and ` COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP ` .
27273 . Pass the options when creating the WebView2 environment.
2828
2929
@@ -38,10 +38,12 @@ if (options.As(&optionsStaging10) == S_OK)
3838 const INT32 udpMin = 50000, udpMax = 55000;
3939
4040 CHECK_FAILURE (optionsStaging10->SetAllowedPortRange(
41+ COREWEBVIEW2_NETWORK_COMPONENT_SCOPE_WEB_R_T_C,
4142 COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP, udpMin, udpMax));
4243
4344 // Get the configured port range
4445 CHECK_FAILURE (optionsStaging10->GetAllowedPortRange(
46+ COREWEBVIEW2_NETWORK_COMPONENT_SCOPE_WEB_R_T_C,
4547 COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP, &m_udpPortRange.minPort,
4648 &m_udpPortRange.maxPort));
4749}
@@ -64,10 +66,12 @@ if (optionsStaging10 != null)
6466 const int udpMin = 50000 , udpMax = 55000 ;
6567
6668 optionsStaging10 .SetAllowedPortRange (
69+ COREWEBVIEW2_NETWORK_COMPONENT_SCOPE_WEB_R_T_C ,
6770 COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP , udpMin , udpMax );
6871
6972 // Get the configured port range
7073 optionsStaging10 .GetAllowedPortRange (
74+ COREWEBVIEW2_NETWORK_COMPONENT_SCOPE_WEB_R_T_C ,
7175 COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP , out m_udpPortRange .minPort ,
7276 out m_udpPortRange .maxPort );
7377}
@@ -80,6 +84,15 @@ OnCreateEnvironmentCompleted(environment);
8084# API Details
8185### C++
8286```
87+ /// Specifies the network component scope for port configuration.
88+ [v1_enum]
89+ typedef enum COREWEBVIEW2_NETWORK_COMPONENT_SCOPE {
90+ /// Scope applies to all components.
91+ COREWEBVIEW2_NETWORK_COMPONENT_SCOPE_ALL,
92+ /// Applies only to WebRTC peer-to-peer connection.
93+ COREWEBVIEW2_NETWORK_COMPONENT_SCOPE_WEB_R_T_C,
94+ } COREWEBVIEW2_NETWORK_COMPONENT_SCOPE;
95+
8396/// Specifies the network protocol for port configuration.
8497[v1_enum]
8598typedef enum COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND {
@@ -88,11 +101,15 @@ typedef enum COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND {
88101} COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND;
89102
90103/// Additional options used to create WebView2 Environment to manage port range configuration.
91- [uuid(eaf22436-27a1-5e3d-a4e3-84d7e7a69a1a ), object, pointer_default(unique)]
104+ [uuid(6ce30f6b-5dcc-5dc1-9c09-723cf233dbe5 ), object, pointer_default(unique)]
92105interface ICoreWebView2StagingEnvironmentOptions10 : IUnknown {
93- /// Sets the allowed port range for the specified transport protocol.
106+ /// Sets the allowed port range restriction for the specified network component
107+ /// scope and transport protocol.
108+ ///
94109 /// This API enables WebView2 to operate within enterprise network or firewall
95110 /// restrictions by limiting network communication to a defined port range.
111+ /// It provides fine-grained control by allowing port restrictions to be applied
112+ /// per network component scope, such as WebRTC or QUIC.
96113 ///
97114 /// Currently, only WebRTC UDP Port Range restriction is supported.
98115 ///
@@ -105,11 +122,13 @@ interface ICoreWebView2StagingEnvironmentOptions10 : IUnknown {
105122 ///
106123 /// Calls with invalid ranges fail with `E_INVALIDARG`.
107124 ///
108- /// `protocol` The transport protocol (currently only UDP is supported).
125+ /// `scope` Network scope on which restrictions will apply.
126+ /// `protocol` Transport protocol on which restrictions will apply.
109127 /// `minPort` The minimum allowed port number (inclusive).
110128 /// `maxPort` The maximum allowed port number (inclusive).
111129 ///
112130 HRESULT SetAllowedPortRange(
131+ [in] COREWEBVIEW2_NETWORK_COMPONENT_SCOPE scope,
113132 [in] COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND protocol,
114133 [in] INT32 minPort,
115134 [in] INT32 maxPort
@@ -122,11 +141,13 @@ interface ICoreWebView2StagingEnvironmentOptions10 : IUnknown {
122141 /// By default, `(0, 0)` is returned, which indicates no restrictions are applied
123142 /// and ports are allocated from the system’s ephemeral range (1025–65535 inclusive).
124143 ///
125- /// `protocol` The transport protocol (currently only UDP is supported).
144+ /// `scope` Network scope on which restrictions is applied.
145+ /// `protocol` Transport protocol on which restrictions is applied.
126146 /// `minPort` Receives the minimum allowed port number (inclusive).
127147 /// `maxPort` Receives the maximum allowed port number (inclusive).
128148 ///
129149 HRESULT GetAllowedPortRange(
150+ [in] COREWEBVIEW2_NETWORK_COMPONENT_SCOPE scope,
130151 [in] COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND protocol,
131152 [out] INT32* minPort,
132153 [out] INT32* maxPort
@@ -140,6 +161,12 @@ interface ICoreWebView2StagingEnvironmentOptions10 : IUnknown {
140161``` csharp
141162namespace Microsoft .Web .WebView2 .Core
142163{
164+ enum CoreWebview2NetworkComponentScope
165+ {
166+ All = 0 ,
167+ WebRTC = 1 ,
168+ };
169+
143170 enum CoreWebView2TransportProtocolKind
144171 {
145172 Udp = 0 ,
@@ -150,8 +177,8 @@ namespace Microsoft.Web.WebView2.Core
150177 [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2StagingEnvironmentOptions10" )]
151178 {
152179 // ICoreWebView2StagingEnvironmentOptions10 members
153- void SetAllowedPortRange(CoreWebView2TransportProtocolKind protocol, Int32 minPort, Int32 maxPort);
154- void GetAllowedPortRange(CoreWebView2TransportProtocolKind protocol, out Int32 minPort, out Int32 maxPort);
180+ void SetAllowedPortRange(CoreWebview2NetworkComponentScope scope, CoreWebView2TransportProtocolKind protocol, Int32 minPort, Int32 maxPort);
181+ void GetAllowedPortRange(CoreWebview2NetworkComponentScope scope, CoreWebView2TransportProtocolKind protocol, out Int32 minPort, out Int32 maxPort);
155182 }
156183 }
157184}
0 commit comments