| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Create a PasswordCredential using the data gathered above. | 84 // Create a PasswordCredential using the data gathered above. |
| 85 PasswordCredential* credential = | 85 PasswordCredential* credential = |
| 86 PasswordCredential::create(data, exceptionState); | 86 PasswordCredential::create(data, exceptionState); |
| 87 if (exceptionState.hadException()) | 87 if (exceptionState.hadException()) |
| 88 return nullptr; | 88 return nullptr; |
| 89 ASSERT(credential); | 89 ASSERT(credential); |
| 90 | 90 |
| 91 // After creating the Credential, populate its 'additionalData', 'idName', and
'passwordName' attributes. | 91 // After creating the Credential, populate its 'additionalData', 'idName', and |
| 92 // If the form's 'enctype' is anything other than multipart, generate a URLSea
rchParams using the | 92 // 'passwordName' attributes. If the form's 'enctype' is anything other than |
| 93 // multipart, generate a URLSearchParams using the |
| 93 // data in |formData|. | 94 // data in |formData|. |
| 94 credential->setIdName(idName); | 95 credential->setIdName(idName); |
| 95 credential->setPasswordName(passwordName); | 96 credential->setPasswordName(passwordName); |
| 96 | 97 |
| 97 FormDataOrURLSearchParams additionalData; | 98 FormDataOrURLSearchParams additionalData; |
| 98 if (form->enctype() == "multipart/form-data") { | 99 if (form->enctype() == "multipart/form-data") { |
| 99 additionalData.setFormData(formData); | 100 additionalData.setFormData(formData); |
| 100 } else { | 101 } else { |
| 101 URLSearchParams* params = URLSearchParams::create(URLSearchParamsInit()); | 102 URLSearchParams* params = URLSearchParams::create(URLSearchParamsInit()); |
| 102 for (const FormData::Entry* entry : formData->entries()) { | 103 for (const FormData::Entry* entry : formData->entries()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 const String& name, | 122 const String& name, |
| 122 const KURL& icon) | 123 const KURL& icon) |
| 123 : SiteBoundCredential( | 124 : SiteBoundCredential( |
| 124 PlatformPasswordCredential::create(id, password, name, icon)), | 125 PlatformPasswordCredential::create(id, password, name, icon)), |
| 125 m_idName("username"), | 126 m_idName("username"), |
| 126 m_passwordName("password") {} | 127 m_passwordName("password") {} |
| 127 | 128 |
| 128 PassRefPtr<EncodedFormData> PasswordCredential::encodeFormData( | 129 PassRefPtr<EncodedFormData> PasswordCredential::encodeFormData( |
| 129 String& contentType) const { | 130 String& contentType) const { |
| 130 if (m_additionalData.isURLSearchParams()) { | 131 if (m_additionalData.isURLSearchParams()) { |
| 131 // If |additionalData| is a 'URLSearchParams' object, build a urlencoded res
ponse. | 132 // If |additionalData| is a 'URLSearchParams' object, build a urlencoded |
| 133 // response. |
| 132 URLSearchParams* params = URLSearchParams::create(URLSearchParamsInit()); | 134 URLSearchParams* params = URLSearchParams::create(URLSearchParamsInit()); |
| 133 URLSearchParams* additionalData = m_additionalData.getAsURLSearchParams(); | 135 URLSearchParams* additionalData = m_additionalData.getAsURLSearchParams(); |
| 134 for (const auto& param : additionalData->params()) { | 136 for (const auto& param : additionalData->params()) { |
| 135 const String& name = param.first; | 137 const String& name = param.first; |
| 136 if (name != idName() && name != passwordName()) | 138 if (name != idName() && name != passwordName()) |
| 137 params->append(name, param.second); | 139 params->append(name, param.second); |
| 138 } | 140 } |
| 139 params->append(idName(), id()); | 141 params->append(idName(), id()); |
| 140 params->append(passwordName(), password()); | 142 params->append(passwordName(), password()); |
| 141 | 143 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get()) | 175 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get()) |
| 174 ->password(); | 176 ->password(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 DEFINE_TRACE(PasswordCredential) { | 179 DEFINE_TRACE(PasswordCredential) { |
| 178 SiteBoundCredential::trace(visitor); | 180 SiteBoundCredential::trace(visitor); |
| 179 visitor->trace(m_additionalData); | 181 visitor->trace(m_additionalData); |
| 180 } | 182 } |
| 181 | 183 |
| 182 } // namespace blink | 184 } // namespace blink |
| OLD | NEW |