Skip to content

Commit

Permalink
Add credit card upload on Android and update save CC strings.
Browse files Browse the repository at this point in the history
Based on the mocks at:

https://folio.googleplex.com/chrome-ux/mocks/304-payments-zero-integration/ZI_Upstream#%2F11-updated-mobile%20prompts%20-%20proposal.png

The "learn more" link and legal text will be added later.

BUG=535784

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

Cr-Commit-Position: refs/heads/master@{#365936}
  • Loading branch information
rsolomakhin authored and Commit bot committed Dec 17, 2015
1 parent 9db7350 commit 752b87c
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 61 deletions.
2 changes: 1 addition & 1 deletion chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -6689,7 +6689,7 @@ Keep your key file in a safe place. You will need it to create new versions of y
Enables the use of an AppContainer on sandboxed processes to improve security.
</message>
</if>
<if expr="toolkit_views">
<if expr="toolkit_views or is_android">
<message name="IDS_FLAGS_AUTOFILL_CREDIT_CARD_UPLOAD_NAME" desc="Name of the flag to enable uploading Autofill credit cards.">
Enable offering upload of Autofilled credit cards
</message>
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2022,15 +2022,15 @@ const FeatureEntry kFeatureEntries[] = {
SINGLE_VALUE_TYPE_AND_VALUE(switches::kDisableAutoHidingToolbarThreshold,
"800")},
#endif
#if defined(TOOLKIT_VIEWS)
#if defined(TOOLKIT_VIEWS) || defined(OS_ANDROID)
{"enable-autofill-credit-card-upload",
IDS_FLAGS_AUTOFILL_CREDIT_CARD_UPLOAD_NAME,
IDS_FLAGS_AUTOFILL_CREDIT_CARD_UPLOAD_DESCRIPTION,
kOsCrOS | kOsWin | kOsLinux,
kOsCrOS | kOsWin | kOsLinux | kOsAndroid,
ENABLE_DISABLE_VALUE_TYPE(
autofill::switches::kEnableOfferUploadCreditCards,
autofill::switches::kDisableOfferUploadCreditCards)},
#endif // defined(TOOLKIT_VIEWS)
#endif // defined(TOOLKIT_VIEWS) || defined(OS_ANDROID)
#if defined(OS_ANDROID)
{"enable-tab-switcher-in-document-mode",
IDS_FLAGS_TAB_SWITCHER_IN_DOCUMENT_MODE_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ AutofillCCInfobarDelegateTest::CreateDelegate() {
base::HistogramTester histogram_tester;
CreditCard credit_card;
scoped_ptr<ConfirmInfoBarDelegate> delegate(AutofillCCInfoBarDelegate::Create(
ChromeAutofillClient::FromWebContents(web_contents()),
base::Bind(
base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
base::Unretained(personal_data_.get()), credit_card)));
Expand Down
11 changes: 7 additions & 4 deletions chrome/browser/ui/autofill/chrome_autofill_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,18 @@ void ChromeAutofillClient::ConfirmSaveCreditCardLocally(
return;
}
#endif
AutofillCCInfoBarDelegate::Create(
InfoBarService::FromWebContents(web_contents()), this, callback);
AutofillCCInfoBarDelegate::CreateForLocalSave(
InfoBarService::FromWebContents(web_contents()), callback);
}

void ChromeAutofillClient::ConfirmSaveCreditCardToCloud(
const base::Closure& callback,
scoped_ptr<base::DictionaryValue> legal_message) {
// TODO(jdonnelly): Implement save card prompt for OS_ANDROID and OS_IOS.
#if !defined(OS_ANDROID)
// TODO(jdonnelly): Implement save card prompt for OS_IOS.
#if defined(OS_ANDROID)
AutofillCCInfoBarDelegate::CreateForUpload(
InfoBarService::FromWebContents(web_contents()), callback);
#else
// Do lazy initialization of SaveCardBubbleControllerImpl.
autofill::SaveCardBubbleControllerImpl::CreateForWebContents(web_contents());
autofill::SaveCardBubbleControllerImpl* controller =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view()

base::string16 SaveCardBubbleControllerImpl::GetWindowTitle() const {
return l10n_util::GetStringUTF16(
is_uploading_ ? IDS_AUTOFILL_SAVE_CARD_BUBBLE_TITLE_TO_CLOUD
: IDS_AUTOFILL_SAVE_CARD_BUBBLE_TITLE_LOCAL);
is_uploading_ ? IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD
: IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL);
}

base::string16 SaveCardBubbleControllerImpl::GetExplanatoryMessage() const {
return is_uploading_ ? l10n_util::GetStringUTF16(
IDS_AUTOFILL_SAVE_CARD_BUBBLE_UPLOAD_EXPLANATION)
IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION)
: base::string16();
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/autofill/save_card_bubble_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ scoped_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {

// Create accept button.
save_button_ = new views::BlueButton(
this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT));
this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT));
save_button_->SetIsDefault(true);

