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

Side by Side Diff: components/autofill/content/renderer/password_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: 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_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 <vector> 9 #include <vector>
10 10
11 #include "base/gtest_prod_util.h"
11 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "components/autofill/core/common/password_form_fill_data.h" 14 #include "components/autofill/core/common/password_form_fill_data.h"
15 #include "content/public/renderer/render_frame_observer.h"
14 #include "content/public/renderer/render_view_observer.h" 16 #include "content/public/renderer/render_view_observer.h"
15 #include "third_party/WebKit/public/web/WebInputElement.h" 17 #include "third_party/WebKit/public/web/WebInputElement.h"
16 18
17 namespace blink { 19 namespace blink {
18 class WebInputElement; 20 class WebInputElement;
19 class WebKeyboardEvent; 21 class WebKeyboardEvent;
20 class WebSecurityOrigin; 22 class WebSecurityOrigin;
21 class WebView; 23 class WebView;
22 } 24 }
23 25
24 namespace autofill { 26 namespace autofill {
25 27
26 // This class is responsible for filling password forms. 28 // This class is responsible for filling password forms.
27 // There is one PasswordAutofillAgent per RenderView. 29 class PasswordAutofillAgent : public content::RenderFrameObserver {
28 class PasswordAutofillAgent : public content::RenderViewObserver {
29 public: 30 public:
30 explicit PasswordAutofillAgent(content::RenderView* render_view); 31 explicit PasswordAutofillAgent(content::RenderFrame* render_frame);
31 ~PasswordAutofillAgent() override; 32 ~PasswordAutofillAgent() override;
32 33
33 // WebViewClient editor related calls forwarded by the RenderView. 34 // WebFrameClient editor related calls forwarded by AutofillAgent.
34 // If they return true, it indicates the event was consumed and should not 35 // If they return true, it indicates the event was consumed and should not
35 // be used for any other autofill activity. 36 // be used for any other autofill activity.
36 bool TextFieldDidEndEditing(const blink::WebInputElement& element); 37 bool TextFieldDidEndEditing(const blink::WebInputElement& element);
37 bool TextDidChangeInTextField(const blink::WebInputElement& element); 38 bool TextDidChangeInTextField(const blink::WebInputElement& element);
38 bool TextFieldHandlingKeyDown(const blink::WebInputElement& element, 39 bool TextFieldHandlingKeyDown(const blink::WebInputElement& element,
39 const blink::WebKeyboardEvent& event); 40 const blink::WebKeyboardEvent& event);
40 41
41 // Fills the username and password fields of this form with the given values. 42 // Fills the username and password fields of this form with the given values.
42 // Returns true if the fields were filled, false otherwise. 43 // Returns true if the fields were filled, false otherwise.
43 bool FillSuggestion(const blink::WebNode& node, 44 bool FillSuggestion(const blink::WebNode& node,
44 const blink::WebString& username, 45 const blink::WebString& username,
45 const blink::WebString& password); 46 const blink::WebString& password);
46 47
47 // Previews the username and password fields of this form with the given 48 // Previews the username and password fields of this form with the given
48 // values. Returns true if the fields were previewed, false otherwise. 49 // values. Returns true if the fields were previewed, false otherwise.
49 bool PreviewSuggestion(const blink::WebNode& node, 50 bool PreviewSuggestion(const blink::WebNode& node,
50 const blink::WebString& username, 51 const blink::WebString& username,
51 const blink::WebString& password); 52 const blink::WebString& password);
52 53
53 // Clears the preview for the username and password fields, restoring both to 54 // Clears the preview for the username and password fields, restoring both to
54 // their previous filled state. Return false if no login information was 55 // their previous filled state. Return false if no login information was
55 // found for the form. 56 // found for the form.
56 bool DidClearAutofillSelection(const blink::WebNode& node); 57 bool DidClearAutofillSelection(const blink::WebNode& node);
58
57 // Shows an Autofill popup with username suggestions for |element|. If 59 // Shows an Autofill popup with username suggestions for |element|. If
58 // |show_all| is |true|, will show all possible suggestions for that element, 60 // |show_all| is |true|, will show all possible suggestions for that element,
59 // otherwise shows suggestions based on current value of |element|. 61 // otherwise shows suggestions based on current value of |element|.
60 // Returns true if any suggestions were shown, false otherwise. 62 // Returns true if any suggestions were shown, false otherwise.
61 bool ShowSuggestions(const blink::WebInputElement& element, bool show_all); 63 bool ShowSuggestions(const blink::WebInputElement& element, bool show_all);
62 64
63 // Called when new form controls are inserted. 65 // Called when new form controls are inserted.
64 void OnDynamicFormsSeen(blink::WebFrame* frame); 66 void OnDynamicFormsSeen();
65 67
66 // Called when the user first interacts with the page after a load. This is a 68 // Called when the user first interacts with the page after a load. This is a
67 // signal to make autofilled values of password input elements accessible to 69 // signal to make autofilled values of password input elements accessible to
68 // JavaScript. 70 // JavaScript.
69 void FirstUserGestureObserved(); 71 void FirstUserGestureObserved();
70 72
71 protected: 73 protected:
72 virtual bool OriginCanAccessPasswordManager( 74 virtual bool OriginCanAccessPasswordManager(
73 const blink::WebSecurityOrigin& origin); 75 const blink::WebSecurityOrigin& origin);
74 76
(...skipping 19 matching lines...) Expand all
94 bool backspace_pressed_last; 96 bool backspace_pressed_last;
95 // The user manually edited the password more recently than the username was 97 // The user manually edited the password more recently than the username was
96 // changed. 98 // changed.
97 bool password_was_edited_last; 99 bool password_was_edited_last;
98 PasswordInfo(); 100 PasswordInfo();
99 }; 101 };
100 typedef std::map<blink::WebElement, PasswordInfo> LoginToPasswordInfoMap; 102 typedef std::map<blink::WebElement, PasswordInfo> LoginToPasswordInfoMap;
101 typedef std::map<blink::WebElement, int> LoginToPasswordInfoKeyMap; 103 typedef std::map<blink::WebElement, int> LoginToPasswordInfoKeyMap;
102 typedef std::map<blink::WebElement, blink::WebElement> PasswordToLoginMap; 104 typedef std::map<blink::WebElement, blink::WebElement> PasswordToLoginMap;
103 typedef std::map<blink::WebFrame*, 105 typedef std::map<blink::WebFrame*,
104 linked_ptr<PasswordForm> > FrameToPasswordFormMap; 106 linked_ptr<PasswordForm> > FrameToPasswordFormMap;
vabr (Chromium) 2014/11/10 14:34:40 You can drop this typedef.
Evan Stade 2014/11/14 23:25:50 Done.
105 107
106 // This class keeps track of autofilled password input elements and makes sure 108 // This class keeps track of autofilled password input elements and makes sure
107 // the autofilled password value is not accessible to JavaScript code until 109 // the autofilled password value is not accessible to JavaScript code until
108 // the user interacts with the page. 110 // the user interacts with the page.
109 class PasswordValueGatekeeper { 111 class PasswordValueGatekeeper {
110 public: 112 public:
111 PasswordValueGatekeeper(); 113 PasswordValueGatekeeper();
112 ~PasswordValueGatekeeper(); 114 ~PasswordValueGatekeeper();
113 115
114 // Call this for every autofilled password field, so that the gatekeeper 116 // Call this for every autofilled password field, so that the gatekeeper
(...skipping 10 matching lines...) Expand all
125 private: 127 private:
126 // Make the value of |element| accessible to JavaScript code. 128 // Make the value of |element| accessible to JavaScript code.
127 void ShowValue(blink::WebInputElement* element); 129 void ShowValue(blink::WebInputElement* element);
128 130
129 bool was_user_gesture_seen_; 131 bool was_user_gesture_seen_;
130 std::vector<blink::WebInputElement> elements_; 132 std::vector<blink::WebInputElement> elements_;
131 133
132 DISALLOW_COPY_AND_ASSIGN(PasswordValueGatekeeper); 134 DISALLOW_COPY_AND_ASSIGN(PasswordValueGatekeeper);
133 }; 135 };
134 136
135 // RenderViewObserver: 137 // Thunk class for RenderViewObserver methods that haven't yet been migrated
138 // to RenderFrameObserver. Should eventually be removed.
139 class LegacyPasswordAutofillAgent : public content::RenderViewObserver {
140 public:
141 LegacyPasswordAutofillAgent(content::RenderView* render_view,
142 PasswordAutofillAgent* agent);
143 ~LegacyPasswordAutofillAgent() override;
144
145 // RenderViewObserver:
146 void OnDestruct() override;
147 void DidStartLoading() override;
148 void DidStopLoading() override;
149 void FrameDetached(blink::WebFrame* frame) override;
150 void WillSendSubmitEvent(blink::WebLocalFrame* frame,
151 const blink::WebFormElement& form) override;
152 void WillSubmitForm(blink::WebLocalFrame* frame,
153 const blink::WebFormElement& form) override;
154
155 private:
156 PasswordAutofillAgent* agent_;
157
158 DISALLOW_COPY_AND_ASSIGN(LegacyPasswordAutofillAgent);
159 };
160 friend class LegacyPasswordAutofillAgent;
161 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest,
162 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared);
163 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest,
164 RememberLastNonEmptyPasswordOnSubmit_UserCleared);
165 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest,
166 RememberLastNonEmptyPasswordOnSubmit_NewPassword);
167
168 // RenderFrameObserver:
136 bool OnMessageReceived(const IPC::Message& message) override; 169 bool OnMessageReceived(const IPC::Message& message) override;
137 void DidStartProvisionalLoad(blink::WebLocalFrame* frame) override; 170 void DidStartProvisionalLoad() override;
138 void DidStartLoading() override; 171 void DidFinishDocumentLoad() override;
139 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; 172 void DidFinishLoad() override;
140 void DidFinishLoad(blink::WebLocalFrame* frame) override; 173 void FrameWillClose() override;
141 void DidStopLoading() override; 174
142 void FrameDetached(blink::WebFrame* frame) override; 175 // Legacy RenderViewObserver:
143 void FrameWillClose(blink::WebFrame* frame) override; 176 void DidStartLoading();
177 void DidStopLoading();
178 void FrameDetached(blink::WebFrame* frame);
144 void WillSendSubmitEvent(blink::WebLocalFrame* frame, 179 void WillSendSubmitEvent(blink::WebLocalFrame* frame,
145 const blink::WebFormElement& form) override; 180 const blink::WebFormElement& form);
146 void WillSubmitForm(blink::WebLocalFrame* frame, 181 void WillSubmitForm(blink::WebLocalFrame* frame,
147 const blink::WebFormElement& form) override; 182 const blink::WebFormElement& form);
148 183
149 // RenderView IPC handlers: 184 // RenderView IPC handlers:
150 void OnFillPasswordForm(int key, const PasswordFormFillData& form_data); 185 void OnFillPasswordForm(int key, const PasswordFormFillData& form_data);
151 void OnSetLoggingState(bool active); 186 void OnSetLoggingState(bool active);
152 187
153 // Scans the given frame for password forms and sends them up to the browser. 188 // Scans the given frame for password forms and sends them up to the browser.
154 // If |only_visible| is true, only forms visible in the layout are sent. 189 // If |only_visible| is true, only forms visible in the layout are sent.
155 void SendPasswordForms(blink::WebFrame* frame, bool only_visible); 190 void SendPasswordForms(bool only_visible);
156 191
157 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data, 192 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data,
158 const blink::WebInputElement& user_input, 193 const blink::WebInputElement& user_input,
159 bool show_all); 194 bool show_all);
160 195
161 // Fills |login_input| and |password| with the most relevant suggestion from 196 // Fills |login_input| and |password| with the most relevant suggestion from
162 // |fill_data| and shows a popup with other suggestions. 197 // |fill_data| and shows a popup with other suggestions.
163 void PerformInlineAutocomplete( 198 void PerformInlineAutocomplete(
164 const blink::WebInputElement& username, 199 const blink::WebInputElement& username,
165 const blink::WebInputElement& password, 200 const blink::WebInputElement& password,
166 const PasswordFormFillData& fill_data); 201 const PasswordFormFillData& fill_data);
167 202
168 // Invoked when the passed frame is closing. Gives us a chance to clear any 203 // Invoked when the frame is closing.
169 // reference we may have to elements in that frame. 204 void FrameClosing();
170 void FrameClosing(const blink::WebFrame* frame);
171 205
172 // Finds login information for a |node| that was previously filled. 206 // Finds login information for a |node| that was previously filled.
173 bool FindLoginInfo(const blink::WebNode& node, 207 bool FindLoginInfo(const blink::WebNode& node,
174 blink::WebInputElement* found_input, 208 blink::WebInputElement* found_input,
175 PasswordInfo** found_password); 209 PasswordInfo** found_password);
176 210
177 // Clears the preview for the username and password fields, restoring both to 211 // Clears the preview for the username and password fields, restoring both to
178 // their previous filled state. 212 // their previous filled state.
179 void ClearPreview(blink::WebInputElement* username, 213 void ClearPreview(blink::WebInputElement* username,
180 blink::WebInputElement* password); 214 blink::WebInputElement* password);
181 215
182 // If |provisionally_saved_forms_| contains a form for |current_frame| or its 216 // Extracts a PasswordForm from |form| and saves it as
183 // children, return such frame. 217 // |provisionally_saved_form_|, as long as it satisfies |restriction|.
184 blink::WebFrame* CurrentOrChildFrameWithSavedForms( 218 void ProvisionallySavePassword(const blink::WebFormElement& form,
185 const blink::WebFrame* current_frame); 219 ProvisionallySaveRestriction restriction);
186 220
187 // Extracts a PasswordForm from |form| and saves it as 221 // Passes through |RenderViewObserver| method to |this|.
188 // |provisionally_saved_forms_[frame]|, as long as it satisfies |restriction|. 222 LegacyPasswordAutofillAgent legacy_;
189 void ProvisionallySavePassword(blink::WebLocalFrame* frame,
190 const blink::WebFormElement& form,
191 ProvisionallySaveRestriction restriction);
192 223
193 // The logins we have filled so far with their associated info. 224 // The logins we have filled so far with their associated info.
194 LoginToPasswordInfoMap login_to_password_info_; 225 LoginToPasswordInfoMap login_to_password_info_;
195 // And the keys under which PasswordAutofillManager can find the same info. 226 // And the keys under which PasswordAutofillManager can find the same info.
196 LoginToPasswordInfoKeyMap login_to_password_info_key_; 227 LoginToPasswordInfoKeyMap login_to_password_info_key_;
197 // A (sort-of) reverse map to |login_to_password_info_|. 228 // A (sort-of) reverse map to |login_to_password_info_|.
198 PasswordToLoginMap password_to_username_; 229 PasswordToLoginMap password_to_username_;
199 230
200 // Used for UMA stats. 231 // Used for UMA stats.
201 OtherPossibleUsernamesUsage usernames_usage_; 232 OtherPossibleUsernamesUsage usernames_usage_;
202 233
203 // Pointer to the WebView. Used to access page scale factor. 234 // Pointer to the WebView. Used to access page scale factor.
204 blink::WebView* web_view_; 235 blink::WebView* web_view_;
205 236
206 // Set if the user might be submitting a password form on the current page, 237 // Set if the user might be submitting a password form on the current page,
207 // but the submit may still fail (i.e. doesn't pass JavaScript validation). 238 // but the submit may still fail (i.e. doesn't pass JavaScript validation).
208 FrameToPasswordFormMap provisionally_saved_forms_; 239 linked_ptr<PasswordForm> provisionally_saved_form_;
vabr (Chromium) 2014/11/10 14:34:40 I believe you can use scoped_ptr instead of linked
Evan Stade 2014/11/14 23:25:50 Done.
209 240
210 PasswordValueGatekeeper gatekeeper_; 241 PasswordValueGatekeeper gatekeeper_;
211 242
212 // True indicates that user debug information should be logged. 243 // True indicates that user debug information should be logged.
213 bool logging_state_active_; 244 bool logging_state_active_;
214 245
215 // True indicates that the username field was autofilled, false otherwise. 246 // True indicates that the username field was autofilled, false otherwise.
216 bool was_username_autofilled_; 247 bool was_username_autofilled_;
217 // True indicates that the password field was autofilled, false otherwise. 248 // True indicates that the password field was autofilled, false otherwise.
218 bool was_password_autofilled_; 249 bool was_password_autofilled_;
219 250
220 // Records original starting point of username element's selection range 251 // Records original starting point of username element's selection range
221 // before preview. 252 // before preview.
222 int username_selection_start_; 253 int username_selection_start_;
223 254
224 // True indicates that all frames in a page have been rendered. 255 // True indicates that all frames in a page have been rendered.
225 bool did_stop_loading_; 256 bool did_stop_loading_;
226 257
227 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; 258 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_;
228 259
229 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); 260 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent);
230 }; 261 };
231 262
232 } // namespace autofill 263 } // namespace autofill
233 264
234 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ 265 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698