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 <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.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 "components/autofill/content/public/interfaces/autofill_agent.mojom.h" | 15 #include "components/autofill/content/public/interfaces/autofill_agent.mojom.h" |
16 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" | 16 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" |
17 #include "components/autofill/content/renderer/form_cache.h" | 17 #include "components/autofill/content/renderer/form_cache.h" |
18 #include "components/autofill/content/renderer/page_click_listener.h" | 18 #include "components/autofill/content/renderer/page_click_listener.h" |
19 #include "content/public/renderer/render_frame_observer.h" | 19 #include "content/public/renderer/render_frame_observer.h" |
20 #include "content/public/renderer/render_view_observer.h" | 20 #include "content/public/renderer/render_view_observer.h" |
21 #include "mojo/public/cpp/bindings/binding_set.h" | 21 #include "mojo/public/cpp/bindings/binding.h" |
22 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 22 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
23 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 23 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
24 #include "third_party/WebKit/public/web/WebFormElement.h" | 24 #include "third_party/WebKit/public/web/WebFormElement.h" |
25 #include "third_party/WebKit/public/web/WebInputElement.h" | 25 #include "third_party/WebKit/public/web/WebInputElement.h" |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 class WebNode; | 28 class WebNode; |
29 class WebView; | 29 class WebView; |
30 } | 30 } |
31 | 31 |
(...skipping 20 matching lines...) Expand all Loading... |
52 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. | 52 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. |
53 // PasswordGenerationAgent may be NULL. If it is not, then it is also | 53 // PasswordGenerationAgent may be NULL. If it is not, then it is also |
54 // guaranteed to outlive AutofillAgent. | 54 // guaranteed to outlive AutofillAgent. |
55 AutofillAgent(content::RenderFrame* render_frame, | 55 AutofillAgent(content::RenderFrame* render_frame, |
56 PasswordAutofillAgent* password_autofill_manager, | 56 PasswordAutofillAgent* password_autofill_manager, |
57 PasswordGenerationAgent* password_generation_agent); | 57 PasswordGenerationAgent* password_generation_agent); |
58 ~AutofillAgent() override; | 58 ~AutofillAgent() override; |
59 | 59 |
60 void BindRequest(mojom::AutofillAgentRequest request); | 60 void BindRequest(mojom::AutofillAgentRequest request); |
61 | 61 |
| 62 const mojom::AutofillDriverPtr& GetMojoAutofillDriver(); |
| 63 |
| 64 // mojom::AutofillAgent: |
| 65 void FirstUserGestureObservedInTab() override; |
| 66 void FillForm(int32_t id, const FormData& form) override; |
| 67 void PreviewForm(int32_t id, const FormData& form) override; |
| 68 void FieldTypePredictionsAvailable( |
| 69 mojo::Array<FormDataPredictions> forms) override; |
| 70 void ClearForm() override; |
| 71 void ClearPreviewedForm() override; |
| 72 void FillFieldWithValue(const mojo::String& value) override; |
| 73 void PreviewFieldWithValue(const mojo::String& value) override; |
| 74 void AcceptDataListSuggestion(const mojo::String& value) override; |
| 75 void FillPasswordSuggestion(const mojo::String& username, |
| 76 const mojo::String& password) override; |
| 77 void PreviewPasswordSuggestion(const mojo::String& username, |
| 78 const mojo::String& password) override; |
| 79 void ShowInitialPasswordAccountSuggestions( |
| 80 int32_t key, |
| 81 const PasswordFormFillData& form_data) override; |
| 82 |
62 private: | 83 private: |
63 // Functor used as a simplified comparison function for FormData. Only | 84 // Functor used as a simplified comparison function for FormData. Only |
64 // compares forms at a high level (notably name, origin, action). | 85 // compares forms at a high level (notably name, origin, action). |
65 struct FormDataCompare { | 86 struct FormDataCompare { |
66 bool operator()(const FormData& lhs, const FormData& rhs) const; | 87 bool operator()(const FormData& lhs, const FormData& rhs) const; |
67 }; | 88 }; |
68 | 89 |
69 // Thunk class for RenderViewObserver methods that haven't yet been migrated | 90 // Thunk class for RenderViewObserver methods that haven't yet been migrated |
70 // to RenderFrameObserver. Should eventually be removed. | 91 // to RenderFrameObserver. Should eventually be removed. |
71 // http://crbug.com/433486 | 92 // http://crbug.com/433486 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // be elided because of the current value of |element| (relevant for inline | 132 // be elided because of the current value of |element| (relevant for inline |
112 // autocomplete). | 133 // autocomplete). |
113 bool show_full_suggestion_list; | 134 bool show_full_suggestion_list; |
114 | 135 |
115 // Specifies that only show a suggestions box if |element| is part of a | 136 // Specifies that only show a suggestions box if |element| is part of a |
116 // password form, otherwise show no suggestions. | 137 // password form, otherwise show no suggestions. |
117 bool show_password_suggestions_only; | 138 bool show_password_suggestions_only; |
118 }; | 139 }; |
119 | 140 |
120 // content::RenderFrameObserver: | 141 // content::RenderFrameObserver: |
121 bool OnMessageReceived(const IPC::Message& message) override; | |
122 void DidCommitProvisionalLoad(bool is_new_navigation, | 142 void DidCommitProvisionalLoad(bool is_new_navigation, |
123 bool is_same_page_navigation) override; | 143 bool is_same_page_navigation) override; |
124 void DidFinishDocumentLoad() override; | 144 void DidFinishDocumentLoad() override; |
125 void WillSendSubmitEvent(const blink::WebFormElement& form) override; | 145 void WillSendSubmitEvent(const blink::WebFormElement& form) override; |
126 void WillSubmitForm(const blink::WebFormElement& form) override; | 146 void WillSubmitForm(const blink::WebFormElement& form) override; |
127 void DidChangeScrollOffset() override; | 147 void DidChangeScrollOffset() override; |
128 void FocusedNodeChanged(const blink::WebNode& node) override; | 148 void FocusedNodeChanged(const blink::WebNode& node) override; |
129 void OnDestruct() override; | 149 void OnDestruct() override; |
130 | 150 |
131 // Fires IPC messages for a given form submission. Will always fire | 151 // Fires IPC messages for a given form submission. Will always fire |
(...skipping 24 matching lines...) Expand all Loading... |
156 const blink::WebInputElement& element, | 176 const blink::WebInputElement& element, |
157 const blink::WebKeyboardEvent& event) override; | 177 const blink::WebKeyboardEvent& event) override; |
158 void setIgnoreTextChanges(bool ignore) override; | 178 void setIgnoreTextChanges(bool ignore) override; |
159 void didAssociateFormControls( | 179 void didAssociateFormControls( |
160 const blink::WebVector<blink::WebNode>& nodes) override; | 180 const blink::WebVector<blink::WebNode>& nodes) override; |
161 void openTextDataListChooser(const blink::WebInputElement& element) override; | 181 void openTextDataListChooser(const blink::WebInputElement& element) override; |
162 void dataListOptionsChanged(const blink::WebInputElement& element) override; | 182 void dataListOptionsChanged(const blink::WebInputElement& element) override; |
163 void firstUserGestureObserved() override; | 183 void firstUserGestureObserved() override; |
164 void ajaxSucceeded() override; | 184 void ajaxSucceeded() override; |
165 | 185 |
166 void OnFieldTypePredictionsAvailable( | |
167 const std::vector<FormDataPredictions>& forms); | |
168 void OnFillForm(int query_id, const FormData& form); | |
169 void OnPing(); | 186 void OnPing(); |
170 void OnPreviewForm(int query_id, const FormData& form); | |
171 | |
172 // mojom::AutofillAgent: | |
173 void FirstUserGestureObservedInTab() override; | |
174 | |
175 // For external Autofill selection. | |
176 void OnClearForm(); | |
177 void OnClearPreviewedForm(); | |
178 void OnFillFieldWithValue(const base::string16& value); | |
179 void OnPreviewFieldWithValue(const base::string16& value); | |
180 void OnAcceptDataListSuggestion(const base::string16& value); | |
181 void OnFillPasswordSuggestion(const base::string16& username, | |
182 const base::string16& password); | |
183 void OnPreviewPasswordSuggestion(const base::string16& username, | |
184 const base::string16& password); | |
185 void OnShowInitialPasswordAccountSuggestions( | |
186 int key, | |
187 const PasswordFormFillData& form_data); | |
188 | 187 |
189 // Called when a same-page navigation is detected. | 188 // Called when a same-page navigation is detected. |
190 void OnSamePageNavigationCompleted(); | 189 void OnSamePageNavigationCompleted(); |
191 // Helper method which collects unowned elements (i.e., those not inside a | 190 // Helper method which collects unowned elements (i.e., those not inside a |
192 // form tag) and writes them into |output|. Returns true if the process is | 191 // form tag) and writes them into |output|. Returns true if the process is |
193 // successful, and all conditions for firing events are true. | 192 // successful, and all conditions for firing events are true. |
194 bool CollectFormlessElements(FormData* output); | 193 bool CollectFormlessElements(FormData* output); |
195 FRIEND_TEST_ALL_PREFIXES(FormAutocompleteTest, CollectFormlessElements); | 194 FRIEND_TEST_ALL_PREFIXES(FormAutocompleteTest, CollectFormlessElements); |
196 | 195 |
197 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug | 196 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug |
198 // http://bugs.webkit.org/show_bug.cgi?id=16976 | 197 // http://bugs.webkit.org/show_bug.cgi?id=16976 |
199 void TextFieldDidChangeImpl(const blink::WebFormControlElement& element); | 198 void TextFieldDidChangeImpl(const blink::WebFormControlElement& element); |
200 | 199 |
201 // Shows the autofill suggestions for |element|. This call is asynchronous | 200 // Shows the autofill suggestions for |element|. This call is asynchronous |
202 // and may or may not lead to the showing of a suggestion popup (no popup is | 201 // and may or may not lead to the showing of a suggestion popup (no popup is |
203 // shown if there are no available suggestions). | 202 // shown if there are no available suggestions). |
204 void ShowSuggestions(const blink::WebFormControlElement& element, | 203 void ShowSuggestions(const blink::WebFormControlElement& element, |
205 const ShowSuggestionsOptions& options); | 204 const ShowSuggestionsOptions& options); |
206 | 205 |
207 // Queries the browser for Autocomplete and Autofill suggestions for the given | 206 // Queries the browser for Autocomplete and Autofill suggestions for the given |
208 // |element|. | 207 // |element|. |
209 void QueryAutofillSuggestions(const blink::WebFormControlElement& element); | 208 void QueryAutofillSuggestions(const blink::WebFormControlElement& element); |
210 | 209 |
211 // Sets the element value to reflect the selected |suggested_value|. | 210 // Sets the element value to reflect the selected |suggested_value|. |
212 void AcceptDataListSuggestion(const base::string16& suggested_value); | 211 void DoAcceptDataListSuggestion(const base::string16& suggested_value); |
213 | 212 |
214 // Fills |form| and |field| with the FormData and FormField corresponding to | 213 // Fills |form| and |field| with the FormData and FormField corresponding to |
215 // |node|. Returns true if the data was found; and false otherwise. | 214 // |node|. Returns true if the data was found; and false otherwise. |
216 bool FindFormAndFieldForNode( | 215 bool FindFormAndFieldForNode( |
217 const blink::WebNode& node, | 216 const blink::WebNode& node, |
218 FormData* form, | 217 FormData* form, |
219 FormFieldData* field) WARN_UNUSED_RESULT; | 218 FormFieldData* field) WARN_UNUSED_RESULT; |
220 | 219 |
221 // Set |node| to display the given |value|. | 220 // Set |node| to display the given |value|. |
222 void FillFieldWithValue(const base::string16& value, | 221 void DoFillFieldWithValue(const base::string16& value, |
223 blink::WebInputElement* node); | 222 blink::WebInputElement* node); |
224 | 223 |
225 // Set |node| to display the given |value| as a preview. The preview is | 224 // Set |node| to display the given |value| as a preview. The preview is |
226 // visible on screen to the user, but not visible to the page via the DOM or | 225 // visible on screen to the user, but not visible to the page via the DOM or |
227 // JavaScript. | 226 // JavaScript. |
228 void PreviewFieldWithValue(const base::string16& value, | 227 void DoPreviewFieldWithValue(const base::string16& value, |
229 blink::WebInputElement* node); | 228 blink::WebInputElement* node); |
230 | 229 |
231 // Notifies browser of new fillable forms in |render_frame|. | 230 // Notifies browser of new fillable forms in |render_frame|. |
232 void ProcessForms(); | 231 void ProcessForms(); |
233 | 232 |
234 // Sends a message to the browser that the form is about to be submitted, | 233 // Sends a message to the browser that the form is about to be submitted, |
235 // only if the particular message has not been previously submitted for the | 234 // only if the particular message has not been previously submitted for the |
236 // form in the current frame. | 235 // form in the current frame. |
237 // Additionally, depending on |send_submitted_event| a message is sent to the | 236 // Additionally, depending on |send_submitted_event| a message is sent to the |
238 // browser that the form was submitted. | 237 // browser that the form was submitted. |
239 void SendFormEvents(const blink::WebFormElement& form, | 238 void SendFormEvents(const blink::WebFormElement& form, |
240 bool send_submitted_event); | 239 bool send_submitted_event); |
241 | 240 |
242 // Hides any currently showing Autofill popup. | 241 // Hides any currently showing Autofill popup. |
243 void HidePopup(); | 242 void HidePopup(); |
244 | 243 |
245 // Returns true if the text field change is due to a user gesture. Can be | 244 // Returns true if the text field change is due to a user gesture. Can be |
246 // overriden in tests. | 245 // overriden in tests. |
247 virtual bool IsUserGesture() const; | 246 virtual bool IsUserGesture() const; |
248 | 247 |
249 void ConnectToMojoAutofillDriverIfNeeded(); | |
250 | |
251 // Formerly cached forms for all frames, now only caches forms for the current | 248 // Formerly cached forms for all frames, now only caches forms for the current |
252 // frame. | 249 // frame. |
253 FormCache form_cache_; | 250 FormCache form_cache_; |
254 | 251 |
255 // Keeps track of the forms for which a "will submit" message has been sent in | 252 // Keeps track of the forms for which a "will submit" message has been sent in |
256 // this frame's current load. We use a simplified comparison function. | 253 // this frame's current load. We use a simplified comparison function. |
257 std::set<FormData, FormDataCompare> submitted_forms_; | 254 std::set<FormData, FormDataCompare> submitted_forms_; |
258 | 255 |
259 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. | 256 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. |
260 PasswordGenerationAgent* password_generation_agent_; // Weak reference. | 257 PasswordGenerationAgent* password_generation_agent_; // Weak reference. |
(...skipping 30 matching lines...) Expand all Loading... |
291 // performance improvement, so that the IPC channel isn't flooded with | 288 // performance improvement, so that the IPC channel isn't flooded with |
292 // messages to close the Autofill popup when it can't possibly be showing. | 289 // messages to close the Autofill popup when it can't possibly be showing. |
293 bool is_popup_possibly_visible_; | 290 bool is_popup_possibly_visible_; |
294 | 291 |
295 // If the generation popup is possibly visible. This is tracked to prevent | 292 // If the generation popup is possibly visible. This is tracked to prevent |
296 // generation UI from displaying at the same time as password manager UI. | 293 // generation UI from displaying at the same time as password manager UI. |
297 // This is needed because generation is shown on field focus vs. field click | 294 // This is needed because generation is shown on field focus vs. field click |
298 // for the password manager. TODO(gcasto): Have both UIs show on focus. | 295 // for the password manager. TODO(gcasto): Have both UIs show on focus. |
299 bool is_generation_popup_possibly_visible_; | 296 bool is_generation_popup_possibly_visible_; |
300 | 297 |
301 mojo::BindingSet<mojom::AutofillAgent> bindings_; | 298 mojo::Binding<mojom::AutofillAgent> binding_; |
302 | 299 |
303 mojom::AutofillDriverPtr mojo_autofill_driver_; | 300 mojom::AutofillDriverPtr mojo_autofill_driver_; |
304 | 301 |
305 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; | 302 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; |
306 | 303 |
307 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); | 304 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); |
308 }; | 305 }; |
309 | 306 |
310 } // namespace autofill | 307 } // namespace autofill |
311 | 308 |
312 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 309 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
OLD | NEW |