#include "browser/autofill/personal_data_manager_factory.h"
-#include "eweb_view.h"
#include "base/memory/scoped_ptr.h"
#include "browser/webdata/web_data_service_factory.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/common/content_client_export.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/common/content_client.h"
namespace autofill {
+
// static
PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
return base::Singleton<PersonalDataManagerFactory>::get();
if (ctx) {
uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
PersonalDataManager* mgr = personal_data_manager_id_map_.Lookup(uniqueId);
-
if (!mgr) {
// TODO: LOCALE!
PrefService* srv = user_prefs::UserPrefs::Get(ctx);
}
void PersonalDataManagerFactory::PersonalDataManagerRemove(content::BrowserContext* ctx) {
- uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
- personal_data_manager_id_map_.Remove(uniqueId);
+ uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
+ personal_data_manager_id_map_.Remove(uniqueId);
}
PersonalDataManager* PersonalDataManagerFactory::PersonalDataManagerForContext(
content::BrowserContext* ctx) {
- uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
- return personal_data_manager_id_map_.Lookup(uniqueId);
-}
-
-int PersonalDataManagerFactory::GetProfileCount(
- content::BrowserContext* ctx) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- return mgr->GetProfiles().size();
- return 0;
-}
-
-AutofillProfile* PersonalDataManagerFactory::GetProfileByIndex(
- content::BrowserContext* ctx, int index) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr) {
- const std::vector<AutofillProfile*>& profiles = mgr->GetProfiles();
- size_t index_size_t = static_cast<size_t>(index);
- DCHECK_LT(index_size_t, profiles.size());
- return (profiles[index_size_t]);
- }
- return NULL;
-}
-
-void PersonalDataManagerFactory::AddProfile(content::BrowserContext* ctx, const AutofillProfile& profile) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- mgr->AddProfile(profile);
-}
-
-void PersonalDataManagerFactory::UpdateProfile(content::BrowserContext* ctx, const AutofillProfile& profile) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- mgr->UpdateProfile(profile);
-}
-
-void PersonalDataManagerFactory::RemoveByGUID(content::BrowserContext* ctx, const std::string& guid) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- mgr->RemoveByGUID(guid);
-}
-
-AutofillProfile* PersonalDataManagerFactory::GetProfileByGUID(content::BrowserContext* ctx, const std::string& guid) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- return mgr->GetProfileByGUID(guid);
-
- return NULL;
-}
-
-void PersonalDataManagerFactory::AddCreditCard(content::BrowserContext* ctx, const CreditCard& credit_card) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- mgr->AddCreditCard(credit_card);
-}
-
-void PersonalDataManagerFactory::UpdateCreditCard(content::BrowserContext* ctx, const CreditCard& credit_card) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- mgr->UpdateCreditCard(credit_card);
-}
-
-CreditCard* PersonalDataManagerFactory::GetCreditCardByGUID(content::BrowserContext* ctx, const std::string& guid) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- return mgr->GetCreditCardByGUID(guid);
-
- return NULL;
-}
-
-int PersonalDataManagerFactory::GetCreditCardCount(content::BrowserContext* ctx) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr)
- return mgr->GetCreditCards().size();
-
- return 0;
-}
-
-CreditCard* PersonalDataManagerFactory::GetCreditCardByIndex(content::BrowserContext* ctx, int index) {
- PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
- if (mgr) {
- const std::vector<CreditCard*>& credit_cards = mgr->GetCreditCards();
- size_t index_size_t = static_cast<size_t>(index);
- DCHECK_LT(index_size_t, credit_cards.size());
- return (credit_cards[index_size_t]);
- }
- return NULL;
+ uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
+ return personal_data_manager_id_map_.Lookup(uniqueId);
}
PersonalDataManagerFactory::PersonalDataManagerFactory()
PersonalDataManager* PersonalDataManagerForContext(
content::BrowserContext* ctx);
- // Returns the number of web and auxiliary profiles.
- int GetProfileCount(content::BrowserContext* mgr);
-
- // Returns the profile with specified |index|
- AutofillProfile* GetProfileByIndex(content::BrowserContext* mgr, int index);
-
- // Adds |profile| to the web database.
- void AddProfile(content::BrowserContext* mgr, const AutofillProfile& profile);
-
- // Updates |profile| which already exists in the web database.
- void UpdateProfile(content::BrowserContext* mgr,
- const AutofillProfile& profile);
-
- // Removes the profile or credit card represented by |guid|.
- void RemoveByGUID(content::BrowserContext* mgr, const std::string& guid);
-
- // Returns the profile with the specified |guid|, or NULL if there is no
- // profile with the specified |guid|. Both web and auxiliary profiles may
- // be returned.
- AutofillProfile* GetProfileByGUID(content::BrowserContext* mgr,
- const std::string& guid);
-
- // Returns the number of web and auxiliary CC.
- int GetCreditCardCount(content::BrowserContext* mgr);
-
- // Returns the credit card with specified |index|
- CreditCard* GetCreditCardByIndex(content::BrowserContext* mgr, int index);
-
- // Adds |credit_card| to the web database.
- void AddCreditCard(content::BrowserContext* mgr,
- const CreditCard& credit_card);
-
- // Updates |credit_card| which already exists in the web database.
- void UpdateCreditCard(content::BrowserContext* mgr,
- const CreditCard& credit_card);
-
- // Returns the credit card with the specified |guid|, or NULL if there is
- // no credit card with the specified |guid|.
- CreditCard* GetCreditCardByGUID(content::BrowserContext* mgr,
- const std::string& guid);
-
void SetCallback(Ewk_Context_Form_Autofill_Profile_Changed_Callback callback,
void* user_data);
return ret;
}
+autofill::PersonalDataManager* PersonalDataManagerForEWKContext(
+ Ewk_Context* ewk_context) {
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, nullptr);
-Eina_List*
-EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get_all(
- Ewk_Context* context) {
- EINA_SAFETY_ON_NULL_RETURN_VAL(context, nullptr);
- autofill::PersonalDataManagerFactory* dataManagerFactory =
+ autofill::PersonalDataManagerFactory* personal_data_manager_factory =
autofill::PersonalDataManagerFactory::GetInstance();
+ content::BrowserContext* context = ewk_context->browser_context();
+ EINA_SAFETY_ON_NULL_RETURN_VAL(context, nullptr);
- autofill::PersonalDataManager* dataManager =
- dataManagerFactory->PersonalDataManagerForContext(
- context->browser_context());
+ return personal_data_manager_factory->PersonalDataManagerForContext(context);
+}
+Eina_List*
+EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get_all(
+ Ewk_Context* ewk_context) {
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, nullptr);
+
+ autofill::PersonalDataManager* manager =
+ PersonalDataManagerForEWKContext(ewk_context);
+ DCHECK(manager);
- EINA_SAFETY_ON_NULL_RETURN_VAL(dataManager, nullptr);
std::vector<autofill::AutofillProfile*> dataVector =
- dataManager->GetProfiles();
+ manager->GetProfiles();
Eina_List* list = nullptr;
for (unsigned i = 0; i < dataVector.size(); ++i) {
autofill::AutofillProfile* profile = dataVector[i];
Ewk_Autofill_Profile*
EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get(
- Ewk_Context* context, unsigned id) {
- EINA_SAFETY_ON_NULL_RETURN_VAL(context, nullptr);
- autofill::PersonalDataManagerFactory* dataManagerFactory =
- autofill::PersonalDataManagerFactory::GetInstance();
+ Ewk_Context* ewk_context, unsigned id) {
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, nullptr);
+
+ autofill::PersonalDataManager* manager =
+ PersonalDataManagerForEWKContext(ewk_context);
+ DCHECK(manager);
+
+ autofill::AutofillProfile* profile = manager->GetProfileByGUID(UnsignedToGUID(id));
- autofill::AutofillProfile* profile =
- dataManagerFactory->GetProfileByGUID(context->browser_context(),
- UnsignedToGUID(id));
Ewk_Autofill_Profile* ret = nullptr;
if (profile)
ret = to_Ewk_Autofill_Profile(*profile);
}
Eina_Bool EwkContextFormAutofillProfileManager::priv_form_autofill_profile_set(
- Ewk_Context* context,
- unsigned id, Ewk_Autofill_Profile* profile) {
- autofill::PersonalDataManagerFactory* personalDataManagerFactory =
- autofill::PersonalDataManagerFactory::GetInstance();
- content::BrowserContext* ctx = context->browser_context();
- EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
-
+ Ewk_Context* ewk_context,
+ unsigned id, Ewk_Autofill_Profile* ewk_profile) {
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, EINA_FALSE);
- // check if such profile already exists
- if (personalDataManagerFactory->GetProfileByGUID(ctx, UnsignedToGUID(id))) {
- personalDataManagerFactory->UpdateProfile(ctx,
- to_Autofill_Profile(profile));
- } else {
- personalDataManagerFactory->AddProfile(ctx, to_Autofill_Profile(profile));
- }
+ autofill::PersonalDataManager* manager =
+ PersonalDataManagerForEWKContext(ewk_context);
+ DCHECK(manager);
+ autofill::AutofillProfile* profile = manager->GetProfileByGUID(UnsignedToGUID(id));
+ if (profile)
+ manager->UpdateProfile(to_Autofill_Profile(ewk_profile));
+ else
+ manager->AddProfile(to_Autofill_Profile(ewk_profile));
return EINA_TRUE;
}
Eina_Bool EwkContextFormAutofillProfileManager::priv_form_autofill_profile_add(
- Ewk_Context* context, Ewk_Autofill_Profile* profile) {
- autofill::PersonalDataManagerFactory* personalDataManagerFactory =
- autofill::PersonalDataManagerFactory::GetInstance();
- personalDataManagerFactory->AddProfile(
- context->browser_context(), to_Autofill_Profile(profile));
+ Ewk_Context* ewk_context, Ewk_Autofill_Profile* profile) {
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, EINA_FALSE);
+
+ autofill::PersonalDataManager* manager =
+ PersonalDataManagerForEWKContext(ewk_context);
+ DCHECK(manager);
+
+ manager->AddProfile(to_Autofill_Profile(profile));
return EINA_TRUE;
}
Eina_Bool
EwkContextFormAutofillProfileManager::priv_form_autofill_profile_remove(
- Ewk_Context* context, unsigned id) {
- autofill::PersonalDataManagerFactory* personalDataManagerFactory =
- autofill::PersonalDataManagerFactory::GetInstance();
- personalDataManagerFactory->RemoveByGUID(context->browser_context(),
- UnsignedToGUID(id));
+ Ewk_Context* ewk_context, unsigned id) {
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, EINA_FALSE);
+
+ autofill::PersonalDataManager* manager =
+ PersonalDataManagerForEWKContext(ewk_context);
+ DCHECK(manager);
+
+ manager->RemoveByGUID(UnsignedToGUID(id));
return EINA_TRUE;
}