| 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/autocomplete_history_manager.h" | 6 #include "chrome/browser/autocomplete_history_manager.h" |
| 7 #include "chrome/browser/autofill/autofill_external_delegate.h" | 7 #include "chrome/browser/autofill/autofill_external_delegate.h" |
| 8 #include "chrome/browser/autofill/autofill_manager.h" | 8 #include "chrome/browser/autofill/autofill_manager.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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 password_autofill_manager_( | 29 password_autofill_manager_( |
| 30 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), | 30 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), |
| 31 autofill_query_id_(0), | 31 autofill_query_id_(0), |
| 32 display_warning_if_disabled_(false), | 32 display_warning_if_disabled_(false), |
| 33 has_shown_autofill_popup_for_current_edit_(false) { | 33 has_shown_autofill_popup_for_current_edit_(false) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) { | 36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) { |
| 37 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions || | 37 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions || |
| 38 unique_id == WebAutofillClient::MenuItemIDClearForm || | 38 unique_id == WebAutofillClient::MenuItemIDClearForm || |
| 39 unique_id == WebAutofillClient::MenuItemIDSeparator || |
| 39 unique_id == WebAutofillClient::MenuItemIDWarningMessage) | 40 unique_id == WebAutofillClient::MenuItemIDWarningMessage) |
| 40 return; | 41 return; |
| 41 | 42 |
| 42 ClearPreviewedForm(); | 43 ClearPreviewedForm(); |
| 43 | 44 |
| 44 if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry) | 45 if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry) |
| 45 return; | 46 return; |
| 46 | 47 |
| 47 FillAutofillFormData(unique_id, true); | 48 FillAutofillFormData(unique_id, true); |
| 48 } | 49 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 73 // No suggestions, any popup currently showing is obsolete. | 74 // No suggestions, any popup currently showing is obsolete. |
| 74 HideAutofillPopup(); | 75 HideAutofillPopup(); |
| 75 return; | 76 return; |
| 76 } | 77 } |
| 77 | 78 |
| 78 std::vector<string16> v(values); | 79 std::vector<string16> v(values); |
| 79 std::vector<string16> l(labels); | 80 std::vector<string16> l(labels); |
| 80 std::vector<string16> i(icons); | 81 std::vector<string16> i(icons); |
| 81 std::vector<int> ids(unique_ids); | 82 std::vector<int> ids(unique_ids); |
| 82 | 83 |
| 84 // Add a separator to go between the values and menu items. |
| 85 v.push_back(string16()); |
| 86 l.push_back(string16()); |
| 87 i.push_back(string16()); |
| 88 ids.push_back(WebAutofillClient::MenuItemIDSeparator); |
| 89 |
| 83 DCHECK_GT(ids.size(), 0U); | 90 DCHECK_GT(ids.size(), 0U); |
| 84 if (!autofill_query_field_.should_autocomplete) { | 91 if (!autofill_query_field_.should_autocomplete) { |
| 85 // If autofill is disabled and we had suggestions, show a warning instead. | 92 // If autofill is disabled and we had suggestions, show a warning instead. |
| 86 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); | 93 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); |
| 87 l.assign(1, string16()); | 94 l.assign(1, string16()); |
| 88 i.assign(1, string16()); | 95 i.assign(1, string16()); |
| 89 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage); | 96 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage); |
| 90 } else if (ids[0] < 0 && ids.size() > 1) { | 97 } else if (ids[0] < 0 && ids.size() > 1) { |
| 91 // If we received a warning instead of suggestions from autofill but regular | 98 // If we received a warning instead of suggestions from autofill but regular |
| 92 // suggestions from autocomplete, don't show the autofill warning. | 99 // suggestions from autocomplete, don't show the autofill warning. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 120 } | 127 } |
| 121 | 128 |
| 122 if (has_autofill_item) { | 129 if (has_autofill_item) { |
| 123 // Append the 'Chrome Autofill options' menu item; | 130 // Append the 'Chrome Autofill options' menu item; |
| 124 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); | 131 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); |
| 125 l.push_back(string16()); | 132 l.push_back(string16()); |
| 126 i.push_back(string16()); | 133 i.push_back(string16()); |
| 127 ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions); | 134 ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions); |
| 128 } | 135 } |
| 129 | 136 |
| 137 // Remove the separator if it is the last element. |
| 138 if (*(ids.rbegin()) == WebAutofillClient::MenuItemIDSeparator) { |
| 139 v.pop_back(); |
| 140 l.pop_back(); |
| 141 i.pop_back(); |
| 142 ids.pop_back(); |
| 143 } |
| 144 |
| 130 // Send to display. | 145 // Send to display. |
| 131 if (!v.empty() && autofill_query_field_.is_focusable) | 146 if (!v.empty() && autofill_query_field_.is_focusable) |
| 132 ApplyAutofillSuggestions(v, l, i, ids); | 147 ApplyAutofillSuggestions(v, l, i, ids); |
| 133 | 148 |
| 134 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( | 149 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( |
| 135 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); | 150 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); |
| 136 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 151 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
| 137 } | 152 } |
| 138 | 153 |
| 139 void AutofillExternalDelegate::OnShowPasswordSuggestions( | 154 void AutofillExternalDelegate::OnShowPasswordSuggestions( |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // none, so all platforms use the default. | 273 // none, so all platforms use the default. |
| 259 | 274 |
| 260 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) | 275 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) |
| 261 | 276 |
| 262 AutofillExternalDelegate* AutofillExternalDelegate::Create( | 277 AutofillExternalDelegate* AutofillExternalDelegate::Create( |
| 263 TabContentsWrapper*, AutofillManager*) { | 278 TabContentsWrapper*, AutofillManager*) { |
| 264 return NULL; | 279 return NULL; |
| 265 } | 280 } |
| 266 | 281 |
| 267 #endif | 282 #endif |
| OLD | NEW |