| 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 "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return true; | 49 return true; |
| 50 | 50 |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 PasswordGenerationManager::PasswordGenerationManager( | 56 PasswordGenerationManager::PasswordGenerationManager( |
| 57 content::RenderView* render_view) | 57 content::RenderView* render_view) |
| 58 : content::RenderViewObserver(render_view), | 58 : content::RenderViewObserver(render_view), |
| 59 render_view_(render_view), |
| 59 enabled_(false) { | 60 enabled_(false) { |
| 60 render_view->GetWebView()->addTextFieldDecoratorClient(this); | 61 render_view_->GetWebView()->addTextFieldDecoratorClient(this); |
| 61 } | 62 } |
| 62 PasswordGenerationManager::~PasswordGenerationManager() {} | 63 PasswordGenerationManager::~PasswordGenerationManager() {} |
| 63 | 64 |
| 64 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { | 65 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { |
| 65 // In every navigation, the IPC message sent by the password autofill manager | 66 // In every navigation, the IPC message sent by the password autofill manager |
| 66 // to query whether the current form is blacklisted or not happens when the | 67 // to query whether the current form is blacklisted or not happens when the |
| 67 // document load finishes, so we need to clear previous states here before we | 68 // document load finishes, so we need to clear previous states here before we |
| 68 // hear back from the browser. Note that we assume there is only one account | 69 // hear back from the browser. Note that we assume there is only one account |
| 69 // creation form, but there could be multiple password forms in each frame. | 70 // creation form, but there could be multiple password forms in each frame. |
| 70 not_blacklisted_password_form_origins_.clear(); | 71 not_blacklisted_password_form_origins_.clear(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 const webkit::forms::PasswordForm& form) { | 183 const webkit::forms::PasswordForm& form) { |
| 183 not_blacklisted_password_form_origins_.push_back(form.origin); | 184 not_blacklisted_password_form_origins_.push_back(form.origin); |
| 184 MaybeShowIcon(); | 185 MaybeShowIcon(); |
| 185 } | 186 } |
| 186 | 187 |
| 187 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { | 188 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { |
| 188 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); | 189 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); |
| 189 it != passwords_.end(); ++it) { | 190 it != passwords_.end(); ++it) { |
| 190 it->setValue(password); | 191 it->setValue(password); |
| 191 it->setAutofilled(true); | 192 it->setAutofilled(true); |
| 193 // Advance focus to the next input field. We assume password fields in |
| 194 // an account creation form are always adjacent. |
| 195 render_view_->GetWebView()->advanceFocus(false); |
| 192 } | 196 } |
| 193 } | 197 } |
| 194 | 198 |
| 195 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { | 199 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { |
| 196 enabled_ = enabled; | 200 enabled_ = enabled; |
| 197 } | 201 } |
| 198 | 202 |
| 199 void PasswordGenerationManager::MaybeShowIcon() { | 203 void PasswordGenerationManager::MaybeShowIcon() { |
| 200 // We should show the password generation icon only when we have detected | 204 // We should show the password generation icon only when we have detected |
| 201 // account creation form and we have confirmed from browser that this form | 205 // account creation form and we have confirmed from browser that this form |
| 202 // is not blacklisted by the users. | 206 // is not blacklisted by the users. |
| 203 if (!account_creation_form_origin_.is_valid() || | 207 if (!account_creation_form_origin_.is_valid() || |
| 204 passwords_.empty() || | 208 passwords_.empty() || |
| 205 not_blacklisted_password_form_origins_.empty()) { | 209 not_blacklisted_password_form_origins_.empty()) { |
| 206 return; | 210 return; |
| 207 } | 211 } |
| 208 | 212 |
| 209 for (std::vector<GURL>::iterator it = | 213 for (std::vector<GURL>::iterator it = |
| 210 not_blacklisted_password_form_origins_.begin(); | 214 not_blacklisted_password_form_origins_.begin(); |
| 211 it != not_blacklisted_password_form_origins_.end(); ++it) { | 215 it != not_blacklisted_password_form_origins_.end(); ++it) { |
| 212 if (*it == account_creation_form_origin_) { | 216 if (*it == account_creation_form_origin_) { |
| 213 passwords_[0].decorationElementFor(this).setAttribute("style", | 217 passwords_[0].decorationElementFor(this).setAttribute("style", |
| 214 "display:block"); | 218 "display:block"); |
| 215 return; | 219 return; |
| 216 } | 220 } |
| 217 } | 221 } |
| 218 } | 222 } |
| 219 | 223 |
| 220 } // namespace autofill | 224 } // namespace autofill |
| OLD | NEW |