| 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 "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 17 | 17 |
| 18 namespace autofill { | 18 namespace autofill { |
| 19 | 19 |
| 20 PasswordGenerationManager::PasswordGenerationManager( | 20 PasswordGenerationManager::PasswordGenerationManager( |
| 21 content::RenderView* render_view) | 21 content::RenderView* render_view) |
| 22 : content::RenderViewObserver(render_view), | 22 : content::RenderViewObserver(render_view), |
| 23 enabled_(false) {} | 23 sync_enabled_(false), |
| 24 password_generation_enabled_(false) {} |
| 24 PasswordGenerationManager::~PasswordGenerationManager() {} | 25 PasswordGenerationManager::~PasswordGenerationManager() {} |
| 25 | 26 |
| 26 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { | 27 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { |
| 27 // We don't want to generate passwords if the browser won't store or sync | 28 // We don't want to generate passwords if browser won't store or sync them, or |
| 28 // them. | 29 // password generation isn't enabled. |
| 29 if (!enabled_) | 30 if (!sync_enabled_ || !password_generation_enabled_) |
| 30 return; | 31 return; |
| 31 | 32 |
| 32 if (!ShouldAnalyzeFrame(*frame)) | 33 if (!ShouldAnalyzeFrame(*frame)) |
| 33 return; | 34 return; |
| 34 | 35 |
| 35 WebKit::WebVector<WebKit::WebFormElement> forms; | 36 WebKit::WebVector<WebKit::WebFormElement> forms; |
| 36 frame->document().forms(forms); | 37 frame->document().forms(forms); |
| 37 for (size_t i = 0; i < forms.size(); ++i) { | 38 for (size_t i = 0; i < forms.size(); ++i) { |
| 38 const WebKit::WebFormElement& web_form = forms[i]; | 39 const WebKit::WebFormElement& web_form = forms[i]; |
| 39 if (!web_form.autoComplete()) | 40 if (!web_form.autoComplete()) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), | 84 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), |
| 84 rect)); | 85 rect)); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { | 89 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { |
| 89 bool handled = true; | 90 bool handled = true; |
| 90 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) | 91 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) |
| 91 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, | 92 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, |
| 92 OnPasswordAccepted) | 93 OnPasswordAccepted) |
| 94 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordSyncEnabled, |
| 95 OnPasswordSyncEnabled) |
| 93 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, | 96 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, |
| 94 OnPasswordSyncEnabled) | 97 OnPasswordGenerationEnabled) |
| 95 IPC_MESSAGE_UNHANDLED(handled = false) | 98 IPC_MESSAGE_UNHANDLED(handled = false) |
| 96 IPC_END_MESSAGE_MAP() | 99 IPC_END_MESSAGE_MAP() |
| 97 return handled; | 100 return handled; |
| 98 } | 101 } |
| 99 | 102 |
| 100 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { | 103 void PasswordGenerationManager::OnPasswordAccepted(const string16& password) { |
| 101 for (std::vector<WebKit::WebInputElement>::iterator it = | 104 for (std::vector<WebKit::WebInputElement>::iterator it = |
| 102 account_creation_elements_.second.begin(); | 105 account_creation_elements_.second.begin(); |
| 103 it != account_creation_elements_.second.end(); ++it) { | 106 it != account_creation_elements_.second.end(); ++it) { |
| 104 it->setValue(password); | 107 it->setValue(password); |
| 105 it->setAutofilled(true); | 108 it->setAutofilled(true); |
| 106 } | 109 } |
| 107 } | 110 } |
| 108 | 111 |
| 109 void PasswordGenerationManager::OnPasswordSyncEnabled(bool enabled) { | 112 void PasswordGenerationManager::OnPasswordSyncEnabled(bool enabled) { |
| 110 enabled_ = enabled; | 113 sync_enabled_ = enabled; |
| 114 } |
| 115 |
| 116 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { |
| 117 password_generation_enabled_ = enabled; |
| 111 } | 118 } |
| 112 | 119 |
| 113 } // namespace autofill | 120 } // namespace autofill |
| OLD | NEW |