Search in sources :

Example 6 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class PaymentRequestImpl method init.

/**
 * Called by the merchant website to initialize the payment request data.
 */
@Override
public void init(PaymentRequestClient client, PaymentMethodData[] methodData, PaymentDetails details, PaymentOptions options) {
    if (mClient != null || client == null)
        return;
    mClient = client;
    if (mMethodData != null) {
        disconnectFromClientWithDebugMessage("PaymentRequest.show() called more than once.");
        recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERER);
        return;
    }
    mMethodData = getValidatedMethodData(methodData, mCardEditor);
    if (mMethodData == null) {
        disconnectFromClientWithDebugMessage("Invalid payment methods or data");
        recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERER);
        return;
    }
    if (!parseAndValidateDetailsOrDisconnectFromClient(details))
        return;
    getMatchingPaymentInstruments();
    boolean requestShipping = options != null && options.requestShipping;
    boolean requestPayerName = options != null && options.requestPayerName;
    boolean requestPayerPhone = options != null && options.requestPayerPhone;
    boolean requestPayerEmail = options != null && options.requestPayerEmail;
    List<AutofillProfile> profiles = null;
    if (requestShipping || requestPayerName || requestPayerPhone || requestPayerEmail) {
        profiles = PersonalDataManager.getInstance().getProfilesToSuggest(false);
    }
    if (requestShipping) {
        List<AutofillAddress> addresses = new ArrayList<>();
        for (int i = 0; i < profiles.size(); i++) {
            AutofillProfile profile = profiles.get(i);
            mAddressEditor.addPhoneNumberIfValid(profile.getPhoneNumber());
            // Only suggest addresses that have a street address.
            if (!TextUtils.isEmpty(profile.getStreetAddress())) {
                addresses.add(new AutofillAddress(mContext, profile));
            }
        }
        // Suggest complete addresses first.
        Collections.sort(addresses, COMPLETENESS_COMPARATOR);
        // Limit the number of suggestions.
        addresses = addresses.subList(0, Math.min(addresses.size(), SUGGESTIONS_LIMIT));
        // Load the validation rules for each unique region code.
        Set<String> uniqueCountryCodes = new HashSet<>();
        for (int i = 0; i < addresses.size(); ++i) {
            String countryCode = AutofillAddress.getCountryCode(addresses.get(i).getProfile());
            if (!uniqueCountryCodes.contains(countryCode)) {
                uniqueCountryCodes.add(countryCode);
                PersonalDataManager.getInstance().loadRulesForRegion(countryCode);
            }
        }
        // Log the number of suggested shipping addresses.
        mJourneyLogger.setNumberOfSuggestionsShown(PaymentRequestJourneyLogger.SECTION_SHIPPING_ADDRESS, addresses.size());
        // Automatically select the first address if one is complete and if the merchant does
        // not require a shipping address to calculate shipping costs.
        int firstCompleteAddressIndex = SectionInformation.NO_SELECTION;
        if (mUiShippingOptions.getSelectedItem() != null && !addresses.isEmpty() && addresses.get(0).isComplete()) {
            firstCompleteAddressIndex = 0;
        }
        mShippingAddressesSection = new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, firstCompleteAddressIndex, addresses);
    }
    if (requestPayerName || requestPayerPhone || requestPayerEmail) {
        Set<String> uniqueContactInfos = new HashSet<>();
        mContactEditor = new ContactEditor(requestPayerName, requestPayerPhone, requestPayerEmail);
        List<AutofillContact> contacts = new ArrayList<>();
        for (int i = 0; i < profiles.size(); i++) {
            AutofillProfile profile = profiles.get(i);
            String name = requestPayerName && !TextUtils.isEmpty(profile.getFullName()) ? profile.getFullName() : null;
            String phone = requestPayerPhone && !TextUtils.isEmpty(profile.getPhoneNumber()) ? profile.getPhoneNumber() : null;
            String email = requestPayerEmail && !TextUtils.isEmpty(profile.getEmailAddress()) ? profile.getEmailAddress() : null;
            mContactEditor.addPayerNameIfValid(name);
            mContactEditor.addPhoneNumberIfValid(phone);
            mContactEditor.addEmailAddressIfValid(email);
            if (name != null || phone != null || email != null) {
                // Different profiles can have identical contact info. Do not add the same
                // contact info to the list twice.
                String uniqueContactInfo = name + phone + email;
                if (!uniqueContactInfos.contains(uniqueContactInfo)) {
                    uniqueContactInfos.add(uniqueContactInfo);
                    boolean isComplete = mContactEditor.isContactInformationComplete(name, phone, email);
                    contacts.add(new AutofillContact(profile, name, phone, email, isComplete));
                }
            }
        }
        // Suggest complete contact infos first.
        Collections.sort(contacts, COMPLETENESS_COMPARATOR);
        // Limit the number of suggestions.
        contacts = contacts.subList(0, Math.min(contacts.size(), SUGGESTIONS_LIMIT));
        // Log the number of suggested contact infos.
        mJourneyLogger.setNumberOfSuggestionsShown(PaymentRequestJourneyLogger.SECTION_CONTACT_INFO, contacts.size());
        // Automatically select the first address if it is complete.
        int firstCompleteContactIndex = SectionInformation.NO_SELECTION;
        if (!contacts.isEmpty() && contacts.get(0).isComplete()) {
            firstCompleteContactIndex = 0;
        }
        mContactSection = new SectionInformation(PaymentRequestUI.TYPE_CONTACT_DETAILS, firstCompleteContactIndex, contacts);
    }
    mUI = new PaymentRequestUI(mContext, this, requestShipping, requestPayerName || requestPayerPhone || requestPayerEmail, mMerchantSupportsAutofillPaymentInstruments, mMerchantName, mOrigin, new ShippingStrings(options == null ? PaymentShippingType.SHIPPING : options.shippingType));
    if (mFavicon != null)
        mUI.setTitleBitmap(mFavicon);
    mFavicon = null;
    mAddressEditor.setEditorView(mUI.getEditorView());
    mCardEditor.setEditorView(mUI.getCardEditorView());
    if (mContactEditor != null)
        mContactEditor.setEditorView(mUI.getEditorView());
    PaymentRequestMetrics.recordRequestedInformationHistogram(requestPayerEmail, requestPayerPhone, requestShipping, requestPayerName);
}
Also used : SectionInformation(org.chromium.chrome.browser.payments.ui.SectionInformation) ArrayList(java.util.ArrayList) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) PaymentRequestUI(org.chromium.chrome.browser.payments.ui.PaymentRequestUI) HashSet(java.util.HashSet)

