org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile Java Examples

The following examples show how to use org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutofillLocalCardEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    PersonalDataManager personalDataManager = PersonalDataManager.getInstance();
    // Issuer network will be empty if credit card number is not valid.
    if (TextUtils.isEmpty(personalDataManager.getBasicCardIssuerNetwork(
                cardNumber, true /* emptyIfInvalid */))) {
        mNumberLabel.setError(mContext.getString(
                R.string.payments_card_number_invalid_validation_message));
        return false;
    }
    CreditCard card = new CreditCard(mGUID, AutofillAndPaymentsPreferences.SETTINGS_ORIGIN,
            true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(),
            cardNumber, "" /* obfuscatedNumber */,
            String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1),
            (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
            0 /* issuerIconDrawableId */,
            ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */,
            "" /* serverId */);
    personalDataManager.setCreditCard(card);
    return true;
}
 
Example #2
Source File: AutofillPaymentInstrument.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the instrument and marks it "complete." Called after the user has edited this
 * instrument.
 *
 * @param card           The new credit card to use. The GUID should not change.
 * @param methodName     The payment method name to use for this instrument, e.g., "visa",
 *                       "basic-card".
 * @param billingAddress The billing address for the card. The GUID should match the billing
 *                       address ID of the new card to use.
 */
public void completeInstrument(
        CreditCard card, String methodName, AutofillProfile billingAddress) {
    assert card != null;
    assert methodName != null;
    assert billingAddress != null;
    assert card.getBillingAddressId() != null;
    assert card.getBillingAddressId().equals(billingAddress.getGUID());
    assert card.getIssuerIconDrawableId() != 0;
    assert AutofillAddress.checkAddressCompletionStatus(
            billingAddress, AutofillAddress.IGNORE_PHONE_COMPLETENESS_CHECK)
            == AutofillAddress.COMPLETE;

    mCard = card;
    mMethodName = methodName;
    mBillingAddress = billingAddress;

    Context context = ChromeActivity.fromWebContents(mWebContents);
    if (context == null) return;

    updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber(), card.getName(),
            null, AppCompatResources.getDrawable(context, card.getIssuerIconDrawableId()));
    checkAndUpateCardCompleteness(context);
    assert mIsComplete;
    assert mHasValidNumberAndName;
}
 
Example #3
Source File: AutofillPreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example #4
Source File: AutofillPaymentInstrument.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a payment instrument for the given credit card.
 *
 * @param webContents    The web contents where PaymentRequest was invoked.
 * @param card           The autofill card that can be used for payment.
 * @param billingAddress The billing address for the card.
 * @param methodName     The payment method name, e.g., "basic-card", "visa", amex", or null.
 */
public AutofillPaymentInstrument(WebContents webContents, CreditCard card,
        @Nullable AutofillProfile billingAddress, @Nullable String methodName) {
    super(card.getGUID(), card.getObfuscatedNumber(), card.getName(), null);
    mWebContents = webContents;
    mCard = card;
    mBillingAddress = billingAddress;
    mIsEditable = true;
    mMethodName = methodName;

    Context context = ChromeActivity.fromWebContents(mWebContents);
    if (context == null) return;

    if (card.getIssuerIconDrawableId() != 0) {
        updateDrawableIcon(
                AppCompatResources.getDrawable(context, card.getIssuerIconDrawableId()));
    }

    checkAndUpateCardCompleteness(context);
}
 
Example #5
Source File: AutofillPaymentInstrument.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the instrument and marks it "complete." Called after the user has edited this
 * instrument.
 *
 * @param card           The new credit card to use. The GUID should not change.
 * @param billingAddress The billing address for the card. The GUID should match the billing
 *                       address ID of the new card to use.
 */
public void completeInstrument(CreditCard card, AutofillProfile billingAddress) {
    assert card != null;
    assert billingAddress != null;
    assert card.getBillingAddressId() != null;
    assert card.getBillingAddressId().equals(billingAddress.getGUID());
    assert card.getIssuerIconDrawableId() != 0;
    assert AutofillAddress.checkAddressCompletionStatus(billingAddress)
            == AutofillAddress.COMPLETE;

    mCard = card;
    mBillingAddress = billingAddress;
    updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber(), card.getName(),
            null, ApiCompatibilityUtils.getDrawable(
                          mContext.getResources(), card.getIssuerIconDrawableId()));
    checkAndUpateCardCompleteness();
    assert mIsComplete;
    assert mHasValidNumberAndName;
}
 
