Skip to content

Commit

Permalink
Revert 282408 "Use upstream libaddressinput in Chrome."
Browse files Browse the repository at this point in the history
Introduced static initializers into chrome binary:
preload_supplier.cc _GLOBAL__sub_I_preload_supplier.cc+0xa
preload_supplier.cc i18n::addressinput::StringCompare::StringCompare()
preload_supplier.cc __cxa_atexit@plt [registers a dtor to run at exit]

Run ./tools/linux/dump-static-initializers.py before re-landing to
verify they're no longer present.

> Use upstream libaddressinput in Chrome.
> 
> Most of the changes are mechanical switches from chromium/ to src/
> directory in third_party/libadressinput/.
> 
> To simplify the switch, autofill::AddressValidator is a shim between
> Chromium and i18n::addressinput::AddressValidator. The shim behaves the
> same way as Chromium's version of libaddressinput. The goal is to
> gradually remove the shim and make Chromium work directly with
> libaddressinupt.
> 
> Upstream libaddressinput does not include suggestions, which now can be
> found in third_party/libadressinput/chromium/input_suggester.{h,cc}.
> 
> A follow up patch will remove Chromium's version of libaddressinput.
> 
> BUG=327046
> 
> Review URL: https://codereview.chromium.org/298863012

TBR=rouslan@chromium.org

