Skip to content

Commit b19c17b

Browse files
Rename properties, add description
1 parent ade0011 commit b19c17b

File tree

1 file changed

+56
-51
lines changed

1 file changed

+56
-51
lines changed

specs/FileTypePolicy.md

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ We'd appreciate your feedback.
1515
# Description
1616

1717
We proposed the `CoreWebView2.SaveFileSecurityCheckStarting` event. As a developer, you can register a handler on
18-
this event to get the file path, file extension and URI source information. Then you can apply your own
18+
this event to get the file path, file extension and document origin URI information. Then you can apply your own
1919
rules to allow save the file without a default file type policy security warning UI;
2020
to cancel the saving; and even to create your own UI to manage runtime
2121
file type policies.
@@ -24,17 +24,17 @@ file type policies.
2424
## Win32 C++
2525
This example will register the event with two custom rules.
2626
- Suppressing file type policy, security dialog, and
27-
allows saving ".eml" files directly; when the uri is trusted.
27+
allows saving ".eml" files directly; when the URI is trusted.
2828
- Showing customized warning UI when saving ".iso" files.
2929
It allows to block the saving directly.
3030
```c++
3131
void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
3232
{
3333
wil::com_ptr<ICoreWebView2> m_webview;
3434
EventRegistrationToken m_saveFileSecurityCheckStartingToken = {};
35-
auto m_webview2_25 = m_webView.try_query<ICoreWebView2_25>();
35+
auto m_webview2_23 = m_webView.try_query<ICoreWebView2_23>();
3636
// Register a handler for the `SaveFileSecurityCheckStarting` event.
37-
m_webView2_25->add_saveFileSecurityCheckStarting(
37+
m_webView2_23->add_saveFileSecurityCheckStarting(
3838
Callback<ICoreWebView2SaveFileSecurityCheckStartingEventHandler>(
3939
[this](
4040
ICoreWebView2* sender,
@@ -43,9 +43,9 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
4343
// Get the file extension for file to be saved.
4444
wil::unique_cotaskmem_string extension;
4545
CHECK_FAILURE(args->get_FileExtension(&extension));
46-
// Get the uri of file to be saved.
46+
// Get the document origin URI of file to be saved.
4747
wil::unique_cotaskmem_string uri;
48-
CHECK_FAILURE(args->get_SourceUri(&uri));
48+
CHECK_FAILURE(args->get_DocumentOriginUri(&uri));
4949
// Convert the file extension value to lower case for
5050
// the case-insensitive comparison.
5151
std::wstring extension_lower = extension.get();
@@ -54,11 +54,11 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
5454
extension_lower.begin(), ::towlower);
5555
// Set the `SuppressDefaultPolicy` property to skip the
5656
// default file type policy checking and a possible security
57-
// alert dialog for ".eml" file, when it's from a trusted uri.
57+
// alert dialog for ".eml" file, when it's from a trusted URI.
5858
// This will consent to save the file.
5959
//
6060
// 'IsTrustedUri' should be your own helper method
61-
// to determine whether the uri is trusted.
61+
// to determine whether the URI is trusted.
6262
if (wcscmp(extension_lower.c_str(), L".eml") == 0 && IsTrustedUri(uri))
6363
{
6464
CHECK_FAILURE(args->put_SuppressDefaultPolicy(TRUE));
@@ -74,7 +74,7 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
7474
m_appWindow->RunAsync(
7575
[args = wil::make_com_ptr(args), deferral]()
7676
{
77-
// Set the `Cancel` property to cancel the saving
77+
// Set the `CancelSave` property to cancel the saving
7878
// for ".iso" file directly. Save action will be aborted.
7979
//
8080
// You can let end users make decision on their save
@@ -83,7 +83,7 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
8383
// your helper method that retrieves result from the UI.
8484
if (IsCancelledFromCustomizedWarningUI())
8585
{
86-
CHECK_FAILURE(args->put_Cancel(TRUE));
86+
CHECK_FAILURE(args->put_CancelSave(TRUE));
8787
}
8888
CHECK_FAILURE(deferral->Complete());
8989
});
@@ -98,7 +98,7 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
9898
## .Net/ WinRT
9999
This example will register the event with two custom rules.
100100
- Suppressing file type policy, security dialog, and
101-
allows saving ".eml" files directly; when the uri is trusted.
101+
allows saving ".eml" files directly; when the URI is trusted.
102102
- Showing customized warning UI when saving ".iso" files.
103103
It allows to block the saving directly.
104104
```c#
@@ -108,15 +108,15 @@ void AddCustomFileTypePolicies()
108108
webView.CoreWebView2.SaveFileSecurityCheckStarting += (sender, args) =>
109109
{
110110
if (string.Equals(args.FileExtension, ".eml", StringComparison.OrdinalIgnoreCase)
111-
&& IsTrustedUri(args.SourceUri))
111+
&& IsTrustedUri(args.DocumentOriginUri))
112112
{
113113
// Set the `SuppressDefaultPolicy` property to skip the
114114
// default file type policy checking and a possible security
115-
// alert dialog for ".eml" file, when it's from a trusted uri.
115+
// alert dialog for ".eml" file, when it's from a trusted URI.
116116
// This will consent to save the file.
117117
//
118118
// 'IsTrustedUri' should be your own helper method
119-
// to determine whether the uri is trusted.
119+
// to determine whether the URI is trusted.
120120
args.SuppressDefaultPolicy = true;
121121
}
122122
if (string.Equals(args.FileExtension, ".iso", StringComparison.OrdinalIgnoreCase))
@@ -128,14 +128,14 @@ void AddCustomFileTypePolicies()
128128
{
129129
if (IsCancelledFromCustomizedWarningUI())
130130
{
131-
// Set the `Cancel` property to cancel the saving
131+
// Set the `CancelSave` property to cancel the saving
132132
// for ".iso" file directly. Save action will be aborted.
133133
//
134134
// You can let end users make decision on their save
135135
// action with your customized warning UI.
136136
// 'IsCancelledFromCustomizedWarningUI' should be
137137
// your helper method that retrieves result from the UI.
138-
args.Cancel = true;
138+
args.CancelSave = true;
139139
}
140140
}
141141
}, null);
@@ -147,32 +147,34 @@ void AddCustomFileTypePolicies()
147147
# API Details
148148
## Win32 C++
149149
```c++
150-
interface ICoreWebView2 : IUnknown {
150+
interface ICoreWebView2_23 : ICoreWebView2_22 {
151151
/// Adds an event handler for the `SaveFileSecurityCheckStarting` event.
152152
/// If the default save file picker is used to save a file, for
153153
/// example, client using the File System API `showSaveFilePicker`;
154154
/// this event will be raised during system FileTypePolicy
155155
/// checking the dangerous file extension list.
156-
///
157-
/// Developers can specify their own decision on if allow this file
158-
/// type extension to be saved, or downloaded. Here are two properties
159-
/// in `ICoreWebView2SaveFileSecurityCheckStartingEventArgs` to manage the
160-
/// decision, `Cancel` and `SuppressDefaultPolicy`.
156+
///
157+
/// Developers can specify their own logic for determining whether
158+
/// to allow a particular type of file to be saved from the document origin URI.
159+
/// Developers can also determine the save decision based on other criteria.
160+
/// Here are two properties in `ICoreWebView2SaveFileSecurityCheckStartingEventArgs`
161+
/// to manage the decision, `CancelSave` and `SuppressDefaultPolicy`.
162+
///
161163
/// Table of Properties' value and result:
162164
///
163-
/// | Cancel | SuppressDefaultPolicy | Result
164-
/// | ------ | ------ | ---------------------
165-
/// | False | False | Perform the default policy check. It may show the
166-
/// | | | security warning UI if the file extension is
167-
/// | | | dangerous.
168-
/// | ------ | ------ | ---------------------
169-
/// | False | True | Skip the default policy check and the possible
170-
/// | | | security warning. Start saving or downloading.
171-
/// | ------ | ------ | ---------------------
172-
/// | True | Any | Skip the default policy check and the possible
173-
/// | | | security warning. Abort save or download.
165+
/// | CancelSave | SuppressDefaultPolicy | Result
166+
/// | ---------- | ------ | ---------------------
167+
/// | False | False | Perform the default policy check. It may show the
168+
/// | | | security warning UI if the file extension is
169+
/// | | | dangerous.
170+
/// | ---------- | ------ | ---------------------
171+
/// | False | True | Skip the default policy check and the possible
172+
/// | | | security warning. Start saving or downloading.
173+
/// | ---------- | ------ | ---------------------
174+
/// | True | Any | Skip the default policy check and the possible
175+
/// | | | security warning. Abort save or download.
174176
HRESULT add_SaveFileSecurityCheckStarting(
175-
[in] ICoreWebView2StagingSaveFileSecurityCheckStartingEventHandler* eventHandler,
177+
[in] ICoreWebView2SaveFileSecurityCheckStartingEventHandler* eventHandler,
176178
[out] EventRegistrationToken* token);
177179

178180
/// Removes an event handler previously added with `add_SaveFileSecurityCheckStarting`.
@@ -182,31 +184,34 @@ interface ICoreWebView2 : IUnknown {
182184

183185

184186
/// The event args for `SaveFileSecurityCheckStarting` event.
185-
interface ICoreWebView2StagingSaveFileSecurityCheckStartingEventArgs : IUnknown {
186-
/// Gets the `Cancel` property.
187-
[propget] HRESULT Cancel([out, retval] BOOL* value);
187+
interface ICoreWebView2SaveFileSecurityCheckStartingEventArgs : IUnknown {
188+
/// Gets the `CancelSave` property.
189+
[propget] HRESULT CancelSave([out, retval] BOOL* value);
188190

189191
/// Set whether to cancel the upcoming save/download. `TRUE` means the action
190192
/// will be cancelled before validations in default policy.
191193
///
192194
/// The default value is `FALSE`.
193-
[propput] HRESULT Cancel([in] BOOL value);
195+
[propput] HRESULT CancelSave([in] BOOL value);
194196

195197
/// Get the extension of file to be saved.
196198
///
197-
/// File extension can be empty, if the file name has no extension
198-
/// at all.
199+
/// The file extension is the extension portion of the FilePath,
200+
/// preserving original case.
199201
///
200-
/// Only final extension without "." will be provided. For example,
201-
/// "*.tar.gz" is a double extension, where the "gz" will be its
202+
/// Only final extension with period "." will be provided. For example,
203+
/// "*.tar.gz" is a double extension, where the ".gz" will be its
202204
/// final extension.
203205
///
204-
/// The file extension is the extension portion of the FilePath,
205-
/// preserving original case.
206+
/// File extension can be empty, if the file name has no extension
207+
/// at all.
206208
[propget] HRESULT FileExtension([out, retval] LPWSTR* value);
207209

208210
/// Get the full path of file to be saved. This includes the
209211
/// file name and extension.
212+
///
213+
/// This method doesn't provide path validation, the returned
214+
/// string may longer than MAX_PATH.
210215
[propget] HRESULT FilePath([out, retval] LPWSTR* value);
211216

212217
/// Gets the `SuppressDefaultPolicy` property.
@@ -218,8 +223,8 @@ interface ICoreWebView2StagingSaveFileSecurityCheckStartingEventArgs : IUnknown
218223
/// The default value is `FALSE`.
219224
[propput] HRESULT SuppressDefaultPolicy([in] BOOL value);
220225

221-
/// The URI source of this file save operation.
222-
[propget] HRESULT SourceUri([out, retval] LPWSTR* value);
226+
/// The document origin URI of this file save operation.
227+
[propget] HRESULT DocumentOriginUri([out, retval] LPWSTR* value);
223228

224229
/// Returns an `ICoreWebView2Deferral` object. Use this operation to complete
225230
/// the SaveFileSecurityCheckStartingEvent.
@@ -232,11 +237,11 @@ interface ICoreWebView2StagingSaveFileSecurityCheckStartingEventArgs : IUnknown
232237
}
233238

234239
/// Receives `SaveFileSecurityCheckStarting` events.
235-
interface ICoreWebView2StagingSaveFileSecurityCheckStartingEventHandler : IUnknown {
240+
interface ICoreWebView2SaveFileSecurityCheckStartingEventHandler : IUnknown {
236241
/// Provides the event args for the corresponding event.
237242
HRESULT Invoke(
238243
[in] ICoreWebView2* sender,
239-
[in] ICoreWebView2StagingSaveFileSecurityCheckStartingEventArgs* args);
244+
[in] ICoreWebView2SaveFileSecurityCheckStartingEventArgs* args);
240245
}
241246
```
242247

@@ -250,19 +255,19 @@ namespace Microsoft.Web.WebView2.Core
250255

251256
runtimeclass CoreWebView2SaveFileSecurityCheckStartingEventArgs
252257
{
253-
Boolean Cancel { get; set; };
258+
Boolean CancelSave { get; set; };
254259
String FileExtension { get; };
255260
String FilePath { get; };
256261
Boolean SuppressDefaultPolicy { get; set; };
257-
String SourceUri { get; };
262+
String DocumentOriginUri { get; };
258263
Windows.Foundation.Deferral GetDeferral();
259264
};
260265

261266
runtimeclass CoreWebView2
262267
{
263268
// ...
264269
265-
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2_25")]
270+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2_23")]
266271
{
267272
event Windows.Foundation.TypedEventHandler
268273
<CoreWebView2, CoreWebView2SaveFileSecurityCheckStartingEventArgs> SaveFileSecurityCheckStarting;

0 commit comments

Comments
 (0)