Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: components/autofill/content/renderer/autofill_agent.h

Issue 707173004: Refactor Autofill for out of process iframes (OOPIF). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update tests some more Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
80 virtual void textFieldDidReceiveKeyDown( 108 virtual void textFieldDidReceiveKeyDown(
81 const blink::WebInputElement& element, 109 const blink::WebInputElement& element,
82 const blink::WebKeyboardEvent& event); 110 const blink::WebKeyboardEvent& event);
83 virtual void didRequestAutocomplete( 111 virtual void didRequestAutocomplete(
84 const blink::WebFormElement& form); 112 const blink::WebFormElement& form);
85 virtual void setIgnoreTextChanges(bool ignore); 113 virtual void setIgnoreTextChanges(bool ignore);
86 virtual void didAssociateFormControls( 114 virtual void didAssociateFormControls(
87 const blink::WebVector<blink::WebNode>& nodes); 115 const blink::WebVector<blink::WebNode>& nodes);
88 virtual void openTextDataListChooser(const blink::WebInputElement& element); 116 virtual void openTextDataListChooser(const blink::WebInputElement& element);
89 virtual void firstUserGestureObserved(); 117 virtual void firstUserGestureObserved();
90 118
91 void OnFieldTypePredictionsAvailable( 119 void OnFieldTypePredictionsAvailable(
92 const std::vector<FormDataPredictions>& forms); 120 const std::vector<FormDataPredictions>& forms);
93 void OnFillForm(int query_id, const FormData& form); 121 void OnFillForm(int query_id, const FormData& form);
122 void OnFirstUserGestureObservedInTab();
94 void OnPing(); 123 void OnPing();
95 void OnPreviewForm(int query_id, const FormData& form); 124 void OnPreviewForm(int query_id, const FormData& form);
96 125
97 // For external Autofill selection. 126 // For external Autofill selection.
98 void OnClearForm(); 127 void OnClearForm();
99 void OnClearPreviewedForm(); 128 void OnClearPreviewedForm();
100 void OnFillFieldWithValue(const base::string16& value); 129 void OnFillFieldWithValue(const base::string16& value);
101 void OnPreviewFieldWithValue(const base::string16& value); 130 void OnPreviewFieldWithValue(const base::string16& value);
102 void OnAcceptDataListSuggestion(const base::string16& value); 131 void OnAcceptDataListSuggestion(const base::string16& value);
103 void OnFillPasswordSuggestion(const base::string16& username, 132 void OnFillPasswordSuggestion(const base::string16& username,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Set |node| to display the given |value|. 195 // Set |node| to display the given |value|.
167 void FillFieldWithValue(const base::string16& value, 196 void FillFieldWithValue(const base::string16& value,
168 blink::WebInputElement* node); 197 blink::WebInputElement* node);
169 198
170 // Set |node| to display the given |value| as a preview. The preview is 199 // 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 200 // visible on screen to the user, but not visible to the page via the DOM or
172 // JavaScript. 201 // JavaScript.
173 void PreviewFieldWithValue(const base::string16& value, 202 void PreviewFieldWithValue(const base::string16& value,
174 blink::WebInputElement* node); 203 blink::WebInputElement* node);
175 204
176 // Notifies browser of new fillable forms in |frame|. 205 // Notifies browser of new fillable forms in |render_frame|.
177 void ProcessForms(const blink::WebLocalFrame& frame); 206 void ProcessForms();
178 207
179 // Hides any currently showing Autofill popup. 208 // Hides any currently showing Autofill popup.
180 void HidePopup(); 209 void HidePopup();
181 210
211 // Formerly cached forms for all frames, now only caches forms for the current
212 // frame. TODO(estade): simplify |FormCache| to only work with a single frame.
182 FormCache form_cache_; 213 FormCache form_cache_;
183 214
184 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. 215 PasswordAutofillAgent* password_autofill_agent_; // Weak reference.
185 PasswordGenerationAgent* password_generation_agent_; // Weak reference. 216 PasswordGenerationAgent* password_generation_agent_; // Weak reference.
186 217
218 // Passes through RenderViewObserver methods to |this|.
219 LegacyAutofillAgent legacy_;
220
221 // Tracks clicks on the RenderViewHost, informs |this|.
222 PageClickTracker page_click_tracker_;
223
187 // The ID of the last request sent for form field Autofill. Used to ignore 224 // The ID of the last request sent for form field Autofill. Used to ignore
188 // out of date responses. 225 // out of date responses.
189 int autofill_query_id_; 226 int autofill_query_id_;
190 227
191 // The element corresponding to the last request sent for form field Autofill. 228 // The element corresponding to the last request sent for form field Autofill.
192 blink::WebFormControlElement element_; 229 blink::WebFormControlElement element_;
193 230
194 // The form element currently requesting an interactive autocomplete. 231 // The form element currently requesting an interactive autocomplete.
195 blink::WebFormElement in_flight_request_form_; 232 blink::WebFormElement in_flight_request_form_;
196 233
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? 234 // Should we display a warning if autofill is disabled?
201 bool display_warning_if_disabled_; 235 bool display_warning_if_disabled_;
202 236
203 // Was the query node autofilled prior to previewing the form? 237 // Was the query node autofilled prior to previewing the form?
204 bool was_query_node_autofilled_; 238 bool was_query_node_autofilled_;
205 239
206 // Have we already shown Autofill suggestions for the field the user is 240 // Have we already shown Autofill suggestions for the field the user is
207 // currently editing? Used to keep track of state for metrics logging. 241 // currently editing? Used to keep track of state for metrics logging.
208 bool has_shown_autofill_popup_for_current_edit_; 242 bool has_shown_autofill_popup_for_current_edit_;
209 243
210 // If true we just set the node text so we shouldn't show the popup. 244 // If true we just set the node text so we shouldn't show the popup.
211 bool did_set_node_text_; 245 bool did_set_node_text_;
212 246
213 // Whether or not to ignore text changes. Useful for when we're committing 247 // 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 248 // a composition when we are defocusing the WebView and we don't want to
215 // trigger an autofill popup to show. 249 // trigger an autofill popup to show.
216 bool ignore_text_changes_; 250 bool ignore_text_changes_;
217 251
218 // Whether the Autofill popup is possibly visible. This is tracked as a 252 // Whether the Autofill popup is possibly visible. This is tracked as a
219 // performance improvement, so that the IPC channel isn't flooded with 253 // 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. 254 // messages to close the Autofill popup when it can't possibly be showing.
221 bool is_popup_possibly_visible_; 255 bool is_popup_possibly_visible_;
222 256
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_; 257 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
229 258
230 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); 259 DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
231 }; 260 };
232 261
233 } // namespace autofill 262 } // namespace autofill
234 263
235 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ 264 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698