1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "components/password_manager/content/browser/content_password_manager_driver.h"
11 #include "components/password_manager/core/browser/password_manager_client.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h"
14 #include "ui/gfx/rect.h"
19 class PasswordGenerationPopupObserver
;
20 class PasswordGenerationPopupControllerImpl
;
27 namespace password_manager
{
28 class PasswordGenerationManager
;
29 class PasswordManager
;
32 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
33 class ChromePasswordManagerClient
34 : public password_manager::PasswordManagerClient
,
35 public content::WebContentsObserver
,
36 public content::WebContentsUserData
<ChromePasswordManagerClient
> {
38 virtual ~ChromePasswordManagerClient();
40 // PasswordManagerClient implementation.
41 virtual bool IsAutomaticPasswordSavingEnabled() const OVERRIDE
;
42 virtual bool IsPasswordManagerEnabledForCurrentPage() const OVERRIDE
;
43 virtual bool ShouldFilterAutofillResult(
44 const autofill::PasswordForm
& form
) OVERRIDE
;
45 virtual bool IsSyncAccountCredential(
46 const std::string
& username
, const std::string
& origin
) const OVERRIDE
;
47 virtual void AutofillResultsComputed() OVERRIDE
;
48 virtual void PromptUserToSavePassword(
49 scoped_ptr
<password_manager::PasswordFormManager
> form_to_save
) OVERRIDE
;
50 virtual void AutomaticPasswordSave(
51 scoped_ptr
<password_manager::PasswordFormManager
> saved_form_manager
)
53 virtual void PasswordWasAutofilled(
54 const autofill::PasswordFormMap
& best_matches
) const OVERRIDE
;
55 virtual void PasswordAutofillWasBlocked(
56 const autofill::PasswordFormMap
& best_matches
) const OVERRIDE
;
57 virtual void AuthenticateAutofillAndFillForm(
58 scoped_ptr
<autofill::PasswordFormFillData
> fill_data
) OVERRIDE
;
59 virtual PrefService
* GetPrefs() OVERRIDE
;
60 virtual password_manager::PasswordStore
* GetPasswordStore() OVERRIDE
;
61 virtual password_manager::PasswordManagerDriver
* GetDriver() OVERRIDE
;
62 virtual base::FieldTrial::Probability
GetProbabilityForExperiment(
63 const std::string
& experiment_name
) OVERRIDE
;
64 virtual bool IsPasswordSyncEnabled() OVERRIDE
;
65 virtual void OnLogRouterAvailabilityChanged(bool router_can_be_used
) OVERRIDE
;
66 virtual void LogSavePasswordProgress(const std::string
& text
) OVERRIDE
;
67 virtual bool IsLoggingActive() const OVERRIDE
;
69 // Hides any visible generation UI.
70 void HidePasswordGenerationPopup();
72 static void CreateForWebContentsWithAutofillClient(
73 content::WebContents
* contents
,
74 autofill::AutofillClient
* autofill_client
);
76 // Convenience method to allow //chrome code easy access to a PasswordManager
77 // from a WebContents instance.
78 static password_manager::PasswordManager
* GetManagerFromWebContents(
79 content::WebContents
* contents
);
81 // Convenience method to allow //chrome code easy access to a
82 // PasswordGenerationManager from a WebContents instance.
83 static password_manager::PasswordGenerationManager
*
84 GetGenerationManagerFromWebContents(content::WebContents
* contents
);
86 // Observer for PasswordGenerationPopup events. Used for testing.
87 void SetTestObserver(autofill::PasswordGenerationPopupObserver
* observer
);
89 // Returns true if the bubble UI is enabled, and false if we're still using
90 // the sad old Infobar UI.
91 static bool IsTheHotNewBubbleUIEnabled();
93 // Returns true if the password manager should be enabled during sync signin.
94 static bool EnabledForSyncSignin();
97 // Callable for tests.
98 ChromePasswordManagerClient(content::WebContents
* web_contents
,
99 autofill::AutofillClient
* autofill_client
);
102 enum AutofillForSyncCredentialsState
{
103 ALLOW_SYNC_CREDENTIALS
,
104 DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH
,
105 DISALLOW_SYNC_CREDENTIALS
,
108 friend class content::WebContentsUserData
<ChromePasswordManagerClient
>;
110 // content::WebContentsObserver overrides.
111 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
113 // Callback method to be triggered when authentication is successful for a
114 // given password authentication request. If authentication is disabled or
115 // not supported, this will be triggered directly.
116 void CommitFillPasswordForm(autofill::PasswordFormFillData
* fill_data
);
118 // Given |bounds| in the renderers coordinate system, return the same bounds
119 // in the screens coordinate system.
120 gfx::RectF
GetBoundsInScreenSpace(const gfx::RectF
& bounds
);
122 // Causes the password generation UI to be shown for the specified form.
123 // The popup will be anchored at |element_bounds|. The generated password
124 // will be no longer than |max_length|.
125 void ShowPasswordGenerationPopup(const gfx::RectF
& bounds
,
127 const autofill::PasswordForm
& form
);
129 // Causes the password editing UI to be shown anchored at |element_bounds|.
130 void ShowPasswordEditingPopup(
131 const gfx::RectF
& bounds
, const autofill::PasswordForm
& form
);
133 // Sends a message to the renderer with the current value of
134 // |can_use_log_router_|.
135 void NotifyRendererOfLoggingAvailability();
137 // Returns true if the last loaded page was for transactional re-auth on a
139 bool LastLoadWasTransactionalReauthPage() const;
141 // Sets |autofill_state_| based on experiment and flag values.
142 void SetUpAutofillSyncState();
144 Profile
* const profile_
;
146 password_manager::ContentPasswordManagerDriver driver_
;
148 // Observer for password generation popup.
149 autofill::PasswordGenerationPopupObserver
* observer_
;
151 // Controls the popup
153 autofill::PasswordGenerationPopupControllerImpl
> popup_controller_
;
155 // Allows authentication callbacks to be destroyed when this client is gone.
156 base::WeakPtrFactory
<ChromePasswordManagerClient
> weak_factory_
;
158 // True if |this| is registered with some LogRouter which can accept logs.
159 bool can_use_log_router_
;
161 // How to handle the sync credential in ShouldFilterAutofillResult().
162 AutofillForSyncCredentialsState autofill_sync_state_
;
164 // If the sync credential was filtered during autofill. Used for statistics
166 bool sync_credential_was_filtered_
;
168 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient
);
171 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_