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

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: 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_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/memory/linked_ptr.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_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 18 matching lines...) Expand all
93 PasswordFormFillData fill_data; 95 PasswordFormFillData fill_data;
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*,
104 linked_ptr<PasswordForm> > FrameToPasswordFormMap;
105 105
106 // This class keeps track of autofilled password input elements and makes sure 106 // This class keeps track of autofilled password input elements and makes sure
107 // the autofilled password value is not accessible to JavaScript code until 107 // the autofilled password value is not accessible to JavaScript code until
108 // the user interacts with the page. 108 // the user interacts with the page.
109 class PasswordValueGatekeeper { 109 class PasswordValueGatekeeper {
110 public: 110 public:
111 PasswordValueGatekeeper(); 111 PasswordValueGatekeeper();
112 ~PasswordValueGatekeeper(); 112 ~PasswordValueGatekeeper();
113 113
114 // Call this for every autofilled password field, so that the gatekeeper 114 // Call this for every autofilled password field, so that the gatekeeper
(...skipping 10 matching lines...) Expand all
125 private: 125 private:
126 // Make the value of |element| accessible to JavaScript code. 126 // Make the value of |element| accessible to JavaScript code.
127 void ShowValue(blink::WebInputElement* element); 127 void ShowValue(blink::WebInputElement* element);
128 128
129 bool was_user_gesture_seen_; 129 bool was_user_gesture_seen_;
130 std::vector<blink::WebInputElement> elements_; 130 std::vector<blink::WebInputElement> elements_;
131 131
132 DISALLOW_COPY_AND_ASSIGN(PasswordValueGatekeeper); 132 DISALLOW_COPY_AND_ASSIGN(PasswordValueGatekeeper);
133 }; 133 };
134 134
135 // RenderViewObserver: 135 // Thunk class for RenderViewObserver methods that haven't yet been migrated
136 // to RenderFrameObserver. Should eventually be removed.
137 // http://crbug.com/433486
138 class LegacyPasswordAutofillAgent : public content::RenderViewObserver {
139 public:
140 LegacyPasswordAutofillAgent(content::RenderView* render_view,
141 PasswordAutofillAgent* agent);
142 ~LegacyPasswordAutofillAgent() override;
143
144 // RenderViewObserver:
145 void OnDestruct() override;
146 void DidStartLoading() override;
147 void DidStopLoading() override;
148 void FrameDetached(blink::WebFrame* frame) override;
149 void WillSendSubmitEvent(blink::WebLocalFrame* frame,
150 const blink::WebFormElement& form) override;
151 void WillSubmitForm(blink::WebLocalFrame* frame,
152 const blink::WebFormElement& form) override;
153
154 private:
155 PasswordAutofillAgent* agent_;
156
157 DISALLOW_COPY_AND_ASSIGN(LegacyPasswordAutofillAgent);
158 };
159 friend class LegacyPasswordAutofillAgent;
160 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest,
161 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared);
162 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest,
163 RememberLastNonEmptyPasswordOnSubmit_UserCleared);
164 FRIEND_TEST_ALL_PREFIXES(PasswordAutofillAgentTest,
165 RememberLastNonEmptyPasswordOnSubmit_NewPassword);
166
167 // RenderFrameObserver:
136 bool OnMessageReceived(const IPC::Message& message) override; 168 bool OnMessageReceived(const IPC::Message& message) override;
137 void DidStartProvisionalLoad(blink::WebLocalFrame* frame) override; 169 void DidStartProvisionalLoad() override;
138 void DidStartLoading() override; 170 void DidFinishDocumentLoad() override;
139 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; 171 void DidFinishLoad() override;
140 void DidFinishLoad(blink::WebLocalFrame* frame) override; 172 void FrameWillClose() override;
141 void DidStopLoading() override; 173
142 void FrameDetached(blink::WebFrame* frame) override; 174 // Legacy RenderViewObserver:
143 void FrameWillClose(blink::WebFrame* frame) override; 175 void DidStartLoading();
176 void DidStopLoading();
177 void FrameDetached(blink::WebFrame* frame);
144 void WillSendSubmitEvent(blink::WebLocalFrame* frame, 178 void WillSendSubmitEvent(blink::WebLocalFrame* frame,
145 const blink::WebFormElement& form) override; 179 const blink::WebFormElement& form);
146 void WillSubmitForm(blink::WebLocalFrame* frame, 180 void WillSubmitForm(blink::WebLocalFrame* frame,
147 const blink::WebFormElement& form) override; 181 const blink::WebFormElement& form);
148 182
149 // RenderView IPC handlers: 183 // RenderView IPC handlers:
150 void OnFillPasswordForm(int key, const PasswordFormFillData& form_data); 184 void OnFillPasswordForm(int key, const PasswordFormFillData& form_data);
151 void OnSetLoggingState(bool active); 185 void OnSetLoggingState(bool active);
152 186
153 // Scans the given frame for password forms and sends them up to the browser. 187 // 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. 188 // If |only_visible| is true, only forms visible in the layout are sent.
155 void SendPasswordForms(blink::WebFrame* frame, bool only_visible); 189 void SendPasswordForms(bool only_visible);
156 190
157 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data, 191 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data,
158 const blink::WebInputElement& user_input, 192 const blink::WebInputElement& user_input,
159 bool show_all); 193 bool show_all);
160 194
161 // Fills |login_input| and |password| with the most relevant suggestion from 195 // Fills |login_input| and |password| with the most relevant suggestion from
162 // |fill_data| and shows a popup with other suggestions. 196 // |fill_data| and shows a popup with other suggestions.
163 void PerformInlineAutocomplete( 197 void PerformInlineAutocomplete(
164 const blink::WebInputElement& username, 198 const blink::WebInputElement& username,
165 const blink::WebInputElement& password, 199 const blink::WebInputElement& password,
166 const PasswordFormFillData& fill_data); 200 const PasswordFormFillData& fill_data);
167 201
168 // Invoked when the passed frame is closing. Gives us a chance to clear any 202 // Invoked when the frame is closing.
169 // reference we may have to elements in that frame. 203 void FrameClosing();
170 void FrameClosing(const blink::WebFrame* frame);
171 204
172 // Finds login information for a |node| that was previously filled. 205 // Finds login information for a |node| that was previously filled.
173 bool FindLoginInfo(const blink::WebNode& node, 206 bool FindLoginInfo(const blink::WebNode& node,
174 blink::WebInputElement* found_input, 207 blink::WebInputElement* found_input,
175 PasswordInfo** found_password); 208 PasswordInfo** found_password);
176 209
177 // Clears the preview for the username and password fields, restoring both to 210 // Clears the preview for the username and password fields, restoring both to
178 // their previous filled state. 211 // their previous filled state.
179 void ClearPreview(blink::WebInputElement* username, 212 void ClearPreview(blink::WebInputElement* username,
180 blink::WebInputElement* password); 213 blink::WebInputElement* password);
181 214
182 // If |provisionally_saved_forms_| contains a form for |current_frame| or its 215 // Extracts a PasswordForm from |form| and saves it as
183 // children, return such frame. 216 // |provisionally_saved_form_|, as long as it satisfies |restriction|.
184 blink::WebFrame* CurrentOrChildFrameWithSavedForms( 217 void ProvisionallySavePassword(const blink::WebFormElement& form,
185 const blink::WebFrame* current_frame); 218 ProvisionallySaveRestriction restriction);
186 219
187 // Extracts a PasswordForm from |form| and saves it as 220 // Passes through |RenderViewObserver| method to |this|.
188 // |provisionally_saved_forms_[frame]|, as long as it satisfies |restriction|. 221 LegacyPasswordAutofillAgent legacy_;
189 void ProvisionallySavePassword(blink::WebLocalFrame* frame,
190 const blink::WebFormElement& form,
191 ProvisionallySaveRestriction restriction);
192 222
193 // The logins we have filled so far with their associated info. 223 // The logins we have filled so far with their associated info.
194 LoginToPasswordInfoMap login_to_password_info_; 224 LoginToPasswordInfoMap login_to_password_info_;
195 // And the keys under which PasswordAutofillManager can find the same info. 225 // And the keys under which PasswordAutofillManager can find the same info.
196 LoginToPasswordInfoKeyMap login_to_password_info_key_; 226 LoginToPasswordInfoKeyMap login_to_password_info_key_;
197 // A (sort-of) reverse map to |login_to_password_info_|. 227 // A (sort-of) reverse map to |login_to_password_info_|.
198 PasswordToLoginMap password_to_username_; 228 PasswordToLoginMap password_to_username_;
199 229
200 // Used for UMA stats. 230 // Used for UMA stats.
201 OtherPossibleUsernamesUsage usernames_usage_; 231 OtherPossibleUsernamesUsage usernames_usage_;
202 232
203 // Pointer to the WebView. Used to access page scale factor. 233 // Pointer to the WebView. Used to access page scale factor.
204 blink::WebView* web_view_; 234 blink::WebView* web_view_;
205 235
206 // Set if the user might be submitting a password form on the current page, 236 // 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). 237 // but the submit may still fail (i.e. doesn't pass JavaScript validation).
208 FrameToPasswordFormMap provisionally_saved_forms_; 238 scoped_ptr<PasswordForm> provisionally_saved_form_;
209 239
210 PasswordValueGatekeeper gatekeeper_; 240 PasswordValueGatekeeper gatekeeper_;
211 241
212 // True indicates that user debug information should be logged. 242 // True indicates that user debug information should be logged.
213 bool logging_state_active_; 243 bool logging_state_active_;
214 244
215 // True indicates that the username field was autofilled, false otherwise. 245 // True indicates that the username field was autofilled, false otherwise.
216 bool was_username_autofilled_; 246 bool was_username_autofilled_;
217 // True indicates that the password field was autofilled, false otherwise. 247 // True indicates that the password field was autofilled, false otherwise.
218 bool was_password_autofilled_; 248 bool was_password_autofilled_;
219 249
220 // Records original starting point of username element's selection range 250 // Records original starting point of username element's selection range
221 // before preview. 251 // before preview.
222 int username_selection_start_; 252 int username_selection_start_;
223 253
224 // True indicates that all frames in a page have been rendered. 254 // True indicates that all frames in a page have been rendered.
225 bool did_stop_loading_; 255 bool did_stop_loading_;
226 256
227 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; 257 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_;
228 258
229 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); 259 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent);
230 }; 260 };
231 261
232 } // namespace autofill 262 } // namespace autofill
233 263
234 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ 264 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698