| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/renderer/form_cache.h" | 5 #include "components/autofill/renderer/form_cache.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "components/autofill/common/autofill_constants.h" | 9 #include "components/autofill/common/autofill_constants.h" |
| 10 #include "components/autofill/common/form_data.h" | 10 #include "components/autofill/common/form_data.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, | 184 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, |
| 185 &control_elements); | 185 &control_elements); |
| 186 for (size_t i = 0; i < control_elements.size(); ++i) { | 186 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 187 WebFormControlElement control_element = control_elements[i]; | 187 WebFormControlElement control_element = control_elements[i]; |
| 188 WebInputElement* input_element = toWebInputElement(&control_element); | 188 WebInputElement* input_element = toWebInputElement(&control_element); |
| 189 if (IsTextInput(input_element)) { | 189 if (IsTextInput(input_element)) { |
| 190 // We don't modify the value of disabled fields. | 190 // We don't modify the value of disabled fields. |
| 191 if (!input_element->isEnabled()) | 191 if (!input_element->isEnabled()) |
| 192 continue; | 192 continue; |
| 193 | 193 |
| 194 input_element->setValue(string16(), true); | 194 input_element->setValue(base::string16(), true); |
| 195 input_element->setAutofilled(false); | 195 input_element->setAutofilled(false); |
| 196 | 196 |
| 197 // Clearing the value in the focused node (above) can cause selection | 197 // Clearing the value in the focused node (above) can cause selection |
| 198 // to be lost. We force selection range to restore the text cursor. | 198 // to be lost. We force selection range to restore the text cursor. |
| 199 if (element == *input_element) { | 199 if (element == *input_element) { |
| 200 int length = input_element->value().length(); | 200 int length = input_element->value().length(); |
| 201 input_element->setSelectionRange(length, length); | 201 input_element->setSelectionRange(length, length); |
| 202 } | 202 } |
| 203 } else if (IsSelectElement(control_element)) { | 203 } else if (IsSelectElement(control_element)) { |
| 204 WebSelectElement select_element = control_element.to<WebSelectElement>(); | 204 WebSelectElement select_element = control_element.to<WebSelectElement>(); |
| 205 | 205 |
| 206 std::map<const WebSelectElement, string16>::const_iterator | 206 std::map<const WebSelectElement, base::string16>::const_iterator |
| 207 initial_value_iter = initial_select_values_.find(select_element); | 207 initial_value_iter = initial_select_values_.find(select_element); |
| 208 if (initial_value_iter != initial_select_values_.end() && | 208 if (initial_value_iter != initial_select_values_.end() && |
| 209 select_element.value() != initial_value_iter->second) { | 209 select_element.value() != initial_value_iter->second) { |
| 210 select_element.setValue(initial_value_iter->second); | 210 select_element.setValue(initial_value_iter->second); |
| 211 select_element.dispatchFormControlChangeEvent(); | 211 select_element.dispatchFormControlChangeEvent(); |
| 212 } | 212 } |
| 213 } else { | 213 } else { |
| 214 WebInputElement input_element = control_element.to<WebInputElement>(); | 214 WebInputElement input_element = control_element.to<WebInputElement>(); |
| 215 DCHECK(IsCheckableElement(&input_element)); | 215 DCHECK(IsCheckableElement(&input_element)); |
| 216 std::map<const WebInputElement, bool>::const_iterator it = | 216 std::map<const WebInputElement, bool>::const_iterator it = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 240 form_element = web_forms[i]; | 240 form_element = web_forms[i]; |
| 241 | 241 |
| 242 // Note: matching on the form name here which is not guaranteed to be | 242 // Note: matching on the form name here which is not guaranteed to be |
| 243 // unique for the page, nor is it guaranteed to be non-empty. Ideally, we | 243 // unique for the page, nor is it guaranteed to be non-empty. Ideally, we |
| 244 // would have a way to uniquely identify the form cross-process. For now, | 244 // would have a way to uniquely identify the form cross-process. For now, |
| 245 // we'll check form name and form action for identity. | 245 // we'll check form name and form action for identity. |
| 246 // Also note that WebString() == WebString(string16()) does not evaluate | 246 // Also note that WebString() == WebString(string16()) does not evaluate |
| 247 // to |true| -- WebKit distinguishes between a "null" string (lhs) and an | 247 // to |true| -- WebKit distinguishes between a "null" string (lhs) and an |
| 248 // "empty" string (rhs). We don't want that distinction, so forcing to | 248 // "empty" string (rhs). We don't want that distinction, so forcing to |
| 249 // string16. | 249 // string16. |
| 250 string16 element_name = GetFormIdentifier(form_element); | 250 base::string16 element_name = GetFormIdentifier(form_element); |
| 251 GURL action(form_element.document().completeURL(form_element.action())); | 251 GURL action(form_element.document().completeURL(form_element.action())); |
| 252 if (element_name == form.data.name && action == form.data.action) { | 252 if (element_name == form.data.name && action == form.data.action) { |
| 253 found_form = true; | 253 found_form = true; |
| 254 break; | 254 break; |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 if (!found_form) | 259 if (!found_form) |
| 260 return false; | 260 return false; |
| 261 | 261 |
| 262 std::vector<WebFormControlElement> control_elements; | 262 std::vector<WebFormControlElement> control_elements; |
| 263 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, | 263 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, |
| 264 &control_elements); | 264 &control_elements); |
| 265 if (control_elements.size() != form.fields.size()) { | 265 if (control_elements.size() != form.fields.size()) { |
| 266 // Keep things simple. Don't show predictions for forms that were modified | 266 // Keep things simple. Don't show predictions for forms that were modified |
| 267 // between page load and the server's response to our query. | 267 // between page load and the server's response to our query. |
| 268 return false; | 268 return false; |
| 269 } | 269 } |
| 270 | 270 |
| 271 for (size_t i = 0; i < control_elements.size(); ++i) { | 271 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 272 WebFormControlElement* element = &control_elements[i]; | 272 WebFormControlElement* element = &control_elements[i]; |
| 273 | 273 |
| 274 if (string16(element->nameForAutofill()) != form.data.fields[i].name) { | 274 if (base::string16(element->nameForAutofill()) != |
| 275 form.data.fields[i].name) { |
| 275 // Keep things simple. Don't show predictions for elements whose names | 276 // Keep things simple. Don't show predictions for elements whose names |
| 276 // were modified between page load and the server's response to our query. | 277 // were modified between page load and the server's response to our query. |
| 277 continue; | 278 continue; |
| 278 } | 279 } |
| 279 | 280 |
| 280 std::string placeholder = form.fields[i].overall_type; | 281 std::string placeholder = form.fields[i].overall_type; |
| 281 string16 title = l10n_util::GetStringFUTF16( | 282 base::string16 title = l10n_util::GetStringFUTF16( |
| 282 IDS_AUTOFILL_SHOW_PREDICTIONS_TITLE, | 283 IDS_AUTOFILL_SHOW_PREDICTIONS_TITLE, |
| 283 UTF8ToUTF16(form.fields[i].heuristic_type), | 284 UTF8ToUTF16(form.fields[i].heuristic_type), |
| 284 UTF8ToUTF16(form.fields[i].server_type), | 285 UTF8ToUTF16(form.fields[i].server_type), |
| 285 UTF8ToUTF16(form.fields[i].signature), | 286 UTF8ToUTF16(form.fields[i].signature), |
| 286 UTF8ToUTF16(form.signature), | 287 UTF8ToUTF16(form.signature), |
| 287 UTF8ToUTF16(form.experiment_id)); | 288 UTF8ToUTF16(form.experiment_id)); |
| 288 if (!element->hasAttribute("placeholder")) | 289 if (!element->hasAttribute("placeholder")) |
| 289 element->setAttribute("placeholder", WebString(UTF8ToUTF16(placeholder))); | 290 element->setAttribute("placeholder", WebString(UTF8ToUTF16(placeholder))); |
| 290 element->setAttribute("title", WebString(title)); | 291 element->setAttribute("title", WebString(title)); |
| 291 } | 292 } |
| 292 | 293 |
| 293 return true; | 294 return true; |
| 294 } | 295 } |
| 295 | 296 |
| 296 } // namespace autofill | 297 } // namespace autofill |
| OLD | NEW |