summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/renderer_host/test/test_render_view_host.cc1
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc1
-rw-r--r--chrome/browser/tab_contents/web_contents_unittest.cc1
-rw-r--r--chrome/common/render_messages.h5
-rw-r--r--chrome/renderer/render_view.cc1
-rw-r--r--webkit/api/public/WebViewClient.h2
-rw-r--r--webkit/glue/dom_operations_private.h5
-rw-r--r--webkit/glue/searchable_form_data.cc242
-rw-r--r--webkit/glue/searchable_form_data.h20
9 files changed, 85 insertions, 193 deletions
diff --git a/chrome/browser/renderer_host/test/test_render_view_host.cc b/chrome/browser/renderer_host/test/test_render_view_host.cc
index 9a65b2e..712d967 100644
--- a/chrome/browser/renderer_host/test/test_render_view_host.cc
+++ b/chrome/browser/renderer_host/test/test_render_view_host.cc
@@ -53,7 +53,6 @@ void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) {
params.redirects = std::vector<GURL>();
params.should_update_history = true;
params.searchable_form_url = GURL::EmptyGURL();
- params.searchable_form_element_name = std::wstring();
params.searchable_form_encoding = std::string();
params.password_form = PasswordForm();
params.security_info = std::string();
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
index de0ba2d..b664718 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
@@ -26,7 +26,6 @@ static void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params,
params->redirects = std::vector<GURL>();
params->should_update_history = false;
params->searchable_form_url = GURL::EmptyGURL();
- params->searchable_form_element_name = std::wstring();
params->searchable_form_encoding = std::string();
params->password_form = PasswordForm();
params->security_info = std::string();
diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc
index a1af7b1..c99a8a8 100644
--- a/chrome/browser/tab_contents/web_contents_unittest.cc
+++ b/chrome/browser/tab_contents/web_contents_unittest.cc
@@ -31,7 +31,6 @@ static void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params,
params->redirects = std::vector<GURL>();
params->should_update_history = false;
params->searchable_form_url = GURL::EmptyGURL();
- params->searchable_form_element_name = std::wstring();
params->searchable_form_encoding = std::string();
params->password_form = PasswordForm();
params->security_info = std::string();
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index ccaa4e0..0ef796c 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -137,7 +137,6 @@ struct ViewHostMsg_FrameNavigate_Params {
// See SearchableFormData for a description of these.
GURL searchable_form_url;
- std::wstring searchable_form_element_name;
std::string searchable_form_encoding;
// See password_form.h.
@@ -773,7 +772,6 @@ struct ParamTraits<ViewHostMsg_FrameNavigate_Params> {
WriteParam(m, p.redirects);
WriteParam(m, p.should_update_history);
WriteParam(m, p.searchable_form_url);
- WriteParam(m, p.searchable_form_element_name);
WriteParam(m, p.searchable_form_encoding);
WriteParam(m, p.password_form);
WriteParam(m, p.security_info);
@@ -792,7 +790,6 @@ struct ParamTraits<ViewHostMsg_FrameNavigate_Params> {
ReadParam(m, iter, &p->redirects) &&
ReadParam(m, iter, &p->should_update_history) &&
ReadParam(m, iter, &p->searchable_form_url) &&
- ReadParam(m, iter, &p->searchable_form_element_name) &&
ReadParam(m, iter, &p->searchable_form_encoding) &&
ReadParam(m, iter, &p->password_form) &&
ReadParam(m, iter, &p->security_info) &&
@@ -818,8 +815,6 @@ struct ParamTraits<ViewHostMsg_FrameNavigate_Params> {
l->append(L", ");
LogParam(p.searchable_form_url, l);
l->append(L", ");
- LogParam(p.searchable_form_element_name, l);
- l->append(L", ");
LogParam(p.searchable_form_encoding, l);
l->append(L", ");
LogParam(p.password_form, l);
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 689b180..d25f439 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1005,7 +1005,6 @@ void RenderView::UpdateURL(WebFrame* frame) {
navigation_state->searchable_form_data();
if (searchable_form_data) {
params.searchable_form_url = searchable_form_data->url();
- params.searchable_form_element_name = searchable_form_data->element_name();
params.searchable_form_encoding = searchable_form_data->encoding();
}
diff --git a/webkit/api/public/WebViewClient.h b/webkit/api/public/WebViewClient.h
index b4a1e2d..5017c9f 100644
--- a/webkit/api/public/WebViewClient.h
+++ b/webkit/api/public/WebViewClient.h
@@ -193,7 +193,7 @@ namespace WebKit {
WebFrame*, const WebString& message) = 0;
// Shows a context menu with commands relevant to a specific element on
- // the a given frame. Additional context data is supplied.
+ // the given frame. Additional context data is supplied.
virtual void showContextMenu(WebFrame*, const WebContextMenuData&) = 0;
// UI ------------------------------------------------------------------
diff --git a/webkit/glue/dom_operations_private.h b/webkit/glue/dom_operations_private.h
index 3173361..f8ca7a6 100644
--- a/webkit/glue/dom_operations_private.h
+++ b/webkit/glue/dom_operations_private.h
@@ -17,6 +17,11 @@ class QualifiedName;
class String;
}
+namespace WebKit {
+class WebView;
+}
+
+class GURL;
class WebFrameImpl;
namespace webkit_glue {
diff --git a/webkit/glue/searchable_form_data.cc b/webkit/glue/searchable_form_data.cc
index 4761435..68336bd 100644
--- a/webkit/glue/searchable_form_data.cc
+++ b/webkit/glue/searchable_form_data.cc
@@ -7,12 +7,10 @@
#include "base/compiler_specific.h"
MSVC_PUSH_WARNING_LEVEL(0);
-#include "CString.h"
#include "Document.h"
-#include "DocumentLoader.h"
-#include "FormData.h"
+#include "FormDataBuilder.h"
#include "FormDataList.h"
-#include "FrameLoader.h"
+#include "Frame.h"
#include "HTMLFormControlElement.h"
#include "HTMLFormElement.h"
#include "HTMLOptionElement.h"
@@ -20,122 +18,55 @@ MSVC_PUSH_WARNING_LEVEL(0);
#include "HTMLNames.h"
#include "HTMLOptionsCollection.h"
#include "HTMLSelectElement.h"
-#include "ResourceRequest.h"
#include "TextEncoding.h"
-#include <wtf/Vector.h>
MSVC_POP_WARNING();
#undef LOG
-#include "base/basictypes.h"
-#include "base/string_util.h"
-#include "webkit/glue/dom_operations.h"
#include "webkit/glue/dom_operations_private.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/searchable_form_data.h"
-#include "webkit/glue/webframe_impl.h"
-using WebCore::HTMLFormElement;
-using WebCore::HTMLInputElement;
-using WebCore::HTMLOptionElement;
-using WebKit::WebForm;
+using namespace WebCore;
namespace webkit_glue {
namespace {
-// TODO(eseidel): appendString and appendEncodedString do *not* follow Google
-// style because they are copy/paste from WebKit and will go away as soon as the
-// WebKit functions are made public.
-static void appendString(Vector<char>& buffer, const char* string)
-{
- buffer.append(string, strlen(string));
-}
-
-// TODO (sky): This comes straight out of HTMLFormElement, will work with
-// WebKit folks to make public.
-static void appendEncodedString(Vector<char>& buffer, const WebCore::CString& string)
-{
- static const char hexDigits[17] = "0123456789ABCDEF";
-
- // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
- int length = string.length();
- for (int i = 0; i < length; i++) {
- unsigned char c = string.data()[i];
-
- // Same safe characters as Netscape for compatibility.
- static const char safe[] = "-._*";
- if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || strchr(safe, c))
- buffer.append(c);
- else if (c == ' ')
- buffer.append('+');
- else if (c == '\n' || (c == '\r' && (i + 1 >= length || string.data()[i + 1] != '\n')))
- appendString(buffer, "%0D%0A");
- else if (c != '\r') {
- buffer.append('%');
- buffer.append(hexDigits[c >> 4]);
- buffer.append(hexDigits[c & 0xF]);
- }
- }
-}
-
-// Returns true if the form element has an 'onsubmit' attribute.
-bool FormHasOnSubmit(WebCore::HTMLFormElement* form) {
- const WebCore::AtomicString& attribute_value =
- form->getAttribute(WebCore::HTMLNames::onsubmitAttr);
- return (!attribute_value.isNull() && !attribute_value.isEmpty());
-}
-
-// Returns true if the form element will submit the data using a GET.
-bool IsFormMethodGet(WebCore::HTMLFormElement* form) {
- const WebCore::AtomicString& attribute_value =
- form->getAttribute(WebCore::HTMLNames::methodAttr);
- return !equalIgnoringCase(attribute_value, "post");
-}
-
// Gets the encoding for the form.
-void GetFormEncoding(WebCore::HTMLFormElement* form,
- WebCore::TextEncoding* encoding) {
- WebCore::String str =
- form->getAttribute(WebCore::HTMLNames::accept_charsetAttr);
+void GetFormEncoding(HTMLFormElement* form, TextEncoding* encoding) {
+ String str(form->getAttribute(HTMLNames::accept_charsetAttr));
str.replace(',', ' ');
- Vector<WebCore::String> charsets;
+ Vector<String> charsets;
str.split(' ', charsets);
- Vector<WebCore::String>::const_iterator end = charsets.end();
- for (Vector<WebCore::String>::const_iterator it = charsets.begin(); it != end;
- ++it) {
- *encoding = WebCore::TextEncoding(*it);
+ for (Vector<String>::const_iterator it = charsets.begin();
+ it != charsets.end(); ++it) {
+ *encoding = TextEncoding(*it);
if (encoding->isValid())
return;
}
if (!encoding->isValid()) {
- WebCore::Frame* frame = form->document()->frame();
- if (frame)
- *encoding = WebCore::TextEncoding(frame->loader()->encoding());
- else
- *encoding = WebCore::Latin1Encoding();
+ Frame* frame = form->document()->frame();
+ *encoding = frame ?
+ TextEncoding(frame->loader()->encoding()) : Latin1Encoding();
}
}
// Returns true if the submit request results in an HTTP URL.
-bool IsHTTPFormSubmit(WebCore::HTMLFormElement* form) {
- WebCore::Frame* frame = form->document()->frame();
- WebCore::String action = form->action();
- WebCore::FrameLoader* loader = frame->loader();
- WebCore::KURL url = loader->completeURL(action.isNull() ? "" : action);
- return (url.protocol() == "http");
+bool IsHTTPFormSubmit(HTMLFormElement* form) {
+ String action(form->action());
+ return form->document()->frame()->loader()->
+ completeURL(action.isNull() ? "" : action).protocol() == "http";
}
// If the form does not have an activated submit button, the first submit
// button is returned.
-WebCore::HTMLFormControlElement* GetButtonToActivate(
- WebCore::HTMLFormElement* form) {
- WTF::Vector<WebCore::HTMLFormControlElement*> form_elements =
- form->formElements;
- WebCore::HTMLFormControlElement* first_submit_button = NULL;
+HTMLFormControlElement* GetButtonToActivate(HTMLFormElement* form) {
+ WTF::Vector<HTMLFormControlElement*> form_elements = form->formElements;
+ HTMLFormControlElement* first_submit_button = NULL;
for (unsigned i = 0; i < form_elements.size(); ++i) {
- WebCore::HTMLFormControlElement* current = form_elements[i];
+ HTMLFormControlElement* current = form_elements[i];
if (current->isActivatedSubmit()) {
// There's a button that is already activated for submit, return NULL.
return NULL;
@@ -149,9 +80,9 @@ WebCore::HTMLFormControlElement* GetButtonToActivate(
// Returns true if the selected state of all the options matches the default
// selected state.
-bool IsSelectInDefaultState(WebCore::HTMLSelectElement* select) {
- RefPtr<WebCore::HTMLOptionsCollection> options = select->options();
- WebCore::Node* node = options->firstItem();
+bool IsSelectInDefaultState(HTMLSelectElement* select) {
+ RefPtr<HTMLOptionsCollection> options = select->options();
+ Node* node = options->firstItem();
if (!select->multiple() && select->size() <= 1) {
// The select is rendered as a combobox (called menulist in WebKit). At
@@ -193,17 +124,17 @@ bool IsCheckBoxOrRadioInDefaultState(HTMLInputElement* element) {
// The default state is the state of the form element on initial load of the
// page, and varies depending upon the form element. For example, a checkbox is
// in its default state if the checked state matches the defaultChecked state.
-bool IsInDefaultState(WebCore::HTMLFormControlElement* form_element) {
- if (form_element->hasTagName(WebCore::HTMLNames::inputTag)) {
+bool IsInDefaultState(HTMLFormControlElement* form_element) {
+ if (form_element->hasTagName(HTMLNames::inputTag)) {
HTMLInputElement* input_element =
static_cast<HTMLInputElement*>(form_element);
- if (input_element->inputType() == HTMLInputElement::CHECKBOX ||
- input_element->inputType() == HTMLInputElement::RADIO) {
+ if ((input_element->inputType() == HTMLInputElement::CHECKBOX) ||
+ (input_element->inputType() == HTMLInputElement::RADIO)) {
return IsCheckBoxOrRadioInDefaultState(input_element);
}
- } else if (form_element->hasTagName(WebCore::HTMLNames::selectTag)) {
+ } else if (form_element->hasTagName(HTMLNames::selectTag)) {
return IsSelectInDefaultState(
- static_cast<WebCore::HTMLSelectElement*>(form_element));
+ static_cast<HTMLSelectElement*>(form_element));
}
return true;
}
@@ -212,11 +143,10 @@ bool IsInDefaultState(WebCore::HTMLFormControlElement* form_element) {
// element is not found, NULL is returned. Additionally, the form data for all
// elements is added to enc_string and the encoding used is set in
// encoding_name.
-WebCore::HTMLInputElement* GetTextElement(
- WebCore::HTMLFormElement* form,
- Vector<char>* enc_string,
- std::string* encoding_name) {
- WebCore::TextEncoding encoding;
+HTMLInputElement* GetTextElement(HTMLFormElement* form,
+ Vector<char>* enc_string,
+ std::string* encoding_name) {
+ TextEncoding encoding;
GetFormEncoding(form, &encoding);
if (!encoding.isValid()) {
// Need a valid encoding to encode the form elements.
@@ -225,28 +155,26 @@ WebCore::HTMLInputElement* GetTextElement(
return NULL;
}
*encoding_name = encoding.name();
- WebCore::HTMLInputElement* text_element = NULL;
- WTF::Vector<WebCore::HTMLFormControlElement*> form_elements =
- form->formElements;
+ HTMLInputElement* text_element = NULL;
+ WTF::Vector<HTMLFormControlElement*> form_elements = form->formElements;
for (unsigned i = 0; i < form_elements.size(); ++i) {
- WebCore::HTMLFormControlElement* form_element = form_elements[i];
+ HTMLFormControlElement* form_element = form_elements[i];
if (!form_element->disabled() && !form_element->name().isNull()) {
bool is_text_element = false;
- if (!IsInDefaultState(form_element)) {
+ if (!IsInDefaultState(form_element))
return NULL;
- }
- if (form_element->hasTagName(WebCore::HTMLNames::inputTag)) {
- WebCore::HTMLInputElement* input_element =
- static_cast<WebCore::HTMLInputElement*>(form_element);
+ if (form_element->hasTagName(HTMLNames::inputTag)) {
+ HTMLInputElement* input_element =
+ static_cast<HTMLInputElement*>(form_element);
switch (input_element->inputType()) {
- case WebCore::HTMLInputElement::TEXT:
- case WebCore::HTMLInputElement::ISINDEX:
+ case HTMLInputElement::TEXT:
+ case HTMLInputElement::ISINDEX:
is_text_element = true;
break;
- case WebCore::HTMLInputElement::PASSWORD:
+ case HTMLInputElement::PASSWORD:
// Don't store passwords! This is most likely an https anyway.
// Fall through.
- case WebCore::HTMLInputElement::FILE:
+ case HTMLInputElement::FILE:
// Too big, don't try to index this.
return NULL;
break;
@@ -254,39 +182,44 @@ WebCore::HTMLInputElement* GetTextElement(
// All other input types are indexable.
break;
}
- } else if (form_element->hasTagName(WebCore::HTMLNames::textareaTag)) {
- // TextArea aren't use for search.
+ } else if (form_element->hasTagName(HTMLNames::textareaTag)) {
+ // Textareas aren't used for search.
return NULL;
}
- WebCore::FormDataList lst(encoding);
+ FormDataList lst(encoding);
if (form_element->appendFormData(lst, false)) {
- if (is_text_element && lst.list().size() > 0) {
+ if (is_text_element && !lst.list().isEmpty()) {
if (text_element != NULL) {
// The auto-complete bar only knows how to fill in one value.
// This form has multiple fields; don't treat it as searchable.
return NULL;
}
- text_element = static_cast<WebCore::HTMLInputElement*>(form_element);
+ text_element = static_cast<HTMLInputElement*>(form_element);
}
- for (int j = 0, max = static_cast<int>(lst.list().size()); j < max; ++j) {
- const WebCore::FormDataList::Item& item = lst.list()[j];
+ for (int j = 0, max = static_cast<int>(lst.list().size()); j < max;
+ ++j) {
+ const FormDataList::Item& item = lst.list()[j];
// handle ISINDEX / <input name=isindex> special
// but only if its the first entry
if (enc_string->isEmpty() && item.data() == "isindex") {
- if (form_element == text_element)
- appendString(*enc_string, "{searchTerms}");
- else
- appendEncodedString(*enc_string, (lst.list()[j + 1].data()));
+ if (form_element == text_element) {
+ enc_string->append("{searchTerms}", 13);
+ } else {
+ FormDataBuilder::encodeStringAsFormData(
+ *enc_string, (lst.list()[j + 1].data()));
+ }
++j;
} else {
if (!enc_string->isEmpty())
enc_string->append('&');
- appendEncodedString(*enc_string, item.data());
+ FormDataBuilder::encodeStringAsFormData(*enc_string, item.data());
enc_string->append('=');
- if (form_element == text_element)
- appendString(*enc_string, "{searchTerms}");
- else
- appendEncodedString(*enc_string, lst.list()[j + 1].data());
+ if (form_element == text_element) {
+ enc_string->append("{searchTerms}", 13);
+ } else {
+ FormDataBuilder::encodeStringAsFormData(
+ *enc_string, lst.list()[j + 1].data());
+ }
++j;
}
}
@@ -298,20 +231,20 @@ WebCore::HTMLInputElement* GetTextElement(
} // namespace
-SearchableFormData* SearchableFormData::Create(const WebForm& webform) {
+SearchableFormData* SearchableFormData::Create(const WebKit::WebForm& webform) {
RefPtr<HTMLFormElement> form = WebFormToHTMLFormElement(webform);
- WebCore::Frame* frame = form->document()->frame();
+ Frame* frame = form->document()->frame();
if (frame == NULL)
return NULL;
// Only consider forms that GET data and the action targets an http page.
- if (!IsFormMethodGet(form.get()) || !IsHTTPFormSubmit(form.get()))
+ if (equalIgnoringCase(form->getAttribute(HTMLNames::methodAttr), "post") ||
+ !IsHTTPFormSubmit(form.get()))
return NULL;
Vector<char> enc_string;
- WebCore::HTMLFormControlElement* first_submit_button =
- GetButtonToActivate(form.get());
+ HTMLFormControlElement* first_submit_button = GetButtonToActivate(form.get());
if (first_submit_button) {
// The form does not have an active submit button, make the first button
@@ -321,7 +254,7 @@ SearchableFormData* SearchableFormData::Create(const WebForm& webform) {
}
std::string encoding;
- WebCore::HTMLInputElement* text_element =
+ HTMLInputElement* text_element =
GetTextElement(form.get(), &enc_string, &encoding);
if (first_submit_button)
@@ -334,37 +267,12 @@ SearchableFormData* SearchableFormData::Create(const WebForm& webform) {
// It's a valid form.
// Generate the URL and create a new SearchableFormData.
- RefPtr<WebCore::FormData> form_data = WebCore::FormData::create(enc_string);
- WebCore::String action = form->action();
- WebCore::FrameLoader* loader = frame->loader();
- WebCore::KURL url = loader->completeURL(action.isNull() ? "" : action);
+ RefPtr<FormData> form_data = FormData::create(enc_string);
+ String action(form->action());
+ KURL url = frame->loader()->completeURL(action.isNull() ? "" : action);
url.setQuery(form_data->flattenToString());
- std::wstring current_value = StringToStdWString(
- static_cast<WebCore::HTMLInputElement*>(text_element)->value());
- std::wstring text_name = StringToStdWString(text_element->name());
GURL gurl(KURLToGURL(url));
- return new SearchableFormData(gurl, text_name, current_value, encoding);
-}
-
-// static
-bool SearchableFormData::Equals(const SearchableFormData* a,
- const SearchableFormData* b) {
- return ((a == b) ||
- (a != NULL && b != NULL &&
- a->url().spec() == b->url().spec() &&
- a->element_name() == b->element_name() &&
- a->element_value() == b->element_value() &&
- a->encoding() == b->encoding()));
-}
-
-SearchableFormData::SearchableFormData(const GURL& url,
- const std::wstring& element_name,
- const std::wstring& element_value,
- const std::string& encoding)
- : url_(url),
- element_name_(element_name),
- element_value_(element_value),
- encoding_(encoding) {
+ return new SearchableFormData(gurl, encoding);
}
} // namespace webkit_glue
diff --git a/webkit/glue/searchable_form_data.h b/webkit/glue/searchable_form_data.h
index fc76c57..204ef39 100644
--- a/webkit/glue/searchable_form_data.h
+++ b/webkit/glue/searchable_form_data.h
@@ -23,31 +23,19 @@ class SearchableFormData {
// request, a SearchableFormData is created and returned.
static SearchableFormData* Create(const WebKit::WebForm& form);
- // Returns true if the two SearchableFormData are equal, false otherwise.
- // Either argument may be NULL. If both elements are NULL, true is returned.
- static bool Equals(const SearchableFormData* a, const SearchableFormData* b);
-
// URL for the searchable form request.
const GURL& url() const { return url_; }
- // Class name of the INPUT element the user input text into.
- const std::wstring element_name() const { return element_name_; }
-
- // Value of the text field in the form.
- const std::wstring element_value() const { return element_value_; }
-
// Encoding used to encode the form parameters; never empty.
const std::string& encoding() const { return encoding_; }
private:
- SearchableFormData(const GURL& url,
- const std::wstring& element_name,
- const std::wstring& element_value,
- const std::string& encoding);
+ SearchableFormData(const GURL& url, const std::string& encoding)
+ : url_(url),
+ encoding_(encoding) {
+ }
const GURL url_;
- const std::wstring element_name_;
- const std::wstring element_value_;
const std::string encoding_;
DISALLOW_COPY_AND_ASSIGN(SearchableFormData);