Example #6
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onAddressNormalized(AutofillProfile profile) {
    ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);

    // Can happen if the tab is closed during the normalization process.
    if (chromeActivity == null) {
        mJourneyLogger.setAborted(AbortReason.OTHER);
        disconnectFromClientWithDebugMessage("Unable to find Chrome activity");
        if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
        return;
    }

    // Don't reuse the selected address because it is formatted for display.
    AutofillAddress shippingAddress = new AutofillAddress(chromeActivity, profile);

    // This updates the line items and the shipping options asynchronously.
    mClient.onShippingAddressChange(shippingAddress.toPaymentAddress());
}
 
Example #7
Source File: CardEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the given billing address to the list of billing addresses, if it's complete. If the
 * address is already known, then updates the existing address. Should be called before opening
 * the card editor.
 *
 * @param billingAddress The billing address to add or update. Should not be null.
 */
public void updateBillingAddressIfComplete(AutofillAddress billingAddress) {
    if (!billingAddress.isComplete()) return;

    for (int i = 0; i < mProfilesForBillingAddress.size(); ++i) {
        if (TextUtils.equals(mProfilesForBillingAddress.get(i).getGUID(),
                    billingAddress.getIdentifier())) {
            mProfilesForBillingAddress.set(i, billingAddress.getProfile());
            mIncompleteProfilesForBillingAddress.remove(billingAddress.getIdentifier());
            return;
        }
    }

    // No matching profile was found. Add the new profile at the top of the list.
    billingAddress.setBillingAddressLabel();
    mProfilesForBillingAddress.add(0, new AutofillProfile(billingAddress.getProfile()));
}
 
Example #8
Source File: ContactDetailsSection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Nullable
private AutofillContact createAutofillContactFromProfile(AutofillProfile profile) {
    boolean requestPayerName = mContactEditor.getRequestPayerName();
    boolean requestPayerPhone = mContactEditor.getRequestPayerPhone();
    boolean requestPayerEmail = mContactEditor.getRequestPayerEmail();
    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;

    if (name != null || phone != null || email != null) {
        @ContactEditor.CompletionStatus
        int completionStatus = mContactEditor.checkContactCompletionStatus(name, phone, email);
        return new AutofillContact(mContext, profile, name, phone, email, completionStatus,
                requestPayerName, requestPayerPhone, requestPayerEmail);
    }
    return null;
}
 
Example #9
Source File: AutofillLocalCardEditor.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    PersonalDataManager personalDataManager = PersonalDataManager.getInstance();
    // Card Payment Type will be empty if credit card number is not valid.
    if (TextUtils.isEmpty(personalDataManager.getBasicCardPaymentType(cardNumber,
            true /* emptyIfInvalid */))) {
        mNumberLabel.setError(mContext.getString(
                R.string.payments_card_number_invalid_validation_message));
        return false;
    }
    CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN,
            true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(),
            cardNumber, "" /* obfuscatedNumber */,
            String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1),
            (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
            0 /* issuerIconDrawableId */,
            ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */,
            "" /* serverId */);
    personalDataManager.setCreditCard(card);
    return true;
}
 
Example #10
Source File: AutofillPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example #11
Source File: AutofillPaymentApp.java    From delion with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example #12
Source File: AutofillAddress.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Checks address completion status in the given profile.
 *
 * If the country code is not set or invalid, but all fields for the default locale's country
 * code are present, then the profile is deemed "complete." AutoflllAddress.toPaymentAddress()
 * will use the default locale to fill in a blank country code before sending the address to the
 * renderer.
 *
 * @param  profile The autofill profile containing the address information.
 * @return int     The completion status.
 */