// Create cancel button.
cancel_button_ = new views::LabelButton(
this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY));
this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY));
cancel_button_->SetStyle(views::Button::STYLE_BUTTON);

if (kIsOkButtonOnLeftSide) {
Expand Down
28 changes: 19 additions & 9 deletions components/autofill/core/browser/autofill_cc_infobar_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "components/autofill/core/browser/autofill_cc_infobar_delegate.h"

#include "base/logging.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/common/autofill_constants.h"
Expand All @@ -20,20 +19,28 @@
namespace autofill {

// static
void AutofillCCInfoBarDelegate::Create(
void AutofillCCInfoBarDelegate::CreateForLocalSave(
infobars::InfoBarManager* infobar_manager,
AutofillClient* autofill_client,
const base::Closure& save_card_callback) {
infobar_manager->AddInfoBar(
infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
new AutofillCCInfoBarDelegate(autofill_client, save_card_callback))));
new AutofillCCInfoBarDelegate(false, save_card_callback))));
}

// static
void AutofillCCInfoBarDelegate::CreateForUpload(
infobars::InfoBarManager* infobar_manager,
const base::Closure& save_card_callback) {
infobar_manager->AddInfoBar(
infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
new AutofillCCInfoBarDelegate(true, save_card_callback))));
}

AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
AutofillClient* autofill_client,
bool upload,
const base::Closure& save_card_callback)
: ConfirmInfoBarDelegate(),
autofill_client_(autofill_client),
upload_(upload),
save_card_callback_(save_card_callback),
had_user_interaction_(false) {
AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN);
Expand Down Expand Up @@ -82,13 +89,16 @@ void AutofillCCInfoBarDelegate::InfoBarDismissed() {
}

base::string16 AutofillCCInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT);
return l10n_util::GetStringUTF16(
upload_ ? IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD
: IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL);
}

base::string16 AutofillCCInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY);
return l10n_util::GetStringUTF16(button == BUTTON_OK
? IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT
: IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY);
}

