Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / password_manager / password_generation_manager.h
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.
4
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_
7
8 #include <vector>
9
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"
14
15 class PasswordManager;
16 class PasswordManagerClient;
17 class PasswordManagerDriver;
18
19 namespace autofill {
20 struct FormData;
21 class FormStructure;
22 class PasswordGenerator;
23 class PasswordGenerationPopupControllerImpl;
24 class PasswordGenerationPopupObserver;
25 struct PasswordForm;
26 }
27
28 namespace content {
29 class RenderViewHost;
30 class WebContents;
31 }
32
33 namespace user_prefs {
34 class PrefRegistrySyncable;
35 }
36
37 // Per-tab manager for password generation. Will enable this feature only if
38 //
39 // -  Password manager is enabled
40 // -  Password sync is enabled
41 //
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
45 // present.
46 //
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 {
51  public:
52   PasswordGenerationManager(content::WebContents* contents,
53                             PasswordManagerClient* client);
54   virtual ~PasswordGenerationManager();
55
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);
61
62   // Hide any visible password generation related popups.
63   void HidePopup();
64
65   // Observer for PasswordGenerationPopup events. Used for testing.
66   void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer);
67
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,
72                                      int max_length,
73                                      const autofill::PasswordForm& form);
74
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);
78
79   // Hides any visible UI.
80   void OnHidePasswordGenerationPopup();
81
82  private:
83   friend class PasswordGenerationManagerTest;
84
85   // Determines current state of password generation
86   bool IsGenerationEnabled() const;
87
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);
93
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);
97
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_;
103
104   // Observer for password generation popup.
105   autofill::PasswordGenerationPopupObserver* observer_;
106
107   // Controls how passwords are generated.
108   scoped_ptr<autofill::PasswordGenerator> password_generator_;
109
110   // Controls the popup
111   base::WeakPtr<
112     autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
113
114   // The PasswordManagerClient instance associated with this instance. Must
115   // outlive this instance.
116   PasswordManagerClient* client_;
117
118   // The PasswordManagerDriver instance associated with this instance. Must
119   // outlive this instance.
120   PasswordManagerDriver* driver_;
121
122   DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager);
123 };
124
125 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_