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_factory.h"
11 #include "components/password_manager/content/browser/credential_manager_dispatcher.h"
12 #include "components/password_manager/core/browser/password_manager.h"
13 #include "components/password_manager/core/browser/password_manager_client.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h"
16 #include "ui/gfx/geometry/rect.h"
21 class PasswordGenerationPopupObserver
;
22 class PasswordGenerationPopupControllerImpl
;
29 namespace password_manager
{
30 struct CredentialInfo
;
31 class PasswordGenerationManager
;
32 class PasswordManagerDriver
;
35 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
36 class ChromePasswordManagerClient
37 : public password_manager::PasswordManagerClient
,
38 public content::WebContentsObserver
,
39 public content::WebContentsUserData
<ChromePasswordManagerClient
> {
41 ~ChromePasswordManagerClient() override
;
43 // PasswordManagerClient implementation.
44 bool IsAutomaticPasswordSavingEnabled() const override
;
45 bool IsPasswordManagerEnabledForCurrentPage() const override
;
46 bool ShouldFilterAutofillResult(const autofill::PasswordForm
& form
) override
;
47 std::string
GetSyncUsername() const override
;
48 bool IsSyncAccountCredential(const std::string
& username
,
49 const std::string
& origin
) const override
;
50 void AutofillResultsComputed() override
;
51 bool PromptUserToSavePassword(
52 scoped_ptr
<password_manager::PasswordFormManager
> form_to_save
,
53 password_manager::CredentialSourceType type
) override
;
54 bool PromptUserToChooseCredentials(
55 ScopedVector
<autofill::PasswordForm
> local_forms
,
56 ScopedVector
<autofill::PasswordForm
> federated_forms
,
58 base::Callback
<void(const password_manager::CredentialInfo
&)> callback
)
60 void NotifyUserAutoSignin(
61 ScopedVector
<autofill::PasswordForm
> local_forms
) override
;
62 void AutomaticPasswordSave(scoped_ptr
<password_manager::PasswordFormManager
>
63 saved_form_manager
) override
;
64 void PasswordWasAutofilled(
65 const autofill::PasswordFormMap
& best_matches
) const override
;
66 void PasswordAutofillWasBlocked(
67 const autofill::PasswordFormMap
& best_matches
) const override
;
68 PrefService
* GetPrefs() override
;
69 password_manager::PasswordStore
* GetPasswordStore() const override
;
70 bool IsPasswordSyncEnabled(
71 password_manager::CustomPassphraseState state
) const override
;
72 void OnLogRouterAvailabilityChanged(bool router_can_be_used
) override
;
73 void LogSavePasswordProgress(const std::string
& text
) const override
;
74 bool IsLoggingActive() const override
;
75 bool WasLastNavigationHTTPError() const override
;
76 bool DidLastPageLoadEncounterSSLErrors() const override
;
77 bool IsOffTheRecord() const override
;
78 password_manager::PasswordManager
* GetPasswordManager() override
;
79 autofill::AutofillManager
* GetAutofillManagerForMainFrame() override
;
80 const GURL
& GetMainFrameURL() const override
;
82 // Hides any visible generation UI.
83 void HidePasswordGenerationPopup();
85 static void CreateForWebContentsWithAutofillClient(
86 content::WebContents
* contents
,
87 autofill::AutofillClient
* autofill_client
);
89 // Observer for PasswordGenerationPopup events. Used for testing.
90 void SetTestObserver(autofill::PasswordGenerationPopupObserver
* observer
);
92 // Returns true if the bubble UI is enabled, and false if we're still using
93 // the sad old Infobar UI.
94 static bool IsTheHotNewBubbleUIEnabled();
96 // Returns true if the password manager should be enabled during sync signin.
97 static bool EnabledForSyncSignin();
100 // Callable for tests.
101 ChromePasswordManagerClient(content::WebContents
* web_contents
,
102 autofill::AutofillClient
* autofill_client
);
105 enum AutofillForSyncCredentialsState
{
106 ALLOW_SYNC_CREDENTIALS
,
107 DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH
,
108 DISALLOW_SYNC_CREDENTIALS
,
111 friend class content::WebContentsUserData
<ChromePasswordManagerClient
>;
113 // content::WebContentsObserver overrides.
114 bool OnMessageReceived(const IPC::Message
& message
,
115 content::RenderFrameHost
* render_frame_host
) override
;
117 // Given |bounds| in the renderers coordinate system, return the same bounds
118 // in the screens coordinate system.
119 gfx::RectF
GetBoundsInScreenSpace(const gfx::RectF
& bounds
);
121 // Causes the password generation UI to be shown for the specified form.
122 // The popup will be anchored at |element_bounds|. The generated password
123 // will be no longer than |max_length|.
124 void ShowPasswordGenerationPopup(content::RenderFrameHost
* render_frame_host
,
125 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(content::RenderFrameHost
* render_frame_host
,
131 const gfx::RectF
& bounds
,
132 const autofill::PasswordForm
& form
);
134 // Sends a message to the renderer with the current value of
135 // |can_use_log_router_|.
136 void NotifyRendererOfLoggingAvailability();
138 // Returns true if the last loaded page was for transactional re-auth on a
140 bool LastLoadWasTransactionalReauthPage() const;
142 // Returns true if |url| is the reauth page for accessing the password
144 bool IsURLPasswordWebsiteReauth(const GURL
& url
) const;
146 // Sets |autofill_state_| based on experiment and flag values.
147 void SetUpAutofillSyncState();
149 Profile
* const profile_
;
151 password_manager::PasswordManager password_manager_
;
153 password_manager::ContentPasswordManagerDriverFactory
* driver_factory_
;
155 password_manager::CredentialManagerDispatcher
156 credential_manager_dispatcher_
;
158 // Observer for password generation popup.
159 autofill::PasswordGenerationPopupObserver
* observer_
;
161 // Controls the popup
163 autofill::PasswordGenerationPopupControllerImpl
> popup_controller_
;
165 // True if |this| is registered with some LogRouter which can accept logs.
166 bool can_use_log_router_
;
168 // How to handle the sync credential in ShouldFilterAutofillResult().
169 AutofillForSyncCredentialsState autofill_sync_state_
;
171 // If the sync credential was filtered during autofill. Used for statistics
173 bool sync_credential_was_filtered_
;
175 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient
);
178 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_