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/text/PlatformLocale.h"
37 #include "public/platform/Platform.h"
38 #include "public/platform/WebLocalizedString.h"
39 #include "wtf/StdLibExtras.h"
41 using namespace blink;
45 using namespace HTMLNames;
47 HTMLKeygenElement::HTMLKeygenElement(Document& document, HTMLFormElement* form)
48 : HTMLFormControlElementWithState(keygenTag, document, form)
52 PassRefPtrWillBeRawPtr<HTMLKeygenElement> HTMLKeygenElement::create(Document& document, HTMLFormElement* form)
54 RefPtrWillBeRawPtr<HTMLKeygenElement> keygen = adoptRefWillBeNoop(new HTMLKeygenElement(document, form));
55 keygen->ensureUserAgentShadowRoot();
56 return keygen.release();
59 void HTMLKeygenElement::didAddUserAgentShadowRoot(ShadowRoot& root)
61 DEFINE_STATIC_LOCAL(AtomicString, keygenSelectPseudoId, ("-webkit-keygen-select", AtomicString::ConstructFromLiteral));
64 keys.reserveCapacity(2);
65 keys.append(locale().queryString(WebLocalizedString::KeygenMenuHighGradeKeySize));
66 keys.append(locale().queryString(WebLocalizedString::KeygenMenuMediumGradeKeySize));
68 // Create a select element with one option element for each key size.
69 RefPtrWillBeRawPtr<HTMLSelectElement> select = HTMLSelectElement::create(document());
70 select->setShadowPseudoId(keygenSelectPseudoId);
71 for (const String& key : keys) {
72 RefPtrWillBeRawPtr<HTMLOptionElement> option = HTMLOptionElement::create(document());
73 option->appendChild(Text::create(document(), key));
74 select->appendChild(option);
77 root.appendChild(select);
80 void HTMLKeygenElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
82 // Reflect disabled attribute on the shadow select element
83 if (name == disabledAttr)
84 shadowSelect()->setAttribute(name, value);
86 HTMLFormControlElement::parseAttribute(name, value);
89 bool HTMLKeygenElement::appendFormData(FormDataList& encoding, bool)
91 // Only RSA is supported at this time.
92 const AtomicString& keyType = fastGetAttribute(keytypeAttr);
93 if (!keyType.isNull() && !equalIgnoringCase(keyType, "rsa"))
95 String value = Platform::current()->signedPublicKeyAndChallengeString(shadowSelect()->selectedIndex(), fastGetAttribute(challengeAttr), document().baseURL());
98 encoding.appendData(name(), value.utf8());
102 const AtomicString& HTMLKeygenElement::formControlType() const
104 DEFINE_STATIC_LOCAL(const AtomicString, keygen, ("keygen", AtomicString::ConstructFromLiteral));
108 void HTMLKeygenElement::resetImpl()
110 shadowSelect()->reset();
113 HTMLSelectElement* HTMLKeygenElement::shadowSelect() const
115 ShadowRoot* root = userAgentShadowRoot();
116 return root ? toHTMLSelectElement(root->firstChild()) : 0;
119 bool HTMLKeygenElement::isInteractiveContent() const
124 bool HTMLKeygenElement::supportsAutofocus() const