bool AutofillCCInfoBarDelegate::Accept() {
Expand Down
19 changes: 8 additions & 11 deletions components/autofill/core/browser/autofill_cc_infobar_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,27 @@ class InfoBarManager;

namespace autofill {

class AutofillClient;

// An InfoBar delegate that enables the user to allow or deny storing credit
// card information gathered from a form submission.
class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
// Creates an autofill credit card infobar and delegate and adds the infobar
// to |infobar_manager|. The |autofill_client| must outlive the infobar.
static void Create(infobars::InfoBarManager* infobar_manager,
AutofillClient* autofill_client,
const base::Closure& save_card_callback);
// to |infobar_manager|.
static void CreateForLocalSave(infobars::InfoBarManager* infobar_manager,
const base::Closure& save_card_callback);
static void CreateForUpload(infobars::InfoBarManager* infobar_manager,
const base::Closure& save_card_callback);

#if defined(UNIT_TEST)
static scoped_ptr<ConfirmInfoBarDelegate> Create(
AutofillClient* autofill_client,
const base::Closure& save_card_callback) {
return scoped_ptr<ConfirmInfoBarDelegate>(
new AutofillCCInfoBarDelegate(autofill_client, save_card_callback));
new AutofillCCInfoBarDelegate(false, save_card_callback));
}
#endif

private:
AutofillCCInfoBarDelegate(AutofillClient* autofill_client,
AutofillCCInfoBarDelegate(bool upload,
const base::Closure& save_card_callback);
~AutofillCCInfoBarDelegate() override;

Expand All @@ -61,8 +59,7 @@ class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate {
base::string16 GetLinkText() const override;
GURL GetLinkURL() const override;

// Performs navigation to handle any link click. Guaranteed to outlive us.
AutofillClient* const autofill_client_;
bool upload_;

// The callback to save credit card if the user accepts the infobar.
base::Closure save_card_callback_;
Expand Down
32 changes: 7 additions & 25 deletions components/autofill_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -168,45 +168,27 @@
Use password for:
</message>

<!-- Autofill infobar -->
<message name="IDS_AUTOFILL_CC_INFOBAR_ACCEPT" desc="Text to show for the Autofill credit card request infobar accept button.">
<!-- Autofill save credit card bubble or infobar prompt -->
<message name="IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT" desc="Text to show for the Autofill save credit card prompt accept button. The prompt can be either a bubble or an infobar.">
Save
</message>
<message name="IDS_AUTOFILL_CC_INFOBAR_DENY" desc="Text to show for the Autofill credit card request infobar deny button.">
Don't save
</message>
<if expr="_google_chrome">
<message name="IDS_AUTOFILL_CC_INFOBAR_TEXT" desc="Text to show in the Autofill credit card request infobar.">
Do you want Chrome to save this credit card information for completing web forms?
</message>
</if>
<if expr="not _google_chrome">
<message name="IDS_AUTOFILL_CC_INFOBAR_TEXT" desc="Text to show in the Autofill credit card request infobar.">
Do you want Chromium to save this credit card information for completing web forms?
</message>
</if>

<!-- Autofill save credit card bubble -->
<message name="IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT" desc="Text to show for the Autofill save credit card bubble accept button.">
Save
</message>
<message name="IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY" desc="Text to show for the Autofill save credit card bubble deny button.">
<message name="IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY" desc="Text to show for the Autofill save credit card prompt deny button. The prompt can be either a bubble or an infobar.">
No thanks
</message>
<if expr="_google_chrome">
<message name="IDS_AUTOFILL_SAVE_CARD_BUBBLE_TITLE_LOCAL" desc="Title text for the Autofill save card bubble when the card is to be saved locally.">
<message name="IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL" desc="Title text for the Autofill save card prompt when the card is to be saved locally. The prompt can be either a bubble or an infobar.">
Do you want Chrome to save this card?
</message>
</if>
<if expr="not _google_chrome">
<message name="IDS_AUTOFILL_SAVE_CARD_BUBBLE_TITLE_LOCAL" desc="Title text for the Autofill save card bubble when the card is to be saved locally.">
<message name="IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL" desc="Title text for the Autofill save card prompt when the card is to be saved locally. The prompt can be either a bubble or an infobar.">
Do you want Chromium to save this card?
</message>
</if>
<message name="IDS_AUTOFILL_SAVE_CARD_BUBBLE_TITLE_TO_CLOUD" desc="Title text for the Autofill save card bubble when the card is to be saved by uploading it to Google Payments.">
<message name="IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD" desc="Title text for the Autofill save card prompt when the card is to be saved by uploading it to Google Payments. The prompt can be either a bubble or an infobar.">
Do you want Google to save this card?
</message>
<message name="IDS_AUTOFILL_SAVE_CARD_BUBBLE_UPLOAD_EXPLANATION" desc="Explanation of the effect of the Autofill save card bubble when the card is to be saved by uploading it to Google Payments.">
<message name="IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION" desc="Explanation of the effect of the Autofill save card prompt when the card is to be saved by uploading it to Google Payments. The prompt can be either a bubble or an infobar.">
Pay quickly on sites and apps across devices using cards you have saved with Google.
</message>

Expand Down
4 changes: 2 additions & 2 deletions ios/chrome/browser/ui/autofill/autofill_client_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
// was submitted, the WebContents is guaranteed to be live. Since the
// InfoBarService is a WebContentsUserData, it must also be alive at this
// time.
AutofillCCInfoBarDelegate::Create(infobar_manager_, this, callback);
AutofillCCInfoBarDelegate::CreateForLocalSave(infobar_manager_, callback);
}

void AutofillClientIOS::ConfirmSaveCreditCardToCloud(
const base::Closure& callback,
scoped_ptr<base::DictionaryValue> legal_message) {
NOTIMPLEMENTED();
AutofillCCInfoBarDelegate::CreateForUpload(infobar_manager_, callback);
}

void AutofillClientIOS::LoadRiskData(
Expand Down

0 comments on commit 752b87c

Please sign in to comment.