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" |
(...skipping 24 matching lines...) Expand all Loading... | |
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 const 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); | |
61 | 64 |
62 // Hides the popup and destroys |this|. | 65 // Hides the popup and destroys |this|. |
63 void HideAndDestroy(); | 66 void HideAndDestroy(); |
64 | 67 |
68 // Setters | |
69 void set_form(const PasswordForm* form) { form_ = form; } | |
Evan Stade
2014/02/07 21:45:48
why are these public? why do you need them at all?
Garrett Casto
2014/02/10 11:02:44
They were there because in the editing form of the
| |
70 void set_generator(PasswordGenerator* generator) { generator_ = generator; } | |
71 void set_password_manager(PasswordManager* password_manager) { | |
72 password_manager_ = password_manager; | |
73 } | |
74 | |
75 | |
65 // Accessors. | 76 // Accessors. |
66 content::WebContents* web_contents() { | 77 content::WebContents* web_contents() { |
67 return controller_common_.web_contents(); | 78 return controller_common_.web_contents(); |
68 } | 79 } |
69 const gfx::RectF& element_bounds() { | 80 const gfx::RectF& element_bounds() { |
70 return controller_common_.element_bounds(); | 81 return controller_common_.element_bounds(); |
71 } | 82 } |
72 | 83 |
73 private: | 84 private: |
74 PasswordGenerationPopupControllerImpl( | 85 PasswordGenerationPopupControllerImpl( |
75 const gfx::RectF& bounds, | 86 const gfx::RectF& bounds, |
76 const PasswordForm& form, | 87 const PasswordForm* form, |
77 PasswordGenerator* generator, | 88 PasswordGenerator* generator, |
78 PasswordManager* password_manager, | 89 PasswordManager* password_manager, |
79 PasswordGenerationPopupObserver* observer, | 90 PasswordGenerationPopupObserver* observer, |
80 content::WebContents* web_contents, | 91 content::WebContents* web_contents, |
81 gfx::NativeView container_view); | 92 gfx::NativeView container_view); |
82 | 93 |
83 // PasswordGenerationPopupController implementation: | 94 // PasswordGenerationPopupController implementation: |
84 virtual void Hide() OVERRIDE; | 95 virtual void Hide() OVERRIDE; |
85 virtual void ViewDestroyed() OVERRIDE; | 96 virtual void ViewDestroyed() OVERRIDE; |
86 virtual void SetSelectionAtPoint(const gfx::Point& point) OVERRIDE; | 97 virtual void SetSelectionAtPoint(const gfx::Point& point) OVERRIDE; |
87 virtual void AcceptSelectionAtPoint(const gfx::Point& point) OVERRIDE; | 98 virtual void AcceptSelectionAtPoint(const gfx::Point& point) OVERRIDE; |
88 virtual void SelectionCleared() OVERRIDE; | 99 virtual void SelectionCleared() OVERRIDE; |
89 virtual bool ShouldRepostEvent(const ui::MouseEvent& event) OVERRIDE; | 100 virtual bool ShouldRepostEvent(const ui::MouseEvent& event) OVERRIDE; |
90 virtual bool ShouldHideOnOutsideClick() const OVERRIDE; | 101 virtual bool ShouldHideOnOutsideClick() const OVERRIDE; |
91 virtual void OnHelpLinkClicked() OVERRIDE; | 102 virtual void OnSavedPasswordsLinkClicked() OVERRIDE; |
92 virtual gfx::NativeView container_view() OVERRIDE; | 103 virtual gfx::NativeView container_view() OVERRIDE; |
104 virtual const gfx::FontList& font_list() const OVERRIDE; | |
93 virtual const gfx::Rect& popup_bounds() const OVERRIDE; | 105 virtual const gfx::Rect& popup_bounds() const OVERRIDE; |
94 virtual const gfx::Rect& password_bounds() const OVERRIDE; | 106 virtual const gfx::Rect& password_bounds() const OVERRIDE; |
95 virtual const gfx::Rect& divider_bounds() const OVERRIDE; | 107 virtual const gfx::Rect& divider_bounds() const OVERRIDE; |
96 virtual const gfx::Rect& help_bounds() const OVERRIDE; | 108 virtual const gfx::Rect& help_bounds() const OVERRIDE; |
109 virtual bool display_password() const OVERRIDE; | |
97 virtual bool password_selected() const OVERRIDE; | 110 virtual bool password_selected() const OVERRIDE; |
98 virtual base::string16 password() const OVERRIDE; | 111 virtual base::string16 password() const OVERRIDE; |
112 virtual base::string16 SuggestedText() OVERRIDE; | |
99 virtual base::string16 HelpText() OVERRIDE; | 113 virtual base::string16 HelpText() OVERRIDE; |
100 virtual base::string16 LearnMoreLink() OVERRIDE; | 114 virtual base::string16 SavedPasswordsLink() OVERRIDE; |
101 | 115 |
102 base::WeakPtr<PasswordGenerationPopupControllerImpl> GetWeakPtr(); | 116 base::WeakPtr<PasswordGenerationPopupControllerImpl> GetWeakPtr(); |
103 | 117 |
104 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event); | 118 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event); |
105 | 119 |
106 // Set if the password is currently selected. | 120 // Set if the password is currently selected. |
107 void PasswordSelected(bool selected); | 121 void PasswordSelected(bool selected); |
108 | 122 |
109 // 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 |
110 // is no longer necessary. | 124 // is no longer necessary. |
111 void PasswordAccepted(); | 125 void PasswordAccepted(); |
112 | 126 |
113 // Accept password if it's selected. | 127 // Accept password if it's selected. |
114 bool PossiblyAcceptPassword(); | 128 bool PossiblyAcceptPassword(); |
115 | 129 |
116 // 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 |
117 // wrapping. | 131 // wrapping. |
118 int GetDesiredWidth(); | 132 int GetDesiredWidth(); |
119 int GetDesiredHeight(int width); | 133 int GetDesiredHeight(int width); |
120 void CalculateBounds(); | 134 void CalculateBounds(); |
121 | 135 |
122 PasswordForm form_; | 136 // These members may be NULL. |
137 const PasswordForm* form_; | |
Evan Stade
2014/02/07 21:45:48
why can this be null?
Garrett Casto
2014/02/10 11:02:44
N/A now, but if a password isn't displayed this va
| |
123 PasswordGenerator* generator_; | 138 PasswordGenerator* generator_; |
124 PasswordManager* password_manager_; | 139 PasswordManager* password_manager_; |
125 PasswordGenerationPopupObserver* observer_; | 140 PasswordGenerationPopupObserver* observer_; |
126 | 141 |
127 // Contains common popup functionality. | 142 // Contains common popup functionality. |
128 PopupControllerCommon controller_common_; | 143 PopupControllerCommon controller_common_; |
129 | 144 |
130 // 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. |
131 PasswordGenerationPopupView* view_; | 146 PasswordGenerationPopupView* view_; |
132 | 147 |
133 // Font list used in the popup. | 148 // Font list used in the popup. |
134 gfx::FontList font_list_; | 149 gfx::FontList font_list_; |
135 | 150 |
136 base::string16 current_password_; | 151 base::string16 current_password_; |
137 bool password_selected_; | 152 bool password_selected_; |
138 | 153 |
154 // If a password will be shown in this popup. | |
155 bool display_password_; | |
156 | |
139 // Bounds for all the elements of the popup. | 157 // Bounds for all the elements of the popup. |
140 gfx::Rect popup_bounds_; | 158 gfx::Rect popup_bounds_; |
141 gfx::Rect password_bounds_; | 159 gfx::Rect password_bounds_; |
142 gfx::Rect divider_bounds_; | 160 gfx::Rect divider_bounds_; |
143 gfx::Rect help_bounds_; | 161 gfx::Rect help_bounds_; |
144 | 162 |
145 base::WeakPtrFactory<PasswordGenerationPopupControllerImpl> weak_ptr_factory_; | 163 base::WeakPtrFactory<PasswordGenerationPopupControllerImpl> weak_ptr_factory_; |
146 | 164 |
147 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationPopupControllerImpl); | 165 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationPopupControllerImpl); |
148 }; | 166 }; |
149 | 167 |
150 } // namespace autofill | 168 } // namespace autofill |
151 | 169 |
152 #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 |