Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / autofill / password_generation_popup_controller_impl.h
blob81143e2f24b0e11792204d14be081ba9377b41d4
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h"
13 #include "chrome/browser/ui/autofill/popup_controller_common.h"
14 #include "components/autofill/core/common/password_form.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/rect_f.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/range/range.h"
20 namespace content {
21 struct NativeWebKeyboardEvent;
22 class WebContents;
25 namespace password_manager {
26 class PasswordManager;
27 class PasswordManagerDriver;
30 namespace autofill {
32 class PasswordGenerator;
33 class PasswordGenerationPopupObserver;
34 class PasswordGenerationPopupView;
36 // This class controls a PasswordGenerationPopupView. It is responsible for
37 // determining the location of the popup, handling keypress events while the
38 // popup is active, and notifying both the renderer and the password manager
39 // if the password is accepted.
40 class PasswordGenerationPopupControllerImpl
41 : public PasswordGenerationPopupController {
42 public:
43 // Create a controller or return |previous| if it is suitable. Will hide
44 // |previous| if it is not returned. |bounds| is the bounds of the element
45 // that we are showing the dropdown for in screen space. |form| is the
46 // identifier for the form that we are filling, and is used to notify
47 // |password_manager| if the password is generated. |max_length| is used to
48 // determine the length of the password shown. If not NULL, |observer| will
49 // be notified of changes of the popup state.
50 static base::WeakPtr<PasswordGenerationPopupControllerImpl> GetOrCreate(
51 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous,
52 const gfx::RectF& bounds,
53 const PasswordForm& form,
54 int max_length,
55 password_manager::PasswordManager* password_manager,
56 password_manager::PasswordManagerDriver* driver,
57 PasswordGenerationPopupObserver* observer,
58 content::WebContents* web_contents,
59 gfx::NativeView container_view);
60 ~PasswordGenerationPopupControllerImpl() override;
62 // Create a PasswordGenerationPopupView if one doesn't already exist.
63 // If |display_password| is true, a generated password is shown that can be
64 // selected by the user. Otherwise just the text explaining generated
65 // passwords is shown. Idempotent.
66 void Show(bool display_password);
68 // Hides the popup and destroys |this|.
69 void HideAndDestroy();
71 // Accessors.
72 content::WebContents* web_contents() {
73 return controller_common_.web_contents();
76 protected:
77 PasswordGenerationPopupControllerImpl(
78 const gfx::RectF& bounds,
79 const PasswordForm& form,
80 int max_length,
81 password_manager::PasswordManager* password_manager,
82 password_manager::PasswordManagerDriver* driver,
83 PasswordGenerationPopupObserver* observer,
84 content::WebContents* web_contents,
85 gfx::NativeView container_view);
87 // Handle to the popup. May be NULL if popup isn't showing.
88 PasswordGenerationPopupView* view_;
90 private:
91 // PasswordGenerationPopupController implementation:
92 void Hide() override;
93 void ViewDestroyed() override;
94 void SetSelectionAtPoint(const gfx::Point& point) override;
95 bool AcceptSelectedLine() override;
96 void SelectionCleared() override;
97 void PasswordAccepted() override;
98 void OnSavedPasswordsLinkClicked() override;
99 int GetMinimumWidth() override;
100 gfx::NativeView container_view() override;
101 const gfx::Rect& popup_bounds() const override;
102 const gfx::RectF& element_bounds() const override;
103 bool IsRTL() const override;
104 bool display_password() const override;
105 bool password_selected() const override;
106 base::string16 password() const override;
107 base::string16 SuggestedText() override;
108 const base::string16& HelpText() override;
109 const gfx::Range& HelpTextLinkRange() override;
111 base::WeakPtr<PasswordGenerationPopupControllerImpl> GetWeakPtr();
113 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event);
115 // Set if the password is currently selected.
116 void PasswordSelected(bool selected);
118 // Accept password if it's selected.
119 bool PossiblyAcceptPassword();
121 // Get desired size of popup. Height depends on width because we do text
122 // wrapping.
123 void CalculateBounds();
125 PasswordForm form_;
126 password_manager::PasswordManager* password_manager_;
127 password_manager::PasswordManagerDriver* driver_;
129 // May be NULL.
130 PasswordGenerationPopupObserver* observer_;
132 // Controls how passwords are generated.
133 scoped_ptr<PasswordGenerator> generator_;
135 // Contains common popup functionality.
136 PopupControllerCommon controller_common_;
138 // Help text and the range in the text that corresponds to the saved passwords
139 // link.
140 base::string16 help_text_;
141 gfx::Range link_range_;
143 base::string16 current_password_;
144 bool password_selected_;
146 // If a password will be shown in this popup.
147 bool display_password_;
149 // Bounds for all the elements of the popup.
150 gfx::Rect popup_bounds_;
152 base::WeakPtrFactory<PasswordGenerationPopupControllerImpl> weak_ptr_factory_;
154 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationPopupControllerImpl);
157 } // namespace autofill
159 #endif // CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_