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 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "components/autofill/content/renderer/form_cache.h" | 16 #include "components/autofill/content/renderer/form_cache.h" |
17 #include "components/autofill/content/renderer/page_click_listener.h" | 17 #include "components/autofill/content/renderer/page_click_listener.h" |
18 #include "components/autofill/core/common/forms_seen_state.h" | 18 #include "components/autofill/core/common/forms_seen_state.h" |
19 #include "content/public/renderer/render_view_observer.h" | 19 #include "content/public/renderer/render_view_observer.h" |
20 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 20 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
| 21 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
21 #include "third_party/WebKit/public/web/WebFormElement.h" | 22 #include "third_party/WebKit/public/web/WebFormElement.h" |
22 #include "third_party/WebKit/public/web/WebInputElement.h" | 23 #include "third_party/WebKit/public/web/WebInputElement.h" |
23 | 24 |
24 namespace blink { | 25 namespace blink { |
25 class WebNode; | 26 class WebNode; |
26 class WebView; | 27 class WebView; |
27 } | 28 } |
28 | 29 |
29 namespace autofill { | 30 namespace autofill { |
30 | 31 |
(...skipping 30 matching lines...) Expand all Loading... |
61 virtual void DidFinishDocumentLoad(blink::WebFrame* frame) OVERRIDE; | 62 virtual void DidFinishDocumentLoad(blink::WebFrame* frame) OVERRIDE; |
62 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; | 63 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; |
63 virtual void WillSubmitForm(blink::WebFrame* frame, | 64 virtual void WillSubmitForm(blink::WebFrame* frame, |
64 const blink::WebFormElement& form) OVERRIDE; | 65 const blink::WebFormElement& form) OVERRIDE; |
65 virtual void ZoomLevelChanged() OVERRIDE; | 66 virtual void ZoomLevelChanged() OVERRIDE; |
66 virtual void DidChangeScrollOffset(blink::WebFrame* frame) OVERRIDE; | 67 virtual void DidChangeScrollOffset(blink::WebFrame* frame) OVERRIDE; |
67 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; | 68 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; |
68 virtual void OrientationChangeEvent(int orientation) OVERRIDE; | 69 virtual void OrientationChangeEvent(int orientation) OVERRIDE; |
69 | 70 |
70 // PageClickListener: | 71 // PageClickListener: |
71 virtual void InputElementClicked(const blink::WebInputElement& element, | 72 virtual void FormControlElementClicked( |
72 bool was_focused, | 73 const blink::WebFormControlElement& element, |
73 bool is_focused) OVERRIDE; | 74 bool was_focused) OVERRIDE; |
74 virtual void InputElementLostFocus() OVERRIDE; | 75 virtual void FormControlElementLostFocus() OVERRIDE; |
75 | 76 |
76 // blink::WebAutofillClient: | 77 // blink::WebAutofillClient: |
77 virtual void textFieldDidEndEditing( | 78 virtual void textFieldDidEndEditing( |
78 const blink::WebInputElement& element) OVERRIDE; | 79 const blink::WebInputElement& element) OVERRIDE; |
| 80 // TODO(ziran.sun): To be removed once next Blink roll is done |
79 virtual void textFieldDidChange( | 81 virtual void textFieldDidChange( |
80 const blink::WebInputElement& element) OVERRIDE; | 82 const blink::WebInputElement& element); |
| 83 // TODO(ziran.sun): OVERRIDE this function once next Blink roll is done |
| 84 virtual void textFieldDidChange( |
| 85 const blink::WebFormControlElement& element); |
81 virtual void textFieldDidReceiveKeyDown( | 86 virtual void textFieldDidReceiveKeyDown( |
82 const blink::WebInputElement& element, | 87 const blink::WebInputElement& element, |
83 const blink::WebKeyboardEvent& event) OVERRIDE; | 88 const blink::WebKeyboardEvent& event) OVERRIDE; |
84 virtual void didRequestAutocomplete( | 89 virtual void didRequestAutocomplete( |
85 blink::WebFrame* frame, | 90 blink::WebFrame* frame, |
86 const blink::WebFormElement& form) OVERRIDE; | 91 const blink::WebFormElement& form) OVERRIDE; |
87 virtual void setIgnoreTextChanges(bool ignore) OVERRIDE; | 92 virtual void setIgnoreTextChanges(bool ignore) OVERRIDE; |
88 virtual void didAssociateFormControls( | 93 virtual void didAssociateFormControls( |
89 const blink::WebVector<blink::WebNode>& nodes) OVERRIDE; | 94 const blink::WebVector<blink::WebNode>& nodes) OVERRIDE; |
90 virtual void openTextDataListChooser(const blink::WebInputElement& element); | 95 virtual void openTextDataListChooser(const blink::WebInputElement& element); |
(...skipping 14 matching lines...) Expand all Loading... |
105 void OnRequestAutocompleteResult( | 110 void OnRequestAutocompleteResult( |
106 blink::WebFormElement::AutocompleteResult result, | 111 blink::WebFormElement::AutocompleteResult result, |
107 const FormData& form_data); | 112 const FormData& form_data); |
108 | 113 |
109 // Called when an autocomplete request succeeds or fails with the |result|. | 114 // Called when an autocomplete request succeeds or fails with the |result|. |
110 void FinishAutocompleteRequest( | 115 void FinishAutocompleteRequest( |
111 blink::WebFormElement::AutocompleteResult result); | 116 blink::WebFormElement::AutocompleteResult result); |
112 | 117 |
113 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug | 118 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug |
114 // http://bugs.webkit.org/show_bug.cgi?id=16976 | 119 // http://bugs.webkit.org/show_bug.cgi?id=16976 |
115 void TextFieldDidChangeImpl(const blink::WebInputElement& element); | 120 void TextFieldDidChangeImpl(const blink::WebFormControlElement& element); |
116 | 121 |
117 // Shows the autofill suggestions for |element|. | 122 // Shows the autofill suggestions for |element|. |
118 // This call is asynchronous and may or may not lead to the showing of a | 123 // This call is asynchronous and may or may not lead to the showing of a |
119 // suggestion popup (no popup is shown if there are no available suggestions). | 124 // suggestion popup (no popup is shown if there are no available suggestions). |
120 // |autofill_on_empty_values| specifies whether suggestions should be shown | 125 // |autofill_on_empty_values| specifies whether suggestions should be shown |
121 // when |element| contains no text. | 126 // when |element| contains no text. |
122 // |requires_caret_at_end| specifies whether suggestions should be shown when | 127 // |requires_caret_at_end| specifies whether suggestions should be shown when |
123 // the caret is not after the last character in |element|. | 128 // the caret is not after the last character in |element|. |
124 // |display_warning_if_disabled| specifies whether a warning should be | 129 // |display_warning_if_disabled| specifies whether a warning should be |
125 // displayed to the user if Autofill has suggestions available, but cannot | 130 // displayed to the user if Autofill has suggestions available, but cannot |
126 // fill them because it is disabled (e.g. when trying to fill a credit card | 131 // fill them because it is disabled (e.g. when trying to fill a credit card |
127 // form on a non-secure website). | 132 // form on a non-secure website). |
128 // |datalist_only| specifies whether all of <datalist> suggestions and no | 133 // |datalist_only| specifies whether all of <datalist> suggestions and no |
129 // autofill suggestions are shown. |autofill_on_empty_values| and | 134 // autofill suggestions are shown. |autofill_on_empty_values| and |
130 // |requires_caret_at_end| are ignored if |datalist_only| is true. | 135 // |requires_caret_at_end| are ignored if |datalist_only| is true. |
131 void ShowSuggestions(const blink::WebInputElement& element, | 136 void ShowSuggestions(const blink::WebFormControlElement& element, |
132 bool autofill_on_empty_values, | 137 bool autofill_on_empty_values, |
133 bool requires_caret_at_end, | 138 bool requires_caret_at_end, |
134 bool display_warning_if_disabled, | 139 bool display_warning_if_disabled, |
135 bool datalist_only); | 140 bool datalist_only); |
136 | 141 |
137 // Queries the browser for Autocomplete and Autofill suggestions for the given | 142 // Queries the browser for Autocomplete and Autofill suggestions for the given |
138 // |element|. | 143 // |element|. |
139 void QueryAutofillSuggestions(const blink::WebInputElement& element, | 144 void QueryAutofillSuggestions(const blink::WebFormControlElement& element, |
140 bool display_warning_if_disabled, | 145 bool display_warning_if_disabled, |
141 bool datalist_only); | 146 bool datalist_only); |
142 | 147 |
143 // Sets the element value to reflect the selected |suggested_value|. | 148 // Sets the element value to reflect the selected |suggested_value|. |
144 void AcceptDataListSuggestion(const base::string16& suggested_value); | 149 void AcceptDataListSuggestion(const base::string16& suggested_value); |
145 | 150 |
146 // Fills |form| and |field| with the FormData and FormField corresponding to | 151 // Fills |form| and |field| with the FormData and FormField corresponding to |
147 // |node|. Returns true if the data was found; and false otherwise. | 152 // |node|. Returns true if the data was found; and false otherwise. |
148 bool FindFormAndFieldForNode( | 153 bool FindFormAndFieldForNode( |
149 const blink::WebNode& node, | 154 const blink::WebNode& node, |
150 FormData* form, | 155 FormData* form, |
151 FormFieldData* field) WARN_UNUSED_RESULT; | 156 FormFieldData* field) WARN_UNUSED_RESULT; |
152 | 157 |
153 // Set |node| to display the given |value|. | 158 // Set |node| to display the given |value|. |
154 void SetNodeText(const base::string16& value, blink::WebInputElement* node); | 159 void SetNodeText(const base::string16& value, blink::WebInputElement* node); |
155 | 160 |
156 // Hides any currently showing Autofill popup. | 161 // Hides any currently showing Autofill popup. |
157 void HidePopup(); | 162 void HidePopup(); |
158 | 163 |
159 FormCache form_cache_; | 164 FormCache form_cache_; |
160 | 165 |
161 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. | 166 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. |
162 PasswordGenerationAgent* password_generation_agent_; // Weak reference. | 167 PasswordGenerationAgent* password_generation_agent_; // Weak reference. |
163 | 168 |
164 // The ID of the last request sent for form field Autofill. Used to ignore | 169 // The ID of the last request sent for form field Autofill. Used to ignore |
165 // out of date responses. | 170 // out of date responses. |
166 int autofill_query_id_; | 171 int autofill_query_id_; |
167 | 172 |
168 // The element corresponding to the last request sent for form field Autofill. | 173 // The element corresponding to the last request sent for form field Autofill. |
169 blink::WebInputElement element_; | 174 blink::WebFormControlElement element_; |
170 | 175 |
171 // The form element currently requesting an interactive autocomplete. | 176 // The form element currently requesting an interactive autocomplete. |
172 blink::WebFormElement in_flight_request_form_; | 177 blink::WebFormElement in_flight_request_form_; |
173 | 178 |
174 // All the form elements seen in the top frame. | 179 // All the form elements seen in the top frame. |
175 std::vector<blink::WebFormElement> form_elements_; | 180 std::vector<blink::WebFormElement> form_elements_; |
176 | 181 |
177 // Pointer to the WebView. Used to access page scale factor. | 182 // Pointer to the WebView. Used to access page scale factor. |
178 blink::WebView* web_view_; | 183 blink::WebView* web_view_; |
179 | 184 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 FRIEND_TEST_ALL_PREFIXES( | 224 FRIEND_TEST_ALL_PREFIXES( |
220 PasswordAutofillAgentTest, | 225 PasswordAutofillAgentTest, |
221 PasswordAutofillTriggersOnChangeEventsWaitForUsername); | 226 PasswordAutofillTriggersOnChangeEventsWaitForUsername); |
222 | 227 |
223 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); | 228 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); |
224 }; | 229 }; |
225 | 230 |
226 } // namespace autofill | 231 } // namespace autofill |
227 | 232 |
228 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 233 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
OLD | NEW |