GetLoginsRequest: Use ScopedVector to express ownership of forms
[chromium-blink-merge.git] / chrome / browser / password_manager / chrome_password_manager_client.h
blob4e19a55178d32baa6dc769cad63c7dcfe788b957
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"
18 class Profile;
20 namespace autofill {
21 class PasswordGenerationPopupObserver;
22 class PasswordGenerationPopupControllerImpl;
25 namespace content {
26 class WebContents;
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> {
40 public:
41 ~ChromePasswordManagerClient() override;
43 // PasswordManagerClient implementation.
44 bool IsAutomaticPasswordSavingEnabled() const override;
45 bool IsPasswordManagerEnabledForCurrentPage() const override;
46 bool ShouldAskUserToSubmitURL(const GURL& url) override;
47 bool ShouldFilterAutofillResult(const autofill::PasswordForm& form) override;
48 std::string GetSyncUsername() const override;
49 bool IsSyncAccountCredential(const std::string& username,
50 const std::string& origin) const override;
51 void AskUserAndMaybeReportURL(const GURL& url) const override;
52 void AutofillResultsComputed() override;
53 bool PromptUserToSavePassword(
54 scoped_ptr<password_manager::PasswordFormManager> form_to_save) override;
55 bool PromptUserToChooseCredentials(
56 ScopedVector<autofill::PasswordForm> local_forms,
57 ScopedVector<autofill::PasswordForm> federated_forms,
58 base::Callback<void(const password_manager::CredentialInfo&)> callback)
59 override;
60 void AutomaticPasswordSave(scoped_ptr<password_manager::PasswordFormManager>
61 saved_form_manager) override;
62 void PasswordWasAutofilled(
63 const autofill::PasswordFormMap& best_matches) const override;
64 void PasswordAutofillWasBlocked(
65 const autofill::PasswordFormMap& best_matches) const override;
66 PrefService* GetPrefs() override;
67 password_manager::PasswordStore* GetPasswordStore() override;
68 base::FieldTrial::Probability GetProbabilityForExperiment(
69 const std::string& experiment_name) override;
70 bool IsPasswordSyncEnabled(
71 password_manager::CustomPassphraseState state) 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() override;
77 bool IsOffTheRecord() override;
78 password_manager::PasswordManager* GetPasswordManager() override;
79 autofill::AutofillManager* GetAutofillManagerForMainFrame() override;
80 const GURL& GetMainFrameURL() 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();
99 protected:
100 // Callable for tests.
101 ChromePasswordManagerClient(content::WebContents* web_contents,
102 autofill::AutofillClient* autofill_client);
104 private:
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,
126 int max_length,
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
139 // Google property.
140 bool LastLoadWasTransactionalReauthPage() const;
142 // Returns true if |url| is the reauth page for accessing the password
143 // website.
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
162 base::WeakPtr<
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
172 // reporting.
173 bool sync_credential_was_filtered_;
175 DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient);
178 #endif // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_