summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-28 19:51:21 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-28 19:51:21 +0000
commit21674df8085ee01ca91bbd4fe41ee1ea240a0cda (patch)
tree39462aa48bef10131eb36c22b38e9566336438f2
parent8b160034c47761a7cefd93019d0c45b9f7911be7 (diff)
downloadchromium_src-21674df8085ee01ca91bbd4fe41ee1ea240a0cda.zip
chromium_src-21674df8085ee01ca91bbd4fe41ee1ea240a0cda.tar.gz
chromium_src-21674df8085ee01ca91bbd4fe41ee1ea240a0cda.tar.bz2
Add initial implementation of AutoFill++. This implementation is hidden behind a switch, --enable-new-autofill. So far, we only pop up an infobar asking the user if he'd like to save the form information. I've added a rudimentary icon for the infobar, pulled from the mocks, so we'll probably want a blessed version of this icon at some point.
BUG=18201 TEST=none Review URL: http://codereview.chromium.org/339030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30378 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chromium_strings.grd3
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/app/google_chrome_strings.grd3
-rw-r--r--chrome/app/theme/infobar_autofill.pngbin0 -> 1718 bytes
-rw-r--r--chrome/app/theme/theme_resources.grd1
-rw-r--r--chrome/browser/autofill/autofill_infobar_delegate.cc76
-rw-r--r--chrome/browser/autofill/autofill_infobar_delegate.h42
-rw-r--r--chrome/browser/autofill/autofill_manager.cc41
-rw-r--r--chrome/browser/autofill/autofill_manager.h48
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc5
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.cc5
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h11
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc8
-rw-r--r--chrome/browser/tab_contents/tab_contents.h9
-rwxr-xr-xchrome/chrome.gyp4
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h2
17 files changed, 265 insertions, 2 deletions
diff --git a/chrome/app/chromium_strings.grd b/chrome/app/chromium_strings.grd
index 1227671..f4a10e2 100644
--- a/chrome/app/chromium_strings.grd
+++ b/chrome/app/chromium_strings.grd
@@ -362,6 +362,9 @@ be available for now. -->
<message name="IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT" desc="More compact text to show in the default browser query infobar.">
Chromium isn't your default browser.
</message>
+ <message name="IDS_AUTOFILL_INFOBAR_TEXT" desc="Text to show in the autofill request infobar.">
+ Do you want Chromium to save this information?
+ </message>
<if expr="os == 'darwin'">
<message name="IDS_SHORT_PRODUCT_NAME" desc="The application's short name, used for the Mac's application menu, activity monitor, etc. This should be less than 16 characters. Example: Chrome, not Google Chrome.">
Chromium
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 3e08028..38acb55 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -4170,6 +4170,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_OPTIONS_AUTOFILL_NEVERSAVE" desc="The label of the 'Never save autofill' radio button">
Never save text from forms
</message>
+ <message name="IDS_AUTOFILL_INFOBAR_ACCEPT" desc="Text to show for the autofill request infobar accept button.">
+ Set up AutoFill...
+ </message>
+ <message name="IDS_AUTOFILL_INFOBAR_DENY" desc="Text to show for the autofill request infobar deny button.">
+ Nope
+ </message>
<message name="IDS_THEMES_GROUP_NAME" desc="The title of the themes group">
Themes:
diff --git a/chrome/app/google_chrome_strings.grd b/chrome/app/google_chrome_strings.grd
index f71d7cf..6ef50a93 100644
--- a/chrome/app/google_chrome_strings.grd
+++ b/chrome/app/google_chrome_strings.grd
@@ -412,6 +412,9 @@ Chrome supports. -->
<message name="IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT" desc="More compact text to show in the default browser query infobar.">
Google Chrome isn't your default browser.
</message>
+ <message name="IDS_AUTOFILL_INFOBAR_TEXT" desc="Text to show in the autofill request infobar.">
+ Do you want Google Chrome to save this information?
+ </message>
<if expr="os == 'darwin'">
<message name="IDS_SHORT_PRODUCT_NAME" desc="The application's short name, used for the Mac's application menu, activity monitor, etc. This should be less than 16 characters. Example: Chrome, not Google Chrome.">
Chrome
diff --git a/chrome/app/theme/infobar_autofill.png b/chrome/app/theme/infobar_autofill.png
new file mode 100644
index 0000000..1ae3c79
--- /dev/null
+++ b/chrome/app/theme/infobar_autofill.png
Binary files differ
diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd
index 9239906..bc4bcc5 100644
--- a/chrome/app/theme/theme_resources.grd
+++ b/chrome/app/theme/theme_resources.grd
@@ -226,6 +226,7 @@
<include name="IDR_FINDINPAGE_NEXT_H" file="find_next_h.png" type="BINDATA" />
<include name="IDR_FINDINPAGE_NEXT_P" file="find_next_d.png" type="BINDATA" />
<include name="IDR_COOKIE_ICON" file="cookie.png" type="BINDATA" />
+ <include name="IDR_INFOBAR_AUTOFILL" file="infobar_autofill.png" type="BINDATA" />
<include name="IDR_INFOBAR_RESTORE_SESSION" file="infobar_restore.png" type="BINDATA" />
<include name="IDR_INFOBAR_SAVE_PASSWORD" file="infobar_savepassword.png" type="BINDATA" />
<include name="IDR_INFOBAR_SSL_WARNING" file="infobar_insecure.png" type="BINDATA" />
diff --git a/chrome/browser/autofill/autofill_infobar_delegate.cc b/chrome/browser/autofill/autofill_infobar_delegate.cc
new file mode 100644
index 0000000..9333b3a
--- /dev/null
+++ b/chrome/browser/autofill/autofill_infobar_delegate.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2009 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_infobar_delegate.h"
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "chrome/browser/autofill/autofill_manager.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+AutoFillInfoBarDelegate::AutoFillInfoBarDelegate(TabContents* tab_contents,
+ AutoFillManager* host)
+ : ConfirmInfoBarDelegate(tab_contents),
+ host_(host) {
+ if (tab_contents)
+ tab_contents->AddInfoBar(this);
+}
+
+AutoFillInfoBarDelegate::~AutoFillInfoBarDelegate() {
+}
+
+bool AutoFillInfoBarDelegate::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 AutoFillInfoBarDelegate::InfoBarClosed() {
+ Cancel();
+ // This will delete us.
+ ConfirmInfoBarDelegate::InfoBarClosed();
+}
+
+std::wstring AutoFillInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetString(IDS_AUTOFILL_INFOBAR_TEXT);
+}
+
+SkBitmap* AutoFillInfoBarDelegate::GetIcon() const {
+ return ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_INFOBAR_AUTOFILL);
+}
+
+int AutoFillInfoBarDelegate::GetButtons() const {
+ return BUTTON_OK | BUTTON_CANCEL;
+}
+
+std::wstring AutoFillInfoBarDelegate::GetButtonLabel(
+ ConfirmInfoBarDelegate::InfoBarButton button) const {
+ if (button == BUTTON_OK)
+ return l10n_util::GetString(IDS_AUTOFILL_INFOBAR_ACCEPT);
+
+ return l10n_util::GetString(IDS_AUTOFILL_INFOBAR_DENY);
+}
+
+bool AutoFillInfoBarDelegate::Accept() {
+ if (host_) {
+ host_->SaveFormData();
+ host_ = NULL;
+ }
+ return true;
+}
+
+bool AutoFillInfoBarDelegate::Cancel() {
+ if (host_) {
+ host_->Reset();
+ host_ = NULL;
+ }
+ return true;
+}
diff --git a/chrome/browser/autofill/autofill_infobar_delegate.h b/chrome/browser/autofill/autofill_infobar_delegate.h
new file mode 100644
index 0000000..1a6e267
--- /dev/null
+++ b/chrome/browser/autofill/autofill_infobar_delegate.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2009 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_INFOBAR_DELEGATE_H_
+#define CHROME_BROWSER_AUTOFILL_AUTOFILL_INFOBAR_DELEGATE_H_
+
+#include <string>
+
+#include "chrome/browser/tab_contents/infobar_delegate.h"
+
+class AutoFillManager;
+class SkBitmap;
+class TabContents;
+
+// An InfoBar delegate that enables the user to allow or deny storing personal
+// information gathered from a form submission.
+class AutoFillInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ AutoFillInfoBarDelegate(TabContents* tab_contents, AutoFillManager* host);
+ virtual ~AutoFillInfoBarDelegate();
+
+ // 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();
+
+ private:
+ // The autofill manager that initiated this infobar.
+ AutoFillManager* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoFillInfoBarDelegate);
+};
+
+#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_INFOBAR_DELEGATE_H_
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
new file mode 100644
index 0000000..6b78a3d
--- /dev/null
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -0,0 +1,41 @@
+// Copyright (c) 2009 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_manager.h"
+
+#include "base/command_line.h"
+#include "chrome/browser/autofill/autofill_infobar_delegate.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_switches.h"
+#include "webkit/glue/form_field_values.h"
+
+AutoFillManager::AutoFillManager(TabContents* tab_contents)
+ : tab_contents_(tab_contents),
+ infobar_(NULL) {
+}
+
+AutoFillManager::~AutoFillManager() {
+}
+
+void AutoFillManager::FormFieldValuesSubmitted(
+ const webkit_glue::FormFieldValues& form) {
+ // TODO(jhawkins): Remove this switch when AutoFill++ is fully implemented.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableNewAutoFill))
+ return;
+
+ // Grab a copy of the form data.
+ form_data_.reset(new webkit_glue::FormFieldValues(form));
+
+ // Ask the user for permission to save form information.
+ infobar_.reset(new AutoFillInfoBarDelegate(tab_contents_, this));
+}
+
+void AutoFillManager::SaveFormData() {
+ // TODO(jhawkins): Save the form data to the web database.
+}
+
+void AutoFillManager::Reset() {
+ form_data_.reset();
+}
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
new file mode 100644
index 0000000..6e09e6f
--- /dev/null
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2009 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_MANAGER_H_
+#define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+
+namespace webkit_glue {
+class FormFieldValues;
+}
+
+class AutoFillInfoBarDelegate;
+class TabContents;
+
+// Manages saving and restoring the user's personal information entered into web
+// forms.
+class AutoFillManager : public RenderViewHostDelegate::AutoFill {
+ public:
+ explicit AutoFillManager(TabContents* tab_contents);
+ virtual ~AutoFillManager();
+
+ // RenderViewHostDelegate::AutoFill implementation.
+ virtual void FormFieldValuesSubmitted(
+ const webkit_glue::FormFieldValues& form);
+
+ // Saves the form data to the web database.
+ void SaveFormData();
+
+ // Resets the stored form data.
+ void Reset();
+
+ private:
+ // The TabContents hosting this AutoFillManager.
+ TabContents* tab_contents_;
+
+ // Our copy of the form data.
+ scoped_ptr<webkit_glue::FormFieldValues> form_data_;
+
+ // The infobar asking for permission to store form information.
+ scoped_ptr<AutoFillInfoBarDelegate> infobar_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoFillManager);
+};
+
+#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 78c7fb0..a56546f 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1355,6 +1355,11 @@ void RenderViewHost::OnMsgFormFieldValuesSubmitted(
delegate_->GetFormFieldHistoryDelegate();
if (formfield_history_delegate)
formfield_history_delegate->FormFieldValuesSubmitted(form);
+
+ RenderViewHostDelegate::AutoFill* autofill_delegate =
+ delegate_->GetAutoFillDelegate();
+ if (autofill_delegate)
+ autofill_delegate->FormFieldValuesSubmitted(form);
}
void RenderViewHost::OnMsgStartDragging(
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc
index 99b8608..304d729 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.cc
+++ b/chrome/browser/renderer_host/render_view_host_delegate.cc
@@ -47,6 +47,11 @@ RenderViewHostDelegate::GetFormFieldHistoryDelegate() {
return NULL;
}
+RenderViewHostDelegate::AutoFill*
+RenderViewHostDelegate::GetAutoFillDelegate() {
+ return NULL;
+}
+
const GURL& RenderViewHostDelegate::GetURL() const {
return GURL::EmptyGURL();
}
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index c3dd529..af87a9e 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -365,6 +365,16 @@ class RenderViewHostDelegate {
const string16& value) = 0;
};
+ // AutoFill ------------------------------------------------------------------
+ // Interface for AutoFill-related functions.
+
+ class AutoFill {
+ public:
+ // Called when the user submits a form.
+ virtual void FormFieldValuesSubmitted(
+ const webkit_glue::FormFieldValues& form) = 0;
+ };
+
// ---------------------------------------------------------------------------
// Returns the current delegate associated with a feature. May return NULL if
@@ -377,6 +387,7 @@ class RenderViewHostDelegate {
virtual Printing* GetPrintingDelegate();
virtual FavIcon* GetFavIconDelegate();
virtual FormFieldHistory* GetFormFieldHistoryDelegate();
+ virtual AutoFill* GetAutoFillDelegate();
// Gets the URL that is currently being displayed, if there is one.
virtual const GURL& GetURL() const;
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 02af3a5..8d98d80 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -11,6 +11,7 @@
#include "base/string16.h"
#include "base/string_util.h"
#include "base/time.h"
+#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/blocked_popup_container.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_process.h"
@@ -230,6 +231,7 @@ TabContents::TabContents(Profile* profile,
save_package_(),
cancelable_consumer_(),
form_field_history_manager_(),
+ autofill_manager_(),
password_manager_(),
plugin_installer_(),
ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
@@ -1937,6 +1939,12 @@ TabContents::GetFormFieldHistoryDelegate() {
return form_field_history_manager_.get();
}
+RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
+ if (autofill_manager_.get() == NULL)
+ autofill_manager_.reset(new AutoFillManager(this));
+ return autofill_manager_.get();
+}
+
RendererPreferences TabContents::GetRendererPrefs() const {
return renderer_preferences_;
}
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index b613627..c33fcc5 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -67,10 +67,11 @@ namespace IPC {
class Message;
}
-class FormFieldHistoryManager;
+class AutoFillManager;
class BlockedPopupContainer;
class DOMUI;
class DownloadItem;
+class FormFieldHistoryManager;
class LoadNotificationDetails;
class OmniboxSearchHint;
class PasswordManager;
@@ -82,11 +83,11 @@ class TabContentsDelegate;
class TabContentsFactory;
class SkBitmap;
class SiteInstance;
+class TabContents;
class TabContentsView;
struct ThumbnailScore;
struct ViewHostMsg_FrameNavigate_Params;
struct ViewHostMsg_DidPrintPage_Params;
-class TabContents;
// Describes what goes in the main content area of a tab. TabContents is
// the only type of TabContents, and these should be merged together.
@@ -836,6 +837,7 @@ class TabContents : public PageNavigator,
virtual RenderViewHostDelegate::FavIcon* GetFavIconDelegate();
virtual RenderViewHostDelegate::FormFieldHistory*
GetFormFieldHistoryDelegate();
+ virtual RenderViewHostDelegate::AutoFill* GetAutoFillDelegate();
virtual TabContents* GetAsTabContents();
virtual void AddBlockedNotice(const GURL& url, const string16& reason);
virtual ViewType::Type GetRenderViewType() const;
@@ -992,6 +994,9 @@ class TabContents : public PageNavigator,
// FormFieldHistoryManager, lazily created.
scoped_ptr<FormFieldHistoryManager> form_field_history_manager_;
+ // AutoFillManager, lazily created.
+ scoped_ptr<AutoFillManager> autofill_manager_;
+
// PasswordManager, lazily created.
scoped_ptr<PasswordManager> password_manager_;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 2246157..1f0f6f4 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -832,6 +832,10 @@
'browser/autocomplete/keyword_provider.h',
'browser/autocomplete/search_provider.cc',
'browser/autocomplete/search_provider.h',
+ 'browser/autofill/autofill_infobar_delegate.cc',
+ 'browser/autofill/autofill_infobar_delegate.h',
+ 'browser/autofill/autofill_manager.cc',
+ 'browser/autofill/autofill_manager.h',
'browser/automation/automation_autocomplete_edit_tracker.h',
'browser/automation/automation_browser_tracker.h',
'browser/automation/extension_automation_constants.h',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 203e4b3..c6d94ed6 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -662,4 +662,7 @@ const char kGearsPluginPathOverride[] = "gears-plugin-path";
// appropriate ifdef at the bottom. The order should match the header.
// -----------------------------------------------------------------------------
+// Enable AutoFill++.
+const char kEnableNewAutoFill[] = "enable-new-autofill";
+
} // namespace switches
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 8ee5088..b946241 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -200,6 +200,8 @@ extern const char kGearsPluginPathOverride[];
// DON'T ADD RANDOM STUFF HERE. Put it in the main section above in
// alphabetical order, or in one of the ifdefs (also in order in each section).
+extern const char kEnableNewAutoFill[];
+
} // namespace switches
#endif // CHROME_COMMON_CHROME_SWITCHES_H_