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_credential_manager_dispatcher.h"
11 #include "components/password_manager/content/browser/content_password_manager_driver.h"
12 #include "components/password_manager/core/browser/password_manager_client.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
15 #include "ui/gfx/rect.h"
20 class PasswordGenerationPopupObserver;
21 class PasswordGenerationPopupControllerImpl;
28 namespace password_manager {
29 struct CredentialInfo;
30 class PasswordGenerationManager;
31 class PasswordManager;
34 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
35 class ChromePasswordManagerClient
36 : public password_manager::PasswordManagerClient,
37 public content::WebContentsObserver,
38 public content::WebContentsUserData<ChromePasswordManagerClient> {
40 ~ChromePasswordManagerClient() override;
42 // PasswordManagerClient implementation.
43 bool IsAutomaticPasswordSavingEnabled() const override;
44 bool IsPasswordManagerEnabledForCurrentPage() const override;
45 bool ShouldFilterAutofillResult(const autofill::PasswordForm& form) override;
46 std::string GetSyncUsername() const override;
47 bool IsSyncAccountCredential(const std::string& username,
48 const std::string& origin) const override;
49 void AutofillResultsComputed() override;
50 bool PromptUserToSavePassword(
51 scoped_ptr<password_manager::PasswordFormManager> form_to_save) override;
52 void AutomaticPasswordSave(scoped_ptr<password_manager::PasswordFormManager>
53 saved_form_manager) override;
54 void PasswordWasAutofilled(
55 const autofill::PasswordFormMap& best_matches) const override;
56 void PasswordAutofillWasBlocked(
57 const autofill::PasswordFormMap& best_matches) const override;
58 PrefService* GetPrefs() override;
59 password_manager::PasswordStore* GetPasswordStore() override;
60 password_manager::PasswordManagerDriver* GetDriver() override;
61 base::FieldTrial::Probability GetProbabilityForExperiment(
62 const std::string& experiment_name) override;
63 bool IsPasswordSyncEnabled(
64 password_manager::CustomPassphraseState state) override;
65 void OnLogRouterAvailabilityChanged(bool router_can_be_used) override;
66 void LogSavePasswordProgress(const std::string& text) override;
67 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 bool OnMessageReceived(const IPC::Message& message) override;
113 // Given |bounds| in the renderers coordinate system, return the same bounds
114 // in the screens coordinate system.
115 gfx::RectF GetBoundsInScreenSpace(const gfx::RectF& bounds);
117 // Causes the password generation UI to be shown for the specified form.
118 // The popup will be anchored at |element_bounds|. The generated password
119 // will be no longer than |max_length|.
120 void ShowPasswordGenerationPopup(const gfx::RectF& bounds,
122 const autofill::PasswordForm& form);
124 // Causes the password editing UI to be shown anchored at |element_bounds|.
125 void ShowPasswordEditingPopup(
126 const gfx::RectF& bounds, const autofill::PasswordForm& form);
128 // Sends a message to the renderer with the current value of
129 // |can_use_log_router_|.
130 void NotifyRendererOfLoggingAvailability();
132 // Returns true if the last loaded page was for transactional re-auth on a
134 bool LastLoadWasTransactionalReauthPage() const;
136 // Returns true if |url| is the reauth page for accessing the password
138 bool IsURLPasswordWebsiteReauth(const GURL& url) const;
140 // Sets |autofill_state_| based on experiment and flag values.
141 void SetUpAutofillSyncState();
143 Profile* const profile_;
145 password_manager::ContentPasswordManagerDriver driver_;
147 password_manager::ContentCredentialManagerDispatcher
148 credential_manager_dispatcher_;
150 // Observer for password generation popup.
151 autofill::PasswordGenerationPopupObserver* observer_;
153 // Controls the popup
155 autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
157 // True if |this| is registered with some LogRouter which can accept logs.
158 bool can_use_log_router_;
160 // How to handle the sync credential in ShouldFilterAutofillResult().
161 AutofillForSyncCredentialsState autofill_sync_state_;
163 // If the sync credential was filtered during autofill. Used for statistics
165 bool sync_credential_was_filtered_;
167 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient);
170 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_