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