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 #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 "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | |
Ilya Sherman
2012/04/11 19:09:58
nit: This should come before the "ui/..." include
keishi
2012/04/12 14:07:11
Done.
| |
16 | 17 |
17 using content::RenderViewHost; | 18 using content::RenderViewHost; |
18 | 19 |
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 | |
29 AutofillExternalDelegate::~AutofillExternalDelegate() { | 20 AutofillExternalDelegate::~AutofillExternalDelegate() { |
30 } | 21 } |
31 | 22 |
32 AutofillExternalDelegate::AutofillExternalDelegate( | 23 AutofillExternalDelegate::AutofillExternalDelegate( |
33 TabContentsWrapper* tab_contents_wrapper, | 24 TabContentsWrapper* tab_contents_wrapper, |
34 AutofillManager* autofill_manager) | 25 AutofillManager* autofill_manager) |
35 : tab_contents_wrapper_(tab_contents_wrapper), | 26 : tab_contents_wrapper_(tab_contents_wrapper), |
36 autofill_manager_(autofill_manager), | 27 autofill_manager_(autofill_manager), |
37 password_autofill_manager_( | 28 password_autofill_manager_( |
38 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), | 29 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), |
39 autofill_query_id_(0), | 30 autofill_query_id_(0), |
40 display_warning_if_disabled_(false), | 31 display_warning_if_disabled_(false), |
41 has_shown_autofill_popup_for_current_edit_(false), | 32 has_shown_autofill_popup_for_current_edit_(false), |
42 suggestions_clear_index_(-1), | 33 suggestions_clear_index_(-1), |
43 suggestions_options_index_(-1) { | 34 suggestions_options_index_(-1) { |
44 } | 35 } |
45 | 36 |
46 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, | 37 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, |
47 int list_index) { | 38 int list_index) { |
48 if (password_autofill_manager_.DidSelectAutofillSuggestion( | 39 if (password_autofill_manager_.DidSelectAutofillSuggestion( |
49 autofill_query_field_)) | 40 autofill_query_field_)) |
50 return; | 41 return; |
51 | 42 |
52 if (list_index == suggestions_options_index_ || | 43 if (list_index == suggestions_options_index_ || |
53 list_index == suggestions_clear_index_ || | 44 list_index == suggestions_clear_index_ || |
54 unique_id == kWarningId) | 45 unique_id == WebKit::WarningMessageMenuItemID) |
55 return; | 46 return; |
56 | 47 |
57 FillAutofillFormData(unique_id, true); | 48 FillAutofillFormData(unique_id, true); |
58 } | 49 } |
59 | 50 |
60 void AutofillExternalDelegate::OnQuery(int query_id, | 51 void AutofillExternalDelegate::OnQuery(int query_id, |
61 const webkit::forms::FormData& form, | 52 const webkit::forms::FormData& form, |
62 const webkit::forms::FormField& field, | 53 const webkit::forms::FormField& field, |
63 const gfx::Rect& bounds, | 54 const gfx::Rect& bounds, |
64 bool display_warning_if_disabled) { | 55 bool display_warning_if_disabled) { |
(...skipping 25 matching lines...) Expand all Loading... | |
90 std::vector<string16> i(icons); | 81 std::vector<string16> i(icons); |
91 std::vector<int> ids(unique_ids); | 82 std::vector<int> ids(unique_ids); |
92 int separator_index = -1; | 83 int separator_index = -1; |
93 | 84 |
94 DCHECK_GT(ids.size(), 0U); | 85 DCHECK_GT(ids.size(), 0U); |
95 if (!autofill_query_field_.should_autocomplete) { | 86 if (!autofill_query_field_.should_autocomplete) { |
96 // If autofill is disabled and we had suggestions, show a warning instead. | 87 // If autofill is disabled and we had suggestions, show a warning instead. |
97 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); | 88 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); |
98 l.assign(1, string16()); | 89 l.assign(1, string16()); |
99 i.assign(1, string16()); | 90 i.assign(1, string16()); |
100 ids.assign(1, kWarningId); | 91 ids.assign(1, WebKit::WarningMessageMenuItemID); |
101 } else if (ids[0] < 0 && ids.size() > 1) { | 92 } else if (ids[0] < 0 && ids.size() > 1) { |
102 // If we received a warning instead of suggestions from autofill but regular | 93 // If we received a warning instead of suggestions from autofill but regular |
103 // suggestions from autocomplete, don't show the autofill warning. | 94 // suggestions from autocomplete, don't show the autofill warning. |
104 v.erase(v.begin()); | 95 v.erase(v.begin()); |
105 l.erase(l.begin()); | 96 l.erase(l.begin()); |
106 i.erase(i.begin()); | 97 i.erase(i.begin()); |
107 ids.erase(ids.begin()); | 98 ids.erase(ids.begin()); |
108 } | 99 } |
109 | 100 |
110 // If we were about to show a warning and we shouldn't, don't. | 101 // 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 Loading... | |
159 autofill_query_field_ = field; | 150 autofill_query_field_ = field; |
160 | 151 |
161 if (suggestions.empty()) { | 152 if (suggestions.empty()) { |
162 HideAutofillPopup(); | 153 HideAutofillPopup(); |
163 return; | 154 return; |
164 } | 155 } |
165 | 156 |
166 SetBounds(bounds); | 157 SetBounds(bounds); |
167 | 158 |
168 std::vector<string16> empty(suggestions.size()); | 159 std::vector<string16> empty(suggestions.size()); |
169 std::vector<int> password_ids(suggestions.size(), kPasswordEntryId); | 160 std::vector<int> password_ids(suggestions.size(), |
161 WebKit::PasswordEntryMenuItemID); | |
170 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); | 162 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); |
171 } | 163 } |
172 | 164 |
173 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 165 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
174 has_shown_autofill_popup_for_current_edit_ = false; | 166 has_shown_autofill_popup_for_current_edit_ = false; |
175 } | 167 } |
176 | 168 |
177 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( | 169 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( |
178 const string16& value, | 170 const string16& value, |
179 int unique_id, | 171 int unique_id, |
180 unsigned index) { | 172 unsigned index) { |
181 // If the selected element is a warning we don't want to do anything. | 173 // If the selected element is a warning we don't want to do anything. |
182 if (unique_id == kWarningId) | 174 if (unique_id == WebKit::WarningMessageMenuItemID) |
183 return false; | 175 return false; |
184 | 176 |
185 if (suggestions_options_index_ != -1 && | 177 if (suggestions_options_index_ != -1 && |
186 index == static_cast<unsigned>(suggestions_options_index_)) { | 178 index == static_cast<unsigned>(suggestions_options_index_)) { |
187 // User selected 'Autofill Options'. | 179 // User selected 'Autofill Options'. |
188 autofill_manager_->OnShowAutofillDialog(); | 180 autofill_manager_->OnShowAutofillDialog(); |
189 } else if (suggestions_clear_index_ != -1 && | 181 } else if (suggestions_clear_index_ != -1 && |
190 index == static_cast<unsigned>(suggestions_clear_index_)) { | 182 index == static_cast<unsigned>(suggestions_clear_index_)) { |
191 // User selected 'Clear form'. | 183 // User selected 'Clear form'. |
192 RenderViewHost* host = | 184 RenderViewHost* host = |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 // none, so all platforms use the default. | 258 // none, so all platforms use the default. |
267 | 259 |
268 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) | 260 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) |
269 | 261 |
270 AutofillExternalDelegate* AutofillExternalDelegate::Create( | 262 AutofillExternalDelegate* AutofillExternalDelegate::Create( |
271 TabContentsWrapper*, AutofillManager*) { | 263 TabContentsWrapper*, AutofillManager*) { |
272 return NULL; | 264 return NULL; |
273 } | 265 } |
274 | 266 |
275 #endif | 267 #endif |
OLD | NEW |