@@ -14,7 +14,7 @@ We'd appreciate your feedback.
1414# Description
1515
1616We proposed the ` CoreWebView2.FileTypePolicyChecking ` event. You can register
17- this event to get the file path, file extension and domain uri information,
17+ this event to get the file path, file extension and URI information,
1818when end users try to save a file from your App. Then you can apply your own
1919rules to allow save the file with, or without a default warning dialog;
2020to cancel the saving; and even to create your own UI to manage runtime
@@ -42,21 +42,20 @@ bool ScenarioFileTypePolicyStaging::AddCustomFileTypePolicies()
4242 LPWSTR extension;
4343 CHECK_FAILURE (args->get_FileExtension(&extension));
4444 if (lstrcmpW(extension, L"eml") == 0)
45+ {
4546 // Set the ` SuppressDefaultPolicy ` property to skip the
4647 // default file type policy checking and a possible security
4748 // alert dialog for "eml" file. This will consent to
4849 // save the file.
4950 CHECK_FAILURE(args->put_SuppressDefaultPolicy(TRUE));
51+ }
5052 if (lstrcmpW(extension, L"exe") == 0)
53+ {
5154 // Set the ` Cancel ` property to cancel the saving for "exe"
5255 // file directly. Save action will be aborted without any
5356 // alert.
5457 CHECK_FAILURE(args->put_Cancel(TRUE));
55- wil::com_ptr<ICoreWebView2Deferral > deferral;
56- CHECK_FAILURE(args->GetDeferral(&deferral));
57-
58- m_appWindow->RunAsync([deferral]() { CHECK_FAILURE(deferral->Complete()); });
59-
58+ }
6059 return S_OK;
6160 })
6261 .Get(),
@@ -75,32 +74,23 @@ void AddCustomFileTypePoliciesExecuted(object target, ExecutedRoutedEventArgs e)
7574 // Register a handler for the `FileTypePolicyChecking` event.
7675 webView .CoreWebView2 .FileTypePolicyChecking += (sender , args ) =>
7776 {
78- // Developer can obtain a deferral for the event so that the CoreWebView2
79- // doesn't examine the properties we set on the event args until
80- // after the deferral completes asynchronously.
81- CoreWebView2Deferral deferral = args .GetDeferral ();
82-
83- // We avoid potential reentrancy from running a message loop in the event
84- // handler. Complete the deferral asynchronously.
85- System .Threading .SynchronizationContext .Current .Post ((_ ) =>
77+ // Get the file extension for file to be saved.
78+ // And create your own rules of file type policy.
79+ if (args .FileExtension == " eml" )
8680 {
87- using (deferral )
88- {
89- // Get the file extension for file to be saved.
90- // And create your own rules of file type policy.
91- if (args .FileExtension == " eml" )
92- // Set the `SuppressDefaultPolicy` property to skip the
93- // default file type policy checking and a possible security
94- // alert dialog for "eml" file. This will consent to
95- // save the file.
96- args .SuppressDefaultPolicy = true ;
97- if (args .FileExtension == " exe" )
98- // Set the `Cancel` property to cancel the saving for "exe"
99- // file directly. Save action will be aborted without any
100- // alert.
101- args .Cancel = true ;
102- }
103- }, null );
81+ // Set the `SuppressDefaultPolicy` property to skip the
82+ // default file type policy checking and a possible security
83+ // alert dialog for "eml" file. This will consent to
84+ // save the file.
85+ args .SuppressDefaultPolicy = true ;
86+ }
87+ if (args .FileExtension == " exe" )
88+ {
89+ // Set the `Cancel` property to cancel the saving for "exe"
90+ // file directly. Save action will be aborted without any
91+ // alert.
92+ args .Cancel = true ;
93+ }
10494 };
10595}
10696```
@@ -110,7 +100,9 @@ void AddCustomFileTypePoliciesExecuted(object target, ExecutedRoutedEventArgs e)
110100``` c++
111101interface ICoreWebView2 : IUnknown {
112102 /// Adds an event handler for the ` FileTypePolicyChecking ` event.
113- /// This event will be raised during system FileTypePolicy
103+ /// If the default save file picker is used to save a file, for
104+ /// example, client using the File System API ` showSaveFilePicker ` ;
105+ /// this event will be raised during system FileTypePolicy
114106 /// checking the dangerous file extension list.
115107 ///
116108 /// Developers can specify their own decision on if allow this file
@@ -121,14 +113,14 @@ interface ICoreWebView2 : IUnknown {
121113 ///
122114 /// | Cancel | SuppressDefaultPolicy | Result
123115 /// | ------ | ------ | ---------------------
124- /// | False | False | Process to default policy check. It might show
116+ /// | False | False | Perform the default policy check. It may show the
125117 /// | | | security warning UI if the file extension is
126118 /// | | | dangerous.
127119 /// | ------ | ------ | ---------------------
128120 /// | False | True | Skip the default policy check and the possible
129121 /// | | | security warning. Start saving or downloading.
130122 /// | ------ | ------ | ---------------------
131- /// | True | T or F | Skip the default policy check and the possible
123+ /// | True | Any | Skip the default policy check and the possible
132124 /// | | | security warning. Abort save or download.
133125 HRESULT add_FileTypePolicyChecking(
134126 [ in] ICoreWebView2StagingFileTypePolicyCheckingEventHandler* eventHandler,
@@ -153,10 +145,12 @@ interface ICoreWebView2StagingFileTypePolicyCheckingEventArgs : IUnknown {
153145
154146 /// Get the extension of file to be saved.
155147 ///
156- /// File extension can be empty.
148+ /// File extension can be empty, if the file name has no extension
149+ /// at all.
157150 ///
158- /// Only final extension will be provided. For example, "* .tar.gz"
159- /// is a double extension, where the "gz" will be its final extension.
151+ /// Only final extension without "." will be provided. For example,
152+ /// "* .tar.gz" is a double extension, where the "gz" will be its
153+ /// final extension.
160154 ///
161155 /// File extension usage in the API is case sensitive.
162156 [ propget] HRESULT FileExtension([ out, retval] LPWSTR* value);
@@ -174,11 +168,14 @@ interface ICoreWebView2StagingFileTypePolicyCheckingEventArgs : IUnknown {
174168 /// The default value is ` FALSE ` .
175169 [ propput] HRESULT SuppressDefaultPolicy([ in] BOOL value);
176170
177- /// Get the uri of file source .
171+ /// The URI source of this file save operation .
178172 [ propget] HRESULT Uri([ out, retval] LPWSTR* value);
179173
180174 /// Returns an ` ICoreWebView2Deferral ` object. Use this operation to complete
181175 /// the FileTypePolicyCheckingEvent.
176+ ///
177+ /// The default policy checking and any default UI will be blocked temporarily,
178+ /// saving file to local won't start, until the deferral is completed.
182179 HRESULT GetDeferral(
183180 [ out, retval] ICoreWebView2Deferral** value
184181 );
0 commit comments