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_autofill_util.h" | 5 #include "components/autofill/content/renderer/form_autofill_util.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 #include <limits> |
7 #include <map> | 9 #include <map> |
8 #include <memory> | 10 #include <memory> |
9 #include <set> | 11 #include <set> |
10 #include <vector> | 12 #include <vector> |
11 | 13 |
12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
15 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
16 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
(...skipping 19 matching lines...) Expand all Loading... |
36 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 38 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
37 #include "third_party/WebKit/public/web/WebNode.h" | 39 #include "third_party/WebKit/public/web/WebNode.h" |
38 #include "third_party/WebKit/public/web/WebOptionElement.h" | 40 #include "third_party/WebKit/public/web/WebOptionElement.h" |
39 #include "third_party/WebKit/public/web/WebSelectElement.h" | 41 #include "third_party/WebKit/public/web/WebSelectElement.h" |
40 | 42 |
41 using blink::WebDocument; | 43 using blink::WebDocument; |
42 using blink::WebElement; | 44 using blink::WebElement; |
43 using blink::WebElementCollection; | 45 using blink::WebElementCollection; |
44 using blink::WebFormControlElement; | 46 using blink::WebFormControlElement; |
45 using blink::WebFormElement; | 47 using blink::WebFormElement; |
46 using blink::WebFrame; | |
47 using blink::WebInputElement; | 48 using blink::WebInputElement; |
48 using blink::WebLabelElement; | 49 using blink::WebLabelElement; |
| 50 using blink::WebLocalFrame; |
49 using blink::WebNode; | 51 using blink::WebNode; |
50 using blink::WebOptionElement; | 52 using blink::WebOptionElement; |
51 using blink::WebSelectElement; | 53 using blink::WebSelectElement; |
52 using blink::WebString; | 54 using blink::WebString; |
53 using blink::WebVector; | 55 using blink::WebVector; |
54 | 56 |
55 namespace autofill { | 57 namespace autofill { |
56 namespace form_util { | 58 namespace form_util { |
57 | 59 |
58 const size_t kMaxParseableFields = 200; | 60 const size_t kMaxParseableFields = 200; |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 | 1189 |
1188 bool ExtractFormData(const WebFormElement& form_element, FormData* data) { | 1190 bool ExtractFormData(const WebFormElement& form_element, FormData* data) { |
1189 return WebFormElementToFormData( | 1191 return WebFormElementToFormData( |
1190 form_element, WebFormControlElement(), nullptr, | 1192 form_element, WebFormControlElement(), nullptr, |
1191 static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | | 1193 static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | |
1192 form_util::EXTRACT_OPTION_TEXT | | 1194 form_util::EXTRACT_OPTION_TEXT | |
1193 form_util::EXTRACT_OPTIONS), | 1195 form_util::EXTRACT_OPTIONS), |
1194 data, NULL); | 1196 data, NULL); |
1195 } | 1197 } |
1196 | 1198 |
1197 bool IsFormVisible(blink::WebFrame* frame, | 1199 bool IsFormVisible(blink::WebLocalFrame* frame, |
1198 const blink::WebFormElement& form_element, | 1200 const blink::WebFormElement& form_element, |
1199 const GURL& canonical_action, | 1201 const GURL& canonical_action, |
1200 const GURL& canonical_origin, | 1202 const GURL& canonical_origin, |
1201 const FormData& form_data) { | 1203 const FormData& form_data) { |
1202 const GURL frame_origin = GetCanonicalOriginForDocument(frame->GetDocument()); | 1204 const GURL frame_origin = GetCanonicalOriginForDocument(frame->GetDocument()); |
1203 blink::WebVector<WebFormElement> forms; | 1205 blink::WebVector<WebFormElement> forms; |
1204 frame->GetDocument().Forms(forms); | 1206 frame->GetDocument().Forms(forms); |
1205 | 1207 |
1206 // Omitting the action attribute would result in |canonical_origin| for | 1208 // Omitting the action attribute would result in |canonical_origin| for |
1207 // hierarchical schemes like http:, and in an empty URL for non-hierarchical | 1209 // hierarchical schemes like http:, and in an empty URL for non-hierarchical |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 field->value = value; | 1468 field->value = value; |
1467 } | 1469 } |
1468 | 1470 |
1469 bool WebFormElementToFormData( | 1471 bool WebFormElementToFormData( |
1470 const blink::WebFormElement& form_element, | 1472 const blink::WebFormElement& form_element, |
1471 const blink::WebFormControlElement& form_control_element, | 1473 const blink::WebFormControlElement& form_control_element, |
1472 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map, | 1474 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map, |
1473 ExtractMask extract_mask, | 1475 ExtractMask extract_mask, |
1474 FormData* form, | 1476 FormData* form, |
1475 FormFieldData* field) { | 1477 FormFieldData* field) { |
1476 const WebFrame* frame = form_element.GetDocument().GetFrame(); | 1478 const WebLocalFrame* frame = form_element.GetDocument().GetFrame(); |
1477 if (!frame) | 1479 if (!frame) |
1478 return false; | 1480 return false; |
1479 | 1481 |
1480 form->name = GetFormIdentifier(form_element); | 1482 form->name = GetFormIdentifier(form_element); |
1481 form->origin = GetCanonicalOriginForDocument(frame->GetDocument()); | 1483 form->origin = GetCanonicalOriginForDocument(frame->GetDocument()); |
1482 form->action = frame->GetDocument().CompleteURL(form_element.Action()); | 1484 form->action = frame->GetDocument().CompleteURL(form_element.Action()); |
1483 | 1485 |
1484 // If the completed URL is not valid, just use the action we get from | 1486 // If the completed URL is not valid, just use the action we get from |
1485 // WebKit. | 1487 // WebKit. |
1486 if (!form->action.is_valid()) | 1488 if (!form->action.is_valid()) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 } | 1757 } |
1756 } else if (IsSelectElement(control_element)) { | 1758 } else if (IsSelectElement(control_element)) { |
1757 control_element.SetSuggestedValue(WebString()); | 1759 control_element.SetSuggestedValue(WebString()); |
1758 control_element.SetAutofilled(false); | 1760 control_element.SetAutofilled(false); |
1759 } | 1761 } |
1760 } | 1762 } |
1761 | 1763 |
1762 return true; | 1764 return true; |
1763 } | 1765 } |
1764 | 1766 |
1765 bool IsWebpageEmpty(const blink::WebFrame* frame) { | 1767 bool IsWebpageEmpty(const blink::WebLocalFrame* frame) { |
1766 blink::WebDocument document = frame->GetDocument(); | 1768 blink::WebDocument document = frame->GetDocument(); |
1767 | 1769 |
1768 return IsWebElementEmpty(document.Head()) && | 1770 return IsWebElementEmpty(document.Head()) && |
1769 IsWebElementEmpty(document.Body()); | 1771 IsWebElementEmpty(document.Body()); |
1770 } | 1772 } |
1771 | 1773 |
1772 bool IsWebElementEmpty(const blink::WebElement& root) { | 1774 bool IsWebElementEmpty(const blink::WebElement& root) { |
1773 CR_DEFINE_STATIC_LOCAL(WebString, kScript, ("script")); | 1775 CR_DEFINE_STATIC_LOCAL(WebString, kScript, ("script")); |
1774 CR_DEFINE_STATIC_LOCAL(WebString, kMeta, ("meta")); | 1776 CR_DEFINE_STATIC_LOCAL(WebString, kMeta, ("meta")); |
1775 CR_DEFINE_STATIC_LOCAL(WebString, kTitle, ("title")); | 1777 CR_DEFINE_STATIC_LOCAL(WebString, kTitle, ("title")); |
(...skipping 27 matching lines...) Expand all Loading... |
1803 // Zero selection start is for password manager, which can show usernames | 1805 // Zero selection start is for password manager, which can show usernames |
1804 // that do not begin with the user input value. | 1806 // that do not begin with the user input value. |
1805 selection_start = (offset == base::string16::npos) ? 0 : offset; | 1807 selection_start = (offset == base::string16::npos) ? 0 : offset; |
1806 } | 1808 } |
1807 | 1809 |
1808 input_element->SetSelectionRange(selection_start, suggestion.length()); | 1810 input_element->SetSelectionRange(selection_start, suggestion.length()); |
1809 } | 1811 } |
1810 | 1812 |
1811 } // namespace form_util | 1813 } // namespace form_util |
1812 } // namespace autofill | 1814 } // namespace autofill |
OLD | NEW |