@@ -23,25 +23,26 @@ Common scenarios:
2323
2424Usage steps:  
25251 .  Create ` CoreWebView2EnvironmentOptions ` .   
26- 2 .  Call ` SetAllowedPortRange `  for ` COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP ` .  
27- 3 .  Pass the options when creating the WebView2 environment.  
28- 
26+ 2 .  Call ` SetAllowedPortRange `  for ` COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_DEFAULT `  and ` COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP ` .
27+ 3 .  Pass the options when creating the WebView2 environment.
2928
3029# Examples  
3130### C++ Configure UDP Port Range  
3231``` cpp 
3332Microsoft::WRL::ComPtr<ICoreWebView2StagingEnvironmentOptions10> optionsStaging10;
3433if  (options.As(&optionsStaging10) == S_OK)
3534{
36-     // Configure port ranges for WebRTC  UDP traffic to work within enterprise firewalls 
35+     // Configure port ranges for UDP traffic to work within enterprise firewalls 
3736    // Set UDP port range (example: 50000-55000 for enterprise environments) 
3837    const INT32 udpMin = 50000, udpMax = 55000; 
3938
4039    CHECK_FAILURE (optionsStaging10->SetAllowedPortRange(
40+         COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_DEFAULT,
4141        COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP, udpMin, udpMax));
4242
4343    // Get the configured port range 
44-     CHECK_FAILURE (optionsStaging10->GetAllowedPortRange(
44+     CHECK_FAILURE (optionsStaging10->GetEffectiveAllowedPortRange(
45+         COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_DEFAULT,
4546        COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP, &m_udpPortRange.minPort,
4647        &m_udpPortRange.maxPort));
4748}
@@ -59,15 +60,17 @@ var options = CoreWebView2Environment.CreateCoreWebView2EnvironmentOptions();
5960var  optionsStaging10  =  options  as  ICoreWebView2StagingEnvironmentOptions10 ;
6061if  (optionsStaging10  !=  null )
6162{
62-     //  Configure port ranges for WebRTC  UDP traffic to work within enterprise firewalls 
63+     //  Configure port ranges for UDP traffic to work within enterprise firewalls 
6364    //  Set UDP port range (example: 50000-55000 for enterprise environments) 
6465     const  int  udpMin  =  50000 , udpMax  =  55000 ;
6566
6667    optionsStaging10 .SetAllowedPortRange (
68+         COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_DEFAULT ,
6769        COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP , udpMin , udpMax );
6870
6971    //  Get the configured port range 
70-      optionsStaging10 .GetAllowedPortRange (
72+      optionsStaging10 .GetEffectiveAllowedPortRange (
73+         COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_DEFAULT ,
7174        COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND_UDP , out  m_udpPortRange .minPort ,
7275        out  m_udpPortRange .maxPort );
7376}
@@ -77,9 +80,50 @@ var environment = await CoreWebView2Environment.CreateAsync(
7780OnCreateEnvironmentCompleted (environment );
7881``` 
7982
83+ API Rules and Precedence
84+ 
85+ 1 .  Port Range Restriction Scope param in SetAllowedPortRange
86+ -  A component specific scope (e.g. _ WEB_RTC) always takes precedence over _ DEFAULT for that component in ` SetAllowedPortRange ` .
87+ -  ` _DEFAULT `  defines the base port range restrictions for all components without specific overrides.
88+ -  Passing ` (0, 0) `  for a component scope unset its specific range restriction and inherit range restriction from ` _DEFAULT ` 
89+ -  If ` _DEFAULT `  is set and a specific scope is unset, that component inherits ` _DEFAULT ` .
90+ -  Passing ` (1025,65535) `  for a component scope make port range unrestricted for that component.
91+ 
92+ |  Scope State                                |  Behaviour                                                                                     | 
93+ |  ------------------------------------------ |  --------------------------------------------------------------------------------------------- | 
94+ |  Only ` _DEFAULT `  is set                           |  ` _DEFAULT `  applies port range restrictions to all components                            | 
95+ |  ` _DEFAULT `  and ` _WEB_RTC `  are both set           |  ` _WEB_RTC `  port range restrictions applies to WebRTC; ` _DEFAULT `  applies to others      | 
96+ |  ` _WEB_RTC `  only is set                           |  ` _WEB_RTC `  applies port range restrictions only to WebRTC; others unrestricted          | 
97+ |  ` _DEFAULT `  set and ` _WEB_RTC `  reset to ` (0,0) `    |  ` _DEFAULT `  applies port range restrictions to all and WebRTC inherits ` _DEFAULT `         | 
98+ |  ` _DEFAULT `  set and ` _WEB_RTC `  set to ` (1025,65535) `  |  ` _DEFAULT `  applies port range restrictions to all except WebRTC which is unrestricted   | 
99+ 
100+ 2 .  Port Range Restriction Scope param in GetEffectiveAllowedPortRange
101+ -  GetEffectiveAllowedPortRange returns the port range to use for the specified scope.
102+ -  If the scope is _ DEFAULT or if the specified scope is unset, then the _ DEFAULT port range is returned.
103+ -  A range of (0, 0) means that no port range has been set.
104+ -  Querying ` _DEFAULT `  only returns ` _DEFAULT ` ; it does not aggregate component-specific settings.
105+ -  If neither ` _DEFAULT `  nor a component-specific scope is set, the default ` (0,0) `  (unset) is returned.
106+ 
107+ |  ` GetEffectiveAllowedPortRange `  Scope query                           |  Returned Range                | 
108+ |  -------------------------------------------------------------------- |  ----------------------------- | 
109+ |  Pass ` _WEB_RTC `  when only ` _DEFAULT `  is set                          |  Returns ` _DEFAULT `  range      | 
110+ |  Pass ` _WEB_RTC `  when ` _WEB_RTC `  explicitly set                       |  Returns ` _WEB_RTC `  range      | 
111+ |  Pass ` _WEB_RTC `  when ` _DEFAULT `  unset and ` _WEB_RTC `  unset           |  Returns ` (0, 0) `               | 
112+ |  Pass ` _WEB_RTC `  when ` _DEFAULT `  set and ` _WEB_RTC `  reset to ` (0, 0) `  |  Returns ` _DEFAULT `             | 
113+ |  Pass ` _DEFAULT `  when only ` _WEB_RTC `  set                             |  Returns  ` (0,0) `               | 
114+ 
80115# API Details  
81116### C++    
82117``` 
118+ /// Specifies the scope for port configuration. 
119+ [v1_enum] 
120+ typedef enum COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE { 
121+   /// Scope applies to all components. 
122+   COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_DEFAULT, 
123+   /// Applies only to WebRTC peer-to-peer connection. 
124+   COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE_WEB_RTC, 
125+ } COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE; 
126+ 
83127/// Specifies the network protocol for port configuration. 
84128[v1_enum] 
85129typedef enum COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND { 
@@ -88,45 +132,75 @@ typedef enum COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND {
88132} COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND; 
89133
90134/// Additional options used to create WebView2 Environment to manage port range configuration. 
91- [uuid(eaf22436-27a1-5e3d-a4e3-84d7e7a69a1a ), object, pointer_default(unique)] 
135+ [uuid(2c0f597d-2958-5a94-82f9-c750cf86cb88 ), object, pointer_default(unique)] 
92136interface ICoreWebView2StagingEnvironmentOptions10 : IUnknown { 
93-   /// Sets the allowed port range for the specified transport protocol. 
137+   /// Sets the allowed port range restriction for the specified  
138+   /// scope and transport protocol. 
139+   ///  
94140  /// This API enables WebView2 to operate within enterprise network or firewall 
95141  /// restrictions by limiting network communication to a defined port range. 
142+   /// It provides fine-grained control by allowing port restrictions to be applied 
143+   /// per network component scope, such as WebRTC. 
96144  ///  
97145  /// Currently, only WebRTC UDP Port Range restriction is supported. 
98146  ///  
99-   /// `minPort` and `maxPort` must be within the range 1025– 65535 (inclusive), 
100-   /// and  `minPort` must be less than or equal to `maxPort`. 
147+   /// `minPort` and `maxPort` must be within the range 1025- 65535 (inclusive), or must both be the sentinel value 0.  
148+   /// `minPort` must be less than or equal to `maxPort`. 
101149  /// If `minPort` equals `maxPort`, the range represents a single port. 
102150  ///  
103-   /// Passing `(0, 0)` resets to the default behavior, meaning no restrictions 
104-   /// are applied and the system assigns ports from the full ephemeral range. 
105-   ///  
106151  /// Calls with invalid ranges fail with `E_INVALIDARG`. 
107-   ///  
108-   /// `protocol` The transport protocol (currently only UDP is supported). 
152+   /// 
153+   /// A component specific scope (e.g. _WEB_RTC) always takes precedence over _DEFAULT for that component in `SetAllowedPortRange`. 
154+   /// `_DEFAULT` defines the port range restrictions for all components without specific overrides. 
155+   /// Passing `(0, 0)` for a component scope unset its specific range restriction and inherit range restriction from `_DEFAULT` 
156+   /// If `_DEFAULT` is set and a specific scope is unset, that component inherits `_DEFAULT`. 
157+   /// Passing `(1025,65535)` for a component scope make port range unrestricted for that component. 
158+ 
159+   /// | Scope State                                         | Behaviour                                                                               | 
160+   /// | --------------------------------------------------- | ----------------------------------------------------------------------------------------| 
161+   /// | Only `_DEFAULT` is set                              | `_DEFAULT` applies port range restrictions to all components                            | 
162+   /// | `_DEFAULT` and `_WEB_RTC` are both set              | `_WEB_RTC` port range restrictions applies to WebRTC; `_DEFAULT` applies to others      | 
163+   /// | `_WEB_RTC` only is set                              | `_WEB_RTC` applies port range restrictions only to WebRTC; others unrestricted          | 
164+   /// | `_DEFAULT` set and `_WEB_RTC` reset to `(0,0)`      | `_DEFAULT` applies port range restrictions to all and WebRTC inherits `_DEFAULT`        | 
165+   /// | `_DEFAULT` set and `_WEB_RTC` set to `(1025,65535)` | `_DEFAULT` applies port range restrictions to all except WebRTC which is unrestricted   | 
166+ 
167+   /// `scope` scope on which restrictions will apply. 
168+   /// `protocol` Transport protocol on which restrictions will apply. 
109169  /// `minPort` The minimum allowed port number (inclusive). 
110170  /// `maxPort` The maximum allowed port number (inclusive). 
111171  ///  
112172  HRESULT SetAllowedPortRange( 
173+       [in] COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE scope, 
113174      [in] COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND protocol, 
114175      [in] INT32 minPort, 
115176      [in] INT32 maxPort 
116177  ); 
117178
118-   /// Retrieves the allowed port range for the specified transport protocol. 
119-   /// Returns the currently configured  port range previously set via 
179+   /// Retrieves the effective  allowed port range for the specified transport protocol. 
180+   /// Returns the effective  port range previously set via 
120181  /// `SetAllowedPortRange`. 
121-   ///  
122-   /// By default, `(0, 0)` is returned, which indicates no restrictions are applied 
123-   /// and ports are allocated from the system’s ephemeral range (1025–65535 inclusive). 
124-   ///  
125-   /// `protocol` The transport protocol (currently only UDP is supported). 
182+   /// 
183+   /// GetEffectiveAllowedPortRange returns the port range to use for the specified scope. 
184+   /// If the scope is _DEFAULT or if the specified scope is unset, then the _DEFAULT port range is returned. 
185+   /// A range of (0, 0) means that no port range has been set. 
186+   /// Querying `_DEFAULT` only returns `_DEFAULT`; it does not aggregate component-specific settings. 
187+   /// If neither `_DEFAULT` nor a component-specific scope is set, the default `(0,0)` (unset) is returned. 
188+ 
189+   /// | `GetEffectiveAllowedPortRange` Scope query                           | Returned Range                | 
190+   /// | -------------------------------------------------------------------- | ----------------------------- | 
191+   /// | Pass `_WEB_RTC` when only `_DEFAULT` is set                          | Returns `_DEFAULT` range      | 
192+   /// | Pass `_WEB_RTC` when `_WEB_RTC` explicitly set                       | Returns `_WEB_RTC` range      | 
193+   /// | Pass `_WEB_RTC` when `_DEFAULT` unset and `_WEB_RTC` unset           | Returns `(0, 0)`              | 
194+   /// | Pass `_WEB_RTC` when `_DEFAULT` set and `_WEB_RTC` reset to `(0, 0)` | Returns `_DEFAULT`            | 
195+   /// | Pass `_DEFAULT` when only `_WEB_RTC` set                             | Returns  `(0,0)`              | 
196+ 
197+   /// `scope` scope on which restrictions is applied. 
198+   /// `protocol` Transport protocol on which restrictions is applied. 
126199  /// `minPort` Receives the minimum allowed port number (inclusive). 
127200  /// `maxPort` Receives the maximum allowed port number (inclusive). 
128201  ///  
129-   HRESULT GetAllowedPortRange( 
202+   HRESULT GetEffectiveAllowedPortRange ( 
203+       [in] COREWEBVIEW2_ALLOWED_PORT_RANGE_SCOPE scope, 
130204      [in] COREWEBVIEW2_TRANSPORT_PROTOCOL_KIND protocol, 
131205      [out] INT32* minPort, 
132206      [out] INT32* maxPort 
@@ -140,6 +214,12 @@ interface ICoreWebView2StagingEnvironmentOptions10 : IUnknown {
140214``` csharp 
141215namespace  Microsoft .Web .WebView2 .Core 
142216{
217+     enum  CoreWebview2AllowedPortRangeScope 
218+     {
219+         Default  =  0 ,
220+         WebRtc  =  1 ,
221+     };
222+ 
143223    enum  CoreWebView2TransportProtocolKind 
144224    {
145225        Udp  =  0 ,
@@ -150,8 +230,8 @@ namespace Microsoft.Web.WebView2.Core
150230        [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2StagingEnvironmentOptions10"  )]
151231        {
152232            //  ICoreWebView2StagingEnvironmentOptions10 members 
153-              void SetAllowedPortRange(CoreWebView2TransportProtocolKind protocol, Int32 minPort, Int32 maxPort);
154-             void GetAllowedPortRange( CoreWebView2TransportProtocolKind protocol, out Int32 minPort, out Int32 maxPort);
233+              void SetAllowedPortRange(CoreWebview2AllowedPortRangeScope scope,  CoreWebView2TransportProtocolKind protocol, Int32 minPort, Int32 maxPort);
234+             void GetEffectiveAllowedPortRange(CoreWebview2AllowedPortRangeScope scope,  CoreWebView2TransportProtocolKind protocol, out Int32 minPort, out Int32 maxPort);
155235        }
156236    }
157237}
0 commit comments