OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/autofill_external_delegate.h" | 5 #include "components/autofill/core/browser/autofill_external_delegate.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 8 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
9 #include "components/autofill/core/browser/autofill_driver.h" | 9 #include "components/autofill/core/browser/autofill_driver.h" |
10 #include "components/autofill/core/browser/autofill_manager.h" | 10 #include "components/autofill/core/browser/autofill_manager.h" |
11 #include "components/autofill/core/common/autofill_messages.h" | |
12 #include "content/public/browser/render_view_host.h" | |
13 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
14 #include "grit/component_strings.h" | 12 #include "grit/component_strings.h" |
15 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 13 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
16 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
17 | 15 |
18 using content::RenderViewHost; | |
19 using blink::WebAutofillClient; | 16 using blink::WebAutofillClient; |
20 | 17 |
21 namespace autofill { | 18 namespace autofill { |
22 | 19 |
23 AutofillExternalDelegate::AutofillExternalDelegate( | 20 AutofillExternalDelegate::AutofillExternalDelegate( |
24 content::WebContents* web_contents, | 21 content::WebContents* web_contents, |
25 AutofillManager* autofill_manager, | 22 AutofillManager* autofill_manager, |
26 AutofillDriver* autofill_driver) | 23 AutofillDriver* autofill_driver) |
27 : web_contents_(web_contents), | 24 : autofill_manager_(autofill_manager), |
28 autofill_manager_(autofill_manager), | |
29 autofill_driver_(autofill_driver), | 25 autofill_driver_(autofill_driver), |
30 password_autofill_manager_(web_contents), | 26 password_autofill_manager_(web_contents), |
31 autofill_query_id_(0), | 27 autofill_query_id_(0), |
32 display_warning_if_disabled_(false), | 28 display_warning_if_disabled_(false), |
33 has_autofill_suggestion_(false), | 29 has_autofill_suggestion_(false), |
34 has_shown_autofill_popup_for_current_edit_(false), | 30 has_shown_autofill_popup_for_current_edit_(false), |
35 weak_ptr_factory_(this) { | 31 weak_ptr_factory_(this) { |
36 DCHECK(autofill_manager); | 32 DCHECK(autofill_manager); |
37 } | 33 } |
38 | 34 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { | 169 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { |
174 ClearPreviewedForm(); | 170 ClearPreviewedForm(); |
175 | 171 |
176 // Only preview the data if it is a profile. | 172 // Only preview the data if it is a profile. |
177 if (identifier > 0) | 173 if (identifier > 0) |
178 FillAutofillFormData(identifier, true); | 174 FillAutofillFormData(identifier, true); |
179 } | 175 } |
180 | 176 |
181 void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value, | 177 void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value, |
182 int identifier) { | 178 int identifier) { |
183 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
184 | |
185 if (identifier == WebAutofillClient::MenuItemIDAutofillOptions) { | 179 if (identifier == WebAutofillClient::MenuItemIDAutofillOptions) { |
186 // User selected 'Autofill Options'. | 180 // User selected 'Autofill Options'. |
187 autofill_manager_->OnShowAutofillDialog(); | 181 autofill_manager_->OnShowAutofillDialog(); |
188 } else if (identifier == WebAutofillClient::MenuItemIDClearForm) { | 182 } else if (identifier == WebAutofillClient::MenuItemIDClearForm) { |
189 // User selected 'Clear form'. | 183 // User selected 'Clear form'. |
190 autofill_driver_->RendererShouldClearFilledForm(); | 184 autofill_driver_->RendererShouldClearFilledForm(); |
191 } else if (identifier == WebAutofillClient::MenuItemIDPasswordEntry) { | 185 } else if (identifier == WebAutofillClient::MenuItemIDPasswordEntry) { |
192 bool success = password_autofill_manager_.DidAcceptAutofillSuggestion( | 186 bool success = password_autofill_manager_.DidAcceptAutofillSuggestion( |
193 autofill_query_field_, value); | 187 autofill_query_field_, value); |
194 DCHECK(success); | 188 DCHECK(success); |
195 } else if (identifier == WebAutofillClient::MenuItemIDDataListEntry) { | 189 } else if (identifier == WebAutofillClient::MenuItemIDDataListEntry) { |
196 autofill_driver_->RendererShouldAcceptDataListSuggestion(value); | 190 autofill_driver_->RendererShouldAcceptDataListSuggestion(value); |
197 } else if (identifier == WebAutofillClient::MenuItemIDAutocompleteEntry) { | 191 } else if (identifier == WebAutofillClient::MenuItemIDAutocompleteEntry) { |
198 // User selected an Autocomplete, so we fill directly. | 192 // User selected an Autocomplete, so we fill directly. |
199 host->Send(new AutofillMsg_SetNodeText(host->GetRoutingID(), value)); | 193 autofill_driver_->RendererShouldSetNodeText(value); |
200 } else { | 194 } else { |
201 FillAutofillFormData(identifier, false); | 195 FillAutofillFormData(identifier, false); |
202 } | 196 } |
203 | 197 |
204 autofill_manager_->delegate()->HideAutofillPopup(); | 198 autofill_manager_->delegate()->HideAutofillPopup(); |
205 } | 199 } |
206 | 200 |
207 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, | 201 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, |
208 int identifier) { | 202 int identifier) { |
209 if (identifier > 0) { | 203 if (identifier > 0) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // Set the values that all datalist elements share. | 351 // Set the values that all datalist elements share. |
358 autofill_icons->insert(autofill_icons->begin(), | 352 autofill_icons->insert(autofill_icons->begin(), |
359 data_list_values_.size(), | 353 data_list_values_.size(), |
360 base::string16()); | 354 base::string16()); |
361 autofill_unique_ids->insert(autofill_unique_ids->begin(), | 355 autofill_unique_ids->insert(autofill_unique_ids->begin(), |
362 data_list_values_.size(), | 356 data_list_values_.size(), |
363 WebAutofillClient::MenuItemIDDataListEntry); | 357 WebAutofillClient::MenuItemIDDataListEntry); |
364 } | 358 } |
365 | 359 |
366 } // namespace autofill | 360 } // namespace autofill |
OLD | NEW |