1 // Copyright 2013 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_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "ui/gfx/rect.h"
15 class PasswordManager
;
16 class PasswordManagerClient
;
17 class PasswordManagerDriver
;
22 class PasswordGenerator
;
23 class PasswordGenerationPopupControllerImpl
;
24 class PasswordGenerationPopupObserver
;
33 namespace user_prefs
{
34 class PrefRegistrySyncable
;
37 // Per-tab manager for password generation. Will enable this feature only if
39 // - Password manager is enabled
40 // - Password sync is enabled
42 // NOTE: At the moment, the creation of the renderer PasswordGenerationManager
43 // is controlled by a switch (--enable-password-generation) so this feature will
44 // not be enabled regardless of the above criteria without the switch being
47 // This class is used to determine what forms we should offer to generate
48 // passwords for and manages the popup which is created if the user chooses to
49 // generate a password.
50 class PasswordGenerationManager
{
52 PasswordGenerationManager(content::WebContents
* contents
,
53 PasswordManagerClient
* client
);
54 virtual ~PasswordGenerationManager();
56 // Detect account creation forms from forms with autofill type annotated.
57 // Will send a message to the renderer if we find a correctly annotated form
58 // and the feature is enabled.
59 void DetectAccountCreationForms(
60 const std::vector
<autofill::FormStructure
*>& forms
);
62 // Hide any visible password generation related popups.
65 // Observer for PasswordGenerationPopup events. Used for testing.
66 void SetTestObserver(autofill::PasswordGenerationPopupObserver
* observer
);
68 // Causes the password generation UI to be shown for the specified form.
69 // The popup will be anchored at |element_bounds|. The generated password
70 // will be no longer than |max_length|.
71 void OnShowPasswordGenerationPopup(const gfx::RectF
& element_bounds
,
73 const autofill::PasswordForm
& form
);
75 // Causes the password editing UI to be shown anchored at |element_bounds|.
76 void OnShowPasswordEditingPopup(const gfx::RectF
& element_bounds
,
77 const autofill::PasswordForm
& form
);
79 // Hides any visible UI.
80 void OnHidePasswordGenerationPopup();
83 friend class PasswordGenerationManagerTest
;
85 // Determines current state of password generation
86 bool IsGenerationEnabled() const;
88 // Sends a message to the renderer specifying form(s) that we should enable
89 // password generation on. This is a separate function to aid in testing.
90 virtual void SendAccountCreationFormsToRenderer(
91 content::RenderViewHost
* host
,
92 const std::vector
<autofill::FormData
>& forms
);
94 // Given |bounds| in the renderers coordinate system, return the same bounds
95 // in the screens coordinate system.
96 gfx::RectF
GetBoundsInScreenSpace(const gfx::RectF
& bounds
);
98 // The WebContents instance associated with this instance. Scoped to the
99 // lifetime of this class, as this class is indirectly a WCUD via
100 // ChromePasswordManagerClient.
101 // TODO(blundell): Eliminate this ivar. crbug.com/340675
102 content::WebContents
* web_contents_
;
104 // Observer for password generation popup.
105 autofill::PasswordGenerationPopupObserver
* observer_
;
107 // Controls how passwords are generated.
108 scoped_ptr
<autofill::PasswordGenerator
> password_generator_
;
110 // Controls the popup
112 autofill::PasswordGenerationPopupControllerImpl
> popup_controller_
;
114 // The PasswordManagerClient instance associated with this instance. Must
115 // outlive this instance.
116 PasswordManagerClient
* client_
;
118 // The PasswordManagerDriver instance associated with this instance. Must
119 // outlive this instance.
120 PasswordManagerDriver
* driver_
;
122 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager
);
125 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_