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

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

Powered by Google App Engine
This is Rietveld 408576698