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 4042182b3204aaa6c5996dcfdc7291a92bf65edf..41bf1f2fb7f1133711728cc39af00308dc2373a4 100644 |
--- a/third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp |
+++ b/third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp |
@@ -8,6 +8,7 @@ |
#include "bindings/core/v8/Dictionary.h" |
#include "bindings/core/v8/ExceptionState.h" |
#include "core/dom/ExecutionContext.h" |
+#include "core/dom/URLSearchParams.h" |
#include "core/html/FormData.h" |
#include "modules/credentialmanager/FormDataOptions.h" |
#include "modules/credentialmanager/PasswordCredentialData.h" |
@@ -33,25 +34,47 @@ PasswordCredential* PasswordCredential::create(const PasswordCredentialData& dat |
PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredential) |
: Credential(webPasswordCredential->platformCredential()) |
+ , m_idName("username") |
+ , m_passwordName("password") |
{ |
} |
PasswordCredential::PasswordCredential(const String& id, const String& password, const String& name, const KURL& icon) |
: Credential(PlatformPasswordCredential::create(id, password, name, icon)) |
+ , m_idName("username") |
+ , m_passwordName("password") |
{ |
} |
-FormData* PasswordCredential::toFormData(ScriptState* scriptState, const FormDataOptions& options) |
+PassRefPtr<EncodedFormData> PasswordCredential::encodeFormData() const |
{ |
- FormData* fd = FormData::create(); |
+ if (m_additionalData.isURLSearchParams()) { |
+ // If |additionalData| is a 'URLSearchParams' object, build a urlencoded response. |
+ URLSearchParams* params = URLSearchParams::create(URLSearchParamsInit()); |
+ URLSearchParams* additionalData = m_additionalData.getAsURLSearchParams(); |
+ for (const auto& param : additionalData->params()) |
+ params->append(param.first, param.second); |
+ params->append(idName(), id()); |
+ params->append(passwordName(), password()); |
- String errorMessage; |
- if (!scriptState->executionContext()->isSecureContext(errorMessage)) |
- return fd; |
+ return params->encodeFormData(); |
+ } |
- fd->append(options.idName(), id()); |
- fd->append(options.passwordName(), password()); |
- return fd; |
+ // Otherwise, we'll build a multipart response. |
+ FormData* formData = FormData::create(nullptr); |
+ if (m_additionalData.isFormData()) { |
+ FormData* additionalData = m_additionalData.getAsFormData(); |
+ for (const FormData::Entry* entry : additionalData->entries()) { |
+ if (entry->blob()) |
+ formData->append(formData->decode(entry->name()), entry->blob(), entry->filename()); |
+ else |
+ formData->append(formData->decode(entry->name()), formData->decode(entry->value())); |
+ } |
+ } |
+ formData->append(idName(), id()); |
+ formData->append(passwordName(), password()); |
+ |
+ return formData->encodeMultiPartFormData(); |
} |
const String& PasswordCredential::password() const |
@@ -62,6 +85,7 @@ const String& PasswordCredential::password() const |
DEFINE_TRACE(PasswordCredential) |
{ |
Credential::trace(visitor); |
+ visitor->trace(m_additionalData); |
} |
} // namespace blink |