| 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/autofill_external_delegate.h" | 6 #include "chrome/browser/autofill/autofill_external_delegate.h" |
| 7 #include "chrome/browser/autofill/autofill_manager.h" | 7 #include "chrome/browser/autofill/autofill_manager.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 9 #include "chrome/common/autofill_messages.h" | 9 #include "chrome/common/autofill_messages.h" |
| 10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
| 11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "grit/chromium_strings.h" | 13 #include "grit/chromium_strings.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 | 16 |
| 17 using content::RenderViewHost; | 17 using content::RenderViewHost; |
| 18 | 18 |
| 19 AutofillExternalDelegate::~AutofillExternalDelegate() { | 19 AutofillExternalDelegate::~AutofillExternalDelegate() { |
| 20 } | 20 } |
| 21 | 21 |
| 22 AutofillExternalDelegate::AutofillExternalDelegate( | 22 AutofillExternalDelegate::AutofillExternalDelegate( |
| 23 TabContentsWrapper* tab_contents_wrapper, | 23 TabContentsWrapper* tab_contents_wrapper, |
| 24 AutofillManager* autofill_manager) | 24 AutofillManager* autofill_manager) |
| 25 : tab_contents_wrapper_(tab_contents_wrapper), | 25 : tab_contents_wrapper_(tab_contents_wrapper), |
| 26 autofill_manager_(autofill_manager), | 26 autofill_manager_(autofill_manager), |
| 27 password_autofill_manager_( |
| 28 tab_contents_wrapper->web_contents()->GetRenderViewHost()), |
| 27 autofill_query_id_(0), | 29 autofill_query_id_(0), |
| 28 display_warning_if_disabled_(false), | 30 display_warning_if_disabled_(false), |
| 29 has_shown_autofill_popup_for_current_edit_(false), | 31 has_shown_autofill_popup_for_current_edit_(false), |
| 30 suggestions_clear_index_(-1), | 32 suggestions_clear_index_(-1), |
| 31 suggestions_options_index_(-1) { | 33 suggestions_options_index_(-1) { |
| 32 } | 34 } |
| 33 | 35 |
| 34 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, | 36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, |
| 35 int list_index) { | 37 int list_index) { |
| 38 if (password_autofill_manager_.DidSelectAutofillSuggestion( |
| 39 autofill_query_field_)) |
| 40 return; |
| 41 |
| 36 if (list_index == suggestions_options_index_ || | 42 if (list_index == suggestions_options_index_ || |
| 37 list_index == suggestions_clear_index_ || | 43 list_index == suggestions_clear_index_ || |
| 38 unique_id == -1) | 44 unique_id == -1) |
| 39 return; | 45 return; |
| 40 | 46 |
| 41 FillAutofillFormData(unique_id, true); | 47 FillAutofillFormData(unique_id, true); |
| 42 } | 48 } |
| 43 | 49 |
| 44 void AutofillExternalDelegate::OnQuery(int query_id, | 50 void AutofillExternalDelegate::OnQuery(int query_id, |
| 45 const webkit::forms::FormData& form, | 51 const webkit::forms::FormData& form, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 147 } |
| 142 | 148 |
| 143 void AutofillExternalDelegate::DidAcceptAutofillSuggestions( | 149 void AutofillExternalDelegate::DidAcceptAutofillSuggestions( |
| 144 const string16& value, | 150 const string16& value, |
| 145 int unique_id, | 151 int unique_id, |
| 146 unsigned index) { | 152 unsigned index) { |
| 147 // If the selected element is a warning we don't want to do anything. | 153 // If the selected element is a warning we don't want to do anything. |
| 148 if (unique_id < 0) | 154 if (unique_id < 0) |
| 149 return; | 155 return; |
| 150 | 156 |
| 151 // TODO(csharp): Add the password autofill manager. | 157 HideAutofillPopup(); |
| 152 // if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) | 158 |
| 153 // return; | 159 if (password_autofill_manager_.DidAcceptAutofillSuggestion( |
| 160 autofill_query_field_, value)) { |
| 161 // Accepting has been handled by the password manager. |
| 162 return; |
| 163 } |
| 154 | 164 |
| 155 if (suggestions_options_index_ != -1 && | 165 if (suggestions_options_index_ != -1 && |
| 156 index == static_cast<unsigned>(suggestions_options_index_)) { | 166 index == static_cast<unsigned>(suggestions_options_index_)) { |
| 157 // User selected 'Autofill Options'. | 167 // User selected 'Autofill Options'. |
| 158 autofill_manager_->OnShowAutofillDialog(); | 168 autofill_manager_->OnShowAutofillDialog(); |
| 159 } else if (suggestions_clear_index_ != -1 && | 169 } else if (suggestions_clear_index_ != -1 && |
| 160 index == static_cast<unsigned>(suggestions_clear_index_)) { | 170 index == static_cast<unsigned>(suggestions_clear_index_)) { |
| 161 // User selected 'Clear form'. | 171 // User selected 'Clear form'. |
| 162 RenderViewHost* host = | 172 RenderViewHost* host = |
| 163 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 173 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| 164 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); | 174 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); |
| 165 } else if (!unique_id) { | 175 } else if (!unique_id) { |
| 166 // User selected an Autocomplete entry, so we fill directly. | 176 // User selected an Autocomplete entry, so we fill directly. |
| 167 RenderViewHost* host = | 177 RenderViewHost* host = |
| 168 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 178 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| 169 host->Send(new AutofillMsg_SetNodeText( | 179 host->Send(new AutofillMsg_SetNodeText( |
| 170 host->GetRoutingID(), | 180 host->GetRoutingID(), |
| 171 value)); | 181 value)); |
| 172 } else { | 182 } else { |
| 173 FillAutofillFormData(unique_id, false); | 183 FillAutofillFormData(unique_id, false); |
| 174 } | 184 } |
| 175 | |
| 176 HideAutofillPopup(); | |
| 177 } | 185 } |
| 178 | 186 |
| 179 void AutofillExternalDelegate::ClearPreviewedForm() { | 187 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 188 if (password_autofill_manager_.DidClearAutofillSelection( |
| 189 autofill_query_field_)) |
| 190 return; |
| 191 |
| 180 RenderViewHost* host = | 192 RenderViewHost* host = |
| 181 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 193 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| 182 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 194 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
| 183 } | 195 } |
| 184 | 196 |
| 185 void AutofillExternalDelegate::HideAutofillPopup() { | 197 void AutofillExternalDelegate::HideAutofillPopup() { |
| 186 suggestions_clear_index_ = -1; | 198 suggestions_clear_index_ = -1; |
| 187 suggestions_options_index_ = -1; | 199 suggestions_options_index_ = -1; |
| 188 | 200 |
| 189 HideAutofillPopupInternal(); | 201 HideAutofillPopupInternal(); |
| 190 } | 202 } |
| 191 | 203 |
| 204 void AutofillExternalDelegate::Reset() { |
| 205 HideAutofillPopup(); |
| 206 |
| 207 password_autofill_manager_.Reset(); |
| 208 } |
| 209 |
| 210 void AutofillExternalDelegate::AddPasswordFormMapping( |
| 211 const webkit::forms::FormField& form, |
| 212 const webkit::forms::PasswordFormFillData& fill_data) { |
| 213 password_autofill_manager_.AddPasswordFormMapping(form, fill_data); |
| 214 } |
| 215 |
| 192 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, | 216 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, |
| 193 bool is_preview) { | 217 bool is_preview) { |
| 194 RenderViewHost* host = | 218 RenderViewHost* host = |
| 195 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 219 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
| 196 | 220 |
| 197 if (is_preview) { | 221 if (is_preview) { |
| 198 host->Send(new AutofillMsg_SetAutofillActionPreview( | 222 host->Send(new AutofillMsg_SetAutofillActionPreview( |
| 199 host->GetRoutingID())); | 223 host->GetRoutingID())); |
| 200 } else { | 224 } else { |
| 201 host->Send(new AutofillMsg_SetAutofillActionFill( | 225 host->Send(new AutofillMsg_SetAutofillActionFill( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 214 // none, so all platforms use the default. | 238 // none, so all platforms use the default. |
| 215 | 239 |
| 216 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) | 240 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) |
| 217 | 241 |
| 218 AutofillExternalDelegate* AutofillExternalDelegate::Create( | 242 AutofillExternalDelegate* AutofillExternalDelegate::Create( |
| 219 TabContentsWrapper*, AutofillManager*) { | 243 TabContentsWrapper*, AutofillManager*) { |
| 220 return NULL; | 244 return NULL; |
| 221 } | 245 } |
| 222 | 246 |
| 223 #endif | 247 #endif |
| OLD | NEW |