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

Side by Side 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 unified diff | Download patch
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "modules/credentialmanager/PasswordCredential.h" 6 #include "modules/credentialmanager/PasswordCredential.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
11 #include "core/dom/URLSearchParams.h"
11 #include "core/html/FormData.h" 12 #include "core/html/FormData.h"
12 #include "modules/credentialmanager/FormDataOptions.h" 13 #include "modules/credentialmanager/FormDataOptions.h"
13 #include "modules/credentialmanager/PasswordCredentialData.h" 14 #include "modules/credentialmanager/PasswordCredentialData.h"
14 #include "platform/credentialmanager/PlatformPasswordCredential.h" 15 #include "platform/credentialmanager/PlatformPasswordCredential.h"
15 #include "platform/weborigin/SecurityOrigin.h" 16 #include "platform/weborigin/SecurityOrigin.h"
16 #include "public/platform/WebCredential.h" 17 #include "public/platform/WebCredential.h"
17 #include "public/platform/WebPasswordCredential.h" 18 #include "public/platform/WebPasswordCredential.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 PasswordCredential* PasswordCredential::create(WebPasswordCredential* webPasswor dCredential) 22 PasswordCredential* PasswordCredential::create(WebPasswordCredential* webPasswor dCredential)
22 { 23 {
23 return new PasswordCredential(webPasswordCredential); 24 return new PasswordCredential(webPasswordCredential);
24 } 25 }
25 26
26 PasswordCredential* PasswordCredential::create(const PasswordCredentialData& dat a, ExceptionState& exceptionState) 27 PasswordCredential* PasswordCredential::create(const PasswordCredentialData& dat a, ExceptionState& exceptionState)
27 { 28 {
28 KURL iconURL = parseStringAsURL(data.iconURL(), exceptionState); 29 KURL iconURL = parseStringAsURL(data.iconURL(), exceptionState);
29 if (exceptionState.hadException()) 30 if (exceptionState.hadException())
30 return nullptr; 31 return nullptr;
31 return new PasswordCredential(data.id(), data.password(), data.name(), iconU RL); 32 return new PasswordCredential(data.id(), data.password(), data.name(), iconU RL);
32 } 33 }
33 34
34 PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredent ial) 35 PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredent ial)
35 : Credential(webPasswordCredential->platformCredential()) 36 : Credential(webPasswordCredential->platformCredential())
37 , m_idName("username")
38 , m_passwordName("password")
36 { 39 {
37 } 40 }
38 41
39 PasswordCredential::PasswordCredential(const String& id, const String& password, const String& name, const KURL& icon) 42 PasswordCredential::PasswordCredential(const String& id, const String& password, const String& name, const KURL& icon)
40 : Credential(PlatformPasswordCredential::create(id, password, name, icon)) 43 : Credential(PlatformPasswordCredential::create(id, password, name, icon))
44 , m_idName("username")
45 , m_passwordName("password")
41 { 46 {
42 } 47 }
43 48
44 FormData* PasswordCredential::toFormData(ScriptState* scriptState, const FormDat aOptions& options) 49 PassRefPtr<EncodedFormData> PasswordCredential::encodeFormData() const
45 { 50 {
46 FormData* fd = FormData::create(); 51 if (m_additionalData.isURLSearchParams()) {
52 // If |additionalData| is a 'URLSearchParams' object, build a urlencoded response.
53 URLSearchParams* params = URLSearchParams::create(URLSearchParamsInit()) ;
54 URLSearchParams* additionalData = m_additionalData.getAsURLSearchParams( );
55 for (const auto& param : additionalData->params())
56 params->append(param.first, param.second);
57 params->append(idName(), id());
58 params->append(passwordName(), password());
47 59
48 String errorMessage; 60 return params->encodeFormData();
49 if (!scriptState->executionContext()->isSecureContext(errorMessage)) 61 }
50 return fd;
51 62
52 fd->append(options.idName(), id()); 63 // Otherwise, we'll build a multipart response.
53 fd->append(options.passwordName(), password()); 64 FormData* formData = FormData::create(nullptr);
54 return fd; 65 if (m_additionalData.isFormData()) {
66 FormData* additionalData = m_additionalData.getAsFormData();
67 for (const FormData::Entry* entry : additionalData->entries()) {
68 if (entry->blob())
69 formData->append(formData->decode(entry->name()), entry->blob(), entry->filename());
70 else
71 formData->append(formData->decode(entry->name()), formData->deco de(entry->value()));
72 }
73 }
74 formData->append(idName(), id());
75 formData->append(passwordName(), password());
76
77 return formData->encodeMultiPartFormData();
55 } 78 }
56 79
57 const String& PasswordCredential::password() const 80 const String& PasswordCredential::password() const
58 { 81 {
59 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get())- >password(); 82 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get())- >password();
60 } 83 }
61 84
62 DEFINE_TRACE(PasswordCredential) 85 DEFINE_TRACE(PasswordCredential)
63 { 86 {
64 Credential::trace(visitor); 87 Credential::trace(visitor);
88 visitor->trace(m_additionalData);
65 } 89 }
66 90
67 } // namespace blink 91 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698