blob: 585ec9e52247cf836ad658b236b26d05adac57d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_
#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/prefs/pref_change_registrar.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace autofill {
struct FormData;
class FormStructure;
class PasswordGenerator;
struct PasswordForm;
}
namespace user_prefs {
class PrefRegistrySyncable;
}
// Per-tab manager for password generation. Will enable this feature only if
//
// - Password manager is enabled
// - Password sync is enabled
// - Password generation pref is enabled
//
// NOTE: At the moment, the creation of the renderer PasswordGenerationManager
// is controlled by a switch (--enable-password-generation) so this feature will
// not be enabled regardless of the above criteria without the switch being
// present.
//
// When enabled we will send a message enabling this feature in the renderer,
// which will show an icon next to password fields which we think are associated
// with account creation. This class also manages the popup which is created
// if the user chooses to generate a password.
class PasswordGenerationManager
: public ProfileSyncServiceObserver,
public content::WebContentsObserver,
public content::WebContentsUserData<PasswordGenerationManager> {
public:
static void CreateForWebContents(content::WebContents* contents);
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
virtual ~PasswordGenerationManager();
// Detect account creation forms from forms with autofill type annotated.
void DetectAccountCreationForms(
const std::vector<autofill::FormStructure*>& forms);
protected:
explicit PasswordGenerationManager(content::WebContents* contents);
private:
friend class content::WebContentsUserData<PasswordGenerationManager>;
friend class PasswordGenerationManagerTest;
// WebContentsObserver:
virtual void RenderViewCreated(content::RenderViewHost* host) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE;
// ProfileSyncServiceObserver:
virtual void OnStateChanged() OVERRIDE;
// Add ourselves as an observer to the sync service to be informed of changes
// to the password sync state.
void RegisterWithSyncService();
// Start watching for changes to the password generation enabled pref.
void SetUpPrefChangeRegistrar();
void OnPrefStateChanged();
// Determines current state of password generation and sends this information
// to the renderer if it is different from |enabled_| or if |new_renderer|
// is true.
void UpdateState(content::RenderViewHost* host, bool new_renderer);
// Sends a message to the renderer enabling or disabling this feature. This
// is a separate function to aid in testing.
virtual void SendStateToRenderer(content::RenderViewHost* host, bool enabled);
virtual void SendAccountCreationFormsToRenderer(
content::RenderViewHost* host,
const std::vector<autofill::FormData>& forms);
// Causes the password generation bubble UI to be shown for the specified
// form. The popup will be anchored at |icon_bounds|. The generated
// password will be no longer than |max_length|.
void OnShowPasswordGenerationPopup(const gfx::Rect& icon_bounds,
int max_length,
const autofill::PasswordForm& form);
// Whether password generation is enabled.
bool enabled_;
// Listens for changes to the state of the password generation pref.
PrefChangeRegistrar registrar_;
// For vending a weak_ptr for |registrar_|.
base::WeakPtrFactory<PasswordGenerationManager> weak_factory_;
// Controls how passwords are generated.
scoped_ptr<autofill::PasswordGenerator> password_generator_;
DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManager);
};
#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_GENERATION_MANAGER_H_
|