- add sources.
[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 "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
12
13 namespace autofill {
14 struct FormData;
15 class FormStructure;
16 class PasswordGenerator;
17 struct PasswordForm;
18 }
19
20 namespace user_prefs {
21 class PrefRegistrySyncable;
22 }
23
24 // Per-tab manager for password generation. Will enable this feature only if
25 //
26 // -  Password manager is enabled
27 // -  Password sync is enabled
28 // -  Password generation pref is enabled
29 //
30 // NOTE: At the moment, the creation of the renderer PasswordGenerationManager
31 // is controlled by a switch (--enable-password-generation) so this feature will
32 // not be enabled regardless of the above criteria without the switch being
33 // present.
34 //
35 // This class is used to determine what forms we should offer to generate
36 // passwords for and manages the popup which is created if the user chooses to
37 // generate a password.
38 class PasswordGenerationManager
39     : public content::WebContentsObserver,
40       public content::WebContentsUserData<PasswordGenerationManager> {
41  public:
42   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
43   virtual ~PasswordGenerationManager();
44
45   // Detect account creation forms from forms with autofill type annotated.
46   // Will send a message to the renderer if we find a correctly annotated form
47   // and the feature is enabled.
48   void DetectAccountCreationForms(
49       const std::vector<autofill::FormStructure*>& forms);
50
51  protected:
52   explicit PasswordGenerationManager(content::WebContents* contents);
53
54  private:
55   friend class content::WebContentsUserData<PasswordGenerationManager>;
56   friend class PasswordGenerationManagerTest;
57
58   // WebContentsObserver:
59   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
60
61   // Determines current state of password generation
62   bool IsGenerationEnabled() const;
63
64   // Sends a message to the renderer specifying form(s) that we should enable
65   // password generation on. This is a separate function to aid in testing.
66   virtual void SendAccountCreationFormsToRenderer(
67       content::RenderViewHost* host,
68       const std::vector<autofill::FormData>& forms);
69
70   // Causes the password generation bubble UI to be shown for the specified
71   // form. The popup will be anchored at |icon_bounds|. The generated
72   // password will be no longer than |max_length|.
73   void OnShowPasswordGenerationPopup(const gfx::Rect& icon_bounds,
74                                      int max_length,
75                                      const autofill::PasswordForm& form);
76
77   // Controls how passwords are generated.
78   scoped_ptr<autofill::PasswordGenerator> password_generator_;
79
80   DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager);
81 };
82
83 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_