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()); }