21ea9bc31946445ba48e1fdab8697f798e5e5af3
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / browser / password_manager / password_generation_manager.h
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.
5
6 #ifndef PASSWORD_GENERATION_MANAGER_H
7 #define PASSWORD_GENERATION_MANAGER_H
8
9 #if defined(TIZEN_AUTOFILL_SUPPORT)
10
11 #include <vector>
12
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"
17
18
19 namespace autofill {
20 struct FormData;
21 class FormStructure;
22 class PasswordGenerator;
23 class PasswordGenerationPopupObserver;
24 struct PasswordForm;
25 }
26
27 namespace content {
28 class RenderViewHost;
29 class WebContents;
30 }
31
32 namespace user_prefs {
33 class PrefRegistrySyncable;
34 }
35
36 namespace password_manager {
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 PasswordManager;
51 class PasswordManagerClient;
52 class PasswordManagerDriver;
53 class PasswordGenerationManager {
54  public:
55   PasswordGenerationManager(content::WebContents* contents,
56                             PasswordManagerClient* client);
57   virtual ~PasswordGenerationManager();
58
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);
64
65   // Hide any visible password generation related popups.
66   void HidePopup();
67
68   // Observer for PasswordGenerationPopup events. Used for testing.
69   void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer);
70
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,
75                                      int max_length,
76                                      const autofill::PasswordForm& form);
77
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);
81
82   // Hides any visible UI.
83   void OnHidePasswordGenerationPopup();
84
85  private:
86   friend class PasswordGenerationManagerTest;
87
88   // Determines current state of password generation
89   bool IsGenerationEnabled() const;
90
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);
96
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_;
102
103   // Observer for password generation popup.
104   autofill::PasswordGenerationPopupObserver* observer_;
105
106   // Controls how passwords are generated.
107   scoped_ptr<autofill::PasswordGenerator> password_generator_;
108
109   // Controls the popup
110   //base::WeakPtr<
111   //  autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
112
113   // The PasswordManagerClient instance associated with this instance. Must
114   // outlive this instance.
115   PasswordManagerClient* client_;
116
117   // The PasswordManagerDriver instance associated with this instance. Must
118   // outlive this instance.
119   PasswordManagerDriver* driver_;
120
121   DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager);
122 };
123 }
124
125 #endif // TIZEN_AUTOFILL_SUPPORT
126
127 #endif  // PASSWORD_GENERATION_MANAGER_H