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

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

Issue 10024059: DataList UI (Chromium part) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits and tests 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/autofill/autofill_external_delegate.h" 6 #include "chrome/browser/autofill/autofill_external_delegate.h"
7 #include "chrome/browser/autofill/autofill_manager.h" 7 #include "chrome/browser/autofill/autofill_manager.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
9 #include "chrome/common/autofill_messages.h" 9 #include "chrome/common/autofill_messages.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
11 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 17
17 using content::RenderViewHost; 18 using content::RenderViewHost;
18 19 using WebKit::WebAutofillClient;
19 namespace {
20
21 // The value to give as the unique id for all warnings.
22 const int kWarningId = -1;
23
24 // The value to give as the unique id for all password entries.
25 const int kPasswordEntryId = -2;
26
27 } // namespace
28 20
29 AutofillExternalDelegate::~AutofillExternalDelegate() { 21 AutofillExternalDelegate::~AutofillExternalDelegate() {
30 } 22 }
31 23
32 AutofillExternalDelegate::AutofillExternalDelegate( 24 AutofillExternalDelegate::AutofillExternalDelegate(
33 TabContentsWrapper* tab_contents_wrapper, 25 TabContentsWrapper* tab_contents_wrapper,
34 AutofillManager* autofill_manager) 26 AutofillManager* autofill_manager)
35 : tab_contents_wrapper_(tab_contents_wrapper), 27 : tab_contents_wrapper_(tab_contents_wrapper),
36 autofill_manager_(autofill_manager), 28 autofill_manager_(autofill_manager),
37 password_autofill_manager_( 29 password_autofill_manager_(
38 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), 30 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL),
39 autofill_query_id_(0), 31 autofill_query_id_(0),
40 display_warning_if_disabled_(false), 32 display_warning_if_disabled_(false),
41 has_shown_autofill_popup_for_current_edit_(false), 33 has_shown_autofill_popup_for_current_edit_(false),
42 suggestions_clear_index_(-1), 34 suggestions_clear_index_(-1),
43 suggestions_options_index_(-1) { 35 suggestions_options_index_(-1) {
44 } 36 }
45 37
46 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, 38 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
47 int list_index) { 39 int list_index) {
48 if (password_autofill_manager_.DidSelectAutofillSuggestion( 40 if (password_autofill_manager_.DidSelectAutofillSuggestion(
49 autofill_query_field_)) 41 autofill_query_field_))
50 return; 42 return;
51 43
52 if (list_index == suggestions_options_index_ || 44 if (list_index == suggestions_options_index_ ||
53 list_index == suggestions_clear_index_ || 45 list_index == suggestions_clear_index_ ||
54 unique_id == kWarningId) 46 unique_id == WebAutofillClient::MenuItemIDWarningMessage)
55 return; 47 return;
56 48
57 FillAutofillFormData(unique_id, true); 49 FillAutofillFormData(unique_id, true);
58 } 50 }
59 51
60 void AutofillExternalDelegate::OnQuery(int query_id, 52 void AutofillExternalDelegate::OnQuery(int query_id,
61 const webkit::forms::FormData& form, 53 const webkit::forms::FormData& form,
62 const webkit::forms::FormField& field, 54 const webkit::forms::FormField& field,
63 const gfx::Rect& bounds, 55 const gfx::Rect& bounds,
64 bool display_warning_if_disabled) { 56 bool display_warning_if_disabled) {
(...skipping 25 matching lines...) Expand all
90 std::vector<string16> i(icons); 82 std::vector<string16> i(icons);
91 std::vector<int> ids(unique_ids); 83 std::vector<int> ids(unique_ids);
92 int separator_index = -1; 84 int separator_index = -1;
93 85
94 DCHECK_GT(ids.size(), 0U); 86 DCHECK_GT(ids.size(), 0U);
95 if (!autofill_query_field_.should_autocomplete) { 87 if (!autofill_query_field_.should_autocomplete) {
96 // If autofill is disabled and we had suggestions, show a warning instead. 88 // If autofill is disabled and we had suggestions, show a warning instead.
97 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); 89 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
98 l.assign(1, string16()); 90 l.assign(1, string16());
99 i.assign(1, string16()); 91 i.assign(1, string16());
100 ids.assign(1, kWarningId); 92 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage);
101 } else if (ids[0] < 0 && ids.size() > 1) { 93 } else if (ids[0] < 0 && ids.size() > 1) {
102 // If we received a warning instead of suggestions from autofill but regular 94 // If we received a warning instead of suggestions from autofill but regular
103 // suggestions from autocomplete, don't show the autofill warning. 95 // suggestions from autocomplete, don't show the autofill warning.
104 v.erase(v.begin()); 96 v.erase(v.begin());
105 l.erase(l.begin()); 97 l.erase(l.begin());
106 i.erase(i.begin()); 98 i.erase(i.begin());
107 ids.erase(ids.begin()); 99 ids.erase(ids.begin());
108 } 100 }
109 101
110 // If we were about to show a warning and we shouldn't, don't. 102 // If we were about to show a warning and we shouldn't, don't.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 autofill_query_field_ = field; 151 autofill_query_field_ = field;
160 152
161 if (suggestions.empty()) { 153 if (suggestions.empty()) {
162 HideAutofillPopup(); 154 HideAutofillPopup();
163 return; 155 return;
164 } 156 }
165 157
166 SetBounds(bounds); 158 SetBounds(bounds);
167 159
168 std::vector<string16> empty(suggestions.size()); 160 std::vector<string16> empty(suggestions.size());
169 std::vector<int> password_ids(suggestions.size(), kPasswordEntryId); 161 std::vector<int> password_ids(suggestions.size(),
162 WebAutofillClient::MenuItemIDPasswordEntry);
170 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); 163 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1);
171 } 164 }
172 165
173 void AutofillExternalDelegate::DidEndTextFieldEditing() { 166 void AutofillExternalDelegate::DidEndTextFieldEditing() {
174 has_shown_autofill_popup_for_current_edit_ = false; 167 has_shown_autofill_popup_for_current_edit_ = false;
175 } 168 }
176 169
177 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( 170 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
178 const string16& value, 171 const string16& value,
179 int unique_id, 172 int unique_id,
180 unsigned index) { 173 unsigned index) {
181 // If the selected element is a warning we don't want to do anything. 174 // If the selected element is a warning we don't want to do anything.
182 if (unique_id == kWarningId) 175 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
183 return false; 176 return false;
184 177
185 if (suggestions_options_index_ != -1 && 178 if (suggestions_options_index_ != -1 &&
186 index == static_cast<unsigned>(suggestions_options_index_)) { 179 index == static_cast<unsigned>(suggestions_options_index_)) {
187 // User selected 'Autofill Options'. 180 // User selected 'Autofill Options'.
188 autofill_manager_->OnShowAutofillDialog(); 181 autofill_manager_->OnShowAutofillDialog();
189 } else if (suggestions_clear_index_ != -1 && 182 } else if (suggestions_clear_index_ != -1 &&
190 index == static_cast<unsigned>(suggestions_clear_index_)) { 183 index == static_cast<unsigned>(suggestions_clear_index_)) {
191 // User selected 'Clear form'. 184 // User selected 'Clear form'.
192 RenderViewHost* host = 185 RenderViewHost* host =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // none, so all platforms use the default. 259 // none, so all platforms use the default.
267 260
268 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 261 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
269 262
270 AutofillExternalDelegate* AutofillExternalDelegate::Create( 263 AutofillExternalDelegate* AutofillExternalDelegate::Create(
271 TabContentsWrapper*, AutofillManager*) { 264 TabContentsWrapper*, AutofillManager*) {
272 return NULL; 265 return NULL;
273 } 266 }
274 267
275 #endif 268 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698