OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ | 5 #ifndef CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ |
6 #define CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ | 6 #define CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/task.h" | 12 #include "base/task.h" |
13 #include "chrome/renderer/page_click_listener.h" | 13 #include "chrome/renderer/page_click_listener.h" |
| 14 #include "chrome/renderer/render_view_observer.h" |
14 #include "webkit/glue/password_form_dom_manager.h" | 15 #include "webkit/glue/password_form_dom_manager.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
16 | 17 |
17 class RenderView; | |
18 namespace WebKit { | 18 namespace WebKit { |
| 19 class WebInputElement; |
19 class WebKeyboardEvent; | 20 class WebKeyboardEvent; |
20 class WebView; | |
21 } | 21 } |
22 | 22 |
23 // This class is responsible for filling password forms. | 23 // This class is responsible for filling password forms. |
24 // There is one PasswordAutocompleteManager per RenderView. | 24 // There is one PasswordAutocompleteManager per RenderView. |
25 class PasswordAutocompleteManager : public PageClickListener { | 25 class PasswordAutocompleteManager : public RenderViewObserver, |
| 26 public PageClickListener { |
26 public: | 27 public: |
27 explicit PasswordAutocompleteManager(RenderView* render_view); | 28 explicit PasswordAutocompleteManager(RenderView* render_view); |
28 virtual ~PasswordAutocompleteManager(); | 29 virtual ~PasswordAutocompleteManager(); |
29 | 30 |
30 // Invoked by the renderer when it receives the password info from the | |
31 // browser. This triggers a password autocomplete (if wait_for_username is | |
32 // false on |form_data|). | |
33 void ReceivedPasswordFormFillData(WebKit::WebView* view, | |
34 const webkit_glue::PasswordFormFillData& form_data); | |
35 | |
36 // Invoked when the passed frame is closing. Gives us a chance to clear any | 31 // Invoked when the passed frame is closing. Gives us a chance to clear any |
37 // reference we may have to elements in that frame. | 32 // reference we may have to elements in that frame. |
38 void FrameClosing(const WebKit::WebFrame* frame); | 33 void FrameClosing(const WebKit::WebFrame* frame); |
39 | 34 |
40 // Fills the password associated with |user_input|, using its current value | 35 // Fills the password associated with |user_input|, using its current value |
41 // as the actual user name. Returns true if the password field was filled, | 36 // as the actual user name. Returns true if the password field was filled, |
42 // false otherwise, typically if there was no matching suggestions for the | 37 // false otherwise, typically if there was no matching suggestions for the |
43 // currently typed username. | 38 // currently typed username. |
44 bool FillPassword(const WebKit::WebInputElement& user_input); | 39 bool FillPassword(const WebKit::WebInputElement& user_input); |
45 | 40 |
46 // Fills |login_input| and |password| with the most relevant suggestion from | 41 // Fills |login_input| and |password| with the most relevant suggestion from |
47 // |fill_data| and shows a popup with other suggestions. | 42 // |fill_data| and shows a popup with other suggestions. |
48 void PerformInlineAutocomplete( | 43 void PerformInlineAutocomplete( |
49 const WebKit::WebInputElement& username, | 44 const WebKit::WebInputElement& username, |
50 const WebKit::WebInputElement& password, | 45 const WebKit::WebInputElement& password, |
51 const webkit_glue::PasswordFormFillData& fill_data); | 46 const webkit_glue::PasswordFormFillData& fill_data); |
52 | 47 |
53 // Scans the given frame for password forms and sends them up to the browser. | |
54 // If |only_visible| is true, only forms visible in the layout are sent. | |
55 void SendPasswordForms(WebKit::WebFrame* frame, bool only_visible); | |
56 | |
57 // WebViewClient editor related calls forwarded by the RenderView. | 48 // WebViewClient editor related calls forwarded by the RenderView. |
58 // If they return true, it indicates the event was consumed and should not | 49 // If they return true, it indicates the event was consumed and should not |
59 // be used for any other autofill activity. | 50 // be used for any other autofill activity. |
60 bool TextFieldDidEndEditing(const WebKit::WebInputElement& element); | 51 bool TextFieldDidEndEditing(const WebKit::WebInputElement& element); |
61 bool TextDidChangeInTextField(const WebKit::WebInputElement& element); | 52 bool TextDidChangeInTextField(const WebKit::WebInputElement& element); |
62 void TextFieldHandlingKeyDown(const WebKit::WebInputElement& element, | 53 void TextFieldHandlingKeyDown(const WebKit::WebInputElement& element, |
63 const WebKit::WebKeyboardEvent& event); | 54 const WebKit::WebKeyboardEvent& event); |
64 | 55 |
65 private: | 56 private: |
| 57 friend class PasswordAutocompleteManagerTest; |
| 58 |
66 struct PasswordInfo { | 59 struct PasswordInfo { |
67 WebKit::WebInputElement password_field; | 60 WebKit::WebInputElement password_field; |
68 webkit_glue::PasswordFormFillData fill_data; | 61 webkit_glue::PasswordFormFillData fill_data; |
69 bool backspace_pressed_last; | 62 bool backspace_pressed_last; |
70 PasswordInfo() : backspace_pressed_last(false) {} | 63 PasswordInfo() : backspace_pressed_last(false) {} |
71 }; | 64 }; |
72 typedef std::map<WebKit::WebElement, PasswordInfo> LoginToPasswordInfoMap; | 65 typedef std::map<WebKit::WebElement, PasswordInfo> LoginToPasswordInfoMap; |
73 | 66 |
| 67 // RenderView::Observer implementation. |
| 68 virtual bool OnMessageReceived(const IPC::Message& message); |
| 69 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame); |
| 70 virtual void DidFinishLoad(WebKit::WebFrame* frame); |
| 71 |
74 // PageClickListener implementation: | 72 // PageClickListener implementation: |
75 virtual bool InputElementClicked(const WebKit::WebInputElement& element, | 73 virtual bool InputElementClicked(const WebKit::WebInputElement& element, |
76 bool was_focused, | 74 bool was_focused, |
77 bool is_focused); | 75 bool is_focused); |
78 | 76 |
| 77 void OnFillPasswordForm( |
| 78 const webkit_glue::PasswordFormFillData& form_data); |
| 79 |
| 80 // Scans the given frame for password forms and sends them up to the browser. |
| 81 // If |only_visible| is true, only forms visible in the layout are sent. |
| 82 void SendPasswordForms(WebKit::WebFrame* frame, bool only_visible); |
| 83 |
79 void GetSuggestions( | 84 void GetSuggestions( |
80 const webkit_glue::PasswordFormFillData& fill_data, | 85 const webkit_glue::PasswordFormFillData& fill_data, |
81 const string16& input, | 86 const string16& input, |
82 std::vector<string16>* suggestions); | 87 std::vector<string16>* suggestions); |
83 | 88 |
84 bool ShowSuggestionPopup( | 89 bool ShowSuggestionPopup( |
85 const webkit_glue::PasswordFormFillData& fill_data, | 90 const webkit_glue::PasswordFormFillData& fill_data, |
86 const WebKit::WebInputElement& user_input); | 91 const WebKit::WebInputElement& user_input); |
87 | 92 |
88 bool FillUserNameAndPassword( | 93 bool FillUserNameAndPassword( |
89 WebKit::WebInputElement* username_element, | 94 WebKit::WebInputElement* username_element, |
90 WebKit::WebInputElement* password_element, | 95 WebKit::WebInputElement* password_element, |
91 const webkit_glue::PasswordFormFillData& fill_data, | 96 const webkit_glue::PasswordFormFillData& fill_data, |
92 bool exact_username_match); | 97 bool exact_username_match); |
93 | 98 |
94 // Convenience method that returns the routing ID of the render view we are | |
95 // associated with. | |
96 int GetRoutingID() const; | |
97 | |
98 // Weak reference. | |
99 RenderView* render_view_; | |
100 | |
101 // The logins we have filled so far with their associated info. | 99 // The logins we have filled so far with their associated info. |
102 LoginToPasswordInfoMap login_to_password_info_; | 100 LoginToPasswordInfoMap login_to_password_info_; |
103 | 101 |
104 ScopedRunnableMethodFactory<PasswordAutocompleteManager> method_factory_; | 102 ScopedRunnableMethodFactory<PasswordAutocompleteManager> method_factory_; |
105 | 103 |
106 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteManager); | 104 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteManager); |
107 }; | 105 }; |
108 | 106 |
109 #endif // CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ | 107 #endif // CHROME_RENDERER_PASSWORD_AUTOCOMPLETE_MANAGER_H_ |
OLD | NEW |