summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzysxqn@google.com <zysxqn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 19:30:10 +0000
committerzysxqn@google.com <zysxqn@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 19:30:10 +0000
commite0f90fcca53b72c5423405c939d6c30546e87ca4 (patch)
treef23454b75f76d65ea6254478c45d7c200d0746bd
parente3ad8173a2f7bca8400eeaa627929543216050a5 (diff)
downloadchromium_src-e0f90fcca53b72c5423405c939d6c30546e87ca4.zip
chromium_src-e0f90fcca53b72c5423405c939d6c30546e87ca4.tar.gz
chromium_src-e0f90fcca53b72c5423405c939d6c30546e87ca4.tar.bz2
This CL does the following: (1) Pass the max_length attribute to the password generator; (2) Update the password generation algorithm to contain at least one upper case letter, one lower case letter, one digit, and one other symbol.
BUG= TEST=PasswordGeneratorTest, AutofillManagerTest, PasswordGenerationManagerTest. Review URL: https://chromiumcodereview.appspot.com/10458018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140812 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_manager.cc6
-rw-r--r--chrome/browser/autofill/autofill_manager.h7
-rw-r--r--chrome/browser/autofill/password_generator.cc95
-rw-r--r--chrome/browser/autofill/password_generator.h21
-rw-r--r--chrome/browser/autofill/password_generator_unittest.cc44
-rw-r--r--chrome/browser/ui/browser_window.h14
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.cc2
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.h5
-rw-r--r--chrome/browser/ui/gtk/password_generation_bubble_gtk.cc5
-rw-r--r--chrome/browser/ui/gtk/password_generation_bubble_gtk.h14
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc2
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h5
-rw-r--r--chrome/browser/ui/views/password_generation_bubble_view.cc5
-rw-r--r--chrome/browser/ui/views/password_generation_bubble_view.h13
-rw-r--r--chrome/common/autofill_messages.h3
-rw-r--r--chrome/renderer/autofill/password_generation_manager.cc1
16 files changed, 212 insertions, 30 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 64c4db8..fc6ce26 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/autofill/form_structure.h"
+#include "chrome/browser/autofill/password_generator.h"
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/autofill/phone_number.h"
@@ -719,13 +720,16 @@ void AutofillManager::OnHideAutofillPopup() {
void AutofillManager::OnShowPasswordGenerationPopup(
const gfx::Rect& bounds,
+ int max_length,
const webkit::forms::PasswordForm& form) {
#if defined(OS_ANDROID)
NOTIMPLEMENTED();
#else
Browser* browser = browser::FindLastActiveWithProfile(
Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
- browser->window()->ShowPasswordGenerationBubble(bounds, form);
+ password_generator_.reset(new autofill::PasswordGenerator(max_length));
+ browser->window()->ShowPasswordGenerationBubble(
+ bounds, password_generator_.get(), form);
#endif // #if defined(OS_ANDROID)
}
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index e7c011f..d5c5867 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -41,6 +41,10 @@ typedef TabContents TabContentsWrapper;
struct ViewHostMsg_FrameNavigate_Params;
+namespace autofill {
+class PasswordGenerator;
+}
+
namespace content {
class RenderViewHost;
}
@@ -96,6 +100,7 @@ class AutofillManager : public content::NotificationObserver,
void OnShowAutofillDialog();
void OnDidPreviewAutofillFormData();
void OnShowPasswordGenerationPopup(const gfx::Rect& bounds,
+ int max_length,
const webkit::forms::PasswordForm& form);
// Remove the credit card or Autofill profile that matches |unique_id|
@@ -361,6 +366,8 @@ class AutofillManager : public content::NotificationObserver,
base::WeakPtr<ProfileSyncService> sync_service_;
// Listens for changes to the 'enabled' state for password generation.
PrefChangeRegistrar registrar_;
+ // To be passed to the password generation UI to generate the password.
+ scoped_ptr<autofill::PasswordGenerator> password_generator_;
// Our copy of the form data.
ScopedVector<FormStructure> form_structures_;
diff --git a/chrome/browser/autofill/password_generator.cc b/chrome/browser/autofill/password_generator.cc
index 3361fb4..9df082c 100644
--- a/chrome/browser/autofill/password_generator.cc
+++ b/chrome/browser/autofill/password_generator.cc
@@ -4,21 +4,106 @@
#include "chrome/browser/autofill/password_generator.h"
+#include <algorithm>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
#include "base/rand_util.h"
const int kMinChar = 33; // First printable character '!'
const int kMaxChar = 126; // Last printable character '~'
-const int kPasswordLength = 12;
+const int kMinUpper = 65; // First upper case letter 'A'
+const int kMaxUpper = 90; // Last upper case letter 'Z'
+const int kMinLower = 97; // First lower case letter 'a'
+const int kMaxLower = 122; // Last lower case letter 'z'
+const int kMinDigit = 48; // First digit '0'
+const int kMaxDigit = 57; // Last digit '9'
+// Copy of the other printable symbols from the ASCII table since they are
+// disjointed.
+const char kOtherSymbols[] =
+ {'!', '\"', '#', '$', '%', '&', '\'', '(',
+ ')', '*', '+', ',', '-', '.', '/', ':',
+ ';', '<', '=', '>', '?', '@', '[', '\\',
+ ']', '^', '_', '`', '{', '|', '}', '~'};
+const size_t kMinPasswordLength = 4;
+const size_t kMaxPasswordLength = 15;
+
+namespace {
+
+// A helper function to get the length of the generated password from
+// |max_length| retrieved from input password field.
+size_t GetLengthFromHint(size_t max_length, size_t default_length) {
+ if (max_length >= kMinPasswordLength && max_length <= kMaxPasswordLength)
+ return max_length;
+ else
+ return default_length;
+}
+
+// Classic algorithm to randomly select |num_select| elements out of
+// |num_total| elements. One description can be found at:
+// "http://stackoverflow.com/questions/48087/select-a-random-n-elements-from-listt-in-c-sharp/48089#48089"
+void GetRandomSelection(size_t num_to_select,
+ size_t num_total,
+ std::vector<size_t>* selections) {
+ DCHECK_GE(num_total, num_to_select);
+ size_t num_left = num_total;
+ size_t num_needed = num_to_select;
+ for (size_t i = 0; i < num_total && num_needed > 0; ++i) {
+ // we have probability = |num_needed| / |num_left| to select
+ // this position.
+ size_t probability = base::RandInt(0, num_left - 1);
+ if (probability < num_needed) {
+ selections->push_back(i);
+ --num_needed;
+ }
+ --num_left;
+ }
+ DCHECK_EQ(num_to_select, selections->size());
+}
+
+} // namespace
namespace autofill {
-PasswordGenerator::PasswordGenerator() {}
+const size_t PasswordGenerator::kDefaultPasswordLength = 12;
+
+PasswordGenerator::PasswordGenerator(size_t max_length)
+ : password_length_(GetLengthFromHint(max_length, kDefaultPasswordLength)) {}
PasswordGenerator::~PasswordGenerator() {}
-std::string PasswordGenerator::Generate() {
+std::string PasswordGenerator::Generate() const {
std::string ret;
- for (int i = 0; i < kPasswordLength; i++) {
- ret.push_back(static_cast<char>(base::RandInt(kMinChar, kMaxChar)));
+ // First, randomly select 4 positions to hold one upper case letter,
+ // one lower case letter, one digit, and one other symbol respectively,
+ // to make sure at least one of each category of characters will be
+ // included in the password.
+ std::vector<size_t> positions;
+ GetRandomSelection(4u, password_length_, &positions);
+
+ // To enhance the strengh of the password, we random suffle the positions so
+ // that the 4 catagories can be put at a random position in it.
+ std::random_shuffle(positions.begin(), positions.end());
+
+ // Next, generate each character of the password.
+ for (size_t i = 0; i < password_length_; ++i) {
+ if (i == positions[0]) {
+ // Generate random upper case letter.
+ ret.push_back(static_cast<char>(base::RandInt(kMinUpper, kMaxUpper)));
+ } else if (i == positions[1]) {
+ // Generate random lower case letter.
+ ret.push_back(static_cast<char>(base::RandInt(kMinLower, kMaxLower)));
+ } else if (i == positions[2]) {
+ // Generate random digit.
+ ret.push_back(static_cast<char>(base::RandInt(kMinDigit, kMaxDigit)));
+ } else if (i == positions[3]) {
+ // Generate random other symbol.
+ ret.push_back(
+ kOtherSymbols[base::RandInt(0, arraysize(kOtherSymbols) - 1)]);
+ } else {
+ // Generate random character from all categories.
+ ret.push_back(static_cast<char>(base::RandInt(kMinChar, kMaxChar)));
+ }
}
return ret;
}
diff --git a/chrome/browser/autofill/password_generator.h b/chrome/browser/autofill/password_generator.h
index 0adbd43..7c2f3d44 100644
--- a/chrome/browser/autofill/password_generator.h
+++ b/chrome/browser/autofill/password_generator.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
namespace autofill {
@@ -18,14 +19,26 @@ namespace autofill {
// previous generated passwords, crowdsourcing, etc.)
class PasswordGenerator {
public:
- PasswordGenerator();
+ // |max_length| is used as a hint for the generated password's length.
+ explicit PasswordGenerator(size_t max_length);
~PasswordGenerator();
- // Returns a random password. The string is guaranteed to be printable and
- // will not include whitespace characters.
- std::string Generate();
+ // Returns a random password such that:
+ // (1) Each character is guaranteed to be a non-whitespace printable ASCII
+ // character.
+ // (2) The generated password will contain AT LEAST one upper case letter, one
+ // lower case letter, one digit, and one other symbol.
+ // (3) The password length will be equal to |password_length_| (see comment
+ // for the constructor).
+ std::string Generate() const;
private:
+ // Unit test also need to access |kDefaultPasswordLength|.
+ static const size_t kDefaultPasswordLength;
+ FRIEND_TEST_ALL_PREFIXES(PasswordGeneratorTest, PasswordLength);
+
+ // The length of the generated password.
+ const size_t password_length_;
DISALLOW_COPY_AND_ASSIGN(PasswordGenerator);
};
diff --git a/chrome/browser/autofill/password_generator_unittest.cc b/chrome/browser/autofill/password_generator_unittest.cc
index 4efbc8b..1602a10 100644
--- a/chrome/browser/autofill/password_generator_unittest.cc
+++ b/chrome/browser/autofill/password_generator_unittest.cc
@@ -5,15 +5,49 @@
#include <locale>
#include "chrome/browser/autofill/password_generator.h"
-
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
-TEST(PasswordGeneratorTest, PasswordGeneratorSimpleTest) {
- // Not much to test, just make sure that the characters in a generated
- // password are reasonable.
- PasswordGenerator pg;
+TEST(PasswordGeneratorTest, PasswordLength) {
+ PasswordGenerator pg1(10);
+ std::string password = pg1.Generate();
+ EXPECT_EQ(password.size(), 10u);
+
+ PasswordGenerator pg2(-1);
+ password = pg2.Generate();
+ EXPECT_EQ(password.size(), PasswordGenerator::kDefaultPasswordLength);
+
+ PasswordGenerator pg3(100);
+ password = pg3.Generate();
+ EXPECT_EQ(password.size(), PasswordGenerator::kDefaultPasswordLength);
+}
+
+TEST(PasswordGeneratorTest, PasswordPattern) {
+ PasswordGenerator pg(12);
+ std::string password = pg.Generate();
+ int num_upper_case_letters = 0;
+ int num_lower_case_letters = 0;
+ int num_digits = 0;
+ int num_other_symbols = 0;
+ for (size_t i = 0; i < password.size(); i++) {
+ if (isupper(password[i]))
+ ++num_upper_case_letters;
+ else if (islower(password[i]))
+ ++num_lower_case_letters;
+ else if (isdigit(password[i]))
+ ++num_digits;
+ else
+ ++num_other_symbols;
+ }
+ EXPECT_GT(num_upper_case_letters, 0);
+ EXPECT_GT(num_lower_case_letters, 0);
+ EXPECT_GT(num_digits, 0);
+ EXPECT_GT(num_other_symbols, 0);
+}
+
+TEST(PasswordGeneratorTest, Printable) {
+ PasswordGenerator pg(12);
std::string password = pg.Generate();
for (size_t i = 0; i < password.size(); i++) {
// Make sure that the character is printable.
diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h
index ecd20d2..ac6b920 100644
--- a/chrome/browser/ui/browser_window.h
+++ b/chrome/browser/ui/browser_window.h
@@ -32,6 +32,9 @@ class TemplateURL;
class ToolbarView;
#endif
+namespace autofill {
+class PasswordGenerator;
+}
namespace content {
class WebContents;
struct NativeWebKeyboardEvent;
@@ -379,12 +382,15 @@ class BrowserWindow : public BaseWindow {
// Shows the avatar bubble on the window frame off of the avatar button.
virtual void ShowAvatarBubbleFromAvatarButton() = 0;
- // Show bubble for password generation positioned relative to |rect|. |form|
- // is the form that contains the password field that the bubble will be
- // associated with. A stub implementation is provided since this feature is
- // currently not available on mac.
+ // Show bubble for password generation positioned relative to |rect|. The
+ // subclasses implementing this interface do not own the |password_generator|
+ // object which is passed to generate the password. |form| is the form that
+ // contains the password field that the bubble will be associated with. A
+ // stub implementation is provided since this feature is currently not
+ // available on mac.
virtual void ShowPasswordGenerationBubble(
const gfx::Rect& rect,
+ autofill::PasswordGenerator* password_generator,
const webkit::forms::PasswordForm& form) {}
protected:
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc
index 3a1c75f..84af99e 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_window_gtk.cc
@@ -1282,6 +1282,7 @@ void BrowserWindowGtk::ShowAvatarBubbleFromAvatarButton() {
void BrowserWindowGtk::ShowPasswordGenerationBubble(
const gfx::Rect& rect,
+ autofill::PasswordGenerator* password_generator,
const webkit::forms::PasswordForm& form) {
WebContents* web_contents = browser_->GetSelectedWebContents();
if (!web_contents || !web_contents->GetContentNativeView()) {
@@ -1298,6 +1299,7 @@ void BrowserWindowGtk::ShowPasswordGenerationBubble(
web_contents->GetContentNativeView(),
browser()->profile(),
web_contents->GetRenderViewHost(),
+ password_generator,
tab_contents->password_manager());
}
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h
index b16b4a7..98d5cee 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.h
+++ b/chrome/browser/ui/gtk/browser_window_gtk.h
@@ -40,6 +40,10 @@ class StatusBubbleGtk;
class TabContentsContainerGtk;
class TabStripGtk;
+namespace autofill {
+class PasswordGenerator;
+}
+
namespace extensions {
class Extension;
}
@@ -169,6 +173,7 @@ class BrowserWindowGtk : public BrowserWindow,
virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE;
virtual void ShowPasswordGenerationBubble(
const gfx::Rect& rect,
+ autofill::PasswordGenerator* password_generator,
const webkit::forms::PasswordForm& form) OVERRIDE;
// Overridden from NotificationObserver:
diff --git a/chrome/browser/ui/gtk/password_generation_bubble_gtk.cc b/chrome/browser/ui/gtk/password_generation_bubble_gtk.cc
index b1a1a1e..5ad26b8 100644
--- a/chrome/browser/ui/gtk/password_generation_bubble_gtk.cc
+++ b/chrome/browser/ui/gtk/password_generation_bubble_gtk.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/ui/gtk/password_generation_bubble_gtk.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autofill/password_generator.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
@@ -29,10 +30,12 @@ PasswordGenerationBubbleGtk::PasswordGenerationBubbleGtk(
GtkWidget* anchor_widget,
Profile* profile,
content::RenderViewHost* render_view_host,
+ autofill::PasswordGenerator* password_generator,
PasswordManager* password_manager)
: profile_(profile),
form_(form),
render_view_host_(render_view_host),
+ password_generator_(password_generator),
password_manager_(password_manager) {
// TODO(gcasto): Localize text after we have finalized the UI.
// crbug.com/118062
@@ -53,7 +56,7 @@ PasswordGenerationBubbleGtk::PasswordGenerationBubbleGtk(
GtkWidget* password_line = gtk_hbox_new(FALSE, kHorizontalSpacing);
text_field_ = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(text_field_),
- password_generator_.Generate().c_str());
+ password_generator_->Generate().c_str());
gtk_entry_set_max_length(GTK_ENTRY(text_field_), 15);
GtkWidget* accept_button = gtk_button_new_with_label("Try It");
gtk_box_pack_start(GTK_BOX(password_line), text_field_, TRUE, TRUE, 0);
diff --git a/chrome/browser/ui/gtk/password_generation_bubble_gtk.h b/chrome/browser/ui/gtk/password_generation_bubble_gtk.h
index d82ba3e..a43db4a 100644
--- a/chrome/browser/ui/gtk/password_generation_bubble_gtk.h
+++ b/chrome/browser/ui/gtk/password_generation_bubble_gtk.h
@@ -8,11 +8,15 @@
#include <gtk/gtk.h>
-#include "chrome/browser/autofill/password_generator.h"
+#include "base/basictypes.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/gfx/rect.h"
#include "webkit/forms/password_form.h"
+namespace autofill {
+class PasswordGenerator;
+}
+
namespace content {
class RenderViewHost;
}
@@ -32,6 +36,7 @@ class PasswordGenerationBubbleGtk {
GtkWidget* anchor_widget,
Profile* profile,
content::RenderViewHost* render_view_host,
+ autofill::PasswordGenerator* password_generator,
PasswordManager* password_manager);
virtual ~PasswordGenerationBubbleGtk();
@@ -52,12 +57,13 @@ class PasswordGenerationBubbleGtk {
// RenderViewHost associated with the button that spawned this bubble.
content::RenderViewHost* render_view_host_;
+ // Object that deals with generating passwords. The class won't take the
+ // ownership of it.
+ autofill::PasswordGenerator* password_generator_;
+
// PasswordManager for this tab.
PasswordManager* password_manager_;
- // Class that deals with generating passwords.
- autofill::PasswordGenerator password_generator_;
-
DISALLOW_COPY_AND_ASSIGN(PasswordGenerationBubbleGtk);
};
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index f864c78..e909901 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -2407,6 +2407,7 @@ void BrowserView::ShowAvatarBubbleFromAvatarButton() {
void BrowserView::ShowPasswordGenerationBubble(
const gfx::Rect& rect,
+ autofill::PasswordGenerator* password_generator,
const webkit::forms::PasswordForm& form) {
// Create a rect in the content bounds that the bubble will point to.
gfx::Point origin(rect.origin());
@@ -2424,6 +2425,7 @@ void BrowserView::ShowPasswordGenerationBubble(
form,
this,
web_contents->GetRenderViewHost(),
+ password_generator,
browser_.get(),
wrapper->password_manager());
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index 447d445..72ce685 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -58,6 +58,10 @@ class JumpList;
class BrowserLauncherItemController;
#endif
+namespace autofill {
+class PasswordGenerator;
+}
+
namespace extensions {
class Extension;
}
@@ -322,6 +326,7 @@ class BrowserView : public BrowserWindow,
virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE;
virtual void ShowPasswordGenerationBubble(
const gfx::Rect& rect,
+ autofill::PasswordGenerator* password_generator,
const webkit::forms::PasswordForm& form) OVERRIDE;
// Overridden from BrowserWindowTesting:
diff --git a/chrome/browser/ui/views/password_generation_bubble_view.cc b/chrome/browser/ui/views/password_generation_bubble_view.cc
index 62c0acc..1e82e3a 100644
--- a/chrome/browser/ui/views/password_generation_bubble_view.cc
+++ b/chrome/browser/ui/views/password_generation_bubble_view.cc
@@ -31,6 +31,7 @@ PasswordGenerationBubbleView::PasswordGenerationBubbleView(
const webkit::forms::PasswordForm& form,
views::View* anchor_view,
content::RenderViewHost* render_view_host,
+ autofill::PasswordGenerator* password_generator,
content::PageNavigator* navigator,
PasswordManager* password_manager)
: BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
@@ -39,6 +40,7 @@ PasswordGenerationBubbleView::PasswordGenerationBubbleView(
anchor_rect_(anchor_rect),
form_(form),
render_view_host_(render_view_host),
+ password_generator_(password_generator),
navigator_(navigator),
password_manager_(password_manager) {}
@@ -51,7 +53,8 @@ void PasswordGenerationBubbleView::Init() {
ASCIIToUTF16("Try It"));
text_field_ = new views::Textfield();
- text_field_->SetText(ASCIIToUTF16(password_generator_.Generate()));
+ text_field_->SetText(
+ ASCIIToUTF16(password_generator_->Generate()));
views::Label* title_label = new views::Label(
ASCIIToUTF16("Password Suggestion"));
diff --git a/chrome/browser/ui/views/password_generation_bubble_view.h b/chrome/browser/ui/views/password_generation_bubble_view.h
index fb24ede..9fe5c7a6 100644
--- a/chrome/browser/ui/views/password_generation_bubble_view.h
+++ b/chrome/browser/ui/views/password_generation_bubble_view.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_PASSWORD_GENERATION_BUBBLE_VIEW_H_
#pragma once
-#include "chrome/browser/autofill/password_generator.h"
+#include "base/basictypes.h"
#include "ui/gfx/rect.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
@@ -14,6 +14,10 @@
#include "ui/views/view.h"
#include "webkit/forms/password_form.h"
+namespace autofill {
+class PasswordGenerator;
+}
+
namespace content {
class PageNavigator;
class RenderViewHost;
@@ -38,6 +42,7 @@ class PasswordGenerationBubbleView : public views::BubbleDelegateView,
const webkit::forms::PasswordForm& form,
views::View* anchor_view,
content::RenderViewHost* render_view_host,
+ autofill::PasswordGenerator* password_generator,
content::PageNavigator* navigator,
PasswordManager* password_manager);
virtual ~PasswordGenerationBubbleView();
@@ -70,6 +75,9 @@ class PasswordGenerationBubbleView : public views::BubbleDelegateView,
// RenderViewHost associated with the button that spawned this bubble.
content::RenderViewHost* render_view_host_;
+ // Object to generate passwords. The class won't take the ownership of it.
+ autofill::PasswordGenerator* password_generator_;
+
// An object used to handle page loads that originate from link clicks
// within this UI.
content::PageNavigator* navigator_;
@@ -77,9 +85,6 @@ class PasswordGenerationBubbleView : public views::BubbleDelegateView,
// PasswordManager associated with this tab.
PasswordManager* password_manager_;
- // Class to generate passwords
- autofill::PasswordGenerator password_generator_;
-
DISALLOW_COPY_AND_ASSIGN(PasswordGenerationBubbleView);
};
diff --git a/chrome/common/autofill_messages.h b/chrome/common/autofill_messages.h
index a2c7fba..5924ba3 100644
--- a/chrome/common/autofill_messages.h
+++ b/chrome/common/autofill_messages.h
@@ -200,8 +200,9 @@ IPC_MESSAGE_ROUTED0(AutofillHostMsg_HideAutofillPopup)
// Instructs the browser to show the password generation bubble at the
// specified location. This location should be specified in the renderers
// coordinate system. Form is the form associated with the password field.
-IPC_MESSAGE_ROUTED2(AutofillHostMsg_ShowPasswordGenerationPopup,
+IPC_MESSAGE_ROUTED3(AutofillHostMsg_ShowPasswordGenerationPopup,
gfx::Rect /* source location */,
+ int /* max length of the password */,
webkit::forms::PasswordForm)
// Instruct the browser that a password mapping has been found for a field.
diff --git a/chrome/renderer/autofill/password_generation_manager.cc b/chrome/renderer/autofill/password_generation_manager.cc
index 6abe555..b853a08 100644
--- a/chrome/renderer/autofill/password_generation_manager.cc
+++ b/chrome/renderer/autofill/password_generation_manager.cc
@@ -112,6 +112,7 @@ void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) {
if (password_form) {
Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(),
rect,
+ element.maxLength(),
*password_form));
}
}