OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_RENDERER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_ | |
6 #define CHROME_RENDERER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "chrome/renderer/page_click_listener.h" | |
13 #include "components/autofill/common/password_form_fill_data.h" | |
14 #include "content/public/renderer/render_view_observer.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | |
16 | |
17 namespace WebKit { | |
18 class WebInputElement; | |
19 class WebKeyboardEvent; | |
20 class WebView; | |
21 } | |
22 | |
23 namespace autofill { | |
24 | |
25 // This class is responsible for filling password forms. | |
26 // There is one PasswordAutofillManager per RenderView. | |
27 class PasswordAutofillManager : public content::RenderViewObserver, | |
28 public PageClickListener { | |
29 public: | |
30 explicit PasswordAutofillManager(content::RenderView* render_view); | |
31 virtual ~PasswordAutofillManager(); | |
32 | |
33 // WebViewClient editor related calls forwarded by the RenderView. | |
34 // If they return true, it indicates the event was consumed and should not | |
35 // be used for any other autofill activity. | |
36 bool TextFieldDidEndEditing(const WebKit::WebInputElement& element); | |
37 bool TextDidChangeInTextField(const WebKit::WebInputElement& element); | |
38 bool TextFieldHandlingKeyDown(const WebKit::WebInputElement& element, | |
39 const WebKit::WebKeyboardEvent& event); | |
40 | |
41 // Fills the password associated with user name |value|. Returns true if the | |
42 // username and password fields were filled, false otherwise. | |
43 bool DidAcceptAutofillSuggestion(const WebKit::WebNode& node, | |
44 const WebKit::WebString& value); | |
45 // A no-op. No filling happens for selection. But this method returns | |
46 // true when |node| is fillable by password Autofill. | |
47 bool DidSelectAutofillSuggestion(const WebKit::WebNode& node); | |
48 // A no-op. Password forms are not previewed, so they do not need to be | |
49 // cleared when the selection changes. However, this method returns | |
50 // true when |node| is fillable by password Autofill. | |
51 bool DidClearAutofillSelection(const WebKit::WebNode& node); | |
52 | |
53 private: | |
54 friend class PasswordAutofillManagerTest; | |
55 | |
56 struct PasswordInfo { | |
57 WebKit::WebInputElement password_field; | |
58 PasswordFormFillData fill_data; | |
59 bool backspace_pressed_last; | |
60 PasswordInfo() : backspace_pressed_last(false) {} | |
61 }; | |
62 typedef std::map<WebKit::WebElement, PasswordInfo> LoginToPasswordInfoMap; | |
63 | |
64 // RenderViewObserver: | |
65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
66 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE; | |
67 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE; | |
68 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE; | |
69 virtual void FrameWillClose(WebKit::WebFrame* frame) OVERRIDE; | |
70 | |
71 // PageClickListener: | |
72 virtual bool InputElementClicked(const WebKit::WebInputElement& element, | |
73 bool was_focused, | |
74 bool is_focused) OVERRIDE; | |
75 virtual bool InputElementLostFocus() OVERRIDE; | |
76 | |
77 // RenderView IPC handlers: | |
78 void OnFillPasswordForm(const PasswordFormFillData& form_data, | |
79 bool disable_popup); | |
80 | |
81 // Scans the given frame for password forms and sends them up to the browser. | |
82 // If |only_visible| is true, only forms visible in the layout are sent. | |
83 void SendPasswordForms(WebKit::WebFrame* frame, bool only_visible); | |
84 | |
85 void GetSuggestions(const PasswordFormFillData& fill_data, | |
86 const string16& input, | |
87 std::vector<string16>* suggestions); | |
88 | |
89 bool ShowSuggestionPopup(const PasswordFormFillData& fill_data, | |
90 const WebKit::WebInputElement& user_input); | |
91 | |
92 bool FillUserNameAndPassword( | |
93 WebKit::WebInputElement* username_element, | |
94 WebKit::WebInputElement* password_element, | |
95 const PasswordFormFillData& fill_data, | |
96 bool exact_username_match, | |
97 bool set_selection); | |
98 | |
99 // Fills |login_input| and |password| with the most relevant suggestion from | |
100 // |fill_data| and shows a popup with other suggestions. | |
101 void PerformInlineAutocomplete( | |
102 const WebKit::WebInputElement& username, | |
103 const WebKit::WebInputElement& password, | |
104 const PasswordFormFillData& fill_data); | |
105 | |
106 // Invoked when the passed frame is closing. Gives us a chance to clear any | |
107 // reference we may have to elements in that frame. | |
108 void FrameClosing(const WebKit::WebFrame* frame); | |
109 | |
110 // Finds login information for a |node| that was previously filled. | |
111 bool FindLoginInfo(const WebKit::WebNode& node, | |
112 WebKit::WebInputElement* found_input, | |
113 PasswordInfo* found_password); | |
114 | |
115 // The logins we have filled so far with their associated info. | |
116 LoginToPasswordInfoMap login_to_password_info_; | |
117 | |
118 // Used to disable and hide the popup. | |
119 bool disable_popup_; | |
120 | |
121 // Pointer to the WebView. Used to access page scale factor. | |
122 WebKit::WebView* web_view_; | |
123 | |
124 base::WeakPtrFactory<PasswordAutofillManager> weak_ptr_factory_; | |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillManager); | |
127 }; | |
128 | |
129 } // namespace autofill | |
130 | |
131 #endif // CHROME_RENDERER_AUTOFILL_PASSWORD_AUTOFILL_MANAGER_H_ | |
OLD | NEW |