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