1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright 2014 Samsung Electronics. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #ifndef PASSWORD_GENERATION_MANAGER_H
7 #define PASSWORD_GENERATION_MANAGER_H
9 #if defined(TIZEN_AUTOFILL_SUPPORT)
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "ui/gfx/geometry/rect.h"
22 class PasswordGenerator;
23 class PasswordGenerationPopupObserver;
32 namespace user_prefs {
33 class PrefRegistrySyncable;
36 namespace password_manager {
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 PasswordManager;
51 class PasswordManagerClient;
52 class PasswordManagerDriver;
53 class PasswordGenerationManager {
55 PasswordGenerationManager(content::WebContents* contents,
56 PasswordManagerClient* client);
57 virtual ~PasswordGenerationManager();
59 // Detect account creation forms from forms with autofill type annotated.
60 // Will send a message to the renderer if we find a correctly annotated form
61 // and the feature is enabled.
62 void DetectAccountCreationForms(
63 const std::vector<autofill::FormStructure*>& forms);
65 // Hide any visible password generation related popups.
68 // Observer for PasswordGenerationPopup events. Used for testing.
69 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer);
71 // Causes the password generation UI to be shown for the specified form.
72 // The popup will be anchored at |element_bounds|. The generated password
73 // will be no longer than |max_length|.
74 void OnShowPasswordGenerationPopup(const gfx::RectF& element_bounds,
76 const autofill::PasswordForm& form);
78 // Causes the password editing UI to be shown anchored at |element_bounds|.
79 void OnShowPasswordEditingPopup(const gfx::RectF& element_bounds,
80 const autofill::PasswordForm& form);
82 // Hides any visible UI.
83 void OnHidePasswordGenerationPopup();
86 friend class PasswordGenerationManagerTest;
88 // Determines current state of password generation
89 bool IsGenerationEnabled() const;
91 // Sends a message to the renderer specifying form(s) that we should enable
92 // password generation on. This is a separate function to aid in testing.
93 virtual void SendAccountCreationFormsToRenderer(
94 content::RenderViewHost* host,
95 const std::vector<autofill::FormData>& forms);
97 // The WebContents instance associated with this instance. Scoped to the
98 // lifetime of this class, as this class is indirectly a WCUD via
99 // ChromePasswordManagerClient.
100 // TODO(blundell): Eliminate this ivar. crbug.com/340675
101 content::WebContents* web_contents_;
103 // Observer for password generation popup.
104 autofill::PasswordGenerationPopupObserver* observer_;
106 // Controls how passwords are generated.
107 scoped_ptr<autofill::PasswordGenerator> password_generator_;
109 // Controls the popup
111 // autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
113 // The PasswordManagerClient instance associated with this instance. Must
114 // outlive this instance.
115 PasswordManagerClient* client_;
117 // The PasswordManagerDriver instance associated with this instance. Must
118 // outlive this instance.
119 PasswordManagerDriver* driver_;
121 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager);
125 #endif // TIZEN_AUTOFILL_SUPPORT
127 #endif // PASSWORD_GENERATION_MANAGER_H