Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1031)

Unified Diff: third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp

Issue 1446963002: CREDENTIAL: Teach Fetch to handle PasswordCredential objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@opaque
Patch Set: webexposed Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698