Example 7 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AutofillProfileEditor method saveEntry.

// Read edited data; save in the associated Chrome profile.
// Ignore empty fields.
@Override
protected boolean saveEntry() {
    AutofillProfile profile = new PersonalDataManager.AutofillProfile(mGUID, AutofillPreferences.SETTINGS_ORIGIN, true, /* isLocal */
    getFieldText(AddressField.RECIPIENT), getFieldText(AddressField.ORGANIZATION), getFieldText(AddressField.STREET_ADDRESS), getFieldText(AddressField.ADMIN_AREA), getFieldText(AddressField.LOCALITY), getFieldText(AddressField.DEPENDENT_LOCALITY), getFieldText(AddressField.POSTAL_CODE), getFieldText(AddressField.SORTING_CODE), mCountryCodes.get(mCurrentCountryPos), mPhoneText.getText().toString(), mEmailText.getText().toString(), mLanguageCodeString);
    PersonalDataManager.getInstance().setProfile(profile);
    return true;
}
Also used : AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)

Example 8 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AutofillCreditCardEditor method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = super.onCreateView(inflater, container, savedInstanceState);
    // Populate the billing address dropdown.
    ArrayAdapter<AutofillProfile> profilesAdapter = new ArrayAdapter<AutofillProfile>(getActivity(), android.R.layout.simple_spinner_item);
    profilesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    AutofillProfile noSelection = new AutofillProfile();
    noSelection.setLabel(getActivity().getString(R.string.select));
    profilesAdapter.add(noSelection);
    List<AutofillProfile> profiles = PersonalDataManager.getInstance().getProfilesForSettings();
    for (int i = 0; i < profiles.size(); i++) {
        AutofillProfile profile = profiles.get(i);
        if (profile.getIsLocal())
            profilesAdapter.add(profile);
    }
    mBillingAddress = (Spinner) v.findViewById(R.id.autofill_credit_card_editor_billing_address_spinner);
    mBillingAddress.setAdapter(profilesAdapter);
    // http://crbug.com/623629
    if (profilesAdapter.getCount() == 1)
        mBillingAddress.setEnabled(false);
    mCard = PersonalDataManager.getInstance().getCreditCard(mGUID);
    if (mCard != null) {
        if (!TextUtils.isEmpty(mCard.getBillingAddressId())) {
            for (int i = 0; i < mBillingAddress.getAdapter().getCount(); i++) {
                AutofillProfile profile = (AutofillProfile) mBillingAddress.getAdapter().getItem(i);
                if (TextUtils.equals(profile.getGUID(), mCard.getBillingAddressId())) {
                    mInitialBillingAddressPos = i;
                    mBillingAddress.setSelection(i);
                    break;
                }
            }
        }
    }
    return v;
}
Also used : AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter)

