Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4895)

Unified Diff: chrome/renderer/autofill/form_cache.cc

Issue 11415221: Add support for autofilling radio buttons and checkboxes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: address comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/autofill/form_cache.cc
diff --git a/chrome/renderer/autofill/form_cache.cc b/chrome/renderer/autofill/form_cache.cc
index f7bec0342a014e362d700f47fe520ddbeb65cdab..5e0f2f93e7763625da80ebf7fa80d2fc3adeaba5 100644
--- a/chrome/renderer/autofill/form_cache.cc
+++ b/chrome/renderer/autofill/form_cache.cc
@@ -80,6 +80,13 @@ void FormCache::ExtractForms(const WebFrame& frame,
element.toConst<WebSelectElement>();
initial_select_values_.insert(std::make_pair(select_element,
select_element.value()));
+ } else {
+ const WebInputElement input_element =
+ element.toConst<WebInputElement>();
+ if (IsRadioButtonElement(&input_element) ||
+ IsCheckboxElement(&input_element))
+ initial_checked_state_.insert(
+ std::make_pair(input_element, input_element.isChecked()));
}
}
@@ -138,6 +145,26 @@ void FormCache::ResetFrame(const WebFrame& frame) {
it != select_values_to_delete.end(); ++it) {
initial_select_values_.erase(*it);
}
+
+ std::vector<WebInputElement> checked_states_to_delete;
+ for (std::map<const WebInputElement, bool>::const_iterator it =
+ initial_checked_state_.begin();
+ it != initial_checked_state_.end(); ++it) {
+ WebFormElement form_element = it->first.form();
+ if (form_element.isNull()) {
+ checked_states_to_delete.push_back(it->first);
+ } else {
+ const WebFrame* element_frame = form_element.document().frame();
+ if (!element_frame || element_frame == &frame)
+ checked_states_to_delete.push_back(it->first);
+ }
+ }
+
+ for (std::vector<WebInputElement>::const_iterator it =
+ checked_states_to_delete.begin();
+ it != checked_states_to_delete.end(); ++it) {
+ initial_checked_state_.erase(*it);
+ }
}
bool FormCache::ClearFormWithElement(const WebInputElement& element) {
@@ -165,8 +192,7 @@ bool FormCache::ClearFormWithElement(const WebInputElement& element) {
int length = input_element->value().length();
input_element->setSelectionRange(length, length);
}
- } else {
- DCHECK(IsSelectElement(control_element));
+ } else if (IsSelectElement(control_element)) {
WebSelectElement select_element = control_element.to<WebSelectElement>();
std::map<const WebSelectElement, string16>::const_iterator
@@ -176,6 +202,16 @@ bool FormCache::ClearFormWithElement(const WebInputElement& element) {
select_element.setValue(initial_value_iter->second);
select_element.dispatchFormControlChangeEvent();
}
+ } else {
+ WebInputElement input_element = control_element.to<WebInputElement>();
+ DCHECK(IsRadioButtonElement(&input_element) ||
+ IsCheckboxElement(&input_element));
+ std::map<const WebInputElement, bool>::const_iterator it =
+ initial_checked_state_.find(input_element);
+ if (it != initial_checked_state_.end() &&
+ input_element.isChecked() != it->second) {
+ input_element.setChecked(it->second, true);
+ }
}
}
« chrome/browser/autofill/autofill_xml_parser.cc ('K') | « chrome/renderer/autofill/form_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698