autofill_driver.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
1dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner// Copyright 2013 The Chromium Authors. All rights reserved.
2dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner// Use of this source code is governed by a BSD-style license that can be
3dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner// found in the LICENSE file.
4dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
5dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DRIVER_H_
6dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DRIVER_H_
7dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
8dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner#include <vector>
9dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
10dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner#include "components/autofill/core/common/form_data.h"
11dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
12dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattnernamespace base {
13dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattnerclass SequencedWorkerPool;
14dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner}
15dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
16dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattnernamespace net {
17dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattnerclass URLRequestContextGetter;
18dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner}
19dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
20dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattnernamespace autofill {
21dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
22dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattnerclass FormStructure;
23dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
24dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner// Interface that allows Autofill core code to interact with its driver (i.e.,
25dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner// obtain information from it and give information to it). A concrete
26dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner// implementation must be provided by the driver.
27dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattnerclass AutofillDriver {
28dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner public:
29dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner   // The possible actions that the renderer can take on receiving form data.
30dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  enum RendererFormDataAction {
31dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner    // The renderer should fill the form data.
32dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner    FORM_DATA_ACTION_FILL,
33dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner    // The renderer should preview the form data.
34dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner    FORM_DATA_ACTION_PREVIEW
35dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  };
36dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
37dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  virtual ~AutofillDriver() {}
38dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
39dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // Returns whether the user is currently operating in an off-the-record
40dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // (i.e., incognito) context.
41dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  virtual bool IsOffTheRecord() const = 0;
42dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
43dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // Returns the URL request context information associated with this driver.
44dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  virtual net::URLRequestContextGetter* GetURLRequestContext() = 0;
45dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
46dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // Returns the SequencedWorkerPool on which core Autofill code should run
47dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // tasks that may block. This pool must live at least as long as the driver.
48dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  virtual base::SequencedWorkerPool* GetBlockingPool() = 0;
49dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
50dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // Returns true iff the renderer is available for communication.
51dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  virtual bool RendererIsAvailable() = 0;
52703f5291c4f7199a95274df5e3381b36f8faf38cChris Lattner
53703f5291c4f7199a95274df5e3381b36f8faf38cChris Lattner  // Forwards |data| to the renderer. |query_id| is the id of the renderer's
54703f5291c4f7199a95274df5e3381b36f8faf38cChris Lattner  // original request for the data. |action| is the action the renderer should
55703f5291c4f7199a95274df5e3381b36f8faf38cChris Lattner  // perform with the |data|. This method is a no-op if the renderer is not
56703f5291c4f7199a95274df5e3381b36f8faf38cChris Lattner  // currently available.
57dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  virtual void SendFormDataToRenderer(int query_id,
58dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner                                      RendererFormDataAction action,
59dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner                                      const FormData& data) = 0;
60dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner
61dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // Sends the field type predictions specified in |forms| to the renderer. This
62dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0Chris Lattner  // method is a no-op if the renderer is not available or the appropriate
63  // command-line flag is not set.
64  virtual void SendAutofillTypePredictionsToRenderer(
65      const std::vector<FormStructure*>& forms) = 0;
66
67  // Tells the renderer to accept data list suggestions for |value|.
68  virtual void RendererShouldAcceptDataListSuggestion(
69      const base::string16& value) = 0;
70
71  // Tells the renderer to clear the currently filled Autofill results.
72  virtual void RendererShouldClearFilledForm() = 0;
73
74  // Tells the renderer to clear the currently previewed Autofill results.
75  virtual void RendererShouldClearPreviewedForm() = 0;
76
77  // Tells the renderer to set the node text.
78  virtual void RendererShouldFillFieldWithValue(
79      const base::string16& value) = 0;
80
81  // Tells the renderer to preview the node with suggested text.
82  virtual void RendererShouldPreviewFieldWithValue(
83      const base::string16& value) = 0;
84
85};
86
87}  // namespace autofill
88
89#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_DRIVER_H_
90