Review URL: https://codereview.chromium.org/388613002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282426 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
scherkus@chromium.org committed Jul 10, 2014
1 parent 07d6ba2 commit 2c6651d
Show file tree
Hide file tree
Showing 56 changed files with 898 additions and 2,647 deletions.
34 changes: 0 additions & 34 deletions build/ios/grit_whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -591,40 +591,6 @@ IDS_IMPORT_FROM_FIREFOX
IDS_IMPORT_FROM_ICEWEASEL
IDS_KEYWORD_SEARCH
IDS_LEARN_MORE
IDS_LIBADDRESSINPUT_ADDRESS_LINE_1_LABEL
IDS_LIBADDRESSINPUT_AREA
IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL
IDS_LIBADDRESSINPUT_COUNTY
IDS_LIBADDRESSINPUT_DEPARTMENT
IDS_LIBADDRESSINPUT_DISTRICT
IDS_LIBADDRESSINPUT_DO_SI
IDS_LIBADDRESSINPUT_EMIRATE
IDS_LIBADDRESSINPUT_ISLAND
IDS_LIBADDRESSINPUT_LOCALITY_LABEL
IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE
IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_POSTAL_CODE_URL
IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_ZIP
IDS_LIBADDRESSINPUT_MISMATCHING_VALUE_ZIP_URL
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE_AND_URL
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_ZIP_CODE_EXAMPLE
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_ZIP_CODE_EXAMPLE_AND_URL
IDS_LIBADDRESSINPUT_PARISH
IDS_LIBADDRESSINPUT_POSTAL_CODE_LABEL
IDS_LIBADDRESSINPUT_PO_BOX_FORBIDDEN_VALUE
IDS_LIBADDRESSINPUT_PREFECTURE
IDS_LIBADDRESSINPUT_PROVINCE
IDS_LIBADDRESSINPUT_RECIPIENT_LABEL
IDS_LIBADDRESSINPUT_STATE
IDS_LIBADDRESSINPUT_UNKNOWN_VALUE
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_POSTAL_CODE_EXAMPLE_AND_URL
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP_CODE_EXAMPLE
IDS_LIBADDRESSINPUT_UNRECOGNIZED_FORMAT_ZIP_CODE_EXAMPLE_AND_URL
IDS_LIBADDRESSINPUT_ZIP_CODE_LABEL
IDS_LOGIN_DIALOG_OK_BUTTON_LABEL
IDS_LOGIN_DIALOG_PASSWORD_FIELD
IDS_LOGIN_DIALOG_TITLE
Expand Down
4 changes: 1 addition & 3 deletions chrome/browser/ui/autofill/DEPS
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
include_rules = [
'+third_party/libaddressinput/chromium/addressinput_util.h',
'+third_party/libaddressinput/chromium/chrome_address_validator.h',
'+third_party/libaddressinput/chromium/chrome_downloader_impl.h',
'+third_party/libaddressinput/chromium/chrome_storage_impl.h',
'+third_party/libaddressinput/messages.h',
'+third_party/libaddressinput/src/cpp/include/libaddressinput',
'+third_party/libaddressinput/chromium/cpp/include/libaddressinput',
]
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace {

using testing::Return;
using testing::_;
using ::i18n::addressinput::AddressValidator;

void MockCallback(AutofillClient::RequestAutocompleteResult,
const base::string16& message,
Expand Down
65 changes: 31 additions & 34 deletions chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,14 @@
#include "grit/component_scaled_resources.h"
#include "grit/components_strings.h"
#include "grit/generated_resources.h"
#include "grit/libaddressinput_strings.h"
#include "grit/platform_locale_settings.h"
#include "grit/theme_resources.h"
#include "net/cert/cert_status_flags.h"
#include "third_party/libaddressinput/chromium/chrome_downloader_impl.h"
#include "third_party/libaddressinput/chromium/chrome_storage_impl.h"
#include "third_party/libaddressinput/messages.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_problem.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/localization.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_problem.h"
#include "ui/base/base_window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/combobox_model.h"
Expand All @@ -101,12 +99,9 @@
using ::i18n::addressinput::AddressData;
using ::i18n::addressinput::AddressField;
using ::i18n::addressinput::AddressProblem;
using ::i18n::addressinput::ADMIN_AREA;
using ::i18n::addressinput::DEPENDENT_LOCALITY;
using ::i18n::addressinput::Downloader;
using ::i18n::addressinput::FieldProblemMap;
using ::i18n::addressinput::Localization;
using ::i18n::addressinput::MISSING_REQUIRED_FIELD;
using ::i18n::addressinput::AddressProblemFilter;
using ::i18n::addressinput::AddressProblems;
using ::i18n::addressinput::AddressValidator;

namespace autofill {

Expand Down Expand Up @@ -872,12 +867,12 @@ void AutofillDialogControllerImpl::Show() {
if (account_chooser_model_->WalletIsSelected())
FetchWalletCookie();

validator_.reset(new AddressValidator(
I18N_ADDRESS_VALIDATION_DATA_URL,
scoped_ptr<Downloader>(
new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())),
scoped_ptr< ::i18n::addressinput::Downloader> downloader(
new autofill::ChromeDownloaderImpl(profile_->GetRequestContext()));
validator_ = AddressValidator::Build(
downloader.Pass(),
ValidationRulesStorageFactory::CreateStorage(),
this));
this);

SuggestionsUpdated();
SubmitButtonDelayBegin();
Expand Down Expand Up @@ -1949,14 +1944,14 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage(
case CREDIT_CARD_EXP_MONTH:
if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) {
return l10n_util::GetStringUTF16(
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD);
IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD);
}
break;

case CREDIT_CARD_EXP_4_DIGIT_YEAR:
if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) {
return l10n_util::GetStringUTF16(
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD);
IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD);
}
break;

Expand Down Expand Up @@ -1988,7 +1983,7 @@ base::string16 AutofillDialogControllerImpl::InputValidityMessage(
}

return value.empty() ? l10n_util::GetStringUTF16(
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD) :
IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD) :
base::string16();
}

Expand All @@ -2009,19 +2004,17 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
profile, g_browser_process->GetApplicationLocale());
address_data->language_code = AddressLanguageCodeForSection(section);

Localization localization;
localization.SetGetter(l10n_util::GetStringUTF8);
FieldProblemMap problems;
status = GetValidator()->ValidateAddress(*address_data, NULL, &problems);
AddressProblems problems;
status = GetValidator()->ValidateAddress(*address_data,
AddressProblemFilter(),
&problems);
common::AddressType address_type = section == SECTION_SHIPPING ?
common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING;

