Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/autofill/password_generation_manager.h" | 5 #include "chrome/renderer/autofill/password_generation_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/ui/password_generation_status.h" | |
| 8 #include "chrome/common/autofill_messages.h" | 11 #include "chrome/common/autofill_messages.h" |
| 9 #include "chrome/common/net/gaia/gaia_urls.h" | 12 #include "chrome/common/net/gaia/gaia_urls.h" |
| 10 #include "content/public/renderer/render_view.h" | 13 #include "content/public/renderer/render_view.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 20 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 21 | 24 |
| 25 using namespace password_generation; | |
|
Ilya Sherman
2012/07/18 05:36:15
"using namespace" is disallowed by the Chromium st
zysxqn
2012/07/18 19:16:46
Done.
| |
| 26 | |
| 22 namespace autofill { | 27 namespace autofill { |
| 23 | 28 |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 // Returns true if we think that this form is for account creation. |passwords| | 31 // Returns true if we think that this form is for account creation. |passwords| |
| 27 // is filled with the password field(s) in the form. | 32 // is filled with the password field(s) in the form. |
| 28 bool GetAccountCreationPasswordFields( | 33 bool GetAccountCreationPasswordFields( |
| 29 const WebKit::WebFormElement& form, | 34 const WebKit::WebFormElement& form, |
| 30 std::vector<WebKit::WebInputElement>* passwords) { | 35 std::vector<WebKit::WebInputElement>* passwords) { |
| 31 // Grab all of the passwords for the form. | 36 // Grab all of the passwords for the form. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 113 |
| 109 // Do not generate password for GAIA since it is used to retrieve the | 114 // Do not generate password for GAIA since it is used to retrieve the |
| 110 // generated paswords. | 115 // generated paswords. |
| 111 GURL realm(password_form->signon_realm); | 116 GURL realm(password_form->signon_realm); |
| 112 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) | 117 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) |
| 113 continue; | 118 continue; |
| 114 | 119 |
| 115 std::vector<WebKit::WebInputElement> passwords; | 120 std::vector<WebKit::WebInputElement> passwords; |
| 116 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { | 121 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { |
| 117 DVLOG(2) << "Account creation form detected"; | 122 DVLOG(2) << "Account creation form detected"; |
| 123 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.Events", | |
| 124 SIGN_UP_DETECTED, EVENT_ENUM_COUNT); | |
| 118 passwords_ = passwords; | 125 passwords_ = passwords; |
| 119 account_creation_form_origin_ = password_form->origin; | 126 account_creation_form_origin_ = password_form->origin; |
| 120 MaybeShowIcon(); | 127 MaybeShowIcon(); |
| 121 // We assume that there is only one account creation field per URL. | 128 // We assume that there is only one account creation field per URL. |
| 122 return; | 129 return; |
| 123 } | 130 } |
| 124 } | 131 } |
| 125 } | 132 } |
| 126 | 133 |
| 127 bool PasswordGenerationManager::ShouldAnalyzeDocument( | 134 bool PasswordGenerationManager::ShouldAnalyzeDocument( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { | 168 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { |
| 162 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); | 169 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); |
| 163 webkit::forms::PasswordForm* password_form( | 170 webkit::forms::PasswordForm* password_form( |
| 164 webkit::forms::PasswordFormDomManager::CreatePasswordForm( | 171 webkit::forms::PasswordFormDomManager::CreatePasswordForm( |
| 165 element.form())); | 172 element.form())); |
| 166 if (password_form) { | 173 if (password_form) { |
| 167 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), | 174 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), |
| 168 rect, | 175 rect, |
| 169 element.maxLength(), | 176 element.maxLength(), |
| 170 *password_form)); | 177 *password_form)); |
| 178 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.Events", | |
| 179 BUBBLE_SHOWN, EVENT_ENUM_COUNT); | |
| 171 } | 180 } |
| 172 } | 181 } |
| 173 | 182 |
| 174 void PasswordGenerationManager::willDetach( | 183 void PasswordGenerationManager::willDetach( |
| 175 const WebKit::WebInputElement& element) { | 184 const WebKit::WebInputElement& element) { |
| 176 // No implementation | 185 // No implementation |
| 177 } | 186 } |
| 178 | 187 |
| 179 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { | 188 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { |
| 180 bool handled = true; | 189 bool handled = true; |
| 181 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) | 190 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) |
| 182 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, | 191 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, |
| 183 OnFormNotBlacklisted) | 192 OnFormNotBlacklisted) |
| 184 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, | 193 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationBubbleClosed, |
| 185 OnPasswordAccepted) | 194 OnPasswordGenerationBubbleClosed) |
| 186 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, | 195 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, |
| 187 OnPasswordGenerationEnabled) | 196 OnPasswordGenerationEnabled) |
| 188 IPC_MESSAGE_UNHANDLED(handled = false) | 197 IPC_MESSAGE_UNHANDLED(handled = false) |
| 189 IPC_END_MESSAGE_MAP() | 198 IPC_END_MESSAGE_MAP() |
| 190 return handled; | 199 return handled; |
| 191 } | 200 } |
| 192 | 201 |
| 193 void PasswordGenerationManager::OnFormNotBlacklisted( | 202 void PasswordGenerationManager::OnFormNotBlacklisted( |
| 194 const webkit::forms::PasswordForm& form) { | 203 const webkit::forms::PasswordForm& form) { |
| 195 not_blacklisted_password_form_origins_.push_back(form.origin); | 204 not_blacklisted_password_form_origins_.push_back(form.origin); |
| 196 MaybeShowIcon(); | 205 MaybeShowIcon(); |
| 197 } | 206 } |
| 198 | 207 |
| 199 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { | 208 void PasswordGenerationManager::OnPasswordGenerationBubbleClosed( |
| 200 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); | 209 const PasswordGenerationStatus& status) { |
| 210 if (status.password_accepted) { | |
| 211 if (status.password_edited) | |
| 212 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.UserActions", | |
| 213 ACCEPT_AFTER_EDITING, ACTION_ENUM_COUNT); | |
| 214 else | |
| 215 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.UserActions", | |
| 216 ACCEPT_ORIGINAL_PASSWORD, ACTION_ENUM_COUNT); | |
| 217 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); | |
| 201 it != passwords_.end(); ++it) { | 218 it != passwords_.end(); ++it) { |
| 202 it->setValue(password); | 219 it->setValue(UTF8ToUTF16(status.generated_password)); |
| 203 it->setAutofilled(true); | 220 it->setAutofilled(true); |
| 204 // Advance focus to the next input field. We assume password fields in | 221 // Advance focus to the next input field. We assume password fields in |
| 205 // an account creation form are always adjacent. | 222 // an account creation form are always adjacent. |
| 206 render_view_->GetWebView()->advanceFocus(false); | 223 render_view_->GetWebView()->advanceFocus(false); |
| 224 } | |
| 225 } else if (status.learn_more_visited) { | |
| 226 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.UserActions", | |
| 227 LEARN_MORE, ACTION_ENUM_COUNT); | |
| 228 } else { | |
| 229 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.UserActions", | |
| 230 IGNORE, ACTION_ENUM_COUNT); | |
| 207 } | 231 } |
| 208 } | 232 } |
| 209 | 233 |
| 210 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { | 234 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { |
| 211 enabled_ = enabled; | 235 enabled_ = enabled; |
| 212 } | 236 } |
| 213 | 237 |
| 214 void PasswordGenerationManager::MaybeShowIcon() { | 238 void PasswordGenerationManager::MaybeShowIcon() { |
| 215 // We should show the password generation icon only when we have detected | 239 // We should show the password generation icon only when we have detected |
| 216 // account creation form and we have confirmed from browser that this form | 240 // account creation form and we have confirmed from browser that this form |
| 217 // is not blacklisted by the users. | 241 // is not blacklisted by the users. |
| 218 if (!account_creation_form_origin_.is_valid() || | 242 if (!account_creation_form_origin_.is_valid() || |
| 219 passwords_.empty() || | 243 passwords_.empty() || |
| 220 not_blacklisted_password_form_origins_.empty()) { | 244 not_blacklisted_password_form_origins_.empty()) { |
| 221 return; | 245 return; |
| 222 } | 246 } |
| 223 | 247 |
| 224 for (std::vector<GURL>::iterator it = | 248 for (std::vector<GURL>::iterator it = |
| 225 not_blacklisted_password_form_origins_.begin(); | 249 not_blacklisted_password_form_origins_.begin(); |
| 226 it != not_blacklisted_password_form_origins_.end(); ++it) { | 250 it != not_blacklisted_password_form_origins_.end(); ++it) { |
| 227 if (*it == account_creation_form_origin_) { | 251 if (*it == account_creation_form_origin_) { |
| 228 passwords_[0].decorationElementFor(this).setAttribute("style", | 252 passwords_[0].decorationElementFor(this).setAttribute("style", |
| 229 "display:block"); | 253 "display:block"); |
| 254 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.Events", | |
| 255 ICON_SHOWN, EVENT_ENUM_COUNT); | |
| 230 return; | 256 return; |
| 231 } | 257 } |
| 232 } | 258 } |
| 233 } | 259 } |
| 234 | 260 |
| 235 } // namespace autofill | 261 } // namespace autofill |
| OLD | NEW |