summaryrefslogtreecommitdiff
path: root/chromium/components/autofill/content/browser/request_autocomplete_manager.h
blob: 093e935bd4f9e073bf25699afb0e0f9168428597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_REQUEST_AUTOCOMPLETE_MANAGER_H_
#define COMPONENTS_AUTOFILL_CONTENT_BROWSER_REQUEST_AUTOCOMPLETE_MANAGER_H_

#include "base/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "third_party/WebKit/public/web/WebFormElement.h"

class GURL;

namespace autofill {

class AutofillDriverImpl;
struct FormData;
class FormStructure;

// Driver for the requestAutocomplete flow.
class RequestAutocompleteManager {
 public:
  explicit RequestAutocompleteManager(AutofillDriverImpl* autofill_driver);
  ~RequestAutocompleteManager();

  // Requests an interactive autocomplete UI to be shown for |frame_url| with
  // |form|.
  void OnRequestAutocomplete(const FormData& form, const GURL& frame_url);

 private:
  // Tells the renderer that the current interactive autocomplete dialog
  // finished with the |result| saying if it was successfull or not, and
  // |form_data| containing the filled form data.
  void ReturnAutocompleteResult(
      blink::WebFormElement::AutocompleteResult result,
      const FormData& form_data);

  // Shows the requestAutocomplete dialog for |source_url| with data from |form|
  // and calls |callback| once the interaction is complete.
  void ShowRequestAutocompleteDialog(
      const FormData& form,
      const GURL& source_url,
      const base::Callback<void(const FormStructure*)>& callback);

  // If |result| is not null, derives a FormData object from it and passes it
  // back to the page along an |AutocompleteResultSuccess| result. Otherwise, it
  // passes to the page an empty FormData along an
  // |AutocompleteResultErrorCancel| result.
  void ReturnAutocompleteData(const FormStructure* result);

  // The autofill driver owns and outlives |this|.
  AutofillDriverImpl* const autofill_driver_;  // weak.

  base::WeakPtrFactory<RequestAutocompleteManager> weak_ptr_factory_;
};

}  // namespace autofill

#endif  // COMPONENTS_AUTOFILL_CONTENT_BROWSER_REQUEST_AUTOCOMPLETE_MANAGER_H_