OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
12 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 | 14 |
| 15 class PasswordManager; |
| 16 class PasswordManagerDelegate; |
| 17 class PasswordManagerDriver; |
| 18 |
15 namespace autofill { | 19 namespace autofill { |
16 struct FormData; | 20 struct FormData; |
17 class FormStructure; | 21 class FormStructure; |
18 class PasswordGenerator; | 22 class PasswordGenerator; |
19 class PasswordGenerationPopupControllerImpl; | 23 class PasswordGenerationPopupControllerImpl; |
20 class PasswordGenerationPopupObserver; | 24 class PasswordGenerationPopupObserver; |
21 struct PasswordForm; | 25 struct PasswordForm; |
22 } | 26 } |
23 | 27 |
24 namespace user_prefs { | 28 namespace user_prefs { |
25 class PrefRegistrySyncable; | 29 class PrefRegistrySyncable; |
26 } | 30 } |
27 | 31 |
28 // Per-tab manager for password generation. Will enable this feature only if | 32 // Per-tab manager for password generation. Will enable this feature only if |
29 // | 33 // |
30 // - Password manager is enabled | 34 // - Password manager is enabled |
31 // - Password sync is enabled | 35 // - Password sync is enabled |
32 // | 36 // |
33 // NOTE: At the moment, the creation of the renderer PasswordGenerationManager | 37 // NOTE: At the moment, the creation of the renderer PasswordGenerationManager |
34 // is controlled by a switch (--enable-password-generation) so this feature will | 38 // is controlled by a switch (--enable-password-generation) so this feature will |
35 // not be enabled regardless of the above criteria without the switch being | 39 // not be enabled regardless of the above criteria without the switch being |
36 // present. | 40 // present. |
37 // | 41 // |
38 // This class is used to determine what forms we should offer to generate | 42 // This class is used to determine what forms we should offer to generate |
39 // passwords for and manages the popup which is created if the user chooses to | 43 // passwords for and manages the popup which is created if the user chooses to |
40 // generate a password. | 44 // generate a password. |
41 class PasswordGenerationManager | 45 class PasswordGenerationManager : public content::WebContentsObserver { |
42 : public content::WebContentsObserver, | |
43 public content::WebContentsUserData<PasswordGenerationManager> { | |
44 public: | 46 public: |
| 47 PasswordGenerationManager(content::WebContents* contents, |
| 48 PasswordManagerDelegate* delegate); |
45 virtual ~PasswordGenerationManager(); | 49 virtual ~PasswordGenerationManager(); |
46 | 50 |
47 // Detect account creation forms from forms with autofill type annotated. | 51 // Detect account creation forms from forms with autofill type annotated. |
48 // Will send a message to the renderer if we find a correctly annotated form | 52 // Will send a message to the renderer if we find a correctly annotated form |
49 // and the feature is enabled. | 53 // and the feature is enabled. |
50 void DetectAccountCreationForms( | 54 void DetectAccountCreationForms( |
51 const std::vector<autofill::FormStructure*>& forms); | 55 const std::vector<autofill::FormStructure*>& forms); |
52 | 56 |
53 // Hide any visible password generation related popups. | 57 // Hide any visible password generation related popups. |
54 void HidePopup(); | 58 void HidePopup(); |
55 | 59 |
56 // Observer for PasswordGenerationPopup events. Used for testing. | 60 // Observer for PasswordGenerationPopup events. Used for testing. |
57 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer); | 61 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer); |
58 | 62 |
59 protected: | |
60 explicit PasswordGenerationManager(content::WebContents* contents); | |
61 | |
62 private: | 63 private: |
63 friend class content::WebContentsUserData<PasswordGenerationManager>; | |
64 friend class PasswordGenerationManagerTest; | 64 friend class PasswordGenerationManagerTest; |
65 | 65 |
66 // WebContentsObserver: | 66 // WebContentsObserver: |
67 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 67 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
68 | 68 |
69 // Determines current state of password generation | 69 // Determines current state of password generation |
70 bool IsGenerationEnabled() const; | 70 bool IsGenerationEnabled() const; |
71 | 71 |
72 // Sends a message to the renderer specifying form(s) that we should enable | 72 // Sends a message to the renderer specifying form(s) that we should enable |
73 // password generation on. This is a separate function to aid in testing. | 73 // password generation on. This is a separate function to aid in testing. |
(...skipping 21 matching lines...) Expand all Loading... |
95 // Observer for password generation popup. | 95 // Observer for password generation popup. |
96 autofill::PasswordGenerationPopupObserver* observer_; | 96 autofill::PasswordGenerationPopupObserver* observer_; |
97 | 97 |
98 // Controls how passwords are generated. | 98 // Controls how passwords are generated. |
99 scoped_ptr<autofill::PasswordGenerator> password_generator_; | 99 scoped_ptr<autofill::PasswordGenerator> password_generator_; |
100 | 100 |
101 // Controls the popup | 101 // Controls the popup |
102 base::WeakPtr< | 102 base::WeakPtr< |
103 autofill::PasswordGenerationPopupControllerImpl> popup_controller_; | 103 autofill::PasswordGenerationPopupControllerImpl> popup_controller_; |
104 | 104 |
| 105 // The PasswordManagerDelegate instance associated with this instance. Must |
| 106 // outlive this instance. |
| 107 PasswordManagerDelegate* delegate_; |
| 108 |
| 109 // The PasswordManagerDriver instance associated with this instance. Must |
| 110 // outlive this instance. |
| 111 PasswordManagerDriver* driver_; |
| 112 |
105 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager); | 113 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager); |
106 }; | 114 }; |
107 | 115 |
108 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_ | 116 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_ |
OLD | NEW |