| OLD | NEW |
| 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 <set> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 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" |
| 14 #include "content/public/renderer/render_view_observer.h" | 15 #include "content/public/renderer/render_view_observer.h" |
| 15 #include "third_party/WebKit/public/web/WebInputElement.h" | 16 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 16 | 17 |
| 17 namespace blink { | 18 namespace blink { |
| 18 class WebInputElement; | 19 class WebInputElement; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Ways to restrict which passwords are saved in ProvisionallySavePassword. | 88 // Ways to restrict which passwords are saved in ProvisionallySavePassword. |
| 88 enum ProvisionallySaveRestriction { | 89 enum ProvisionallySaveRestriction { |
| 89 RESTRICTION_NONE, | 90 RESTRICTION_NONE, |
| 90 RESTRICTION_NON_EMPTY_PASSWORD | 91 RESTRICTION_NON_EMPTY_PASSWORD |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 struct PasswordInfo { | 94 struct PasswordInfo { |
| 94 blink::WebInputElement password_field; | 95 blink::WebInputElement password_field; |
| 95 PasswordFormFillData fill_data; | 96 PasswordFormFillData fill_data; |
| 96 bool backspace_pressed_last; | 97 bool backspace_pressed_last; |
| 97 PasswordInfo() : backspace_pressed_last(false) {} | 98 // "Wait for username change" before overwriting the password value -- if |
| 99 // set to true, this flag means that after selecting a username for password |
| 100 // autofill, the user overwrote the autofileld password. The agent should |
| 101 // not restore it back to the autofilled password, so it holds on with |
| 102 // changing the password value until the flag is reset. The flag is reset |
| 103 // when the user chooses another username for autofill. |
| 104 bool wait_for_username_change; |
| 105 PasswordInfo(); |
| 98 }; | 106 }; |
| 99 typedef std::map<blink::WebElement, PasswordInfo> LoginToPasswordInfoMap; | 107 // LoginToPasswordInfoMap contains pointers to instead of values of type |
| 108 // PasswordInfo, because the addresses of the values are passed to a |
| 109 // PasswordValueGatekeeper instance, and need therefore remain constant for |
| 110 // the lifetime of the values. |
| 111 typedef std::map<blink::WebElement, PasswordInfo*> LoginToPasswordInfoMap; |
| 112 typedef std::map<blink::WebElement, blink::WebElement> PasswordToLoginMap; |
| 100 typedef std::map<blink::WebFrame*, | 113 typedef std::map<blink::WebFrame*, |
| 101 linked_ptr<PasswordForm> > FrameToPasswordFormMap; | 114 linked_ptr<PasswordForm> > FrameToPasswordFormMap; |
| 102 | 115 |
| 103 // This class holds a vector of autofilled password input elements and makes | 116 // This class keeps track of autofilled password input elements and makes sure |
| 104 // sure the autofilled password value is not accessible to JavaScript code | 117 // the autofilled password value is not accessible to JavaScript code until |
| 105 // until the user interacts with the page. | 118 // the user interacts with the page. |
| 106 class PasswordValueGatekeeper { | 119 class PasswordValueGatekeeper { |
| 107 public: | 120 public: |
| 108 PasswordValueGatekeeper(); | 121 PasswordValueGatekeeper(); |
| 109 ~PasswordValueGatekeeper(); | 122 ~PasswordValueGatekeeper(); |
| 110 | 123 |
| 111 // Call this for every autofilled password field, so that the gatekeeper | 124 // Register |element_info| for every autofilled password field, so that the |
| 112 // protects the value accordingly. | 125 // gatekeeper protects the value accordingly. Ownership of |element_info| |
| 113 void RegisterElement(blink::WebInputElement* element); | 126 // remains with the caller, and the caller must unregister it via |
| 127 // UnregisterElementInfo or Reset prior to destruction of |element_info|. |
| 128 // The caller also must ensure that the object pointed to by |element_info| |
| 129 // does not change address. |
| 130 void RegisterElementInfo(PasswordInfo* element_info); |
| 131 // Remove |element_info| from the internal map. It is OK to call |
| 132 // UnregisterElementInfo for pointers not contained in the internal map, |
| 133 // because the gatekeeper may choose to not include, or later exclude, |
| 134 // registered pointers at its own discretion. |
| 135 void UnregisterElementInfo(PasswordInfo* element_info); |
| 114 | 136 |
| 115 // Call this to notify the gatekeeper that the user interacted with the | 137 // Call this to notify the gatekeeper that the user interacted with the |
| 116 // page. | 138 // page. |
| 117 void OnUserGesture(); | 139 void OnUserGesture(); |
| 118 | 140 |
| 119 // Call this to reset the gatekeeper on a new page navigation. | 141 // Call this to reset the gatekeeper on a new page navigation. |
| 120 void Reset(); | 142 void Reset(); |
| 121 | 143 |
| 122 private: | 144 private: |
| 123 // Make the value of |element| accessible to JavaScript code. | 145 // Make the value of |element| accessible to JavaScript code. |
| 124 void ShowValue(blink::WebInputElement* element); | 146 void ShowValue(blink::WebInputElement* element); |
| 125 | 147 |
| 126 bool was_user_gesture_seen_; | 148 bool was_user_gesture_seen_; |
| 127 std::vector<blink::WebInputElement> elements_; | 149 // Weak pointers to the PasswordInfo data associated with the guarded |
| 150 // password elements. The Gatekeeper assumes those objects are alive until |
| 151 // they are unregistered. |
| 152 std::set<PasswordInfo*> elements_info_; |
| 128 | 153 |
| 129 DISALLOW_COPY_AND_ASSIGN(PasswordValueGatekeeper); | 154 DISALLOW_COPY_AND_ASSIGN(PasswordValueGatekeeper); |
| 130 }; | 155 }; |
| 131 | 156 |
| 132 // RenderViewObserver: | 157 // RenderViewObserver: |
| 133 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 158 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 134 virtual void DidStartProvisionalLoad(blink::WebLocalFrame* frame) OVERRIDE; | 159 virtual void DidStartProvisionalLoad(blink::WebLocalFrame* frame) OVERRIDE; |
| 135 virtual void DidStartLoading() OVERRIDE; | 160 virtual void DidStartLoading() OVERRIDE; |
| 136 virtual void DidFinishDocumentLoad(blink::WebLocalFrame* frame) OVERRIDE; | 161 virtual void DidFinishDocumentLoad(blink::WebLocalFrame* frame) OVERRIDE; |
| 137 virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE; | 162 virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 154 void GetSuggestions(const PasswordFormFillData& fill_data, | 179 void GetSuggestions(const PasswordFormFillData& fill_data, |
| 155 const base::string16& input, | 180 const base::string16& input, |
| 156 std::vector<base::string16>* suggestions, | 181 std::vector<base::string16>* suggestions, |
| 157 std::vector<base::string16>* realms, | 182 std::vector<base::string16>* realms, |
| 158 bool show_all); | 183 bool show_all); |
| 159 | 184 |
| 160 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data, | 185 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data, |
| 161 const blink::WebInputElement& user_input, | 186 const blink::WebInputElement& user_input, |
| 162 bool show_all); | 187 bool show_all); |
| 163 | 188 |
| 164 // Attempts to fill |username_element| and |password_element| with the | 189 // Attempts to fill |username_element| and the corresponding password field |
| 165 // |fill_data|. Will use the data corresponding to the preferred username, | 190 // with |password_info|. Will use the data corresponding to the preferred |
| 166 // unless the |username_element| already has a value set. In that case, | 191 // username, unless the username element already has a value set. In that |
| 167 // attempts to fill the password matching the already filled username, if | 192 // case, attempts to fill the password matching the already filled username, |
| 168 // such a password exists. | 193 // if such a password exists. |
| 169 void FillFormOnPasswordRecieved(const PasswordFormFillData& fill_data, | 194 void FillFormOnPasswordRecieved(blink::WebInputElement* username_element, |
| 170 blink::WebInputElement username_element, | 195 PasswordInfo* password_info); |
| 171 blink::WebInputElement password_element); | |
| 172 | 196 |
| 173 bool FillUserNameAndPassword(blink::WebInputElement* username_element, | 197 bool FillUserNameAndPassword(blink::WebInputElement* username_element, |
| 174 blink::WebInputElement* password_element, | 198 PasswordInfo* password_info, |
| 175 const PasswordFormFillData& fill_data, | |
| 176 bool exact_username_match, | 199 bool exact_username_match, |
| 177 bool set_selection); | 200 bool set_selection); |
| 178 | 201 |
| 179 // Fills |login_input| and |password| with the most relevant suggestion from | 202 // Fills |username| and corresponding password field with the most relevant |
| 180 // |fill_data| and shows a popup with other suggestions. | 203 // suggestion from |password_info| and shows a popup with other suggestions. |
| 181 void PerformInlineAutocomplete( | 204 void PerformInlineAutocomplete(blink::WebInputElement* username, |
| 182 const blink::WebInputElement& username, | 205 PasswordInfo* password_info); |
| 183 const blink::WebInputElement& password, | |
| 184 const PasswordFormFillData& fill_data); | |
| 185 | 206 |
| 186 // Invoked when the passed frame is closing. Gives us a chance to clear any | 207 // Invoked when the passed frame is closing. Gives us a chance to clear any |
| 187 // reference we may have to elements in that frame. | 208 // reference we may have to elements in that frame. |
| 188 void FrameClosing(const blink::WebFrame* frame); | 209 void FrameClosing(const blink::WebFrame* frame); |
| 189 | 210 |
| 190 // Finds login information for a |node| that was previously filled. | 211 // Finds login information for a |node| that was previously filled. |
| 191 bool FindLoginInfo(const blink::WebNode& node, | 212 bool FindLoginInfo(const blink::WebNode& node, |
| 192 blink::WebInputElement* found_input, | 213 blink::WebInputElement* found_input, |
| 193 PasswordInfo* found_password); | 214 PasswordInfo** found_password); |
| 194 | 215 |
| 195 // Clears the preview for the username and password fields, restoring both to | 216 // Clears the preview for the username and password fields, restoring both to |
| 196 // their previous filled state. | 217 // their previous filled state. |
| 197 void ClearPreview(blink::WebInputElement* username, | 218 void ClearPreview(blink::WebInputElement* username, |
| 198 blink::WebInputElement* password); | 219 blink::WebInputElement* password); |
| 199 | 220 |
| 200 // If |provisionally_saved_forms_| contains a form for |current_frame| or its | 221 // If |provisionally_saved_forms_| contains a form for |current_frame| or its |
| 201 // children, return such frame. | 222 // children, return such frame. |
| 202 blink::WebFrame* CurrentOrChildFrameWithSavedForms( | 223 blink::WebFrame* CurrentOrChildFrameWithSavedForms( |
| 203 const blink::WebFrame* current_frame); | 224 const blink::WebFrame* current_frame); |
| 204 | 225 |
| 205 // Extracts a PasswordForm from |form| and saves it as | 226 // Extracts a PasswordForm from |form| and saves it as |
| 206 // |provisionally_saved_forms_[frame]|, as long as it satisfies |restriction|. | 227 // |provisionally_saved_forms_[frame]|, as long as it satisfies |restriction|. |
| 207 void ProvisionallySavePassword(blink::WebLocalFrame* frame, | 228 void ProvisionallySavePassword(blink::WebLocalFrame* frame, |
| 208 const blink::WebFormElement& form, | 229 const blink::WebFormElement& form, |
| 209 ProvisionallySaveRestriction restriction); | 230 ProvisionallySaveRestriction restriction); |
| 210 | 231 |
| 211 // The logins we have filled so far with their associated info. | 232 // The logins we have filled so far with their associated info. |
| 212 LoginToPasswordInfoMap login_to_password_info_; | 233 LoginToPasswordInfoMap login_to_password_info_; |
| 234 // Stores the PasswordInfo objects pointed to by |login_to_password_info_|, |
| 235 // grouped by frames for easy deletion on frame destruction. |
| 236 std::map<const blink::WebFrame*, std::vector<linked_ptr<PasswordInfo> > > |
| 237 password_infos_; |
| 238 // Maps password elements to the corresponding username elements, good for |
| 239 // looking up PasswordInfo associated with a password element in |
| 240 // |login_to_password_info_|. |
| 241 PasswordToLoginMap password_to_username_; |
| 213 | 242 |
| 214 // Used for UMA stats. | 243 // Used for UMA stats. |
| 215 OtherPossibleUsernamesUsage usernames_usage_; | 244 OtherPossibleUsernamesUsage usernames_usage_; |
| 216 | 245 |
| 217 // Pointer to the WebView. Used to access page scale factor. | 246 // Pointer to the WebView. Used to access page scale factor. |
| 218 blink::WebView* web_view_; | 247 blink::WebView* web_view_; |
| 219 | 248 |
| 220 // Set if the user might be submitting a password form on the current page, | 249 // Set if the user might be submitting a password form on the current page, |
| 221 // but the submit may still fail (i.e. doesn't pass JavaScript validation). | 250 // but the submit may still fail (i.e. doesn't pass JavaScript validation). |
| 222 FrameToPasswordFormMap provisionally_saved_forms_; | 251 FrameToPasswordFormMap provisionally_saved_forms_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 239 bool did_stop_loading_; | 268 bool did_stop_loading_; |
| 240 | 269 |
| 241 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; | 270 base::WeakPtrFactory<PasswordAutofillAgent> weak_ptr_factory_; |
| 242 | 271 |
| 243 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); | 272 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent); |
| 244 }; | 273 }; |
| 245 | 274 |
| 246 } // namespace autofill | 275 } // namespace autofill |
| 247 | 276 |
| 248 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ | 277 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_AUTOFILL_AGENT_H_ |
| OLD | NEW |