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