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)
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.
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.
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.
26 #include "HTMLKeygenElement.h"
28 #include "Attribute.h"
30 #include "FormDataList.h"
31 #include "HTMLNames.h"
32 #include "HTMLSelectElement.h"
33 #include "HTMLOptionElement.h"
34 #include "SSLKeyGenerator.h"
35 #include "ShadowRoot.h"
37 #include <wtf/StdLibExtras.h>
39 using namespace WebCore;
43 using namespace HTMLNames;
45 class KeygenSelectElement : public HTMLSelectElement {
47 static PassRefPtr<KeygenSelectElement> create(Document* document)
49 return adoptRef(new KeygenSelectElement(document));
52 virtual const AtomicString& shadowPseudoId() const
54 DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-keygen-select"));
59 KeygenSelectElement(Document* document)
60 : HTMLSelectElement(selectTag, document, 0)
65 virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren()
67 return create(document());
71 inline HTMLKeygenElement::HTMLKeygenElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
72 : HTMLFormControlElementWithState(tagName, document, form)
74 ASSERT(hasTagName(keygenTag));
76 // Create a select element with one option element for each key size.
78 getSupportedKeySizes(keys);
80 RefPtr<HTMLSelectElement> select = KeygenSelectElement::create(document);
82 for (size_t i = 0; i < keys.size(); ++i) {
83 RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document, this->form());
84 select->appendChild(option, ec);
85 option->appendChild(Text::create(document, keys[i]), ec);
88 ensureShadowRoot()->appendChild(select, ec);
91 PassRefPtr<HTMLKeygenElement> HTMLKeygenElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
93 return adoptRef(new HTMLKeygenElement(tagName, document, form));
96 void HTMLKeygenElement::parseMappedAttribute(Attribute* attr)
98 // Reflect disabled attribute on the shadow select element
99 if (attr->name() == disabledAttr)
100 shadowSelect()->setAttribute(attr->name(), attr->value());
102 HTMLFormControlElement::parseMappedAttribute(attr);
105 bool HTMLKeygenElement::appendFormData(FormDataList& encoded_values, bool)
107 // Only RSA is supported at this time.
108 const AtomicString& keyType = fastGetAttribute(keytypeAttr);
109 if (!keyType.isNull() && !equalIgnoringCase(keyType, "rsa"))
111 String value = signedPublicKeyAndChallengeString(shadowSelect()->selectedIndex(), fastGetAttribute(challengeAttr), document()->baseURL());
114 encoded_values.appendData(name(), value.utf8());
118 const AtomicString& HTMLKeygenElement::formControlType() const
120 DEFINE_STATIC_LOCAL(const AtomicString, keygen, ("keygen"));
124 void HTMLKeygenElement::reset()
126 static_cast<HTMLFormControlElement*>(shadowSelect())->reset();
129 HTMLSelectElement* HTMLKeygenElement::shadowSelect() const
131 ShadowRoot* shadow = shadowRoot();
133 return shadow ? toHTMLSelectElement(shadow->firstChild()) : 0;