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/string16.h" | 10 #include "base/string16.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/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/validation.h" | 13 #include "components/autofill/browser/validation.h" |
14 #include "components/autofill/common/autofill_messages.h" | 14 #include "components/autofill/common/autofill_messages.h" |
15 #include "components/autofill/common/autofill_pref_names.h" | 15 #include "components/autofill/common/autofill_pref_names.h" |
16 #include "components/autofill/common/form_data.h" | 16 #include "components/autofill/common/form_data.h" |
17 #include "components/user_prefs/user_prefs.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 #include "ipc/ipc_message_macros.h" | |
21 | 22 |
22 using content::BrowserContext; | 23 using content::BrowserContext; |
23 using content::WebContents; | 24 using content::WebContents; |
24 | 25 |
25 namespace autofill { | 26 namespace autofill { |
26 namespace { | 27 namespace { |
27 | 28 |
28 // 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 |
29 // text input element in a form. | 30 // text input element in a form. |
30 const int kMaxAutocompleteMenuItems = 6; | 31 const int kMaxAutocompleteMenuItems = 6; |
31 | 32 |
32 bool IsTextField(const FormFieldData& field) { | 33 bool IsTextField(const FormFieldData& field) { |
33 return | 34 return |
34 field.form_control_type == "text" || | 35 field.form_control_type == "text" || |
35 field.form_control_type == "search" || | 36 field.form_control_type == "search" || |
36 field.form_control_type == "tel" || | 37 field.form_control_type == "tel" || |
37 field.form_control_type == "url" || | 38 field.form_control_type == "url" || |
38 field.form_control_type == "email" || | 39 field.form_control_type == "email" || |
39 field.form_control_type == "text"; | 40 field.form_control_type == "text"; |
40 } | 41 } |
41 | 42 |
42 } // namespace | 43 } // namespace |
43 | 44 |
44 AutocompleteHistoryManager::AutocompleteHistoryManager( | 45 AutocompleteHistoryManager::AutocompleteHistoryManager( |
45 WebContents* web_contents) | 46 WebContents* web_contents) |
46 : content::WebContentsObserver(web_contents), | 47 : browser_context_(web_contents->GetBrowserContext()), |
47 browser_context_(web_contents->GetBrowserContext()), | 48 web_contents_(web_contents), |
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), |
54 send_IPC_(true) { | |
53 autofill_enabled_.Init( | 55 autofill_enabled_.Init( |
54 prefs::kAutofillEnabled, | 56 prefs::kAutofillEnabled, |
55 components::UserPrefs::Get(browser_context_)); | 57 components::UserPrefs::Get(browser_context_)); |
56 } | 58 } |
57 | 59 |
58 AutocompleteHistoryManager::~AutocompleteHistoryManager() { | 60 AutocompleteHistoryManager::~AutocompleteHistoryManager() { |
59 CancelPendingQuery(); | 61 CancelPendingQuery(); |
60 } | 62 } |
61 | 63 |
62 bool AutocompleteHistoryManager::OnMessageReceived( | |
63 const IPC::Message& message) { | |
64 bool handled = true; | |
65 IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message) | |
66 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry, | |
blundell
2013/06/04 17:30:48
I moved the reception of this message into Autofil
Evan Stade
2013/06/04 18:06:36
Ilya would know for sure but my guess is that it's
Ilya Sherman
2013/06/05 10:50:02
Yes, Evan is correct -- this IPC message would onl
blundell
2013/06/11 15:35:47
Are you saying (a) that it's OK to just not handle
Ilya Sherman
2013/06/12 00:07:46
(b), though not all of autofill_agent will be goin
| |
67 OnRemoveAutocompleteEntry) | |
68 IPC_MESSAGE_UNHANDLED(handled = false) | |
69 IPC_END_MESSAGE_MAP() | |
70 return handled; | |
71 } | |
72 | |
73 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( | 64 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( |
74 WebDataServiceBase::Handle h, | 65 WebDataServiceBase::Handle h, |
75 const WDTypedResult* result) { | 66 const WDTypedResult* result) { |
76 DCHECK(pending_query_handle_); | 67 DCHECK(pending_query_handle_); |
77 pending_query_handle_ = 0; | 68 pending_query_handle_ = 0; |
78 | 69 |
79 if (!*autofill_enabled_) { | 70 if (!*autofill_enabled_) { |
80 SendSuggestions(NULL); | 71 SendSuggestions(NULL); |
81 return; | 72 return; |
82 } | 73 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 } | 190 } |
200 } | 191 } |
201 | 192 |
202 if (external_delegate_) { | 193 if (external_delegate_) { |
203 external_delegate_->OnSuggestionsReturned( | 194 external_delegate_->OnSuggestionsReturned( |
204 query_id_, | 195 query_id_, |
205 autofill_values_, | 196 autofill_values_, |
206 autofill_labels_, | 197 autofill_labels_, |
207 autofill_icons_, | 198 autofill_icons_, |
208 autofill_unique_ids_); | 199 autofill_unique_ids_); |
209 } else { | 200 } else if (send_IPC_) { |
blundell
2013/06/04 17:30:48
This change is to preserve the behavior of the Ext
| |
210 Send(new AutofillMsg_SuggestionsReturned(routing_id(), | 201 web_contents_->Send( |
211 query_id_, | 202 new AutofillMsg_SuggestionsReturned(web_contents_->GetRoutingID(), |
212 autofill_values_, | 203 query_id_, |
213 autofill_labels_, | 204 autofill_values_, |
214 autofill_icons_, | 205 autofill_labels_, |
215 autofill_unique_ids_)); | 206 autofill_icons_, |
207 autofill_unique_ids_)); | |
216 } | 208 } |
217 | 209 |
218 query_id_ = 0; | 210 query_id_ = 0; |
219 autofill_values_.clear(); | 211 autofill_values_.clear(); |
220 autofill_labels_.clear(); | 212 autofill_labels_.clear(); |
221 autofill_icons_.clear(); | 213 autofill_icons_.clear(); |
222 autofill_unique_ids_.clear(); | 214 autofill_unique_ids_.clear(); |
223 } | 215 } |
224 | 216 |
225 } // namespace autofill | 217 } // namespace autofill |
OLD | NEW |