OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_ |
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/compiler_specific.h" |
11 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "webkit/forms/form_data.h" |
12 #include "webkit/forms/form_field.h" | 14 #include "webkit/forms/form_field.h" |
13 | 15 |
14 class AutofillManager; | 16 class AutofillManager; |
15 class TabContentsWrapper; | 17 class TabContentsWrapper; |
16 | 18 |
17 namespace gfx { | 19 namespace gfx { |
18 class Rect; | 20 class Rect; |
19 } | 21 } |
20 | 22 |
21 namespace webkit { | |
22 namespace forms { | |
23 struct FormData; | |
24 } | |
25 } | |
26 | |
27 // TODO(csharp): A lot of the logic in this class is copied from autofillagent. | 23 // TODO(csharp): A lot of the logic in this class is copied from autofillagent. |
28 // Once Autofill is moved out of WebKit this class should be the only home for | 24 // Once Autofill is moved out of WebKit this class should be the only home for |
29 // this logic. See http://crbug.com/51644 | 25 // this logic. See http://crbug.com/51644 |
30 | 26 |
31 // Delegate for external processing of Autocomplete and Autofill | 27 // Delegate for external processing of Autocomplete and Autofill |
32 // display and selection. | 28 // display and selection. |
33 class AutofillExternalDelegate { | 29 class AutofillExternalDelegate { |
34 public: | 30 public: |
35 virtual ~AutofillExternalDelegate(); | 31 virtual ~AutofillExternalDelegate(); |
36 | 32 |
37 // When using an external Autofill delegate. Allows Chrome to tell | 33 // When using an external Autofill delegate. Allows Chrome to tell |
38 // WebKit which Autofill selection has been chosen. | 34 // WebKit which Autofill selection has been chosen. |
39 // TODO(jrg): add feedback mechanism for hover on relevant platforms. | 35 // TODO(jrg): add feedback mechanism for hover on relevant platforms. |
40 void SelectAutofillSuggestionAtIndex(int listIndex); | 36 void SelectAutofillSuggestionAtIndex(int unique_id, int list_index); |
41 | 37 |
42 // Records and associates a query_id with web form data. Called | 38 // Records and associates a query_id with web form data. Called |
43 // when the renderer posts an Autofill query to the browser. |bounds| | 39 // when the renderer posts an Autofill query to the browser. |bounds| |
44 // is window relative. |display_warning_if_disabled| tells us if we should | 40 // is window relative. |display_warning_if_disabled| tells us if we should |
45 // display warnings (such as autofill is disabled, but had suggestions). | 41 // display warnings (such as autofill is disabled, but had suggestions). |
46 // We might not want to display the warning if a website has disabled | 42 // We might not want to display the warning if a website has disabled |
47 // Autocomplete because they have their own popup, and showing our popup | 43 // Autocomplete because they have their own popup, and showing our popup |
48 // on to of theirs would be a poor user experience. | 44 // on to of theirs would be a poor user experience. |
49 virtual void OnQuery(int query_id, | 45 virtual void OnQuery(int query_id, |
50 const webkit::forms::FormData& form, | 46 const webkit::forms::FormData& form, |
(...skipping 17 matching lines...) Expand all Loading... |
68 // MUST implement this. The 1st arg is the tab contents that owns | 64 // MUST implement this. The 1st arg is the tab contents that owns |
69 // this delegate; the second is the Autofill manager owned by the | 65 // this delegate; the second is the Autofill manager owned by the |
70 // tab contents. | 66 // tab contents. |
71 static AutofillExternalDelegate* Create(TabContentsWrapper*, | 67 static AutofillExternalDelegate* Create(TabContentsWrapper*, |
72 AutofillManager*); | 68 AutofillManager*); |
73 | 69 |
74 // Inform the delegate that the text field editing has ended, this is | 70 // 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. | 71 // used to help record the metrics of when a new popup is shown. |
76 void DidEndTextFieldEditing(); | 72 void DidEndTextFieldEditing(); |
77 | 73 |
| 74 // Inform the delegate that an autofill suggestion have been chosen. |
| 75 void didAcceptAutofillSuggestions( |
| 76 string16 value,int unique_id, unsigned index); |
| 77 |
78 protected: | 78 protected: |
79 explicit AutofillExternalDelegate(TabContentsWrapper* tab_contents_wrapper, | 79 explicit AutofillExternalDelegate(TabContentsWrapper* tab_contents_wrapper, |
80 AutofillManager* autofill_manager); | 80 AutofillManager* autofill_manager); |
81 | 81 |
82 // Displays the the Autofill results to the user with an external | 82 // Displays the the Autofill results to the user with an external |
83 // Autofill popup that lives completely in the browser. The suggestions | 83 // Autofill popup that lives completely in the browser. The suggestions |
84 // have be correctly formatted by this point. | 84 // have be correctly formatted by this point. |
85 virtual void ApplyAutofillSuggestions( | 85 virtual void ApplyAutofillSuggestions( |
86 const std::vector<string16>& autofill_values, | 86 const std::vector<string16>& autofill_values, |
87 const std::vector<string16>& autofill_labels, | 87 const std::vector<string16>& autofill_labels, |
88 const std::vector<string16>& autofill_icons, | 88 const std::vector<string16>& autofill_icons, |
89 const std::vector<int>& autofill_unique_ids, | 89 const std::vector<int>& autofill_unique_ids, |
90 int separator_index) = 0; | 90 int separator_index) = 0; |
91 | 91 |
92 // Handle instance specific OnQueryCode. | 92 // Handle instance specific OnQueryCode. |
93 virtual void OnQueryPlatformSpecific(int query_id, | 93 virtual void OnQueryPlatformSpecific(int query_id, |
94 const webkit::forms::FormData& form, | 94 const webkit::forms::FormData& form, |
95 const webkit::forms::FormField& field, | 95 const webkit::forms::FormField& field, |
96 const gfx::Rect& bounds) = 0; | 96 const gfx::Rect& bounds) = 0; |
97 | 97 |
98 private: | 98 private: |
99 TabContentsWrapper* tab_contents_wrapper_; // weak; owns me. | 99 TabContentsWrapper* tab_contents_wrapper_; // weak; owns me. |
100 AutofillManager* autofill_manager_; // weak. | 100 AutofillManager* autofill_manager_; // weak. |
101 | 101 |
102 // The ID of the last request sent for form field Autofill. Used to ignore | 102 // The ID of the last request sent for form field Autofill. Used to ignore |
103 // out of date responses. | 103 // out of date responses. |
104 int autofill_query_id_; | 104 int autofill_query_id_; |
105 | 105 |
106 // The current field selected by Autofill. | 106 // The current form and field selected by Autofill. |
| 107 webkit::forms::FormData autofill_query_form_; |
107 webkit::forms::FormField autofill_query_field_; | 108 webkit::forms::FormField autofill_query_field_; |
108 | 109 |
109 // Should we display a warning if Autofill is disabled? | 110 // Should we display a warning if Autofill is disabled? |
110 bool display_warning_if_disabled_; | 111 bool display_warning_if_disabled_; |
111 | 112 |
112 // Have we already shown Autofill suggestions for the field the user is | 113 // Have we already shown Autofill suggestions for the field the user is |
113 // currently editing? Used to keep track of state for metrics logging. | 114 // currently editing? Used to keep track of state for metrics logging. |
114 bool has_shown_autofill_popup_for_current_edit_; | 115 bool has_shown_autofill_popup_for_current_edit_; |
115 | 116 |
| 117 // The menu index of the "Clear" menu item. |
| 118 int suggestions_clear_index_; |
| 119 |
| 120 // The menu index of the "Autofill options..." menu item. |
| 121 int suggestions_options_index_; |
| 122 |
116 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegate); | 123 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegate); |
117 }; | 124 }; |
118 | 125 |
119 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_ | 126 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_ |
OLD | NEW |