Skip to content

Commit 839250a

Browse files
authored
added allow list changes
Add examples for configuring and retrieving the allowlist in C# and C++.
1 parent 4e6e122 commit 839250a

1 file changed

Lines changed: 159 additions & 1 deletion

File tree

specs/SensitivityLabel.md

Lines changed: 159 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,107 @@ The core features of this proposal are as follows:
9898
• Sensitivity labels are cleared when navigating away from the current WebView.
9999

100100
# Examples
101+
102+
## Setting Up an Allowlist
103+
104+
Configure the PageInteractionRestrictionManager allowlist to enable DLP functionality on trusted domains.
105+
106+
```c#
107+
// Configure allowlist for trusted company domains
108+
var allowlist = new List<string>
109+
{
110+
"https://intranet.company.com",
111+
"https://*.company.com", // Wildcard for all company subdomains
112+
"https://trusted-partner.com",
113+
"https://secure.vendor.net"
114+
};
115+
116+
// Set the allowlist on the profile
117+
await webView2Control.CoreWebView2.Profile.SetPageInteractionRestrictionManagerAllowlistAsync(allowlist);
118+
119+
MessageBox.Show($"Allowlist configured with {allowlist.Count} domains");
120+
```
121+
122+
```cpp
123+
void ConfigureAllowlist()
124+
{
125+
// Get the WebView2 profile
126+
wil::com_ptr<ICoreWebView2Profile> profile;
127+
CHECK_FAILURE(m_webView->get_Profile(&profile));
128+
129+
auto stagingProfile3 = profile.try_query<ICoreWebView2StagingProfile3>();
130+
if (stagingProfile3) {
131+
// Create allowlist with trusted domains
132+
std::vector<std::wstring> allowlist = {
133+
L"https://intranet.company.com",
134+
L"https://*.company.com",
135+
L"https://trusted-partner.com"
136+
};
137+
138+
// Convert to LPCWSTR array for COM interface
139+
std::vector<LPCWSTR> items;
140+
for (const auto& url : allowlist) {
141+
items.push_back(url.c_str());
142+
}
143+
144+
// Get environment to create string collection
145+
wil::com_ptr<ICoreWebView2Environment> environment;
146+
CHECK_FAILURE(m_webView->get_Environment(&environment));
147+
148+
auto stagingEnvironment15 = environment.try_query<ICoreWebView2StagingEnvironment15>();
149+
if (stagingEnvironment15) {
150+
wil::com_ptr<ICoreWebView2StringCollection> stringCollection;
151+
CHECK_FAILURE(stagingEnvironment15->CreateStringCollection(
152+
static_cast<UINT32>(items.size()),
153+
items.data(),
154+
&stringCollection));
155+
156+
// Apply the allowlist
157+
CHECK_FAILURE(stagingProfile3->SetPageInteractionRestrictionManagerAllowlist(
158+
stringCollection.get()));
159+
}
160+
}
161+
}
162+
```
163+
164+
## Retrieving Current Allowlist
165+
166+
```c#
167+
// Get current allowlist
168+
var currentAllowlist = await webView2Control.CoreWebView2.Profile.GetPageInteractionRestrictionManagerAllowlistAsync();
169+
170+
Console.WriteLine($"Current allowlist contains {currentAllowlist.Count} entries:");
171+
foreach (var url in currentAllowlist)
172+
{
173+
Console.WriteLine($" • {url}");
174+
}
175+
```
176+
177+
```cpp
178+
void GetCurrentAllowlist()
179+
{
180+
auto stagingProfile3 = m_profile.try_query<ICoreWebView2StagingProfile3>();
181+
if (stagingProfile3) {
182+
CHECK_FAILURE(stagingProfile3->GetPageInteractionRestrictionManagerAllowlist(
183+
Callback<ICoreWebView2StagingGetPageInteractionRestrictionManagerAllowlistCompletedHandler>(
184+
[](HRESULT result, ICoreWebView2StringCollection* allowlist) -> HRESULT {
185+
if (SUCCEEDED(result) && allowlist) {
186+
UINT count = 0;
187+
CHECK_FAILURE(allowlist->get_Count(&count));
188+
189+
wprintf(L"Current allowlist contains %u entries:\n", count);
190+
for (UINT i = 0; i < count; ++i) {
191+
wil::unique_cotaskmem_string item;
192+
CHECK_FAILURE(allowlist->GetValueAtIndex(i, &item));
193+
wprintf(L" • %s\n", item.get());
194+
}
195+
}
196+
return S_OK;
197+
}).Get()));
198+
}
199+
}
200+
```
201+
101202
<!-- TEMPLATE
102203
Use this section to explain the features of the API, showing
103204
example code with each description in both C# (for our WinRT API or .NET API) and
@@ -169,8 +270,65 @@ The core features of this proposal are as follows:
169270
```
170271
171272
-->
172-
173273
# API Details
274+
275+
```
276+
[uuid(764ffcc6-b341-5307-8ca4-58face289427), object, pointer_default(unique)]
277+
interface ICoreWebView2StagingEnvironment15 : IUnknown {
278+
/// Create an ICoreWebView2StringCollection from an array of strings.
279+
/// This provides a convenient way to create string collections for use
280+
/// with WebView2 APIs that require ICoreWebView2StringCollection objects.
281+
HRESULT CreateStringCollection(
282+
[in] UINT32 count,
283+
[in] LPCWSTR* items,
284+
[out, retval] ICoreWebView2StringCollection** value);
285+
}
286+
```
287+
288+
```
289+
[uuid(25b0fd91-f2e8-5c54-92f4-f74751b1fa0e), object, pointer_default(unique)]
290+
interface ICoreWebView2StagingProfile3 : IUnknown {
291+
/// Get the current PageInteractionRestrictionManager allowlist.
292+
/// The allowlist contains URL patterns that are exempt from page interaction restrictions.
293+
HRESULT GetPageInteractionRestrictionManagerAllowlist(
294+
[in] ICoreWebView2StagingGetPageInteractionRestrictionManagerAllowlistCompletedHandler* handler);
295+
296+
/// Set the PageInteractionRestrictionManager allowlist.
297+
/// URL patterns in this allowlist will be exempt from page interaction restrictions
298+
/// imposed by DLP policies. Pass an empty collection to clear the allowlist.
299+
HRESULT SetPageInteractionRestrictionManagerAllowlist(
300+
[in] ICoreWebView2StringCollection* allow_list);
301+
}
302+
```
303+
304+
```
305+
[uuid(ac924e9c-1639-586b-a402-1b81e6309d8a), object, pointer_default(unique)]
306+
interface ICoreWebView2StagingGetPageInteractionRestrictionManagerAllowlistCompletedHandler : IUnknown {
307+
/// Provides the result of the GetPageInteractionRestrictionManagerAllowlist operation.
308+
HRESULT Invoke([in] HRESULT errorCode, [in] ICoreWebView2StringCollection* result);
309+
}
310+
```
311+
312+
```c#
313+
namespace Microsoft.Web.WebView2.Core
314+
{
315+
public partial class CoreWebView2Profile
316+
{
317+
/// <summary>
318+
/// Get the current PageInteractionRestrictionManager allowlist.
319+
/// </summary>
320+
/// <returns>A collection of URL patterns that are exempt from page interaction restrictions.</returns>
321+
public async Task<IReadOnlyList<string>> GetPageInteractionRestrictionManagerAllowlistAsync();
322+
323+
/// <summary>
324+
/// Set the PageInteractionRestrictionManager allowlist.
325+
/// </summary>
326+
/// <param name="allowList">Collection of URL patterns to exempt from page interaction restrictions.
327+
/// Pass an empty collection to clear the allowlist.</param>
328+
public void SetPageInteractionRestrictionManagerAllowlist(IReadOnlyList<string> allowList);
329+
}
330+
}
331+
```
174332
<!-- TEMPLATE
175333
The exact API, in IDL format for our COM API and
176334
in MIDL3 format (https://learn.microsoft.com/uwp/midl-3/)

0 commit comments

Comments
 (0)