summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorgcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-17 15:06:10 +0000
committergcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-17 15:06:10 +0000
commit5c42c37b30a91d94c0fa8c1d0d1d250f9c754597 (patch)
tree4d734c07528286a58df0c3a87759a5cb7f2cdede /components
parent1a611e93fc9d9a2e5c4c54cc81e70cca1f0e349c (diff)
downloadchromium_src-5c42c37b30a91d94c0fa8c1d0d1d250f9c754597.zip
chromium_src-5c42c37b30a91d94c0fa8c1d0d1d250f9c754597.tar.gz
chromium_src-5c42c37b30a91d94c0fa8c1d0d1d250f9c754597.tar.bz2
[password generation] Add a switch to skip waiting on Autofill
Normally we will not show the password generation icon unless Autofill has labeled the form as being used for account creation. By setting "--no-autofill-for-password-generation" this check is skipped. This flag should only be used for testing. Review URL: https://codereview.chromium.org/26754004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/autofill/content/renderer/password_generation_agent.cc52
-rw-r--r--components/autofill/content/renderer/password_generation_agent.h12
-rw-r--r--components/autofill/core/common/autofill_messages.h4
-rw-r--r--components/autofill/core/common/autofill_switches.cc5
-rw-r--r--components/autofill/core/common/autofill_switches.h1
5 files changed, 37 insertions, 37 deletions
diff --git a/components/autofill/content/renderer/password_generation_agent.cc b/components/autofill/content/renderer/password_generation_agent.cc
index fe53344..682f33a 100644
--- a/components/autofill/content/renderer/password_generation_agent.cc
+++ b/components/autofill/content/renderer/password_generation_agent.cc
@@ -4,10 +4,12 @@
#include "components/autofill/content/renderer/password_generation_agent.h"
+#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "components/autofill/content/renderer/password_form_conversion_utils.h"
#include "components/autofill/core/common/autofill_messages.h"
+#include "components/autofill/core/common/autofill_switches.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/password_form.h"
#include "components/autofill/core/common/password_generation_util.h"
@@ -93,8 +95,7 @@ bool ContainsForm(const std::vector<autofill::FormData>& forms,
PasswordGenerationAgent::PasswordGenerationAgent(
content::RenderView* render_view)
: content::RenderViewObserver(render_view),
- render_view_(render_view),
- enabled_(false) {
+ render_view_(render_view) {
render_view_->GetWebView()->setPasswordGeneratorClient(this);
}
PasswordGenerationAgent::~PasswordGenerationAgent() {}
@@ -112,7 +113,7 @@ void PasswordGenerationAgent::DidFinishDocumentLoad(WebKit::WebFrame* frame) {
// password generation icon.
if (!frame->parent()) {
not_blacklisted_password_form_origins_.clear();
- account_creation_forms_.clear();
+ generation_enabled_forms_.clear();
possible_account_creation_form_.reset(new PasswordForm());
passwords_.clear();
}
@@ -121,9 +122,6 @@ void PasswordGenerationAgent::DidFinishDocumentLoad(WebKit::WebFrame* frame) {
void PasswordGenerationAgent::DidFinishLoad(WebKit::WebFrame* frame) {
// We don't want to generate passwords if the browser won't store or sync
// them.
- if (!enabled_)
- return;
-
if (!ShouldAnalyzeDocument(frame->document()))
return;
@@ -201,8 +199,6 @@ bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) {
OnFormNotBlacklisted)
IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted,
OnPasswordAccepted)
- IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled,
- OnPasswordGenerationEnabled)
IPC_MESSAGE_HANDLER(AutofillMsg_AccountCreationFormsDetected,
OnAccountCreationFormsDetected)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -227,36 +223,42 @@ void PasswordGenerationAgent::OnPasswordAccepted(
}
}
-void PasswordGenerationAgent::OnPasswordGenerationEnabled(bool enabled) {
- enabled_ = enabled;
-}
-
void PasswordGenerationAgent::OnAccountCreationFormsDetected(
const std::vector<autofill::FormData>& forms) {
- account_creation_forms_.insert(
- account_creation_forms_.end(), forms.begin(), forms.end());
+ generation_enabled_forms_.insert(
+ generation_enabled_forms_.end(), forms.begin(), forms.end());
MaybeShowIcon();
}
void PasswordGenerationAgent::MaybeShowIcon() {
- // We should show the password generation icon only when we have detected
- // account creation form, we have confirmed from browser that this form
- // is not blacklisted by the users, and the Autofill server has marked one
- // of its field as ACCOUNT_CREATION_PASSWORD.
- if (!possible_account_creation_form_.get() ||
- passwords_.empty() ||
- not_blacklisted_password_form_origins_.empty() ||
- account_creation_forms_.empty()) {
+ // Make sure local heuristics have identified a possible account creation
+ // form.
+ if (!possible_account_creation_form_.get() || passwords_.empty()) {
+ DVLOG(2) << "Local hueristics have not detected a possible account "
+ << "creation form";
return;
}
- if (!ContainsURL(not_blacklisted_password_form_origins_,
+ // Verify that it's not blacklisted.
+ if (not_blacklisted_password_form_origins_.empty() ||
+ !ContainsURL(not_blacklisted_password_form_origins_,
possible_account_creation_form_->origin)) {
+ DVLOG(2) << "Have not recieved confirmation that password form isn't "
+ << "blacklisted";
return;
}
- if (!ContainsForm(account_creation_forms_,
- *possible_account_creation_form_)) {
+ // Ensure that we get a ping from Autofill saying that this form is used for
+ // account creation. Note that this message will not be set if this feature
+ // is not enabled. If kNoAutofillNecessaryForPasswordGeneration is set,
+ // skip this check. This switch should only be used in testing environments.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kNoAutofillNecessaryForPasswordGeneration) &&
+ (generation_enabled_forms_.empty() ||
+ !ContainsForm(generation_enabled_forms_,
+ *possible_account_creation_form_))) {
+ DVLOG(2) << "Have not recieved confirmation from Autofill that form is used"
+ << " for account creation";
return;
}
diff --git a/components/autofill/content/renderer/password_generation_agent.h b/components/autofill/content/renderer/password_generation_agent.h
index 0bbc573..cf5af00 100644
--- a/components/autofill/content/renderer/password_generation_agent.h
+++ b/components/autofill/content/renderer/password_generation_agent.h
@@ -29,7 +29,7 @@ struct PasswordForm;
// generation between the browser (which shows the popup and generates
// passwords) and WebKit (shows the generation icon in the password field).
class PasswordGenerationAgent : public content::RenderViewObserver,
- public WebKit::WebPasswordGeneratorClient {
+ public WebKit::WebPasswordGeneratorClient {
public:
explicit PasswordGenerationAgent(content::RenderView* render_view);
virtual ~PasswordGenerationAgent();
@@ -53,7 +53,6 @@ class PasswordGenerationAgent : public content::RenderViewObserver,
// Message handlers.
void OnFormNotBlacklisted(const PasswordForm& form);
void OnPasswordAccepted(const base::string16& password);
- void OnPasswordGenerationEnabled(bool enabled);
void OnAccountCreationFormsDetected(
const std::vector<autofill::FormData>& forms);
@@ -62,10 +61,6 @@ class PasswordGenerationAgent : public content::RenderViewObserver,
content::RenderView* render_view_;
- // True if password generation is enabled for the profile associated
- // with this renderer.
- bool enabled_;
-
// Stores the origin of the account creation form we detected.
scoped_ptr<PasswordForm> possible_account_creation_form_;
@@ -75,8 +70,9 @@ class PasswordGenerationAgent : public content::RenderViewObserver,
std::vector<GURL> not_blacklisted_password_form_origins_;
// Stores each password form for which the Autofill server classifies one of
- // the form's fields as an ACCOUNT_CREATION_PASSWORD.
- std::vector<autofill::FormData> account_creation_forms_;
+ // the form's fields as an ACCOUNT_CREATION_PASSWORD. These forms will
+ // not be sent if the feature is disabled.
+ std::vector<autofill::FormData> generation_enabled_forms_;
std::vector<WebKit::WebInputElement> passwords_;
diff --git a/components/autofill/core/common/autofill_messages.h b/components/autofill/core/common/autofill_messages.h
index 006744f..e52e229 100644
--- a/components/autofill/core/common/autofill_messages.h
+++ b/components/autofill/core/common/autofill_messages.h
@@ -136,10 +136,6 @@ IPC_MESSAGE_ROUTED1(AutofillMsg_AcceptDataListSuggestion,
IPC_MESSAGE_ROUTED1(AutofillMsg_GeneratedPasswordAccepted,
base::string16 /* generated_password */)
-// Tells the renderer whether password generation is enabled.
-IPC_MESSAGE_ROUTED1(AutofillMsg_PasswordGenerationEnabled,
- bool /* is_enabled */)
-
// Tells the renderer that the password field has accept the suggestion.
IPC_MESSAGE_ROUTED1(AutofillMsg_AcceptPasswordAutofillSuggestion,
base::string16 /* username value*/)
diff --git a/components/autofill/core/common/autofill_switches.cc b/components/autofill/core/common/autofill_switches.cc
index b471af9..b3b3a66 100644
--- a/components/autofill/core/common/autofill_switches.cc
+++ b/components/autofill/core/common/autofill_switches.cc
@@ -32,6 +32,11 @@ const char kEnableInteractiveAutocomplete[] = "enable-interactive-autocomplete";
// account creation.
const char kEnablePasswordGeneration[] = "enable-password-generation";
+// Removes the requirement that we recieved a ping from the autofill servers.
+// Used in testing.
+const char kNoAutofillNecessaryForPasswordGeneration[] =
+ "no-autofill-for-password-generation";
+
// Annotates forms with Autofill field type predictions.
const char kShowAutofillTypePredictions[] = "show-autofill-type-predictions";
diff --git a/components/autofill/core/common/autofill_switches.h b/components/autofill/core/common/autofill_switches.h
index 9d055ad..6535ad0 100644
--- a/components/autofill/core/common/autofill_switches.h
+++ b/components/autofill/core/common/autofill_switches.h
@@ -16,6 +16,7 @@ extern const char kDisablePasswordGeneration[];
extern const char kEnableExperimentalFormFilling[];
extern const char kEnableInteractiveAutocomplete[];
extern const char kEnablePasswordGeneration[];
+extern const char kNoAutofillNecessaryForPasswordGeneration[];
extern const char kShowAutofillTypePredictions[];
extern const char kWalletSecureServiceUrl[];
extern const char kWalletServiceUrl[];