Skip to content

Commit 598bdc7

Browse files
authored
Update CustomStoragePartition.md
1 parent 9717157 commit 598bdc7

1 file changed

Lines changed: 59 additions & 55 deletions

File tree

specs/CustomStoragePartition.md

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
Custom Storage Partition
1+
Custom Data Partition
22
===
33

44
# Background
55
For certain WebView host apps, there is a desire to have different contexts for
66
different WebViews using the same profile so that when the same websites run in
7-
these WebViews, they will have different DOM storages and cookie jars. An example
8-
is different accounts within an application.
7+
these WebViews, they will have different DOM storages and cookie jars. For example,
8+
a content editing application might use one WebView to visit a site as signed in user
9+
to modify content on the site, while using another WebView to visit the same site as
10+
anonymous user to view the changes as seen by normal users.
911
Previously, the application can use different profiles for different contexts, but
1012
that has 2 short comings:
1113
- WebViews from different profiles are not allowed to have opener/opened window relationship.
1214
- Using profiles means totally different storage for all files like http caches and less performance.
1315

1416
To help managing different application contexts while using the same profile, we are
15-
introducing an API to set custom storage partition and an API to clear all data in
16-
a custom storage partition.
17+
introducing an API to set custom data partition and an API to clear all data in
18+
a custom data partition.
1719

