Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / password_manager / chrome_password_manager_client.h
blob04b13400e5becf29a96da785fb769d6d2f3d53de
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"
19 class Profile;
21 namespace autofill {
22 class PasswordGenerationPopupObserver;
23 class PasswordGenerationPopupControllerImpl;
26 namespace content {
27 class WebContents;
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> {
41 public:
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 PromptUserToSavePassword(
54 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
55 password_manager::CredentialSourceType type) override;
56 bool PromptUserToChooseCredentials(
57 ScopedVector<autofill::PasswordForm> local_forms,
58 ScopedVector<autofill::PasswordForm> federated_forms,
59 const GURL& origin,
60 base::Callback<void(const password_manager::CredentialInfo&)> callback)
61 override;
62 void ForceSavePassword() override;
63 void NotifyUserAutoSignin(
64 ScopedVector<autofill::PasswordForm> local_forms) override;
65 void AutomaticPasswordSave(scoped_ptr<password_manager::PasswordFormManager>
66 saved_form_manager) override;
67 void PasswordWasAutofilled(
68 const autofill::PasswordFormMap& best_matches) const override;
69 void PasswordAutofillWasBlocked(
70 const autofill::PasswordFormMap& best_matches) const override;
71 PrefService* GetPrefs() override;
72 password_manager::PasswordStore* GetPasswordStore() const override;
73 password_manager::PasswordSyncState GetPasswordSyncState() const override;
74 void OnLogRouterAvailabilityChanged(bool router_can_be_used) override;
75 void LogSavePasswordProgress(const std::string& text) const override;
76 bool IsLoggingActive() const override;
77 bool WasLastNavigationHTTPError() const override;
78 bool DidLastPageLoadEncounterSSLErrors() const override;
79 bool IsOffTheRecord() const override;
80 password_manager::PasswordManager* GetPasswordManager() override;
81 autofill::AutofillManager* GetAutofillManagerForMainFrame() override;
82 const GURL& GetMainFrameURL() const override;
84 // Hides any visible generation UI.
85 void HidePasswordGenerationPopup();
87 static void CreateForWebContentsWithAutofillClient(
88 content::WebContents* contents,
89 autofill::AutofillClient* autofill_client);
91 // Observer for PasswordGenerationPopup events. Used for testing.
92 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer);
94 // Returns true if the bubble UI is enabled, and false if we're still using
95 // the sad old Infobar UI.
96 static bool IsTheHotNewBubbleUIEnabled();
98 // Returns true if the password manager should be enabled during sync signin.
99 static bool EnabledForSyncSignin();
101 protected:
102 // Callable for tests.
103 ChromePasswordManagerClient(content::WebContents* web_contents,
104 autofill::AutofillClient* autofill_client);
106 private:
107 enum AutofillForSyncCredentialsState {
108 ALLOW_SYNC_CREDENTIALS,
109 DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH,
110 DISALLOW_SYNC_CREDENTIALS,
113 friend class content::WebContentsUserData<ChromePasswordManagerClient>;
115 // content::WebContentsObserver overrides.
116 bool OnMessageReceived(const IPC::Message& message,
117 content::RenderFrameHost* render_frame_host) override;
119 // Given |bounds| in the renderers coordinate system, return the same bounds
120 // in the screens coordinate system.
121 gfx::RectF GetBoundsInScreenSpace(const gfx::RectF& bounds);
123 // Causes the password generation UI to be shown for the specified form.
124 // The popup will be anchored at |element_bounds|. The generated password
125 // will be no longer than |max_length|.
126 void ShowPasswordGenerationPopup(content::RenderFrameHost* render_frame_host,
127 const gfx::RectF& bounds,
128 int max_length,
129 const autofill::PasswordForm& form);
131 // Causes the password editing UI to be shown anchored at |element_bounds|.
132 void ShowPasswordEditingPopup(content::RenderFrameHost* render_frame_host,
133 const gfx::RectF& bounds,
134 const autofill::PasswordForm& form);
136 // Sends a message to the renderer with the current value of
137 // |can_use_log_router_|.
138 void NotifyRendererOfLoggingAvailability();
140 // Returns true if the last loaded page was for transactional re-auth on a
141 // Google property.
142 bool LastLoadWasTransactionalReauthPage() const;
144 // Returns true if |url| is the reauth page for accessing the password
145 // website.
146 bool IsURLPasswordWebsiteReauth(const GURL& url) const;
148 // Sets |autofill_state_| based on experiment and flag values.
149 void SetUpAutofillSyncState();
151 Profile* const profile_;
153 password_manager::PasswordManager password_manager_;
155 password_manager::ContentPasswordManagerDriverFactory* driver_factory_;
157 password_manager::CredentialManagerDispatcher
158 credential_manager_dispatcher_;
160 // Observer for password generation popup.
161 autofill::PasswordGenerationPopupObserver* observer_;
163 // Controls the popup
164 base::WeakPtr<
165 autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
167 // True if |this| is registered with some LogRouter which can accept logs.
168 bool can_use_log_router_;
170 // How to handle the sync credential in ShouldFilterAutofillResult().
171 AutofillForSyncCredentialsState autofill_sync_state_;
173 // If the sync credential was filtered during autofill. Used for statistics
174 // reporting.
175 bool sync_credential_was_filtered_;
177 // Set to false to disable password saving (will no longer ask if you
178 // want to save passwords but will continue to fill passwords).
179 BooleanPrefMember saving_passwords_enabled_;
181 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient);
184 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_