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 "components/autofill/content/renderer/form_cache.h" | 15 #include "components/autofill/content/renderer/form_cache.h" |
16 #include "components/autofill/content/renderer/page_click_listener.h" | 16 #include "components/autofill/content/renderer/page_click_listener.h" |
| 17 #include "components/autofill/content/renderer/page_click_tracker.h" |
| 18 #include "content/public/renderer/render_frame_observer.h" |
17 #include "content/public/renderer/render_view_observer.h" | 19 #include "content/public/renderer/render_view_observer.h" |
18 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 20 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
19 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 21 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
20 #include "third_party/WebKit/public/web/WebFormElement.h" | 22 #include "third_party/WebKit/public/web/WebFormElement.h" |
21 #include "third_party/WebKit/public/web/WebInputElement.h" | 23 #include "third_party/WebKit/public/web/WebInputElement.h" |
22 | 24 |
23 namespace blink { | 25 namespace blink { |
24 class WebNode; | 26 class WebNode; |
25 class WebView; | 27 class WebView; |
26 } | 28 } |
27 | 29 |
28 namespace autofill { | 30 namespace autofill { |
29 | 31 |
30 struct FormData; | 32 struct FormData; |
31 struct FormFieldData; | 33 struct FormFieldData; |
32 struct WebElementDescriptor; | 34 struct WebElementDescriptor; |
33 class PasswordAutofillAgent; | 35 class PasswordAutofillAgent; |
34 class PasswordGenerationAgent; | 36 class PasswordGenerationAgent; |
35 | 37 |
36 // AutofillAgent deals with Autofill related communications between WebKit and | 38 // AutofillAgent deals with Autofill related communications between WebKit and |
37 // the browser. There is one AutofillAgent per RenderView. | 39 // the browser. There is one AutofillAgent per RenderFrame. |
38 // This code was originally part of RenderView. | |
39 // Note that Autofill encompasses: | 40 // Note that Autofill encompasses: |
40 // - single text field suggestions, that we usually refer to as Autocomplete, | 41 // - single text field suggestions, that we usually refer to as Autocomplete, |
41 // - password form fill, refered to as Password Autofill, and | 42 // - password form fill, refered to as Password Autofill, and |
42 // - entire form fill based on one field entry, referred to as Form Autofill. | 43 // - entire form fill based on one field entry, referred to as Form Autofill. |
43 | 44 |
44 class AutofillAgent : public content::RenderViewObserver, | 45 class AutofillAgent : public content::RenderFrameObserver, |
45 public PageClickListener, | 46 public PageClickListener, |
46 public blink::WebAutofillClient { | 47 public blink::WebAutofillClient { |
47 public: | 48 public: |
48 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. | 49 // PasswordAutofillAgent is guaranteed to outlive AutofillAgent. |
49 // PasswordGenerationAgent may be NULL. If it is not, then it is also | 50 // PasswordGenerationAgent may be NULL. If it is not, then it is also |
50 // guaranteed to outlive AutofillAgent. | 51 // guaranteed to outlive AutofillAgent. |
51 AutofillAgent(content::RenderView* render_view, | 52 AutofillAgent(content::RenderFrame* render_frame, |
52 PasswordAutofillAgent* password_autofill_manager, | 53 PasswordAutofillAgent* password_autofill_manager, |
53 PasswordGenerationAgent* password_generation_agent); | 54 PasswordGenerationAgent* password_generation_agent); |
54 virtual ~AutofillAgent(); | 55 virtual ~AutofillAgent(); |
55 | 56 |
56 private: | 57 private: |
57 // content::RenderViewObserver: | 58 // Thunk class for RenderViewObserver methods that haven't yet been migrated |
| 59 // to RenderFrameObserver. Should eventually be removed. |
| 60 // http://crbug.com/433486 |
| 61 class LegacyAutofillAgent : public content::RenderViewObserver { |
| 62 public: |
| 63 LegacyAutofillAgent(content::RenderView* render_view, AutofillAgent* agent); |
| 64 ~LegacyAutofillAgent() override; |
| 65 |
| 66 private: |
| 67 // content::RenderViewObserver: |
| 68 void OnDestruct() override; |
| 69 void FrameDetached(blink::WebFrame* frame) override; |
| 70 void WillSubmitForm(blink::WebLocalFrame* frame, |
| 71 const blink::WebFormElement& form) override; |
| 72 void DidChangeScrollOffset(blink::WebLocalFrame* frame) override; |
| 73 void FocusedNodeChanged(const blink::WebNode& node) override; |
| 74 void OrientationChangeEvent() override; |
| 75 void Resized() override; |
| 76 |
| 77 AutofillAgent* agent_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(LegacyAutofillAgent); |
| 80 }; |
| 81 friend class LegacyAutofillAgent; |
| 82 |
| 83 // content::RenderFrameObserver: |
58 bool OnMessageReceived(const IPC::Message& message) override; | 84 bool OnMessageReceived(const IPC::Message& message) override; |
59 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; | 85 void DidCommitProvisionalLoad(bool is_new_navigation) override; |
60 void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, | 86 void DidFinishDocumentLoad() override; |
61 bool is_new_navigation) override; | 87 void FrameWillClose() override; |
62 void FrameDetached(blink::WebFrame* frame) override; | 88 |
63 void FrameWillClose(blink::WebFrame* frame) override; | 89 // Pass-throughs from LegacyAutofillAgent. These correlate with |
| 90 // RenderViewObserver methods. |
| 91 void FrameDetached(blink::WebFrame* frame); |
64 void WillSubmitForm(blink::WebLocalFrame* frame, | 92 void WillSubmitForm(blink::WebLocalFrame* frame, |
65 const blink::WebFormElement& form) override; | 93 const blink::WebFormElement& form); |
66 void DidChangeScrollOffset(blink::WebLocalFrame* frame) override; | 94 void DidChangeScrollOffset(blink::WebLocalFrame* frame); |
67 void FocusedNodeChanged(const blink::WebNode& node) override; | 95 void FocusedNodeChanged(const blink::WebNode& node); |
68 void OrientationChangeEvent() override; | 96 void OrientationChangeEvent(); |
69 void Resized() override; | 97 void Resized(); |
70 | 98 |
71 // PageClickListener: | 99 // PageClickListener: |
72 void FormControlElementClicked(const blink::WebFormControlElement& element, | 100 void FormControlElementClicked(const blink::WebFormControlElement& element, |
73 bool was_focused) override; | 101 bool was_focused) override; |
74 | 102 |
75 // blink::WebAutofillClient: | 103 // blink::WebAutofillClient: |
76 virtual void textFieldDidEndEditing( | 104 virtual void textFieldDidEndEditing( |
77 const blink::WebInputElement& element); | 105 const blink::WebInputElement& element); |
78 virtual void textFieldDidChange( | 106 virtual void textFieldDidChange( |
79 const blink::WebFormControlElement& element); | 107 const blink::WebFormControlElement& element); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // Set |node| to display the given |value|. | 194 // Set |node| to display the given |value|. |
167 void FillFieldWithValue(const base::string16& value, | 195 void FillFieldWithValue(const base::string16& value, |
168 blink::WebInputElement* node); | 196 blink::WebInputElement* node); |
169 | 197 |
170 // Set |node| to display the given |value| as a preview. The preview is | 198 // Set |node| to display the given |value| as a preview. The preview is |
171 // visible on screen to the user, but not visible to the page via the DOM or | 199 // visible on screen to the user, but not visible to the page via the DOM or |
172 // JavaScript. | 200 // JavaScript. |
173 void PreviewFieldWithValue(const base::string16& value, | 201 void PreviewFieldWithValue(const base::string16& value, |
174 blink::WebInputElement* node); | 202 blink::WebInputElement* node); |
175 | 203 |
176 // Notifies browser of new fillable forms in |frame|. | 204 // Notifies browser of new fillable forms in |render_frame|. |
177 void ProcessForms(const blink::WebLocalFrame& frame); | 205 void ProcessForms(); |
178 | 206 |
179 // Hides any currently showing Autofill popup. | 207 // Hides any currently showing Autofill popup. |
180 void HidePopup(); | 208 void HidePopup(); |
181 | 209 |
| 210 // Formerly cached forms for all frames, now only caches forms for the current |
| 211 // frame. TODO(estade): simplify |FormCache| to only work with a single frame. |
182 FormCache form_cache_; | 212 FormCache form_cache_; |
183 | 213 |
184 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. | 214 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. |
185 PasswordGenerationAgent* password_generation_agent_; // Weak reference. | 215 PasswordGenerationAgent* password_generation_agent_; // Weak reference. |
186 | 216 |
| 217 // Passes through RenderViewObserver methods to |this|. |
| 218 LegacyAutofillAgent legacy_; |
| 219 |
| 220 // Tracks clicks on the RenderViewHost, informs |this|. |
| 221 PageClickTracker page_click_tracker_; |
| 222 |
187 // The ID of the last request sent for form field Autofill. Used to ignore | 223 // The ID of the last request sent for form field Autofill. Used to ignore |
188 // out of date responses. | 224 // out of date responses. |
189 int autofill_query_id_; | 225 int autofill_query_id_; |
190 | 226 |
191 // The element corresponding to the last request sent for form field Autofill. | 227 // The element corresponding to the last request sent for form field Autofill. |
192 blink::WebFormControlElement element_; | 228 blink::WebFormControlElement element_; |
193 | 229 |
194 // The form element currently requesting an interactive autocomplete. | 230 // The form element currently requesting an interactive autocomplete. |
195 blink::WebFormElement in_flight_request_form_; | 231 blink::WebFormElement in_flight_request_form_; |
196 | 232 |
197 // Pointer to the WebView. Used to access page scale factor. | |
198 blink::WebView* web_view_; | |
199 | |
200 // Should we display a warning if autofill is disabled? | 233 // Should we display a warning if autofill is disabled? |
201 bool display_warning_if_disabled_; | 234 bool display_warning_if_disabled_; |
202 | 235 |
203 // Was the query node autofilled prior to previewing the form? | 236 // Was the query node autofilled prior to previewing the form? |
204 bool was_query_node_autofilled_; | 237 bool was_query_node_autofilled_; |
205 | 238 |
206 // Have we already shown Autofill suggestions for the field the user is | 239 // Have we already shown Autofill suggestions for the field the user is |
207 // currently editing? Used to keep track of state for metrics logging. | 240 // currently editing? Used to keep track of state for metrics logging. |
208 bool has_shown_autofill_popup_for_current_edit_; | 241 bool has_shown_autofill_popup_for_current_edit_; |
209 | 242 |
210 // If true we just set the node text so we shouldn't show the popup. | 243 // If true we just set the node text so we shouldn't show the popup. |
211 bool did_set_node_text_; | 244 bool did_set_node_text_; |
212 | 245 |
213 // Whether or not to ignore text changes. Useful for when we're committing | 246 // Whether or not to ignore text changes. Useful for when we're committing |
214 // a composition when we are defocusing the WebView and we don't want to | 247 // a composition when we are defocusing the WebView and we don't want to |
215 // trigger an autofill popup to show. | 248 // trigger an autofill popup to show. |
216 bool ignore_text_changes_; | 249 bool ignore_text_changes_; |
217 | 250 |
218 // Whether the Autofill popup is possibly visible. This is tracked as a | 251 // Whether the Autofill popup is possibly visible. This is tracked as a |
219 // performance improvement, so that the IPC channel isn't flooded with | 252 // performance improvement, so that the IPC channel isn't flooded with |
220 // messages to close the Autofill popup when it can't possibly be showing. | 253 // messages to close the Autofill popup when it can't possibly be showing. |
221 bool is_popup_possibly_visible_; | 254 bool is_popup_possibly_visible_; |
222 | 255 |
223 // True if a message has already been sent about forms for the main frame. | |
224 // When the main frame is first loaded, a message is sent even if no forms | |
225 // exist in the frame. Otherwise, such messages are supressed. | |
226 bool main_frame_processed_; | |
227 | |
228 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; | 256 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; |
229 | 257 |
230 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); | 258 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); |
231 }; | 259 }; |
232 | 260 |
233 } // namespace autofill | 261 } // namespace autofill |
234 | 262 |
235 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ | 263 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ |
OLD | NEW |