@CompletionStatus
public static int checkAddressCompletionStatus(
        AutofillProfile profile, @CompletenessCheckType int checkType) {
    int invalidFieldsCount = 0;
    int completionStatus = COMPLETE;

    if (checkType != IGNORE_PHONE_COMPLETENESS_CHECK
            && !PhoneNumberUtils.isGlobalPhoneNumber(
                       PhoneNumberUtils.stripSeparators(profile.getPhoneNumber().toString()))) {
        completionStatus = INVALID_PHONE_NUMBER;
        invalidFieldsCount++;
    }

    List<Integer> requiredFields = AutofillProfileBridge.getRequiredAddressFields(
            AutofillAddress.getCountryCode(profile));
    for (int fieldId : requiredFields) {
        if (fieldId == AddressField.RECIPIENT || fieldId == AddressField.COUNTRY) continue;
        if (!TextUtils.isEmpty(getProfileField(profile, fieldId))) continue;
        completionStatus = INVALID_ADDRESS;
        invalidFieldsCount++;
        break;
    }

    if (TextUtils.isEmpty(profile.getFullName())) {
        completionStatus = INVALID_RECIPIENT;
        invalidFieldsCount++;
    }

    if (invalidFieldsCount > 1) {
        completionStatus = INVALID_MULTIPLE_FIELDS;
    }

    return completionStatus;
}
 
Example #13
Source File: AutofillAddress.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the address and marks it "complete." Called after the user has edited this address.
 * Updates the identifier and labels.
 *
 * @param profile The new profile to use.
 */
public void completeAddress(AutofillProfile profile) {
    // Since the profile changed, our cached labels are now out of date. Set them to null so the
    // labels are recomputed next time they are needed.
    mShippingLabelWithCountry = null;
    mShippingLabelWithoutCountry = null;
    mBillingLabel = null;

    mProfile = profile;
    updateIdentifierAndLabels(mProfile.getGUID(), mProfile.getFullName(), mProfile.getLabel(),
            mProfile.getPhoneNumber());
    checkAndUpdateAddressCompleteness();
    assert mIsComplete;
}
 
Example #14
Source File: AutofillAddress.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the autofill address.
 *
 * @param profile The autofill profile containing the address information.
 */
public AutofillAddress(Context context, AutofillProfile profile) {
    super(profile.getGUID(), profile.getFullName(), profile.getLabel(),
            profile.getPhoneNumber(), null);
    mContext = context;
    mProfile = profile;
    mIsEditable = true;
    checkAndUpdateAddressCompleteness();
}
 
Example #15
Source File: AutofillAddress.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** @return The country code to use, e.g., when constructing an editor for this address. */
public static String getCountryCode(@Nullable AutofillProfile profile) {
    if (sRegionCodePattern == null) sRegionCodePattern = Pattern.compile(REGION_CODE_PATTERN);

    return profile == null || TextUtils.isEmpty(profile.getCountryCode())
                    || !sRegionCodePattern.matcher(profile.getCountryCode()).matches()
            ? Locale.getDefault().getCountry() : profile.getCountryCode();
}
 
Example #16
Source File: AutofillAddress.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** @return The given autofill profile field. */
public static String getProfileField(AutofillProfile profile, int field) {
    assert profile != null;
    switch (field) {
        case AddressField.COUNTRY:
            return profile.getCountryCode();
        case AddressField.ADMIN_AREA:
            return profile.getRegion();
        case AddressField.LOCALITY:
            return profile.getLocality();
        case AddressField.DEPENDENT_LOCALITY:
            return profile.getDependentLocality();
        case AddressField.SORTING_CODE:
            return profile.getSortingCode();
        case AddressField.POSTAL_CODE:
            return profile.getPostalCode();
        case AddressField.STREET_ADDRESS:
            return profile.getStreetAddress();
        case AddressField.ORGANIZATION:
            return profile.getCompanyName();
        case AddressField.RECIPIENT:
            return profile.getFullName();
    }

    assert false;
    return null;
}
 
Example #17
Source File: AddressEditor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Saves the edited profile on disk. */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());

    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());

    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }

    // Clear the fields that are hidden from the user interface, so
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }

    // Calculate the label for this profile. The label's format depends on the country and
    // language code for the profile.
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    // TODO(crbug.com/666048): New billing address label is wrong.
    profile.setLabel(pdm.getAddressLabelForPaymentRequest(profile));

    // Save the edited autofill profile locally.
    profile.setGUID(pdm.setProfileToLocal(profile));
    profile.setIsLocal(true);
}
 
