@@ -15,7 +15,7 @@ We'd appreciate your feedback.
15
15
# Description
16
16
17
17
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
19
19
rules to allow save the file without a default file type policy security warning UI;
20
20
to cancel the saving; and even to create your own UI to manage runtime
21
21
file type policies.
@@ -24,17 +24,17 @@ file type policies.
24
24
## Win32 C++
25
25
This example will register the event with two custom rules.
26
26
- 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.
28
28
- Showing customized warning UI when saving ".iso" files.
29
29
It allows to block the saving directly.
30
30
``` c++
31
31
void ScenarioFileTypePolicy::AddCustomFileTypePolicies ()
32
32
{
33
33
wil::com_ptr<ICoreWebView2> m_webview;
34
34
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 >();
36
36
// Register a handler for the `SaveFileSecurityCheckStarting` event.
37
- m_webView2_25 ->add_saveFileSecurityCheckStarting(
37
+ m_webView2_23 ->add_saveFileSecurityCheckStarting(
38
38
Callback<ICoreWebView2SaveFileSecurityCheckStartingEventHandler>(
39
39
[this](
40
40
ICoreWebView2* sender,
@@ -43,9 +43,9 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
43
43
// Get the file extension for file to be saved.
44
44
wil::unique_cotaskmem_string extension;
45
45
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.
47
47
wil::unique_cotaskmem_string uri;
48
- CHECK_FAILURE(args->get_SourceUri (&uri));
48
+ CHECK_FAILURE(args->get_DocumentOriginUri (&uri));
49
49
// Convert the file extension value to lower case for
50
50
// the case-insensitive comparison.
51
51
std::wstring extension_lower = extension.get();
@@ -54,11 +54,11 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
54
54
extension_lower.begin(), ::towlower);
55
55
// Set the ` SuppressDefaultPolicy ` property to skip the
56
56
// 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 .
58
58
// This will consent to save the file.
59
59
//
60
60
// 'IsTrustedUri' should be your own helper method
61
- // to determine whether the uri is trusted.
61
+ // to determine whether the URI is trusted.
62
62
if (wcscmp(extension_lower.c_str(), L".eml") == 0 && IsTrustedUri(uri))
63
63
{
64
64
CHECK_FAILURE(args->put_SuppressDefaultPolicy(TRUE));
@@ -74,7 +74,7 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
74
74
m_appWindow->RunAsync(
75
75
[args = wil::make_com_ptr(args), deferral]()
76
76
{
77
- // Set the `Cancel ` property to cancel the saving
77
+ // Set the `CancelSave ` property to cancel the saving
78
78
// for ".iso" file directly. Save action will be aborted.
79
79
//
80
80
// You can let end users make decision on their save
@@ -83,7 +83,7 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
83
83
// your helper method that retrieves result from the UI.
84
84
if (IsCancelledFromCustomizedWarningUI())
85
85
{
86
- CHECK_FAILURE (args->put_Cancel (TRUE));
86
+ CHECK_FAILURE (args->put_CancelSave (TRUE));
87
87
}
88
88
CHECK_FAILURE(deferral->Complete());
89
89
});
@@ -98,7 +98,7 @@ void ScenarioFileTypePolicy::AddCustomFileTypePolicies()
98
98
## .Net/ WinRT
99
99
This example will register the event with two custom rules.
100
100
- 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.
102
102
- Showing customized warning UI when saving ".iso" files.
103
103
It allows to block the saving directly.
104
104
``` c#
@@ -108,15 +108,15 @@ void AddCustomFileTypePolicies()
108
108
webView .CoreWebView2 .SaveFileSecurityCheckStarting += (sender , args ) =>
109
109
{
110
110
if (string .Equals (args .FileExtension , " .eml" , StringComparison .OrdinalIgnoreCase )
111
- && IsTrustedUri (args .SourceUri ))
111
+ && IsTrustedUri (args .DocumentOriginUri ))
112
112
{
113
113
// Set the `SuppressDefaultPolicy` property to skip the
114
114
// 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 .
116
116
// This will consent to save the file.
117
117
//
118
118
// 'IsTrustedUri' should be your own helper method
119
- // to determine whether the uri is trusted.
119
+ // to determine whether the URI is trusted.
120
120
args .SuppressDefaultPolicy = true ;
121
121
}
122
122
if (string .Equals (args .FileExtension , " .iso" , StringComparison .OrdinalIgnoreCase ))
@@ -128,14 +128,14 @@ void AddCustomFileTypePolicies()
128
128
{
129
129
if (IsCancelledFromCustomizedWarningUI ())
130
130
{
131
- // Set the `Cancel ` property to cancel the saving
131
+ // Set the `CancelSave ` property to cancel the saving
132
132
// for ".iso" file directly. Save action will be aborted.
133
133
//
134
134
// You can let end users make decision on their save
135
135
// action with your customized warning UI.
136
136
// 'IsCancelledFromCustomizedWarningUI' should be
137
137
// your helper method that retrieves result from the UI.
138
- args .Cancel = true ;
138
+ args .CancelSave = true ;
139
139
}
140
140
}
141
141
}, null );
@@ -147,32 +147,34 @@ void AddCustomFileTypePolicies()
147
147
# API Details
148
148
## Win32 C++
149
149
``` c++
150
- interface ICoreWebView2 : IUnknown {
150
+ interface ICoreWebView2_23 : ICoreWebView2_22 {
151
151
/// Adds an event handler for the ` SaveFileSecurityCheckStarting ` event.
152
152
/// If the default save file picker is used to save a file, for
153
153
/// example, client using the File System API ` showSaveFilePicker ` ;
154
154
/// this event will be raised during system FileTypePolicy
155
155
/// 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
+ ///
161
163
/// Table of Properties' value and result:
162
164
///
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.
174
176
HRESULT add_SaveFileSecurityCheckStarting(
175
- [ in] ICoreWebView2StagingSaveFileSecurityCheckStartingEventHandler * eventHandler,
177
+ [ in] ICoreWebView2SaveFileSecurityCheckStartingEventHandler * eventHandler,
176
178
[ out] EventRegistrationToken* token);
177
179
178
180
/// Removes an event handler previously added with ` add_SaveFileSecurityCheckStarting ` .
@@ -182,31 +184,34 @@ interface ICoreWebView2 : IUnknown {
182
184
183
185
184
186
// / 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);
188
190
189
191
/// Set whether to cancel the upcoming save/download. ` TRUE ` means the action
190
192
/// will be cancelled before validations in default policy.
191
193
///
192
194
/// The default value is ` FALSE ` .
193
- [ propput] HRESULT Cancel ([ in] BOOL value);
195
+ [ propput] HRESULT CancelSave ([ in] BOOL value);
194
196
195
197
/// Get the extension of file to be saved.
196
198
///
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 .
199
201
///
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
202
204
/// final extension.
203
205
///
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 .
206
208
[ propget] HRESULT FileExtension([ out, retval] LPWSTR* value);
207
209
208
210
/// Get the full path of file to be saved. This includes the
209
211
/// file name and extension.
212
+ ///
213
+ /// This method doesn't provide path validation, the returned
214
+ /// string may longer than MAX_PATH.
210
215
[ propget] HRESULT FilePath([ out, retval] LPWSTR* value);
211
216
212
217
/// Gets the ` SuppressDefaultPolicy ` property.
@@ -218,8 +223,8 @@ interface ICoreWebView2StagingSaveFileSecurityCheckStartingEventArgs : IUnknown
218
223
/// The default value is ` FALSE ` .
219
224
[ propput] HRESULT SuppressDefaultPolicy([ in] BOOL value);
220
225
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);
223
228
224
229
/// Returns an ` ICoreWebView2Deferral ` object. Use this operation to complete
225
230
/// the SaveFileSecurityCheckStartingEvent.
@@ -232,11 +237,11 @@ interface ICoreWebView2StagingSaveFileSecurityCheckStartingEventArgs : IUnknown
232
237
}
233
238
234
239
// / Receives `SaveFileSecurityCheckStarting` events.
235
- interface ICoreWebView2StagingSaveFileSecurityCheckStartingEventHandler : IUnknown {
240
+ interface ICoreWebView2SaveFileSecurityCheckStartingEventHandler : IUnknown {
236
241
/// Provides the event args for the corresponding event.
237
242
HRESULT Invoke(
238
243
[ in] ICoreWebView2* sender,
239
- [ in] ICoreWebView2StagingSaveFileSecurityCheckStartingEventArgs * args);
244
+ [ in] ICoreWebView2SaveFileSecurityCheckStartingEventArgs * args);
240
245
}
241
246
```
242
247
@@ -250,19 +255,19 @@ namespace Microsoft.Web.WebView2.Core
250
255
251
256
runtimeclass CoreWebView2SaveFileSecurityCheckStartingEventArgs
252
257
{
253
- Boolean Cancel { get; set; };
258
+ Boolean CancelSave { get; set; };
254
259
String FileExtension { get ; };
255
260
String FilePath { get ; };
256
261
Boolean SuppressDefaultPolicy { get ; set ; };
257
- String SourceUri { get ; };
262
+ String DocumentOriginUri { get ; };
258
263
Windows .Foundation .Deferral GetDeferral ();
259
264
};
260
265
261
266
runtimeclass CoreWebView2
262
267
{
263
268
// ...
264
269
265
- [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2_25 " )]
270
+ [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2_23 " )]
266
271
{
267
272
event Windows .Foundation .TypedEventHandler
268
273
< CoreWebView2 , CoreWebView2SaveFileSecurityCheckStartingEventArgs > SaveFileSecurityCheckStarting ;
0 commit comments