- add sources.
[platform/framework/web/crosswalk.git] / src / components / autofill / content / browser / autofill_driver_impl.h
1 // Copyright 2013 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 COMPONENTS_AUTOFILL_CONTENT_BROWSER_AUTOFILL_DRIVER_IMPL_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_AUTOFILL_DRIVER_IMPL_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/supports_user_data.h"
12 #include "components/autofill/core/browser/autofill_driver.h"
13 #include "components/autofill/core/browser/autofill_external_delegate.h"
14 #include "components/autofill/core/browser/autofill_manager.h"
15 #include "content/public/browser/web_contents_observer.h"
16
17 namespace content {
18 class WebContents;
19 }
20
21 namespace IPC {
22 class Message;
23 }
24
25 namespace autofill {
26
27 class AutofillContext;
28 class AutofillManagerDelegate;
29
30 // Class that drives autofill flow in the browser process based on
31 // communication from the renderer and from the external world. There is one
32 // instance per WebContents.
33 class AutofillDriverImpl : public AutofillDriver,
34                            public content::WebContentsObserver,
35                            public base::SupportsUserData::Data {
36  public:
37   static void CreateForWebContentsAndDelegate(
38       content::WebContents* contents,
39       autofill::AutofillManagerDelegate* delegate,
40       const std::string& app_locale,
41       AutofillManager::AutofillDownloadManagerState enable_download_manager);
42   static AutofillDriverImpl* FromWebContents(content::WebContents* contents);
43
44   // AutofillDriver:
45   virtual content::WebContents* GetWebContents() OVERRIDE;
46   virtual base::SequencedWorkerPool* GetBlockingPool() OVERRIDE;
47   virtual bool RendererIsAvailable() OVERRIDE;
48   virtual void SetRendererActionOnFormDataReception(
49       RendererFormDataAction action) OVERRIDE;
50   virtual void SendFormDataToRenderer(int query_id,
51                                       const FormData& data) OVERRIDE;
52   virtual void SendAutofillTypePredictionsToRenderer(
53       const std::vector<FormStructure*>& forms) OVERRIDE;
54   virtual void RendererShouldClearFilledForm() OVERRIDE;
55   virtual void RendererShouldClearPreviewedForm() OVERRIDE;
56
57   AutofillExternalDelegate* autofill_external_delegate() {
58     return &autofill_external_delegate_;
59   }
60
61   AutofillManager* autofill_manager() { return autofill_manager_.get(); }
62
63  protected:
64   AutofillDriverImpl(
65       content::WebContents* web_contents,
66       autofill::AutofillManagerDelegate* delegate,
67       const std::string& app_locale,
68       AutofillManager::AutofillDownloadManagerState enable_download_manager);
69   virtual ~AutofillDriverImpl();
70
71   // content::WebContentsObserver:
72   virtual void DidNavigateMainFrame(
73       const content::LoadCommittedDetails& details,
74       const content::FrameNavigateParams& params) OVERRIDE;
75   virtual void NavigationEntryCommitted(
76       const content::LoadCommittedDetails& load_details) OVERRIDE;
77   virtual void WasHidden() OVERRIDE;
78   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
79
80   // Sets the manager to |manager| and sets |manager|'s external delegate
81   // to |autofill_external_delegate_|. Takes ownership of |manager|.
82   void SetAutofillManager(scoped_ptr<AutofillManager> manager);
83
84  private:
85   // AutofillManager instance via which this object drives the shared Autofill
86   // code.
87   scoped_ptr<AutofillManager> autofill_manager_;
88
89   // AutofillExternalDelegate instance that this object instantiates in the
90   // case where the Autofill native UI is enabled.
91   AutofillExternalDelegate autofill_external_delegate_;
92 };
93
94 }  // namespace autofill
95
96 #endif  // COMPONENTS_AUTOFILL_CONTENT_BROWSER_AUTOFILL_DRIVER_IMPL_H_