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/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/prefs/pref_member.h"
13 #include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
14 #include "components/password_manager/content/browser/credential_manager_dispatcher.h"
15 #include "components/password_manager/core/browser/password_manager.h"
16 #include "components/password_manager/core/browser/password_manager_client.h"
17 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h"
19 #include "ui/gfx/geometry/rect.h"
24 class PasswordGenerationPopupObserver
;
25 class PasswordGenerationPopupControllerImpl
;
32 namespace password_manager
{
33 struct CredentialInfo
;
34 class PasswordGenerationManager
;
35 class PasswordManagerDriver
;
38 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
39 class ChromePasswordManagerClient
40 : public password_manager::PasswordManagerClient
,
41 public content::WebContentsObserver
,
42 public content::WebContentsUserData
<ChromePasswordManagerClient
> {
44 ~ChromePasswordManagerClient() override
;
46 // PasswordManagerClient implementation.
47 bool IsAutomaticPasswordSavingEnabled() const override
;
48 bool IsPasswordManagementEnabledForCurrentPage() const override
;
49 bool IsSavingEnabledForCurrentPage() const override
;
50 std::string
GetSyncUsername() const override
;
51 bool IsSyncAccountCredential(const std::string
& username
,
52 const std::string
& realm
) const 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
;
85 const GURL
& GetLastCommittedEntryURL() const override
;
86 scoped_ptr
<password_manager::CredentialsFilter
> CreateStoreResultFilter()
89 // Hides any visible generation UI.
90 void HidePasswordGenerationPopup();
92 static void CreateForWebContentsWithAutofillClient(
93 content::WebContents
* contents
,
94 autofill::AutofillClient
* autofill_client
);
96 // Observer for PasswordGenerationPopup events. Used for testing.
97 void SetTestObserver(autofill::PasswordGenerationPopupObserver
* observer
);
99 // Returns true if the bubble UI is enabled, and false if we're still using
100 // the sad old Infobar UI.
101 static bool IsTheHotNewBubbleUIEnabled();
103 // Returns true if the password manager should be enabled during sync signin.
104 static bool EnabledForSyncSignin();
107 // Callable for tests.
108 ChromePasswordManagerClient(content::WebContents
* web_contents
,
109 autofill::AutofillClient
* autofill_client
);
112 friend class content::WebContentsUserData
<ChromePasswordManagerClient
>;
114 // content::WebContentsObserver overrides.
115 bool OnMessageReceived(const IPC::Message
& message
,
116 content::RenderFrameHost
* render_frame_host
) override
;
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(content::RenderFrameHost
* render_frame_host
,
126 const gfx::RectF
& bounds
,
128 const autofill::PasswordForm
& form
);
130 // Causes the password editing UI to be shown anchored at |element_bounds|.
131 void ShowPasswordEditingPopup(content::RenderFrameHost
* render_frame_host
,
132 const gfx::RectF
& bounds
,
133 const autofill::PasswordForm
& form
);
135 // Notify the PasswordManager that generation is available for |form|. Used
137 void GenerationAvailableForForm(const autofill::PasswordForm
& form
);
139 // Sends a message to the renderer with the current value of
140 // |can_use_log_router_|.
141 void NotifyRendererOfLoggingAvailability();
143 // Returns true if |url| is the reauth page for accessing the password
145 bool IsURLPasswordWebsiteReauth(const GURL
& url
) const;
147 Profile
* const profile_
;
149 password_manager::PasswordManager password_manager_
;
151 password_manager::ContentPasswordManagerDriverFactory
* driver_factory_
;
153 password_manager::CredentialManagerDispatcher
154 credential_manager_dispatcher_
;
156 // Observer for password generation popup.
157 autofill::PasswordGenerationPopupObserver
* observer_
;
159 // Controls the popup
161 autofill::PasswordGenerationPopupControllerImpl
> popup_controller_
;
163 // True if |this| is registered with some LogRouter which can accept logs.
164 bool can_use_log_router_
;
166 // Set to false to disable password saving (will no longer ask if you
167 // want to save passwords but will continue to fill passwords).
168 BooleanPrefMember saving_passwords_enabled_
;
170 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient
);
173 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_