Skip to content

Commit 84cdf1d

Browse files
lichen63zhuhaichao518david-risney
authored
API spec review for password-autosave and general-autofill in Profile (#3285)
* Add multiprofile password-autosave and general-autofill interfaces. * only general-autofill can work immediately while password-autosave can only work after next navigation. * comments fix * API Review: cookieManager for multiprofile (#1844) * API documentation: cookieManager for multiprofile * update comments. * typo * fix grammatical errors * typo * typo * update cookie manager description in prologue * update runtimeclass CoreWebView2Profile * Update MultiProfile.md * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update specs/MultiProfile.md Co-authored-by: David Risney <dave@deletethis.net> * Update MultiProfile.md * Update MultiProfile.md * Update MultiProfile.md --------- Co-authored-by: zhuhaichao518 <54018092+zhuhaichao518@users.noreply.github.com> Co-authored-by: David Risney <dave@deletethis.net>
1 parent 5c0c310 commit 84cdf1d

1 file changed

Lines changed: 161 additions & 0 deletions

File tree

specs/MultiProfile.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ Users can use this interface to get the cookie manager, which is shared by all W
2929
with this profile. The cookie manager got from profile (CoreWebView2.Profile.CookieManager) is the
3030
same as that got from CoreWebView2 (CoreWebView2.CookieManager).
3131

32+
Currently, we already have **CoreWebView2Settings** interface to manage password-autosave and
33+
general-autofill, and these two properties are different from other properties in
34+
**CoreWebView2Settings** because they will take effect immediately and apply for all WebView2s
35+
that created from the same profile. By adding password-autosave and general-autofill management
36+
interfaces in profile, we can manage the properties and they will apply immediately if we set a
37+
new value, and all WebView2s that created with the same profile can share the settings, which
38+
means if we change password-autosave or general-autofill property in one WebView2, the others
39+
with the same profile will also take effect. And these two properties are linked with their
40+
corresponding properties in ICoreWebView2Settings, so changing one will change the other.
41+
it will take effect immediately no matter setting the properties in **CoreWebView2Settings** or
42+
**CoreWebView2Profile**, and when the property is changed in one interface, the same property
43+
in the other interface is changed as well immediately. So for the WebView2s with the same profile,
44+
their **IsPasswordAutosaveEnabled** or **IsGeneralAutofillEnabled** property in
45+
**CoreWebView2Settings** and **CoreWebView2Profile** should always keep in sync.
46+
3247
# Examples
3348

3449
## Win32 C++
@@ -217,6 +232,80 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(
217232
}
218233
```
219234
235+
### Manage password-autosave and general-autofill settings in profile
236+
237+
```cpp
238+
HRESULT AppWindow::TogglePasswordAutosaveInProfile(ICoreWebView2Controller* controller)
239+
{
240+
// ...
241+
242+
// Get the profile object.
243+
wil::com_ptr<ICoreWebView2> coreWebView2;
244+
CHECK_FAILURE(controller->get_CoreWebView2(&coreWebView2));
245+
Microsoft::WRL::ComPtr<ICoreWebView2Profile> webView2Profile;
246+
CHECK_FAILURE(coreWebView2->get_Profile(&webView2Profile));
247+
Microsoft::WRL::ComPtr<ICoreWebView2Profile3> webView2Profile3;
248+
CHECK_FAILURE(webView2Profile.As(&webView2Profile3));
249+
250+
// Get current value of password-autosave property.
251+
BOOL enabled;
252+
CHECK_FAILURE(webView2Profile3->get_IsPasswordAutosaveEnabled(&enabled));
253+
254+
// Set password-autosave property to the opposite value to current value.
255+
if (enabled)
256+
{
257+
CHECK_FAILURE(webView2Profile3->put_IsPasswordAutosaveEnabled(FALSE));
258+
MessageBox(
259+
hWnd, L"Password autosave will be disabled immediately in all WebView2 with the same profile.",
260+
L"Profile settings change", MB_OK);
261+
}
262+
else
263+
{
264+
CHECK_FAILURE(webView2Profile3->put_IsPasswordAutosaveEnabled(TRUE));
265+
MessageBox(
266+
hWnd, L"Password autosave will be enabled immediately in all WebView2 with the same profile.",
267+
L"Profile settings change", MB_OK);
268+
}
269+
270+
// ...
271+
}
272+
273+
HRESULT AppWindow::ToggleGeneralAutofillInProfile(ICoreWebView2Controller* controller)
274+
{
275+
// ...
276+
277+
// Get the profile object.
278+
wil::com_ptr<ICoreWebView2> coreWebView2;
279+
CHECK_FAILURE(controller->get_CoreWebView2(&coreWebView2));
280+
Microsoft::WRL::ComPtr<ICoreWebView2Profile> webView2Profile;
281+
CHECK_FAILURE(coreWebView2->get_Profile(&webView2Profile));
282+
Microsoft::WRL::ComPtr<ICoreWebView2Profile3> webView2Profile3;
283+
CHECK_FAILURE(webView2Profile.As(&webView2Profile3));
284+
285+
// Get current value of general-autofill property.
286+
BOOL enabled;
287+
CHECK_FAILURE(webView2Profile3->get_IsGeneralAutofillsaveEnabled(&enabled));
288+
289+
// Set general-autofill property to the opposite value to current value.
290+
if (enabled)
291+
{
292+
CHECK_FAILURE(webView2Profile3->put_IsGeneralAutofillEnabled(FALSE));
293+
MessageBox(
294+
hWnd, L"General autofill will be disabled immediately in all WebView2 with the same profile.",
295+
L"Profile settings change", MB_OK);
296+
}
297+
else
298+
{
299+
CHECK_FAILURE(webView2Profile3->put_IsGeneralAutofillEnabled(TRUE));
300+
MessageBox(
301+
hWnd, L"General autofill will be enabled immediately in all WebView2 with the same profile.",
302+
L"Profile settings change", MB_OK);
303+
}
304+
305+
// ...
306+
}
307+
```
308+
220309
## .NET and WinRT
221310

222311
### Create WebView2 with a specific profile, then access the profile property of WebView2
@@ -314,6 +403,32 @@ private void WebViewProfile_Deleted(object sender, object e)
314403
Close();
315404
});
316405
}
406+
### Manage password-autosave and general-autofill settings in profile
407+
408+
```csharp
409+
public TogglePasswordAutosaveInProfile(CoreWebView2Controller controller)
410+
{
411+
// Get the profile object.
412+
CoreWebView2Profile profile = controller.CoreWebView2.Profile;
413+
414+
// Get current value of password-autosave property.
415+
bool enabled = profile.IsPasswordAutosaveEnabled;
416+
417+
// Set password-autosave property to the opposite value to current value.
418+
profile.IsPasswordAutosaveEnabled = !enabled;
419+
}
420+
421+
public ToggleGeneralAutofillInProfile(CoreWebView2Controller controller)
422+
{
423+
// Get the profile object.
424+
CoreWebView2Profile profile = controller.CoreWebView2.Profile;
425+
426+
// Get current value of general-autofill property.
427+
bool enabled = profile.IsGeneralAutofillEnabled;
428+
429+
// Set general-autofill property to the opposite value to current value.
430+
profile.IsGeneralAutofillEnabled = !enabled;
431+
}
317432
```
318433

319434
# API Details
@@ -459,6 +574,45 @@ interface ICoreWebView2StagingProfileDeletedEventHandler: IUnknown {
459574
[in] ICoreWebView2Profile* sender,
460575
[in] IUnknown* args);
461576
}
577+
578+
[uuid(e2e8dce3-8213-4a32-b3b0-c80a8d154b61), object, pointer_default(unique)]
579+
interface ICoreWebView2Profile3 : ICoreWebView2Profile2 {
580+
/// IsPasswordAutosaveEnabled controls whether autosave for password
581+
/// information is enabled. The IsPasswordAutosaveEnabled property behaves
582+
/// independently of the IsGeneralAutofillEnabled property. When IsPasswordAutosaveEnabled is
583+
/// false, no new password data is saved and no Save/Update Password prompts are displayed.
584+
/// However, if there was password data already saved before disabling this setting,
585+
/// then that password information is auto-populated, suggestions are shown and clicking on
586+
/// one will populate the fields.
587+
/// When IsPasswordAutosaveEnabled is true, password information is auto-populated,
588+
/// suggestions are shown and clicking on one will populate the fields, new data
589+
/// is saved, and a Save/Update Password prompt is displayed.
590+
/// The default value is `FALSE`.
591+
/// This property has the same value as `CoreWebView2Settings.IsPasswordAutosaveEnabled`, and
592+
/// changing one will change the other. All `CoreWebView2`s with the same
593+
/// `CoreWebView2Profile` will share the same value for this property, so for the `CoreWebView2`s with the same
594+
/// profile, their `CoreWebView2Settings.IsPasswordAutosaveEnabled` and
595+
/// `CoreWebView2Profile.IsPasswordAutosaveEnabled` will always have the same value.
596+
[propget] HRESULT IsPasswordAutosaveEnabled([out, retval] BOOL* value);
597+
/// Set the IsPasswordAutosaveEnabled property.
598+
[propput] HRESULT IsPasswordAutosaveEnabled([in] BOOL value);
599+
600+
/// IsGeneralAutofillEnabled controls whether autofill for information
601+
/// like names, street and email addresses, phone numbers, and arbitrary input
602+
/// is enabled. This excludes password and credit card information. When
603+
/// IsGeneralAutofillEnabled is false, no suggestions appear, and no new information
604+
/// is saved. When IsGeneralAutofillEnabled is true, information is saved, suggestions
605+
/// appear and clicking on one will populate the form fields.
606+
/// The default value is `TRUE`.
607+
/// This property has the same value as `CoreWebView2Settings.IsGeneralAutofillEnabled`, and
608+
/// changing one will change the other. All `CoreWebView2`s with the same
609+
/// `CoreWebView2Profile` will share the same value for this property, so for the `CoreWebView2`s with the same
610+
/// profile, their `CoreWebView2Settings.IsGeneralAutofillEnabled` and
611+
/// `CoreWebView2Profile.IsGeneralAutofillEnabled` will always have the same value.
612+
[propget] HRESULT IsGeneralAutofillEnabled([out, retval] BOOL* value);
613+
/// Set the IsGeneralAutofillEnabled property.
614+
[propput] HRESULT IsGeneralAutofillEnabled([in] BOOL value);
615+
}
462616
```
463617

464618
## .NET and WinRT
@@ -516,6 +670,13 @@ namespace Microsoft.Web.WebView2.Core
516670
void Delete();
517671
event Windows.Foundation.TypedEventHandler<CoreWebView2Profile, Object> Deleted;
518672
}
673+
674+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Profile3")]
675+
{
676+
Boolean IsPasswordAutosaveEnabled { get; set; };
677+
678+
Boolean IsGeneralAutofillEnabled { get; set; };
679+
}
519680
}
520681
}
521682
```

0 commit comments

Comments
 (0)