|
1 /* |
|
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
|
5 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. |
|
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
|
7 * |
|
8 * This library is free software; you can redistribute it and/or |
|
9 * modify it under the terms of the GNU Library General Public |
|
10 * License as published by the Free Software Foundation; either |
|
11 * version 2 of the License, or (at your option) any later version. |
|
12 * |
|
13 * This library is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * Library General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU Library General Public License |
|
19 * along with this library; see the file COPYING.LIB. If not, write to |
|
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
21 * Boston, MA 02110-1301, USA. |
|
22 * |
|
23 */ |
|
24 |
|
25 #include "config.h" |
|
26 #include "HTMLKeygenElement.h" |
|
27 |
|
28 #include "Attribute.h" |
|
29 #include "Document.h" |
|
30 #include "FormDataList.h" |
|
31 #include "HTMLNames.h" |
|
32 #include "HTMLOptionElement.h" |
|
33 #include "SSLKeyGenerator.h" |
|
34 #include "Text.h" |
|
35 #include <wtf/StdLibExtras.h> |
|
36 |
|
37 using namespace WebCore; |
|
38 |
|
39 namespace WebCore { |
|
40 |
|
41 using namespace HTMLNames; |
|
42 |
|
43 inline HTMLKeygenElement::HTMLKeygenElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) |
|
44 : HTMLSelectElement(tagName, document, form) |
|
45 { |
|
46 ASSERT(hasTagName(keygenTag)); |
|
47 |
|
48 // Add one option element for each key size. |
|
49 Vector<String> keys; |
|
50 getSupportedKeySizes(keys); |
|
51 for (size_t i = 0; i < keys.size(); ++i) { |
|
52 RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document, this->form()); |
|
53 legacyParserAddChild(option); |
|
54 option->legacyParserAddChild(Text::create(document, keys[i])); |
|
55 } |
|
56 } |
|
57 |
|
58 PassRefPtr<HTMLKeygenElement> HTMLKeygenElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) |
|
59 { |
|
60 return adoptRef(new HTMLKeygenElement(tagName, document, form)); |
|
61 } |
|
62 |
|
63 const AtomicString& HTMLKeygenElement::formControlType() const |
|
64 { |
|
65 DEFINE_STATIC_LOCAL(const AtomicString, keygen, ("keygen")); |
|
66 return keygen; |
|
67 } |
|
68 |
|
69 void HTMLKeygenElement::parseMappedAttribute(Attribute* attr) |
|
70 { |
|
71 if (attr->name() == challengeAttr) |
|
72 m_challenge = attr->value(); |
|
73 else if (attr->name() == keytypeAttr) |
|
74 m_keyType = attr->value(); |
|
75 else { |
|
76 // Skip HTMLSelectElement parsing. |
|
77 HTMLFormControlElement::parseMappedAttribute(attr); |
|
78 } |
|
79 } |
|
80 |
|
81 bool HTMLKeygenElement::appendFormData(FormDataList& encoded_values, bool) |
|
82 { |
|
83 // Only RSA is supported at this time. |
|
84 if (!m_keyType.isNull() && !equalIgnoringCase(m_keyType, "rsa")) |
|
85 return false; |
|
86 String value = signedPublicKeyAndChallengeString(selectedIndex(), m_challenge, document()->baseURL()); |
|
87 if (value.isNull()) |
|
88 return false; |
|
89 encoded_values.appendData(name(), value.utf8()); |
|
90 return true; |
|
91 } |
|
92 |
|
93 } // namespace |