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

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: self review Created 6 years 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 void FrameWillClose(blink::WebFrame* frame) override;
77
78 AutofillAgent* agent_;
79
80 DISALLOW_COPY_AND_ASSIGN(LegacyAutofillAgent);
81 };
82 friend class LegacyAutofillAgent;
83
84 // content::RenderFrameObserver:
58 bool OnMessageReceived(const IPC::Message& message) override; 85 bool OnMessageReceived(const IPC::Message& message) override;
59 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; 86 void DidCommitProvisionalLoad(bool is_new_navigation) override;
60 void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, 87 void DidFinishDocumentLoad() override;
61 bool is_new_navigation) override; 88
62 void FrameDetached(blink::WebFrame* frame) override; 89 // Pass-throughs from LegacyAutofillAgent. These correlate with
63 void FrameWillClose(blink::WebFrame* frame) override; 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();
98 void LegacyFrameWillClose(blink::WebFrame* frame);
70 99
71 // PageClickListener: 100 // PageClickListener:
72 void FormControlElementClicked(const blink::WebFormControlElement& element, 101 void FormControlElementClicked(const blink::WebFormControlElement& element,
73 bool was_focused) override; 102 bool was_focused) override;
74 103
75 // blink::WebAutofillClient: 104 // blink::WebAutofillClient:
76 virtual void textFieldDidEndEditing( 105 virtual void textFieldDidEndEditing(
77 const blink::WebInputElement& element); 106 const blink::WebInputElement& element);
78 virtual void textFieldDidChange( 107 virtual void textFieldDidChange(
79 const blink::WebFormControlElement& element); 108 const blink::WebFormControlElement& element);
80 virtual void textFieldDidReceiveKeyDown( 109 virtual void textFieldDidReceiveKeyDown(
81 const blink::WebInputElement& element, 110 const blink::WebInputElement& element,
82 const blink::WebKeyboardEvent& event); 111 const blink::WebKeyboardEvent& event);
83 virtual void didRequestAutocomplete( 112 virtual void didRequestAutocomplete(
84 const blink::WebFormElement& form); 113 const blink::WebFormElement& form);
85 virtual void setIgnoreTextChanges(bool ignore); 114 virtual void setIgnoreTextChanges(bool ignore);
86 virtual void didAssociateFormControls( 115 virtual void didAssociateFormControls(
87 const blink::WebVector<blink::WebNode>& nodes); 116 const blink::WebVector<blink::WebNode>& nodes);
88 virtual void openTextDataListChooser(const blink::WebInputElement& element); 117 virtual void openTextDataListChooser(const blink::WebInputElement& element);
89 virtual void firstUserGestureObserved(); 118 virtual void firstUserGestureObserved();
90 119
91 void OnFieldTypePredictionsAvailable( 120 void OnFieldTypePredictionsAvailable(
92 const std::vector<FormDataPredictions>& forms); 121 const std::vector<FormDataPredictions>& forms);
93 void OnFillForm(int query_id, const FormData& form); 122 void OnFillForm(int query_id, const FormData& form);
123 void OnFirstUserGestureObservedInTab();
94 void OnPing(); 124 void OnPing();
95 void OnPreviewForm(int query_id, const FormData& form); 125 void OnPreviewForm(int query_id, const FormData& form);
96 126
97 // For external Autofill selection. 127 // For external Autofill selection.
98 void OnClearForm(); 128 void OnClearForm();
99 void OnClearPreviewedForm(); 129 void OnClearPreviewedForm();
100 void OnFillFieldWithValue(const base::string16& value); 130 void OnFillFieldWithValue(const base::string16& value);
101 void OnPreviewFieldWithValue(const base::string16& value); 131 void OnPreviewFieldWithValue(const base::string16& value);
102 void OnAcceptDataListSuggestion(const base::string16& value); 132 void OnAcceptDataListSuggestion(const base::string16& value);
103 void OnFillPasswordSuggestion(const base::string16& username, 133 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|. 196 // Set |node| to display the given |value|.
167 void FillFieldWithValue(const base::string16& value, 197 void FillFieldWithValue(const base::string16& value,
168 blink::WebInputElement* node); 198 blink::WebInputElement* node);
169 199
170 // Set |node| to display the given |value| as a preview. The preview is 200 // 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 201 // visible on screen to the user, but not visible to the page via the DOM or
172 // JavaScript. 202 // JavaScript.
173 void PreviewFieldWithValue(const base::string16& value, 203 void PreviewFieldWithValue(const base::string16& value,
174 blink::WebInputElement* node); 204 blink::WebInputElement* node);
175 205
176 // Notifies browser of new fillable forms in |frame|. 206 // Notifies browser of new fillable forms in |render_frame|.
177 void ProcessForms(const blink::WebLocalFrame& frame); 207 void ProcessForms();
178 208
179 // Hides any currently showing Autofill popup. 209 // Hides any currently showing Autofill popup.
180 void HidePopup(); 210 void HidePopup();
181 211
212 // Formerly cached forms for all frames, now only caches forms for the current
213 // frame. TODO(estade): simplify |FormCache| to only work with a single frame.
182 FormCache form_cache_; 214 FormCache form_cache_;
183 215
184 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. 216 PasswordAutofillAgent* password_autofill_agent_; // Weak reference.
185 PasswordGenerationAgent* password_generation_agent_; // Weak reference. 217 PasswordGenerationAgent* password_generation_agent_; // Weak reference.
186 218
219 // Passes through RenderViewObserver methods to |this|.
220 LegacyAutofillAgent legacy_;
221
222 // Tracks clicks on the RenderViewHost, informs |this|.
223 PageClickTracker page_click_tracker_;
224
187 // The ID of the last request sent for form field Autofill. Used to ignore 225 // The ID of the last request sent for form field Autofill. Used to ignore
188 // out of date responses. 226 // out of date responses.
189 int autofill_query_id_; 227 int autofill_query_id_;
190 228
191 // The element corresponding to the last request sent for form field Autofill. 229 // The element corresponding to the last request sent for form field Autofill.
192 blink::WebFormControlElement element_; 230 blink::WebFormControlElement element_;
193 231
194 // The form element currently requesting an interactive autocomplete. 232 // The form element currently requesting an interactive autocomplete.
195 blink::WebFormElement in_flight_request_form_; 233 blink::WebFormElement in_flight_request_form_;
196 234
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? 235 // Should we display a warning if autofill is disabled?
201 bool display_warning_if_disabled_; 236 bool display_warning_if_disabled_;
202 237
203 // Was the query node autofilled prior to previewing the form? 238 // Was the query node autofilled prior to previewing the form?
204 bool was_query_node_autofilled_; 239 bool was_query_node_autofilled_;
205 240
206 // Have we already shown Autofill suggestions for the field the user is 241 // Have we already shown Autofill suggestions for the field the user is
207 // currently editing? Used to keep track of state for metrics logging. 242 // currently editing? Used to keep track of state for metrics logging.
208 bool has_shown_autofill_popup_for_current_edit_; 243 bool has_shown_autofill_popup_for_current_edit_;
209 244
210 // If true we just set the node text so we shouldn't show the popup. 245 // If true we just set the node text so we shouldn't show the popup.
211 bool did_set_node_text_; 246 bool did_set_node_text_;
212 247
213 // Whether or not to ignore text changes. Useful for when we're committing 248 // 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 249 // a composition when we are defocusing the WebView and we don't want to
215 // trigger an autofill popup to show. 250 // trigger an autofill popup to show.
216 bool ignore_text_changes_; 251 bool ignore_text_changes_;
217 252
218 // Whether the Autofill popup is possibly visible. This is tracked as a 253 // Whether the Autofill popup is possibly visible. This is tracked as a
219 // performance improvement, so that the IPC channel isn't flooded with 254 // 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. 255 // messages to close the Autofill popup when it can't possibly be showing.
221 bool is_popup_possibly_visible_; 256 bool is_popup_possibly_visible_;
222 257
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_; 258 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
229 259
230 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); 260 DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
231 }; 261 };
232 262
233 } // namespace autofill 263 } // namespace autofill
234 264
235 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ 265 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698