Chromium Code Reviews| Index: third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp |
| diff --git a/third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp b/third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp |
| index 101706dae4ca904599a4401981610a99f9d16b37..743bb10745e0b6960d88be09327e989c75b7be36 100644 |
| --- a/third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp |
| +++ b/third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp |
| @@ -6,9 +6,12 @@ |
| #include "bindings/core/v8/Dictionary.h" |
| #include "bindings/core/v8/ExceptionState.h" |
| +#include "core/HTMLNames.h" |
| #include "core/dom/ExecutionContext.h" |
| #include "core/dom/URLSearchParams.h" |
| +#include "core/html/FormAssociatedElement.h" |
| #include "core/html/FormData.h" |
| +#include "core/html/HTMLFormElement.h" |
| #include "modules/credentialmanager/FormDataOptions.h" |
| #include "modules/credentialmanager/PasswordCredentialData.h" |
| #include "platform/credentialmanager/PlatformPasswordCredential.h" |
| @@ -41,6 +44,51 @@ PasswordCredential* PasswordCredential::create(const PasswordCredentialData& dat |
| return new PasswordCredential(data.id(), data.password(), data.name(), iconURL); |
| } |
| +PasswordCredential* PasswordCredential::create(HTMLFormElement* form, ExceptionState& exceptionState) |
| +{ |
| + // Extract data from the form, then use the extracted |formData| object's |
| + // value to populate |data|. |
| + FormData* formData = FormData::create(form); |
| + PasswordCredentialData data; |
| + |
| + AtomicString idName; |
| + AtomicString passwordName; |
| + for (FormAssociatedElement* element : form->associatedElements()) { |
|
philipj_slow
2016/03/29 05:45:54
The spec wants the "submittable elements" which is
Mike West
2016/03/31 08:31:41
Done.
|
| + FileOrUSVString result; |
| + formData->get(element->name(), result); |
| + if (!result.isUSVString()) |
| + continue; |
| + |
| + AtomicString autocomplete = toHTMLElement(element)->fastGetAttribute(HTMLNames::autocompleteAttr); |
| + if (equalIgnoringCase(autocomplete, "photo")) |
| + data.setIconURL(result.getAsUSVString()); |
| + if (equalIgnoringCase(autocomplete, "name") || equalIgnoringCase(autocomplete, "nickname")) |
|
philipj_slow
2016/03/29 05:45:54
Maybe more else all the way down? Unless there's a
Mike West
2016/03/31 08:31:41
Done and done.
|
| + data.setName(result.getAsUSVString()); |
| + if (equalIgnoringCase(autocomplete, "current-password") || equalIgnoringCase(autocomplete, "new-password")) { |
| + data.setPassword(result.getAsUSVString()); |
| + passwordName = element->name(); |
| + } |
| + if (equalIgnoringCase(autocomplete, "username")) { |
| + data.setId(result.getAsUSVString()); |
| + idName = element->name(); |
| + } |
| + } |
| + |
| + // Create a PasswordCredential using the data gathered above. |
| + PasswordCredential* credential = PasswordCredential::create(data, exceptionState); |
| + if (exceptionState.hadException()) |
| + return nullptr; |
| + ASSERT(credential); |
| + |
| + // After creating the Credential, populate its 'additionalData', 'idName', and 'passwordName' attributes. |
| + FormDataOrURLSearchParams additionalData; |
| + additionalData.setFormData(formData); |
| + credential->setAdditionalData(additionalData); |
| + credential->setIdName(idName); |
| + credential->setPasswordName(passwordName); |
| + return credential; |
| +} |
| + |
| PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredential) |
| : Credential(webPasswordCredential->getPlatformCredential()) |
| , m_idName("username") |