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

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

Issue 1814193002: Better filling on suggestion of password fields in Password Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 4 years, 8 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_PASSWORD_AUTOFILL_AGENT_H_ 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 29 matching lines...) Expand all
40 bool TextDidChangeInTextField(const blink::WebInputElement& element); 40 bool TextDidChangeInTextField(const blink::WebInputElement& element);
41 41
42 // Function that should be called whenever the value of |element| changes due 42 // Function that should be called whenever the value of |element| changes due
43 // to user input. This is separate from TextDidChangeInTextField() as that 43 // to user input. This is separate from TextDidChangeInTextField() as that
44 // function may trigger UI and should only be called when other UI won't be 44 // function may trigger UI and should only be called when other UI won't be
45 // shown. 45 // shown.
46 void UpdateStateForTextChange(const blink::WebInputElement& element); 46 void UpdateStateForTextChange(const blink::WebInputElement& element);
47 47
48 // Fills the username and password fields of this form with the given values. 48 // Fills the username and password fields of this form with the given values.
49 // Returns true if the fields were filled, false otherwise. 49 // Returns true if the fields were filled, false otherwise.
50 bool FillSuggestion(const blink::WebNode& node, 50 bool FillSuggestion(const blink::WebFormControlElement& node,
51 const blink::WebString& username, 51 const blink::WebString& username,
52 const blink::WebString& password); 52 const blink::WebString& password);
53 53
54 // Previews the username and password fields of this form with the given 54 // Previews the username and password fields of this form with the given
55 // values. Returns true if the fields were previewed, false otherwise. 55 // values. Returns true if the fields were previewed, false otherwise.
56 bool PreviewSuggestion(const blink::WebNode& node, 56 bool PreviewSuggestion(const blink::WebFormControlElement& node,
57 const blink::WebString& username, 57 const blink::WebString& username,
58 const blink::WebString& password); 58 const blink::WebString& password);
59 59
60 // Clears the preview for the username and password fields, restoring both to 60 // Clears the preview for the username and password fields, restoring both to
61 // their previous filled state. Return false if no login information was 61 // their previous filled state. Return false if no login information was
62 // found for the form. 62 // found for the form.
63 bool DidClearAutofillSelection(const blink::WebNode& node); 63 bool DidClearAutofillSelection(
64 const blink::WebFormControlElement& control_element);
64 65
65 // Shows an Autofill popup with username suggestions for |element|. If 66 // Shows an Autofill popup with username suggestions for |element|. If
66 // |show_all| is |true|, will show all possible suggestions for that element, 67 // |show_all| is |true|, will show all possible suggestions for that element,
67 // otherwise shows suggestions based on current value of |element|. 68 // otherwise shows suggestions based on current value of |element|.
68 // If |generation_popup_showing| is true, this function will return false 69 // If |generation_popup_showing| is true, this function will return false
69 // as both UIs should not be shown at the same time. This function should 70 // as both UIs should not be shown at the same time. This function should
70 // still be called in this situation so that UMA stats can be logged. 71 // still be called in this situation so that UMA stats can be logged.
71 // Returns true if any suggestions were shown, false otherwise. 72 // Returns true if any suggestions were shown, false otherwise.
72 bool ShowSuggestions(const blink::WebInputElement& element, 73 bool ShowSuggestions(const blink::WebInputElement& element,
73 bool show_all, 74 bool show_all,
(...skipping 20 matching lines...) Expand all
94 enum ProvisionallySaveRestriction { 95 enum ProvisionallySaveRestriction {
95 RESTRICTION_NONE, 96 RESTRICTION_NONE,
96 RESTRICTION_NON_EMPTY_PASSWORD 97 RESTRICTION_NON_EMPTY_PASSWORD
97 }; 98 };
98 99
99 struct PasswordInfo { 100 struct PasswordInfo {
100 blink::WebInputElement password_field; 101 blink::WebInputElement password_field;
101 PasswordFormFillData fill_data; 102 PasswordFormFillData fill_data;
102 // The user manually edited the password more recently than the username was 103 // The user manually edited the password more recently than the username was
103 // changed. 104 // changed.
104 bool password_was_edited_last; 105 bool password_was_edited_last = false;
105 // The user edited the username field after page loading. 106 // The user accepted a suggestion from a dropdown on a password field.
106 bool username_was_edited; 107 bool password_field_suggestion_was_accepted = false;
107 PasswordInfo(); 108 // The key under which PasswordAutofillManager can find info for filling.
109 int key = -1;
108 }; 110 };
109 typedef std::map<blink::WebInputElement, PasswordInfo> 111 typedef std::map<blink::WebInputElement, PasswordInfo>
110 WebInputToPasswordInfoMap; 112 WebInputToPasswordInfoMap;
111 typedef std::map<blink::WebElement, int> WebElementToPasswordInfoKeyMap; 113 typedef std::map<blink::WebElement, int> WebElementToPasswordInfoKeyMap;
112 typedef std::map<blink::WebInputElement, blink::WebInputElement> 114 typedef std::map<blink::WebInputElement, blink::WebInputElement>
113 PasswordToLoginMap; 115 PasswordToLoginMap;
114 116
115 // This class keeps track of autofilled password input elements and makes sure 117 // This class keeps track of autofilled password input elements and makes sure
116 // the autofilled password value is not accessible to JavaScript code until 118 // the autofilled password value is not accessible to JavaScript code until
117 // the user interacts with the page. 119 // the user interacts with the page.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Scans the given frame for password forms and sends them up to the browser. 165 // Scans the given frame for password forms and sends them up to the browser.
164 // If |only_visible| is true, only forms visible in the layout are sent. 166 // If |only_visible| is true, only forms visible in the layout are sent.
165 void SendPasswordForms(bool only_visible); 167 void SendPasswordForms(bool only_visible);
166 168
167 // Instructs the browser to show a pop-up suggesting which credentials could 169 // Instructs the browser to show a pop-up suggesting which credentials could
168 // be filled. |show_in_password_field| should indicate whether the pop-up is 170 // be filled. |show_in_password_field| should indicate whether the pop-up is
169 // to be shown on the password field instead of on the username field. If the 171 // to be shown on the password field instead of on the username field. If the
170 // username exists, it should be passed as |user_input|. If there is no 172 // username exists, it should be passed as |user_input|. If there is no
171 // username, pass the password field in |user_input|. In the latter case, no 173 // username, pass the password field in |user_input|. In the latter case, no
172 // username value will be shown in the pop-up. 174 // username value will be shown in the pop-up.
173 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data, 175 bool ShowSuggestionPopup(const PasswordInfo& password_info,
174 const blink::WebInputElement& user_input, 176 const blink::WebInputElement& user_input,
175 bool show_all, 177 bool show_all,
176 bool show_on_password_field); 178 bool show_on_password_field);
177 179
178 // Finds the PasswordInfo that corresponds to the passed in element. The 180 // Finds the PasswordInfo, username and password fields that corresponds to
179 // passed in element can be either a username element or a password element. 181 // the passed in |element|. |element| can refer either to a username element
180 // If a PasswordInfo was found, returns |true| and also assigns the 182 // or a password element. If a PasswordInfo was found, returns |true| and also
181 // corresponding username WebInputElement and PasswordInfo into 183 // assigns the corresponding username, password elements and PasswordInfo into
182 // username_element and pasword_info, respectively. Note, that 184 // |username_element|, |password_element| and |pasword_info|, respectively.
183 // |username_element->isNull()| can be true for forms without a username 185 // Note, that |username_element->isNull()| can be true if |element| is a
184 // field. 186 // password.
185 bool FindPasswordInfoForElement( 187 bool FindPasswordInfoForElement(const blink::WebInputElement& element,
186 const blink::WebInputElement& element, 188 blink::WebInputElement* username_element,
187 const blink::WebInputElement** username_element, 189 blink::WebInputElement* password_element,
188 PasswordInfo** password_info); 190 PasswordInfo** password_info);
189 191
190 // Invoked when the frame is closing. 192 // Invoked when the frame is closing.
191 void FrameClosing(); 193 void FrameClosing();
192 194
193 // Finds login information for a |node| that was previously filled.
194 bool FindLoginInfo(const blink::WebNode& node,
195 blink::WebInputElement* found_input,
196 PasswordInfo** found_password);
197
198 // Clears the preview for the username and password fields, restoring both to 195 // Clears the preview for the username and password fields, restoring both to
199 // their previous filled state. 196 // their previous filled state.
200 void ClearPreview(blink::WebInputElement* username, 197 void ClearPreview(blink::WebInputElement* username,
201 blink::WebInputElement* password); 198 blink::WebInputElement* password);
202 199
203 // Saves |password_form| in |provisionally_saved_form_|, as long as it 200 // Saves |password_form| in |provisionally_saved_form_|, as long as it
204 // satisfies |restriction|. 201 // satisfies |restriction|.
205 void ProvisionallySavePassword(std::unique_ptr<PasswordForm> password_form, 202 void ProvisionallySavePassword(std::unique_ptr<PasswordForm> password_form,
206 ProvisionallySaveRestriction restriction); 203 ProvisionallySaveRestriction restriction);
207 204
208 // Returns true if |provisionally_saved_form_| has enough information that 205 // Returns true if |provisionally_saved_form_| has enough information that
209 // it is likely filled out. 206 // it is likely filled out.
210 bool ProvisionallySavedPasswordIsValid(); 207 bool ProvisionallySavedPasswordIsValid();
211 208
212 // Helper function called when in-page navigation completed 209 // Helper function called when in-page navigation completed
213 void OnSamePageNavigationCompleted(); 210 void OnSamePageNavigationCompleted();
214 211
215 // The logins we have filled so far with their associated info. 212 // The logins we have filled so far with their associated info.
216 WebInputToPasswordInfoMap web_input_to_password_info_; 213 WebInputToPasswordInfoMap web_input_to_password_info_;
217 // And the keys under which PasswordAutofillManager can find the same info.
218 WebElementToPasswordInfoKeyMap web_element_to_password_info_key_;
219 // A (sort-of) reverse map to |login_to_password_info_|. 214 // A (sort-of) reverse map to |login_to_password_info_|.
220 PasswordToLoginMap password_to_username_; 215 PasswordToLoginMap password_to_username_;
221 216
222 // Set if the user might be submitting a password form on the current page, 217 // Set if the user might be submitting a password form on the current page,
223 // but the submit may still fail (i.e. doesn't pass JavaScript validation). 218 // but the submit may still fail (i.e. doesn't pass JavaScript validation).
224 std::unique_ptr<PasswordForm> provisionally_saved_form_; 219 std::unique_ptr<PasswordForm> provisionally_saved_form_;
225 220
226 // Contains the most recent text that user typed or PasswordManager autofilled 221 // Contains the most recent text that user typed or PasswordManager autofilled
227 // in input elements. Used for storing username/password before JavaScript 222 // in input elements. Used for storing username/password before JavaScript
228 // changes them. 223 // changes them.
(...skipping 17 matching lines...) Expand all
246 FormsPredictionsMap form_predictions_; 241 FormsPredictionsMap form_predictions_;
247 242
248 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; 243 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_;
249 244
250 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); 245 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent);
251 }; 246 };
252 247
253 } // namespace autofill 248 } // namespace autofill
254 249
255 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ 250 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698