| 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/HTMLNames.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 AtomicString idName; | 57 AtomicString idName; |
| 58 AtomicString passwordName; | 58 AtomicString passwordName; |
| 59 for (FormAssociatedElement* element : form->associatedElements()) { | 59 for (FormAssociatedElement* element : form->associatedElements()) { |
| 60 // If |element| isn't a "submittable element" with string data, then it | 60 // If |element| isn't a "submittable element" with string data, then it |
| 61 // won't have a matching value in |formData|, and we can safely skip it. | 61 // won't have a matching value in |formData|, and we can safely skip it. |
| 62 FileOrUSVString result; | 62 FileOrUSVString result; |
| 63 formData->get(element->name(), result); | 63 formData->get(element->name(), result); |
| 64 if (!result.isUSVString()) | 64 if (!result.isUSVString()) |
| 65 continue; | 65 continue; |
| 66 | 66 |
| 67 AtomicString autocomplete = | 67 Vector<String> autofillTokens; |
| 68 toHTMLElement(element)->fastGetAttribute(HTMLNames::autocompleteAttr); | 68 toHTMLElement(element) |
| 69 if (equalIgnoringCase(autocomplete, "current-password") || | 69 ->fastGetAttribute(HTMLNames::autocompleteAttr) |
| 70 equalIgnoringCase(autocomplete, "new-password")) { | 70 .getString() |
| 71 data.setPassword(result.getAsUSVString()); | 71 .lower() // Lowercase here once to avoid the case-folding logic below. |
| 72 passwordName = element->name(); | 72 .split(' ', autofillTokens); |
| 73 } else if (equalIgnoringCase(autocomplete, "photo")) { | 73 for (const auto& token : autofillTokens) { |
| 74 data.setIconURL(result.getAsUSVString()); | 74 if (token == "current-password" || token == "new-password") { |
| 75 } else if (equalIgnoringCase(autocomplete, "name") || | 75 data.setPassword(result.getAsUSVString()); |
| 76 equalIgnoringCase(autocomplete, "nickname")) { | 76 passwordName = element->name(); |
| 77 data.setName(result.getAsUSVString()); | 77 } else if (token == "photo") { |
| 78 } else if (equalIgnoringCase(autocomplete, "username")) { | 78 data.setIconURL(result.getAsUSVString()); |
| 79 data.setId(result.getAsUSVString()); | 79 } else if (token == "name" || token == "nickname") { |
| 80 idName = element->name(); | 80 data.setName(result.getAsUSVString()); |
| 81 } else if (token == "username") { |
| 82 data.setId(result.getAsUSVString()); |
| 83 idName = element->name(); |
| 84 } |
| 81 } | 85 } |
| 82 } | 86 } |
| 83 | 87 |
| 84 // Create a PasswordCredential using the data gathered above. | 88 // Create a PasswordCredential using the data gathered above. |
| 85 PasswordCredential* credential = | 89 PasswordCredential* credential = |
| 86 PasswordCredential::create(data, exceptionState); | 90 PasswordCredential::create(data, exceptionState); |
| 87 if (exceptionState.hadException()) | 91 if (exceptionState.hadException()) |
| 88 return nullptr; | 92 return nullptr; |
| 89 ASSERT(credential); | 93 ASSERT(credential); |
| 90 | 94 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get()) | 179 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get()) |
| 176 ->password(); | 180 ->password(); |
| 177 } | 181 } |
| 178 | 182 |
| 179 DEFINE_TRACE(PasswordCredential) { | 183 DEFINE_TRACE(PasswordCredential) { |
| 180 SiteBoundCredential::trace(visitor); | 184 SiteBoundCredential::trace(visitor); |
| 181 visitor->trace(m_additionalData); | 185 visitor->trace(m_additionalData); |
| 182 } | 186 } |
| 183 | 187 |
| 184 } // namespace blink | 188 } // namespace blink |
| OLD | NEW |