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 "base/prefs/pref_member.h"
11 #include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
12 #include "components/password_manager/content/browser/credential_manager_dispatcher.h"
13 #include "components/password_manager/core/browser/password_manager.h"
14 #include "components/password_manager/core/browser/password_manager_client.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_user_data.h"
17 #include "ui/gfx/geometry/rect.h"
22 class PasswordGenerationPopupObserver
;
23 class PasswordGenerationPopupControllerImpl
;
30 namespace password_manager
{
31 struct CredentialInfo
;
32 class PasswordGenerationManager
;
33 class PasswordManagerDriver
;
36 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
37 class ChromePasswordManagerClient
38 : public password_manager::PasswordManagerClient
,
39 public content::WebContentsObserver
,
40 public content::WebContentsUserData
<ChromePasswordManagerClient
> {
42 ~ChromePasswordManagerClient() override
;
44 // PasswordManagerClient implementation.
45 bool IsAutomaticPasswordSavingEnabled() const override
;
46 bool IsPasswordManagementEnabledForCurrentPage() const override
;
47 bool IsSavingEnabledForCurrentPage() const override
;
48 bool ShouldFilterAutofillResult(const autofill::PasswordForm
& form
) override
;
49 std::string
GetSyncUsername() const override
;
50 bool IsSyncAccountCredential(const std::string
& username
,
51 const std::string
& realm
) const override
;
52 void AutofillResultsComputed() override
;
53 bool PromptUserToSaveOrUpdatePassword(
54 scoped_ptr
<password_manager::PasswordFormManager
> form_to_save
,
55 password_manager::CredentialSourceType type
,
56 bool update_password
) override
;
57 bool PromptUserToChooseCredentials(
58 ScopedVector
<autofill::PasswordForm
> local_forms
,
59 ScopedVector
<autofill::PasswordForm
> federated_forms
,
61 base::Callback
<void(const password_manager::CredentialInfo
&)> callback
)
63 void ForceSavePassword() override
;
64 void NotifyUserAutoSignin(
65 ScopedVector
<autofill::PasswordForm
> local_forms
) override
;
66 void AutomaticPasswordSave(scoped_ptr
<password_manager::PasswordFormManager
>
67 saved_form_manager
) override
;
68 void PasswordWasAutofilled(
69 const autofill::PasswordFormMap
& best_matches
) const override
;
70 void PasswordAutofillWasBlocked(
71 const autofill::PasswordFormMap
& best_matches
) const override
;
72 PrefService
* GetPrefs() override
;
73 password_manager::PasswordStore
* GetPasswordStore() const override
;
74 password_manager::PasswordSyncState
GetPasswordSyncState() const override
;
75 void OnLogRouterAvailabilityChanged(bool router_can_be_used
) override
;
76 void LogSavePasswordProgress(const std::string
& text
) const override
;
77 bool IsLoggingActive() const override
;
78 bool WasLastNavigationHTTPError() const override
;
79 bool DidLastPageLoadEncounterSSLErrors() const override
;
80 bool IsOffTheRecord() const override
;
81 password_manager::PasswordManager
* GetPasswordManager() override
;
82 autofill::AutofillManager
* GetAutofillManagerForMainFrame() override
;
83 const GURL
& GetMainFrameURL() const override
;
84 bool IsUpdatePasswordUIEnabled() const override
;
86 // Hides any visible generation UI.
87 void HidePasswordGenerationPopup();
89 static void CreateForWebContentsWithAutofillClient(
90 content::WebContents
* contents
,
91 autofill::AutofillClient
* autofill_client
);
93 // Observer for PasswordGenerationPopup events. Used for testing.
94 void SetTestObserver(autofill::PasswordGenerationPopupObserver
* observer
);
96 // Returns true if the bubble UI is enabled, and false if we're still using
97 // the sad old Infobar UI.
98 static bool IsTheHotNewBubbleUIEnabled();
100 // Returns true if the password manager should be enabled during sync signin.
101 static bool EnabledForSyncSignin();
104 // Callable for tests.
105 ChromePasswordManagerClient(content::WebContents
* web_contents
,
106 autofill::AutofillClient
* autofill_client
);
109 enum AutofillForSyncCredentialsState
{
110 ALLOW_SYNC_CREDENTIALS
,
111 DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH
,
112 DISALLOW_SYNC_CREDENTIALS
,
115 friend class content::WebContentsUserData
<ChromePasswordManagerClient
>;
117 // content::WebContentsObserver overrides.
118 bool OnMessageReceived(const IPC::Message
& message
,
119 content::RenderFrameHost
* render_frame_host
) override
;
121 // Given |bounds| in the renderers coordinate system, return the same bounds
122 // in the screens coordinate system.
123 gfx::RectF
GetBoundsInScreenSpace(const gfx::RectF
& bounds
);
125 // Causes the password generation UI to be shown for the specified form.
126 // The popup will be anchored at |element_bounds|. The generated password
127 // will be no longer than |max_length|.
128 void ShowPasswordGenerationPopup(content::RenderFrameHost
* render_frame_host
,
129 const gfx::RectF
& bounds
,
131 const autofill::PasswordForm
& form
);
133 // Causes the password editing UI to be shown anchored at |element_bounds|.
134 void ShowPasswordEditingPopup(content::RenderFrameHost
* render_frame_host
,
135 const gfx::RectF
& bounds
,
136 const autofill::PasswordForm
& form
);
138 // Sends a message to the renderer with the current value of
139 // |can_use_log_router_|.
140 void NotifyRendererOfLoggingAvailability();
142 // Returns true if the last loaded page was for transactional re-auth on a
144 bool LastLoadWasTransactionalReauthPage() const;
146 // Returns true if |url| is the reauth page for accessing the password
148 bool IsURLPasswordWebsiteReauth(const GURL
& url
) const;
150 // Sets |autofill_state_| based on experiment and flag values.
151 void SetUpAutofillSyncState();
153 Profile
* const profile_
;
155 password_manager::PasswordManager password_manager_
;
157 password_manager::ContentPasswordManagerDriverFactory
* driver_factory_
;
159 password_manager::CredentialManagerDispatcher
160 credential_manager_dispatcher_
;
162 // Observer for password generation popup.
163 autofill::PasswordGenerationPopupObserver
* observer_
;
165 // Controls the popup
167 autofill::PasswordGenerationPopupControllerImpl
> popup_controller_
;
169 // True if |this| is registered with some LogRouter which can accept logs.
170 bool can_use_log_router_
;
172 // How to handle the sync credential in ShouldFilterAutofillResult().
173 AutofillForSyncCredentialsState autofill_sync_state_
;
175 // If the sync credential was filtered during autofill. Used for statistics
177 bool sync_credential_was_filtered_
;
179 // Set to false to disable password saving (will no longer ask if you
180 // want to save passwords but will continue to fill passwords).
181 BooleanPrefMember saving_passwords_enabled_
;
183 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient
);
186 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_