OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" | 12 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" |
13 #include "chrome/browser/ui/autofill/popup_controller_common.h" | 13 #include "chrome/browser/ui/autofill/popup_controller_common.h" |
14 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
15 #include "ui/gfx/font.h" | 15 #include "ui/gfx/font_list.h" |
16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
18 #include "ui/gfx/rect_f.h" | 18 #include "ui/gfx/rect_f.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 struct NativeWebKeyboardEvent; | 21 struct NativeWebKeyboardEvent; |
22 class WebContents; | 22 class WebContents; |
23 } | 23 } |
24 | 24 |
25 class PasswordManager; | 25 class PasswordManager; |
26 | 26 |
27 namespace autofill { | 27 namespace autofill { |
28 | 28 |
29 class PasswordGenerator; | 29 class PasswordGenerator; |
30 class PasswordGenerationPopupObserver; | 30 class PasswordGenerationPopupObserver; |
31 class PasswordGenerationPopupView; | 31 class PasswordGenerationPopupView; |
32 | 32 |
33 // This class controls a PasswordGenerationPopupView. It is responsible for | 33 // This class controls a PasswordGenerationPopupView. It is responsible for |
34 // determining the location of the popup, handling keypress events while the | 34 // determining the location of the popup, handling keypress events while the |
35 // popup is active, and notifying both the renderer and the password manager | 35 // popup is active, and notifying both the renderer and the password manager |
36 // if the password is accepted. | 36 // if the password is accepted. |
37 class PasswordGenerationPopupControllerImpl | 37 class PasswordGenerationPopupControllerImpl |
38 : public PasswordGenerationPopupController { | 38 : public PasswordGenerationPopupController { |
39 public: | 39 public: |
40 // Create a controller or return |previous| if it is suitable. Will hide | 40 // Create a controller or return |previous| if it is suitable. Will hide |
41 // |previous| if it is not returned. |bounds| is the bounds of the element | 41 // |previous| if it is not returned. |bounds| is the bounds of the element |
42 // that we are showing the dropdown for in screen space. |form| is the | 42 // that we are showing the dropdown for in screen space. |form| is the |
43 // identifier for the form that we are filling, and is used to notify | 43 // identifier for the form that we are filling, and is used to notify |
44 // |password_manager| if the password is generated. |generator| is used to | 44 // |password_manager| if the password is generated. |generator| is used to |
45 // create the password shown. If not NULL, |observer| will be notified of | 45 // create the password shown. These three parameters may be NULL if a |
46 // changes of the popup state. | 46 // generated password won't be suggested. If not NULL, |observer| will be |
| 47 // notified of changes of the popup state. |
47 static base::WeakPtr<PasswordGenerationPopupControllerImpl> GetOrCreate( | 48 static base::WeakPtr<PasswordGenerationPopupControllerImpl> GetOrCreate( |
48 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous, | 49 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous, |
49 const gfx::RectF& bounds, | 50 const gfx::RectF& bounds, |
50 const PasswordForm& form, | 51 PasswordForm* form, |
51 PasswordGenerator* generator, | 52 PasswordGenerator* generator, |
52 PasswordManager* password_manager, | 53 PasswordManager* password_manager, |
53 PasswordGenerationPopupObserver* observer, | 54 PasswordGenerationPopupObserver* observer, |
54 content::WebContents* web_contents, | 55 content::WebContents* web_contents, |
55 gfx::NativeView container_view); | 56 gfx::NativeView container_view); |
56 virtual ~PasswordGenerationPopupControllerImpl(); | 57 virtual ~PasswordGenerationPopupControllerImpl(); |
57 | 58 |
58 // Create a PasswordGenerationPopupView if one doesn't already exist. | 59 // Create a PasswordGenerationPopupView if one doesn't already exist. |
59 // Does not update the view if one is already showing. | 60 // If |display_password| is true, a generated password is shown that can be |
60 void Show(); | 61 // selected by the user. Otherwise just the text explaining generated |
| 62 // passwords is shown. |
| 63 void Show(bool display_password); |
| 64 |
| 65 // Hides the popup and destroys |this|. |
| 66 void HideAndDestroy(); |
| 67 |
| 68 // Setters |
| 69 void set_form(PasswordForm* form) { form_ = form; } |
| 70 void set_generator(PasswordGenerator* generator) { generator_ = generator; } |
| 71 void set_password_manager(PasswordManager* password_manager) { |
| 72 password_manager_ = password_manager; |
| 73 } |
| 74 |
61 | 75 |
62 // Accessors. | 76 // Accessors. |
63 content::WebContents* web_contents() { | 77 content::WebContents* web_contents() { |
64 return controller_common_.web_contents(); | 78 return controller_common_.web_contents(); |
65 } | 79 } |
66 const gfx::RectF& element_bounds() { | 80 const gfx::RectF& element_bounds() { |
67 return controller_common_.element_bounds(); | 81 return controller_common_.element_bounds(); |
68 } | 82 } |
69 | 83 |
70 private: | 84 private: |
71 PasswordGenerationPopupControllerImpl( | 85 PasswordGenerationPopupControllerImpl( |
72 const gfx::RectF& bounds, | 86 const gfx::RectF& bounds, |
73 const PasswordForm& form, | 87 PasswordForm* form, |
74 PasswordGenerator* generator, | 88 PasswordGenerator* generator, |
75 PasswordManager* password_manager, | 89 PasswordManager* password_manager, |
76 PasswordGenerationPopupObserver* observer, | 90 PasswordGenerationPopupObserver* observer, |
77 content::WebContents* web_contents, | 91 content::WebContents* web_contents, |
78 gfx::NativeView container_view); | 92 gfx::NativeView container_view); |
79 | 93 |
80 // PasswordGenerationPopupController implementation: | 94 // PasswordGenerationPopupController implementation: |
81 virtual void Hide() OVERRIDE; | 95 virtual void Hide() OVERRIDE; |
82 virtual void ViewDestroyed() OVERRIDE; | 96 virtual void ViewDestroyed() OVERRIDE; |
83 virtual void SetSelectionAtPoint(const gfx::Point& point) OVERRIDE; | 97 virtual void SetSelectionAtPoint(const gfx::Point& point) OVERRIDE; |
84 virtual void AcceptSelectionAtPoint(const gfx::Point& point) OVERRIDE; | 98 virtual void AcceptSelectionAtPoint(const gfx::Point& point) OVERRIDE; |
85 virtual void SelectionCleared() OVERRIDE; | 99 virtual void SelectionCleared() OVERRIDE; |
86 virtual bool ShouldRepostEvent(const ui::MouseEvent& event) OVERRIDE; | 100 virtual bool ShouldRepostEvent(const ui::MouseEvent& event) OVERRIDE; |
87 virtual bool ShouldHideOnOutsideClick() const OVERRIDE; | 101 virtual bool ShouldHideOnOutsideClick() const OVERRIDE; |
88 virtual void OnHelpLinkClicked() OVERRIDE; | 102 virtual void OnSavedPasswordsLinkClicked() OVERRIDE; |
89 virtual gfx::NativeView container_view() OVERRIDE; | 103 virtual gfx::NativeView container_view() OVERRIDE; |
| 104 virtual const gfx::FontList& font_list() const OVERRIDE; |
90 virtual const gfx::Rect& popup_bounds() const OVERRIDE; | 105 virtual const gfx::Rect& popup_bounds() const OVERRIDE; |
91 virtual const gfx::Rect& password_bounds() const OVERRIDE; | 106 virtual const gfx::Rect& password_bounds() const OVERRIDE; |
92 virtual const gfx::Rect& divider_bounds() const OVERRIDE; | 107 virtual const gfx::Rect& divider_bounds() const OVERRIDE; |
93 virtual const gfx::Rect& help_bounds() const OVERRIDE; | 108 virtual const gfx::Rect& help_bounds() const OVERRIDE; |
| 109 virtual bool display_password() const OVERRIDE; |
94 virtual bool password_selected() const OVERRIDE; | 110 virtual bool password_selected() const OVERRIDE; |
95 virtual base::string16 password() const OVERRIDE; | 111 virtual base::string16 password() const OVERRIDE; |
| 112 virtual base::string16 SuggestedText() OVERRIDE; |
96 virtual base::string16 HelpText() OVERRIDE; | 113 virtual base::string16 HelpText() OVERRIDE; |
97 virtual base::string16 LearnMoreLink() OVERRIDE; | 114 virtual base::string16 SavedPasswordsLink() OVERRIDE; |
98 | 115 |
99 base::WeakPtr<PasswordGenerationPopupControllerImpl> GetWeakPtr(); | 116 base::WeakPtr<PasswordGenerationPopupControllerImpl> GetWeakPtr(); |
100 | 117 |
101 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event); | 118 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event); |
102 | 119 |
103 // Set if the password is currently selected. | 120 // Set if the password is currently selected. |
104 void PasswordSelected(bool selected); | 121 void PasswordSelected(bool selected); |
105 | 122 |
106 // Accept the password. Causes the controller to hide itself as the popup | 123 // Accept the password. Causes the controller to hide itself as the popup |
107 // is no longer necessary. | 124 // is no longer necessary. |
108 void PasswordAccepted(); | 125 void PasswordAccepted(); |
109 | 126 |
110 // Accept password if it's selected. | 127 // Accept password if it's selected. |
111 bool PossiblyAcceptPassword(); | 128 bool PossiblyAcceptPassword(); |
112 | 129 |
113 // Get desired size of popup. Height depends on width because we do text | 130 // Get desired size of popup. Height depends on width because we do text |
114 // wrapping. | 131 // wrapping. |
115 int GetDesiredWidth(); | 132 int GetDesiredWidth(); |
116 int GetDesiredHeight(int width); | 133 int GetDesiredHeight(int width); |
117 void CalculateBounds(); | 134 void CalculateBounds(); |
118 | 135 |
119 PasswordForm form_; | 136 // These members may be NULL. |
| 137 PasswordForm* form_; |
120 PasswordGenerator* generator_; | 138 PasswordGenerator* generator_; |
121 PasswordManager* password_manager_; | 139 PasswordManager* password_manager_; |
122 PasswordGenerationPopupObserver* observer_; | 140 PasswordGenerationPopupObserver* observer_; |
123 | 141 |
124 // Contains common popup functionality. | 142 // Contains common popup functionality. |
125 PopupControllerCommon controller_common_; | 143 PopupControllerCommon controller_common_; |
126 | 144 |
127 // Handle to the popup. May be NULL if popup isn't showing. | 145 // Handle to the popup. May be NULL if popup isn't showing. |
128 PasswordGenerationPopupView* view_; | 146 PasswordGenerationPopupView* view_; |
129 | 147 |
130 // Font used in the popup. | 148 // Fonts used in the popup. |
131 gfx::Font font_; | 149 gfx::FontList font_list_; |
132 | 150 |
133 base::string16 current_password_; | 151 base::string16 current_password_; |
134 bool password_selected_; | 152 bool password_selected_; |
135 | 153 |
| 154 // If a password will be shown in this popup. |
| 155 bool display_password_; |
| 156 |
136 // Bounds for all the elements of the popup. | 157 // Bounds for all the elements of the popup. |
137 gfx::Rect popup_bounds_; | 158 gfx::Rect popup_bounds_; |
138 gfx::Rect password_bounds_; | 159 gfx::Rect password_bounds_; |
139 gfx::Rect divider_bounds_; | 160 gfx::Rect divider_bounds_; |
140 gfx::Rect help_bounds_; | 161 gfx::Rect help_bounds_; |
141 | 162 |
142 base::WeakPtrFactory<PasswordGenerationPopupControllerImpl> weak_ptr_factory_; | 163 base::WeakPtrFactory<PasswordGenerationPopupControllerImpl> weak_ptr_factory_; |
143 | 164 |
144 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationPopupControllerImpl); | 165 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationPopupControllerImpl); |
145 }; | 166 }; |
146 | 167 |
147 } // namespace autofill | 168 } // namespace autofill |
148 | 169 |
149 #endif // CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_
H_ | 170 #endif // CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_
H_ |
OLD | NEW |