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(AutofillDriver* driver) |
45 WebContents* web_contents) | 47 : browser_context_(driver->GetWebContents()->GetBrowserContext()), |
46 : content::WebContentsObserver(web_contents), | 48 driver_(driver), |
47 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), |
| 54 send_ipc_(true) { |
53 autofill_enabled_.Init( | 55 autofill_enabled_.Init( |
54 prefs::kAutofillEnabled, | 56 prefs::kAutofillEnabled, |
55 user_prefs::UserPrefs::Get(browser_context_)); | 57 user_prefs::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, | |
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 { |
210 Send(new AutofillMsg_SuggestionsReturned(routing_id(), | 201 WebContents* web_contents = driver_->GetWebContents(); |
211 query_id_, | 202 if (web_contents && send_ipc_) { |
212 autofill_values_, | 203 web_contents->Send( |
213 autofill_labels_, | 204 new AutofillMsg_SuggestionsReturned(web_contents->GetRoutingID(), |
214 autofill_icons_, | 205 query_id_, |
215 autofill_unique_ids_)); | 206 autofill_values_, |
| 207 autofill_labels_, |
| 208 autofill_icons_, |
| 209 autofill_unique_ids_)); |
| 210 } |
216 } | 211 } |
217 | 212 |
218 query_id_ = 0; | 213 query_id_ = 0; |
219 autofill_values_.clear(); | 214 autofill_values_.clear(); |
220 autofill_labels_.clear(); | 215 autofill_labels_.clear(); |
221 autofill_icons_.clear(); | 216 autofill_icons_.clear(); |
222 autofill_unique_ids_.clear(); | 217 autofill_unique_ids_.clear(); |
223 } | 218 } |
224 | 219 |
225 } // namespace autofill | 220 } // namespace autofill |
OLD | NEW |