18-
When an application sets custom storage partition for a WebView, the sites and iframes
20+
When an application sets custom data partition for a WebView, the sites and iframes
1921
running inside the WebView will act as if the site were running in a third party iframe
20-
inside a top level site uniquely associated with the custom storage partition id and have
22+
inside a top level site uniquely associated with the custom data partition id and have
2123
separate [storage partition](https://developer.chrome.com/docs/privacy-sandbox/storage-partitioning/)
2224
and [cookie partition](https://developer.chrome.com/docs/privacy-sandbox/chips/).
2325

@@ -27,16 +29,16 @@ and [cookie partition](https://developer.chrome.com/docs/privacy-sandbox/chips/)
2729
features which are currently experimental. Before those features are enabled by default,
2830
the application must enable them by ensuring `--enable-features=ThirdPartyStoragePartitioning,PartitionedCookies`
2931
is set in [CoreWebView2EnvironmentOptions.AdditionalBrowserArguments](https://learn.microsoft.com/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2environmentoptions#additionalbrowserarguments)
30-
used to create CoreWebView2Environment. If not set, no custom storage partition will be
32+
used to create CoreWebView2Environment. If the features are not enabled, no custom data partition will be
3133
created and all data will be treated as unpartitioned and stored in the global default
3234
location for the profile.
33-
The custom storage partition APIs will remain experimental when related browser features
35+
The custom data partition APIs will remain experimental when related browser features
3436
are still experimental.
3537

3638
# Examples
3739

3840
The example below illustrates how to set partition id on WebView and how to clear all
39-
data stored in the custom storage partition.
41+
data stored in the custom data partition.
4042

4143
## Win32 C++
4244
```cpp
@@ -47,38 +49,39 @@ data stored in the custom storage partition.
4749
// ...
4850
// other WebView setup like add event handlers, update settings.
4951
50-
// Sets custom storage partition identified by the partitionId, which uniquely
51-
// identifies an application context.
52+
// Sets custom data partition identified by the partitionId. Used by app
53+
// to uniquely identify an application context, like for visiting the site
54+
// as anonymous user instead of the signed in user in other WebViews.
5255
PCWSTR partitionId = L"Partition 1";
53-
CHECK_FAILURE(m_webview->put_CustomStoragePartitionId(partitionId));
56+
CHECK_FAILURE(m_webview->put_CustomDataPartitionId(partitionId));
5457

5558
// Navigate to start page
5659
m_webview->Navigate(startPage);
5760
}
5861

59-
// Clears all data in custom storage partition identified by the partitionId.
60-
// Called when the application context is removed.
62+
// Clears all data in custom data partition identified by the partitionId.
63+
// Called when the custom data partition is no longer needed.
6164
HRESULT ClearPartitionData(PCWSTR partitionId)
6265
{
6366
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
6467
CHECK_FAILURE(m_webview->get_Profile(&webView2Profile));
6568
auto webView2Profile8 = webView2Profile.try_query<ICoreWebView2Profile8>();
6669
CHECK_FEATURE_RETURN(webView2Profile8);
67-
CHECK_FAILURE(webView2Profile8->ClearCustomStoragePartitionData(
70+
CHECK_FAILURE(webView2Profile8->ClearCustomDataPartition(
6871
partitionId,
69-
Callback<ICoreWebView2StagingClearCustomStoragePartitionDataCompletedHandler>(
72+
Callback<ICoreWebView2ClearCustomDataPartitionCompletedHandler>(
7073
[this](HRESULT result) -> HRESULT
7174
{
7275
if (SUCCEEDED(result))
7376
{
74-
AsyncMessageBox(L"Completed", L"Clear Custom Partition Data");
77+
AsyncMessageBox(L"Completed", L"Clear Custom Data Partition");
7578
}
7679
else
7780
{
7881
std::wstringstream message;
7982
message << L"Failed: " << std::to_wstring(result) << L"(0x" << std::hex
8083
<< result << L")" << std::endl;
81-
AsyncMessageBox(message.str(), L"Clear Custom Partition Data");
84+
AsyncMessageBox(message.str(), L"Clear Custom Data Partition");
8285
}
8386
return S_OK;
8487
}).Get()));
@@ -91,28 +94,27 @@ data stored in the custom storage partition.
9194
```c#
9295
private CoreWebView2 m_webview;
9396
94-
// Sets custom storage partition identified by the partitionId, which uniquely
95-
// identifies an application context.
9697
void CoreWebView_Created()
9798
{
9899
// ...
99100
// other WebView setup like add event handlers, update settings.
100101
101-
// Sets custom storage partition identified by the partitionId, which uniquely
102-
// identifies an application context.
102+
// Sets custom data partition identified by the partitionId. Used by app
103+
// to uniquely identify an application context, like for visiting the site
104+
// as anonymous user instead of the signed in user in other WebViews.
103105
string partitionId = "Partition 1";
104-
m_webview.CustomStoragePartitionId = partitionId;
106+
m_webview.CustomDataPartitionId = partitionId;
105107
106108
// Navigate to start page
107109
m_webview.Navigate(startPage);
108110
}
109111
110-
// Clears all data in custom storage partition identified by the partitionId.
111-
// Called when the application context is removed.
112+
// Clears all data in custom data partition identified by the partitionId.
113+
// Called when the custom data partition is no longer needed.
112114
async void ClearPartitionData(string partitionId)
113115
{
114-
await m_webview.Profile.ClearCustomStoragePartitionDataAsync(partitionId);
115-
MessageBox.Show(this, "Completed", "Clear Custom Partition Data");
116+
await m_webview.Profile.ClearCustomDataPartitionAsync(partitionId);
117+
MessageBox.Show(this, "Completed", "Clear Custom Data Partition");
116118
}
117119
118120
```
@@ -121,11 +123,11 @@ data stored in the custom storage partition.
121123
## Win32 C++
122124
```
123125
interface ICoreWebView2_18 : ICoreWebView2_17 {
124-
/// Gets the `CustomStoragePartitionId` property.
125-
[propget] HRESULT CustomStoragePartitionId([out, retval] LPWSTR* customStoragePartitionId);
126+
/// Gets the `CustomDataPartitionId` property.
127+
[propget] HRESULT CustomDataPartitionId([out, retval] LPWSTR* customDataPartitionId);
126128
127-
/// Sets the `CustomStoragePartitionId` property.
128-
/// This feature requires enabling 2 experimental browser features to work properly.
129+
/// Sets the `CustomDataPartitionId` property.
130+
/// This API requires enabling 2 experimental browser features to work properly.
129131
/// These features will be enabled by default in the future.
130132
/// Before these features are enabled by default, please enable them by ensuring
131133
/// `--enable-features=ThirdPartyStoragePartitioning,PartitionedCookies` is set in
@@ -137,47 +139,49 @@ interface ICoreWebView2_18 : ICoreWebView2_17 {
137139
/// storage partition as described in https://developer.chrome.com/docs/privacy-sandbox/storage-partitioning/
138140
/// and separete cookie partition as described in https://developer.chrome.com/docs/privacy-sandbox/chips/
139141
/// with all cookies partitioned.
140-
/// If `customStoragePartitionId` is nullptr or empty string, the
141-
/// `CustomStoragePartitionId` will be reset and the page inside the WebView
142-
/// will work normally with data treated as unpartitioned.
143-
/// The `customStoragePartitionId` parameter is case sensitive. The default is
142+
/// If `customDataPartitionId` is nullptr or empty string, the page inside the
143+
/// WebView will work normally with data treated as unpartitioned.
144+
/// The `customDataPartitionId` parameter is case sensitive. The default is
144145
/// an empty string. There is no restriction on the length or what characters
145146
/// can be used in partition id.
146-
/// The change of the custom storage partition id will be applied to new
147+
/// The change of the custom data partition id will be applied to new
147148
/// page or iframe navigations and not impact existing pages and iframes.
148-
/// To avoid accidentally using the new partition id for pending navigations of old page
149-
/// or iframe, it is recommended to create a new WebView for new partition instead
150-
/// of changing partition. If you really have to change partition, it is
149+
/// To avoid accidentally using the new partition id for new page or iframe navigations
150+
/// started by the old page, it is recommended to create a new WebView for new partition
151+
/// instead of changing partition. If you really have to change partition, it is
151152
/// recommended to navigate to a blank page before setting the new partition
152-
/// id and navigate to a page for the new partition.
153+
/// id and navigating to a page with the new partition.
153154
///
154-
/// As setting custom storage partition id does not change DOM security
155+
/// As setting custom data partition id does not change DOM security
155156
/// model, developers should be very careful for WebViews with opener and
156157
/// opened window relationship, especially when the pages in the WebViews
157-
/// have same origin, like when the opened window is the same site or
158+
/// have same origin, like when the opened window is the same website or
158159
/// about:blank. The pages in these WebViews can access each other’s DOM and
159160
/// therefore can potentially access DOM storage and cookies in different
160-
/// partition for the same site. It is recommended to set the same custom
161-
/// storage partition id for these WebViews, unless there is an absolute need
161+
/// partition for the same website. It is recommended to set the same custom
162+
/// data partition id for these WebViews, unless there is an absolute need
162163
/// to set different partition ids and only trusted code is hosted in them.
163164
///
164-
[propput] HRESULT CustomStoragePartitionId([in] LPCWSTR customStoragePartitionId);
165+
[propput] HRESULT CustomDataPartitionId([in] LPCWSTR customDataPartitionId);
165166
}
166167
167168
interface ICoreWebView2Profile8 : ICoreWebView2Profile7 {
168-
/// Clears all DOM storage and cookies in the custom storage partition
169-
/// identified by the `customStoragePartitionId`.
170-
/// As DOM storage and cookies in the custom storage partition is also browsing
169+
/// Clears all DOM storage and cookies in the custom data partition
170+
/// identified by the `customDataPartitionId`.
171+
/// If `customDataPartitionId` is nullptr or empty string, the API will fail with
172+
/// E_INVALIDARG. If no partition is found for the specified `customDataPartitionId`,
173+
/// the API succeeds without doing anything.
174+
/// As DOM storage and cookies in the custom data partition is also browsing
171175
/// data, they will also be cleared when `ClearBrowsingData`,
172176
/// `ClearBrowsingDataInTimeRange` or `ClearBrowsingDataAll` is called and
173177
/// the clearing condition is met.
174178
///
175-
HRESULT ClearCustomStoragePartitionData(
176-
[in] LPCWSTR customStoragePartitionId,
177-
[in] ICoreWebView2ClearCustomStoragePartitionDataCompletedHandler* handler);
179+
HRESULT ClearCustomDataPartition(
180+
[in] LPCWSTR customDataPartitionId,
181+
[in] ICoreWebView2ClearCustomDataPartitionCompletedHandler* handler);
178182
}
179183
180-
interface ICoreWebView2ClearCustomStoragePartitionDataCompletedHandler : IUnknown {
184+
interface ICoreWebView2ClearCustomDataPartitionCompletedHandler : IUnknown {
181185
182186
/// Provide the completion status of the corresponding asynchronous method.
183187
HRESULT Invoke([in] HRESULT errorCode);
@@ -194,15 +198,15 @@ namespace Microsoft.Web.WebView2.Core
194198
{
195199
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2_18")]
196200
{
197-
public string CustomStoragePartitionId { get; set; };
201+
public string CustomDataPartitionId { get; set; };
198202
}
199203
}
200204

201205
class CoreWebView2Profile
202206
{
203207
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Profile8")]
204208
{
205-
public async Task ClearCustomStoragePartitionDataAsync(string customStoragePartitionId);
209+
public async Task ClearCustomDataPartitionAsync(string customDataPartitionId);
206210
}
207211
}
208212
```

0 commit comments

Comments
 (0)