| 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" | |
| 10 #include "chrome/common/autofill_messages.h" | 9 #include "chrome/common/autofill_messages.h" |
| 11 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
| 12 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
| 13 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
| 15 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 16 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | |
| 19 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 23 | 21 |
| 24 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
| 25 #include "content/public/browser/android/content_view_core.h" | 23 #include "content/public/browser/android/content_view_core.h" |
| 26 #endif | 24 #endif |
| 27 | 25 |
| 28 using content::RenderViewHost; | 26 using content::RenderViewHost; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 57 registrar_.Add(this, | 55 registrar_.Add(this, |
| 58 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 56 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 59 content::Source<content::WebContents>(web_contents)); | 57 content::Source<content::WebContents>(web_contents)); |
| 60 registrar_.Add( | 58 registrar_.Add( |
| 61 this, | 59 this, |
| 62 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 60 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 63 content::Source<content::NavigationController>( | 61 content::Source<content::NavigationController>( |
| 64 &(web_contents->GetController()))); | 62 &(web_contents->GetController()))); |
| 65 } | 63 } |
| 66 | 64 |
| 67 AutofillExternalDelegate::~AutofillExternalDelegate() { | 65 AutofillExternalDelegate::~AutofillExternalDelegate() {} |
| 68 if (controller_) | |
| 69 controller_->Hide(); | |
| 70 } | |
| 71 | 66 |
| 72 void AutofillExternalDelegate::OnQuery(int query_id, | 67 void AutofillExternalDelegate::OnQuery(int query_id, |
| 73 const FormData& form, | 68 const FormData& form, |
| 74 const FormFieldData& field, | 69 const FormFieldData& field, |
| 75 const gfx::RectF& element_bounds, | 70 const gfx::RectF& element_bounds, |
| 76 bool display_warning_if_disabled) { | 71 bool display_warning_if_disabled) { |
| 77 autofill_query_form_ = form; | 72 autofill_query_form_ = form; |
| 78 autofill_query_field_ = field; | 73 autofill_query_field_ = field; |
| 79 display_warning_if_disabled_ = display_warning_if_disabled; | 74 display_warning_if_disabled_ = display_warning_if_disabled; |
| 80 autofill_query_id_ = query_id; | 75 autofill_query_id_ = query_id; |
| 81 | 76 element_bounds_ = element_bounds; |
| 82 EnsurePopupForElement(element_bounds); | |
| 83 } | 77 } |
| 84 | 78 |
| 85 void AutofillExternalDelegate::OnSuggestionsReturned( | 79 void AutofillExternalDelegate::OnSuggestionsReturned( |
| 86 int query_id, | 80 int query_id, |
| 87 const std::vector<string16>& autofill_values, | 81 const std::vector<string16>& autofill_values, |
| 88 const std::vector<string16>& autofill_labels, | 82 const std::vector<string16>& autofill_labels, |
| 89 const std::vector<string16>& autofill_icons, | 83 const std::vector<string16>& autofill_icons, |
| 90 const std::vector<int>& autofill_unique_ids) { | 84 const std::vector<int>& autofill_unique_ids) { |
| 91 if (query_id != autofill_query_id_ || !controller_) | 85 if (query_id != autofill_query_id_) |
| 92 return; | 86 return; |
| 93 | 87 |
| 94 std::vector<string16> values(autofill_values); | 88 std::vector<string16> values(autofill_values); |
| 95 std::vector<string16> labels(autofill_labels); | 89 std::vector<string16> labels(autofill_labels); |
| 96 std::vector<string16> icons(autofill_icons); | 90 std::vector<string16> icons(autofill_icons); |
| 97 std::vector<int> ids(autofill_unique_ids); | 91 std::vector<int> ids(autofill_unique_ids); |
| 98 | 92 |
| 99 // Add a separator to go between the values and menu items. | 93 // Add a separator to go between the values and menu items. |
| 100 values.push_back(string16()); | 94 values.push_back(string16()); |
| 101 labels.push_back(string16()); | 95 labels.push_back(string16()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 127 | 121 |
| 128 InsertDataListValues(&values, &labels, &icons, &ids); | 122 InsertDataListValues(&values, &labels, &icons, &ids); |
| 129 | 123 |
| 130 if (values.empty()) { | 124 if (values.empty()) { |
| 131 // No suggestions, any popup currently showing is obsolete. | 125 // No suggestions, any popup currently showing is obsolete. |
| 132 HideAutofillPopup(); | 126 HideAutofillPopup(); |
| 133 return; | 127 return; |
| 134 } | 128 } |
| 135 | 129 |
| 136 // Send to display. | 130 // Send to display. |
| 137 if (autofill_query_field_.is_focusable) | 131 if (autofill_query_field_.is_focusable) { |
| 138 ApplyAutofillSuggestions(values, labels, icons, ids); | 132 autofill_manager_->delegate()->ShowAutofillPopup( |
| 133 element_bounds_, values, labels, icons, ids, this); |
| 134 } |
| 139 } | 135 } |
| 140 | 136 |
| 141 void AutofillExternalDelegate::OnShowPasswordSuggestions( | 137 void AutofillExternalDelegate::OnShowPasswordSuggestions( |
| 142 const std::vector<string16>& suggestions, | 138 const std::vector<string16>& suggestions, |
| 143 const FormFieldData& field, | 139 const FormFieldData& field, |
| 144 const gfx::RectF& element_bounds) { | 140 const gfx::RectF& element_bounds) { |
| 145 autofill_query_field_ = field; | 141 autofill_query_field_ = field; |
| 146 EnsurePopupForElement(element_bounds); | 142 element_bounds_ = element_bounds; |
| 147 | 143 |
| 148 if (suggestions.empty()) { | 144 if (suggestions.empty()) { |
| 149 HideAutofillPopup(); | 145 HideAutofillPopup(); |
| 150 return; | 146 return; |
| 151 } | 147 } |
| 152 | 148 |
| 153 std::vector<string16> empty(suggestions.size()); | 149 std::vector<string16> empty(suggestions.size()); |
| 154 std::vector<int> password_ids(suggestions.size(), | 150 std::vector<int> password_ids(suggestions.size(), |
| 155 WebAutofillClient::MenuItemIDPasswordEntry); | 151 WebAutofillClient::MenuItemIDPasswordEntry); |
| 156 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids); | 152 autofill_manager_->delegate()->ShowAutofillPopup( |
| 157 } | 153 element_bounds_, suggestions, empty, empty, password_ids, this); |
| 158 | |
| 159 void AutofillExternalDelegate::EnsurePopupForElement( | |
| 160 const gfx::RectF& element_bounds) { | |
| 161 // Convert element_bounds to be in screen space. | |
| 162 gfx::Rect client_area; | |
| 163 web_contents_->GetContainerBounds(&client_area); | |
| 164 gfx::RectF element_bounds_in_screen_space = | |
| 165 element_bounds + client_area.OffsetFromOrigin(); | |
| 166 | |
| 167 // |controller_| owns itself. | |
| 168 controller_ = AutofillPopupControllerImpl::GetOrCreate( | |
| 169 controller_, | |
| 170 this, | |
| 171 web_contents()->GetView()->GetContentNativeView(), | |
| 172 element_bounds_in_screen_space); | |
| 173 } | |
| 174 | |
| 175 void AutofillExternalDelegate::ApplyAutofillSuggestions( | |
| 176 const std::vector<string16>& autofill_values, | |
| 177 const std::vector<string16>& autofill_labels, | |
| 178 const std::vector<string16>& autofill_icons, | |
| 179 const std::vector<int>& autofill_unique_ids) { | |
| 180 controller_->Show(autofill_values, | |
| 181 autofill_labels, | |
| 182 autofill_icons, | |
| 183 autofill_unique_ids); | |
| 184 } | 154 } |
| 185 | 155 |
| 186 void AutofillExternalDelegate::SetCurrentDataListValues( | 156 void AutofillExternalDelegate::SetCurrentDataListValues( |
| 187 const std::vector<string16>& data_list_values, | 157 const std::vector<string16>& data_list_values, |
| 188 const std::vector<string16>& data_list_labels, | 158 const std::vector<string16>& data_list_labels, |
| 189 const std::vector<string16>& data_list_icons, | 159 const std::vector<string16>& data_list_icons, |
| 190 const std::vector<int>& data_list_unique_ids) { | 160 const std::vector<int>& data_list_unique_ids) { |
| 191 data_list_values_ = data_list_values; | 161 data_list_values_ = data_list_values; |
| 192 data_list_labels_ = data_list_labels; | 162 data_list_labels_ = data_list_labels; |
| 193 data_list_icons_ = data_list_icons; | 163 data_list_icons_ = data_list_icons; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 has_shown_autofill_popup_for_current_edit_ = false; | 236 has_shown_autofill_popup_for_current_edit_ = false; |
| 267 } | 237 } |
| 268 | 238 |
| 269 void AutofillExternalDelegate::ClearPreviewedForm() { | 239 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 270 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 240 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 271 if (host) | 241 if (host) |
| 272 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 242 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
| 273 } | 243 } |
| 274 | 244 |
| 275 void AutofillExternalDelegate::HideAutofillPopup() { | 245 void AutofillExternalDelegate::HideAutofillPopup() { |
| 276 if (controller_) | 246 autofill_manager_->delegate()->HideAutofillPopup(); |
| 277 controller_->Hide(); | |
| 278 } | 247 } |
| 279 | 248 |
| 280 void AutofillExternalDelegate::Reset() { | 249 void AutofillExternalDelegate::Reset() { |
| 281 HideAutofillPopup(); | 250 HideAutofillPopup(); |
| 282 | 251 |
| 283 password_autofill_manager_.Reset(); | 252 password_autofill_manager_.Reset(); |
| 284 } | 253 } |
| 285 | 254 |
| 286 void AutofillExternalDelegate::AddPasswordFormMapping( | 255 void AutofillExternalDelegate::AddPasswordFormMapping( |
| 287 const FormFieldData& form, | 256 const FormFieldData& form, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 const content::NotificationDetails& details) { | 378 const content::NotificationDetails& details) { |
| 410 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { | 379 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
| 411 if (!*content::Details<bool>(details).ptr()) | 380 if (!*content::Details<bool>(details).ptr()) |
| 412 HideAutofillPopup(); | 381 HideAutofillPopup(); |
| 413 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 382 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
| 414 HideAutofillPopup(); | 383 HideAutofillPopup(); |
| 415 } else { | 384 } else { |
| 416 NOTREACHED(); | 385 NOTREACHED(); |
| 417 } | 386 } |
| 418 } | 387 } |
| OLD | NEW |