Example #18
Source File: ContactDetailsSection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a Contact section from a list of AutofillProfile.
 *
 * @param context               Context
 * @param unmodifiableProfiles  The list of profiles to build from.
 * @param mContactEditor        The Contact Editor associated with this flow.
 */
public ContactDetailsSection(Context context, Collection<AutofillProfile> unmodifiableProfiles,
        ContactEditor contactEditor) {
    // Initially no items are selected, but they are updated later in the constructor.
    super(PaymentRequestUI.TYPE_CONTACT_DETAILS, null);

    mContext = context;
    mContactEditor = contactEditor;
    // Copy the profiles from which this section is derived.
    mProfiles = new ArrayList<AutofillProfile>(unmodifiableProfiles);

    // Refresh the contact section items and selection.
    createContactListFromAutofillProfiles();
}
 
Example #19
Source File: AddressEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Saves the edited profile on disk. */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());

    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());

    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }

    // Clear the fields that are hidden from the user interface, so
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }

    // Save the edited autofill profile locally.
    profile.setGUID(PersonalDataManager.getInstance().setProfileToLocal(mProfile));
    profile.setIsLocal(true);
}
 
Example #20
Source File: AddressEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Writes the given value into the specified autofill profile field. */
private static void setProfileField(
        AutofillProfile profile, int field, @Nullable CharSequence value) {
    assert profile != null;
    switch (field) {
        case AddressField.COUNTRY:
            profile.setCountryCode(ensureNotNull(value));
            return;
        case AddressField.ADMIN_AREA:
            profile.setRegion(ensureNotNull(value));
            return;
        case AddressField.LOCALITY:
            profile.setLocality(ensureNotNull(value));
            return;
        case AddressField.DEPENDENT_LOCALITY:
            profile.setDependentLocality(ensureNotNull(value));
            return;
        case AddressField.SORTING_CODE:
            profile.setSortingCode(ensureNotNull(value));
            return;
        case AddressField.POSTAL_CODE:
            profile.setPostalCode(ensureNotNull(value));
            return;
        case AddressField.STREET_ADDRESS:
            profile.setStreetAddress(ensureNotNull(value));
            return;
        case AddressField.ORGANIZATION:
            profile.setCompanyName(ensureNotNull(value));
            return;
        case AddressField.RECIPIENT:
            profile.setFullName(ensureNotNull(value));
            return;
    }

    assert false;
}
 
Example #21
Source File: PaymentResponseHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onAddressNormalized(AutofillProfile profile) {
    // Check if a normalization is still required.
    if (!mIsWaitingForShippingNormalization) return;
    mIsWaitingForShippingNormalization = false;

    if (profile != null) {
        // The normalization finished first: use the normalized address.
        mSelectedShippingAddress.completeAddress(profile);
        mPaymentResponse.shippingAddress = mSelectedShippingAddress.toPaymentAddress();
    }

    // Wait for the payment details before sending the response.
    if (!mIsWaitingForPaymentsDetails) mDelegate.onPaymentResponseReady(mPaymentResponse);
}
 
Example #22
Source File: AutofillServerCardEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean saveEntry() {
    if (mBillingAddress.getSelectedItem() != null
            && mBillingAddress.getSelectedItem() instanceof AutofillProfile) {
        mCard.setBillingAddressId(
                ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID());
        PersonalDataManager.getInstance().updateServerCardBillingAddress(mCard);
    }
    return true;
}
 
