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