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