Example #23
Source File: AutofillProfileEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean saveEntry() {
    AutofillProfile profile = new PersonalDataManager.AutofillProfile(mGUID,
            AutofillAndPaymentsPreferences.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;
}
 
Example #24
Source File: AutofillContact.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Builds contact details.
 *
 * @param context          The application context.
 * @param profile          The autofill profile where this contact data lives.
 * @param name             The payer name. If not empty, this will be the primary label.
 * @param phone            The phone number. If name is empty, this will be the primary label.
 * @param email            The email address. If name and phone are empty, this will be the
 *                         primary label.
 * @param completionStatus The completion status of this contact.
 * @param requestName      Whether the merchant requests a payer name.
 * @param requestPhone     Whether the merchant requests a payer phone number.
 * @param requestEmail     Whether the merchant requests a payer email address.
 */
public AutofillContact(Context context, AutofillProfile profile, @Nullable String name,
        @Nullable String phone, @Nullable String email,
        @ContactEditor.CompletionStatus int completionStatus, boolean requestName,
        boolean requestPhone, boolean requestEmail) {
    super(profile.getGUID(), null, null, null, null);
    mContext = context;
    mProfile = profile;
    mRequestName = requestName;
    mRequestPhone = requestPhone;
    mRequestEmail = requestEmail;
    mIsEditable = true;
    setContactInfo(profile.getGUID(), name, phone, email);
    updateCompletionStatus(completionStatus);
}
 
Example #25
Source File: AutofillPaymentInstrument.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onAddressNormalized(AutofillProfile profile) {
    if (!mIsWaitingForBillingNormalization) return;
    mIsWaitingForBillingNormalization = false;

    // If the normalization finished first, use the normalized address.
    if (profile != null) mBillingAddress = profile;

    // Wait for the full card details before sending the instrument details.
    if (!mIsWaitingForFullCardDetails) sendInstrumentDetails();
}
 
Example #26
Source File: CardEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static AutofillProfile findTargetProfile(List<AutofillProfile> profiles, String guid) {
    for (int i = 0; i < profiles.size(); i++) {
        if (profiles.get(i).getGUID().equals(guid)) return profiles.get(i);
    }
    assert false : "Never reached.";
    return null;
}
 
Example #27
Source File: AutofillProfileEditor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #28
Source File: PaymentResponseHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onAddressNormalized(AutofillProfile profile) {
    // Check if a normalization is still required.
    if (!mIsWaitingForShippingNormalization) return;
    mIsWaitingForShippingNormalization = false;

    if (profile != null) {
        // The normalization finished first: use the normalized address.
        mSelectedShippingAddress.completeAddress(profile);
        mPaymentResponse.shippingAddress = mSelectedShippingAddress.toPaymentAddress();
    }

    // Wait for the payment details before sending the response.
    if (!mIsWaitingForPaymentsDetails) mDelegate.onPaymentResponseReady(mPaymentResponse);
}
 
Example #29
Source File: AddressEditor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Writes the given value into the specified autofill profile field. */
private static void setProfileField(
        AutofillProfile profile, int field, @Nullable CharSequence value) {
    assert profile != null;
    switch (field) {
        case AddressField.COUNTRY:
            profile.setCountryCode(ensureNotNull(value));
            return;
        case AddressField.ADMIN_AREA:
            profile.setRegion(ensureNotNull(value));
            return;
        case AddressField.LOCALITY:
            profile.setLocality(ensureNotNull(value));
            return;
        case AddressField.DEPENDENT_LOCALITY:
            profile.setDependentLocality(ensureNotNull(value));
            return;
        case AddressField.SORTING_CODE:
            profile.setSortingCode(ensureNotNull(value));
            return;
        case AddressField.POSTAL_CODE:
            profile.setPostalCode(ensureNotNull(value));
            return;
        case AddressField.STREET_ADDRESS:
            profile.setStreetAddress(ensureNotNull(value));
            return;
        case AddressField.ORGANIZATION:
            profile.setCompanyName(ensureNotNull(value));
            return;
        case AddressField.RECIPIENT:
            profile.setFullName(ensureNotNull(value));
            return;
    }

    assert false;
}
 
Example #30
Source File: AutofillPaymentInstrument.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a payment instrument for the given credit card.
 *
 * @param webContents    The web contents where PaymentRequest was invoked.
 * @param card           The autofill card that can be used for payment.
 * @param billingAddress The optional billing address for the card.
 */
public AutofillPaymentInstrument(
        WebContents webContents, CreditCard card, @Nullable AutofillProfile billingAddress) {
    super(card.getGUID(), card.getObfuscatedNumber(), card.getName(),
            card.getIssuerIconDrawableId());
    mWebContents = webContents;
    mCard = card;
    mBillingAddress = billingAddress;
}