mirror of
https://github.com/bitwarden/android.git
synced 2024-12-20 08:12:26 +03:00
autofill improvements to fallback when no "viewable" password/username fields are detected.
This commit is contained in:
parent
9938fdd4a2
commit
07bec16539
1 changed files with 30 additions and 4 deletions
|
@ -20,6 +20,12 @@ namespace Bit.iOS.Extension.Models
|
||||||
List<PageDetails.Field> passwords = new List<PageDetails.Field>();
|
List<PageDetails.Field> passwords = new List<PageDetails.Field>();
|
||||||
|
|
||||||
var passwordFields = pageDetails.Fields.Where(f => f.Type == "password" && f.Viewable).ToArray();
|
var passwordFields = pageDetails.Fields.Where(f => f.Type == "password" && f.Viewable).ToArray();
|
||||||
|
if(!passwordFields.Any())
|
||||||
|
{
|
||||||
|
// not able to find any viewable password fields. maybe there are some "hidden" ones?
|
||||||
|
passwordFields = pageDetails.Fields.Where(f => f.Type == "password").ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
foreach(var form in pageDetails.Forms)
|
foreach(var form in pageDetails.Forms)
|
||||||
{
|
{
|
||||||
var passwordFieldsForForm = passwordFields.Where(f => f.Form == form.Key).ToArray();
|
var passwordFieldsForForm = passwordFields.Where(f => f.Form == form.Key).ToArray();
|
||||||
|
@ -32,8 +38,13 @@ namespace Bit.iOS.Extension.Models
|
||||||
|
|
||||||
foreach(var pf in passwordFieldsForForm)
|
foreach(var pf in passwordFieldsForForm)
|
||||||
{
|
{
|
||||||
var username = pageDetails.Fields.LastOrDefault(f => f.Form == pf.Form && f.Viewable
|
var username = FindUsernameField(pageDetails, pf, false, true);
|
||||||
&& f.ElementNumber < pf.ElementNumber && (f.Type == "text" || f.Type == "email" || f.Type == "tel"));
|
if(username == null)
|
||||||
|
{
|
||||||
|
// not able to find any viewable username fields. maybe there are some "hidden" ones?
|
||||||
|
username = FindUsernameField(pageDetails, pf, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
if(username != null)
|
if(username != null)
|
||||||
{
|
{
|
||||||
usernames.Add(username);
|
usernames.Add(username);
|
||||||
|
@ -51,8 +62,13 @@ namespace Bit.iOS.Extension.Models
|
||||||
|
|
||||||
if(!string.IsNullOrWhiteSpace(fillUsername) && pf.ElementNumber > 0)
|
if(!string.IsNullOrWhiteSpace(fillUsername) && pf.ElementNumber > 0)
|
||||||
{
|
{
|
||||||
var username = pageDetails.Fields.LastOrDefault(f => f.ElementNumber < pf.ElementNumber && f.Viewable
|
var username = FindUsernameField(pageDetails, pf, false, false);
|
||||||
&& (f.Type == "text" || f.Type == "email" || f.Type == "tel"));
|
if(username == null)
|
||||||
|
{
|
||||||
|
// not able to find any viewable username fields. maybe there are some "hidden" ones?
|
||||||
|
username = FindUsernameField(pageDetails, pf, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
if(username != null)
|
if(username != null)
|
||||||
{
|
{
|
||||||
usernames.Add(username);
|
usernames.Add(username);
|
||||||
|
@ -78,6 +94,16 @@ namespace Bit.iOS.Extension.Models
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PageDetails.Field FindUsernameField(PageDetails pageDetails, PageDetails.Field passwordField, bool canBeHidden,
|
||||||
|
bool checkForm)
|
||||||
|
{
|
||||||
|
return pageDetails.Fields.LastOrDefault(f =>
|
||||||
|
(!checkForm || f.Form == passwordField.Form)
|
||||||
|
&& (canBeHidden || f.Viewable)
|
||||||
|
&& f.ElementNumber < passwordField.ElementNumber
|
||||||
|
&& (f.Type == "text" || f.Type == "email" || f.Type == "tel"));
|
||||||
|
}
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "script")]
|
[JsonProperty(PropertyName = "script")]
|
||||||
public List<List<string>> Script { get; set; } = new List<List<string>>();
|
public List<List<string>> Script { get; set; } = new List<List<string>>();
|
||||||
[JsonProperty(PropertyName = "autosubmit")]
|
[JsonProperty(PropertyName = "autosubmit")]
|
||||||
|
|
Loading…
Reference in a new issue