for (FieldProblemMap::const_iterator iter = problems.begin();
iter != problems.end(); ++iter) {
bool sure = iter->second != MISSING_REQUIRED_FIELD;
base::string16 text = base::UTF8ToUTF16(localization.GetErrorMessage(
*address_data, iter->first, iter->second, true, false));
messages.Set(i18ninput::TypeForField(iter->first, address_type),
for (size_t i = 0; i < problems.size(); ++i) {
const AddressProblem& problem = problems[i];
bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD;
base::string16 text = l10n_util::GetStringUTF16(problem.description_id);
messages.Set(i18ninput::TypeForField(problem.field, address_type),
ValidityMessage(text, sure));
}
}
Expand Down Expand Up @@ -3438,7 +3431,9 @@ void AutofillDialogControllerImpl::GetI18nValidatorSuggestions(
// region of the suggested address:
// ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY
popup_labels->push_back(base::string16());
for (int field = DEPENDENT_LOCALITY; field >= ADMIN_AREA; --field) {
for (int field = ::i18n::addressinput::DEPENDENT_LOCALITY;
field >= ::i18n::addressinput::ADMIN_AREA;
--field) {
const std::string& field_value =
i18n_validator_suggestions_[i].GetFieldValue(
static_cast<AddressField>(field));
Expand Down Expand Up @@ -3621,7 +3616,7 @@ bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) {
AddressData address_data;
address_data.region_code = CountryCodeForSection(section);
AddressValidator::Status status = GetValidator()->ValidateAddress(
address_data, NULL, NULL);
address_data, AddressProblemFilter(), NULL);
return status == AddressValidator::SUCCESS;
}

Expand Down Expand Up @@ -3673,8 +3668,10 @@ bool AutofillDialogControllerImpl::HasInvalidAddress(
i18n::CreateAddressDataFromAutofillProfile(
profile, g_browser_process->GetApplicationLocale());

FieldProblemMap problems;
GetValidator()->ValidateAddress(*address_data, NULL, &problems);
AddressProblems problems;
GetValidator()->ValidateAddress(*address_data,
AddressProblemFilter(),
&problems);
return !problems.empty();
}

Expand Down
17 changes: 6 additions & 11 deletions chrome/browser/ui/autofill/autofill_dialog_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/ssl_status.h"
#include "third_party/libaddressinput/chromium/chrome_address_validator.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/ui_base_types.h"
Expand All @@ -49,12 +50,6 @@ namespace content {
class WebContents;
}

namespace i18n {
namespace addressinput {
struct AddressData;
}
}

namespace autofill {

class AutofillDataModel;
Expand Down Expand Up @@ -84,7 +79,7 @@ class AutofillDialogControllerImpl
public PersonalDataManagerObserver,
public AccountChooserModelDelegate,
public gfx::AnimationDelegate,
public LoadRulesListener {
public ::i18n::addressinput::LoadRulesDelegate {
public:
virtual ~AutofillDialogControllerImpl();

Expand Down Expand Up @@ -223,7 +218,7 @@ class AutofillDialogControllerImpl
virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;

// LoadRulesListener implementation.
// ::i18n::addressinput::LoadRulesDelegate implementation.
virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
bool success) OVERRIDE;

Expand Down Expand Up @@ -254,7 +249,7 @@ class AutofillDialogControllerImpl
virtual PersonalDataManager* GetManager() const;

// Returns an address validation helper. May be NULL during tests.
virtual AddressValidator* GetValidator();
virtual ::i18n::addressinput::AddressValidator* GetValidator();

// Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
// for testing.
Expand Down Expand Up @@ -660,7 +655,7 @@ class AutofillDialogControllerImpl
wallet::WalletClient wallet_client_;

// A helper to validate international address input.
scoped_ptr<AddressValidator> validator_;
scoped_ptr< ::i18n::addressinput::AddressValidator> validator_;

// True if |this| has ever called GetWalletItems().
bool wallet_items_requested_;
Expand Down
29 changes: 17 additions & 12 deletions chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// found in the LICENSE file.

#include <map>
#include <utility>

#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
Expand Down Expand Up @@ -57,9 +55,8 @@
#include "grit/generated_resources.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libaddressinput/chromium/chrome_address_validator.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_problem.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"

Expand All @@ -74,7 +71,11 @@ namespace autofill {

namespace {

using ::i18n::addressinput::FieldProblemMap;
using ::i18n::addressinput::AddressData;
using ::i18n::addressinput::AddressProblemFilter;
using ::i18n::addressinput::AddressProblem;
using ::i18n::addressinput::AddressProblems;
using ::i18n::addressinput::AddressValidator;
using testing::AtLeast;
using testing::DoAll;
using testing::Return;
Expand Down Expand Up @@ -1020,9 +1021,11 @@ TEST_F(AutofillDialogControllerTest, AutofillProfilesPopInvalidIntoEdit) {
// Now make up a problem and make sure the profile isn't in the list.
Reset();
SwitchToAutofill();
FieldProblemMap problems;
problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE,
::i18n::addressinput::MISMATCHING_VALUE));
AddressProblems problems;
problems.push_back(
AddressProblem(::i18n::addressinput::POSTAL_CODE,
AddressProblem::MISMATCHING_VALUE,
IDS_LEARN_MORE));
EXPECT_CALL(*controller()->GetMockValidator(),
ValidateAddress(CountryCodeMatcher("US"), _, _)).
WillRepeatedly(DoAll(SetArgPointee<2>(problems),
Expand Down Expand Up @@ -1050,9 +1053,11 @@ TEST_F(AutofillDialogControllerTest, AutofillProfilesRevalidateAfterRulesLoad) {
EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING));

FieldProblemMap problems;
problems.insert(std::make_pair(::i18n::addressinput::POSTAL_CODE,
::i18n::addressinput::MISMATCHING_VALUE));
AddressProblems problems;
problems.push_back(
AddressProblem(::i18n::addressinput::POSTAL_CODE,
AddressProblem::MISMATCHING_VALUE,
IDS_LEARN_MORE));
EXPECT_CALL(*controller()->GetMockValidator(),
ValidateAddress(CountryCodeMatcher("US"), _, _)).
WillRepeatedly(DoAll(SetArgPointee<2>(problems),
Expand Down
32 changes: 12 additions & 20 deletions chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
#include "components/autofill/core/browser/field_types.h"
#include "grit/components_strings.h"
#include "third_party/libaddressinput/chromium/addressinput_util.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui_component.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/localization.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_field.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui.h"
#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_ui_component.h"
#include "ui/base/l10n/l10n_util.h"

namespace autofill {
Expand All @@ -26,19 +25,9 @@ namespace i18ninput {
namespace {

using base::UTF16ToUTF8;
using ::i18n::addressinput::AddressData;
using ::i18n::addressinput::AddressField;
using ::i18n::addressinput::AddressUiComponent;
using ::i18n::addressinput::Localization;

std::vector<AddressUiComponent> BuildComponents(const std::string& country_code,
std::string* language_code) {
Localization localization;
localization.SetGetter(l10n_util::GetStringUTF8);
std::string not_used;
return ::i18n::addressinput::BuildComponents(
country_code, localization, g_browser_process->GetApplicationLocale(),
language_code == NULL ? &not_used : language_code);
}

DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) {
if (hint == AddressUiComponent::HINT_SHORT)
Expand All @@ -53,16 +42,18 @@ void BuildAddressInputs(common::AddressType address_type,
const std::string& country_code,
DetailInputs* inputs,
std::string* language_code) {
const std::vector<AddressUiComponent>& components(
BuildComponents(country_code, language_code));
std::vector<AddressUiComponent> components(
::i18n::addressinput::BuildComponents(
country_code, g_browser_process->GetApplicationLocale(),
language_code));

const bool billing = address_type == common::ADDRESS_TYPE_BILLING;

for (size_t i = 0; i < components.size(); ++i) {
const AddressUiComponent& component = components[i];
ServerFieldType server_type = TypeForField(component.field, address_type);
DetailInput::Length length = LengthFromHint(component.length_hint);
base::string16 placeholder = base::UTF8ToUTF16(component.name);
base::string16 placeholder = l10n_util::GetStringUTF16(component.name_id);
DetailInput input = { length, server_type, placeholder };
inputs->push_back(input);
}
Expand Down Expand Up @@ -143,7 +134,8 @@ ServerFieldType TypeForField(AddressField address_field,
return UNKNOWN_TYPE;
}

bool FieldForType(ServerFieldType server_type, AddressField* field) {
bool FieldForType(ServerFieldType server_type,
::i18n::addressinput::AddressField* field) {
switch (server_type) {
case ADDRESS_BILLING_COUNTRY:
case ADDRESS_HOME_COUNTRY:
Expand Down
Loading

0 comments on commit 2c6651d

Please sign in to comment.