Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: components/autofill/browser/autocomplete_history_manager.cc

Issue 15097004: Enable Autocomplete feature for chromium webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setSaveFormData2
Patch Set: enable autocomplete independent of autofill. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_external_delegate.h" 12 #include "components/autofill/browser/autofill_external_delegate.h"
13 #include "components/autofill/browser/autofill_manager_delegate.h"
13 #include "components/autofill/browser/validation.h" 14 #include "components/autofill/browser/validation.h"
14 #include "components/autofill/common/autofill_messages.h" 15 #include "components/autofill/common/autofill_messages.h"
15 #include "components/autofill/common/autofill_pref_names.h" 16 #include "components/autofill/common/autofill_pref_names.h"
16 #include "components/autofill/common/form_data.h" 17 #include "components/autofill/common/form_data.h"
17 #include "components/user_prefs/user_prefs.h"
18 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 21
22 using content::BrowserContext; 22 using content::BrowserContext;
23 using content::WebContents; 23 using content::WebContents;
24 24
25 namespace autofill { 25 namespace autofill {
26 namespace { 26 namespace {
27 27
28 // Limit on the number of suggestions to appear in the pop-up menu under an 28 // Limit on the number of suggestions to appear in the pop-up menu under an
29 // text input element in a form. 29 // text input element in a form.
30 const int kMaxAutocompleteMenuItems = 6; 30 const int kMaxAutocompleteMenuItems = 6;
31 31
32 bool IsTextField(const FormFieldData& field) { 32 bool IsTextField(const FormFieldData& field) {
33 return 33 return
34 field.form_control_type == "text" || 34 field.form_control_type == "text" ||
35 field.form_control_type == "search" || 35 field.form_control_type == "search" ||
36 field.form_control_type == "tel" || 36 field.form_control_type == "tel" ||
37 field.form_control_type == "url" || 37 field.form_control_type == "url" ||
38 field.form_control_type == "email" || 38 field.form_control_type == "email" ||
39 field.form_control_type == "text"; 39 field.form_control_type == "text";
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 AutocompleteHistoryManager::AutocompleteHistoryManager( 44 AutocompleteHistoryManager::AutocompleteHistoryManager(
45 WebContents* web_contents) 45 WebContents* web_contents,
46 autofill::AutofillManagerDelegate* const manager_delegate)
46 : content::WebContentsObserver(web_contents), 47 : content::WebContentsObserver(web_contents),
47 browser_context_(web_contents->GetBrowserContext()), 48 browser_context_(web_contents->GetBrowserContext()),
48 autofill_data_( 49 autofill_data_(
49 AutofillWebDataService::FromBrowserContext(browser_context_)), 50 AutofillWebDataService::FromBrowserContext(browser_context_)),
50 pending_query_handle_(0), 51 pending_query_handle_(0),
51 query_id_(0), 52 query_id_(0),
52 external_delegate_(NULL) { 53 external_delegate_(NULL),
53 autofill_enabled_.Init( 54 manager_delegate_(manager_delegate) {
54 prefs::kAutofillEnabled, 55 DCHECK(manager_delegate_);
55 user_prefs::UserPrefs::Get(browser_context_));
56 } 56 }
57 57
58 AutocompleteHistoryManager::~AutocompleteHistoryManager() { 58 AutocompleteHistoryManager::~AutocompleteHistoryManager() {
59 CancelPendingQuery(); 59 CancelPendingQuery();
60 } 60 }
61 61
62 bool AutocompleteHistoryManager::OnMessageReceived( 62 bool AutocompleteHistoryManager::OnMessageReceived(
63 const IPC::Message& message) { 63 const IPC::Message& message) {
64 bool handled = true; 64 bool handled = true;
65 IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message) 65 IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message)
66 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry, 66 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry,
67 OnRemoveAutocompleteEntry) 67 OnRemoveAutocompleteEntry)
68 IPC_MESSAGE_UNHANDLED(handled = false) 68 IPC_MESSAGE_UNHANDLED(handled = false)
69 IPC_END_MESSAGE_MAP() 69 IPC_END_MESSAGE_MAP()
70 return handled; 70 return handled;
71 } 71 }
72 72
73 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( 73 void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
74 WebDataServiceBase::Handle h, 74 WebDataServiceBase::Handle h,
75 const WDTypedResult* result) { 75 const WDTypedResult* result) {
76 DCHECK(pending_query_handle_); 76 DCHECK(pending_query_handle_);
77 pending_query_handle_ = 0; 77 pending_query_handle_ = 0;
78 78
79 if (!*autofill_enabled_) { 79 if (!manager_delegate_->IsAutoCompleteEnabled()) {
80 SendSuggestions(NULL); 80 SendSuggestions(NULL);
81 return; 81 return;
82 } 82 }
83 83
84 DCHECK(result); 84 DCHECK(result);
85 // Returning early here if |result| is NULL. We've seen this happen on 85 // Returning early here if |result| is NULL. We've seen this happen on
86 // Linux due to NFS dismounting and causing sql failures. 86 // Linux due to NFS dismounting and causing sql failures.
87 // See http://crbug.com/68783. 87 // See http://crbug.com/68783.
88 if (!result) { 88 if (!result) {
89 SendSuggestions(NULL); 89 SendSuggestions(NULL);
(...skipping 15 matching lines...) Expand all
105 const std::vector<base::string16>& autofill_labels, 105 const std::vector<base::string16>& autofill_labels,
106 const std::vector<string16>& autofill_icons, 106 const std::vector<string16>& autofill_icons,
107 const std::vector<int>& autofill_unique_ids) { 107 const std::vector<int>& autofill_unique_ids) {
108 CancelPendingQuery(); 108 CancelPendingQuery();
109 109
110 query_id_ = query_id; 110 query_id_ = query_id;
111 autofill_values_ = autofill_values; 111 autofill_values_ = autofill_values;
112 autofill_labels_ = autofill_labels; 112 autofill_labels_ = autofill_labels;
113 autofill_icons_ = autofill_icons; 113 autofill_icons_ = autofill_icons;
114 autofill_unique_ids_ = autofill_unique_ids; 114 autofill_unique_ids_ = autofill_unique_ids;
115 if (!*autofill_enabled_) { 115 if (!manager_delegate_->IsAutoCompleteEnabled()) {
116 SendSuggestions(NULL); 116 SendSuggestions(NULL);
117 return; 117 return;
118 } 118 }
119 119
120 if (autofill_data_.get()) { 120 if (autofill_data_.get()) {
121 pending_query_handle_ = autofill_data_->GetFormValuesForElementName( 121 pending_query_handle_ = autofill_data_->GetFormValuesForElementName(
122 name, prefix, kMaxAutocompleteMenuItems, this); 122 name, prefix, kMaxAutocompleteMenuItems, this);
123 } 123 }
124 } 124 }
125 125
126 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 126 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
127 if (!*autofill_enabled_)
128 return;
Ilya Sherman 2013/06/18 05:56:25 Why did you remove this check?
sgurun-gerrit only 2013/06/19 00:16:17 weird. I have if (!manager_delegate_->IsAutocomp
129
130 if (browser_context_->IsOffTheRecord()) 127 if (browser_context_->IsOffTheRecord())
131 return; 128 return;
132 129
133 // Don't save data that was submitted through JavaScript. 130 // Don't save data that was submitted through JavaScript.
134 if (!form.user_submitted) 131 if (!form.user_submitted)
135 return; 132 return;
136 133
137 // We put the following restriction on stored FormFields: 134 // We put the following restriction on stored FormFields:
138 // - non-empty name 135 // - non-empty name
139 // - non-empty value 136 // - non-empty value
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 213 }
217 214
218 query_id_ = 0; 215 query_id_ = 0;
219 autofill_values_.clear(); 216 autofill_values_.clear();
220 autofill_labels_.clear(); 217 autofill_labels_.clear();
221 autofill_icons_.clear(); 218 autofill_icons_.clear();
222 autofill_unique_ids_.clear(); 219 autofill_unique_ids_.clear();
223 } 220 }
224 221
225 } // namespace autofill 222 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698