Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / password_manager / chrome_password_manager_client.h
blob57631903801f60d7d78f7c978f2f5e1dc0c76781
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 "components/password_manager/sync/browser/sync_store_result_filter.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/browser/web_contents_user_data.h"
20 #include "ui/gfx/geometry/rect.h"
22 class Profile;
24 namespace autofill {
25 class PasswordGenerationPopupObserver;
26 class PasswordGenerationPopupControllerImpl;
29 namespace content {
30 class WebContents;
33 namespace password_manager {
34 struct CredentialInfo;
35 class PasswordGenerationManager;
36 class PasswordManagerDriver;
39 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
40 class ChromePasswordManagerClient
41 : public password_manager::PasswordManagerClient,
42 public content::WebContentsObserver,
43 public content::WebContentsUserData<ChromePasswordManagerClient> {
44 public:
45 ~ChromePasswordManagerClient() override;
47 // PasswordManagerClient implementation.
48 bool IsAutomaticPasswordSavingEnabled() const override;
49 bool IsPasswordManagementEnabledForCurrentPage() const override;
50 bool IsSavingEnabledForCurrentPage() const override;
51 bool PromptUserToSaveOrUpdatePassword(
52 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
53 password_manager::CredentialSourceType type,
54 bool update_password) override;
55 bool PromptUserToChooseCredentials(
56 ScopedVector<autofill::PasswordForm> local_forms,
57 ScopedVector<autofill::PasswordForm> federated_forms,
58 const GURL& origin,
59 base::Callback<void(const password_manager::CredentialInfo&)> callback)
60 override;
61 void ForceSavePassword() override;
62 void NotifyUserAutoSignin(
63 ScopedVector<autofill::PasswordForm> local_forms) override;
64 void AutomaticPasswordSave(scoped_ptr<password_manager::PasswordFormManager>
65 saved_form_manager) override;
66 void PasswordWasAutofilled(
67 const autofill::PasswordFormMap& best_matches) const override;
68 void PasswordAutofillWasBlocked(
69 const autofill::PasswordFormMap& best_matches) const override;
70 PrefService* GetPrefs() override;
71 password_manager::PasswordStore* GetPasswordStore() const override;
72 password_manager::PasswordSyncState GetPasswordSyncState() const override;
73 void OnLogRouterAvailabilityChanged(bool router_can_be_used) override;
74 void LogSavePasswordProgress(const std::string& text) const override;
75 bool IsLoggingActive() const override;
76 bool WasLastNavigationHTTPError() const override;
77 bool DidLastPageLoadEncounterSSLErrors() const override;
78 bool IsOffTheRecord() const override;
79 password_manager::PasswordManager* GetPasswordManager() override;
80 autofill::AutofillManager* GetAutofillManagerForMainFrame() override;
81 const GURL& GetMainFrameURL() const override;
82 bool IsUpdatePasswordUIEnabled() const override;
83 const GURL& GetLastCommittedEntryURL() const override;
84 const password_manager::CredentialsFilter* GetStoreResultFilter()
85 const override;
87 // Hides any visible generation UI.
88 void HidePasswordGenerationPopup();
90 static void CreateForWebContentsWithAutofillClient(
91 content::WebContents* contents,
92 autofill::AutofillClient* autofill_client);
94 // Observer for PasswordGenerationPopup events. Used for testing.
95 void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer);
97 // Returns true if the bubble UI is enabled, and false if we're still using
98 // the sad old Infobar UI.
99 static bool IsTheHotNewBubbleUIEnabled();
101 // Returns true if the password manager should be enabled during sync signin.
102 static bool EnabledForSyncSignin();
104 protected:
105 // Callable for tests.
106 ChromePasswordManagerClient(content::WebContents* web_contents,
107 autofill::AutofillClient* autofill_client);
109 private:
110 friend class content::WebContentsUserData<ChromePasswordManagerClient>;
112 // content::WebContentsObserver overrides.
113 bool OnMessageReceived(const IPC::Message& message,
114 content::RenderFrameHost* render_frame_host) override;
116 // Given |bounds| in the renderers coordinate system, return the same bounds
117 // in the screens coordinate system.
118 gfx::RectF GetBoundsInScreenSpace(const gfx::RectF& bounds);
120 // Causes the password generation UI to be shown for the specified form.
121 // The popup will be anchored at |element_bounds|. The generated password
122 // will be no longer than |max_length|.
123 void ShowPasswordGenerationPopup(content::RenderFrameHost* render_frame_host,
124 const gfx::RectF& bounds,
125 int max_length,
126 const autofill::PasswordForm& form);
128 // Causes the password editing UI to be shown anchored at |element_bounds|.
129 void ShowPasswordEditingPopup(content::RenderFrameHost* render_frame_host,
130 const gfx::RectF& bounds,
131 const autofill::PasswordForm& form);
133 // Notify the PasswordManager that generation is available for |form|. Used
134 // for UMA stats.
135 void GenerationAvailableForForm(const autofill::PasswordForm& form);
137 // Sends a message to the renderer with the current value of
138 // |can_use_log_router_|.
139 void NotifyRendererOfLoggingAvailability();
141 // Returns true if |url| is the reauth page for accessing the password
142 // website.
143 bool IsURLPasswordWebsiteReauth(const GURL& url) const;
145 Profile* const profile_;
147 password_manager::PasswordManager password_manager_;
149 password_manager::ContentPasswordManagerDriverFactory* driver_factory_;
151 password_manager::CredentialManagerDispatcher
152 credential_manager_dispatcher_;
154 // Observer for password generation popup.
155 autofill::PasswordGenerationPopupObserver* observer_;
157 // Controls the popup
158 base::WeakPtr<
159 autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
161 // True if |this| is registered with some LogRouter which can accept logs.
162 bool can_use_log_router_;
164 // Set to false to disable password saving (will no longer ask if you
165 // want to save passwords but will continue to fill passwords).
166 BooleanPrefMember saving_passwords_enabled_;
168 const password_manager::SyncStoreResultFilter credentials_filter_;
170 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient);
173 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_