Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / autofill / chrome_autofill_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_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_
7
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/i18n/rtl.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/ui/zoom/zoom_observer.h"
13 #include "components/autofill/core/browser/autofill_client.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h"
16
17 namespace content {
18 struct FrameNavigateParams;
19 struct LoadCommittedDetails;
20 class WebContents;
21 }
22
23 namespace autofill {
24
25 class AutofillDialogController;
26 class AutofillKeystoneBridgeWrapper;
27 class AutofillPopupControllerImpl;
28 struct FormData;
29
30 // Chrome implementation of AutofillClient.
31 class ChromeAutofillClient
32     : public AutofillClient,
33       public content::WebContentsUserData<ChromeAutofillClient>,
34       public content::WebContentsObserver,
35       public ZoomObserver {
36  public:
37   virtual ~ChromeAutofillClient();
38
39   // Called when the tab corresponding to |this| instance is activated.
40   void TabActivated();
41
42   // AutofillClient:
43   virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE;
44   virtual scoped_refptr<AutofillWebDataService> GetDatabase() OVERRIDE;
45   virtual PrefService* GetPrefs() OVERRIDE;
46   virtual void HideRequestAutocompleteDialog() OVERRIDE;
47   virtual void ShowAutofillSettings() OVERRIDE;
48   virtual void ConfirmSaveCreditCard(
49       const AutofillMetrics& metric_logger,
50       const base::Closure& save_card_callback) OVERRIDE;
51   virtual void ShowRequestAutocompleteDialog(
52       const FormData& form,
53       const GURL& source_url,
54       const ResultCallback& callback) OVERRIDE;
55   virtual void ShowAutofillPopup(
56       const gfx::RectF& element_bounds,
57       base::i18n::TextDirection text_direction,
58       const std::vector<base::string16>& values,
59       const std::vector<base::string16>& labels,
60       const std::vector<base::string16>& icons,
61       const std::vector<int>& identifiers,
62       base::WeakPtr<AutofillPopupDelegate> delegate) OVERRIDE;
63   virtual void UpdateAutofillPopupDataListValues(
64       const std::vector<base::string16>& values,
65       const std::vector<base::string16>& labels) OVERRIDE;
66   virtual void HideAutofillPopup() OVERRIDE;
67   virtual bool IsAutocompleteEnabled() OVERRIDE;
68   virtual void DetectAccountCreationForms(
69       const std::vector<autofill::FormStructure*>& forms) OVERRIDE;
70   virtual void DidFillOrPreviewField(
71       const base::string16& autofilled_value,
72       const base::string16& profile_full_name) OVERRIDE;
73
74   // content::WebContentsObserver implementation.
75   virtual void WebContentsDestroyed() OVERRIDE;
76
77   // ZoomObserver implementation.
78   virtual void OnZoomChanged(
79       const ZoomController::ZoomChangedEventData& data) OVERRIDE;
80
81   // Exposed for testing.
82   AutofillDialogController* GetDialogControllerForTesting() {
83     return dialog_controller_.get();
84   }
85   void SetDialogControllerForTesting(
86       const base::WeakPtr<AutofillDialogController>& dialog_controller) {
87     dialog_controller_ = dialog_controller;
88   }
89
90  private:
91 #if defined(OS_MACOSX) && !defined(OS_IOS)
92   // Creates |bridge_wrapper_|, which is responsible for dealing with Keystone
93   // notifications.
94   void RegisterForKeystoneNotifications();
95
96   // Deletes |bridge_wrapper_|.
97   void UnregisterFromKeystoneNotifications();
98 #endif  // defined(OS_MACOSX) && !defined(OS_IOS)
99
100   explicit ChromeAutofillClient(content::WebContents* web_contents);
101   friend class content::WebContentsUserData<ChromeAutofillClient>;
102
103   content::WebContents* const web_contents_;
104   base::WeakPtr<AutofillDialogController> dialog_controller_;
105   base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
106
107 #if defined(OS_MACOSX) && !defined(OS_IOS)
108   // Listens to Keystone notifications and passes relevant ones on to the
109   // PersonalDataManager.
110   //
111   // The class of this member must remain a forward declaration, even in the
112   // .cc implementation file, since the class is defined in a Mac-only
113   // implementation file. This means that the pointer cannot be wrapped in a
114   // scoped_ptr.
115   AutofillKeystoneBridgeWrapper* bridge_wrapper_;
116 #endif  // defined(OS_MACOSX) && !defined(OS_IOS)
117
118   DISALLOW_COPY_AND_ASSIGN(ChromeAutofillClient);
119 };
120
121 }  // namespace autofill
122
123 #endif  // CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_