| 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 6 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
| 7 #include "chrome/browser/autofill/autofill_external_delegate.h" | 7 #include "chrome/browser/autofill/autofill_external_delegate.h" |
| 8 #include "chrome/browser/autofill/autofill_manager.h" | 8 #include "chrome/browser/autofill/autofill_manager.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
| 10 #include "chrome/common/autofill_messages.h" | 10 #include "chrome/common/autofill_messages.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 AutofillExternalDelegate::AutofillExternalDelegate( | 44 AutofillExternalDelegate::AutofillExternalDelegate( |
| 45 content::WebContents* web_contents, | 45 content::WebContents* web_contents, |
| 46 AutofillManager* autofill_manager) | 46 AutofillManager* autofill_manager) |
| 47 : web_contents_(web_contents), | 47 : web_contents_(web_contents), |
| 48 autofill_manager_(autofill_manager), | 48 autofill_manager_(autofill_manager), |
| 49 password_autofill_manager_(web_contents), | 49 password_autofill_manager_(web_contents), |
| 50 autofill_query_id_(0), | 50 autofill_query_id_(0), |
| 51 display_warning_if_disabled_(false), | 51 display_warning_if_disabled_(false), |
| 52 has_shown_autofill_popup_for_current_edit_(false) { | 52 has_shown_autofill_popup_for_current_edit_(false), |
| 53 registered_keyboard_listener_with_(NULL) { |
| 53 registrar_.Add(this, | 54 registrar_.Add(this, |
| 54 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 55 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 55 content::Source<content::WebContents>(web_contents)); | 56 content::Source<content::WebContents>(web_contents)); |
| 56 if (web_contents) { | 57 if (web_contents) { |
| 57 registrar_.Add( | 58 registrar_.Add( |
| 58 this, | 59 this, |
| 59 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 60 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 60 content::Source<content::NavigationController>( | 61 content::Source<content::NavigationController>( |
| 61 &(web_contents->GetController()))); | 62 &(web_contents->GetController()))); |
| 62 } | 63 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 const std::vector<string16>& data_list_icons, | 200 const std::vector<string16>& data_list_icons, |
| 200 const std::vector<int>& data_list_unique_ids) { | 201 const std::vector<int>& data_list_unique_ids) { |
| 201 data_list_values_ = data_list_values; | 202 data_list_values_ = data_list_values; |
| 202 data_list_labels_ = data_list_labels; | 203 data_list_labels_ = data_list_labels; |
| 203 data_list_icons_ = data_list_icons; | 204 data_list_icons_ = data_list_icons; |
| 204 data_list_unique_ids_ = data_list_unique_ids; | 205 data_list_unique_ids_ = data_list_unique_ids; |
| 205 } | 206 } |
| 206 | 207 |
| 207 void AutofillExternalDelegate::OnPopupShown( | 208 void AutofillExternalDelegate::OnPopupShown( |
| 208 content::KeyboardListener* listener) { | 209 content::KeyboardListener* listener) { |
| 209 if (web_contents_) | 210 if (web_contents_ && !registered_keyboard_listener_with_) { |
| 210 web_contents_->GetRenderViewHost()->AddKeyboardListener(listener); | 211 registered_keyboard_listener_with_ = web_contents_->GetRenderViewHost(); |
| 212 registered_keyboard_listener_with_->AddKeyboardListener(listener); |
| 213 } |
| 211 } | 214 } |
| 212 | 215 |
| 213 void AutofillExternalDelegate::OnPopupHidden( | 216 void AutofillExternalDelegate::OnPopupHidden( |
| 214 content::KeyboardListener* listener) { | 217 content::KeyboardListener* listener) { |
| 215 if (web_contents_) | 218 if (web_contents_ && registered_keyboard_listener_with_ == |
| 219 web_contents_->GetRenderViewHost()) |
| 216 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(listener); | 220 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(listener); |
| 221 |
| 222 registered_keyboard_listener_with_ = NULL; |
| 217 } | 223 } |
| 218 | 224 |
| 219 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { | 225 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { |
| 220 ClearPreviewedForm(); | 226 ClearPreviewedForm(); |
| 221 | 227 |
| 222 // Only preview the data if it is a profile. | 228 // Only preview the data if it is a profile. |
| 223 if (identifier > 0) | 229 if (identifier > 0) |
| 224 FillAutofillFormData(identifier, true); | 230 FillAutofillFormData(identifier, true); |
| 225 } | 231 } |
| 226 | 232 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 void AutofillExternalDelegate::ClearPreviewedForm() { | 277 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 272 if (web_contents_) { | 278 if (web_contents_) { |
| 273 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 279 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 274 | 280 |
| 275 if (host) | 281 if (host) |
| 276 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 282 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
| 277 } | 283 } |
| 278 } | 284 } |
| 279 | 285 |
| 280 void AutofillExternalDelegate::HideAutofillPopup() { | 286 void AutofillExternalDelegate::HideAutofillPopup() { |
| 281 if (controller_) { | 287 if (controller_) |
| 282 controller_->Hide(); | 288 controller_->Hide(); |
| 283 OnPopupHidden(controller_.get()); | |
| 284 } | |
| 285 } | 289 } |
| 286 | 290 |
| 287 void AutofillExternalDelegate::Reset() { | 291 void AutofillExternalDelegate::Reset() { |
| 288 HideAutofillPopup(); | 292 HideAutofillPopup(); |
| 289 | 293 |
| 290 password_autofill_manager_.Reset(); | 294 password_autofill_manager_.Reset(); |
| 291 } | 295 } |
| 292 | 296 |
| 293 void AutofillExternalDelegate::AddPasswordFormMapping( | 297 void AutofillExternalDelegate::AddPasswordFormMapping( |
| 294 const FormFieldData& form, | 298 const FormFieldData& form, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 const content::NotificationDetails& details) { | 420 const content::NotificationDetails& details) { |
| 417 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { | 421 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
| 418 if (!*content::Details<bool>(details).ptr()) | 422 if (!*content::Details<bool>(details).ptr()) |
| 419 HideAutofillPopup(); | 423 HideAutofillPopup(); |
| 420 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 424 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
| 421 HideAutofillPopup(); | 425 HideAutofillPopup(); |
| 422 } else { | 426 } else { |
| 423 NOTREACHED(); | 427 NOTREACHED(); |
| 424 } | 428 } |
| 425 } | 429 } |
| OLD | NEW |