HTMLKeygenElement.cpp [plain text]
#include "config.h"
#include "HTMLKeygenElement.h"
#include "Attribute.h"
#include "Document.h"
#include "FormDataList.h"
#include "HTMLNames.h"
#include "HTMLSelectElement.h"
#include "HTMLOptionElement.h"
#include "SSLKeyGenerator.h"
#include "ShadowRoot.h"
#include "ShadowTree.h"
#include "Text.h"
#include <wtf/StdLibExtras.h>
using namespace WebCore;
namespace WebCore {
using namespace HTMLNames;
class KeygenSelectElement : public HTMLSelectElement {
public:
static PassRefPtr<KeygenSelectElement> create(Document* document)
{
return adoptRef(new KeygenSelectElement(document));
}
virtual const AtomicString& shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-keygen-select"));
return pseudoId;
}
protected:
KeygenSelectElement(Document* document)
: HTMLSelectElement(selectTag, document, 0)
{
}
private:
virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren()
{
return create(document());
}
};
inline HTMLKeygenElement::HTMLKeygenElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
: HTMLFormControlElementWithState(tagName, document, form)
{
ASSERT(hasTagName(keygenTag));
Vector<String> keys;
getSupportedKeySizes(keys);
RefPtr<HTMLSelectElement> select = KeygenSelectElement::create(document);
ExceptionCode ec = 0;
for (size_t i = 0; i < keys.size(); ++i) {
RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document);
select->appendChild(option, ec);
option->appendChild(Text::create(document, keys[i]), ec);
}
ASSERT(!hasShadowRoot());
RefPtr<ShadowRoot> root = ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot);
root->appendChild(select, ec);
}
PassRefPtr<HTMLKeygenElement> HTMLKeygenElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
{
return adoptRef(new HTMLKeygenElement(tagName, document, form));
}
void HTMLKeygenElement::parseAttribute(Attribute* attr)
{
if (attr->name() == disabledAttr)
shadowSelect()->setAttribute(attr->name(), attr->value());
HTMLFormControlElement::parseAttribute(attr);
}
bool HTMLKeygenElement::appendFormData(FormDataList& encoded_values, bool)
{
const AtomicString& keyType = fastGetAttribute(keytypeAttr);
if (!keyType.isNull() && !equalIgnoringCase(keyType, "rsa"))
return false;
String value = signedPublicKeyAndChallengeString(shadowSelect()->selectedIndex(), fastGetAttribute(challengeAttr), document()->baseURL());
if (value.isNull())
return false;
encoded_values.appendData(name(), value.utf8());
return true;
}
const AtomicString& HTMLKeygenElement::formControlType() const
{
DEFINE_STATIC_LOCAL(const AtomicString, keygen, ("keygen"));
return keygen;
}
void HTMLKeygenElement::reset()
{
static_cast<HTMLFormControlElement*>(shadowSelect())->reset();
}
HTMLSelectElement* HTMLKeygenElement::shadowSelect() const
{
ASSERT(hasShadowRoot());
ShadowRoot* shadow = shadowTree()->oldestShadowRoot();
return shadow ? toHTMLSelectElement(shadow->firstChild()) : 0;
}
}