| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/autofill_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "chrome/browser/autofill/autofill_dialog.h" | 10 #include "chrome/browser/autofill/autofill_dialog.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 infobar_(NULL) { | 41 infobar_(NULL) { |
| 42 DCHECK(tab_contents); | 42 DCHECK(tab_contents); |
| 43 | 43 |
| 44 // |personal_data_| is NULL when using TestTabContents. | 44 // |personal_data_| is NULL when using TestTabContents. |
| 45 personal_data_ = | 45 personal_data_ = |
| 46 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager(); | 46 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager(); |
| 47 download_manager_.SetObserver(this); | 47 download_manager_.SetObserver(this); |
| 48 } | 48 } |
| 49 | 49 |
| 50 AutoFillManager::~AutoFillManager() { | 50 AutoFillManager::~AutoFillManager() { |
| 51 // This is NULL in the MockAutoFillManager. | |
| 52 if (personal_data_) | |
| 53 personal_data_->RemoveObserver(this); | |
| 54 download_manager_.SetObserver(NULL); | 51 download_manager_.SetObserver(NULL); |
| 55 } | 52 } |
| 56 | 53 |
| 57 // static | 54 // static |
| 58 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) { | 55 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) { |
| 59 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement); | 56 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement); |
| 60 } | 57 } |
| 61 | 58 |
| 62 // static | 59 // static |
| 63 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { | 60 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 break; | 254 break; |
| 258 } | 255 } |
| 259 } | 256 } |
| 260 } | 257 } |
| 261 } | 258 } |
| 262 | 259 |
| 263 host->AutoFillFormDataFilled(query_id, result); | 260 host->AutoFillFormDataFilled(query_id, result); |
| 264 return true; | 261 return true; |
| 265 } | 262 } |
| 266 | 263 |
| 267 void AutoFillManager::OnPersonalDataLoaded() { | |
| 268 // We might have been alerted that the PersonalDataManager has loaded, so | |
| 269 // remove ourselves as observer. | |
| 270 personal_data_->RemoveObserver(this); | |
| 271 | |
| 272 #if !defined(OS_WIN) | |
| 273 #if defined(OS_MACOSX) | |
| 274 ShowAutoFillDialog(personal_data_, | |
| 275 personal_data_->web_profiles(), | |
| 276 personal_data_->credit_cards(), | |
| 277 tab_contents_->profile()->GetOriginalProfile()); | |
| 278 #else // defined(OS_MACOSX) | |
| 279 ShowAutoFillDialog(NULL, personal_data_, | |
| 280 tab_contents_->profile()->GetOriginalProfile()); | |
| 281 #endif // defined(OS_MACOSX) | |
| 282 #endif // !defined(OS_WIN) | |
| 283 } | |
| 284 | |
| 285 void AutoFillManager::OnInfoBarClosed() { | 264 void AutoFillManager::OnInfoBarClosed() { |
| 286 PrefService* prefs = tab_contents_->profile()->GetPrefs(); | 265 PrefService* prefs = tab_contents_->profile()->GetPrefs(); |
| 287 prefs->SetBoolean(prefs::kAutoFillEnabled, true); | 266 prefs->SetBoolean(prefs::kAutoFillEnabled, true); |
| 288 | 267 |
| 289 // Save the imported form data as a profile. | 268 // Save the imported form data as a profile. |
| 290 personal_data_->SaveImportedFormData(); | 269 personal_data_->SaveImportedFormData(); |
| 291 } | 270 } |
| 292 | 271 |
| 293 void AutoFillManager::OnInfoBarAccepted() { | 272 void AutoFillManager::OnInfoBarAccepted() { |
| 294 PrefService* prefs = tab_contents_->profile()->GetPrefs(); | 273 PrefService* prefs = tab_contents_->profile()->GetPrefs(); |
| 295 prefs->SetBoolean(prefs::kAutoFillEnabled, true); | 274 prefs->SetBoolean(prefs::kAutoFillEnabled, true); |
| 296 | 275 |
| 297 // This is the first time the user is interacting with AutoFill, so set the | 276 // This is the first time the user is interacting with AutoFill, so set the |
| 298 // uploaded form structure as the initial profile in the AutoFillDialog. | 277 // uploaded form structure as the initial profile and credit card in the |
| 299 personal_data_->SaveImportedFormData(); | 278 // AutoFillDialog. |
| 300 | 279 AutoFillProfile* profile = NULL; |
| 301 #if defined(OS_WIN) | 280 CreditCard* credit_card = NULL; |
| 302 ShowAutoFillDialog(tab_contents_->GetContentNativeView(), personal_data_, | 281 // TODO(dhollowa) Now that we aren't immediately saving the imported form |
| 303 tab_contents_->profile()->GetOriginalProfile()); | 282 // data, we should store the profile and CC in the AFM instead of the PDM. |
| 304 #else | 283 personal_data_->GetImportedFormData(&profile, &credit_card); |
| 305 // If the personal data manager has not loaded the data yet, set ourselves as | 284 ShowAutoFillDialog(tab_contents_->GetContentNativeView(), |
| 306 // its observer so that we can listen for the OnPersonalDataLoaded signal. | 285 personal_data_, |
| 307 if (!personal_data_->IsDataLoaded()) | 286 tab_contents_->profile()->GetOriginalProfile(), |
| 308 personal_data_->SetObserver(this); | 287 profile, |
| 309 else | 288 credit_card); |
| 310 OnPersonalDataLoaded(); | |
| 311 #endif | |
| 312 } | 289 } |
| 313 | 290 |
| 314 void AutoFillManager::OnInfoBarCancelled() { | 291 void AutoFillManager::OnInfoBarCancelled() { |
| 315 PrefService* prefs = tab_contents_->profile()->GetPrefs(); | 292 PrefService* prefs = tab_contents_->profile()->GetPrefs(); |
| 316 prefs->SetBoolean(prefs::kAutoFillEnabled, false); | 293 prefs->SetBoolean(prefs::kAutoFillEnabled, false); |
| 317 } | 294 } |
| 318 | 295 |
| 319 void AutoFillManager::Reset() { | 296 void AutoFillManager::Reset() { |
| 320 upload_form_structure_.reset(); | 297 upload_form_structure_.reset(); |
| 321 form_structures_.reset(); | 298 form_structures_.reset(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 // The value of the stored data for this field type in the |credit_card|. | 502 // The value of the stored data for this field type in the |credit_card|. |
| 526 string16 creditcard_field_value = | 503 string16 creditcard_field_value = |
| 527 credit_card->GetFieldText(AutoFillType(type)); | 504 credit_card->GetFieldText(AutoFillType(type)); |
| 528 if (!creditcard_field_value.empty() && | 505 if (!creditcard_field_value.empty() && |
| 529 StartsWith(creditcard_field_value, field.value(), false)) { | 506 StartsWith(creditcard_field_value, field.value(), false)) { |
| 530 values->push_back(credit_card->ObfuscatedNumber()); | 507 values->push_back(credit_card->ObfuscatedNumber()); |
| 531 labels->push_back(credit_card->Label()); | 508 labels->push_back(credit_card->Label()); |
| 532 } | 509 } |
| 533 } | 510 } |
| 534 } | 511 } |
| OLD | NEW |