summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorhayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 09:34:50 +0000
committerhayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 09:34:50 +0000
commite6efd025246dc04f22ee0f62a25e1259ab95512e (patch)
treea7bee5e86797af0826bf2cbda24070526ef33b60 /chrome
parent5c43b97cfe76c02c88900a4c68326adac842b7be (diff)
downloadchromium_src-e6efd025246dc04f22ee0f62a25e1259ab95512e.zip
chromium_src-e6efd025246dc04f22ee0f62a25e1259ab95512e.tar.gz
chromium_src-e6efd025246dc04f22ee0f62a25e1259ab95512e.tar.bz2
Page Cycler Intl2 perf regression.
Revert 43181 - AutoFill: Send the forms cached in the FormManager to the AutoFillManager on page load instead of duplicating this parsing in RenderView. BUG=38325 TEST=none Review URL: http://codereview.chromium.org/1530011 TBR=jhawkins@chromium.org Review URL: http://codereview.chromium.org/1540008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43195 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/renderer/form_manager.cc114
-rw-r--r--chrome/renderer/form_manager.h24
-rw-r--r--chrome/renderer/render_view.cc43
3 files changed, 47 insertions, 134 deletions
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 4377b1b..5413963 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -32,7 +32,6 @@ using WebKit::WebString;
using WebKit::WebVector;
using webkit_glue::FormData;
using webkit_glue::FormField;
-using webkit_glue::FormFieldValues;
FormManager::FormManager() {
}
@@ -41,9 +40,7 @@ FormManager::~FormManager() {
Reset();
}
-void FormManager::ExtractForms(const WebFrame* frame) {
- DCHECK(frame);
-
+void FormManager::ExtractForms(WebFrame* frame) {
// Reset the vector of FormElements for this frame.
ResetFrame(frame);
@@ -71,12 +68,10 @@ void FormManager::ExtractForms(const WebFrame* frame) {
void FormManager::GetForms(std::vector<FormData>* forms,
RequirementsMask requirements) {
- DCHECK(forms);
-
// Frame loop.
for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin();
iter != form_elements_map_.end(); ++iter) {
- const WebFrame* frame = iter->first;
+ WebFrame* frame = iter->first;
// Form loop.
for (std::vector<FormElement*>::iterator form_iter = iter->second.begin();
@@ -94,40 +89,12 @@ void FormManager::GetForms(std::vector<FormData>* forms,
}
}
-void FormManager::GetFormsInFrame(const WebFrame* frame,
- RequirementsMask requirements,
- std::vector<FormData>* forms) {
- DCHECK(frame);
- DCHECK(forms);
-
- WebFrameFormElementMap::iterator iter = form_elements_map_.find(frame);
- if (iter == form_elements_map_.end())
- return;
-
- const std::vector<FormElement*>& form_elements = iter->second;
- for (std::vector<FormElement*>::const_iterator form_iter =
- form_elements.begin();
- form_iter != form_elements.end(); ++form_iter) {
- FormElement* form_element = *form_iter;
-
- if (requirements & REQUIRE_AUTOCOMPLETE &&
- !form_element->form_element.autoComplete())
- continue;
-
- FormData form;
- FormElementToFormData(frame, form_element, requirements, &form);
- forms->push_back(form);
- }
-}
-
bool FormManager::FindForm(const WebFormControlElement& element,
FormData* form) {
- DCHECK(form);
-
// Frame loop.
for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin();
iter != form_elements_map_.end(); ++iter) {
- const WebFrame* frame = iter->first;
+ WebFrame* frame = iter->first;
// Form loop.
for (std::vector<FormElement*>::iterator form_iter = iter->second.begin();
@@ -206,54 +173,7 @@ void FormManager::Reset() {
form_elements_map_.clear();
}
-// static
-void FormManager::FormDataToFormFieldValues(
- const std::vector<FormData>& forms,
- std::vector<FormFieldValues>* form_field_values) {
- DCHECK(form_field_values);
-
- for (std::vector<FormData>::const_iterator iter = forms.begin();
- iter != forms.end(); ++iter) {
- FormFieldValues form;
- form.form_name = iter->name;
- // TODO(jhawkins): Store the method in FormData.
- form.method = ASCIIToUTF16("post");
- form.source_url = iter->origin;
- form.target_url = iter->action;
- form.elements = iter->fields;
- form_field_values->push_back(form);
- }
-}
-
-// static
-void FormManager::WebFormControlElementToFormField(
- const WebFormControlElement& element,
- webkit_glue::FormField* field) {
- DCHECK(field);
- field->set_label(LabelForElement(element));
- field->set_name(element.nameForAutofill());
- field->set_form_control_type(element.formControlType());
-
- // TODO(jhawkins): In WebKit, move value() and setValue() to
- // WebFormControlElement.
- string16 value;
- if (element.formControlType() == ASCIIToUTF16("text")) {
- const WebInputElement& input_element =
- element.toConstElement<WebInputElement>();
- value = input_element.value();
- } else if (element.formControlType() == ASCIIToUTF16("select-one")) {
- // TODO(jhawkins): This is ugly. WebSelectElement::value() is a non-const
- // method. Look into fixing this on the WebKit side.
- WebFormControlElement& e = const_cast<WebFormControlElement&>(element);
- WebSelectElement select_element = e.toElement<WebSelectElement>();
- value = select_element.value();
- }
- field->set_value(value);
-}
-
-void FormManager::ResetFrame(const WebFrame* frame) {
- DCHECK(frame);
-
+void FormManager::ResetFrame(WebFrame* frame) {
WebFrameFormElementMap::iterator iter = form_elements_map_.find(frame);
if (iter != form_elements_map_.end()) {
STLDeleteElements(&iter->second);
@@ -261,14 +181,10 @@ void FormManager::ResetFrame(const WebFrame* frame) {
}
}
-void FormManager::FormElementToFormData(const WebFrame* frame,
+void FormManager::FormElementToFormData(WebFrame* frame,
const FormElement* form_element,
RequirementsMask requirements,
FormData* form) {
- DCHECK(frame);
- DCHECK(form_element);
- DCHECK(form);
-
form->name = form_element->form_element.name();
form->origin = frame->url();
form->action = frame->completeURL(form_element->form_element.action());
@@ -295,9 +211,23 @@ void FormManager::FormElementToFormData(const WebFrame* frame,
if (requirements & REQUIRE_ELEMENTS_ENABLED && !control_element.isEnabled())
continue;
- FormField field;
- WebFormControlElementToFormField(control_element, &field);
- form->fields.push_back(field);
+ string16 label = LabelForElement(control_element);
+ string16 name = control_element.nameForAutofill();
+
+ string16 value;
+ if (control_element.formControlType() == ASCIIToUTF16("text")) {
+ const WebInputElement& input_element =
+ control_element.toConstElement<WebInputElement>();
+ value = input_element.value();
+ } else if (control_element.formControlType() ==
+ ASCIIToUTF16("select-one")) {
+ WebSelectElement select_element =
+ control_element.toElement<WebSelectElement>();
+ value = select_element.value();
+ }
+
+ string16 form_control_type = control_element.formControlType();
+ form->fields.push_back(FormField(label, name, value, form_control_type));
}
}
diff --git a/chrome/renderer/form_manager.h b/chrome/renderer/form_manager.h
index cc19bd8..5445a4f 100644
--- a/chrome/renderer/form_manager.h
+++ b/chrome/renderer/form_manager.h
@@ -12,7 +12,6 @@
#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
#include "webkit/glue/form_data.h"
-#include "webkit/glue/form_field_values.h"
namespace WebKit {
class WebFrame;
@@ -32,17 +31,12 @@ class FormManager {
virtual ~FormManager();
// Scans the DOM in |frame| extracting and storing forms.
- void ExtractForms(const WebKit::WebFrame* frame);
+ void ExtractForms(WebKit::WebFrame* frame);
// Returns a vector of forms that match |requirements|.
void GetForms(std::vector<webkit_glue::FormData>* forms,
RequirementsMask requirements);
- // Returns a vector of forms in |frame| that match |requirements|.
- void GetFormsInFrame(const WebKit::WebFrame* frame,
- RequirementsMask requirements,
- std::vector<webkit_glue::FormData>* forms);
-
// Finds the form that contains |element| and returns it in |form|. Returns
// false if the form is not found.
bool FindForm(const WebKit::WebFormControlElement& element,
@@ -58,16 +52,6 @@ class FormManager {
// Resets the stored set of forms.
void Reset();
- // TODO(jhawkins): Remove this method once AutoFillManager uses FormData.
- static void FormDataToFormFieldValues(
- const std::vector<webkit_glue::FormData>& forms,
- std::vector<webkit_glue::FormFieldValues>* form_field_values);
-
- // Creates a FormField object from a given WebFormControlElement.
- static void WebFormControlElementToFormField(
- const WebKit::WebFormControlElement& element,
- webkit_glue::FormField* field);
-
private:
// A map of WebFormControlElements keyed by each element's name.
typedef std::map<string16, WebKit::WebFormControlElement>
@@ -82,15 +66,15 @@ class FormManager {
// A map of vectors of FormElements keyed by the WebFrame containing each
// form.
- typedef std::map<const WebKit::WebFrame*, std::vector<FormElement*> >
+ typedef std::map<WebKit::WebFrame*, std::vector<FormElement*> >
WebFrameFormElementMap;
// Resets the forms for the specified |frame|.
- void ResetFrame(const WebKit::WebFrame* frame);
+ void ResetFrame(WebKit::WebFrame* frame);
// Converts a FormElement to FormData storage.
// TODO(jhawkins): Modify FormElement so we don't need |frame|.
- void FormElementToFormData(const WebKit::WebFrame* frame,
+ void FormElementToFormData(WebKit::WebFrame* frame,
const FormElement* form_element,
RequirementsMask requirements,
webkit_glue::FormData* form);
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 6c8b8a2..0d84b7ab 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -79,11 +79,11 @@
#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
@@ -106,7 +106,6 @@
#include "webkit/appcache/web_application_cache_host_impl.h"
#include "webkit/default_plugin/default_plugin_shared.h"
#include "webkit/glue/dom_operations.h"
-#include "webkit/glue/form_data.h"
#include "webkit/glue/form_field.h"
#include "webkit/glue/form_field_values.h"
#include "webkit/glue/glue_serialize.h"
@@ -135,7 +134,6 @@ using appcache::WebApplicationCacheHostImpl;
using base::Time;
using base::TimeDelta;
using webkit_glue::AltErrorPageResourceFetcher;
-using webkit_glue::FormData;
using webkit_glue::FormField;
using webkit_glue::FormFieldValues;
using webkit_glue::ImageResourceFetcher;
@@ -159,11 +157,11 @@ using WebKit::WebDragOperationsMask;
using WebKit::WebEditingAction;
using WebKit::WebFileChooserCompletion;
using WebKit::WebFindOptions;
-using WebKit::WebFormControlElement;
using WebKit::WebFormElement;
using WebKit::WebFrame;
using WebKit::WebHistoryItem;
using WebKit::WebImage;
+using WebKit::WebInputElement;
using WebKit::WebMediaPlayer;
using WebKit::WebMediaPlayerAction;
using WebKit::WebMediaPlayerClient;
@@ -1952,12 +1950,10 @@ void RenderView::queryAutofillSuggestions(const WebNode& node,
static int query_counter = 0;
autofill_query_id_ = query_counter++;
autofill_query_node_ = node;
- const WebKit::WebFormControlElement element =
- node.toConstElement<WebFormControlElement>();
- FormField field;
- FormManager::WebFormControlElementToFormField(element, &field);
+ const WebKit::WebInputElement input_element =
+ node.toConstElement<WebInputElement>();
Send(new ViewHostMsg_QueryFormFieldAutofill(
- routing_id_, autofill_query_id_, field));
+ routing_id_, autofill_query_id_, FormField(input_element)));
}
void RenderView::removeAutofillSuggestions(const WebString& name,
@@ -1973,8 +1969,7 @@ void RenderView::didAcceptAutoFillSuggestion(
autofill_query_id_ = query_counter++;
webkit_glue::FormData form;
- const WebFormControlElement element =
- node.toConstElement<WebFormControlElement>();
+ const WebInputElement element = node.toConstElement<WebInputElement>();
if (!form_manager_.FindForm(element, &form))
return;
@@ -4658,18 +4653,22 @@ void RenderView::focusAccessibilityObject(
}
void RenderView::SendForms(WebFrame* frame) {
- std::vector<FormData> forms;
- FormManager::RequirementsMask requirements =
- static_cast<FormManager::RequirementsMask>(
- FormManager::REQUIRE_AUTOCOMPLETE |
- FormManager::REQUIRE_ELEMENTS_ENABLED);
- form_manager_.GetFormsInFrame(frame, requirements, &forms);
- if (!forms.empty()) {
- // TODO(jhawkins): Remove this call once AutoFillManager uses FormData.
- std::vector<FormFieldValues> form_field_values;
- FormManager::FormDataToFormFieldValues(forms, &form_field_values);
- Send(new ViewHostMsg_FormsSeen(routing_id_, form_field_values));
+ WebVector<WebFormElement> web_forms;
+ frame->forms(web_forms);
+
+ std::vector<FormFieldValues> forms;
+ for (size_t i = 0; i < web_forms.size(); ++i) {
+ const WebFormElement& web_form = web_forms[i];
+
+ if (web_form.autoComplete()) {
+ scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form));
+ if (form.get())
+ forms.push_back(*form);
+ }
}
+
+ if (!forms.empty())
+ Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
}
void RenderView::didChangeAccessibilityObjectState(