| Index: chrome/browser/autofill/autofill_flow_infobar_delegate.cc
|
| diff --git a/chrome/browser/autofill/autofill_flow_infobar_delegate.cc b/chrome/browser/autofill/autofill_flow_infobar_delegate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..62f192adc0db6911ea83e04528987d94e610440a
|
| --- /dev/null
|
| +++ b/chrome/browser/autofill/autofill_flow_infobar_delegate.cc
|
| @@ -0,0 +1,125 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/autofill/autofill_flow_infobar_delegate.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/api/infobars/infobar_service.h"
|
| +#include "chrome/browser/autofill/autofill_flow_util.h"
|
| +#include "chrome/browser/autofill/autofill_manager.h"
|
| +#include "chrome/common/form_data.h"
|
| +#include "chrome/common/url_constants.h"
|
| +#include "content/public/browser/page_navigator.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/browser/web_contents_delegate.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "grit/theme_resources.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +
|
| +// static
|
| +void AutofillFlowInfoBarDelegate::Create(
|
| + InfoBarService* infobar_service,
|
| + AutofillManager* autofill_manager,
|
| + const AutofillMetrics* metric_logger,
|
| + const GURL& source_url,
|
| + const content::SSLStatus& ssl_status) {
|
| + infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
|
| + new AutofillFlowInfoBarDelegate(infobar_service, autofill_manager,
|
| + metric_logger, source_url, ssl_status)));
|
| +}
|
| +
|
| +AutofillFlowInfoBarDelegate::AutofillFlowInfoBarDelegate(
|
| + InfoBarService* infobar_service,
|
| + AutofillManager* autofill_manager,
|
| + const AutofillMetrics* metric_logger,
|
| + const GURL& source_url,
|
| + const content::SSLStatus& ssl_status)
|
| + : ConfirmInfoBarDelegate(infobar_service),
|
| + metric_logger_(metric_logger),
|
| + autofill_manager_(autofill_manager),
|
| + source_url_(source_url),
|
| + ssl_status_(ssl_status),
|
| + had_user_interaction_(false) {
|
| + metric_logger_->LogAutofillFlowInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN);
|
| + autofill_flow_form_data_ = autofill::BuildAutofillFlowFormData();
|
| +}
|
| +
|
| +AutofillFlowInfoBarDelegate::~AutofillFlowInfoBarDelegate() {
|
| + if (!had_user_interaction_)
|
| + LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
|
| +}
|
| +
|
| +void AutofillFlowInfoBarDelegate::LogUserAction(
|
| + AutofillMetrics::InfoBarMetric user_action) {
|
| + DCHECK(!had_user_interaction_);
|
| + metric_logger_->LogAutofillFlowInfoBarMetric(user_action);
|
| + had_user_interaction_ = true;
|
| +}
|
| +
|
| +void AutofillFlowInfoBarDelegate::InfoBarDismissed() {
|
| + LogUserAction(AutofillMetrics::INFOBAR_DENIED);
|
| +}
|
| +
|
| +gfx::Image* AutofillFlowInfoBarDelegate::GetIcon() const {
|
| + return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
| + IDR_INFOBAR_AUTOFILL);
|
| +}
|
| +
|
| +InfoBarDelegate::Type AutofillFlowInfoBarDelegate::GetInfoBarType() const {
|
| + return PAGE_ACTION_TYPE;
|
| +}
|
| +
|
| +bool AutofillFlowInfoBarDelegate::ShouldExpireInternal(
|
| + const content::LoadCommittedDetails& details) const {
|
| + // The user has submitted a form, causing the page to navigate elsewhere. We
|
| + // want the infobar to be expired at this point, because the user has
|
| + // potentially started the checkout flow manually.
|
| + return true;
|
| +}
|
| +
|
| +
|
| +string16 AutofillFlowInfoBarDelegate::GetMessageText() const {
|
| + return l10n_util::GetStringUTF16(IDS_AUTOFILL_FLOW_INFOBAR_TEXT);
|
| +}
|
| +
|
| +string16 AutofillFlowInfoBarDelegate::GetButtonLabel(
|
| + InfoBarButton button) const {
|
| + return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
|
| + IDS_AUTOFILL_FLOW_INFOBAR_ACCEPT : IDS_AUTOFILL_FLOW_INFOBAR_DENY);
|
| +}
|
| +
|
| +bool AutofillFlowInfoBarDelegate::Accept() {
|
| + LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED);
|
| + GURL frame_url;
|
| + content::SSLStatus ssl_status;
|
| +
|
| + autofill_manager_->ShowAutofillFlowDialog(autofill_flow_form_data_,
|
| + source_url_, ssl_status_);
|
| + return true;
|
| +}
|
| +
|
| +bool AutofillFlowInfoBarDelegate::Cancel() {
|
| + LogUserAction(AutofillMetrics::INFOBAR_DENIED);
|
| + return true;
|
| +}
|
| +
|
| +string16 AutofillFlowInfoBarDelegate::GetLinkText() const {
|
| + return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
|
| +}
|
| +
|
| +bool AutofillFlowInfoBarDelegate::LinkClicked(
|
| + WindowOpenDisposition disposition) {
|
| + // TODO(ramankk): Fix the help URL when we have one.
|
| + owner()->GetWebContents()->GetDelegate()->OpenURLFromTab(
|
| + owner()->GetWebContents(),
|
| + content::OpenURLParams(GURL(chrome::kAutofillHelpURL),
|
| + content::Referrer(),
|
| + NEW_FOREGROUND_TAB,
|
| + content::PAGE_TRANSITION_LINK,
|
| + false));
|
| + return false;
|
| +}
|
| +
|
|
|