| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autocomplete_history_manager.h" | 5 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/autofill/core/browser/autofill_driver.h" | 12 #include "components/autofill/core/browser/autofill_driver.h" |
| 13 #include "components/autofill/core/browser/autofill_external_delegate.h" | 13 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 14 #include "components/autofill/core/browser/autofill_manager_delegate.h" |
| 14 #include "components/autofill/core/browser/validation.h" | 15 #include "components/autofill/core/browser/validation.h" |
| 15 #include "components/autofill/core/common/autofill_messages.h" | 16 #include "components/autofill/core/common/autofill_messages.h" |
| 16 #include "components/autofill/core/common/autofill_pref_names.h" | 17 #include "components/autofill/core/common/autofill_pref_names.h" |
| 17 #include "components/autofill/core/common/form_data.h" | 18 #include "components/autofill/core/common/form_data.h" |
| 18 #include "components/user_prefs/user_prefs.h" | |
| 19 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 | 22 |
| 23 using content::BrowserContext; | 23 using content::BrowserContext; |
| 24 using content::WebContents; | 24 using content::WebContents; |
| 25 | 25 |
| 26 namespace autofill { | 26 namespace autofill { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Limit on the number of suggestions to appear in the pop-up menu under an | 29 // Limit on the number of suggestions to appear in the pop-up menu under an |
| 30 // text input element in a form. | 30 // text input element in a form. |
| 31 const int kMaxAutocompleteMenuItems = 6; | 31 const int kMaxAutocompleteMenuItems = 6; |
| 32 | 32 |
| 33 bool IsTextField(const FormFieldData& field) { | 33 bool IsTextField(const FormFieldData& field) { |
| 34 return | 34 return |
| 35 field.form_control_type == "text" || | 35 field.form_control_type == "text" || |
| 36 field.form_control_type == "search" || | 36 field.form_control_type == "search" || |
| 37 field.form_control_type == "tel" || | 37 field.form_control_type == "tel" || |
| 38 field.form_control_type == "url" || | 38 field.form_control_type == "url" || |
| 39 field.form_control_type == "email" || | 39 field.form_control_type == "email" || |
| 40 field.form_control_type == "text"; | 40 field.form_control_type == "text"; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 AutocompleteHistoryManager::AutocompleteHistoryManager(AutofillDriver* driver) | 45 AutocompleteHistoryManager::AutocompleteHistoryManager( |
| 46 AutofillDriver* driver, |
| 47 AutofillManagerDelegate* manager_delegate) |
| 46 : browser_context_(driver->GetWebContents()->GetBrowserContext()), | 48 : browser_context_(driver->GetWebContents()->GetBrowserContext()), |
| 47 driver_(driver), | 49 driver_(driver), |
| 48 autofill_data_( | 50 autofill_data_( |
| 49 AutofillWebDataService::FromBrowserContext(browser_context_)), | 51 AutofillWebDataService::FromBrowserContext(browser_context_)), |
| 50 pending_query_handle_(0), | 52 pending_query_handle_(0), |
| 51 query_id_(0), | 53 query_id_(0), |
| 52 external_delegate_(NULL), | 54 external_delegate_(NULL), |
| 55 manager_delegate_(manager_delegate), |
| 53 send_ipc_(true) { | 56 send_ipc_(true) { |
| 54 autofill_enabled_.Init( | 57 DCHECK(manager_delegate_); |
| 55 prefs::kAutofillEnabled, | |
| 56 user_prefs::UserPrefs::Get(browser_context_)); | |
| 57 } | 58 } |
| 58 | 59 |
| 59 AutocompleteHistoryManager::~AutocompleteHistoryManager() { | 60 AutocompleteHistoryManager::~AutocompleteHistoryManager() { |
| 60 CancelPendingQuery(); | 61 CancelPendingQuery(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( | 64 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( |
| 64 WebDataServiceBase::Handle h, | 65 WebDataServiceBase::Handle h, |
| 65 const WDTypedResult* result) { | 66 const WDTypedResult* result) { |
| 66 DCHECK(pending_query_handle_); | 67 DCHECK(pending_query_handle_); |
| 67 pending_query_handle_ = 0; | 68 pending_query_handle_ = 0; |
| 68 | 69 |
| 69 if (!*autofill_enabled_) { | 70 if (!manager_delegate_->IsAutocompleteEnabled()) { |
| 70 SendSuggestions(NULL); | 71 SendSuggestions(NULL); |
| 71 return; | 72 return; |
| 72 } | 73 } |
| 73 | 74 |
| 74 DCHECK(result); | 75 DCHECK(result); |
| 75 // Returning early here if |result| is NULL. We've seen this happen on | 76 // Returning early here if |result| is NULL. We've seen this happen on |
| 76 // Linux due to NFS dismounting and causing sql failures. | 77 // Linux due to NFS dismounting and causing sql failures. |
| 77 // See http://crbug.com/68783. | 78 // See http://crbug.com/68783. |
| 78 if (!result) { | 79 if (!result) { |
| 79 SendSuggestions(NULL); | 80 SendSuggestions(NULL); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 95 const std::vector<base::string16>& autofill_labels, | 96 const std::vector<base::string16>& autofill_labels, |
| 96 const std::vector<string16>& autofill_icons, | 97 const std::vector<string16>& autofill_icons, |
| 97 const std::vector<int>& autofill_unique_ids) { | 98 const std::vector<int>& autofill_unique_ids) { |
| 98 CancelPendingQuery(); | 99 CancelPendingQuery(); |
| 99 | 100 |
| 100 query_id_ = query_id; | 101 query_id_ = query_id; |
| 101 autofill_values_ = autofill_values; | 102 autofill_values_ = autofill_values; |
| 102 autofill_labels_ = autofill_labels; | 103 autofill_labels_ = autofill_labels; |
| 103 autofill_icons_ = autofill_icons; | 104 autofill_icons_ = autofill_icons; |
| 104 autofill_unique_ids_ = autofill_unique_ids; | 105 autofill_unique_ids_ = autofill_unique_ids; |
| 105 if (!*autofill_enabled_) { | 106 if (!manager_delegate_->IsAutocompleteEnabled()) { |
| 106 SendSuggestions(NULL); | 107 SendSuggestions(NULL); |
| 107 return; | 108 return; |
| 108 } | 109 } |
| 109 | 110 |
| 110 if (autofill_data_.get()) { | 111 if (autofill_data_.get()) { |
| 111 pending_query_handle_ = autofill_data_->GetFormValuesForElementName( | 112 pending_query_handle_ = autofill_data_->GetFormValuesForElementName( |
| 112 name, prefix, kMaxAutocompleteMenuItems, this); | 113 name, prefix, kMaxAutocompleteMenuItems, this); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 | 116 |
| 116 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { | 117 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { |
| 117 if (!*autofill_enabled_) | 118 if (!manager_delegate_->IsAutocompleteEnabled()) |
| 118 return; | 119 return; |
| 119 | 120 |
| 120 if (browser_context_->IsOffTheRecord()) | 121 if (browser_context_->IsOffTheRecord()) |
| 121 return; | 122 return; |
| 122 | 123 |
| 123 // Don't save data that was submitted through JavaScript. | 124 // Don't save data that was submitted through JavaScript. |
| 124 if (!form.user_submitted) | 125 if (!form.user_submitted) |
| 125 return; | 126 return; |
| 126 | 127 |
| 127 // We put the following restriction on stored FormFields: | 128 // We put the following restriction on stored FormFields: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 211 } |
| 211 | 212 |
| 212 query_id_ = 0; | 213 query_id_ = 0; |
| 213 autofill_values_.clear(); | 214 autofill_values_.clear(); |
| 214 autofill_labels_.clear(); | 215 autofill_labels_.clear(); |
| 215 autofill_icons_.clear(); | 216 autofill_icons_.clear(); |
| 216 autofill_unique_ids_.clear(); | 217 autofill_unique_ids_.clear(); |
| 217 } | 218 } |
| 218 | 219 |
| 219 } // namespace autofill | 220 } // namespace autofill |
| OLD | NEW |