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 struct CredentialInfo;
29 class PasswordGenerationManager;
30 class PasswordManager;
33 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
34 class ChromePasswordManagerClient
35 : public password_manager::PasswordManagerClient,
36 public content::WebContentsObserver,
37 public content::WebContentsUserData<ChromePasswordManagerClient> {
39 virtual ~ChromePasswordManagerClient();
41 // PasswordManagerClient implementation.
42 virtual bool IsAutomaticPasswordSavingEnabled() const OVERRIDE;
43 virtual bool IsPasswordManagerEnabledForCurrentPage() const OVERRIDE;
44 virtual bool ShouldFilterAutofillResult(
45 const autofill::PasswordForm& form) OVERRIDE;
46 virtual bool IsSyncAccountCredential(
47 const std::string& username, const std::string& origin) const OVERRIDE;
48 virtual void AutofillResultsComputed() OVERRIDE;
49 virtual bool PromptUserToSavePassword(
50 scoped_ptr<password_manager::PasswordFormManager> form_to_save) OVERRIDE;
51 virtual void AutomaticPasswordSave(
52 scoped_ptr<password_manager::PasswordFormManager> saved_form_manager)
54 virtual void PasswordWasAutofilled(
55 const autofill::PasswordFormMap& best_matches) const OVERRIDE;
56 virtual void PasswordAutofillWasBlocked(
57 const autofill::PasswordFormMap& best_matches) const OVERRIDE;
58 virtual void AuthenticateAutofillAndFillForm(
59 scoped_ptr<autofill::PasswordFormFillData> fill_data) OVERRIDE;
60 virtual PrefService* GetPrefs() OVERRIDE;
61 virtual password_manager::PasswordStore* GetPasswordStore() OVERRIDE;
62 virtual password_manager::PasswordManagerDriver* GetDriver() OVERRIDE;
63 virtual base::FieldTrial::Probability GetProbabilityForExperiment(
64 const std::string& experiment_name) OVERRIDE;
65 virtual bool IsPasswordSyncEnabled() OVERRIDE;
66 virtual void OnLogRouterAvailabilityChanged(bool router_can_be_used) OVERRIDE;
67 virtual void LogSavePasswordProgress(const std::string& text) OVERRIDE;
68 virtual bool IsLoggingActive() const OVERRIDE;
69 virtual void OnNotifyFailedSignIn(
71 const password_manager::CredentialInfo&) OVERRIDE;
72 virtual void OnNotifySignedIn(
74 const password_manager::CredentialInfo&) OVERRIDE;
75 virtual void OnNotifySignedOut(int request_id) OVERRIDE;
76 virtual void OnRequestCredential(
79 const std::vector<GURL>& federations) OVERRIDE;
81 // Hides any visible generation UI.
82 void HidePasswordGenerationPopup();
84 static void CreateForWebContentsWithAutofillClient(
85 content::WebContents* contents,
86 autofill::AutofillClient* autofill_client);
88 // Convenience method to allow //chrome code easy access to a PasswordManager
89 // from a WebContents instance.
90 static password_manager::PasswordManager* GetManagerFromWebContents(
91 content::WebContents* contents);
93 // Convenience method to allow //chrome code easy access to a
94 // PasswordGenerationManager from a WebContents instance.
95 static password_manager::PasswordGenerationManager*
96 GetGenerationManagerFromWebContents(content::WebContents* contents);
98 // Observer for PasswordGenerationPopup events. Used for testing.
99 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer);
101 // Returns true if the bubble UI is enabled, and false if we're still using
102 // the sad old Infobar UI.
103 static bool IsTheHotNewBubbleUIEnabled();
105 // Returns true if the password manager should be enabled during sync signin.
106 static bool EnabledForSyncSignin();
109 // Callable for tests.
110 ChromePasswordManagerClient(content::WebContents* web_contents,
111 autofill::AutofillClient* autofill_client);
114 enum AutofillForSyncCredentialsState {
115 ALLOW_SYNC_CREDENTIALS,
116 DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH,
117 DISALLOW_SYNC_CREDENTIALS,
120 friend class content::WebContentsUserData<ChromePasswordManagerClient>;
122 // content::WebContentsObserver overrides.
123 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
125 // Callback method to be triggered when authentication is successful for a
126 // given password authentication request. If authentication is disabled or
127 // not supported, this will be triggered directly.
128 void CommitFillPasswordForm(autofill::PasswordFormFillData* fill_data);
130 // Given |bounds| in the renderers coordinate system, return the same bounds
131 // in the screens coordinate system.
132 gfx::RectF GetBoundsInScreenSpace(const gfx::RectF& bounds);
134 // Causes the password generation UI to be shown for the specified form.
135 // The popup will be anchored at |element_bounds|. The generated password
136 // will be no longer than |max_length|.
137 void ShowPasswordGenerationPopup(const gfx::RectF& bounds,
139 const autofill::PasswordForm& form);
141 // Causes the password editing UI to be shown anchored at |element_bounds|.
142 void ShowPasswordEditingPopup(
143 const gfx::RectF& bounds, const autofill::PasswordForm& form);
145 // Sends a message to the renderer with the current value of
146 // |can_use_log_router_|.
147 void NotifyRendererOfLoggingAvailability();
149 // Returns true if the last loaded page was for transactional re-auth on a
151 bool LastLoadWasTransactionalReauthPage() const;
153 // Returns true if |url| is the reauth page for accessing the password
155 bool IsURLPasswordWebsiteReauth(const GURL& url) const;
157 // Sets |autofill_state_| based on experiment and flag values.
158 void SetUpAutofillSyncState();
160 Profile* const profile_;
162 password_manager::ContentPasswordManagerDriver driver_;
164 // Observer for password generation popup.
165 autofill::PasswordGenerationPopupObserver* observer_;
167 // Controls the popup
169 autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
171 // True if |this| is registered with some LogRouter which can accept logs.
172 bool can_use_log_router_;
174 // How to handle the sync credential in ShouldFilterAutofillResult().
175 AutofillForSyncCredentialsState autofill_sync_state_;
177 // If the sync credential was filtered during autofill. Used for statistics
179 bool sync_credential_was_filtered_;
181 // Allows authentication callbacks to be destroyed when this client is gone.
182 base::WeakPtrFactory<ChromePasswordManagerClient> weak_factory_;
184 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient);
187 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_