summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h126
-rw-r--r--third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h43
-rw-r--r--third_party/libaddressinput/chromium/cpp/libaddressinput.gyp4
-rw-r--r--third_party/libaddressinput/chromium/cpp/src/address_validator.cc51
-rw-r--r--third_party/libaddressinput/libaddressinput.gyp6
5 files changed, 230 insertions, 0 deletions
diff --git a/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h
new file mode 100644
index 0000000..4ede9a6
--- /dev/null
+++ b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h
@@ -0,0 +1,126 @@
+// Copyright (C) 2013 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_
+#define I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_
+
+#include <libaddressinput/address_field.h>
+#include <libaddressinput/address_problem.h>
+#include <libaddressinput/util/basictypes.h>
+#include <libaddressinput/util/scoped_ptr.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+namespace i18n {
+namespace addressinput {
+
+class Downloader;
+class LoadRulesDelegate;
+class Localization;
+class RuleRetriever;
+class Storage;
+struct AddressData;
+
+typedef std::vector<AddressProblem> AddressProblems;
+typedef std::multimap<AddressField, AddressProblem::Type> AddressProblemFilter;
+
+// Validates an AddressData structure. Sample usage:
+// class MyClass : public LoadRulesDelegate {
+// public:
+// MyClass() : validator_(new MyDownloader, new MyStorage, this) {
+// validator_.LoadRules("US");
+// }
+//
+// virtual ~MyClass() {}
+//
+// virtual void OnAddressValidationRulesLoaded(
+// const std::string& country_code,
+// bool success) {
+// ...
+// }
+//
+// void ValidateAddress() {
+// AddressData address;
+// address.country_code = "US";
+// address.administrative_area = "CA";
+// AddressProblems problems;
+// AddressProblemFilter filter;
+// AddressValidator::Status status =
+// validator_.ValidateAddress(address, filter, &problems);
+// if (status == AddressValidator::SUCCESS) {
+// Process(problems);
+// }
+// }
+//
+// private:
+// AddressValidator validator_;
+// };
+class AddressValidator {
+ public:
+ // The status of address validation.
+ enum Status {
+ // Address validation completed successfully. Check |problems| to see if any
+ // problems were found.
+ SUCCESS,
+
+ // The validation rules are not available, because LoadRules() was not
+ // called or failed. Reload the rules.
+ RULES_UNAVAILABLE,
+
+ // The validation rules are being loaded. Try again later.
+ RULES_NOT_READY
+ };
+
+ // Takes ownership of |downloader| and |storage|, which cannot be NULL. Does
+ // not take ownership of |load_rules_delegate|, which can be NULL.
+ AddressValidator(const Downloader* downloader,
+ Storage* storage,
+ LoadRulesDelegate* load_rules_delegate);
+ ~AddressValidator();
+
+ // Loads the generic validation rules for |country_code| and specific rules
+ // for the country's administrative areas, localities, and dependent
+ // localities. A typical data size is 10KB. The largest is 250KB. If a country
+ // has language-specific validation rules, then these are also loaded.
+ //
+ // If the rules were loaded successfully before, then does nothing. Notifies
+ // |load_rules_delegate| when the loading finishes.
+ void LoadRules(const std::string& country_code);
+
+ // Validates the |address| and populates |problems| with the validation
+ // problems, filtered according to the |filter| parameter.
+ //
+ // If the |filter| is empty, then all discovered validation problems are
+ // returned. If the |filter| contains problem elements, then only the problems
+ // in the |filter| may be returned.
+ //
+ // If the |problems| parameter is NULL, then checks whether the validation
+ // rules are available, but does not validate the |address|.
+ Status ValidateAddress(const AddressData& address,
+ const AddressProblemFilter& filter,
+ const Localization& localization,
+ AddressProblems* problems) const;
+ private:
+ scoped_ptr<RuleRetriever> rule_retriever_;
+ LoadRulesDelegate* load_rules_delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(AddressValidator);
+};
+
+} // namespace addressinput
+} // namespace i18n
+
+#endif // I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_
diff --git a/third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h
new file mode 100644
index 0000000..cb56fba
--- /dev/null
+++ b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h
@@ -0,0 +1,43 @@
+// Copyright (C) 2013 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef I18N_ADDRESSINPUT_LOAD_RULES_DELEGATE_H_
+#define I18N_ADDRESSINPUT_LOAD_RULES_DELEGATE_H_
+
+#include <string>
+
+namespace i18n {
+namespace addressinput {
+
+// The object to be notified when loading of address validation rules is
+// finished.
+class LoadRulesDelegate {
+ public:
+ virtual ~LoadRulesDelegate() {}
+
+ // Called when the validation rules for the |country_code| have been loaded.
+ // The validation rules include the generic rules for the |country_code| and
+ // specific rules for the country's administrative areas, localities, and
+ // dependent localities. If a country has language-specific validation rules,
+ // then these are also loaded.
+ //
+ // The |success| parameter is true when the rules were loaded successfully.
+ virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
+ bool success) = 0;
+};
+
+} // namespace addressinput
+} // namespace i18n
+
+#endif // I18N_ADDRESSINPUT_LOAD_RULES_DELEGATE_H_
diff --git a/third_party/libaddressinput/chromium/cpp/libaddressinput.gyp b/third_party/libaddressinput/chromium/cpp/libaddressinput.gyp
index ff9c86a..f1614b5 100644
--- a/third_party/libaddressinput/chromium/cpp/libaddressinput.gyp
+++ b/third_party/libaddressinput/chromium/cpp/libaddressinput.gyp
@@ -35,6 +35,7 @@
'src/address_field_util.cc',
'src/address_problem.cc',
'src/address_ui.cc',
+ 'src/address_validator.cc',
'src/localization.cc',
'src/lookup_key_util.cc',
'src/region_data_constants.cc',
@@ -46,6 +47,9 @@
'src/validating_storage.cc',
'src/validating_util.cc',
],
+ 'defines': [
+ 'VALIDATION_DATA_URL="https://i18napis.appspot.com/ssl-address/"',
+ ],
'dependencies': [
'grit.gyp:generated_messages',
'rapidjson.gyp:rapidjson',
diff --git a/third_party/libaddressinput/chromium/cpp/src/address_validator.cc b/third_party/libaddressinput/chromium/cpp/src/address_validator.cc
new file mode 100644
index 0000000..011396d
--- /dev/null
+++ b/third_party/libaddressinput/chromium/cpp/src/address_validator.cc
@@ -0,0 +1,51 @@
+// Copyright (C) 2013 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <libaddressinput/address_validator.h>
+
+#include <libaddressinput/downloader.h>
+#include <libaddressinput/load_rules_delegate.h>
+#include <libaddressinput/localization.h>
+#include <libaddressinput/storage.h>
+
+#include <string>
+
+#include "retriever.h"
+#include "rule_retriever.h"
+#include "validating_storage.h"
+
+namespace i18n {
+namespace addressinput {
+
+AddressValidator::AddressValidator(const Downloader* downloader,
+ Storage* storage,
+ LoadRulesDelegate* load_rules_delegate)
+ : rule_retriever_(new RuleRetriever(new Retriever(
+ VALIDATION_DATA_URL, downloader, new ValidatingStorage(storage)))),
+ load_rules_delegate_(load_rules_delegate) {}
+
+AddressValidator::~AddressValidator() {}
+
+void AddressValidator::LoadRules(const std::string& country_code) {}
+
+AddressValidator::Status AddressValidator::ValidateAddress(
+ const AddressData& address,
+ const AddressProblemFilter& filter,
+ const Localization& localization,
+ AddressProblems* problems) const {
+ return RULES_UNAVAILABLE;
+}
+
+} // namespace addressinput
+} // namespace i18n
diff --git a/third_party/libaddressinput/libaddressinput.gyp b/third_party/libaddressinput/libaddressinput.gyp
index b8ddf96..adf3785 100644
--- a/third_party/libaddressinput/libaddressinput.gyp
+++ b/third_party/libaddressinput/libaddressinput.gyp
@@ -51,6 +51,8 @@
'<(libaddressinput_dir)/cpp/include/libaddressinput/address_problem.h',
'<(libaddressinput_dir)/cpp/include/libaddressinput/address_ui_component.h',
'<(libaddressinput_dir)/cpp/include/libaddressinput/address_ui.h',
+ '<(libaddressinput_dir)/cpp/include/libaddressinput/address_validator.h',
+ '<(libaddressinput_dir)/cpp/include/libaddressinput/load_rules_delegate.h',
'<(libaddressinput_dir)/cpp/include/libaddressinput/localization.h',
'<(libaddressinput_dir)/cpp/include/libaddressinput/util/basictypes.h',
'<(libaddressinput_dir)/cpp/include/libaddressinput/util/scoped_ptr.h',
@@ -60,6 +62,7 @@
'<(libaddressinput_dir)/cpp/src/address_field_util.h',
'<(libaddressinput_dir)/cpp/src/address_problem.cc',
'<(libaddressinput_dir)/cpp/src/address_ui.cc',
+ '<(libaddressinput_dir)/cpp/src/address_validator.cc',
'<(libaddressinput_dir)/cpp/src/grit.h',
'<(libaddressinput_dir)/cpp/src/localization.cc',
'<(libaddressinput_dir)/cpp/src/lookup_key_util.cc',
@@ -80,6 +83,9 @@
'<(libaddressinput_dir)/cpp/src/validating_util.cc',
'<(libaddressinput_dir)/cpp/src/validating_util.h',
],
+ 'defines': [
+ 'VALIDATION_DATA_URL="https://i18napis.appspot.com/ssl-address/"',
+ ],
'dependencies': [
'generated_messages',
'<(DEPTH)/base/base.gyp:base',