18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (C) 1999 Antti Koivisto (koivisto@kde.org) 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (C) 2001 Dirk Mueller (mueller@kde.org) 55af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is free software; you can redistribute it and/or 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modify it under the terms of the GNU Library General Public 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License as published by the Free Software Foundation; either 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * version 2 of the License, or (at your option) any later version. 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is distributed in the hope that it will be useful, 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Library General Public License for more details. 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * You should have received a copy of the GNU Library General Public License 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * along with this library; see the file COPYING.LIB. If not, write to 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Boston, MA 02110-1301, USA. 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */ 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h" 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "HTMLKeygenElement.h" 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 28e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block#include "Attribute.h" 298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "Document.h" 308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "FormDataList.h" 318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "HTMLNames.h" 322fc2651226baac27029e38c9d6ef883fa32084dbSteve Block#include "HTMLSelectElement.h" 338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "HTMLOptionElement.h" 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SSLKeyGenerator.h" 352daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch#include "ShadowRoot.h" 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "Text.h" 37635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <wtf/StdLibExtras.h> 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace WebCore; 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore { 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace HTMLNames; 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 452fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockclass KeygenSelectElement : public HTMLSelectElement { 462fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockpublic: 472fc2651226baac27029e38c9d6ef883fa32084dbSteve Block static PassRefPtr<KeygenSelectElement> create(Document* document) 482fc2651226baac27029e38c9d6ef883fa32084dbSteve Block { 492fc2651226baac27029e38c9d6ef883fa32084dbSteve Block return adoptRef(new KeygenSelectElement(document)); 502fc2651226baac27029e38c9d6ef883fa32084dbSteve Block } 512fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 522fc2651226baac27029e38c9d6ef883fa32084dbSteve Block virtual const AtomicString& shadowPseudoId() const 532fc2651226baac27029e38c9d6ef883fa32084dbSteve Block { 542fc2651226baac27029e38c9d6ef883fa32084dbSteve Block DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-keygen-select")); 552fc2651226baac27029e38c9d6ef883fa32084dbSteve Block return pseudoId; 562fc2651226baac27029e38c9d6ef883fa32084dbSteve Block } 572fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 582fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockprotected: 592fc2651226baac27029e38c9d6ef883fa32084dbSteve Block KeygenSelectElement(Document* document) 602fc2651226baac27029e38c9d6ef883fa32084dbSteve Block : HTMLSelectElement(selectTag, document, 0) 612fc2651226baac27029e38c9d6ef883fa32084dbSteve Block { 622fc2651226baac27029e38c9d6ef883fa32084dbSteve Block } 632fc2651226baac27029e38c9d6ef883fa32084dbSteve Block}; 642fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 655af96e2c7b73ebc627c6894727826a7576d31758Leon Clarkeinline HTMLKeygenElement::HTMLKeygenElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) 662fc2651226baac27029e38c9d6ef883fa32084dbSteve Block : HTMLFormControlElementWithState(tagName, document, form) 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 68635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project ASSERT(hasTagName(keygenTag)); 695af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 702fc2651226baac27029e38c9d6ef883fa32084dbSteve Block // Create a select element with one option element for each key size. 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Vector<String> keys; 728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project getSupportedKeySizes(keys); 732daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch 742daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch RefPtr<HTMLSelectElement> select = KeygenSelectElement::create(document); 752daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch ExceptionCode ec = 0; 765af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke for (size_t i = 0; i < keys.size(); ++i) { 775af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document, this->form()); 782daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch select->appendChild(option, ec); 792daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch option->appendChild(Text::create(document, keys[i]), ec); 808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 812daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch 822daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch ensureShadowRoot()->appendChild(select, ec); 838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 855af96e2c7b73ebc627c6894727826a7576d31758Leon ClarkePassRefPtr<HTMLKeygenElement> HTMLKeygenElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) 865af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{ 8706ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen return adoptRef(new HTMLKeygenElement(tagName, document, form)); 885af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke} 895af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 90e78cbe89e6f337f2f1fe40315be88f742b547151Steve Blockvoid HTMLKeygenElement::parseMappedAttribute(Attribute* attr) 918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 922fc2651226baac27029e38c9d6ef883fa32084dbSteve Block // Reflect disabled attribute on the shadow select element 932fc2651226baac27029e38c9d6ef883fa32084dbSteve Block if (attr->name() == disabledAttr) 942daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch shadowSelect()->setAttribute(attr->name(), attr->value()); 952fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (attr->name() == challengeAttr) 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_challenge = attr->value(); 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else if (attr->name() == keytypeAttr) 998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_keyType = attr->value(); 1002fc2651226baac27029e38c9d6ef883fa32084dbSteve Block else 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project HTMLFormControlElement::parseMappedAttribute(attr); 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectbool HTMLKeygenElement::appendFormData(FormDataList& encoded_values, bool) 1058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Only RSA is supported at this time. 1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!m_keyType.isNull() && !equalIgnoringCase(m_keyType, "rsa")) 1088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return false; 1092daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch String value = signedPublicKeyAndChallengeString(shadowSelect()->selectedIndex(), m_challenge, document()->baseURL()); 1108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (value.isNull()) 1118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return false; 1128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project encoded_values.appendData(name(), value.utf8()); 1138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return true; 1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1162fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockconst AtomicString& HTMLKeygenElement::formControlType() const 1172fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{ 1182fc2651226baac27029e38c9d6ef883fa32084dbSteve Block DEFINE_STATIC_LOCAL(const AtomicString, keygen, ("keygen")); 1192fc2651226baac27029e38c9d6ef883fa32084dbSteve Block return keygen; 1202fc2651226baac27029e38c9d6ef883fa32084dbSteve Block} 1212fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 1222fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockvoid HTMLKeygenElement::reset() 1232fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{ 1242daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch static_cast<HTMLFormControlElement*>(shadowSelect())->reset(); 1252fc2651226baac27029e38c9d6ef883fa32084dbSteve Block} 1262fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 1272daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochHTMLSelectElement* HTMLKeygenElement::shadowSelect() const 1282fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{ 1292daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch Node* shadow = shadowRoot(); 1302daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch ASSERT(shadow); 1312daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch return shadow ? static_cast<HTMLSelectElement*>(shadow->firstChild()) : 0; 1322fc2651226baac27029e38c9d6ef883fa32084dbSteve Block} 1332fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 1348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace 135