Update To 11.40.268.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   ~ChromeAutofillClient() override;
38
39   // Called when the tab corresponding to |this| instance is activated.
40   void TabActivated();
41
42   // AutofillClient:
43   PersonalDataManager* GetPersonalDataManager() override;
44   scoped_refptr<AutofillWebDataService> GetDatabase() override;
45   PrefService* GetPrefs() override;
46   void HideRequestAutocompleteDialog() override;
47   void ShowAutofillSettings() override;
48   void ConfirmSaveCreditCard(const AutofillMetrics& metric_logger,
49                              const base::Closure& save_card_callback) override;
50   void ShowRequestAutocompleteDialog(const FormData& form,
51                                      const GURL& source_url,
52                                      const ResultCallback& callback) override;
53   void ShowAutofillPopup(
54       const gfx::RectF& element_bounds,
55       base::i18n::TextDirection text_direction,
56       const std::vector<base::string16>& values,
57       const std::vector<base::string16>& labels,
58       const std::vector<base::string16>& icons,
59       const std::vector<int>& identifiers,
60       base::WeakPtr<AutofillPopupDelegate> delegate) override;
61   void UpdateAutofillPopupDataListValues(
62       const std::vector<base::string16>& values,
63       const std::vector<base::string16>& labels) override;
64   void HideAutofillPopup() override;
65   bool IsAutocompleteEnabled() override;
66   void DetectAccountCreationForms(
67       const std::vector<autofill::FormStructure*>& forms) override;
68   void DidFillOrPreviewField(const base::string16& autofilled_value,
69                              const base::string16& profile_full_name) override;
70
71   // content::WebContentsObserver implementation.
72   void WebContentsDestroyed() override;
73
74   // ZoomObserver implementation.
75   void OnZoomChanged(const ZoomController::ZoomChangedEventData& data) override;
76
77   // Exposed for testing.
78   AutofillDialogController* GetDialogControllerForTesting() {
79     return dialog_controller_.get();
80   }
81   void SetDialogControllerForTesting(
82       const base::WeakPtr<AutofillDialogController>& dialog_controller) {
83     dialog_controller_ = dialog_controller;
84   }
85
86  private:
87 #if defined(OS_MACOSX) && !defined(OS_IOS)
88   // Creates |bridge_wrapper_|, which is responsible for dealing with Keystone
89   // notifications.
90   void RegisterForKeystoneNotifications();
91
92   // Deletes |bridge_wrapper_|.
93   void UnregisterFromKeystoneNotifications();
94 #endif  // defined(OS_MACOSX) && !defined(OS_IOS)
95
96   explicit ChromeAutofillClient(content::WebContents* web_contents);
97   friend class content::WebContentsUserData<ChromeAutofillClient>;
98
99   content::WebContents* const web_contents_;
100   base::WeakPtr<AutofillDialogController> dialog_controller_;
101   base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
102
103 #if defined(OS_MACOSX) && !defined(OS_IOS)
104   // Listens to Keystone notifications and passes relevant ones on to the
105   // PersonalDataManager.
106   //
107   // The class of this member must remain a forward declaration, even in the
108   // .cc implementation file, since the class is defined in a Mac-only
109   // implementation file. This means that the pointer cannot be wrapped in a
110   // scoped_ptr.
111   AutofillKeystoneBridgeWrapper* bridge_wrapper_;
112 #endif  // defined(OS_MACOSX) && !defined(OS_IOS)
113
114   DISALLOW_COPY_AND_ASSIGN(ChromeAutofillClient);
115 };
116
117 }  // namespace autofill
118
119 #endif  // CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_