| 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..9fcbacbfa87eeffff5f96106b0cc66f2886d0420 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,53 @@ PasswordCredential* PasswordCredential::create(const PasswordCredentialData& dat
|
| return new PasswordCredential(data.id(), data.password(), data.name(), iconURL);
|
| }
|
|
|
| +// https://w3c.github.io/webappsec-credential-management/#passwordcredential-form-constructor
|
| +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()) {
|
| + // If |element| isn't a "submittable element" with string data, then it
|
| + // won't have a matching value in |formData|, and we can safely skip it.
|
| + FileOrUSVString result;
|
| + formData->get(element->name(), result);
|
| + if (!result.isUSVString())
|
| + continue;
|
| +
|
| + AtomicString autocomplete = toHTMLElement(element)->fastGetAttribute(HTMLNames::autocompleteAttr);
|
| + if (equalIgnoringCase(autocomplete, "current-password") || equalIgnoringCase(autocomplete, "new-password")) {
|
| + data.setPassword(result.getAsUSVString());
|
| + passwordName = element->name();
|
| + } else if (equalIgnoringCase(autocomplete, "photo")) {
|
| + data.setIconURL(result.getAsUSVString());
|
| + } else if (equalIgnoringCase(autocomplete, "name") || equalIgnoringCase(autocomplete, "nickname")) {
|
| + data.setName(result.getAsUSVString());
|
| + } else 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")
|
|
|