Example 9 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AutofillPaymentApp method getInstruments.

@Override
public void getInstruments(JSONObject unusedDetails, final InstrumentsCallback callback) {
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    List<CreditCard> cards = pdm.getCreditCardsToSuggest();
    final List<PaymentInstrument> instruments = new ArrayList<>(cards.size());
    for (int i = 0; i < cards.size(); i++) {
        CreditCard card = cards.get(i);
        AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId());
        instruments.add(new AutofillPaymentInstrument(mWebContents, card, billingAddress));
    }
    new Handler().post(new Runnable() {

        @Override
        public void run() {
            callback.onInstrumentsReady(AutofillPaymentApp.this, instruments);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 10 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AutofillPaymentApp method getInstruments.

@Override
public void getInstruments(Map<String, PaymentMethodData> unusedMethodData, final InstrumentsCallback callback) {
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    List<CreditCard> cards = pdm.getCreditCardsToSuggest();
    final List<PaymentInstrument> instruments = new ArrayList<>(cards.size());
    for (int i = 0; i < cards.size(); i++) {
        CreditCard card = cards.get(i);
        AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId());
        if (billingAddress != null && AutofillAddress.checkAddressCompletionStatus(billingAddress) != AutofillAddress.COMPLETE) {
            billingAddress = null;
        }
        instruments.add(new AutofillPaymentInstrument(mContext, mWebContents, card, billingAddress));
    }
    new Handler().post(new Runnable() {

        @Override
        public void run() {
            callback.onInstrumentsReady(AutofillPaymentApp.this, instruments);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Aggregations

AutofillProfile (org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)10 ArrayList (java.util.ArrayList)3 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 Preference (android.preference.Preference)2 PersonalDataManager (org.chromium.chrome.browser.autofill.PersonalDataManager)2 CreditCard (org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)2 EditorFieldModel (org.chromium.chrome.browser.payments.ui.EditorFieldModel)2 EditorModel (org.chromium.chrome.browser.payments.ui.EditorModel)2 PreferenceGroup (android.preference.PreferenceGroup)1 Pair (android.util.Pair)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 PaymentRequestUI (org.chromium.chrome.browser.payments.ui.PaymentRequestUI)1 SectionInformation (org.chromium.chrome.browser.payments.ui.SectionInformation)1 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)1 AutofillProfileBridge (org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge)1