Upstream version 5.34.104.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 "chrome/browser/password_manager/content_password_manager_driver.h"
11 #include "chrome/browser/password_manager/password_manager_client.h"
12 #include "content/public/browser/web_contents_user_data.h"
13
14 class PasswordGenerationManager;
15 class PasswordManager;
16 class Profile;
17
18 namespace content {
19 class WebContents;
20 }
21
22 // ChromePasswordManagerClient implements the PasswordManagerClient interface.
23 class ChromePasswordManagerClient
24     : public PasswordManagerClient,
25       public content::WebContentsUserData<ChromePasswordManagerClient> {
26  public:
27   virtual ~ChromePasswordManagerClient();
28
29   // PasswordManagerClient implementation.
30   virtual void PromptUserToSavePassword(PasswordFormManager* form_to_save)
31       OVERRIDE;
32   virtual void PasswordWasAutofilled(
33       const autofill::PasswordFormMap& best_matches) const OVERRIDE;
34   virtual void AuthenticateAutofillAndFillForm(
35       scoped_ptr<autofill::PasswordFormFillData> fill_data) OVERRIDE;
36   virtual PrefService* GetPrefs() OVERRIDE;
37   virtual PasswordStore* GetPasswordStore() OVERRIDE;
38   virtual PasswordManagerDriver* GetDriver() OVERRIDE;
39   virtual base::FieldTrial::Probability GetProbabilityForExperiment(
40       const std::string& experiment_name) OVERRIDE;
41   virtual bool IsPasswordSyncEnabled() OVERRIDE;
42
43   // Convenience method to allow //chrome code easy access to a PasswordManager
44   // from a WebContents instance.
45   static PasswordManager* GetManagerFromWebContents(
46       content::WebContents* contents);
47
48   // Convenience method to allow //chrome code easy access to a
49   // PasswordGenerationManager from a WebContents instance.
50   static PasswordGenerationManager* GetGenerationManagerFromWebContents(
51       content::WebContents* contents);
52
53  private:
54   explicit ChromePasswordManagerClient(content::WebContents* web_contents);
55   friend class content::WebContentsUserData<ChromePasswordManagerClient>;
56
57   // Callback method to be triggered when authentication is successful for a
58   // given password authentication request.  If authentication is disabled or
59   // not supported, this will be triggered directly.
60   void CommitFillPasswordForm(autofill::PasswordFormFillData* fill_data);
61
62   Profile* GetProfile();
63
64   content::WebContents* web_contents_;
65   ContentPasswordManagerDriver driver_;
66
67   // Allows authentication callbacks to be destroyed when this client is gone.
68   base::WeakPtrFactory<ChromePasswordManagerClient> weak_factory_;
69
70   DISALLOW_COPY_AND_ASSIGN(ChromePasswordManagerClient);
71 };
72
73 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_CHROME_PASSWORD_MANAGER_CLIENT_H_