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_external_delegate.h" | 13 #include "components/autofill/browser/autofill_external_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 "components/user_prefs/user_prefs.h" |
18 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "ipc/ipc_message_macros.h" | |
21 | 23 |
22 using content::BrowserContext; | 24 using content::BrowserContext; |
23 using content::WebContents; | 25 using content::WebContents; |
24 | 26 |
25 namespace autofill { | 27 namespace autofill { |
26 namespace { | 28 namespace { |
27 | 29 |
28 // 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 |
29 // text input element in a form. | 31 // text input element in a form. |
30 const int kMaxAutocompleteMenuItems = 6; | 32 const int kMaxAutocompleteMenuItems = 6; |
31 | 33 |
32 bool IsTextField(const FormFieldData& field) { | 34 bool IsTextField(const FormFieldData& field) { |
33 return | 35 return |
34 field.form_control_type == "text" || | 36 field.form_control_type == "text" || |
35 field.form_control_type == "search" || | 37 field.form_control_type == "search" || |
36 field.form_control_type == "tel" || | 38 field.form_control_type == "tel" || |
37 field.form_control_type == "url" || | 39 field.form_control_type == "url" || |
38 field.form_control_type == "email" || | 40 field.form_control_type == "email" || |
39 field.form_control_type == "text"; | 41 field.form_control_type == "text"; |
40 } | 42 } |
41 | 43 |
42 } // namespace | 44 } // namespace |
43 | 45 |
44 AutocompleteHistoryManager::AutocompleteHistoryManager( | 46 AutocompleteHistoryManager::AutocompleteHistoryManager( |
45 WebContents* web_contents) | 47 AutofillDriver* driver) |
Ilya Sherman
2013/06/12 00:07:46
nit: Looks like this fits on the previous line.
blundell
2013/06/12 16:29:37
Done.
| |
46 : content::WebContentsObserver(web_contents), | 48 : browser_context_(driver->GetWebContents()->GetBrowserContext()), |
47 browser_context_(web_contents->GetBrowserContext()), | 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 send_IPC_(true) { | |
53 autofill_enabled_.Init( | 56 autofill_enabled_.Init( |
54 prefs::kAutofillEnabled, | 57 prefs::kAutofillEnabled, |
55 user_prefs::UserPrefs::Get(browser_context_)); | 58 user_prefs::UserPrefs::Get(browser_context_)); |
56 } | 59 } |
57 | 60 |
58 AutocompleteHistoryManager::~AutocompleteHistoryManager() { | 61 AutocompleteHistoryManager::~AutocompleteHistoryManager() { |
59 CancelPendingQuery(); | 62 CancelPendingQuery(); |
60 } | 63 } |
61 | 64 |
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, | |
67 OnRemoveAutocompleteEntry) | |
68 IPC_MESSAGE_UNHANDLED(handled = false) | |
69 IPC_END_MESSAGE_MAP() | |
70 return handled; | |
71 } | |
72 | |
73 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( | 65 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( |
74 WebDataServiceBase::Handle h, | 66 WebDataServiceBase::Handle h, |
75 const WDTypedResult* result) { | 67 const WDTypedResult* result) { |
76 DCHECK(pending_query_handle_); | 68 DCHECK(pending_query_handle_); |
77 pending_query_handle_ = 0; | 69 pending_query_handle_ = 0; |
78 | 70 |
79 if (!*autofill_enabled_) { | 71 if (!*autofill_enabled_) { |
80 SendSuggestions(NULL); | 72 SendSuggestions(NULL); |
81 return; | 73 return; |
82 } | 74 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 } | 192 } |
201 | 193 |
202 if (external_delegate_) { | 194 if (external_delegate_) { |
203 external_delegate_->OnSuggestionsReturned( | 195 external_delegate_->OnSuggestionsReturned( |
204 query_id_, | 196 query_id_, |
205 autofill_values_, | 197 autofill_values_, |
206 autofill_labels_, | 198 autofill_labels_, |
207 autofill_icons_, | 199 autofill_icons_, |
208 autofill_unique_ids_); | 200 autofill_unique_ids_); |
209 } else { | 201 } else { |
210 Send(new AutofillMsg_SuggestionsReturned(routing_id(), | 202 WebContents* web_contents = driver_->GetWebContents(); |
211 query_id_, | 203 if (web_contents) { |
blundell
2013/06/12 16:29:37
This is where send_ipc_ should have been used (and
| |
212 autofill_values_, | 204 web_contents->Send( |
213 autofill_labels_, | 205 new AutofillMsg_SuggestionsReturned(web_contents->GetRoutingID(), |
214 autofill_icons_, | 206 query_id_, |
215 autofill_unique_ids_)); | 207 autofill_values_, |
208 autofill_labels_, | |
209 autofill_icons_, | |
210 autofill_unique_ids_)); | |
211 } | |
216 } | 212 } |
217 | 213 |
218 query_id_ = 0; | 214 query_id_ = 0; |
219 autofill_values_.clear(); | 215 autofill_values_.clear(); |
220 autofill_labels_.clear(); | 216 autofill_labels_.clear(); |
221 autofill_icons_.clear(); | 217 autofill_icons_.clear(); |
222 autofill_unique_ids_.clear(); | 218 autofill_unique_ids_.clear(); |
223 } | 219 } |
224 | 220 |
225 } // namespace autofill | 221 } // namespace autofill |
OLD | NEW |