| 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 "chrome/browser/ui/webui/options/autofill_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h" | 
| 6 | 6 | 
| 7 #include <vector> | 7 #include <vector> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" | 
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" | 
| 12 #include "base/guid.h" | 12 #include "base/guid.h" | 
| 13 #include "base/logging.h" | 13 #include "base/logging.h" | 
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" | 
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" | 
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" | 
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" | 
| 18 #include "base/values.h" | 18 #include "base/values.h" | 
| 19 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 19 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" | 
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" | 
| 22 #include "chrome/browser/sync/profile_sync_service.h" |  | 
| 23 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 
| 24 #include "chrome/browser/ui/autofill/country_combobox_model.h" | 23 #include "chrome/browser/ui/autofill/country_combobox_model.h" | 
| 25 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" | 
| 26 #include "chrome/grit/chromium_strings.h" | 25 #include "chrome/grit/chromium_strings.h" | 
| 27 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" | 
| 28 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 27 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 
| 29 #include "components/autofill/core/browser/autofill_country.h" | 28 #include "components/autofill/core/browser/autofill_country.h" | 
| 30 #include "components/autofill/core/browser/autofill_profile.h" | 29 #include "components/autofill/core/browser/autofill_profile.h" | 
| 31 #include "components/autofill/core/browser/credit_card.h" | 30 #include "components/autofill/core/browser/credit_card.h" | 
| 32 #include "components/autofill/core/browser/personal_data_manager.h" | 31 #include "components/autofill/core/browser/personal_data_manager.h" | 
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 309   scoped_ptr<base::ListValue> list(extracted_list->DeepCopy()); | 308   scoped_ptr<base::ListValue> list(extracted_list->DeepCopy()); | 
| 310   RemoveDuplicatePhoneNumberAtIndex(index, country_code, list.get()); | 309   RemoveDuplicatePhoneNumberAtIndex(index, country_code, list.get()); | 
| 311   return list.Pass(); | 310   return list.Pass(); | 
| 312 } | 311 } | 
| 313 | 312 | 
| 314 }  // namespace | 313 }  // namespace | 
| 315 | 314 | 
| 316 namespace options { | 315 namespace options { | 
| 317 | 316 | 
| 318 AutofillOptionsHandler::AutofillOptionsHandler() | 317 AutofillOptionsHandler::AutofillOptionsHandler() | 
| 319     : personal_data_(NULL) {} | 318     : personal_data_(NULL), observer_(this) { | 
|  | 319 } | 
| 320 | 320 | 
| 321 AutofillOptionsHandler::~AutofillOptionsHandler() { | 321 AutofillOptionsHandler::~AutofillOptionsHandler() { | 
| 322   if (personal_data_) | 322   if (personal_data_) | 
| 323     personal_data_->RemoveObserver(this); | 323     personal_data_->RemoveObserver(this); | 
| 324 } | 324 } | 
| 325 | 325 | 
| 326 ///////////////////////////////////////////////////////////////////////////// | 326 ///////////////////////////////////////////////////////////////////////////// | 
| 327 // OptionsPageUIHandler implementation: | 327 // OptionsPageUIHandler implementation: | 
| 328 void AutofillOptionsHandler::GetLocalizedValues( | 328 void AutofillOptionsHandler::GetLocalizedValues( | 
| 329     base::DictionaryValue* localized_strings) { | 329     base::DictionaryValue* localized_strings) { | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 354                 IDS_AUTOFILL_OPTIONS_TITLE); | 354                 IDS_AUTOFILL_OPTIONS_TITLE); | 
| 355 | 355 | 
| 356   localized_strings->SetString("helpUrl", autofill::kHelpURL); | 356   localized_strings->SetString("helpUrl", autofill::kHelpURL); | 
| 357 | 357 | 
| 358   personal_data_ = autofill::PersonalDataManagerFactory::GetForProfile( | 358   personal_data_ = autofill::PersonalDataManagerFactory::GetForProfile( | 
| 359       Profile::FromWebUI(web_ui())); | 359       Profile::FromWebUI(web_ui())); | 
| 360 | 360 | 
| 361   SetAddressOverlayStrings(localized_strings); | 361   SetAddressOverlayStrings(localized_strings); | 
| 362   SetCreditCardOverlayStrings(localized_strings); | 362   SetCreditCardOverlayStrings(localized_strings); | 
| 363 | 363 | 
| 364   ProfileSyncService* service = |  | 
| 365       ProfileSyncServiceFactory::GetInstance()->GetForProfile( |  | 
| 366           Profile::FromWebUI(web_ui())); |  | 
| 367   localized_strings->SetBoolean( |  | 
| 368       "enableAutofillWalletIntegration", |  | 
| 369       service && service->IsSyncEnabledAndLoggedIn() && |  | 
| 370           personal_data_->IsExperimentalWalletIntegrationEnabled()); |  | 
| 371   localized_strings->SetString( | 364   localized_strings->SetString( | 
| 372       "manageWalletAddressesUrl", | 365       "manageWalletAddressesUrl", | 
| 373       autofill::wallet::GetManageAddressesUrl(0).spec()); | 366       autofill::wallet::GetManageAddressesUrl(0).spec()); | 
| 374   localized_strings->SetString( | 367   localized_strings->SetString( | 
| 375       "manageWalletPaymentMethodsUrl", | 368       "manageWalletPaymentMethodsUrl", | 
| 376       autofill::wallet::GetManageInstrumentsUrl(0).spec()); | 369       autofill::wallet::GetManageInstrumentsUrl(0).spec()); | 
|  | 370 | 
|  | 371   // This is set in loadTimeData to minimize the chance of a load-time flash of | 
|  | 372   // content. | 
|  | 373   ProfileSyncService* service = | 
|  | 374       ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 
|  | 375           Profile::FromWebUI(web_ui())); | 
|  | 376   if (service) | 
|  | 377     observer_.Add(service); | 
|  | 378   localized_strings->SetBoolean( | 
|  | 379       "autofillWalletIntegrationAvailable", | 
|  | 380       service && service->IsSyncEnabledAndLoggedIn() && | 
|  | 381           personal_data_->IsExperimentalWalletIntegrationEnabled()); | 
| 377 } | 382 } | 
| 378 | 383 | 
| 379 void AutofillOptionsHandler::InitializeHandler() { | 384 void AutofillOptionsHandler::InitializeHandler() { | 
| 380   // personal_data_ is NULL in guest mode on Chrome OS. | 385   // personal_data_ is NULL in guest mode on Chrome OS. | 
| 381   if (personal_data_) | 386   if (personal_data_) | 
| 382     personal_data_->AddObserver(this); | 387     personal_data_->AddObserver(this); | 
| 383 } | 388 } | 
| 384 | 389 | 
| 385 void AutofillOptionsHandler::InitializePage() { | 390 void AutofillOptionsHandler::InitializePage() { | 
| 386   if (personal_data_) | 391   if (personal_data_) | 
| 387     LoadAutofillData(); | 392     LoadAutofillData(); | 
|  | 393 | 
|  | 394   // Also update the visibility of the Wallet checkbox (which may have | 
|  | 395   // changed since the localized string dictionary was built). | 
|  | 396   OnStateChanged(); | 
| 388 } | 397 } | 
| 389 | 398 | 
| 390 void AutofillOptionsHandler::RegisterMessages() { | 399 void AutofillOptionsHandler::RegisterMessages() { | 
| 391 #if defined(OS_MACOSX) && !defined(OS_IOS) | 400 #if defined(OS_MACOSX) && !defined(OS_IOS) | 
| 392   web_ui()->RegisterMessageCallback( | 401   web_ui()->RegisterMessageCallback( | 
| 393       "accessAddressBook", | 402       "accessAddressBook", | 
| 394       base::Bind(&AutofillOptionsHandler::AccessAddressBook, | 403       base::Bind(&AutofillOptionsHandler::AccessAddressBook, | 
| 395                  base::Unretained(this))); | 404                  base::Unretained(this))); | 
| 396 #endif  // defined(OS_MACOSX) && !defined(OS_IOS) | 405 #endif  // defined(OS_MACOSX) && !defined(OS_IOS) | 
| 397   web_ui()->RegisterMessageCallback( | 406   web_ui()->RegisterMessageCallback( | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 426       base::Bind(&AutofillOptionsHandler::RemaskServerCard, | 435       base::Bind(&AutofillOptionsHandler::RemaskServerCard, | 
| 427                  base::Unretained(this))); | 436                  base::Unretained(this))); | 
| 428 } | 437 } | 
| 429 | 438 | 
| 430 ///////////////////////////////////////////////////////////////////////////// | 439 ///////////////////////////////////////////////////////////////////////////// | 
| 431 // PersonalDataManagerObserver implementation: | 440 // PersonalDataManagerObserver implementation: | 
| 432 void AutofillOptionsHandler::OnPersonalDataChanged() { | 441 void AutofillOptionsHandler::OnPersonalDataChanged() { | 
| 433   LoadAutofillData(); | 442   LoadAutofillData(); | 
| 434 } | 443 } | 
| 435 | 444 | 
|  | 445 void AutofillOptionsHandler::OnStateChanged() { | 
|  | 446   ProfileSyncService* service = | 
|  | 447       ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 
|  | 448           Profile::FromWebUI(web_ui())); | 
|  | 449   web_ui()->CallJavascriptFunction( | 
|  | 450       "AutofillOptions.walletIntegrationAvailableStateChanged", | 
|  | 451       base::FundamentalValue(service && service->IsSyncEnabledAndLoggedIn())); | 
|  | 452 } | 
|  | 453 | 
| 436 void AutofillOptionsHandler::SetAddressOverlayStrings( | 454 void AutofillOptionsHandler::SetAddressOverlayStrings( | 
| 437     base::DictionaryValue* localized_strings) { | 455     base::DictionaryValue* localized_strings) { | 
| 438   localized_strings->SetString("autofillEditAddressTitle", | 456   localized_strings->SetString("autofillEditAddressTitle", | 
| 439       l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 457       l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 
| 440   localized_strings->SetString("autofillCountryLabel", | 458   localized_strings->SetString("autofillCountryLabel", | 
| 441       l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); | 459       l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); | 
| 442   localized_strings->SetString("autofillPhoneLabel", | 460   localized_strings->SetString("autofillPhoneLabel", | 
| 443       l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 461       l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 
| 444   localized_strings->SetString("autofillEmailLabel", | 462   localized_strings->SetString("autofillEmailLabel", | 
| 445       l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 463       l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 768   scoped_ptr<base::ListValue> components(new base::ListValue); | 786   scoped_ptr<base::ListValue> components(new base::ListValue); | 
| 769   GetAddressComponents( | 787   GetAddressComponents( | 
| 770       base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 788       base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 
| 771       profile.language_code(), | 789       profile.language_code(), | 
| 772       components.get(), | 790       components.get(), | 
| 773       NULL); | 791       NULL); | 
| 774   address->Set(kComponents, components.release()); | 792   address->Set(kComponents, components.release()); | 
| 775 } | 793 } | 
| 776 | 794 | 
| 777 }  // namespace options | 795 }  // namespace options | 
| OLD | NEW | 
|---|