Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/content/renderer/form_cache.h" | 5 #include "components/autofill/content/renderer/form_cache.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/autofill/content/renderer/form_autofill_util.h" | 9 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 10 #include "components/autofill/core/common/autofill_constants.h" | 10 #include "components/autofill/core/common/autofill_constants.h" |
| 11 #include "components/autofill/core/common/form_data.h" | 11 #include "components/autofill/core/common/form_data.h" |
| 12 #include "components/autofill/core/common/form_data_predictions.h" | 12 #include "components/autofill/core/common/form_data_predictions.h" |
| 13 #include "components/autofill/core/common/form_field_data.h" | 13 #include "components/autofill/core/common/form_field_data.h" |
| 14 #include "components/autofill/core/common/form_field_data_predictions.h" | 14 #include "components/autofill/core/common/form_field_data_predictions.h" |
| 15 #include "grit/components_strings.h" | 15 #include "grit/components_strings.h" |
| 16 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
| 17 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
| 18 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | |
| 18 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebDocument.h" |
| 19 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 20 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 20 #include "third_party/WebKit/public/web/WebFormElement.h" | 21 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 21 #include "third_party/WebKit/public/web/WebInputElement.h" | 22 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 23 #include "third_party/WebKit/public/web/WebNodeList.h" | 24 #include "third_party/WebKit/public/web/WebNodeList.h" |
| 24 #include "third_party/WebKit/public/web/WebSelectElement.h" | 25 #include "third_party/WebKit/public/web/WebSelectElement.h" |
| 25 #include "third_party/WebKit/public/web/WebTextAreaElement.h" | 26 #include "third_party/WebKit/public/web/WebTextAreaElement.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 | 28 |
| 29 using blink::WebConsoleMessage; | |
| 28 using blink::WebDocument; | 30 using blink::WebDocument; |
| 29 using blink::WebFormControlElement; | 31 using blink::WebFormControlElement; |
| 30 using blink::WebFormElement; | 32 using blink::WebFormElement; |
| 31 using blink::WebFrame; | 33 using blink::WebFrame; |
| 32 using blink::WebInputElement; | 34 using blink::WebInputElement; |
| 33 using blink::WebSelectElement; | 35 using blink::WebSelectElement; |
| 34 using blink::WebTextAreaElement; | 36 using blink::WebTextAreaElement; |
| 35 using blink::WebString; | 37 using blink::WebString; |
| 36 using blink::WebVector; | 38 using blink::WebVector; |
| 37 | 39 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 std::vector<FormData>* forms) { | 75 std::vector<FormData>* forms) { |
| 74 WebDocument document = frame.document(); | 76 WebDocument document = frame.document(); |
| 75 if (document.isNull()) | 77 if (document.isNull()) |
| 76 return; | 78 return; |
| 77 | 79 |
| 78 web_documents_.insert(document); | 80 web_documents_.insert(document); |
| 79 | 81 |
| 80 WebVector<WebFormElement> web_forms; | 82 WebVector<WebFormElement> web_forms; |
| 81 document.forms(web_forms); | 83 document.forms(web_forms); |
| 82 | 84 |
| 85 // We log an error message for deprecated attributes, but only the first time | |
|
Ilya Sherman
2014/06/10 00:40:40
nit: "We log" -> "Log"
Evan Stade
2014/06/12 01:49:47
Done.
| |
| 86 // the form is parsed. | |
| 87 bool log_deprecation_messages = | |
| 88 parsed_forms_.find(&frame) == parsed_forms_.end(); | |
| 89 | |
| 83 size_t num_fields_seen = 0; | 90 size_t num_fields_seen = 0; |
| 84 for (size_t i = 0; i < web_forms.size(); ++i) { | 91 for (size_t i = 0; i < web_forms.size(); ++i) { |
| 85 WebFormElement form_element = web_forms[i]; | 92 WebFormElement form_element = web_forms[i]; |
| 86 | 93 |
| 87 std::vector<WebFormControlElement> control_elements; | 94 std::vector<WebFormControlElement> control_elements; |
| 88 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, | 95 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, |
| 89 &control_elements); | 96 &control_elements); |
| 90 | 97 |
| 91 size_t num_editable_elements = 0; | 98 size_t num_editable_elements = 0; |
| 92 for (size_t j = 0; j < control_elements.size(); ++j) { | 99 for (size_t j = 0; j < control_elements.size(); ++j) { |
| 93 WebFormControlElement element = control_elements[j]; | 100 WebFormControlElement element = control_elements[j]; |
| 94 | 101 |
| 102 if (log_deprecation_messages) { | |
| 103 std::string autocomplete_attribute = | |
| 104 base::UTF16ToUTF8(element.getAttribute("autocomplete")); | |
| 105 | |
| 106 static const char* deprecated[] = { "region", "locality" }; | |
|
Ilya Sherman
2014/06/10 00:40:40
nit: "const char*" -> "const char* const"
Evan Stade
2014/06/12 01:49:46
Done.
| |
| 107 for (size_t i = 0; i < arraysize(deprecated); ++i) { | |
| 108 if (autocomplete_attribute.find(deprecated[i]) != std::string::npos) { | |
| 109 WebConsoleMessage console_message = WebConsoleMessage( | |
| 110 WebConsoleMessage::LevelLog, | |
|
Ilya Sherman
2014/06/10 00:40:40
Wouldn't LevelWarning or LevelError be more approp
Evan Stade
2014/06/12 01:49:46
yea, I think warning is correct
| |
| 111 WebString(base::ASCIIToUTF16(std::string("autocomplete='") + | |
| 112 deprecated[i] + "' is deprecated and will soon be ignored. " | |
| 113 "See http://goo.gl/YjeSsW"))); | |
| 114 element.document().frame()->addMessageToConsole(console_message); | |
| 115 } | |
| 116 } | |
| 117 } | |
| 118 | |
| 95 // Save original values of <select> elements so we can restore them | 119 // Save original values of <select> elements so we can restore them |
| 96 // when |ClearFormWithNode()| is invoked. | 120 // when |ClearFormWithNode()| is invoked. |
| 97 if (IsSelectElement(element)) { | 121 if (IsSelectElement(element)) { |
| 98 const WebSelectElement select_element = | 122 const WebSelectElement select_element = |
| 99 element.toConst<WebSelectElement>(); | 123 element.toConst<WebSelectElement>(); |
| 100 initial_select_values_.insert(std::make_pair(select_element, | 124 initial_select_values_.insert(std::make_pair(select_element, |
| 101 select_element.value())); | 125 select_element.value())); |
| 102 ++num_editable_elements; | 126 ++num_editable_elements; |
| 103 } else if (IsTextAreaElement(element)) { | 127 } else if (IsTextAreaElement(element)) { |
| 104 ++num_editable_elements; | 128 ++num_editable_elements; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 element->setAttribute("placeholder", | 304 element->setAttribute("placeholder", |
| 281 WebString(base::UTF8ToUTF16(placeholder))); | 305 WebString(base::UTF8ToUTF16(placeholder))); |
| 282 } | 306 } |
| 283 element->setAttribute("title", WebString(title)); | 307 element->setAttribute("title", WebString(title)); |
| 284 } | 308 } |
| 285 | 309 |
| 286 return true; | 310 return true; |
| 287 } | 311 } |
| 288 | 312 |
| 289 } // namespace autofill | 313 } // namespace autofill |
| OLD | NEW |