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 "core/html/HTMLKeygenElement.h"
28 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
29 #include "core/HTMLNames.h"
30 #include "core/dom/Document.h"
31 #include "core/dom/Text.h"
32 #include "core/dom/shadow/ShadowRoot.h"
33 #include "core/html/FormDataList.h"
34 #include "core/html/HTMLOptionElement.h"
35 #include "core/html/HTMLSelectElement.h"
36 #include "platform/SSLKeyGenerator.h"
37 #include "wtf/StdLibExtras.h"
39 using namespace blink;
43 using namespace HTMLNames;
45 HTMLKeygenElement::HTMLKeygenElement(Document& document, HTMLFormElement* form)
46 : HTMLFormControlElementWithState(keygenTag, document, form)
48 ScriptWrappable::init(this);
51 PassRefPtrWillBeRawPtr<HTMLKeygenElement> HTMLKeygenElement::create(Document& document, HTMLFormElement* form)
53 RefPtrWillBeRawPtr<HTMLKeygenElement> keygen = adoptRefWillBeNoop(new HTMLKeygenElement(document, form));
54 keygen->ensureUserAgentShadowRoot();
55 return keygen.release();
58 void HTMLKeygenElement::didAddUserAgentShadowRoot(ShadowRoot& root)
60 DEFINE_STATIC_LOCAL(AtomicString, keygenSelectPseudoId, ("-webkit-keygen-select", AtomicString::ConstructFromLiteral));
63 getSupportedKeySizes(locale(), keys);
65 // Create a select element with one option element for each key size.
66 RefPtrWillBeRawPtr<HTMLSelectElement> select = HTMLSelectElement::create(document());
67 select->setShadowPseudoId(keygenSelectPseudoId);
68 for (size_t i = 0; i < keys.size(); ++i) {
69 RefPtrWillBeRawPtr<HTMLOptionElement> option = HTMLOptionElement::create(document());
70 option->appendChild(Text::create(document(), keys[i]));
71 select->appendChild(option);
74 root.appendChild(select);
77 void HTMLKeygenElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
79 // Reflect disabled attribute on the shadow select element
80 if (name == disabledAttr)
81 shadowSelect()->setAttribute(name, value);
83 HTMLFormControlElement::parseAttribute(name, value);
86 bool HTMLKeygenElement::appendFormData(FormDataList& encoding, bool)
88 // Only RSA is supported at this time.
89 const AtomicString& keyType = fastGetAttribute(keytypeAttr);
90 if (!keyType.isNull() && !equalIgnoringCase(keyType, "rsa"))
92 String value = signedPublicKeyAndChallengeString(shadowSelect()->selectedIndex(), fastGetAttribute(challengeAttr), document().baseURL());
95 encoding.appendData(name(), value.utf8());
99 const AtomicString& HTMLKeygenElement::formControlType() const
101 DEFINE_STATIC_LOCAL(const AtomicString, keygen, ("keygen", AtomicString::ConstructFromLiteral));
105 void HTMLKeygenElement::resetImpl()
107 shadowSelect()->reset();
110 HTMLSelectElement* HTMLKeygenElement::shadowSelect() const
112 ShadowRoot* root = userAgentShadowRoot();
113 return root ? toHTMLSelectElement(root->firstChild()) : 0;
116 bool HTMLKeygenElement::isInteractiveContent() const
121 bool HTMLKeygenElement::supportsAutofocus() const