| 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 "chrome/common/autofill_messages.h" | 8 #include "chrome/common/autofill_messages.h" |
| 9 #include "chrome/common/password_generation_util.h" | 9 #include "chrome/common/password_generation_util.h" |
| 10 #include "content/public/renderer/password_form_conversion_utils.h" |
| 10 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 11 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/gaia/gaia_urls.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 frame->document().forms(forms); | 104 frame->document().forms(forms); |
| 104 for (size_t i = 0; i < forms.size(); ++i) { | 105 for (size_t i = 0; i < forms.size(); ++i) { |
| 105 // Ignore forms with autocomplete turned off for now. We may remove this in | 106 // Ignore forms with autocomplete turned off for now. We may remove this in |
| 106 // the future, as we only want to avoid creating passwords if the signin | 107 // the future, as we only want to avoid creating passwords if the signin |
| 107 // form has autocomplete turned off. | 108 // form has autocomplete turned off. |
| 108 if (forms[i].isNull() || !forms[i].autoComplete()) | 109 if (forms[i].isNull() || !forms[i].autoComplete()) |
| 109 continue; | 110 continue; |
| 110 | 111 |
| 111 // If we can't get a valid PasswordForm, we skip this form because the | 112 // If we can't get a valid PasswordForm, we skip this form because the |
| 112 // the password won't get saved even if we generate it. | 113 // the password won't get saved even if we generate it. |
| 113 scoped_ptr<webkit::forms::PasswordForm> password_form( | 114 scoped_ptr<content::PasswordForm> password_form( |
| 114 webkit::forms::PasswordFormDomManager::CreatePasswordForm(forms[i])); | 115 content::CreatePasswordForm(forms[i])); |
| 115 if (!password_form.get()) { | 116 if (!password_form.get()) { |
| 116 DVLOG(2) << "Skipping form as it would not be saved"; | 117 DVLOG(2) << "Skipping form as it would not be saved"; |
| 117 continue; | 118 continue; |
| 118 } | 119 } |
| 119 | 120 |
| 120 // Do not generate password for GAIA since it is used to retrieve the | 121 // Do not generate password for GAIA since it is used to retrieve the |
| 121 // generated paswords. | 122 // generated paswords. |
| 122 GURL realm(password_form->signon_realm); | 123 GURL realm(password_form->signon_realm); |
| 123 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) | 124 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) |
| 124 continue; | 125 continue; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 WebKit::WebCString PasswordGenerationManager::imageNameForDisabledState() { | 169 WebKit::WebCString PasswordGenerationManager::imageNameForDisabledState() { |
| 169 return imageNameForNormalState(); | 170 return imageNameForNormalState(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 WebKit::WebCString PasswordGenerationManager::imageNameForReadOnlyState() { | 173 WebKit::WebCString PasswordGenerationManager::imageNameForReadOnlyState() { |
| 173 return imageNameForNormalState(); | 174 return imageNameForNormalState(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { | 177 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { |
| 177 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); | 178 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); |
| 178 scoped_ptr<webkit::forms::PasswordForm> password_form( | 179 scoped_ptr<content::PasswordForm> password_form( |
| 179 webkit::forms::PasswordFormDomManager::CreatePasswordForm( | 180 content::CreatePasswordForm(element.form())); |
| 180 element.form())); | |
| 181 // We should not have shown the icon we can't create a valid PasswordForm. | 181 // We should not have shown the icon we can't create a valid PasswordForm. |
| 182 DCHECK(password_form.get()); | 182 DCHECK(password_form.get()); |
| 183 | 183 |
| 184 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), | 184 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), |
| 185 rect, | 185 rect, |
| 186 element.maxLength(), | 186 element.maxLength(), |
| 187 *password_form)); | 187 *password_form)); |
| 188 password_generation::LogPasswordGenerationEvent( | 188 password_generation::LogPasswordGenerationEvent( |
| 189 password_generation::BUBBLE_SHOWN); | 189 password_generation::BUBBLE_SHOWN); |
| 190 } | 190 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 202 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, | 202 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, |
| 203 OnPasswordAccepted) | 203 OnPasswordAccepted) |
| 204 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, | 204 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, |
| 205 OnPasswordGenerationEnabled) | 205 OnPasswordGenerationEnabled) |
| 206 IPC_MESSAGE_UNHANDLED(handled = false) | 206 IPC_MESSAGE_UNHANDLED(handled = false) |
| 207 IPC_END_MESSAGE_MAP() | 207 IPC_END_MESSAGE_MAP() |
| 208 return handled; | 208 return handled; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void PasswordGenerationManager::OnFormNotBlacklisted( | 211 void PasswordGenerationManager::OnFormNotBlacklisted( |
| 212 const webkit::forms::PasswordForm& form) { | 212 const content::PasswordForm& form) { |
| 213 not_blacklisted_password_form_origins_.push_back(form.origin); | 213 not_blacklisted_password_form_origins_.push_back(form.origin); |
| 214 MaybeShowIcon(); | 214 MaybeShowIcon(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { | 217 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { |
| 218 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); | 218 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); |
| 219 it != passwords_.end(); ++it) { | 219 it != passwords_.end(); ++it) { |
| 220 it->setValue(password); | 220 it->setValue(password); |
| 221 it->setAutofilled(true); | 221 it->setAutofilled(true); |
| 222 // Advance focus to the next input field. We assume password fields in | 222 // Advance focus to the next input field. We assume password fields in |
| (...skipping 23 matching lines...) Expand all Loading... |
| 246 passwords_[0].decorationElementFor(this).setAttribute("style", | 246 passwords_[0].decorationElementFor(this).setAttribute("style", |
| 247 "display:block"); | 247 "display:block"); |
| 248 password_generation::LogPasswordGenerationEvent( | 248 password_generation::LogPasswordGenerationEvent( |
| 249 password_generation::ICON_SHOWN); | 249 password_generation::ICON_SHOWN); |
| 250 return; | 250 return; |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace autofill | 255 } // namespace autofill |
| OLD | NEW |