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

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) {
40 if (password_autofill_manager_.DidSelectAutofillSuggestion( 38 if (password_autofill_manager_.DidSelectAutofillSuggestion(
41 autofill_query_field_)) 39 autofill_query_field_))
42 return; 40 return;
43 41
44 if (list_index == suggestions_options_index_ || 42 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions ||
45 list_index == suggestions_clear_index_ || 43 unique_id == WebAutofillClient::MenuItemIDClearForm ||
46 unique_id == WebAutofillClient::MenuItemIDWarningMessage) 44 unique_id == WebAutofillClient::MenuItemIDWarningMessage)
47 return; 45 return;
48 46
49 FillAutofillFormData(unique_id, true); 47 FillAutofillFormData(unique_id, true);
50 } 48 }
51 49
52 void AutofillExternalDelegate::OnQuery(int query_id, 50 void AutofillExternalDelegate::OnQuery(int query_id,
53 const webkit::forms::FormData& form, 51 const webkit::forms::FormData& form,
54 const webkit::forms::FormField& field, 52 const webkit::forms::FormField& field,
55 const gfx::Rect& bounds, 53 const gfx::Rect& bounds,
(...skipping 18 matching lines...) Expand all
74 if (values.empty()) { 72 if (values.empty()) {
75 // No suggestions, any popup currently showing is obsolete. 73 // No suggestions, any popup currently showing is obsolete.
76 HideAutofillPopup(); 74 HideAutofillPopup();
77 return; 75 return;
78 } 76 }
79 77
80 std::vector<string16> v(values); 78 std::vector<string16> v(values);
81 std::vector<string16> l(labels); 79 std::vector<string16> l(labels);
82 std::vector<string16> i(icons); 80 std::vector<string16> i(icons);
83 std::vector<int> ids(unique_ids); 81 std::vector<int> ids(unique_ids);
84 int separator_index = -1;
85 82
86 DCHECK_GT(ids.size(), 0U); 83 DCHECK_GT(ids.size(), 0U);
87 if (!autofill_query_field_.should_autocomplete) { 84 if (!autofill_query_field_.should_autocomplete) {
88 // If autofill is disabled and we had suggestions, show a warning instead. 85 // If autofill is disabled and we had suggestions, show a warning instead.
89 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); 86 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
90 l.assign(1, string16()); 87 l.assign(1, string16());
91 i.assign(1, string16()); 88 i.assign(1, string16());
92 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage); 89 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage);
93 } else if (ids[0] < 0 && ids.size() > 1) { 90 } else if (ids[0] < 0 && ids.size() > 1) {
94 // If we received a warning instead of suggestions from autofill but regular 91 // 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 103 // Only include "Autofill Options" special menu item if we have Autofill
107 // items, identified by |unique_ids| having at least one valid value. 104 // items, identified by |unique_ids| having at least one valid value.
108 bool has_autofill_item = false; 105 bool has_autofill_item = false;
109 for (size_t i = 0; i < ids.size(); ++i) { 106 for (size_t i = 0; i < ids.size(); ++i) {
110 if (ids[i] > 0) { 107 if (ids[i] > 0) {
111 has_autofill_item = true; 108 has_autofill_item = true;
112 break; 109 break;
113 } 110 }
114 } 111 }
115 112
113 int separator_index = ids.size();
114
116 // The form has been auto-filled, so give the user the chance to clear the 115 // The form has been auto-filled, so give the user the chance to clear the
117 // form. Append the 'Clear form' menu item. 116 // form. Append the 'Clear form' menu item.
118 if (has_autofill_item && 117 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)); 118 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
121 l.push_back(string16()); 119 l.push_back(string16());
122 i.push_back(string16()); 120 i.push_back(string16());
123 ids.push_back(0); 121 ids.push_back(WebAutofillClient::MenuItemIDClearForm);
124 suggestions_clear_index_ = v.size() - 1;
125 separator_index = v.size() - 1;
126 } 122 }
127 123
128 if (has_autofill_item) { 124 if (has_autofill_item) {
129 // Append the 'Chrome Autofill options' menu item; 125 // Append the 'Chrome Autofill options' menu item;
130 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); 126 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP));
131 l.push_back(string16()); 127 l.push_back(string16());
132 i.push_back(string16()); 128 i.push_back(string16());
133 ids.push_back(0); 129 ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions);
134 suggestions_options_index_ = v.size() - 1;
135 separator_index = values.size();
136 } 130 }
137 131
138 // Send to display. 132 // Send to display.
139 if (!v.empty() && autofill_query_field_.is_focusable) 133 if (!v.empty() && autofill_query_field_.is_focusable)
140 ApplyAutofillSuggestions(v, l, i, ids, separator_index); 134 ApplyAutofillSuggestions(v, l, i, ids, separator_index);
141 135
142 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( 136 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions(
143 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); 137 has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
144 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; 138 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
145 } 139 }
(...skipping 10 matching lines...) Expand all
156 } 150 }
157 151
158 SetBounds(bounds); 152 SetBounds(bounds);
159 153
160 std::vector<string16> empty(suggestions.size()); 154 std::vector<string16> empty(suggestions.size());
161 std::vector<int> password_ids(suggestions.size(), 155 std::vector<int> password_ids(suggestions.size(),
162 WebAutofillClient::MenuItemIDPasswordEntry); 156 WebAutofillClient::MenuItemIDPasswordEntry);
163 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); 157 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1);
164 } 158 }
165 159
160 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) {
161 if (tab_contents_wrapper_) {
162 tab_contents_wrapper_->autocomplete_history_manager()->
163 OnRemoveAutocompleteEntry(autofill_query_field_.name, value);
164 }
165 }
166
167 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard(
168 int unique_id) {
169 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id);
170 }
171
172
166 void AutofillExternalDelegate::DidEndTextFieldEditing() { 173 void AutofillExternalDelegate::DidEndTextFieldEditing() {
167 has_shown_autofill_popup_for_current_edit_ = false; 174 has_shown_autofill_popup_for_current_edit_ = false;
168 } 175 }
169 176
170 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( 177 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
171 const string16& value, 178 const string16& value,
172 int unique_id, 179 int unique_id,
173 unsigned index) { 180 unsigned index) {
174 // If the selected element is a warning we don't want to do anything. 181 // If the selected element is a warning we don't want to do anything.
175 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage) 182 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
176 return false; 183 return false;
177 184
178 if (suggestions_options_index_ != -1 && 185 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) {
179 index == static_cast<unsigned>(suggestions_options_index_)) {
180 // User selected 'Autofill Options'. 186 // User selected 'Autofill Options'.
181 autofill_manager_->OnShowAutofillDialog(); 187 autofill_manager_->OnShowAutofillDialog();
182 } else if (suggestions_clear_index_ != -1 && 188 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) {
183 index == static_cast<unsigned>(suggestions_clear_index_)) {
184 // User selected 'Clear form'. 189 // User selected 'Clear form'.
185 RenderViewHost* host = 190 RenderViewHost* host =
186 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 191 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
187 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); 192 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
188 } else if (password_autofill_manager_.DidAcceptAutofillSuggestion( 193 } else if (password_autofill_manager_.DidAcceptAutofillSuggestion(
189 autofill_query_field_, value)) { 194 autofill_query_field_, value)) {
190 // DidAcceptAutofillSuggestion has already handled the work to fill in 195 // DidAcceptAutofillSuggestion has already handled the work to fill in
191 // the page as required. 196 // the page as required.
192 } else if (!unique_id) { 197 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) {
193 // User selected an Autocomplete, so we fill directly. 198 // User selected an Autocomplete, so we fill directly.
194 RenderViewHost* host = 199 RenderViewHost* host =
195 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 200 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
196 host->Send(new AutofillMsg_SetNodeText( 201 host->Send(new AutofillMsg_SetNodeText(
197 host->GetRoutingID(), 202 host->GetRoutingID(),
198 value)); 203 value));
199 } else { 204 } else {
200 FillAutofillFormData(unique_id, false); 205 FillAutofillFormData(unique_id, false);
201 } 206 }
202 207
203 HideAutofillPopup(); 208 HideAutofillPopup();
204 209
205 return true; 210 return true;
206 } 211 }
207 212
208 void AutofillExternalDelegate::ClearPreviewedForm() { 213 void AutofillExternalDelegate::ClearPreviewedForm() {
209 if (password_autofill_manager_.DidClearAutofillSelection( 214 if (password_autofill_manager_.DidClearAutofillSelection(
210 autofill_query_field_)) 215 autofill_query_field_))
211 return; 216 return;
212 217
213 RenderViewHost* host = 218 RenderViewHost* host =
214 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 219 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
215 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); 220 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
216 } 221 }
217 222
218 void AutofillExternalDelegate::HideAutofillPopup() { 223 void AutofillExternalDelegate::HideAutofillPopup() {
219 suggestions_clear_index_ = -1;
220 suggestions_options_index_ = -1;
221
222 HideAutofillPopupInternal(); 224 HideAutofillPopupInternal();
223 } 225 }
224 226
225 void AutofillExternalDelegate::Reset() { 227 void AutofillExternalDelegate::Reset() {
226 HideAutofillPopup(); 228 HideAutofillPopup();
227 229
228 password_autofill_manager_.Reset(); 230 password_autofill_manager_.Reset();
229 } 231 }
230 232
231 void AutofillExternalDelegate::AddPasswordFormMapping( 233 void AutofillExternalDelegate::AddPasswordFormMapping(
(...skipping 27 matching lines...) Expand all
259 // none, so all platforms use the default. 261 // none, so all platforms use the default.
260 262
261 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 263 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
262 264
263 AutofillExternalDelegate* AutofillExternalDelegate::Create( 265 AutofillExternalDelegate* AutofillExternalDelegate::Create(
264 TabContentsWrapper*, AutofillManager*) { 266 TabContentsWrapper*, AutofillManager*) {
265 return NULL; 267 return NULL;
266 } 268 }
267 269
268 #endif 270 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698