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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_EXTERNAL_DELEGATE_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_EXTERNAL_DELEGATE_H_
10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string16.h"
14 #include "components/autofill/core/browser/autofill_popup_delegate.h"
15 #include "components/autofill/core/browser/suggestion.h"
16 #include "components/autofill/core/common/form_data.h"
17 #include "components/autofill/core/common/form_field_data.h"
18 #include "ui/gfx/geometry/rect.h"
23 class AutofillManager
;
25 // TODO(csharp): A lot of the logic in this class is copied from autofillagent.
26 // Once Autofill is moved out of WebKit this class should be the only home for
27 // this logic. See http://crbug.com/51644
29 // Delegate for in-browser Autocomplete and Autofill display and selection.
30 class AutofillExternalDelegate
: public AutofillPopupDelegate
{
32 // Creates an AutofillExternalDelegate for the specified AutofillManager and
34 AutofillExternalDelegate(AutofillManager
* manager
,
35 AutofillDriver
* driver
);
36 virtual ~AutofillExternalDelegate();
38 // AutofillPopupDelegate implementation.
39 void OnPopupShown() override
;
40 void OnPopupHidden() override
;
41 void DidSelectSuggestion(const base::string16
& value
,
42 int identifier
) override
;
43 void DidAcceptSuggestion(const base::string16
& value
,
45 int position
) override
;
46 bool GetDeletionConfirmationText(const base::string16
& value
,
48 base::string16
* title
,
49 base::string16
* body
) override
;
50 bool RemoveSuggestion(const base::string16
& value
, int identifier
) override
;
51 void ClearPreviewedForm() override
;
53 // Records and associates a query_id with web form data. Called
54 // when the renderer posts an Autofill query to the browser. |bounds|
55 // is window relative. We might not want to display the warning if a website
56 // has disabled Autocomplete because they have their own popup, and showing
57 // our popup on to of theirs would be a poor user experience.
58 virtual void OnQuery(int query_id
,
60 const FormFieldData
& field
,
61 const gfx::RectF
& element_bounds
);
63 // Records query results and correctly formats them before sending them off
64 // to be displayed. Called when an Autofill query result is available.
65 virtual void OnSuggestionsReturned(
67 const std::vector
<Suggestion
>& suggestions
);
69 // Set the data list value associated with the current field.
70 void SetCurrentDataListValues(
71 const std::vector
<base::string16
>& data_list_values
,
72 const std::vector
<base::string16
>& data_list_labels
);
74 // Inform the delegate that the text field editing has ended. This is
75 // used to help record the metrics of when a new popup is shown.
76 void DidEndTextFieldEditing();
78 // Returns the delegate to its starting state by removing any page specific
79 // values or settings.
82 // The renderer sent an IPC acknowledging an earlier ping IPC.
86 base::WeakPtr
<AutofillExternalDelegate
> GetWeakPtr();
89 FRIEND_TEST_ALL_PREFIXES(AutofillExternalDelegateUnitTest
,
92 // Called when a credit card is scanned using device camera.
93 void OnCreditCardScanned(const base::string16
& card_number
,
97 // Fills the form with the Autofill data corresponding to |unique_id|.
98 // If |is_preview| is true then this is just a preview to show the user what
99 // would be selected and if |is_preview| is false then the user has selected
101 void FillAutofillFormData(int unique_id
, bool is_preview
);
103 // Handle applying any Autofill warnings to the Autofill popup.
104 void ApplyAutofillWarnings(std::vector
<Suggestion
>* suggestions
);
106 // Handle applying any Autofill option listings to the Autofill popup.
107 // This function should only get called when there is at least one
108 // multi-field suggestion in the list of suggestions.
109 void ApplyAutofillOptions(std::vector
<Suggestion
>* suggestions
);
111 // Insert the data list values at the start of the given list, including
112 // any required separators.
113 void InsertDataListValues(std::vector
<Suggestion
>* suggestions
);
115 #if defined(OS_MACOSX) && !defined(OS_IOS)
116 // Pings the renderer.
118 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
120 AutofillManager
* manager_
; // weak.
122 // Provides driver-level context to the shared code of the component. Must
123 // outlive this object.
124 AutofillDriver
* driver_
; // weak
126 // The ID of the last request sent for form field Autofill. Used to ignore
127 // out of date responses.
130 // The current form and field selected by Autofill.
131 FormData query_form_
;
132 FormFieldData query_field_
;
134 // The bounds of the form field that user is interacting with.
135 gfx::RectF element_bounds_
;
137 // Does the popup include any Autofill profile or credit card suggestions?
138 bool has_suggestion_
;
140 // Have we already shown Autofill suggestions for the field the user is
141 // currently editing? Used to keep track of state for metrics logging.
142 bool has_shown_popup_for_current_edit_
;
145 bool should_show_scan_credit_card_
;
147 // Whether the access Address Book prompt has ever been shown for the current
148 // |query_form_|. This variable is only used on OSX.
149 bool has_shown_address_book_prompt
;
151 // The current data list values.
152 std::vector
<base::string16
> data_list_values_
;
153 std::vector
<base::string16
> data_list_labels_
;
155 base::WeakPtrFactory
<AutofillExternalDelegate
> weak_ptr_factory_
;
157 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegate
);
160 } // namespace autofill
162 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_EXTERNAL_DELEGATE_H_