Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 10073018: Add Delete Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autocomplete_history_manager.h"
6 #include "chrome/browser/autofill/autofill_external_delegate.h" 7 #include "chrome/browser/autofill/autofill_external_delegate.h"
7 #include "chrome/browser/autofill/autofill_manager.h" 8 #include "chrome/browser/autofill/autofill_manager.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
9 #include "chrome/common/autofill_messages.h" 10 #include "chrome/common/autofill_messages.h"
10 #include "chrome/common/chrome_constants.h" 11 #include "chrome/common/chrome_constants.h"
11 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "grit/chromium_strings.h" 14 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 18
18 using content::RenderViewHost; 19 using content::RenderViewHost;
19 using WebKit::WebAutofillClient; 20 using WebKit::WebAutofillClient;
20 21
21 AutofillExternalDelegate::~AutofillExternalDelegate() { 22 AutofillExternalDelegate::~AutofillExternalDelegate() {
22 } 23 }
23 24
24 AutofillExternalDelegate::AutofillExternalDelegate( 25 AutofillExternalDelegate::AutofillExternalDelegate(
25 TabContentsWrapper* tab_contents_wrapper, 26 TabContentsWrapper* tab_contents_wrapper,
26 AutofillManager* autofill_manager) 27 AutofillManager* autofill_manager)
27 : tab_contents_wrapper_(tab_contents_wrapper), 28 : tab_contents_wrapper_(tab_contents_wrapper),
28 autofill_manager_(autofill_manager), 29 autofill_manager_(autofill_manager),
29 password_autofill_manager_( 30 password_autofill_manager_(
30 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), 31 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL),
31 autofill_query_id_(0), 32 autofill_query_id_(0),
32 display_warning_if_disabled_(false), 33 display_warning_if_disabled_(false),
33 has_shown_autofill_popup_for_current_edit_(false), 34 has_shown_autofill_popup_for_current_edit_(false) {
34 suggestions_clear_index_(-1),
35 suggestions_options_index_(-1) {
36 } 35 }
37 36
38 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, 37 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
39 int list_index) { 38 int list_index) {
Ilya Sherman 2012/04/19 21:01:57 nit: It looks like |list_index| is no longer used.
csharp 2012/04/20 15:03:18 Done.
40 if (password_autofill_manager_.DidSelectAutofillSuggestion( 39 if (password_autofill_manager_.DidSelectAutofillSuggestion(
41 autofill_query_field_)) 40 autofill_query_field_))
42 return; 41 return;
43 42
44 if (list_index == suggestions_options_index_ || 43 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions ||
45 list_index == suggestions_clear_index_ || 44 unique_id == WebAutofillClient::MenuItemIDClearForm ||
46 unique_id == WebAutofillClient::MenuItemIDWarningMessage) 45 unique_id == WebAutofillClient::MenuItemIDWarningMessage)
47 return; 46 return;
48 47
49 FillAutofillFormData(unique_id, true); 48 FillAutofillFormData(unique_id, true);
50 } 49 }
51 50
52 void AutofillExternalDelegate::OnQuery(int query_id, 51 void AutofillExternalDelegate::OnQuery(int query_id,
53 const webkit::forms::FormData& form, 52 const webkit::forms::FormData& form,
54 const webkit::forms::FormField& field, 53 const webkit::forms::FormField& field,
55 const gfx::Rect& bounds, 54 const gfx::Rect& bounds,
(...skipping 18 matching lines...) Expand all
74 if (values.empty()) { 73 if (values.empty()) {
75 // No suggestions, any popup currently showing is obsolete. 74 // No suggestions, any popup currently showing is obsolete.
76 HideAutofillPopup(); 75 HideAutofillPopup();
77 return; 76 return;
78 } 77 }
79 78
80 std::vector<string16> v(values); 79 std::vector<string16> v(values);
81 std::vector<string16> l(labels); 80 std::vector<string16> l(labels);
82 std::vector<string16> i(icons); 81 std::vector<string16> i(icons);
83 std::vector<int> ids(unique_ids); 82 std::vector<int> ids(unique_ids);
84 int separator_index = -1;
85 83
86 DCHECK_GT(ids.size(), 0U); 84 DCHECK_GT(ids.size(), 0U);
87 if (!autofill_query_field_.should_autocomplete) { 85 if (!autofill_query_field_.should_autocomplete) {
88 // If autofill is disabled and we had suggestions, show a warning instead. 86 // If autofill is disabled and we had suggestions, show a warning instead.
89 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); 87 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
90 l.assign(1, string16()); 88 l.assign(1, string16());
91 i.assign(1, string16()); 89 i.assign(1, string16());
92 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage); 90 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage);
93 } else if (ids[0] < 0 && ids.size() > 1) { 91 } else if (ids[0] < 0 && ids.size() > 1) {
94 // If we received a warning instead of suggestions from autofill but regular 92 // If we received a warning instead of suggestions from autofill but regular
(...skipping 11 matching lines...) Expand all
106 // Only include "Autofill Options" special menu item if we have Autofill 104 // Only include "Autofill Options" special menu item if we have Autofill
107 // items, identified by |unique_ids| having at least one valid value. 105 // items, identified by |unique_ids| having at least one valid value.
108 bool has_autofill_item = false; 106 bool has_autofill_item = false;
109 for (size_t i = 0; i < ids.size(); ++i) { 107 for (size_t i = 0; i < ids.size(); ++i) {
110 if (ids[i] > 0) { 108 if (ids[i] > 0) {
111 has_autofill_item = true; 109 has_autofill_item = true;
112 break; 110 break;
113 } 111 }
114 } 112 }
115 113
114 int separator_index = ids.size();
Ilya Sherman 2012/04/19 21:01:57 Do we still need to keep track of the separator_in
csharp 2012/04/20 15:03:18 See other comment for reason to keep this.
115
116 // The form has been auto-filled, so give the user the chance to clear the 116 // The form has been auto-filled, so give the user the chance to clear the
117 // form. Append the 'Clear form' menu item. 117 // form. Append the 'Clear form' menu item.
118 if (has_autofill_item && 118 if (has_autofill_item && autofill_query_field_.is_autofilled) {
119 autofill_query_field_.is_autofilled) {
120 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); 119 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
121 l.push_back(string16()); 120 l.push_back(string16());
122 i.push_back(string16()); 121 i.push_back(string16());
123 ids.push_back(0); 122 ids.push_back(WebAutofillClient::MenuItemIDClearForm);
124 suggestions_clear_index_ = v.size() - 1;
125 separator_index = v.size() - 1;
126 } 123 }
127 124
128 if (has_autofill_item) { 125 if (has_autofill_item) {
129 // Append the 'Chrome Autofill options' menu item; 126 // Append the 'Chrome Autofill options' menu item;
130 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); 127 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP));
131 l.push_back(string16()); 128 l.push_back(string16());
132 i.push_back(string16()); 129 i.push_back(string16());
133 ids.push_back(0); 130 ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions);
134 suggestions_options_index_ = v.size() - 1;
135 separator_index = values.size();
136 } 131 }
137 132
138 // Send to display. 133 // Send to display.
139 if (!v.empty() && autofill_query_field_.is_focusable) 134 if (!v.empty() && autofill_query_field_.is_focusable)
140 ApplyAutofillSuggestions(v, l, i, ids, separator_index); 135 ApplyAutofillSuggestions(v, l, i, ids, separator_index);
141 136
142 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( 137 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions(
143 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); 138 has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
144 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; 139 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
145 } 140 }
(...skipping 10 matching lines...) Expand all
156 } 151 }
157 152
158 SetBounds(bounds); 153 SetBounds(bounds);
159 154
160 std::vector<string16> empty(suggestions.size()); 155 std::vector<string16> empty(suggestions.size());
161 std::vector<int> password_ids(suggestions.size(), 156 std::vector<int> password_ids(suggestions.size(),
162 WebAutofillClient::MenuItemIDPasswordEntry); 157 WebAutofillClient::MenuItemIDPasswordEntry);
163 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); 158 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1);
164 } 159 }
165 160
161 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) {
162 if (tab_contents_wrapper_) {
163 tab_contents_wrapper_->autocomplete_history_manager()->
164 OnRemoveAutocompleteEntry(autofill_query_field_.name, value);
165 }
166 }
167
168 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard(
169 int unique_id) {
170 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id);
171 }
172
173
166 void AutofillExternalDelegate::DidEndTextFieldEditing() { 174 void AutofillExternalDelegate::DidEndTextFieldEditing() {
167 has_shown_autofill_popup_for_current_edit_ = false; 175 has_shown_autofill_popup_for_current_edit_ = false;
168 } 176 }
169 177
170 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( 178 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
171 const string16& value, 179 const string16& value,
172 int unique_id, 180 int unique_id,
173 unsigned index) { 181 unsigned index) {
174 // If the selected element is a warning we don't want to do anything. 182 // If the selected element is a warning we don't want to do anything.
175 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage) 183 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
176 return false; 184 return false;
177 185
178 if (suggestions_options_index_ != -1 && 186 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) {
179 index == static_cast<unsigned>(suggestions_options_index_)) {
180 // User selected 'Autofill Options'. 187 // User selected 'Autofill Options'.
181 autofill_manager_->OnShowAutofillDialog(); 188 autofill_manager_->OnShowAutofillDialog();
182 } else if (suggestions_clear_index_ != -1 && 189 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) {
183 index == static_cast<unsigned>(suggestions_clear_index_)) {
184 // User selected 'Clear form'. 190 // User selected 'Clear form'.
185 RenderViewHost* host = 191 RenderViewHost* host =
186 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 192 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
187 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); 193 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
188 } else if (password_autofill_manager_.DidAcceptAutofillSuggestion( 194 } else if (password_autofill_manager_.DidAcceptAutofillSuggestion(
189 autofill_query_field_, value)) { 195 autofill_query_field_, value)) {
190 // DidAcceptAutofillSuggestion has already handled the work to fill in 196 // DidAcceptAutofillSuggestion has already handled the work to fill in
191 // the page as required. 197 // the page as required.
192 } else if (!unique_id) { 198 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) {
193 // User selected an Autocomplete, so we fill directly. 199 // User selected an Autocomplete, so we fill directly.
194 RenderViewHost* host = 200 RenderViewHost* host =
195 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 201 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
196 host->Send(new AutofillMsg_SetNodeText( 202 host->Send(new AutofillMsg_SetNodeText(
197 host->GetRoutingID(), 203 host->GetRoutingID(),
198 value)); 204 value));
199 } else { 205 } else {
200 FillAutofillFormData(unique_id, false); 206 FillAutofillFormData(unique_id, false);
201 } 207 }
202 208
203 HideAutofillPopup(); 209 HideAutofillPopup();
204 210
205 return true; 211 return true;
206 } 212 }
207 213
208 void AutofillExternalDelegate::ClearPreviewedForm() { 214 void AutofillExternalDelegate::ClearPreviewedForm() {
209 if (password_autofill_manager_.DidClearAutofillSelection( 215 if (password_autofill_manager_.DidClearAutofillSelection(
210 autofill_query_field_)) 216 autofill_query_field_))
211 return; 217 return;
212 218
213 RenderViewHost* host = 219 RenderViewHost* host =
214 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 220 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
215 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); 221 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
216 } 222 }
217 223
218 void AutofillExternalDelegate::HideAutofillPopup() { 224 void AutofillExternalDelegate::HideAutofillPopup() {
219 suggestions_clear_index_ = -1;
220 suggestions_options_index_ = -1;
221
222 HideAutofillPopupInternal(); 225 HideAutofillPopupInternal();
223 } 226 }
224 227
225 void AutofillExternalDelegate::Reset() { 228 void AutofillExternalDelegate::Reset() {
226 HideAutofillPopup(); 229 HideAutofillPopup();
227 230
228 password_autofill_manager_.Reset(); 231 password_autofill_manager_.Reset();
229 } 232 }
230 233
231 void AutofillExternalDelegate::AddPasswordFormMapping( 234 void AutofillExternalDelegate::AddPasswordFormMapping(
(...skipping 27 matching lines...) Expand all
259 // none, so all platforms use the default. 262 // none, so all platforms use the default.
260 263
261 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 264 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
262 265
263 AutofillExternalDelegate* AutofillExternalDelegate::Create( 266 AutofillExternalDelegate* AutofillExternalDelegate::Create(
264 TabContentsWrapper*, AutofillManager*) { 267 TabContentsWrapper*, AutofillManager*) {
265 return NULL; 268 return NULL;
266 } 269 }
267 270
268 #endif 271 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698