Chromium Code Reviews| 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 .split(' ', autofillTokens); | |
| 72 auto hasToken = [&autofillTokens](const StringView& expectedToken) { | |
|
haraken
2016/11/10 02:01:51
Nit: The lambda function is allowed in the style g
Mike West
2016/11/10 07:46:39
It also seems like it would be more efficient to l
vasilii
2016/11/10 09:21:55
Done.
| |
| 73 for (const auto& token : autofillTokens) { | |
| 74 if (equalIgnoringASCIICase(token, expectedToken)) | |
| 75 return true; | |
| 76 } | |
| 77 return false; | |
| 78 }; | |
| 79 if (hasToken("current-password") || hasToken("new-password")) { | |
| 71 data.setPassword(result.getAsUSVString()); | 80 data.setPassword(result.getAsUSVString()); |
| 72 passwordName = element->name(); | 81 passwordName = element->name(); |
| 73 } else if (equalIgnoringCase(autocomplete, "photo")) { | 82 } else if (hasToken("photo")) { |
| 74 data.setIconURL(result.getAsUSVString()); | 83 data.setIconURL(result.getAsUSVString()); |
| 75 } else if (equalIgnoringCase(autocomplete, "name") || | 84 } else if (hasToken("name") || hasToken("nickname")) { |
| 76 equalIgnoringCase(autocomplete, "nickname")) { | |
| 77 data.setName(result.getAsUSVString()); | 85 data.setName(result.getAsUSVString()); |
| 78 } else if (equalIgnoringCase(autocomplete, "username")) { | 86 } else if (hasToken("username")) { |
| 79 data.setId(result.getAsUSVString()); | 87 data.setId(result.getAsUSVString()); |
| 80 idName = element->name(); | 88 idName = element->name(); |
| 81 } | 89 } |
| 82 } | 90 } |
| 83 | 91 |
| 84 // Create a PasswordCredential using the data gathered above. | 92 // Create a PasswordCredential using the data gathered above. |
| 85 PasswordCredential* credential = | 93 PasswordCredential* credential = |
| 86 PasswordCredential::create(data, exceptionState); | 94 PasswordCredential::create(data, exceptionState); |
| 87 if (exceptionState.hadException()) | 95 if (exceptionState.hadException()) |
| 88 return nullptr; | 96 return nullptr; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get()) | 183 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get()) |
| 176 ->password(); | 184 ->password(); |
| 177 } | 185 } |
| 178 | 186 |
| 179 DEFINE_TRACE(PasswordCredential) { | 187 DEFINE_TRACE(PasswordCredential) { |
| 180 SiteBoundCredential::trace(visitor); | 188 SiteBoundCredential::trace(visitor); |
| 181 visitor->trace(m_additionalData); | 189 visitor->trace(m_additionalData); |
| 182 } | 190 } |
| 183 | 191 |
| 184 } // namespace blink | 192 } // namespace blink |
| OLD | NEW |