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

Side by Side Diff: third_party/WebKit/Source/modules/credentialmanager/PasswordCredential.cpp

Issue 1828213002: CREDENTIAL: Implement the 'PasswordCredential(HTMLFormElement)' constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months 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 "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/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
10 #include "core/dom/URLSearchParams.h" 11 #include "core/dom/URLSearchParams.h"
12 #include "core/html/FormAssociatedElement.h"
11 #include "core/html/FormData.h" 13 #include "core/html/FormData.h"
14 #include "core/html/HTMLFormElement.h"
12 #include "modules/credentialmanager/FormDataOptions.h" 15 #include "modules/credentialmanager/FormDataOptions.h"
13 #include "modules/credentialmanager/PasswordCredentialData.h" 16 #include "modules/credentialmanager/PasswordCredentialData.h"
14 #include "platform/credentialmanager/PlatformPasswordCredential.h" 17 #include "platform/credentialmanager/PlatformPasswordCredential.h"
15 #include "platform/weborigin/SecurityOrigin.h" 18 #include "platform/weborigin/SecurityOrigin.h"
16 #include "public/platform/WebCredential.h" 19 #include "public/platform/WebCredential.h"
17 #include "public/platform/WebPasswordCredential.h" 20 #include "public/platform/WebPasswordCredential.h"
18 21
19 namespace blink { 22 namespace blink {
20 23
21 PasswordCredential* PasswordCredential::create(WebPasswordCredential* webPasswor dCredential) 24 PasswordCredential* PasswordCredential::create(WebPasswordCredential* webPasswor dCredential)
(...skipping 12 matching lines...) Expand all
34 return nullptr; 37 return nullptr;
35 } 38 }
36 39
37 KURL iconURL = parseStringAsURL(data.iconURL(), exceptionState); 40 KURL iconURL = parseStringAsURL(data.iconURL(), exceptionState);
38 if (exceptionState.hadException()) 41 if (exceptionState.hadException())
39 return nullptr; 42 return nullptr;
40 43
41 return new PasswordCredential(data.id(), data.password(), data.name(), iconU RL); 44 return new PasswordCredential(data.id(), data.password(), data.name(), iconU RL);
42 } 45 }
43 46
47 PasswordCredential* PasswordCredential::create(HTMLFormElement* form, ExceptionS tate& exceptionState)
48 {
49 // Extract data from the form, then use the extracted |formData| object's
50 // value to populate |data|.
51 FormData* formData = FormData::create(form);
52 PasswordCredentialData data;
53
54 AtomicString idName;
55 AtomicString passwordName;
56 for (FormAssociatedElement* element : form->associatedElements()) {
philipj_slow 2016/03/29 05:45:54 The spec wants the "submittable elements" which is
Mike West 2016/03/31 08:31:41 Done.
57 FileOrUSVString result;
58 formData->get(element->name(), result);
59 if (!result.isUSVString())
60 continue;
61
62 AtomicString autocomplete = toHTMLElement(element)->fastGetAttribute(HTM LNames::autocompleteAttr);
63 if (equalIgnoringCase(autocomplete, "photo"))
64 data.setIconURL(result.getAsUSVString());
65 if (equalIgnoringCase(autocomplete, "name") || equalIgnoringCase(autocom plete, "nickname"))
philipj_slow 2016/03/29 05:45:54 Maybe more else all the way down? Unless there's a
Mike West 2016/03/31 08:31:41 Done and done.
66 data.setName(result.getAsUSVString());
67 if (equalIgnoringCase(autocomplete, "current-password") || equalIgnoring Case(autocomplete, "new-password")) {
68 data.setPassword(result.getAsUSVString());
69 passwordName = element->name();
70 }
71 if (equalIgnoringCase(autocomplete, "username")) {
72 data.setId(result.getAsUSVString());
73 idName = element->name();
74 }
75 }
76
77 // Create a PasswordCredential using the data gathered above.
78 PasswordCredential* credential = PasswordCredential::create(data, exceptionS tate);
79 if (exceptionState.hadException())
80 return nullptr;
81 ASSERT(credential);
82
83 // After creating the Credential, populate its 'additionalData', 'idName', a nd 'passwordName' attributes.
84 FormDataOrURLSearchParams additionalData;
85 additionalData.setFormData(formData);
86 credential->setAdditionalData(additionalData);
87 credential->setIdName(idName);
88 credential->setPasswordName(passwordName);
89 return credential;
90 }
91
44 PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredent ial) 92 PasswordCredential::PasswordCredential(WebPasswordCredential* webPasswordCredent ial)
45 : Credential(webPasswordCredential->getPlatformCredential()) 93 : Credential(webPasswordCredential->getPlatformCredential())
46 , m_idName("username") 94 , m_idName("username")
47 , m_passwordName("password") 95 , m_passwordName("password")
48 { 96 {
49 } 97 }
50 98
51 PasswordCredential::PasswordCredential(const String& id, const String& password, const String& name, const KURL& icon) 99 PasswordCredential::PasswordCredential(const String& id, const String& password, const String& name, const KURL& icon)
52 : Credential(PlatformPasswordCredential::create(id, password, name, icon)) 100 : Credential(PlatformPasswordCredential::create(id, password, name, icon))
53 , m_idName("username") 101 , m_idName("username")
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get())- >password(); 150 return static_cast<PlatformPasswordCredential*>(m_platformCredential.get())- >password();
103 } 151 }
104 152
105 DEFINE_TRACE(PasswordCredential) 153 DEFINE_TRACE(PasswordCredential)
106 { 154 {
107 Credential::trace(visitor); 155 Credential::trace(visitor);
108 visitor->trace(m_additionalData); 156 visitor->trace(m_additionalData);
109 } 157 }
110 158
111 } // namespace blink 159 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698