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

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

Issue 2007473004: [Autofill] Migrate ContentAutofillDriver<-->AutofillAgent IPCs to mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initialize remote_interfaces_ in Init() Created 4 years, 5 months 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 <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
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& GetAutofillDriver();
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 protected: 83 protected:
63 // blink::WebAutofillClient: 84 // blink::WebAutofillClient:
64 void didAssociateFormControls( 85 void didAssociateFormControls(
65 const blink::WebVector<blink::WebNode>& nodes) override; 86 const blink::WebVector<blink::WebNode>& nodes) override;
66 87
67 private: 88 private:
68 // Functor used as a simplified comparison function for FormData. Only 89 // Functor used as a simplified comparison function for FormData. Only
69 // compares forms at a high level (notably name, origin, action). 90 // compares forms at a high level (notably name, origin, action).
70 struct FormDataCompare { 91 struct FormDataCompare {
71 bool operator()(const FormData& lhs, const FormData& rhs) const; 92 bool operator()(const FormData& lhs, const FormData& rhs) const;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // be elided because of the current value of |element| (relevant for inline 137 // be elided because of the current value of |element| (relevant for inline
117 // autocomplete). 138 // autocomplete).
118 bool show_full_suggestion_list; 139 bool show_full_suggestion_list;
119 140
120 // Specifies that only show a suggestions box if |element| is part of a 141 // Specifies that only show a suggestions box if |element| is part of a
121 // password form, otherwise show no suggestions. 142 // password form, otherwise show no suggestions.
122 bool show_password_suggestions_only; 143 bool show_password_suggestions_only;
123 }; 144 };
124 145
125 // content::RenderFrameObserver: 146 // content::RenderFrameObserver:
126 bool OnMessageReceived(const IPC::Message& message) override;
127 void DidCommitProvisionalLoad(bool is_new_navigation, 147 void DidCommitProvisionalLoad(bool is_new_navigation,
128 bool is_same_page_navigation) override; 148 bool is_same_page_navigation) override;
129 void DidFinishDocumentLoad() override; 149 void DidFinishDocumentLoad() override;
130 void WillSendSubmitEvent(const blink::WebFormElement& form) override; 150 void WillSendSubmitEvent(const blink::WebFormElement& form) override;
131 void WillSubmitForm(const blink::WebFormElement& form) override; 151 void WillSubmitForm(const blink::WebFormElement& form) override;
132 void DidChangeScrollOffset() override; 152 void DidChangeScrollOffset() override;
133 void FocusedNodeChanged(const blink::WebNode& node) override; 153 void FocusedNodeChanged(const blink::WebNode& node) override;
134 void OnDestruct() override; 154 void OnDestruct() override;
135 155
136 // Fires IPC messages for a given form submission. Will always fire 156 // Fires IPC messages for a given form submission. Will always fire
(...skipping 22 matching lines...) Expand all
159 void textFieldDidChange(const blink::WebFormControlElement& element) override; 179 void textFieldDidChange(const blink::WebFormControlElement& element) override;
160 void textFieldDidReceiveKeyDown( 180 void textFieldDidReceiveKeyDown(
161 const blink::WebInputElement& element, 181 const blink::WebInputElement& element,
162 const blink::WebKeyboardEvent& event) override; 182 const blink::WebKeyboardEvent& event) override;
163 void setIgnoreTextChanges(bool ignore) override; 183 void setIgnoreTextChanges(bool ignore) override;
164 void openTextDataListChooser(const blink::WebInputElement& element) override; 184 void openTextDataListChooser(const blink::WebInputElement& element) override;
165 void dataListOptionsChanged(const blink::WebInputElement& element) override; 185 void dataListOptionsChanged(const blink::WebInputElement& element) override;
166 void firstUserGestureObserved() override; 186 void firstUserGestureObserved() override;
167 void ajaxSucceeded() override; 187 void ajaxSucceeded() override;
168 188
169 void OnFieldTypePredictionsAvailable(
170 const std::vector<FormDataPredictions>& forms);
171 void OnFillForm(int query_id, const FormData& form);
172 void OnPing(); 189 void OnPing();
173 void OnPreviewForm(int query_id, const FormData& form);
174
175 // mojom::AutofillAgent:
176 void FirstUserGestureObservedInTab() override;
177
178 // For external Autofill selection.
179 void OnClearForm();
180 void OnClearPreviewedForm();
181 void OnFillFieldWithValue(const base::string16& value);
182 void OnPreviewFieldWithValue(const base::string16& value);
183 void OnAcceptDataListSuggestion(const base::string16& value);
184 void OnFillPasswordSuggestion(const base::string16& username,
185 const base::string16& password);
186 void OnPreviewPasswordSuggestion(const base::string16& username,
187 const base::string16& password);
188 void OnShowInitialPasswordAccountSuggestions(
189 int key,
190 const PasswordFormFillData& form_data);
191 190
192 // Called when a same-page navigation is detected. 191 // Called when a same-page navigation is detected.
193 void OnSamePageNavigationCompleted(); 192 void OnSamePageNavigationCompleted();
194 // Helper method which collects unowned elements (i.e., those not inside a 193 // Helper method which collects unowned elements (i.e., those not inside a
195 // form tag) and writes them into |output|. Returns true if the process is 194 // form tag) and writes them into |output|. Returns true if the process is
196 // successful, and all conditions for firing events are true. 195 // successful, and all conditions for firing events are true.
197 bool CollectFormlessElements(FormData* output); 196 bool CollectFormlessElements(FormData* output);
198 FRIEND_TEST_ALL_PREFIXES(FormAutocompleteTest, CollectFormlessElements); 197 FRIEND_TEST_ALL_PREFIXES(FormAutocompleteTest, CollectFormlessElements);
199 198
200 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug 199 // Called in a posted task by textFieldDidChange() to work-around a WebKit bug
201 // http://bugs.webkit.org/show_bug.cgi?id=16976 200 // http://bugs.webkit.org/show_bug.cgi?id=16976
202 void TextFieldDidChangeImpl(const blink::WebFormControlElement& element); 201 void TextFieldDidChangeImpl(const blink::WebFormControlElement& element);
203 202
204 // Shows the autofill suggestions for |element|. This call is asynchronous 203 // Shows the autofill suggestions for |element|. This call is asynchronous
205 // and may or may not lead to the showing of a suggestion popup (no popup is 204 // and may or may not lead to the showing of a suggestion popup (no popup is
206 // shown if there are no available suggestions). 205 // shown if there are no available suggestions).
207 void ShowSuggestions(const blink::WebFormControlElement& element, 206 void ShowSuggestions(const blink::WebFormControlElement& element,
208 const ShowSuggestionsOptions& options); 207 const ShowSuggestionsOptions& options);
209 208
210 // Queries the browser for Autocomplete and Autofill suggestions for the given 209 // Queries the browser for Autocomplete and Autofill suggestions for the given
211 // |element|. 210 // |element|.
212 void QueryAutofillSuggestions(const blink::WebFormControlElement& element); 211 void QueryAutofillSuggestions(const blink::WebFormControlElement& element);
213 212
214 // Sets the element value to reflect the selected |suggested_value|. 213 // Sets the element value to reflect the selected |suggested_value|.
215 void AcceptDataListSuggestion(const base::string16& suggested_value); 214 void DoAcceptDataListSuggestion(const base::string16& suggested_value);
216 215
217 // Fills |form| and |field| with the FormData and FormField corresponding to 216 // Fills |form| and |field| with the FormData and FormField corresponding to
218 // |node|. Returns true if the data was found; and false otherwise. 217 // |node|. Returns true if the data was found; and false otherwise.
219 bool FindFormAndFieldForNode( 218 bool FindFormAndFieldForNode(
220 const blink::WebNode& node, 219 const blink::WebNode& node,
221 FormData* form, 220 FormData* form,
222 FormFieldData* field) WARN_UNUSED_RESULT; 221 FormFieldData* field) WARN_UNUSED_RESULT;
223 222
224 // Set |node| to display the given |value|. 223 // Set |node| to display the given |value|.
225 void FillFieldWithValue(const base::string16& value, 224 void DoFillFieldWithValue(const base::string16& value,
226 blink::WebInputElement* node); 225 blink::WebInputElement* node);
227 226
228 // Set |node| to display the given |value| as a preview. The preview is 227 // Set |node| to display the given |value| as a preview. The preview is
229 // visible on screen to the user, but not visible to the page via the DOM or 228 // visible on screen to the user, but not visible to the page via the DOM or
230 // JavaScript. 229 // JavaScript.
231 void PreviewFieldWithValue(const base::string16& value, 230 void DoPreviewFieldWithValue(const base::string16& value,
232 blink::WebInputElement* node); 231 blink::WebInputElement* node);
233 232
234 // Notifies browser of new fillable forms in |render_frame|. 233 // Notifies browser of new fillable forms in |render_frame|.
235 void ProcessForms(); 234 void ProcessForms();
236 235
237 // Sends a message to the browser that the form is about to be submitted, 236 // Sends a message to the browser that the form is about to be submitted,
238 // only if the particular message has not been previously submitted for the 237 // only if the particular message has not been previously submitted for the
239 // form in the current frame. 238 // form in the current frame.
240 // Additionally, depending on |send_submitted_event| a message is sent to the 239 // Additionally, depending on |send_submitted_event| a message is sent to the
241 // browser that the form was submitted. 240 // browser that the form was submitted.
242 void SendFormEvents(const blink::WebFormElement& form, 241 void SendFormEvents(const blink::WebFormElement& form,
243 bool send_submitted_event); 242 bool send_submitted_event);
244 243
245 // Hides any currently showing Autofill popup. 244 // Hides any currently showing Autofill popup.
246 void HidePopup(); 245 void HidePopup();
247 246
248 // Returns true if the text field change is due to a user gesture. Can be 247 // Returns true if the text field change is due to a user gesture. Can be
249 // overriden in tests. 248 // overriden in tests.
250 virtual bool IsUserGesture() const; 249 virtual bool IsUserGesture() const;
251 250
252 void ConnectToMojoAutofillDriverIfNeeded();
253
254 // Formerly cached forms for all frames, now only caches forms for the current 251 // Formerly cached forms for all frames, now only caches forms for the current
255 // frame. 252 // frame.
256 FormCache form_cache_; 253 FormCache form_cache_;
257 254
258 // Keeps track of the forms for which a "will submit" message has been sent in 255 // Keeps track of the forms for which a "will submit" message has been sent in
259 // this frame's current load. We use a simplified comparison function. 256 // this frame's current load. We use a simplified comparison function.
260 std::set<FormData, FormDataCompare> submitted_forms_; 257 std::set<FormData, FormDataCompare> submitted_forms_;
261 258
262 PasswordAutofillAgent* password_autofill_agent_; // Weak reference. 259 PasswordAutofillAgent* password_autofill_agent_; // Weak reference.
263 PasswordGenerationAgent* password_generation_agent_; // Weak reference. 260 PasswordGenerationAgent* password_generation_agent_; // Weak reference.
(...skipping 30 matching lines...) Expand all
294 // performance improvement, so that the IPC channel isn't flooded with 291 // performance improvement, so that the IPC channel isn't flooded with
295 // messages to close the Autofill popup when it can't possibly be showing. 292 // messages to close the Autofill popup when it can't possibly be showing.
296 bool is_popup_possibly_visible_; 293 bool is_popup_possibly_visible_;
297 294
298 // If the generation popup is possibly visible. This is tracked to prevent 295 // If the generation popup is possibly visible. This is tracked to prevent
299 // generation UI from displaying at the same time as password manager UI. 296 // generation UI from displaying at the same time as password manager UI.
300 // This is needed because generation is shown on field focus vs. field click 297 // This is needed because generation is shown on field focus vs. field click
301 // for the password manager. TODO(gcasto): Have both UIs show on focus. 298 // for the password manager. TODO(gcasto): Have both UIs show on focus.
302 bool is_generation_popup_possibly_visible_; 299 bool is_generation_popup_possibly_visible_;
303 300
304 mojo::BindingSet<mojom::AutofillAgent> bindings_; 301 mojo::Binding<mojom::AutofillAgent> binding_;
305 302
306 mojom::AutofillDriverPtr mojo_autofill_driver_; 303 mojom::AutofillDriverPtr mojo_autofill_driver_;
307 304
308 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; 305 base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
309 306
310 DISALLOW_COPY_AND_ASSIGN(AutofillAgent); 307 DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
311 }; 308 };
312 309
313 } // namespace autofill 310 } // namespace autofill
314 311
315 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_ 312 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_AUTOFILL_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698