| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/credentialmanager/PasswordCredential.h" | 5 #include "modules/credentialmanager/PasswordCredential.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "core/HTMLNames.h" |
| 9 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/dom/URLSearchParams.h" | 11 #include "core/dom/URLSearchParams.h" |
| 12 #include "core/html/FormAssociatedElement.h" |
| 11 #include "core/html/FormData.h" | 13 #include "core/html/FormData.h" |
| 14 #include "core/html/HTMLFormElement.h" |
| 12 #include "modules/credentialmanager/FormDataOptions.h" | 15 #include "modules/credentialmanager/FormDataOptions.h" |
| 13 #include "modules/credentialmanager/PasswordCredentialData.h" | 16 #include "modules/credentialmanager/PasswordCredentialData.h" |
| 14 #include "platform/credentialmanager/PlatformPasswordCredential.h" | 17 #include "platform/credentialmanager/PlatformPasswordCredential.h" |
| 15 #include "platform/weborigin/SecurityOrigin.h" | 18 #include "platform/weborigin/SecurityOrigin.h" |
| 16 #include "public/platform/WebCredential.h" | 19 #include "public/platform/WebCredential.h" |
| 17 #include "public/platform/WebPasswordCredential.h" | 20 #include "public/platform/WebPasswordCredential.h" |
| 18 | 21 |
| 19 namespace blink { | 22 namespace blink { |
| 20 | 23 |
| 21 PasswordCredential* PasswordCredential::create(WebPasswordCredential* webPasswor
dCredential) | 24 PasswordCredential* PasswordCredential::create(WebPasswordCredential* webPasswor
dCredential) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 return nullptr; | 37 return nullptr; |
| 35 } | 38 } |
| 36 | 39 |
| 37 KURL iconURL = parseStringAsURL(data.iconURL(), exceptionState); | 40 KURL iconURL = parseStringAsURL(data.iconURL(), exceptionState); |
| 38 if (exceptionState.hadException()) | 41 if (exceptionState.hadException()) |
| 39 return nullptr; | 42 return nullptr; |
| 40 | 43 |
| 41 return new PasswordCredential(data.id(), data.password(), data.name(), iconU
RL); | 44 return new PasswordCredential(data.id(), data.password(), data.name(), iconU
RL); |
| 42 } | 45 } |
| 43 | 46 |
| 47 // https://w3c.github.io/webappsec-credential-management/#passwordcredential-for
m-constructor |
| 48 PasswordCredential* PasswordCredential::create(HTMLFormElement* form, ExceptionS
tate& exceptionState) |
| 49 { |
| 50 // Extract data from the form, then use the extracted |formData| object's |
| 51 // value to populate |data|. |
| 52 FormData* formData = FormData::create(form); |
| 53 PasswordCredentialData data; |
| 54 |
| 55 AtomicString idName; |
| 56 AtomicString passwordName; |
| 57 for (FormAssociatedElement* element : form->associatedElements()) { |
| 58 // If |element| isn't a "submittable element" with string data, then it |
| 59 // won't have a matching value in |formData|, and we can safely skip it. |
| 60 FileOrUSVString result; |
| 61 formData->get(element->name(), result); |
| 62 if (!result.isUSVString()) |
| 63 continue; |
| 64 |
| 65 AtomicString autocomplete = toHTMLElement(element)->fastGetAttribute(HTM
LNames::autocompleteAttr); |
| 66 if (equalIgnoringCase(autocomplete, "current-password") || equalIgnoring
Case(autocomplete, "new-password")) { |
| 67 data.setPassword(result.getAsUSVString()); |
| 68 passwordName = element->name(); |
| 69 } else if (equalIgnoringCase(autocomplete, "photo")) { |
| 70 data.setIconURL(result.getAsUSVString()); |
| 71 } else if (equalIgnoringCase(autocomplete, "name") || equalIgnoringCase(
autocomplete, "nickname")) { |
| 72 data.setName(result.getAsUSVString()); |
| 73 } else if (equalIgnoringCase(autocomplete, "username")) { |
| 74 data.setId(result.getAsUSVString()); |
| 75 idName = element->name(); |
| 76 } |
| 77 } |
| 78 |
| 79 // Create a PasswordCredential using the data gathered above. |
| 80 PasswordCredential* credential = PasswordCredential::create(data, exceptionS
tate); |
| 81 if (exceptionState.hadException()) |
| 82 return nullptr; |
| 83 ASSERT(credential); |
| 84 |
| 85 // After creating the Credential, populate its 'additionalData', 'idName', a
nd 'passwordName' attributes. |
| 86 FormDataOrURLSearchParams additionalData; |
| 87 additionalData.setFormData(formData); |
| 88 credential->setAdditionalData(additionalData); |
| 89 credential->setIdName(idName); |
| 90 credential->setPasswordName(passwordName); |
| 91 return credential; |
| 92 } |
| 93 |
| 44 PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredent
ial) | 94 PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredent
ial) |
| 45 : Credential(webPasswordCredential->getPlatformCredential()) | 95 : Credential(webPasswordCredential->getPlatformCredential()) |
| 46 , m_idName("username") | 96 , m_idName("username") |
| 47 , m_passwordName("password") | 97 , m_passwordName("password") |
| 48 { | 98 { |
| 49 } | 99 } |
| 50 | 100 |
| 51 PasswordCredential::PasswordCredential(const String& id, const String& password,
const String& name, const KURL& icon) | 101 PasswordCredential::PasswordCredential(const String& id, const String& password,
const String& name, const KURL& icon) |
| 52 : Credential(PlatformPasswordCredential::create(id, password, name, icon)) | 102 : Credential(PlatformPasswordCredential::create(id, password, name, icon)) |
| 53 , m_idName("username") | 103 , m_idName("username") |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get())-
>password(); | 152 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get())-
>password(); |
| 103 } | 153 } |
| 104 | 154 |
| 105 DEFINE_TRACE(PasswordCredential) | 155 DEFINE_TRACE(PasswordCredential) |
| 106 { | 156 { |
| 107 Credential::trace(visitor); | 157 Credential::trace(visitor); |
| 108 visitor->trace(m_additionalData); | 158 visitor->trace(m_additionalData); |
| 109 } | 159 } |
| 110 | 160 |
| 111 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |