| 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 "chrome/browser/autocomplete_history_manager.h" | 5 #include "chrome/browser/autocomplete_history_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const IPC::Message& message) { | 127 const IPC::Message& message) { |
| 128 bool handled = true; | 128 bool handled = true; |
| 129 IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message) | 129 IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message) |
| 130 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry, | 130 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry, |
| 131 OnRemoveAutocompleteEntry) | 131 OnRemoveAutocompleteEntry) |
| 132 IPC_MESSAGE_UNHANDLED(handled = false) | 132 IPC_MESSAGE_UNHANDLED(handled = false) |
| 133 IPC_END_MESSAGE_MAP() | 133 IPC_END_MESSAGE_MAP() |
| 134 return handled; | 134 return handled; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { | 137 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( |
| 138 if (!*autofill_enabled_) | 138 WebDataService::Handle h, |
| 139 const WDTypedResult* result) { |
| 140 DCHECK(pending_query_handle_); |
| 141 pending_query_handle_ = 0; |
| 142 |
| 143 if (!*autofill_enabled_) { |
| 144 SendSuggestions(NULL); |
| 139 return; | 145 return; |
| 140 | |
| 141 if (profile_->IsOffTheRecord()) | |
| 142 return; | |
| 143 | |
| 144 // Don't save data that was submitted through JavaScript. | |
| 145 if (!form.user_submitted) | |
| 146 return; | |
| 147 | |
| 148 // We put the following restriction on stored FormFields: | |
| 149 // - non-empty name | |
| 150 // - non-empty value | |
| 151 // - text field | |
| 152 // - value is not a credit card number | |
| 153 // - value is not a SSN | |
| 154 std::vector<FormField> values; | |
| 155 for (std::vector<FormField>::const_iterator iter = | |
| 156 form.fields.begin(); | |
| 157 iter != form.fields.end(); ++iter) { | |
| 158 if (!iter->value.empty() && | |
| 159 !iter->name.empty() && | |
| 160 IsTextField(*iter) && | |
| 161 !CreditCard::IsValidCreditCardNumber(iter->value) && | |
| 162 !IsSSN(iter->value)) { | |
| 163 values.push_back(*iter); | |
| 164 } | |
| 165 } | 146 } |
| 166 | 147 |
| 167 if (!values.empty() && web_data_service_.get()) | 148 DCHECK(result); |
| 168 web_data_service_->AddFormFields(values); | 149 // Returning early here if |result| is NULL. We've seen this happen on |
| 169 } | 150 // Linux due to NFS dismounting and causing sql failures. |
| 151 // See http://crbug.com/68783. |
| 152 if (!result) { |
| 153 SendSuggestions(NULL); |
| 154 return; |
| 155 } |
| 170 | 156 |
| 171 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry( | 157 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); |
| 172 const string16& name, const string16& value) { | 158 const WDResult<std::vector<string16> >* autofill_result = |
| 173 if (web_data_service_.get()) | 159 static_cast<const WDResult<std::vector<string16> >*>(result); |
| 174 web_data_service_->RemoveFormValueForElementName(name, value); | 160 std::vector<string16> suggestions = autofill_result->GetValue(); |
| 161 SendSuggestions(&suggestions); |
| 175 } | 162 } |
| 176 | 163 |
| 177 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( | 164 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( |
| 178 int query_id, | 165 int query_id, |
| 179 const string16& name, | 166 const string16& name, |
| 180 const string16& prefix, | 167 const string16& prefix, |
| 181 const std::vector<string16>& autofill_values, | 168 const std::vector<string16>& autofill_values, |
| 182 const std::vector<string16>& autofill_labels, | 169 const std::vector<string16>& autofill_labels, |
| 183 const std::vector<string16>& autofill_icons, | 170 const std::vector<string16>& autofill_icons, |
| 184 const std::vector<int>& autofill_unique_ids) { | 171 const std::vector<int>& autofill_unique_ids) { |
| 185 CancelPendingQuery(); | 172 CancelPendingQuery(); |
| 186 | 173 |
| 187 query_id_ = query_id; | 174 query_id_ = query_id; |
| 188 autofill_values_ = autofill_values; | 175 autofill_values_ = autofill_values; |
| 189 autofill_labels_ = autofill_labels; | 176 autofill_labels_ = autofill_labels; |
| 190 autofill_icons_ = autofill_icons; | 177 autofill_icons_ = autofill_icons; |
| 191 autofill_unique_ids_ = autofill_unique_ids; | 178 autofill_unique_ids_ = autofill_unique_ids; |
| 192 if (!*autofill_enabled_) { | 179 if (!*autofill_enabled_) { |
| 193 SendSuggestions(NULL); | 180 SendSuggestions(NULL); |
| 194 return; | 181 return; |
| 195 } | 182 } |
| 196 | 183 |
| 197 if (web_data_service_.get()) { | 184 if (web_data_service_.get()) { |
| 198 pending_query_handle_ = web_data_service_->GetFormValuesForElementName( | 185 pending_query_handle_ = web_data_service_->GetFormValuesForElementName( |
| 199 name, prefix, kMaxAutocompleteMenuItems, this); | 186 name, prefix, kMaxAutocompleteMenuItems, this); |
| 200 } | 187 } |
| 201 } | 188 } |
| 202 | 189 |
| 203 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( | 190 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { |
| 204 WebDataService::Handle h, | 191 if (!*autofill_enabled_) |
| 205 const WDTypedResult* result) { | 192 return; |
| 206 DCHECK(pending_query_handle_); | |
| 207 pending_query_handle_ = 0; | |
| 208 | 193 |
| 209 if (!*autofill_enabled_) { | 194 if (profile_->IsOffTheRecord()) |
| 210 SendSuggestions(NULL); | |
| 211 return; | 195 return; |
| 196 |
| 197 // Don't save data that was submitted through JavaScript. |
| 198 if (!form.user_submitted) |
| 199 return; |
| 200 |
| 201 // We put the following restriction on stored FormFields: |
| 202 // - non-empty name |
| 203 // - non-empty value |
| 204 // - text field |
| 205 // - value is not a credit card number |
| 206 // - value is not a SSN |
| 207 std::vector<FormField> values; |
| 208 for (std::vector<FormField>::const_iterator iter = |
| 209 form.fields.begin(); |
| 210 iter != form.fields.end(); ++iter) { |
| 211 if (!iter->value.empty() && |
| 212 !iter->name.empty() && |
| 213 IsTextField(*iter) && |
| 214 !CreditCard::IsValidCreditCardNumber(iter->value) && |
| 215 !IsSSN(iter->value)) { |
| 216 values.push_back(*iter); |
| 217 } |
| 212 } | 218 } |
| 213 | 219 |
| 214 DCHECK(result); | 220 if (!values.empty() && web_data_service_.get()) |
| 215 // Returning early here if |result| is NULL. We've seen this happen on | 221 web_data_service_->AddFormFields(values); |
| 216 // Linux due to NFS dismounting and causing sql failures. | 222 } |
| 217 // See http://crbug.com/68783. | |
| 218 if (!result) { | |
| 219 SendSuggestions(NULL); | |
| 220 return; | |
| 221 } | |
| 222 | 223 |
| 223 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); | 224 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry( |
| 224 const WDResult<std::vector<string16> >* autofill_result = | 225 const string16& name, const string16& value) { |
| 225 static_cast<const WDResult<std::vector<string16> >*>(result); | 226 if (web_data_service_.get()) |
| 226 std::vector<string16> suggestions = autofill_result->GetValue(); | 227 web_data_service_->RemoveFormValueForElementName(name, value); |
| 227 SendSuggestions(&suggestions); | |
| 228 } | 228 } |
| 229 | 229 |
| 230 void AutocompleteHistoryManager::SetExternalDelegate( | 230 void AutocompleteHistoryManager::SetExternalDelegate( |
| 231 AutofillExternalDelegate* delegate) { | 231 AutofillExternalDelegate* delegate) { |
| 232 external_delegate_ = delegate; | 232 external_delegate_ = delegate; |
| 233 } | 233 } |
| 234 | 234 |
| 235 AutocompleteHistoryManager::AutocompleteHistoryManager( | 235 AutocompleteHistoryManager::AutocompleteHistoryManager( |
| 236 WebContents* web_contents, | 236 WebContents* web_contents, |
| 237 Profile* profile, | 237 Profile* profile, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 autofill_icons_, | 293 autofill_icons_, |
| 294 autofill_unique_ids_)); | 294 autofill_unique_ids_)); |
| 295 } | 295 } |
| 296 | 296 |
| 297 query_id_ = 0; | 297 query_id_ = 0; |
| 298 autofill_values_.clear(); | 298 autofill_values_.clear(); |
| 299 autofill_labels_.clear(); | 299 autofill_labels_.clear(); |
| 300 autofill_icons_.clear(); | 300 autofill_icons_.clear(); |
| 301 autofill_unique_ids_.clear(); | 301 autofill_unique_ids_.clear(); |
| 302 } | 302 } |
| OLD | NEW |