diff options
author | gcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 02:01:01 +0000 |
---|---|---|
committer | gcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 02:01:01 +0000 |
commit | 90ee092309f6b1b1b2c30d7f2b1cf61116bc757c (patch) | |
tree | 65bd1ac92c362535ad70f35699264c3ee1815c3f /chrome/browser/autofill | |
parent | 9ccf5ec7ec6965e6fb0cffb3e8dbd3dc861c1f8a (diff) | |
download | chromium_src-90ee092309f6b1b1b2c30d7f2b1cf61116bc757c.zip chromium_src-90ee092309f6b1b1b2c30d7f2b1cf61116bc757c.tar.gz chromium_src-90ee092309f6b1b1b2c30d7f2b1cf61116bc757c.tar.bz2 |
Add password generation browser UI for Windows.
The mocks that I am modeling this off of are located at http://dev.chromium.org/developers/design-documents/password-generation. You can see a screenshot of this implementation at http://www.corp.google.com/~gcasto/windows_ui.png
There are two major differences between this implementation and the mocks.
- Currently the bubble does not have a close button, but instead is closed when it loses focus. Doing it the other way requires
constructing a native close button (which wasn't obvious to me) and controlling when to hide or move the UI (say when you switch
tabs or move the browser window).
- There is no clickable image to regenerate the password. This should be trivial once we have an image to use.
Both of these can be added in a later CL. I also need to add some polish to the bubble (I don't like the font, not sure if I like the spacing, etc).
Note that what I'm doing in the renderer right now is temporary until I get the shadow dom changes into WebKit.
BUG=114092
TEST=Ran unittests
Review URL: http://codereview.chromium.org/9704040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127879 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 9 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.h | 1 | ||||
-rw-r--r-- | chrome/browser/autofill/password_generator.cc | 26 | ||||
-rw-r--r-- | chrome/browser/autofill/password_generator.h | 35 | ||||
-rw-r--r-- | chrome/browser/autofill/password_generator_unittest.cc | 24 |
5 files changed, 95 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index 571e05f3..7119d54 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -37,6 +37,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/autofill_messages.h" #include "chrome/common/chrome_notification_types.h" @@ -318,6 +319,8 @@ bool AutofillManager::OnMessageReceived(const IPC::Message& message) { OnDidEndTextFieldEditing) IPC_MESSAGE_HANDLER(AutofillHostMsg_HideAutofillPopup, OnHideAutofillPopup) + IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, + OnShowPasswordGenerationPopup) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -691,6 +694,12 @@ void AutofillManager::OnHideAutofillPopup() { external_delegate_->HideAutofillPopup(); } +void AutofillManager::OnShowPasswordGenerationPopup(const gfx::Rect& bounds) { + Browser* browser = BrowserList::GetLastActiveWithProfile( + Profile::FromBrowserContext(web_contents()->GetBrowserContext())); + browser->window()->ShowPasswordGenerationBubble(bounds); +} + void AutofillManager::OnLoadedServerPredictions( const std::string& response_xml) { // Parse and store the server predictions. diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index f372819..b750703 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -82,6 +82,7 @@ class AutofillManager : public content::WebContentsObserver, void OnDidFillAutofillFormData(const base::TimeTicks& timestamp); void OnShowAutofillDialog(); void OnDidPreviewAutofillFormData(); + void OnShowPasswordGenerationPopup(const gfx::Rect& bounds); protected: // Only test code should subclass AutofillManager. diff --git a/chrome/browser/autofill/password_generator.cc b/chrome/browser/autofill/password_generator.cc new file mode 100644 index 0000000..3361fb4 --- /dev/null +++ b/chrome/browser/autofill/password_generator.cc @@ -0,0 +1,26 @@ +// 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/password_generator.h" + +#include "base/rand_util.h" + +const int kMinChar = 33; // First printable character '!' +const int kMaxChar = 126; // Last printable character '~' +const int kPasswordLength = 12; + +namespace autofill { + +PasswordGenerator::PasswordGenerator() {} +PasswordGenerator::~PasswordGenerator() {} + +std::string PasswordGenerator::Generate() { + std::string ret; + for (int i = 0; i < kPasswordLength; i++) { + ret.push_back(static_cast<char>(base::RandInt(kMinChar, kMaxChar))); + } + return ret; +} + +} // namespace autofill diff --git a/chrome/browser/autofill/password_generator.h b/chrome/browser/autofill/password_generator.h new file mode 100644 index 0000000..0adbd43 --- /dev/null +++ b/chrome/browser/autofill/password_generator.h @@ -0,0 +1,35 @@ +// 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. + +#ifndef CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ +#define CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" + +namespace autofill { + +// Class to generate random passwords. Currently we just use a generic algorithm +// for all sites, but eventually we can incorporate additional information to +// determine passwords that are likely to be accepted (i.e. use pattern field, +// previous generated passwords, crowdsourcing, etc.) +class PasswordGenerator { + public: + PasswordGenerator(); + ~PasswordGenerator(); + + // Returns a random password. The string is guaranteed to be printable and + // will not include whitespace characters. + std::string Generate(); + + private: + + DISALLOW_COPY_AND_ASSIGN(PasswordGenerator); +}; + +} // namespace autofill + +#endif // CHROME_BROWSER_AUTOFILL_PASSWORD_GENERATOR_H_ diff --git a/chrome/browser/autofill/password_generator_unittest.cc b/chrome/browser/autofill/password_generator_unittest.cc new file mode 100644 index 0000000..4efbc8b --- /dev/null +++ b/chrome/browser/autofill/password_generator_unittest.cc @@ -0,0 +1,24 @@ +// 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 <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; + std::string password = pg.Generate(); + for (size_t i = 0; i < password.size(); i++) { + // Make sure that the character is printable. + EXPECT_TRUE(isgraph(password[i])); + } +} + +} // namespace autofill |