Exemplo n.º 1
0
JSValue jsHTMLFormElementAction(ExecState* exec, const Identifier&, const PropertySlot& slot)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slot.slotBase()));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    return jsString(exec, imp->action());
}
JSValue jsHTMLFormElementAction(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->action());
    return result;
}
WebSearchableFormData::WebSearchableFormData(const WebFormElement& form, const WebInputElement& selectedInputElement)
{
    HTMLFormElement* formElement = static_cast<HTMLFormElement*>(form);
    HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(selectedInputElement);

    // Only consider forms that GET data.
    // Allow HTTPS only when an input element is provided.
    if (equalIgnoringCase(formElement->getAttribute(methodAttr), "post")
        || (!isHTTPFormSubmit(*formElement) && !inputElement))
        return;

    WTF::TextEncoding encoding;
    getFormEncoding(*formElement, &encoding);
    if (!encoding.isValid()) {
        // Need a valid encoding to encode the form elements.
        // If the encoding isn't found webkit ends up replacing the params with
        // empty strings. So, we don't try to do anything here.
        return;
    }

    // Look for a suitable search text field in the form when a
    // selectedInputElement is not provided.
    if (!inputElement) {
        inputElement = findSuitableSearchInputElement(*formElement);

        // Return if no suitable text element has been found.
        if (!inputElement)
            return;
    }

    HTMLFormControlElement* firstSubmitButton = buttonToActivate(*formElement);
    if (firstSubmitButton) {
        // The form does not have an active submit button, make the first button
        // active. We need to do this, otherwise the URL will not contain the
        // name of the submit button.
        firstSubmitButton->setActivatedSubmit(true);
    }

    Vector<char> encodedString;
    bool isValidSearchString = buildSearchString(*formElement, &encodedString, encoding, inputElement);

    if (firstSubmitButton)
        firstSubmitButton->setActivatedSubmit(false);

    // Return if the search string is not valid.
    if (!isValidSearchString)
        return;

    String action(formElement->action());
    KURL url(formElement->document().completeURL(action.isNull() ? "" : action));
    RefPtr<EncodedFormData> formData = EncodedFormData::create(encodedString);
    url.setQuery(formData->flattenToString());
    m_url = url;
    m_encoding = String(encoding.name());
}
Exemplo n.º 4
0
JSValue* JSHTMLFormElement::getValueProperty(ExecState* exec, int token) const
{
    switch (token) {
    case ElementsAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return toJS(exec, WTF::getPtr(imp->elements()));
    }
    case LengthAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsNumber(imp->length());
    }
    case NameAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsString(imp->name());
    }
    case AcceptCharsetAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsString(imp->acceptCharset());
    }
    case ActionAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsString(imp->action());
    }
    case EncodingAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsString(imp->encoding());
    }
    case EnctypeAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsString(imp->enctype());
    }
    case MethodAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsString(imp->method());
    }
    case TargetAttrNum: {
        HTMLFormElement* imp = static_cast<HTMLFormElement*>(impl());

        return jsString(imp->target());
    }
    case ConstructorAttrNum:
        return getConstructor(exec);
    }
    return 0;
}