fb83b535130b4aec38cc303411429b51b80fa47d
[platform/framework/web/crosswalk.git] / src / chrome / browser / password_manager / chrome_password_manager_client.h
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.
4
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "components/password_manager/content/browser/content_password_manager_driver.h"
11 #include "components/password_manager/core/browser/password_manager_client.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h"
14 #include "ui/gfx/rect.h"
15
16 class Profile;
17
18 namespace autofill {
19 class PasswordGenerationPopupObserver;
20 class PasswordGenerationPopupControllerImpl;
21 }
22
23 namespace content {
24 class WebContents;
25 }
26
27 namespace password_manager {
28 struct CredentialInfo;
29 class PasswordGenerationManager;
30 class PasswordManager;
31 }
32
33 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
34 class ChromePasswordManagerClient
35     : public password_manager::PasswordManagerClient,
36       public content::WebContentsObserver,
37       public content::WebContentsUserData<ChromePasswordManagerClient> {
38  public:
39   virtual ~ChromePasswordManagerClient();
40
41   // PasswordManagerClient implementation.
42   virtual bool IsAutomaticPasswordSavingEnabled() const OVERRIDE;
43   virtual bool IsPasswordManagerEnabledForCurrentPage() const OVERRIDE;
44   virtual bool ShouldFilterAutofillResult(
45       const autofill::PasswordForm& form) OVERRIDE;
46   virtual bool IsSyncAccountCredential(
47       const std::string& username, const std::string& origin) const OVERRIDE;
48   virtual void AutofillResultsComputed() OVERRIDE;
49   virtual bool PromptUserToSavePassword(
50       scoped_ptr<password_manager::PasswordFormManager> form_to_save) OVERRIDE;
51   virtual void AutomaticPasswordSave(
52       scoped_ptr<password_manager::PasswordFormManager> saved_form_manager)
53       OVERRIDE;
54   virtual void PasswordWasAutofilled(
55       const autofill::PasswordFormMap& best_matches) const OVERRIDE;
56   virtual void PasswordAutofillWasBlocked(
57       const autofill::PasswordFormMap& best_matches) const OVERRIDE;
58   virtual void AuthenticateAutofillAndFillForm(
59       scoped_ptr<autofill::PasswordFormFillData> fill_data) OVERRIDE;
60   virtual PrefService* GetPrefs() OVERRIDE;
61   virtual password_manager::PasswordStore* GetPasswordStore() OVERRIDE;
62   virtual password_manager::PasswordManagerDriver* GetDriver() OVERRIDE;
63   virtual base::FieldTrial::Probability GetProbabilityForExperiment(
64       const std::string& experiment_name) OVERRIDE;
65   virtual bool IsPasswordSyncEnabled() OVERRIDE;
66   virtual void OnLogRouterAvailabilityChanged(bool router_can_be_used) OVERRIDE;
67   virtual void LogSavePasswordProgress(const std::string& text) OVERRIDE;
68   virtual bool IsLoggingActive() const OVERRIDE;
69   virtual void OnNotifyFailedSignIn(
70       int request_id,
71       const password_manager::CredentialInfo&) OVERRIDE;
72   virtual void OnNotifySignedIn(
73       int request_id,
74       const password_manager::CredentialInfo&) OVERRIDE;
75   virtual void OnNotifySignedOut(int request_id) OVERRIDE;
76   virtual void OnRequestCredential(
77       int request_id,
78       bool zero_click_only,
79       const std::vector<GURL>& federations) OVERRIDE;
80
81   // Hides any visible generation UI.
82   void HidePasswordGenerationPopup();
83
84   static void CreateForWebContentsWithAutofillClient(
85       content::WebContents* contents,
86       autofill::AutofillClient* autofill_client);
87
88   // Convenience method to allow //chrome code easy access to a PasswordManager
89   // from a WebContents instance.
90   static password_manager::PasswordManager* GetManagerFromWebContents(
91       content::WebContents* contents);
92
93   // Convenience method to allow //chrome code easy access to a
94   // PasswordGenerationManager from a WebContents instance.
95   static password_manager::PasswordGenerationManager*
96       GetGenerationManagerFromWebContents(content::WebContents* contents);
97
98   // Observer for PasswordGenerationPopup events. Used for testing.
99   void SetTestObserver(autofill::PasswordGenerationPopupObserver* observer);
100
101   // Returns true if the bubble UI is enabled, and false if we're still using
102   // the sad old Infobar UI.
103   static bool IsTheHotNewBubbleUIEnabled();
104
105   // Returns true if the password manager should be enabled during sync signin.
106   static bool EnabledForSyncSignin();
107
108  protected:
109   // Callable for tests.
110   ChromePasswordManagerClient(content::WebContents* web_contents,
111                               autofill::AutofillClient* autofill_client);
112
113  private:
114   enum AutofillForSyncCredentialsState {
115     ALLOW_SYNC_CREDENTIALS,
116     DISALLOW_SYNC_CREDENTIALS_FOR_REAUTH,
117     DISALLOW_SYNC_CREDENTIALS,
118   };
119
120   friend class content::WebContentsUserData<ChromePasswordManagerClient>;
121
122   // content::WebContentsObserver overrides.
123   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
124
125   // Callback method to be triggered when authentication is successful for a
126   // given password authentication request.  If authentication is disabled or
127   // not supported, this will be triggered directly.
128   void CommitFillPasswordForm(autofill::PasswordFormFillData* fill_data);
129
130   // Given |bounds| in the renderers coordinate system, return the same bounds
131   // in the screens coordinate system.
132   gfx::RectF GetBoundsInScreenSpace(const gfx::RectF& bounds);
133
134   // Causes the password generation UI to be shown for the specified form.
135   // The popup will be anchored at |element_bounds|. The generated password
136   // will be no longer than |max_length|.
137   void ShowPasswordGenerationPopup(const gfx::RectF& bounds,
138                                    int max_length,
139                                    const autofill::PasswordForm& form);
140
141   // Causes the password editing UI to be shown anchored at |element_bounds|.
142   void ShowPasswordEditingPopup(
143       const gfx::RectF& bounds, const autofill::PasswordForm& form);
144
145   // Sends a message to the renderer with the current value of
146   // |can_use_log_router_|.
147   void NotifyRendererOfLoggingAvailability();
148
149   // Returns true if the last loaded page was for transactional re-auth on a
150   // Google property.
151   bool LastLoadWasTransactionalReauthPage() const;
152
153   // Returns true if |url| is the reauth page for accessing the password
154   // website.
155   bool IsURLPasswordWebsiteReauth(const GURL& url) const;
156
157   // Sets |autofill_state_| based on experiment and flag values.
158   void SetUpAutofillSyncState();
159
160   Profile* const profile_;
161
162   password_manager::ContentPasswordManagerDriver driver_;
163
164   // Observer for password generation popup.
165   autofill::PasswordGenerationPopupObserver* observer_;
166
167   // Controls the popup
168   base::WeakPtr<
169     autofill::PasswordGenerationPopupControllerImpl> popup_controller_;
170
171   // True if |this| is registered with some LogRouter which can accept logs.
172   bool can_use_log_router_;
173
174   // How to handle the sync credential in ShouldFilterAutofillResult().
175   AutofillForSyncCredentialsState autofill_sync_state_;
176
177   // If the sync credential was filtered during autofill. Used for statistics
178   // reporting.
179   bool sync_credential_was_filtered_;
180
181   // Allows authentication callbacks to be destroyed when this client is gone.
182   base::WeakPtrFactory<ChromePasswordManagerClient> weak_factory_;
183
184   DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient);
185 };
186
187 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_