summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 22:34:38 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 22:34:38 +0000
commitcf8ebbba224c7d01170a46d81b3feda976298b67 (patch)
tree3ab819a18e818d03820c43f676de1ea3b0f997f2 /chrome/browser
parent6d11e40470ab1574c8a2a85389a281a5436e8263 (diff)
downloadchromium_src-cf8ebbba224c7d01170a46d81b3feda976298b67.zip
chromium_src-cf8ebbba224c7d01170a46d81b3feda976298b67.tar.gz
chromium_src-cf8ebbba224c7d01170a46d81b3feda976298b67.tar.bz2
Add "save credit card info?" infobar for Autofill.
BUG=http://crbug.com/48114 TEST=none (depends on bug 47428) Review URL: http://codereview.chromium.org/2949002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51908 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autofill/autofill_cc_infobar_delegate.cc106
-rw-r--r--chrome/browser/autofill/autofill_cc_infobar_delegate.h48
-rw-r--r--chrome/browser/autofill/autofill_manager.cc18
-rw-r--r--chrome/browser/autofill/autofill_manager.h8
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc7
-rw-r--r--chrome/browser/autofill/personal_data_manager.h13
6 files changed, 193 insertions, 7 deletions
diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc
new file mode 100644
index 0000000..8c59b39
--- /dev/null
+++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2010 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_cc_infobar_delegate.h"
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "chrome/browser/autofill/autofill_manager.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/pref_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_delegate.h"
+#include "chrome/common/pref_names.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+AutoFillCCInfoBarDelegate::AutoFillCCInfoBarDelegate(TabContents* tab_contents,
+ AutoFillManager* host)
+ : ConfirmInfoBarDelegate(tab_contents),
+ browser_(NULL),
+ host_(host) {
+ if (tab_contents) {
+ // This is NULL for TestTabContents.
+ if (tab_contents->delegate())
+ browser_ = tab_contents->delegate()->GetBrowser();
+
+ tab_contents->AddInfoBar(this);
+ }
+}
+
+AutoFillCCInfoBarDelegate::~AutoFillCCInfoBarDelegate() {
+}
+
+bool AutoFillCCInfoBarDelegate::ShouldExpire(
+ const NavigationController::LoadCommittedDetails& details) const {
+ // The user has submitted a form, causing the page to navigate elsewhere. We
+ // don't want the infobar to be expired at this point, because the user won't
+ // get a chance to answer the question.
+ return false;
+}
+
+void AutoFillCCInfoBarDelegate::InfoBarClosed() {
+ if (host_) {
+ host_->OnInfoBarClosed(false);
+ host_ = NULL;
+ }
+
+ // This will delete us.
+ ConfirmInfoBarDelegate::InfoBarClosed();
+}
+
+std::wstring AutoFillCCInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetString(IDS_AUTOFILL_CC_INFOBAR_TEXT);
+}
+
+SkBitmap* AutoFillCCInfoBarDelegate::GetIcon() const {
+ return ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_INFOBAR_AUTOFILL);
+}
+
+int AutoFillCCInfoBarDelegate::GetButtons() const {
+ return BUTTON_OK | BUTTON_CANCEL;
+}
+
+std::wstring AutoFillCCInfoBarDelegate::GetButtonLabel(
+ ConfirmInfoBarDelegate::InfoBarButton button) const {
+ if (button == BUTTON_OK)
+ return l10n_util::GetString(IDS_AUTOFILL_CC_INFOBAR_ACCEPT);
+ else if (button == BUTTON_CANCEL)
+ return l10n_util::GetString(IDS_AUTOFILL_CC_INFOBAR_DENY);
+ else
+ NOTREACHED();
+
+ return std::wstring();
+}
+
+bool AutoFillCCInfoBarDelegate::Accept() {
+ if (host_) {
+ host_->OnInfoBarClosed(true);
+ host_ = NULL;
+ }
+ return true;
+}
+
+bool AutoFillCCInfoBarDelegate::Cancel() {
+ if (host_) {
+ host_->OnInfoBarClosed(false);
+ host_ = NULL;
+ }
+ return true;
+}
+
+std::wstring AutoFillCCInfoBarDelegate::GetLinkText() {
+ return l10n_util::GetString(IDS_AUTOFILL_CC_LEARN_MORE);
+}
+
+bool AutoFillCCInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
+ browser_->OpenURL(GURL(kAutoFillLearnMoreUrl), GURL(), NEW_FOREGROUND_TAB,
+ PageTransition::TYPED);
+ return false;
+}
+
diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.h b/chrome/browser/autofill/autofill_cc_infobar_delegate.h
new file mode 100644
index 0000000..9d476a7
--- /dev/null
+++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_
+#define CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_
+
+#include <string>
+
+#include "chrome/browser/tab_contents/infobar_delegate.h"
+
+class AutoFillManager;
+class Browser;
+class SkBitmap;
+class TabContents;
+
+// 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:
+ AutoFillCCInfoBarDelegate(TabContents* tab_contents, AutoFillManager* host);
+ virtual ~AutoFillCCInfoBarDelegate();
+
+ // ConfirmInfoBarDelegate implementation.
+ virtual bool ShouldExpire(
+ const NavigationController::LoadCommittedDetails& details) const;
+ virtual void InfoBarClosed();
+ virtual std::wstring GetMessageText() const;
+ virtual SkBitmap* GetIcon() const;
+ virtual int GetButtons() const;
+ virtual std::wstring GetButtonLabel(
+ ConfirmInfoBarDelegate::InfoBarButton button) const;
+ virtual bool Accept();
+ virtual bool Cancel();
+ virtual std::wstring GetLinkText();
+ virtual bool LinkClicked(WindowOpenDisposition disposition);
+
+ private:
+ // The browser.
+ Browser* browser_;
+
+ // The AutoFillManager that initiated this InfoBar.
+ AutoFillManager* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoFillCCInfoBarDelegate);
+};
+
+#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 0c778f0..d4e54d8 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/string16.h"
#include "chrome/browser/autofill/autofill_dialog.h"
+#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "chrome/browser/autofill/form_structure.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
@@ -400,7 +401,16 @@ void AutoFillManager::HandleSubmit() {
if (!personal_data_->ImportFormData(import, this))
return;
- UploadFormData();
+ // Did we get credit card info?
+ AutoFillProfile* profile;
+ CreditCard* credit_card;
+ personal_data_->GetImportedFormData(&profile, &credit_card);
+
+ if (credit_card) {
+ cc_infobar_.reset(new AutoFillCCInfoBarDelegate(tab_contents_, this));
+ } else {
+ UploadFormData();
+ }
}
void AutoFillManager::UploadFormData() {
@@ -410,6 +420,12 @@ void AutoFillManager::UploadFormData() {
// form_is_autofilled);
}
+void AutoFillManager::OnInfoBarClosed(bool should_save) {
+ if (should_save)
+ personal_data_->SaveImportedCreditCard();
+ UploadFormData();
+}
+
AutoFillManager::AutoFillManager()
: tab_contents_(NULL),
personal_data_(NULL),
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index 3804848..c46d625 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -15,6 +15,7 @@
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+class AutoFillCCInfoBarDelegate;
class AutoFillProfile;
class CreditCard;
class FormStructure;
@@ -55,6 +56,10 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
const string16& label);
virtual void ShowAutoFillDialog();
+ // Called by the AutoFillCCInfoBarDelegate when the user interacts with the
+ // infobar.
+ virtual void OnInfoBarClosed(bool should_save);
+
// Resets the stored form data.
virtual void Reset();
@@ -156,6 +161,9 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
// The form data the user has submitted.
scoped_ptr<FormStructure> upload_form_structure_;
+ // The InfoBar that asks for permission to store credit card information.
+ scoped_ptr<AutoFillCCInfoBarDelegate> cc_infobar_;
+
DISALLOW_COPY_AND_ASSIGN(AutoFillManager);
};
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 69ade7b..f2d16dd 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -224,6 +224,9 @@ bool PersonalDataManager::ImportFormData(
// We always save imported profiles.
SaveImportedProfile();
+
+ // We never save an imported credit card at this point. If there was one we
+ // found, we'll be asked to save it later once the user gives their OK.
}
return true;
@@ -668,3 +671,7 @@ void PersonalDataManager::SaveImportedProfile() {
SetProfiles(&profiles);
}
+
+void PersonalDataManager::SaveImportedCreditCard() {
+ // http://crbug.com/47428
+}
diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h
index a719de8..8c5a04e 100644
--- a/chrome/browser/autofill/personal_data_manager.h
+++ b/chrome/browser/autofill/personal_data_manager.h
@@ -56,11 +56,10 @@ class PersonalDataManager
// Removes |observer| as the observer of this PersonalDataManager.
virtual void RemoveObserver(PersonalDataManager::Observer* observer);
- // If AutoFill is able to determine the field types of a significant number
- // of field types that contain information in the FormStructures and the user
- // has not previously been prompted, the user will be asked if he would like
- // to import the data. If the user selects yes, a profile will be created
- // with all of the information from recognized fields.
+ // If AutoFill is able to determine the field types of a significant number of
+ // field types that contain information in the FormStructures a profile will
+ // be created with all of the information from recognized fields. Returns
+ // whether a profile was created.
bool ImportFormData(const std::vector<FormStructure*>& form_structures,
AutoFillManager* autofill_manager);
@@ -72,6 +71,9 @@ class PersonalDataManager
// data, we should store the profile and CC in the AFM instead of the PDM.
void GetImportedFormData(AutoFillProfile** profile, CreditCard** credit_card);
+ // Saves a credit card value detected in |ImportedFormData|.
+ void SaveImportedCreditCard();
+
// Sets |web_profiles_| to the contents of |profiles| and updates the web
// database by adding, updating and removing profiles. Sets the unique ID of
// newly-added profiles.
@@ -189,7 +191,6 @@ class PersonalDataManager
void SetUniqueCreditCardLabels(std::vector<CreditCard>* credit_cards);
// Saves |imported_profile_| to the WebDB if it exists.
- // TODO(jhawkins): SaveImportedCreditCard.
void SaveImportedProfile();
// The profile hosting this PersonalDataManager.