| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/autofill_helper.h" | 5 #include "chrome/renderer/autofill_helper.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "chrome/renderer/form_manager.h" | 8 #include "chrome/renderer/form_manager.h" |
| 9 #include "chrome/renderer/render_view.h" | 9 #include "chrome/renderer/render_view.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 if (suggestions_options_index_ != -1) | 59 if (suggestions_options_index_ != -1) |
| 60 suggestions_options_index_--; | 60 suggestions_options_index_--; |
| 61 | 61 |
| 62 render_view_->Send(new ViewHostMsg_RemoveAutocompleteEntry( | 62 render_view_->Send(new ViewHostMsg_RemoveAutocompleteEntry( |
| 63 render_view_->routing_id(), name, value)); | 63 render_view_->routing_id(), name, value)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void AutoFillHelper::SuggestionsReceived(int query_id, | 66 void AutoFillHelper::SuggestionsReceived(int query_id, |
| 67 const std::vector<string16>& values, | 67 const std::vector<string16>& values, |
| 68 const std::vector<string16>& labels, | 68 const std::vector<string16>& labels, |
| 69 const std::vector<string16>& icons, |
| 69 const std::vector<int>& unique_ids) { | 70 const std::vector<int>& unique_ids) { |
| 70 WebKit::WebView* web_view = render_view_->webview(); | 71 WebKit::WebView* web_view = render_view_->webview(); |
| 71 if (!web_view || query_id != autofill_query_id_) | 72 if (!web_view || query_id != autofill_query_id_) |
| 72 return; | 73 return; |
| 73 | 74 |
| 74 // Any popup currently showing is now obsolete. | 75 // Any popup currently showing is now obsolete. |
| 75 web_view->hidePopups(); | 76 web_view->hidePopups(); |
| 76 | 77 |
| 77 // No suggestions: nothing to do. | 78 // No suggestions: nothing to do. |
| 78 if (values.empty()) | 79 if (values.empty()) |
| 79 return; | 80 return; |
| 80 | 81 |
| 81 std::vector<string16> v(values); | 82 std::vector<string16> v(values); |
| 82 std::vector<string16> l(labels); | 83 std::vector<string16> l(labels); |
| 84 std::vector<string16> i(icons); |
| 83 std::vector<int> ids(unique_ids); | 85 std::vector<int> ids(unique_ids); |
| 84 int separator_index = -1; | 86 int separator_index = -1; |
| 85 | 87 |
| 86 // The form has been auto-filled, so give the user the chance to clear the | 88 // The form has been auto-filled, so give the user the chance to clear the |
| 87 // form. Append the 'Clear form' menu item. | 89 // form. Append the 'Clear form' menu item. |
| 88 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { | 90 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) { |
| 89 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); | 91 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); |
| 90 l.push_back(string16()); | 92 l.push_back(string16()); |
| 93 i.push_back(string16()); |
| 91 ids.push_back(0); | 94 ids.push_back(0); |
| 92 suggestions_clear_index_ = v.size() - 1; | 95 suggestions_clear_index_ = v.size() - 1; |
| 93 separator_index = values.size(); | 96 separator_index = values.size(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 // Only include "AutoFill Options" special menu item if we have AutoFill | 99 // Only include "AutoFill Options" special menu item if we have AutoFill |
| 97 // items, identified by |unique_ids| having at least one valid value. | 100 // items, identified by |unique_ids| having at least one valid value. |
| 98 bool show_options = false; | 101 bool show_options = false; |
| 99 for (size_t i = 0; i < ids.size(); ++i) { | 102 for (size_t i = 0; i < ids.size(); ++i) { |
| 100 if (ids[i] != 0) { | 103 if (ids[i] != 0) { |
| 101 show_options = true; | 104 show_options = true; |
| 102 break; | 105 break; |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 if (show_options) { | 108 if (show_options) { |
| 106 // Append the 'AutoFill Options...' menu item. | 109 // Append the 'AutoFill Options...' menu item. |
| 107 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); | 110 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)); |
| 108 l.push_back(string16()); | 111 l.push_back(string16()); |
| 112 i.push_back(string16()); |
| 109 ids.push_back(0); | 113 ids.push_back(0); |
| 110 suggestions_options_index_ = v.size() - 1; | 114 suggestions_options_index_ = v.size() - 1; |
| 111 separator_index = values.size(); | 115 separator_index = values.size(); |
| 112 } | 116 } |
| 113 | 117 |
| 114 // Send to WebKit for display. | 118 // Send to WebKit for display. |
| 115 if (!v.empty()) { | 119 if (!v.empty()) { |
| 116 web_view->applyAutoFillSuggestions( | 120 web_view->applyAutoFillSuggestions( |
| 117 autofill_query_node_, v, l, ids, separator_index); | 121 autofill_query_node_, v, l, i, ids, separator_index); |
| 118 } | 122 } |
| 119 } | 123 } |
| 120 | 124 |
| 121 void AutoFillHelper::FormDataFilled(int query_id, | 125 void AutoFillHelper::FormDataFilled(int query_id, |
| 122 const webkit_glue::FormData& form) { | 126 const webkit_glue::FormData& form) { |
| 123 if (!render_view_->webview() || query_id != autofill_query_id_) | 127 if (!render_view_->webview() || query_id != autofill_query_id_) |
| 124 return; | 128 return; |
| 125 | 129 |
| 126 switch (autofill_action_) { | 130 switch (autofill_action_) { |
| 127 case AUTOFILL_FILL: | 131 case AUTOFILL_FILL: |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 web_form, FormManager::REQUIRE_NONE, false, &form)) { | 235 web_form, FormManager::REQUIRE_NONE, false, &form)) { |
| 232 forms.push_back(form); | 236 forms.push_back(form); |
| 233 } | 237 } |
| 234 } | 238 } |
| 235 | 239 |
| 236 if (!forms.empty()) { | 240 if (!forms.empty()) { |
| 237 render_view_->Send(new ViewHostMsg_FormsSeen(render_view_->routing_id(), | 241 render_view_->Send(new ViewHostMsg_FormsSeen(render_view_->routing_id(), |
| 238 forms)); | 242 forms)); |
| 239 } | 243 } |
| 240 } | 244 } |
| OLD | NEW |