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..06cd00d04ed434459f1d4e083fe831837787892e 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); |
+ } |
Ilya Sherman
2012/12/01 00:54:12
nit: It seems like this code should be decomposed
Raman Kakilate
2012/12/06 01:54:05
code looks repeated 3 times, but the container obj
Ilya Sherman
2012/12/07 01:47:22
I agree that the set is different, but the two map
Raman Kakilate
2012/12/10 18:36:45
templatized helper method.
|
} |
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 { |
Ilya Sherman
2012/12/01 00:54:12
nit: Please DCHECK that the type is a radio or che
Raman Kakilate
2012/12/06 01:54:05
Done.
|
+ WebInputElement input_element = control_element.to<WebInputElement>(); |
+ initial_checked_state_.insert( |
+ std::make_pair(input_element, input_element.isChecked())); |
Ilya Sherman
2012/12/01 00:54:12
Lines 207-208 don't look like they belong. Am I m
Raman Kakilate
2012/12/06 01:54:05
my-bad. removed them. thanks for catching it.
|
+ std::map<const WebInputElement, bool>::const_iterator |
+ it = initial_checked_state_.find(input_element); |
Ilya Sherman
2012/12/01 00:54:12
nit: "it =" belongs on the previous line, since it
Raman Kakilate
2012/12/06 01:54:05
Done.
|
+ if (it != initial_checked_state_.end() && |
+ input_element.isChecked() != it->second) { |
+ input_element.setChecked(it->second, true); |
+ } |
} |
} |